log eth-rpc results + different req-id approach

This commit is contained in:
Martin Klepsch 2018-04-13 13:24:03 +02:00
parent 5c9245810b
commit 248da65d32
No known key found for this signature in database
GPG Key ID: 1A35E702AD48A9F6
1 changed files with 13 additions and 7 deletions

View File

@ -122,18 +122,24 @@
nil)))))
(def req-id-tracker
;; HACK to ensure previous random-number approach doesn't lead to
;; unintended collisions
(atom 0))
(defn eth-rpc
[method params]
(let [request-id (rand-int 4096)
body (json/write-str {:jsonrpc "2.0"
:method method
:params params
:id request-id})
(let [request-id (swap! req-id-tracker inc)
body {:jsonrpc "2.0"
:method method
:params params
:id request-id}
options {:headers {"content-type" "application/json"}
:body body}
:body (json/write-str body)}
response @(post (eth-rpc-url) options)
result (safe-read-str (:body response))]
(log/debug body "\n" result)
(log/infof "eth-rpc req(%s) body: %s\neth-rpc req(%s) result: %s"
request-id body request-id result)
(cond
;; Ignore any responses that have mismatching request ID