Read data from parity token registry + fix build

* read data from parity's mainnet token registry contract to a clojure
  map
This commit is contained in:
Teemu Patja 2017-08-19 12:44:32 +03:00
parent ec2e49601d
commit c647e4afd4
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
3 changed files with 372 additions and 2 deletions

View File

@ -57,7 +57,7 @@
:java-source-paths ["src/java"]
:target-path "target/%s/"
:repositories {"MVN repository" "https://mvnrepository.com"}
:main commiteth.core
:main ^:skip-aot commiteth.core
:migratus {:store :database
:migration-dir "migrations"
:db ~(get (System/getenv) "DATABASE_URL")}
@ -88,7 +88,6 @@
:profiles
{:uberjar {:omit-source true
:prep-tasks ["compile" ["cljsbuild" "once" "min"]]
:cljsbuild
{:builds
{:min

View File

@ -0,0 +1,56 @@
(ns commiteth.eth.token-registry
(:require [commiteth.eth.core :as eth]
[commiteth.config :refer [env]])
(:import [org.web3j
abi.datatypes.generated.Uint256
protocol.Web3j
protocol.http.HttpService
crypto.Credentials
crypto.WalletUtils]
commiteth.contracts.TokenReg))
(defonce PARITY-TOKENREG-ADDR "0x5f0281910af44bfb5fc7e86a404d0304b0e042f1")
(defonce GAS_PRICE (eth/gas-price))
(defonce GAS_LIMIT (BigInteger/valueOf 21000))
(defn wallet-file-path []
(env :eth-wallet-file))
(defn wallet-password []
(env :eth-password))
(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)
(creds)
GAS_PRICE
GAS_LIMIT))
(defn load-parity-tokenreg-data
"Construct a mapping of ERC20 token mnemonic -> token data (name, address, digits, owner) from data
in Parity's mainnet token registry contract."
[]
(let [contract (load-tokenreg-contract)]
(assert (.isValid contract))
(let [token-count (-> contract .tokenCount .get .getValue)]
(println "token-count" token-count)
(into {}
(map (fn [[addr mnemonic digits name owner]]
[(-> 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