Workaround for smart contract issue related to payouts

If our smart contract is used as designed for payout (first commiteth
bot executes confirmTransaction() with a withdrawEverything call in
payload and then the repo owner calls confirmTransaction() with the
returned tx-id) the contract fails when executing, but confirming
succeeds. Because of this, we now look for contracts that have been
confirmed by both and that still have ETH and/or tokens, and call
executeTransaction() for those.

This needs testing.
This commit is contained in:
Teemu Patja 2017-08-31 11:33:08 +03:00
parent 5ab68f3b18
commit 11d2c6e4ce
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
3 changed files with 26 additions and 12 deletions

View File

@ -294,6 +294,7 @@ SELECT
i.value_usd AS value_usd, i.value_usd AS value_usd,
u.address AS payout_address, u.address AS payout_address,
u.login AS payee_login, u.login AS payee_login,
i.confirm_hash AS confirm_hash,
i.payout_hash AS payout_hash i.payout_hash AS payout_hash
FROM issues i, pull_requests p, users u, repositories r FROM issues i, pull_requests p, users u, repositories r
WHERE WHERE

View File

@ -208,7 +208,8 @@
contract." contract."
[bounty-addr tx-id] [bounty-addr tx-id]
(let [bounty-contract (load-bounty-contract bounty-addr) (let [bounty-contract (load-bounty-contract bounty-addr)
tx-id-web3j (uint256 tx-id) tx-id-numeric (read-string tx-id)
tx-id-web3j (uint256 tx-id-numeric)
ret (-> bounty-contract ret (-> bounty-contract
(.isConfirmed tx-id-web3j) (.isConfirmed tx-id-web3j)
.get)] .get)]
@ -221,7 +222,8 @@
is mined." is mined."
[bounty-addr tx-id] [bounty-addr tx-id]
(let [bounty-contract (load-bounty-contract bounty-addr) (let [bounty-contract (load-bounty-contract bounty-addr)
tx-id-web3j (uint256 tx-id) tx-id-numeric (read-string tx-id)
tx-id-web3j (uint256 tx-id-numeric)
ret (-> bounty-contract ret (-> bounty-contract
(.executeTransaction tx-id-web3j) (.executeTransaction tx-id-web3j)
.get)] .get)]

View File

@ -128,19 +128,31 @@
issue-number :issue_number issue-number :issue_number
balance-eth :balance_eth balance-eth :balance_eth
tokens :tokens tokens :tokens
confirm-id :confirm-hash
payee-login :payee_login} (db-bounties/confirmed-payouts)] payee-login :payee_login} (db-bounties/confirmed-payouts)]
(log/debug "confirmed payout:" payout-hash) (log/debug "confirmed payout:" payout-hash)
(when-let [receipt (eth/get-transaction-receipt payout-hash)] (when-let [receipt (eth/get-transaction-receipt payout-hash)]
(log/info "payout receipt for issue #" issue-id ": " receipt) (let [tokens (multisig/token-balances contract-address)
(db-bounties/update-payout-receipt issue-id receipt) eth-balance (eth/get-balance-wei contract-address)]
(github/update-paid-issue-comment owner (if (or
repo (some #(> (second %) 0.0) tokens)
comment-id (> eth-balance 0))
contract-address (log/info "Contract still has funds")
(eth-decimal->str balance-eth) (when (multisig/is-confirmed? contract-address confirm-id)
tokens (log/info "Detected bounty with funds and confirmed payout, calling executeTransaction")
payee-login)))) (let [execute-tx-hash (multisig/execute-tx contract-address confirm-id)]
(log/info "execute tx:" execute-tx-hash))))
(do
(log/info "Payout has succeeded, saving payout receipt for issue #" issue-id ": " receipt)
(db-bounties/update-payout-receipt issue-id receipt)
(github/update-paid-issue-comment owner
repo
comment-id
contract-address
(eth-decimal->str balance-eth)
tokens
payee-login))))))
(defn abs (defn abs
"(abs n) is the absolute value of n" "(abs n) is the absolute value of n"
@ -223,7 +235,6 @@
(log/debug "balances differ") (log/debug "balances differ")
(issues/update-eth-balance contract-address balance-eth) (issues/update-eth-balance contract-address balance-eth)
(issues/update-token-balances contract-address token-balances) (issues/update-token-balances contract-address token-balances)
;; TODO: comment and comment image will show tokens and USD value
(bounties/update-bounty-comment-image issue-id (bounties/update-bounty-comment-image issue-id
owner owner
repo repo