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."
|
||||||
|
([]
|
||||||
|
(load-parity-tokenreg-data PARITY-MAINNET-ADDR))
|
||||||
|
([addr]
|
||||||
|
(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)
|
||||||
|
(into {}
|
||||||
|
(map (fn [[addr tla digits name owner]]
|
||||||
|
[(-> tla str keyword)
|
||||||
|
{:tla (str tla)
|
||||||
|
:name (str name)
|
||||||
|
:base (.getValue digits)
|
||||||
|
:address (str addr)
|
||||||
|
:owner (str owner)}])
|
||||||
|
(for [i (range token-count)]
|
||||||
|
(-> (.token contract
|
||||||
|
(org.web3j.abi.datatypes.generated.Uint256. i))
|
||||||
|
.get))))))))
|
||||||
|
|
||||||
|
(defn deploy-parity-tokenreg
|
||||||
|
"Deploy an instance of parity token-registry to current network"
|
||||||
[]
|
[]
|
||||||
(let [contract (load-tokenreg-contract)]
|
(let [web3j (create-web3j)]
|
||||||
(assert (.isValid contract))
|
(TokenReg/deploy web3j
|
||||||
(let [token-count (-> contract .tokenCount .get .getValue)]
|
(creds)
|
||||||
(println "token-count" token-count)
|
(eth/gas-price)
|
||||||
(into {}
|
(BigInteger/valueOf 4000000) ;; gas limit
|
||||||
(map (fn [[addr mnemonic digits name owner]]
|
BigInteger/ZERO)))
|
||||||
[(-> mnemonic .toString (keyword))
|
|
||||||
{:name (.toString name)
|
|
||||||
:digits (.getValue digits)
|
|
||||||
:address (.toString addr)
|
|
||||||
:owner (.toString owner)}])
|
|
||||||
(for [i (range token-count)]
|
|
||||||
(-> (.token contract
|
|
||||||
(org.web3j.abi.datatypes.generated.Uint256. i))
|
|
||||||
.get)))))))
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue