From f7456db04ceea56f99d0b8132b68ec7b5a393661 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 31 Jan 2019 12:55:42 +0300 Subject: [PATCH] fix receipts for pending transactions --- apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/receipt.ex | 9 ++++++++- .../test/ethereum_jsonrpc/receipt_test.exs | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/receipt.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/receipt.ex index c050776801..0a20f4ba5d 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/receipt.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/receipt.ex @@ -258,7 +258,14 @@ defmodule EthereumJSONRPC.Receipt do defp entry_to_elixir({key, quantity}) when key in ~w(blockNumber cumulativeGasUsed gasUsed transactionIndex) do - {:ok, {key, quantity_to_integer(quantity)}} + result = + if is_nil(quantity) do + nil + else + quantity_to_integer(quantity) + end + + {:ok, {key, result}} end defp entry_to_elixir({"logs" = key, logs}) do diff --git a/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/receipt_test.exs b/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/receipt_test.exs index 38f5fa7a7a..b5ee4ae2ef 100644 --- a/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/receipt_test.exs +++ b/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/receipt_test.exs @@ -30,4 +30,11 @@ defmodule EthereumJSONRPC.ReceiptTest do assert Receipt.to_elixir(%{"status" => nil, "transactionHash" => "0x0"}) == %{"transactionHash" => "0x0"} end end + + test "leaves nil if blockNumber is nil" do + assert Receipt.to_elixir(%{"blockNumber" => nil, "transactionHash" => "0x0"}) == %{ + "transactionHash" => "0x0", + "blockNumber" => nil + } + end end