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 (`[]`).
pull/384/head
Luke Imhoff 6 years ago
parent 466c1e76f6
commit 3d1aa20287
  1. 6
      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)

Loading…
Cancel
Save