From 87effb5f6cdbe5c6f1531fe9c07df13302004826 Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Fri, 18 Aug 2017 21:49:04 +0300 Subject: [PATCH] eth.core improvements * add conversion func for (big)int -> hex string * use integer instead of hex string for gas-price --- src/clj/commiteth/eth/core.clj | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/clj/commiteth/eth/core.clj b/src/clj/commiteth/eth/core.clj index 416c03e..0222235 100644 --- a/src/clj/commiteth/eth/core.clj +++ b/src/clj/commiteth/eth/core.clj @@ -11,7 +11,12 @@ (defn eth-rpc-url [] (env :eth-rpc-url "http://localhost:8545")) (defn eth-account [] (:eth-account env)) (defn eth-password [] (:eth-password env)) -(defn gas-price [] (:gas-price env)) + +(defn gas-price + [] + (-> (:gas-price env 2000000000) + str + BigInteger.)) (defn eth-rpc [method params] @@ -43,6 +48,11 @@ [hex] (new BigInteger (subs hex 2) 16)) +(defn integer->hex + "Convert integer to 0x prefixed hex string. Works with native ints and BigInteger" + [n] + (str "0x" (.toString (BigInteger. (str n)) 16))) + (defn from-wei [wei] (/ wei 1000000000000000000)) @@ -70,7 +80,7 @@ {:from from :value value} (when-not (nil? (gas-price)) - {:gasPrice (gas-price)}) + {:gasPrice (integer->hex gas-price)}) (when-not (contains? params :gas) {:gas (estimate-gas from to value params)}))]