From d7fd7d27fb9a4c5e02e69b37e426aa120fd5ecb4 Mon Sep 17 00:00:00 2001 From: Stamates Date: Fri, 3 Aug 2018 15:28:06 -0400 Subject: [PATCH] Update etherscan context transactions list to use created_contract_address_hash from transaction --- apps/explorer/lib/explorer/etherscan.ex | 23 +++++++++---------- .../explorer/test/explorer/etherscan_test.exs | 16 +++++++++---- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/apps/explorer/lib/explorer/etherscan.ex b/apps/explorer/lib/explorer/etherscan.ex index a480a8ee23..e8cdd3ea18 100644 --- a/apps/explorer/lib/explorer/etherscan.ex +++ b/apps/explorer/lib/explorer/etherscan.ex @@ -45,20 +45,21 @@ defmodule Explorer.Etherscan do end @transaction_fields [ - :block_number, - :hash, - :nonce, :block_hash, - :index, + :block_number, + :created_contract_address_hash, + :cumulative_gas_used, :from_address_hash, - :to_address_hash, - :value, :gas, :gas_price, - :status, + :gas_used, + :hash, + :index, :input, - :cumulative_gas_used, - :gas_used + :nonce, + :status, + :to_address_hash, + :value ] defp list_transactions(address_hash, max_block_number, options) do @@ -66,17 +67,15 @@ defmodule Explorer.Etherscan do from( t in Transaction, inner_join: b in assoc(t, :block), - left_join: it in assoc(t, :internal_transactions), where: t.to_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}], limit: ^options.page_size, offset: ^offset(options), select: merge(map(t, ^@transaction_fields), %{ block_timestamp: b.timestamp, - created_contract_address_hash: it.created_contract_address_hash, confirmations: fragment("? - ?", ^max_block_number, t.block_number) }) ) diff --git a/apps/explorer/test/explorer/etherscan_test.exs b/apps/explorer/test/explorer/etherscan_test.exs index 99828632ec..aaa32d742d 100644 --- a/apps/explorer/test/explorer/etherscan_test.exs +++ b/apps/explorer/test/explorer/etherscan_test.exs @@ -54,14 +54,18 @@ defmodule Explorer.EtherscanTest do test "with created contract address" do address = insert(:address) + contract_address = insert(:contract_address) transaction = :transaction - |> insert(from_address: address) + |> insert(from_address: address, to_address: nil) + |> with_contract_creation(contract_address) |> with_block() %{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) @@ -121,14 +125,18 @@ defmodule Explorer.EtherscanTest do test "loads created_contract_address_hash if available" do address = insert(:address) + contract_address = insert(:contract_address) transaction = :transaction - |> insert(from_address: address) + |> insert(from_address: address, to_address: nil) + |> with_contract_creation(contract_address) |> with_block() %{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)