Fix crash in token-balances, fix update-balances

* fix null pointer crash in token-balances
* fix bug in periodic update-balances
This commit is contained in:
Teemu Patja 2017-08-22 19:45:00 +03:00
parent f8d00196d6
commit e4124d6bc2
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
2 changed files with 30 additions and 28 deletions

View File

@ -157,11 +157,14 @@
"Get a given bounty contract's token balances. Assumes contract's internal balances have been updated" "Get a given bounty contract's token balances. Assumes contract's internal balances have been updated"
[bounty-addr] [bounty-addr]
(let [bounty-contract (load-bounty-contract bounty-addr) (let [bounty-contract (load-bounty-contract bounty-addr)
token-addresses (map str (-> bounty-contract token-addresses (-> bounty-contract
(.getTokenList) (.getTokenList)
.get .get)]
.getValue))] (if token-addresses
(let [addrs (map str
(.getValue token-addresses))]
(into {} (into {}
(map (fn [addr] (let [tla (first (token-data/token-info-by-addr addr))] (map (fn [addr] (let [tla (first (token-data/token-info-by-addr addr))]
(assert tla) (assert tla)
[tla (token-balance bounty-addr tla)])) token-addresses)))) [tla (token-balance bounty-addr tla)])) addrs)))
{})))

View File

@ -161,33 +161,32 @@
db-tokens :tokens db-tokens :tokens
issue-number :issue_number} (db-bounties/open-bounty-contracts)] issue-number :issue_number} (db-bounties/open-bounty-contracts)]
(when comment-id (when comment-id
(let [current-balance-eth-str (eth/get-balance-eth contract-address 6) (let [balance-eth-str (eth/get-balance-eth contract-address 6)
current-balance-eth (read-string current-balance-eth-str) balance-eth (read-string balance-eth-str)
current-token-balances (multisig/token-balances contract-address)] token-balances (multisig/token-balances contract-address)]
(log/debug "update-balances" current-balance-eth (log/debug "update-balances" balance-eth
current-balance-eth-str owner repo issue-number) balance-eth-str token-balances owner repo issue-number)
(when (or (when (or
(not (float= db-balance-eth current-balance-eth)) (not (float= db-balance-eth balance-eth))
(not= db-tokens current-token-balances)) (not= db-tokens token-balances))
(log/debug "balances differ") (log/debug "balances differ")
(-> contract-address (issues/update-eth-balance contract-address balance-eth)
(issues/update-eth-balance current-balance-eth) (issues/update-token-balances contract-address token-balances)
(issues/update-token-balances current-token-balances))
;; TODO: comment and comment image will show tokens and USD value ;; TODO: comment and comment image will show tokens and USD value
(bounties/update-bounty-comment-image issue-id (bounties/update-bounty-comment-image issue-id
owner owner
repo repo
issue-number issue-number
contract-address contract-address
current-balance-eth balance-eth
current-balance-eth-str) balance-eth-str)
(github/update-comment owner (github/update-comment owner
repo repo
comment-id comment-id
issue-number issue-number
contract-address contract-address
current-balance-eth balance-eth
current-balance-eth-str)))))) balance-eth-str))))))
(defn update-bounty-token-balances (defn update-bounty-token-balances