log eth-rpc results + different req-id approach

This commit is contained in:
Martin Klepsch 2018-04-13 13:24:03 +02:00
parent 2df66222fc
commit 4705b6619a
No known key found for this signature in database
GPG Key ID: 1A35E702AD48A9F6

View File

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