Merge pull request #4862 from blockscout/np-fix-internal-txs-pagination

Fix internal txs pagination
pull/5197/head
Victor Baranov 3 years ago committed by GitHub
commit 9c3cc37b71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 52
      apps/explorer/lib/explorer/chain.ex
  3. 14
      apps/explorer/test/explorer/chain_test.exs

@ -18,6 +18,7 @@
- [#5160](https://github.com/blockscout/blockscout/pull/5160) - Fix blocks validated hint
- [#5155](https://github.com/blockscout/blockscout/pull/5155) - Fix get_implementation_abi_from_proxy/2 implementation
- [#5154](https://github.com/blockscout/blockscout/pull/5154) - Fix token counters bug
- [#4862](https://github.com/blockscout/blockscout/pull/4862) - Fix internal transactions pagination
### Chore
- [#5202](https://github.com/blockscout/blockscout/pull/5202) - Docker setup Makefile release/publish tasks

@ -297,7 +297,7 @@ defmodule Explorer.Chain do
query
|> InternalTransaction.where_is_different_from_parent_transaction()
|> InternalTransaction.where_block_number_is_not_null()
|> page_internal_transaction(paging_options)
|> page_internal_transaction(paging_options, %{index_int_tx_desc_order: true})
|> limit(^paging_options.page_size)
|> order_by(
[it],
@ -4473,24 +4473,48 @@ defmodule Explorer.Chain do
where(query, [coin_balance], coin_balance.block_number < ^block_number)
end
defp page_internal_transaction(query, %PagingOptions{key: nil}), do: query
defp page_internal_transaction(_, _, _ \\ %{index_int_tx_desc_order: false})
defp page_internal_transaction(query, %PagingOptions{key: {block_number, transaction_index, index}}) do
where(
query,
[internal_transaction],
internal_transaction.block_number < ^block_number or
(internal_transaction.block_number == ^block_number and
internal_transaction.transaction_index < ^transaction_index) or
(internal_transaction.block_number == ^block_number and
internal_transaction.transaction_index == ^transaction_index and internal_transaction.index < ^index)
)
defp page_internal_transaction(query, %PagingOptions{key: nil}, _), do: query
defp page_internal_transaction(query, %PagingOptions{key: {block_number, transaction_index, index}}, %{
index_int_tx_desc_order: desc
}) do
hardcoded_where_for_page_int_tx(query, block_number, transaction_index, index, desc)
end
defp page_internal_transaction(query, %PagingOptions{key: {index}}) do
where(query, [internal_transaction], internal_transaction.index > ^index)
defp page_internal_transaction(query, %PagingOptions{key: {index}}, %{index_int_tx_desc_order: desc}) do
if desc do
where(query, [internal_transaction], internal_transaction.index < ^index)
else
where(query, [internal_transaction], internal_transaction.index > ^index)
end
end
defp hardcoded_where_for_page_int_tx(query, block_number, transaction_index, index, false),
do:
where(
query,
[internal_transaction],
internal_transaction.block_number < ^block_number or
(internal_transaction.block_number == ^block_number and
internal_transaction.transaction_index < ^transaction_index) or
(internal_transaction.block_number == ^block_number and
internal_transaction.transaction_index == ^transaction_index and internal_transaction.index > ^index)
)
defp hardcoded_where_for_page_int_tx(query, block_number, transaction_index, index, true),
do:
where(
query,
[internal_transaction],
internal_transaction.block_number < ^block_number or
(internal_transaction.block_number == ^block_number and
internal_transaction.transaction_index < ^transaction_index) or
(internal_transaction.block_number == ^block_number and
internal_transaction.transaction_index == ^transaction_index and internal_transaction.index < ^index)
)
defp page_logs(query, %PagingOptions{key: nil}), do: query
defp page_logs(query, %PagingOptions{key: {index}}) do

@ -2710,7 +2710,7 @@ defmodule Explorer.ChainTest do
transaction_index: transaction.index
)
%InternalTransaction{transaction_hash: second_transaction_hash, index: second_index} =
%InternalTransaction{transaction_hash: transaction_hash_1, index: index_1} =
insert(:internal_transaction,
transaction: transaction,
index: 1,
@ -2720,13 +2720,23 @@ defmodule Explorer.ChainTest do
transaction_index: transaction.index
)
%InternalTransaction{transaction_hash: transaction_hash_2, index: index_2} =
insert(:internal_transaction,
transaction: transaction,
index: 2,
block_number: transaction.block_number,
block_hash: transaction.block_hash,
block_index: 2,
transaction_index: transaction.index
)
result =
transaction.hash
|> Chain.transaction_to_internal_transactions()
|> Enum.map(&{&1.transaction_hash, &1.index})
# excluding of internal transactions with type=call and index=0
assert [{second_transaction_hash, second_index}] == result
assert [{transaction_hash_1, index_1}, {transaction_hash_2, index_2}] == result
end
test "pages by index" do

Loading…
Cancel
Save