diff --git a/lib/explorer/importers/block_importer.ex b/lib/explorer/importers/block_importer.ex index 13c5b56ed4..e980ee693c 100644 --- a/lib/explorer/importers/block_importer.ex +++ b/lib/explorer/importers/block_importer.ex @@ -38,7 +38,9 @@ defmodule Explorer.BlockImporter do @dialyzer {:nowarn_function, download_block: 1} def download_block(block_number) do - {:ok, block} = eth_get_block_by_number(block_number, true) + {:ok, block} = block_number + |> encode_number() + |> eth_get_block_by_number(true) block end @@ -58,6 +60,17 @@ defmodule Explorer.BlockImporter do } end + defp encode_number("latest"), do: "latest" + defp encode_number("earliest"), do: "earliest" + defp encode_number("pending"), do: "pending" + defp encode_number(number) when is_binary(number) do + number + |> String.to_integer() + |> encode_number() + end + + defp encode_number(number), do: "0x" <> Integer.to_string(number, 16) + def decode_integer_field(hex) do {"0x", base_16} = String.split_at(hex, 2) String.to_integer(base_16, 16)