Update etherscan context transactions list to use created_contract_address_hash from transaction

pull/501/head
Stamates 6 years ago
parent 5a54caecb7
commit d7fd7d27fb
  1. 23
      apps/explorer/lib/explorer/etherscan.ex
  2. 16
      apps/explorer/test/explorer/etherscan_test.exs

@ -45,20 +45,21 @@ defmodule Explorer.Etherscan do
end end
@transaction_fields [ @transaction_fields [
:block_number,
:hash,
:nonce,
:block_hash, :block_hash,
:index, :block_number,
:created_contract_address_hash,
:cumulative_gas_used,
:from_address_hash, :from_address_hash,
:to_address_hash,
:value,
:gas, :gas,
:gas_price, :gas_price,
:status, :gas_used,
:hash,
:index,
:input, :input,
:cumulative_gas_used, :nonce,
:gas_used :status,
:to_address_hash,
:value
] ]
defp list_transactions(address_hash, max_block_number, options) do defp list_transactions(address_hash, max_block_number, options) do
@ -66,17 +67,15 @@ defmodule Explorer.Etherscan do
from( from(
t in Transaction, t in Transaction,
inner_join: b in assoc(t, :block), inner_join: b in assoc(t, :block),
left_join: it in assoc(t, :internal_transactions),
where: t.to_address_hash == ^address_hash, where: t.to_address_hash == ^address_hash,
or_where: t.from_address_hash == ^address_hash, or_where: t.from_address_hash == ^address_hash,
or_where: it.transaction_hash == t.hash and it.type == ^"create", or_where: t.created_contract_address_hash == ^address_hash,
order_by: [{^options.order_by_direction, t.block_number}], order_by: [{^options.order_by_direction, t.block_number}],
limit: ^options.page_size, limit: ^options.page_size,
offset: ^offset(options), offset: ^offset(options),
select: select:
merge(map(t, ^@transaction_fields), %{ merge(map(t, ^@transaction_fields), %{
block_timestamp: b.timestamp, block_timestamp: b.timestamp,
created_contract_address_hash: it.created_contract_address_hash,
confirmations: fragment("? - ?", ^max_block_number, t.block_number) confirmations: fragment("? - ?", ^max_block_number, t.block_number)
}) })
) )

@ -54,14 +54,18 @@ defmodule Explorer.EtherscanTest do
test "with created contract address" do test "with created contract address" do
address = insert(:address) address = insert(:address)
contract_address = insert(:contract_address)
transaction = transaction =
:transaction :transaction
|> insert(from_address: address) |> insert(from_address: address, to_address: nil)
|> with_contract_creation(contract_address)
|> with_block() |> with_block()
%{created_contract_address_hash: contract_address_hash} = %{created_contract_address_hash: contract_address_hash} =
insert(:internal_transaction_create, transaction: transaction, index: 0) :internal_transaction_create
|> insert(transaction: transaction, index: 0)
|> with_contract_creation(contract_address)
[found_transaction] = Etherscan.list_transactions(contract_address_hash) [found_transaction] = Etherscan.list_transactions(contract_address_hash)
@ -121,14 +125,18 @@ defmodule Explorer.EtherscanTest do
test "loads created_contract_address_hash if available" do test "loads created_contract_address_hash if available" do
address = insert(:address) address = insert(:address)
contract_address = insert(:contract_address)
transaction = transaction =
:transaction :transaction
|> insert(from_address: address) |> insert(from_address: address, to_address: nil)
|> with_contract_creation(contract_address)
|> with_block() |> with_block()
%{created_contract_address_hash: contract_hash} = %{created_contract_address_hash: contract_hash} =
insert(:internal_transaction_create, transaction: transaction, index: 0) :internal_transaction_create
|> insert(transaction: transaction, index: 0)
|> with_contract_creation(contract_address)
[found_transaction] = Etherscan.list_transactions(address.hash) [found_transaction] = Etherscan.list_transactions(address.hash)

Loading…
Cancel
Save