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

@ -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)))
{})))

View File

@ -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