Merge pull request #8969 from blockscout/mf-fix-address-transactions-sorting

Support legacy paging options for address transactions endpoint
pull/8975/head
Victor Baranov 11 months ago committed by GitHub
commit 22a2e22c4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 45
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs
  3. 3
      apps/explorer/lib/explorer/chain/transaction.ex

@ -11,6 +11,7 @@
### Fixes
- [#9013](https://github.com/blockscout/blockscout/pull/9013) - Speed up `Indexer.Fetcher.TokenInstance.LegacySanitize`
- [#8969](https://github.com/blockscout/blockscout/pull/8969) - Support legacy paging options for address transaction endpoint
- [#8955](https://github.com/blockscout/blockscout/pull/8955) - Remove daily balances updating from BlockReward fetcher
- [#8846](https://github.com/blockscout/blockscout/pull/8846) - Handle nil gas_price at address view

@ -447,6 +447,51 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
check_paginated_response(response, response_2nd_page, txs)
end
test "backward compatible with legacy paging params", %{conn: conn} do
address = insert(:address)
block = insert(:block)
txs = insert_list(51, :transaction, from_address: address) |> with_block(block)
[_, tx_before_last | _] = txs
request = get(conn, "/api/v2/addresses/#{address.hash}/transactions")
assert response = json_response(request, 200)
request_2nd_page =
get(
conn,
"/api/v2/addresses/#{address.hash}/transactions",
%{"block_number" => to_string(block.number), "index" => to_string(tx_before_last.index)}
)
assert response_2nd_page = json_response(request_2nd_page, 200)
check_paginated_response(response, response_2nd_page, txs)
end
test "backward compatible with legacy paging params for pending transactions", %{conn: conn} do
address = insert(:address)
txs = insert_list(51, :transaction, from_address: address)
[_, tx_before_last | _] = txs
request = get(conn, "/api/v2/addresses/#{address.hash}/transactions")
assert response = json_response(request, 200)
request_2nd_page_pending =
get(
conn,
"/api/v2/addresses/#{address.hash}/transactions",
%{"inserted_at" => to_string(tx_before_last.inserted_at), "hash" => to_string(tx_before_last.hash)}
)
assert response_2nd_page_pending = json_response(request_2nd_page_pending, 200)
check_paginated_response(response, response_2nd_page_pending, txs)
end
test "can order and paginate by fee ascending", %{conn: conn} do
address = insert(:address)

@ -1373,6 +1373,7 @@ defmodule Explorer.Chain.Transaction do
defp address_to_transactions_tasks(address_hash, options, old_ui?) do
direction = Keyword.get(options, :direction)
necessity_by_association = Keyword.get(options, :necessity_by_association, %{})
old_ui? = old_ui? || is_tuple(Keyword.get(options, :paging_options, Chain.default_paging_options()).key)
options
|> address_to_transactions_tasks_query(false, old_ui?)
@ -1603,7 +1604,7 @@ defmodule Explorer.Chain.Transaction do
end
@doc """
Adds a `has_token_transfers` field to the query via `select_merge` if second argument is `true` and returns
Adds a `has_token_transfers` field to the query via `select_merge` if second argument is `false` and returns
the query untouched otherwise.
"""
@spec put_has_token_transfers_to_tx(Ecto.Query.t() | atom, boolean) :: Ecto.Query.t()

Loading…
Cancel
Save