Fix bug in payout confirm on backend side + cleanup

* fix parsing of confirmation transaction ID from confirmation event
* remove unused func, improve logging, general cleanup
This commit is contained in:
Teemu Patja 2017-08-26 14:12:56 +03:00
parent a1be68122c
commit 92628d040b
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
2 changed files with 32 additions and 30 deletions

View File

@ -24,7 +24,8 @@
(def topics (def topics
{:factory-create (eth/event-sig->topic-id "Create(address,address)") {:factory-create (eth/event-sig->topic-id "Create(address,address)")
:submission (eth/event-sig->topic-id "Submission(uint256)")}) :submission (eth/event-sig->topic-id "Submission(uint256)")
:confirmation (eth/event-sig->topic-id "Confirmation(address,uint256)")})
(defn factory-contract-addr [] (defn factory-contract-addr []
(env :contract-factory-addr "0x47F56FD26EEeCda4FdF5DB5843De1fe75D2A64A6")) (env :contract-factory-addr "0x47F56FD26EEeCda4FdF5DB5843De1fe75D2A64A6"))
@ -41,49 +42,50 @@
owner2)) owner2))
(defn deploy-multisig (defn deploy-multisig
"Deploy a new multisig contract to the blockchain with commiteth bot
and given owner as owners."
[owner] [owner]
(create-new (eth/eth-account) owner 2)) (create-new (eth/eth-account) owner 2))
(defn find-event-in-tx-receipt [tx-receipt topic-id]
(defn execute
[contract to value]
(log/debug "multisig.execute(contract, to, value)" contract to value)
(eth/execute (eth/eth-account)
contract
(:submit-transaction method-ids)
to
value
"0x60"
"0x0"
"0x0"))
(defn find-event-in-tx [tx-receipt topic-id]
(let [logs (:logs tx-receipt) (let [logs (:logs tx-receipt)
correct-topic? (fn [topic] correct-topic? (fn [topic]
(= topic topic-id)) (= topic topic-id))
has-correct-event? #(some correct-topic? has-correct-event? #(some correct-topic?
(:topics %)) (:topics %))
event (first (filter has-correct-event? logs))] log-entry (first (filter has-correct-event? logs))]
(:data event))) log-entry))
(defn addr-from-topic [topic]
(assert (= 66 (count topic)))
(str "0x" (subs topic 26)))
(defn find-confirmation-hash (defn find-confirmation-tx-id
[tx-receipt] [tx-receipt]
(let [confirmation-data (find-event-in-tx tx-receipt (:submission topics))] (let [confirmation-event (find-event-in-tx-receipt
(when confirmation-data tx-receipt
(subs confirmation-data 2 66)))) (:confirmation topics))]
(log/debug "confirmation-event" confirmation-event)
(when-let [topics (:topics confirmation-event)]
(let [ [_ addr-raw tx-id] topics
address (addr-from-topic addr-raw)]
(log/info "event: Confirmation(_sender=" address ", _transactionId=" tx-id ")")
tx-id))))
(defn find-created-multisig-address (defn find-created-multisig-address
[tx-receipt] [tx-receipt]
(let [factory-data (find-event-in-tx tx-receipt (:factory-create topics))] (let [factory-data (-> (find-event-in-tx-receipt
tx-receipt
(:factory-create topics))
:data)]
(when factory-data (when factory-data
(str "0x" (subs factory-data 26))))) (addr-from-topic factory-data))))
(defn send-all ;; TODO: not tested (defn send-all
[contract to] [contract to]
(log/debug "multisig.send-all(contract, to)" contract to) (log/debug "multisig/send-all " contract to)
(let [params (eth/format-call-params (let [params (eth/format-call-params
(:withdraw-everything method-ids) (:withdraw-everything method-ids)
to)] to)]
@ -92,8 +94,8 @@
(:submit-transaction method-ids) (:submit-transaction method-ids)
contract contract
0 0
"0x60" "0x60" ;; TODO: document these
"0x24" "0x24" ;; or refactor out
params))) params)))
@ -104,7 +106,7 @@
(defn watch-token (defn watch-token
[bounty-addr token] [bounty-addr token]
(log/debug "multisig.watch-token(contract, token)" bounty-addr token) (log/debug "multisig/watch-token" bounty-addr token)
(let [token-address (get-token-address token)] (let [token-address (get-token-address token)]
(assert token-address) (assert token-address)
(eth/execute (eth/eth-account) (eth/execute (eth/eth-account)

View File

@ -105,14 +105,14 @@
winner-login))))) winner-login)))))
(defn update-confirm-hash (defn update-confirm-hash
"Gets transaction receipt for each pending payout and updates confirm_hash" "Gets transaction receipt for each pending payout and updates DB confirm_hash with tranaction ID of commiteth bot account's confirmation."
[] []
(doseq [{issue-id :issue_id (doseq [{issue-id :issue_id
execute-hash :execute_hash} (db-bounties/pending-payouts)] execute-hash :execute_hash} (db-bounties/pending-payouts)]
(log/info "pending payout:" execute-hash) (log/info "pending payout:" execute-hash)
(when-let [receipt (eth/get-transaction-receipt execute-hash)] (when-let [receipt (eth/get-transaction-receipt execute-hash)]
(log/info "execution receipt for issue #" issue-id ": " receipt) (log/info "execution receipt for issue #" issue-id ": " receipt)
(when-let [confirm-hash (multisig/find-confirmation-hash receipt)] (when-let [confirm-hash (multisig/find-confirmation-tx-id receipt)]
(log/info "confirm hash:" confirm-hash) (log/info "confirm hash:" confirm-hash)
(db-bounties/update-confirm-hash issue-id confirm-hash))))) (db-bounties/update-confirm-hash issue-id confirm-hash)))))