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.
pull/1829/head
goodsoft 6 years ago
parent f3fdd4e348
commit 7a6c60ddeb
No known key found for this signature in database
GPG Key ID: DF5159A3A5F09D21
  1. 7
      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

Loading…
Cancel
Save