diff --git a/CHANGELOG.md b/CHANGELOG.md index 0457d876f7..1184bb0ec7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs index 6ed830528b..d3749c1628 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs @@ -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) diff --git a/apps/explorer/lib/explorer/chain/transaction.ex b/apps/explorer/lib/explorer/chain/transaction.ex index 1f7e67790b..c488d56bac 100644 --- a/apps/explorer/lib/explorer/chain/transaction.ex +++ b/apps/explorer/lib/explorer/chain/transaction.ex @@ -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()