From f1cf4c737542a062d8c56aecdd0f22663756beba Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Tue, 22 Aug 2017 14:28:38 +0300 Subject: [PATCH] Function for getting all token balances in a multisig --- src/clj/commiteth/eth/multisig_wallet.clj | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/clj/commiteth/eth/multisig_wallet.clj b/src/clj/commiteth/eth/multisig_wallet.clj index ca6d5e0..1481224 100644 --- a/src/clj/commiteth/eth/multisig_wallet.clj +++ b/src/clj/commiteth/eth/multisig_wallet.clj @@ -145,8 +145,23 @@ "Query balance of given ERC20 token TLA for given address from ERC20 contract" [bounty-addr token] (let [token-address (get-token-address token)] + (-> (eth/call token-address (:balance-of method-ids) bounty-addr) eth/hex->big-integer (convert-token-value token)))) + + +(defn token-balances + "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 {:balance (token-balance bounty-addr tla)}])) token-addresses))))