From cb3feeeec365906ef2e910d70c99c9c4a087aacd Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Fri, 10 Mar 2017 20:19:35 +0200 Subject: [PATCH] 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)) --- src/clj/commiteth/eth/core.clj | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/clj/commiteth/eth/core.clj b/src/clj/commiteth/eth/core.clj index 7c0dfc3..078435b 100644 --- a/src/clj/commiteth/eth/core.clj +++ b/src/clj/commiteth/eth/core.clj @@ -14,18 +14,23 @@ (defn eth-rpc [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 :params params - :id 1}) + :id request-id}) options {:headers {"content-type" "application/json"} :body body} response (:body @(post eth-rpc-url options)) result (json/read-str response :key-fn keyword)] (log/debug body "\n" result) - (when-let [error (:error result)] - (log/error "Method: " method ", error: " error)) - (:result result))) + (if (= (:id result) request-id) + (: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 [from to value & [params]]