From 11d2c6e4ce6424d4b3962a07e34616e317b6297a Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Thu, 31 Aug 2017 11:33:08 +0300 Subject: [PATCH] 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. --- resources/sql/queries.sql | 1 + src/clj/commiteth/eth/multisig_wallet.clj | 6 +++-- src/clj/commiteth/scheduler.clj | 31 +++++++++++++++-------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/resources/sql/queries.sql b/resources/sql/queries.sql index 38c2bf2..5a0ad5f 100644 --- a/resources/sql/queries.sql +++ b/resources/sql/queries.sql @@ -294,6 +294,7 @@ SELECT i.value_usd AS value_usd, u.address AS payout_address, u.login AS payee_login, + i.confirm_hash AS confirm_hash, i.payout_hash AS payout_hash FROM issues i, pull_requests p, users u, repositories r WHERE diff --git a/src/clj/commiteth/eth/multisig_wallet.clj b/src/clj/commiteth/eth/multisig_wallet.clj index ed3c30f..2e30d4a 100644 --- a/src/clj/commiteth/eth/multisig_wallet.clj +++ b/src/clj/commiteth/eth/multisig_wallet.clj @@ -208,7 +208,8 @@ contract." [bounty-addr tx-id] (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 (.isConfirmed tx-id-web3j) .get)] @@ -221,7 +222,8 @@ is mined." [bounty-addr tx-id] (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 (.executeTransaction tx-id-web3j) .get)] diff --git a/src/clj/commiteth/scheduler.clj b/src/clj/commiteth/scheduler.clj index 4bf999e..f58049c 100644 --- a/src/clj/commiteth/scheduler.clj +++ b/src/clj/commiteth/scheduler.clj @@ -128,19 +128,31 @@ issue-number :issue_number balance-eth :balance_eth tokens :tokens + confirm-id :confirm-hash payee-login :payee_login} (db-bounties/confirmed-payouts)] (log/debug "confirmed payout:" payout-hash) (when-let [receipt (eth/get-transaction-receipt payout-hash)] - (log/info "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)))) + (let [tokens (multisig/token-balances contract-address) + eth-balance (eth/get-balance-wei contract-address)] + (if (or + (some #(> (second %) 0.0) tokens) + (> eth-balance 0)) + (log/info "Contract still has funds") + (when (multisig/is-confirmed? contract-address confirm-id) + (log/info "Detected bounty with funds and confirmed payout, calling executeTransaction") + (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 "(abs n) is the absolute value of n" @@ -223,7 +235,6 @@ (log/debug "balances differ") (issues/update-eth-balance contract-address balance-eth) (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 owner repo