Handles Ganache transaction input bug

Why:

* To be able to index transactions, we need to add special handling for
a bug in Ganache in which transaction inputs are returned as invalid
`DATA` types. For details please see:
https://github.com/trufflesuite/ganache/issues/997
* Issue link: https://github.com/poanetwork/blockscout/issues/1068

This change addresses the need by:

* Editing `EthereumJSONRPC.Transaction` to convert incorrectly formatted
transaction `input`s of `0x0` to `0x`.
pull/1143/head
Sebastian Abondano 6 years ago
parent a3636c8c56
commit f0de6f4b09
  1. 44
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex

@ -103,8 +103,52 @@ defmodule EthereumJSONRPC.Transaction do
transaction_index: 0
}
Ganache bug: https://github.com/trufflesuite/ganache/issues/997
Invalid input of `0x0` is converted to `0x`.
iex> EthereumJSONRPC.Transaction.elixir_to_params(
...> %{
...> "blockHash" => "0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1bdd",
...> "blockNumber" => 46147,
...> "from" => "0xa1e4380a3b1f749673e270229993ee55f35663b4",
...> "gas" => 21000,
...> "gasPrice" => 50000000000000,
...> "hash" => "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060",
...> "input" => "0x0",
...> "nonce" => 0,
...> "r" => 61965845294689009770156372156374760022787886965323743865986648153755601564112,
...> "s" => 31606574786494953692291101914709926755545765281581808821704454381804773090106,
...> "to" => "0x5df9b87991262f6ba471f09758cde1c0fc1de734",
...> "transactionIndex" => 0,
...> "v" => 28,
...> "value" => 31337
...> }
...> )
%{
block_hash: "0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1bdd",
block_number: 46147,
from_address_hash: "0xa1e4380a3b1f749673e270229993ee55f35663b4",
gas: 21000,
gas_price: 50000000000000,
hash: "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060",
index: 0,
input: "0x",
nonce: 0,
r: 61965845294689009770156372156374760022787886965323743865986648153755601564112,
s: 31606574786494953692291101914709926755545765281581808821704454381804773090106,
to_address_hash: "0x5df9b87991262f6ba471f09758cde1c0fc1de734",
v: 28,
value: 31337,
transaction_index: 0
}
"""
@spec elixir_to_params(elixir) :: params
def elixir_to_params(%{"input" => "0x0"} = transaction) do
elixir_to_params(%{transaction | "input" => "0x"})
end
def elixir_to_params(%{
"blockHash" => block_hash,
"blockNumber" => block_number,

Loading…
Cancel
Save