TokenReg clojure support improvements
* allow loading of parity tokenreg contract data from any address, including our own test instance * use tokenreg data from config.edn for testnet only when availaned, otherwise from our smart contract on rinkeby * clean up + refactoring * remove generated java wrapper for parity tokenreg contract
This commit is contained in:
parent
270dd3e277
commit
5f6ad85011
|
@ -13,8 +13,11 @@
|
||||||
(log/info "token-data started")
|
(log/info "token-data started")
|
||||||
(let [token-data
|
(let [token-data
|
||||||
(if (env :on-testnet true)
|
(if (env :on-testnet true)
|
||||||
(env :testnet-token-data {})
|
(if-let [token-data (env :testnet-token-data)]
|
||||||
(token-reg/load-parity-tokenreg-data))]
|
token-data
|
||||||
|
(token-reg/load-parity-tokenreg-data token-reg/STATUS-RINKEBY-ADDR))
|
||||||
|
|
||||||
|
(token-reg/load-parity-tokenreg-data token-reg/PARITY-MAINNET-ADDR))]
|
||||||
(reset! token-data-atom token-data)))
|
(reset! token-data-atom token-data)))
|
||||||
:stop
|
:stop
|
||||||
(log/info "token-data stopped"))
|
(log/info "token-data stopped"))
|
||||||
|
@ -22,5 +25,5 @@
|
||||||
(defn as-map []
|
(defn as-map []
|
||||||
@token-data-atom)
|
@token-data-atom)
|
||||||
|
|
||||||
(defn token-info [mnemonic]
|
(defn token-info [tla]
|
||||||
(get @token-data-atom (keyword mnemonic)))
|
(get @token-data-atom (keyword tla)))
|
||||||
|
|
|
@ -1,56 +1,59 @@
|
||||||
(ns commiteth.eth.token-registry
|
(ns commiteth.eth.token-registry
|
||||||
(:require [commiteth.eth.core :as eth]
|
(:require [commiteth.eth.core :as eth]
|
||||||
|
[commiteth.eth.web3j
|
||||||
|
:refer [create-web3j creds]]
|
||||||
[commiteth.config :refer [env]])
|
[commiteth.config :refer [env]])
|
||||||
(:import [org.web3j
|
(:import [org.web3j
|
||||||
abi.datatypes.generated.Uint256
|
abi.datatypes.generated.Uint256
|
||||||
|
abi.datatypes.Address
|
||||||
|
abi.datatypes.Utf8String
|
||||||
protocol.Web3j
|
protocol.Web3j
|
||||||
protocol.http.HttpService
|
protocol.http.HttpService
|
||||||
crypto.Credentials
|
crypto.Credentials
|
||||||
crypto.WalletUtils]
|
crypto.WalletUtils]
|
||||||
commiteth.contracts.TokenReg))
|
commiteth.eth.contracts.TokenReg))
|
||||||
|
|
||||||
(defonce PARITY-TOKENREG-ADDR "0x5f0281910af44bfb5fc7e86a404d0304b0e042f1")
|
(defonce PARITY-MAINNET-ADDR "0x5f0281910af44bfb5fc7e86a404d0304b0e042f1")
|
||||||
(defonce GAS_PRICE (eth/gas-price))
|
(defonce STATUS-RINKEBY-ADDR "0x4826Ee32532EeA00Bb71C17Da491f1B2D2193C21")
|
||||||
(defonce GAS_LIMIT (BigInteger/valueOf 21000))
|
|
||||||
|
|
||||||
(defn wallet-file-path []
|
|
||||||
(env :eth-wallet-file))
|
|
||||||
|
|
||||||
(defn wallet-password []
|
(defn- load-tokenreg-contract [addr]
|
||||||
(env :eth-password))
|
(TokenReg/load addr
|
||||||
|
|
||||||
(defn creds []
|
|
||||||
(WalletUtils/loadCredentials
|
|
||||||
(wallet-password)
|
|
||||||
(wallet-file-path)))
|
|
||||||
|
|
||||||
(defn create-web3j []
|
|
||||||
(Web3j/build (HttpService. (eth/eth-rpc-url))))
|
|
||||||
|
|
||||||
(defn load-tokenreg-contract []
|
|
||||||
(TokenReg/load PARITY-TOKENREG-ADDR
|
|
||||||
(create-web3j)
|
(create-web3j)
|
||||||
(creds)
|
(creds)
|
||||||
GAS_PRICE
|
(eth/gas-price)
|
||||||
GAS_LIMIT))
|
(BigInteger/valueOf 21000)))
|
||||||
|
|
||||||
|
|
||||||
(defn load-parity-tokenreg-data
|
(defn load-parity-tokenreg-data
|
||||||
"Construct a mapping of ERC20 token mnemonic -> token data (name, address, digits, owner) from data
|
"Construct a mapping of ERC20 token mnemonic -> token data (name, address, digits, owner) from data
|
||||||
in Parity's mainnet token registry contract."
|
in Parity's mainnet token registry contract."
|
||||||
[]
|
([]
|
||||||
(let [contract (load-tokenreg-contract)]
|
(load-parity-tokenreg-data PARITY-MAINNET-ADDR))
|
||||||
(assert (.isValid contract))
|
([addr]
|
||||||
|
(let [contract (load-tokenreg-contract addr)]
|
||||||
|
;(assert (.isValid contract)) ;; web3j's isValid can't be trusted...
|
||||||
(let [token-count (-> contract .tokenCount .get .getValue)]
|
(let [token-count (-> contract .tokenCount .get .getValue)]
|
||||||
(println "token-count" token-count)
|
(println "token-count" token-count)
|
||||||
(into {}
|
(into {}
|
||||||
(map (fn [[addr mnemonic digits name owner]]
|
(map (fn [[addr tla digits name owner]]
|
||||||
[(-> mnemonic .toString (keyword))
|
[(-> tla str keyword)
|
||||||
{:name (.toString name)
|
{:tla (str tla)
|
||||||
:digits (.getValue digits)
|
:name (str name)
|
||||||
:address (.toString addr)
|
:base (.getValue digits)
|
||||||
:owner (.toString owner)}])
|
:address (str addr)
|
||||||
|
:owner (str owner)}])
|
||||||
(for [i (range token-count)]
|
(for [i (range token-count)]
|
||||||
(-> (.token contract
|
(-> (.token contract
|
||||||
(org.web3j.abi.datatypes.generated.Uint256. i))
|
(org.web3j.abi.datatypes.generated.Uint256. i))
|
||||||
.get)))))))
|
.get))))))))
|
||||||
|
|
||||||
|
(defn deploy-parity-tokenreg
|
||||||
|
"Deploy an instance of parity token-registry to current network"
|
||||||
|
[]
|
||||||
|
(let [web3j (create-web3j)]
|
||||||
|
(TokenReg/deploy web3j
|
||||||
|
(creds)
|
||||||
|
(eth/gas-price)
|
||||||
|
(BigInteger/valueOf 4000000) ;; gas limit
|
||||||
|
BigInteger/ZERO)))
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue