From 7a6c60ddeb93eb43a5d318c609a775e63dc7905b Mon Sep 17 00:00:00 2001 From: goodsoft Date: Wed, 24 Apr 2019 18:33:37 +0300 Subject: [PATCH] Handle nil quantities in block decoding routine Uncle block fetched using eth_getUncleByBlockHashAndIndex API may have null in their size field. We shouldn't crash in this case. --- apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block.ex index b2f3a87fcd..116232f999 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block.ex @@ -435,10 +435,15 @@ defmodule EthereumJSONRPC.Block do end defp entry_to_elixir({key, quantity}) - when key in ~w(difficulty gasLimit gasUsed minimumGasPrice number size totalDifficulty) do + when key in ~w(difficulty gasLimit gasUsed minimumGasPrice number size totalDifficulty) and not is_nil(quantity) do {key, quantity_to_integer(quantity)} end + # Size may be `nil` for uncle blocks + defp entry_to_elixir({key, nil}) when key in ~w(size) do + {key, nil} + end + # double check that no new keys are being missed by requiring explicit match for passthrough # `t:EthereumJSONRPC.address/0` and `t:EthereumJSONRPC.hash/0` pass through as `Explorer.Chain` can verify correct # hash format