Merge pull request #1581 from poanetwork/ab-creates-param

consider `creates` param when fetching transactions
pull/1597/head
Victor Baranov 6 years ago committed by GitHub
commit 504c0995bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 42
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex
  2. 3
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transactions.ex
  3. 9
      apps/indexer/lib/indexer/block/fetcher/receipts.ex

@ -149,23 +149,25 @@ defmodule EthereumJSONRPC.Transaction do
elixir_to_params(%{transaction | "input" => "0x"})
end
def elixir_to_params(%{
"blockHash" => block_hash,
"blockNumber" => block_number,
"from" => from_address_hash,
"gas" => gas,
"gasPrice" => gas_price,
"hash" => hash,
"input" => input,
"nonce" => nonce,
"r" => r,
"s" => s,
"to" => to_address_hash,
"transactionIndex" => index,
"v" => v,
"value" => value
}) do
%{
def elixir_to_params(
%{
"blockHash" => block_hash,
"blockNumber" => block_number,
"from" => from_address_hash,
"gas" => gas,
"gasPrice" => gas_price,
"hash" => hash,
"input" => input,
"nonce" => nonce,
"r" => r,
"s" => s,
"to" => to_address_hash,
"transactionIndex" => index,
"v" => v,
"value" => value
} = transaction
) do
result = %{
block_hash: block_hash,
block_number: block_number,
from_address_hash: from_address_hash,
@ -182,6 +184,12 @@ defmodule EthereumJSONRPC.Transaction do
value: value,
transaction_index: index
}
if transaction["creates"] do
Map.put(result, :created_contract_address_hash, transaction["creates"])
else
result
end
end
# Ganache bug. it return `to: "0x0"` except of `to: null`

@ -56,7 +56,8 @@ defmodule EthereumJSONRPC.Transactions do
to_address_hash: nil,
v: "0xbd",
value: 0,
transaction_index: 0
transaction_index: 0,
created_contract_address_hash: "0xffc87239eb0267bc3ca2cd51d12fbf278e02ccb4"
}
]

@ -42,7 +42,14 @@ defmodule Indexer.Block.Fetcher.Receipts do
end)
Enum.map(transactions_params, fn %{hash: transaction_hash} = transaction_params ->
Map.merge(transaction_params, Map.fetch!(transaction_hash_to_receipt_params, transaction_hash))
receipts_params = Map.fetch!(transaction_hash_to_receipt_params, transaction_hash)
merged_params = Map.merge(transaction_params, receipts_params)
if transaction_params[:created_contract_address_hash] && is_nil(receipts_params[:created_contract_address_hash]) do
Map.put(merged_params, :created_contract_address_hash, transaction_params[:created_contract_address_hash])
else
merged_params
end
end)
end

Loading…
Cancel
Save