From 245b9e1e2a04ddc16f31feeaefd2c1b017272093 Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Mon, 28 Aug 2017 09:56:23 +0300 Subject: [PATCH] ClojureScript fixes for payout * fix broken retrieval of injected web3 function * specify gas + gasPrice for sendTransaction * fix data value for confirmTransaction() call * eliminate hard-coded hex-string --- src/cljs/commiteth/handlers.cljs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/cljs/commiteth/handlers.cljs b/src/cljs/commiteth/handlers.cljs index 3fb39c9..db314d4 100644 --- a/src/cljs/commiteth/handlers.cljs +++ b/src/cljs/commiteth/handlers.cljs @@ -338,7 +338,12 @@ (when payout-hash (dispatch [:save-payout-hash issue-id payout-hash])))) +(defn sig->method-id [sig] + (let [sha3 (.-sha3 js/web3)] + (apply str (take 10 (sha3 sig))))) +(defn strip-0x [x] + (str/replace x #"^0x" "")) (reg-event-fx :confirm-payout @@ -346,17 +351,22 @@ owner-address :owner_address contract-address :contract_address confirm-hash :confirm_hash} issue]] - (let [send-transaction-fn (aget js/web3 "eth" "sendTransaction") - confirm-transaction-methodid "0xc01a8c84" - ;; confirmTransaction(uint256) + (let [web3-eth (-> js/web3 .-eth) + bignum (-> js/web3 .-BigNumber) + confirm-method-id (sig->method-id "confirmTransaction(uint256)") + confirm-id (strip-0x confirm-hash) + data (str confirm-method-id + confirm-id) payload {:from owner-address :to contract-address + :gas (bignum. "200000") + :gasPrice (bignum. "20000000000") :value 0 - :data (str confirm-transaction-methodid - confirm-hash)}] + :data data}] + (println "data:" data) (try - (apply send-transaction-fn [(clj->js payload) - (send-transaction-callback issue-id)]) + (.sendTransaction web3-eth (clj->js payload) + (send-transaction-callback issue-id)) {:db (assoc-in db [:owner-bounties issue-id :confirming?] true)} (catch js/Error e {:db (assoc-in db [:owner-bounties issue-id :confirm-failed?] true)