More token support changes
* prepare scheduler for updating bounty balances * fix retrieving of created multisig address * retrieve token info by address * fix method-id for watch(address)
This commit is contained in:
parent
5f6ad85011
commit
a2a569f980
|
@ -9,7 +9,7 @@
|
|||
abi.datatypes.Address]
|
||||
[commiteth.eth.contracts MultiSigTokenWallet]))
|
||||
|
||||
(defonce method-ids
|
||||
(def method-ids
|
||||
(into {}
|
||||
(map (fn [[k signature]]
|
||||
[k (eth/sig->method-id signature)])
|
||||
|
@ -18,10 +18,10 @@
|
|||
:token-balances "tokenBalances(address)"
|
||||
:get-token-list "getTokenList()"
|
||||
:create "create(address[],uint256)"
|
||||
:watch "watch(address,bytes)"
|
||||
:watch "watch(address)"
|
||||
:balance-of "balanceOf(address)"})))
|
||||
|
||||
(defonce topics
|
||||
(def topics
|
||||
{:factory-create (eth/event-sig->topic-id "Create(address,address)")
|
||||
:submission (eth/event-sig->topic-id "Submission(uint256)")})
|
||||
|
||||
|
@ -114,16 +114,6 @@
|
|||
(:watch method-ids)
|
||||
token-address)))
|
||||
|
||||
(defn token-balances
|
||||
"Query ERC20 token balances from bounty contract"
|
||||
[bounty-contract token]
|
||||
(let [token-address (get-token-address token)]
|
||||
(println "token-address:" token-address)
|
||||
(eth/call bounty-contract
|
||||
(:token-balances method-ids)
|
||||
token-address
|
||||
0)))
|
||||
|
||||
|
||||
(defn load-bounty-contract [addr]
|
||||
(MultiSigTokenWallet/load addr
|
||||
|
@ -142,7 +132,7 @@
|
|||
|
||||
|
||||
(defn token-balance-in-bounty
|
||||
"Query ERC20 token balances from bounty contract"
|
||||
"Query (internal) ERC20 token balance from bounty contract for given token TLA"
|
||||
[bounty-addr token]
|
||||
(let [bounty-contract (load-bounty-contract bounty-addr)
|
||||
token-address (get-token-address token)
|
||||
|
@ -155,7 +145,7 @@
|
|||
(convert-token-value token))))
|
||||
|
||||
(defn token-balance
|
||||
"Query balance of given ERC20 token for given address from ERC20 contract"
|
||||
"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
|
||||
|
|
|
@ -27,3 +27,9 @@
|
|||
|
||||
(defn token-info [tla]
|
||||
(get @token-data-atom (keyword tla)))
|
||||
|
||||
(defn token-info-by-addr [addr]
|
||||
(let [tokens-data (as-map)]
|
||||
(first (filter (fn [[tla data]]
|
||||
(= (:address data) addr))
|
||||
tokens-data))))
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
(:require [commiteth.eth.core :as eth]
|
||||
[commiteth.eth.web3j
|
||||
:refer [create-web3j creds]]
|
||||
[commiteth.config :refer [env]])
|
||||
[commiteth.config :refer [env]]
|
||||
[clojure.tools.logging :as log])
|
||||
(:import [org.web3j
|
||||
abi.datatypes.generated.Uint256
|
||||
abi.datatypes.Address
|
||||
|
@ -34,7 +35,7 @@
|
|||
(let [contract (load-tokenreg-contract addr)]
|
||||
;(assert (.isValid contract)) ;; web3j's isValid can't be trusted...
|
||||
(let [token-count (-> contract .tokenCount .get .getValue)]
|
||||
(println "token-count" token-count)
|
||||
(log/debug "token-count" token-count)
|
||||
(into {}
|
||||
(map (fn [[addr tla digits name owner]]
|
||||
[(-> tla str keyword)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(ns commiteth.scheduler
|
||||
(:require [commiteth.eth.core :as eth]
|
||||
[commiteth.eth.multisig-wallet :as wallet]
|
||||
[commiteth.eth.multisig-wallet :as multisig]
|
||||
[commiteth.eth.token-data :as token-data]
|
||||
[commiteth.github.core :as github]
|
||||
[commiteth.db.issues :as issues]
|
||||
[commiteth.db.bounties :as db-bounties]
|
||||
|
@ -21,7 +22,7 @@
|
|||
(log/debug "pending deployment:" transaction-hash)
|
||||
(when-let [receipt (eth/get-transaction-receipt transaction-hash)]
|
||||
(log/info "transaction receipt for issue #" issue-id ": " receipt)
|
||||
(when-let [contract-address (:contractAddress receipt)]
|
||||
(when-let [contract-address (multisig/find-created-multisig-address receipt)]
|
||||
(let [issue (issues/update-contract-address issue-id contract-address)
|
||||
{owner :owner
|
||||
repo :repo
|
||||
|
@ -46,7 +47,7 @@
|
|||
|
||||
|
||||
(defn deploy-contract [owner-address issue-id]
|
||||
(let [transaction-hash (wallet/deploy-multisig owner-address)]
|
||||
(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:"
|
||||
|
@ -88,7 +89,7 @@
|
|||
:let [value (eth/get-balance-hex contract-address)]]
|
||||
(if (empty? payout-address)
|
||||
(log/error "Cannot sign pending bounty - winner has no payout address")
|
||||
(let [execute-hash (wallet/send-all contract-address payout-address)]
|
||||
(let [execute-hash (multisig/send-all contract-address payout-address)]
|
||||
(db-bounties/update-execute-hash issue-id execute-hash)
|
||||
(github/update-merged-issue-comment owner
|
||||
repo
|
||||
|
@ -105,7 +106,7 @@
|
|||
(log/debug "pending payout:" execute-hash)
|
||||
(when-let [receipt (eth/get-transaction-receipt execute-hash)]
|
||||
(log/info "execution receipt for issue #" issue-id ": " receipt)
|
||||
(when-let [confirm-hash (wallet/find-confirmation-hash receipt)]
|
||||
(when-let [confirm-hash (multisig/find-confirmation-hash receipt)]
|
||||
(db-bounties/update-confirm-hash issue-id confirm-hash)))))
|
||||
|
||||
(defn update-payout-receipt
|
||||
|
@ -181,6 +182,21 @@
|
|||
current-balance-eth-str))))))
|
||||
|
||||
|
||||
(defn update-bounty-token-balances
|
||||
"Helper function for updating internal ERC20 token balances to token multisig contract. Will be called periodically for all open bounty contracts."
|
||||
[bounty-addr]
|
||||
(for [[tla token-data] (token-data/as-map)]
|
||||
(let [balance (multisig/token-balance bounty-addr tla)]
|
||||
(when (> balance 0)
|
||||
(do
|
||||
(println "bounty at" bounty-addr "has" balance "of tla" tla)
|
||||
(let [internal-balance (multisig/token-balance-in-bounty bounty-addr tla)]
|
||||
(when (not= balance internal-balance)
|
||||
(println "balances not in sync, calling watch")
|
||||
(multisig/watch-token bounty-addr tla))))))))
|
||||
|
||||
|
||||
|
||||
(defn run-periodic-tasks [time]
|
||||
(do
|
||||
(log/debug "run-periodic-tasks" time)
|
||||
|
|
Loading…
Reference in New Issue