fix joining

pull/2888/head
Ayrat Badykov 5 years ago
parent 8aa55932f7
commit 5ad684dc5e
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 7
      apps/explorer/lib/explorer/etherscan.ex
  2. 7
      apps/explorer/test/explorer/etherscan_test.exs

@ -8,7 +8,7 @@ defmodule Explorer.Etherscan do
alias Explorer.Etherscan.Logs
alias Explorer.{Chain, Repo}
alias Explorer.Chain.Address.TokenBalance
alias Explorer.Chain.{Block, Hash, InternalTransaction, Transaction}
alias Explorer.Chain.{Block, Hash, InternalTransaction, TokenTransfer, Transaction}
@default_options %{
order_by_direction: :desc,
@ -318,10 +318,11 @@ defmodule Explorer.Etherscan do
query =
from(
t in Transaction,
inner_join: tt in assoc(t, :token_transfers),
inner_join: tt in TokenTransfer,
on: tt.transaction_hash == t.hash and tt.block_number == t.block_number and tt.block_hash == t.block_hash,
inner_join: tkn in assoc(tt, :token),
inner_join: b in assoc(t, :block),
where: tt.from_address_hash == ^address_hash and b.number == tt.block_number and b.hash == t.block_hash,
where: tt.from_address_hash == ^address_hash,
or_where: tt.to_address_hash == ^address_hash,
order_by: [{^options.order_by_direction, t.block_number}],
limit: ^options.page_size,

@ -846,7 +846,12 @@ defmodule Explorer.EtherscanTest do
|> insert()
|> with_block()
token_transfer = insert(:token_transfer, transaction: transaction)
token_transfer =
insert(:token_transfer,
transaction: transaction,
block: transaction.block,
block_number: transaction.block_number
)
[found_token_transfer] = Etherscan.list_token_transfers(token_transfer.to_address_hash, nil)

Loading…
Cancel
Save