Function for getting all token balances in a multisig

This commit is contained in:
Teemu Patja 2017-08-22 14:28:38 +03:00
parent c6f6afa461
commit f1cf4c7375
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
1 changed files with 15 additions and 0 deletions

View File

@ -145,8 +145,23 @@
"Query balance of given ERC20 token TLA for given address from ERC20 contract" "Query balance of given ERC20 token TLA for given address from ERC20 contract"
[bounty-addr token] [bounty-addr token]
(let [token-address (get-token-address token)] (let [token-address (get-token-address token)]
(-> (eth/call token-address (-> (eth/call token-address
(:balance-of method-ids) (:balance-of method-ids)
bounty-addr) bounty-addr)
eth/hex->big-integer eth/hex->big-integer
(convert-token-value token)))) (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))))