Add API v2 output for transaction list of the specified batch

pull/7584/head
POA 1 year ago
parent 5d990c941c
commit c87e64fa3a
  1. 1
      apps/block_scout_web/lib/block_scout_web/api_router.ex
  2. 12
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/transaction_controller.ex
  3. 1
      apps/block_scout_web/lib/block_scout_web/views/api/v2/transaction_view.ex
  4. 9
      apps/explorer/lib/explorer/chain.ex
  5. 2
      apps/explorer/priv/repo/migrations/20230420110800_create_zkevm_tables.exs

@ -135,6 +135,7 @@ defmodule BlockScoutWeb.ApiRouter do
scope "/transactions" do
get("/", V2.TransactionController, :transactions)
get("/watchlist", V2.TransactionController, :watchlist_transactions)
get("/zkevm-batch/:batch_number", V2.TransactionController, :zkevm_batch)
get("/:transaction_hash_param", V2.TransactionController, :transaction)
get("/:transaction_hash_param/token-transfers", V2.TransactionController, :token_transfers)
get("/:transaction_hash_param/internal-transactions", V2.TransactionController, :internal_transactions)

@ -111,6 +111,18 @@ defmodule BlockScoutWeb.API.V2.TransactionController do
|> render(:transactions, %{transactions: transactions, next_page_params: next_page_params})
end
def zkevm_batch(conn, %{"batch_number" => batch_number} = _params) do
transactions =
batch_number
|> Chain.zkevm_batch_transactions(api?: true)
|> Enum.map(fn tx -> tx.hash end)
|> Chain.hashes_to_transactions(api?: true, necessity_by_association: @transaction_necessity_by_association)
conn
|> put_status(200)
|> render(:transactions, %{transactions: transactions})
end
def raw_trace(conn, %{"transaction_hash_param" => transaction_hash_string} = params) do
with {:format, {:ok, transaction_hash}} <- {:format, Chain.string_to_transaction_hash(transaction_hash_string)},
{:not_found, {:ok, transaction}} <-

@ -430,6 +430,7 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
defp add_optional_transaction_field(result, transaction, field_name, assoc_name, assoc_field) do
case Map.get(transaction, assoc_name) do
nil -> result
%Ecto.Association.NotLoaded{} -> result
item -> Map.put(result, field_name, Map.get(item, assoc_field))
end
end

@ -65,6 +65,7 @@ defmodule Explorer.Chain do
Transaction,
Wei,
Withdrawal,
ZkevmBatchTxn,
ZkevmTxnBatch
}
@ -1752,7 +1753,7 @@ defmodule Explorer.Chain do
|> where([transaction], transaction.hash in ^hashes)
|> join_associations(necessity_by_association)
|> preload([{:token_transfers, [:token, :from_address, :to_address]}])
|> Repo.all()
|> select_repo(options).all()
end
@doc """
@ -6462,6 +6463,12 @@ defmodule Explorer.Chain do
select_repo(options).all(query)
end
def zkevm_batch_transactions(batch_number, options \\ []) do
query = from(bts in ZkevmBatchTxn, where: bts.batch_number == ^batch_number)
select_repo(options).all(query)
end
defp page_zkevm_batches(query, %PagingOptions{key: nil}), do: query
defp page_zkevm_batches(query, %PagingOptions{key: {number}}) do

@ -48,5 +48,7 @@ defmodule Explorer.Repo.Migrations.CreateZkevmTables do
add(:hash, :bytea, null: false, primary_key: true)
timestamps(null: false, type: :utc_datetime_usec)
end
create(index(:zkevm_batch_l2_transactions, :batch_number))
end
end

Loading…
Cancel
Save