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,
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

View File

@ -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)]

View File

@ -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