Skip to content

Commit

Permalink
Merge pull request blockscout#1451 from poanetwork/ab-do-not-try-to-c…
Browse files Browse the repository at this point in the history
…onvert-nil-in-logs

do not try to convert nils in logs
  • Loading branch information
acravenho authored Feb 19, 2019
2 parents e975525 + b091eaf commit 845f0bd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/log.ex
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ defmodule EthereumJSONRPC.Log do
do: entry

defp entry_to_elixir({key, quantity}) when key in ~w(blockNumber logIndex transactionIndex transactionLogIndex) do
{key, quantity_to_integer(quantity)}
if is_nil(quantity) do
{key, nil}
else
{key, quantity_to_integer(quantity)}
end
end

defp put_topics(params, topics) when is_map(params) and is_list(topics) do
Expand Down
27 changes: 27 additions & 0 deletions apps/ethereum_jsonrpc/test/ethereum_jsonrpc/log_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,31 @@ defmodule EthereumJSONRPC.LogTest do
use ExUnit.Case, async: true

doctest EthereumJSONRPC.Log

alias EthereumJSONRPC.Log

describe "to_elixir/1" do
test "does not tries convert nils to integer" do
input = %{
"address" => "0xda8b3276cde6d768a44b9dac659faa339a41ac55",
"blockHash" => nil,
"blockNumber" => nil,
"data" => "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563",
"logIndex" => "0x0",
"removed" => false,
"topics" => [
"0xadc1e8a294f8415511303acc4a8c0c5906c7eb0bf2a71043d7f4b03b46a39130",
"0x000000000000000000000000c15bf627accd3b054075c7880425f903106be72a",
"0x000000000000000000000000a59eb37750f9c8f2e11aac6700e62ef89187e4ed"
],
"transactionHash" => "0xf9b663b4e9b1fdc94eb27b5cfba04eb03d2f7b3fa0b24eb2e1af34f823f2b89e",
"transactionIndex" => "0x0"
}

result = Log.to_elixir(input)

assert result["blockNumber"] == nil
assert result["blockHash"] == nil
end
end
end

0 comments on commit 845f0bd

Please sign in to comment.