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