From 4705b6619aa1e35f1ca1cb810844b05f675bac76 Mon Sep 17 00:00:00 2001 From: Martin Klepsch Date: Fri, 13 Apr 2018 13:24:03 +0200 Subject: [PATCH] log eth-rpc results + different req-id approach --- src/clj/commiteth/eth/core.clj | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/clj/commiteth/eth/core.clj b/src/clj/commiteth/eth/core.clj index 4db60c1..b172592 100644 --- a/src/clj/commiteth/eth/core.clj +++ b/src/clj/commiteth/eth/core.clj @@ -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