Use random json-rpc request IDs
* use a random 0-4096 int for json-rpc request ID and ensure reponse has the same ID (may solve #32))
This commit is contained in:
parent
01f1bffd77
commit
cb3feeeec3
|
@ -14,18 +14,23 @@
|
||||||
|
|
||||||
(defn eth-rpc
|
(defn eth-rpc
|
||||||
[method params]
|
[method params]
|
||||||
(let [body (json/write-str {:jsonrpc "2.0"
|
(let [request-id (rand-int 4096)
|
||||||
|
body (json/write-str {:jsonrpc "2.0"
|
||||||
:method method
|
:method method
|
||||||
:params params
|
:params params
|
||||||
:id 1})
|
:id request-id})
|
||||||
options {:headers {"content-type" "application/json"}
|
options {:headers {"content-type" "application/json"}
|
||||||
:body body}
|
:body body}
|
||||||
response (:body @(post eth-rpc-url options))
|
response (:body @(post eth-rpc-url options))
|
||||||
result (json/read-str response :key-fn keyword)]
|
result (json/read-str response :key-fn keyword)]
|
||||||
(log/debug body "\n" result)
|
(log/debug body "\n" result)
|
||||||
(when-let [error (:error result)]
|
(if (= (:id result) request-id)
|
||||||
(log/error "Method: " method ", error: " error))
|
(:result result)
|
||||||
(:result result)))
|
(do
|
||||||
|
(log/error "Geth returned an invalid json-rpc request ID,"
|
||||||
|
"ignoring response")
|
||||||
|
(when-let [error (:error result)]
|
||||||
|
(log/error "Method: " method ", error: " error))))))
|
||||||
|
|
||||||
(defn estimate-gas
|
(defn estimate-gas
|
||||||
[from to value & [params]]
|
[from to value & [params]]
|
||||||
|
|
Loading…
Reference in New Issue