From 3d1aa2028798ee49c3f7fe4cfd4889999c0ca7d1 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Mon, 9 Jul 2018 12:45:09 -0500 Subject: [PATCH] Convert empty batch to empty response list JSONRPC 2.0 standard says that an empty batch (`[]`) return an empty response (`""`), but an empty response isn't valid JSON, so instead act like it returns an empty list (`[]`). --- apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/http.ex | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/http.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/http.ex index e6792b75a2..46910857bb 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/http.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/http.ex @@ -40,6 +40,12 @@ defmodule EthereumJSONRPC.HTTP do {:ok, list} end + # JSONRPC 2.0 standard says that an empty batch (`[]`) returns an empty response (`""`), but an empty response isn't + # valid JSON, so instead act like it returns an empty list (`[]`) + defp chunked_json_rpc([[] | tail], options, decoded_response_bodies) do + chunked_json_rpc(tail, options, decoded_response_bodies) + end + defp chunked_json_rpc([[%{method: method} | _] = batch | tail] = chunks, options, decoded_response_bodies) when is_list(tail) and is_list(decoded_response_bodies) do http = Keyword.fetch!(options, :http)