From e4124d6bc22a84ca66db5cafd76fb1396c33266c Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Tue, 22 Aug 2017 19:45:00 +0300 Subject: [PATCH] Fix crash in token-balances, fix update-balances * fix null pointer crash in token-balances * fix bug in periodic update-balances --- src/clj/commiteth/eth/multisig_wallet.clj | 21 +++++++------ src/clj/commiteth/scheduler.clj | 37 +++++++++++------------ 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/clj/commiteth/eth/multisig_wallet.clj b/src/clj/commiteth/eth/multisig_wallet.clj index f7132ef..7d5bfa1 100644 --- a/src/clj/commiteth/eth/multisig_wallet.clj +++ b/src/clj/commiteth/eth/multisig_wallet.clj @@ -61,7 +61,7 @@ correct-topic? (fn [topic] (= topic topic-id)) has-correct-event? #(some correct-topic? - (:topics %)) + (:topics %)) event (first (filter has-correct-event? logs))] (:data event))) @@ -157,11 +157,14 @@ "Get a given bounty contract's token balances. Assumes contract's internal balances have been updated" [bounty-addr] (let [bounty-contract (load-bounty-contract bounty-addr) - token-addresses (map str (-> bounty-contract - (.getTokenList) - .get - .getValue))] - (into {} - (map (fn [addr] (let [tla (first (token-data/token-info-by-addr addr))] - (assert tla) - [tla (token-balance bounty-addr tla)])) token-addresses)))) + token-addresses (-> bounty-contract + (.getTokenList) + .get)] + (if token-addresses + (let [addrs (map str + (.getValue token-addresses))] + (into {} + (map (fn [addr] (let [tla (first (token-data/token-info-by-addr addr))] + (assert tla) + [tla (token-balance bounty-addr tla)])) addrs))) + {}))) diff --git a/src/clj/commiteth/scheduler.clj b/src/clj/commiteth/scheduler.clj index fb19247..461521c 100644 --- a/src/clj/commiteth/scheduler.clj +++ b/src/clj/commiteth/scheduler.clj @@ -49,11 +49,11 @@ (defn deploy-contract [owner-address issue-id] (let [transaction-hash (multisig/deploy-multisig owner-address)] - (if (nil? transaction-hash) - (log/error "Failed to deploy contract to" owner-address) - (log/info "Contract deployed, transaction-hash:" - transaction-hash )) - (issues/update-transaction-hash issue-id transaction-hash))) + (if (nil? transaction-hash) + (log/error "Failed to deploy contract to" owner-address) + (log/info "Contract deployed, transaction-hash:" + transaction-hash )) + (issues/update-transaction-hash issue-id transaction-hash))) (defn redeploy-failed-contracts @@ -161,33 +161,32 @@ db-tokens :tokens issue-number :issue_number} (db-bounties/open-bounty-contracts)] (when comment-id - (let [current-balance-eth-str (eth/get-balance-eth contract-address 6) - current-balance-eth (read-string current-balance-eth-str) - current-token-balances (multisig/token-balances contract-address)] - (log/debug "update-balances" current-balance-eth - current-balance-eth-str owner repo issue-number) + (let [balance-eth-str (eth/get-balance-eth contract-address 6) + balance-eth (read-string balance-eth-str) + token-balances (multisig/token-balances contract-address)] + (log/debug "update-balances" balance-eth + balance-eth-str token-balances owner repo issue-number) (when (or - (not (float= db-balance-eth current-balance-eth)) - (not= db-tokens current-token-balances)) + (not (float= db-balance-eth balance-eth)) + (not= db-tokens token-balances)) (log/debug "balances differ") - (-> contract-address - (issues/update-eth-balance current-balance-eth) - (issues/update-token-balances current-token-balances)) + (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 issue-number contract-address - current-balance-eth - current-balance-eth-str) + balance-eth + balance-eth-str) (github/update-comment owner repo comment-id issue-number contract-address - current-balance-eth - current-balance-eth-str)))))) + balance-eth + balance-eth-str)))))) (defn update-bounty-token-balances