refactor: Fixate naming convention for "transaction" and "block number" entities (#10913)

* refactor: tx_hash -> transaction_hash, txn -> transaction, "block" in API v2 response to "block_number"

* More functions/vars to rename

* Update apps/block_scout_web/lib/block_scout_web/graphql/celo/schema/query_fields.ex

Co-authored-by: Fedor Ivanov <ivnfedor@gmail.com>

* Rename files

* Return l1_tx_origin / l2_tx_gas_limit in optimism view for the compatibility with fe at the time of transaition to new props

* Rename shorthand in template

* Repair merge

---------

Co-authored-by: Fedor Ivanov <ivnfedor@gmail.com>
pull/10977/head
Victor Baranov 1 week ago committed by GitHub
parent 6d8aa194c3
commit b030792cf1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 24
      CONTRIBUTING.md
  2. 26
      apps/block_scout_web/lib/block_scout_web/chain.ex
  3. 4
      apps/block_scout_web/lib/block_scout_web/controllers/account/api/v2/tags_controller.ex
  4. 6
      apps/block_scout_web/lib/block_scout_web/controllers/account/api/v2/user_controller.ex
  5. 4
      apps/block_scout_web/lib/block_scout_web/controllers/account/tag_transaction_controller.ex
  6. 4
      apps/block_scout_web/lib/block_scout_web/controllers/address_controller.ex
  7. 10
      apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/transaction_controller.ex
  8. 4
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/address_controller.ex
  9. 33
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/advanced_filter_controller.ex
  10. 11
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/arbitrum_controller.ex
  11. 4
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/block_controller.ex
  12. 6
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/fallback_controller.ex
  13. 4
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/import_controller.ex
  14. 24
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/optimism_controller.ex
  15. 11
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/proxy/account_abstraction_controller.ex
  16. 6
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/proxy/noves_fi_controller.ex
  17. 2
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/stats_controller.ex
  18. 31
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/transaction_controller.ex
  19. 6
      apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex
  20. 4
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_controller.ex
  21. 2
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex
  22. 2
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex
  23. 2
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex
  24. 2
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_state_controller.ex
  25. 2
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex
  26. 2
      apps/block_scout_web/lib/block_scout_web/etherscan.ex
  27. 2
      apps/block_scout_web/lib/block_scout_web/graphql/celo/resolvers/token_transfer.ex
  28. 4
      apps/block_scout_web/lib/block_scout_web/graphql/celo/resolvers/token_transfer_transaction.ex
  29. 6
      apps/block_scout_web/lib/block_scout_web/graphql/celo/schema/query_fields.ex
  30. 6
      apps/block_scout_web/lib/block_scout_web/graphql/celo/schema/types.ex
  31. 2
      apps/block_scout_web/lib/block_scout_web/graphql/schema/types.ex
  32. 21
      apps/block_scout_web/lib/block_scout_web/microservice_interfaces/transaction_interpretation.ex
  33. 8
      apps/block_scout_web/lib/block_scout_web/models/get_transaction_tags.ex
  34. 11
      apps/block_scout_web/lib/block_scout_web/models/transaction_state_helper.ex
  35. 6
      apps/block_scout_web/lib/block_scout_web/notifier.ex
  36. 6
      apps/block_scout_web/lib/block_scout_web/paging_helper.ex
  37. 13
      apps/block_scout_web/lib/block_scout_web/routers/api_router.ex
  38. 6
      apps/block_scout_web/lib/block_scout_web/templates/account/tag_transaction/form.html.eex
  39. 6
      apps/block_scout_web/lib/block_scout_web/templates/account/tag_transaction/index.html.eex
  40. 8
      apps/block_scout_web/lib/block_scout_web/templates/account/tag_transaction/row.html.eex
  41. 2
      apps/block_scout_web/lib/block_scout_web/templates/address/_tile.html.eex
  42. 6
      apps/block_scout_web/lib/block_scout_web/templates/robots/sitemap.xml.eex
  43. 4
      apps/block_scout_web/lib/block_scout_web/templates/search/_tile.html.eex
  44. 8
      apps/block_scout_web/lib/block_scout_web/templates/transaction/_tile.html.eex
  45. 8
      apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex
  46. 6
      apps/block_scout_web/lib/block_scout_web/views/account/api/v2/tags_view.ex
  47. 6
      apps/block_scout_web/lib/block_scout_web/views/account/api/v2/user_view.ex
  48. 6
      apps/block_scout_web/lib/block_scout_web/views/api/rpc/contract_view.ex
  49. 10
      apps/block_scout_web/lib/block_scout_web/views/api/rpc/transaction_view.ex
  50. 16
      apps/block_scout_web/lib/block_scout_web/views/api/v2/address_view.ex
  51. 97
      apps/block_scout_web/lib/block_scout_web/views/api/v2/arbitrum_view.ex
  52. 6
      apps/block_scout_web/lib/block_scout_web/views/api/v2/block_view.ex
  53. 4
      apps/block_scout_web/lib/block_scout_web/views/api/v2/ethereum_view.ex
  54. 2
      apps/block_scout_web/lib/block_scout_web/views/api/v2/mud_view.ex
  55. 40
      apps/block_scout_web/lib/block_scout_web/views/api/v2/optimism_view.ex
  56. 6
      apps/block_scout_web/lib/block_scout_web/views/api/v2/polygon_edge_view.ex
  57. 28
      apps/block_scout_web/lib/block_scout_web/views/api/v2/polygon_zkevm_view.ex
  58. 8
      apps/block_scout_web/lib/block_scout_web/views/api/v2/search_view.ex
  59. 2
      apps/block_scout_web/lib/block_scout_web/views/api/v2/smart_contract_view.ex
  60. 6
      apps/block_scout_web/lib/block_scout_web/views/api/v2/stability_view.ex
  61. 12
      apps/block_scout_web/lib/block_scout_web/views/api/v2/suave_view.ex
  62. 6
      apps/block_scout_web/lib/block_scout_web/views/api/v2/token_transfer_view.ex
  63. 189
      apps/block_scout_web/lib/block_scout_web/views/api/v2/transaction_view.ex
  64. 48
      apps/block_scout_web/lib/block_scout_web/views/api/v2/zksync_view.ex
  65. 2
      apps/block_scout_web/lib/block_scout_web/views/tab_helper.ex
  66. 4
      apps/block_scout_web/lib/block_scout_web/views/transaction_state_view.ex
  67. 36
      apps/block_scout_web/test/block_scout_web/channels/websocket_v2_test.exs
  68. 60
      apps/block_scout_web/test/block_scout_web/controllers/account/api/v2/user_controller_test.exs
  69. 8
      apps/block_scout_web/test/block_scout_web/controllers/api/rpc/address_controller_test.exs
  70. 14
      apps/block_scout_web/test/block_scout_web/controllers/api/rpc/contract_controller_test.exs
  71. 693
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs
  72. 288
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/advanced_filter_controller_test.exs
  73. 52
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/block_controller_test.exs
  74. 24
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/main_page_controller_test.exs
  75. 20
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/search_controller_test.exs
  76. 16
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs
  77. 98
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/token_controller_test.exs
  78. 44
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/token_transfer_controller_test.exs
  79. 450
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/transaction_controller_test.exs
  80. 2
      apps/block_scout_web/test/block_scout_web/controllers/transaction_controller_test.exs
  81. 2
      apps/block_scout_web/test/block_scout_web/controllers/verified_contracts_controller_test.exs
  82. 4
      apps/block_scout_web/test/block_scout_web/features/viewing_transactions_test.exs
  83. 22
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/filecoin.ex
  84. 20
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex
  85. 8
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth/tracer.ex
  86. 14
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex
  87. 6
      apps/ethereum_jsonrpc/test/ethereum_jsonrpc/geth/tracer_test.exs
  88. 10
      apps/ethereum_jsonrpc/test/ethereum_jsonrpc/geth_test.exs
  89. 4
      apps/explorer/lib/encrypt.ex
  90. 2
      apps/explorer/lib/explorer/account/notifier/email.ex
  91. 2
      apps/explorer/lib/explorer/account/notifier/notify.ex
  92. 14
      apps/explorer/lib/explorer/account/notifier/summary.ex
  93. 36
      apps/explorer/lib/explorer/account/tag_transaction.ex
  94. 17
      apps/explorer/lib/explorer/account/watchlist_notification.ex
  95. 246
      apps/explorer/lib/explorer/chain.ex
  96. 80
      apps/explorer/lib/explorer/chain/address/counters.ex
  97. 22
      apps/explorer/lib/explorer/chain/address/metadata_preloader.ex
  98. 79
      apps/explorer/lib/explorer/chain/advanced_filter.ex
  99. 14
      apps/explorer/lib/explorer/chain/arbitrum/batch_transaction.ex
  100. 15
      apps/explorer/lib/explorer/chain/arbitrum/da_multi_purpose_record.ex
  101. Some files were not shown because too many files have changed in this diff Show More

@ -59,3 +59,27 @@ There is a [PULL_REQUEST_TEMPLATE.md](PULL_REQUEST_TEMPLATE.md) for this reposit
* What was changed for incompatible changes
See [#255](https://github.com/blockscout/blockscout/pull/255) as an example PR that uses GitHub keywords and a Changelog to explain multiple changes.
## Basic Naming Convention
When contributing to the codebase, please adhere to the following naming conventions to ensure clarity and consistency:
- Use full names for entities. Avoid abbreviations or shorthand.
- Instead of "tx" or "txn", use "transaction".
- Instead of "txs", use "transactions".
- Instead of "tx_hash" or "txn_hash", use "transaction_hash".
- Instead of "block_num", use "block_number".
- Ensure that variable names are descriptive and convey the purpose or content clearly.
- Consistent naming helps in maintaining readability and understanding of the code, especially for new contributors.
By following these conventions, we can maintain a clean and understandable codebase.
### API V2 Naming Convention
When contributing to the API v2, please adhere to the following naming conventions for response fields to ensure clarity and consistency:
- The block number should be returned as a number in the `block_number` property.
- The transaction hash should be returned as a hex string in the `transaction_hash` property.
- All fields that contain the "index" suffix should be returned as numbers.

@ -181,21 +181,21 @@ defmodule BlockScoutWeb.Chain do
def paging_options(%{
"address_hash" => address_hash_string,
"tx_hash" => tx_hash_string,
"transaction_hash" => transaction_hash_string,
"block_hash" => block_hash_string,
"holder_count" => holder_count_string,
"name" => name_string,
"inserted_at" => inserted_at_string,
"item_type" => item_type_string
})
when is_binary(address_hash_string) and is_binary(tx_hash_string) and is_binary(block_hash_string) and
when is_binary(address_hash_string) and is_binary(transaction_hash_string) and is_binary(block_hash_string) and
is_binary(holder_count_string) and is_binary(name_string) and is_binary(inserted_at_string) and
is_binary(item_type_string) do
[
paging_options: %{
@default_paging_options
| key:
{address_hash_string, tx_hash_string, block_hash_string, holder_count_string, name_string,
{address_hash_string, transaction_hash_string, block_hash_string, holder_count_string, name_string,
inserted_at_string, item_type_string}
}
]
@ -376,7 +376,7 @@ defmodule BlockScoutWeb.Chain do
when is_binary(inserted_at_string) and is_binary(hash_string) do
with {:ok, inserted_at, _} <- DateTime.from_iso8601(inserted_at_string),
{:ok, hash} <- string_to_transaction_hash(hash_string) do
[paging_options: %{@default_paging_options | key: {inserted_at, hash}, is_pending_tx: true}]
[paging_options: %{@default_paging_options | key: {inserted_at, hash}, is_pending_transaction: true}]
else
_ ->
[paging_options: @default_paging_options]
@ -406,7 +406,7 @@ defmodule BlockScoutWeb.Chain do
end
def paging_options(%{"smart_contract_id" => id_str} = params) do
transactions_count = parse_integer(params["tx_count"])
transactions_count = parse_integer(params["transaction_count"])
coin_balance = parse_integer(params["coin_balance"])
id = parse_integer(id_str)
@ -425,10 +425,10 @@ defmodule BlockScoutWeb.Chain do
end
end
def paging_options(%{"l1_block_number" => block_number, "tx_hash" => tx_hash}) do
def paging_options(%{"l1_block_number" => block_number, "transaction_hash" => transaction_hash}) do
with {block_number, ""} <- Integer.parse(block_number),
{:ok, tx_hash} <- string_to_transaction_hash(tx_hash) do
[paging_options: %{@default_paging_options | key: {block_number, tx_hash}}]
{:ok, transaction_hash} <- string_to_transaction_hash(transaction_hash) do
[paging_options: %{@default_paging_options | key: {block_number, transaction_hash}}]
else
_ ->
[paging_options: @default_paging_options]
@ -707,8 +707,8 @@ defmodule BlockScoutWeb.Chain do
%{"smart_contract_id" => smart_contract.id}
end
defp paging_params(%OptimismDeposit{l1_block_number: l1_block_number, l2_transaction_hash: l2_tx_hash}) do
%{"l1_block_number" => l1_block_number, "tx_hash" => l2_tx_hash}
defp paging_params(%OptimismDeposit{l1_block_number: l1_block_number, l2_transaction_hash: l2_transaction_hash}) do
%{"l1_block_number" => l1_block_number, "transaction_hash" => l2_transaction_hash}
end
defp paging_params(%OptimismOutputRoot{l2_output_index: index}) do
@ -718,7 +718,7 @@ defmodule BlockScoutWeb.Chain do
defp paging_params(%SmartContract{} = smart_contract) do
%{
"smart_contract_id" => smart_contract.id,
"tx_count" => smart_contract.address.transactions_count,
"transaction_count" => smart_contract.address.transactions_count,
"coin_balance" =>
smart_contract.address.fetched_coin_balance && Wei.to(smart_contract.address.fetched_coin_balance, :wei)
}
@ -744,7 +744,7 @@ defmodule BlockScoutWeb.Chain do
# clause for search results pagination
defp paging_params(%{
address_hash: address_hash,
tx_hash: tx_hash,
transaction_hash: transaction_hash,
block_hash: block_hash,
holder_count: holder_count,
name: name,
@ -755,7 +755,7 @@ defmodule BlockScoutWeb.Chain do
%{
"address_hash" => address_hash,
"tx_hash" => tx_hash,
"transaction_hash" => transaction_hash,
"block_hash" => block_hash,
"holder_count" => holder_count,
"name" => name,

@ -54,7 +54,7 @@ defmodule BlockScoutWeb.Account.Api.V2.TagsController do
personal_tags =
if is_nil(current_user(conn)) do
%{personal_tags: [], watchlist_names: [], personal_tx_tag: nil}
%{personal_tags: [], watchlist_names: [], personal_transaction_tag: nil}
else
uid = current_user(conn).id
@ -68,7 +68,7 @@ defmodule BlockScoutWeb.Account.Api.V2.TagsController do
})
else
_ ->
%{personal_tags: [], watchlist_names: [], personal_tx_tag: nil}
%{personal_tags: [], watchlist_names: [], personal_transaction_tag: nil}
end
end

@ -298,13 +298,13 @@ defmodule BlockScoutWeb.Account.Api.V2.UserController do
end
end
def create_tag_transaction(conn, %{"transaction_hash" => tx_hash, "name" => name}) do
def create_tag_transaction(conn, %{"transaction_hash" => transaction_hash, "name" => name}) do
with {:auth, %{id: uid}} <- {:auth, current_user(conn)},
{:identity, %Identity{} = identity} <- {:identity, UserFromAuth.find_identity(uid)},
{:ok, transaction_tag} <-
TagTransaction.create(%{
name: name,
tx_hash: tx_hash,
transaction_hash: transaction_hash,
identity_id: identity.id
}) do
conn
@ -321,7 +321,7 @@ defmodule BlockScoutWeb.Account.Api.V2.UserController do
reject_nil_map_values(%{
id: tag_id,
name: attrs["name"],
tx_hash: attrs["transaction_hash"],
transaction_hash: attrs["transaction_hash"],
identity_id: identity.id
})
) do

@ -8,7 +8,7 @@ defmodule BlockScoutWeb.Account.TagTransactionController do
def index(conn, _params) do
current_user = authenticate!(conn)
render(conn, "index.html", tx_tags: TagTransaction.get_tags_transaction_by_identity_id(current_user.id))
render(conn, "index.html", transaction_tags: TagTransaction.get_tags_transaction_by_identity_id(current_user.id))
end
def new(conn, _params) do
@ -22,7 +22,7 @@ defmodule BlockScoutWeb.Account.TagTransactionController do
case TagTransaction.create(%{
name: tag_address["name"],
tx_hash: tag_address["tx_hash"],
transaction_hash: tag_address["transaction_hash"],
identity_id: current_user.id
}) do
{:ok, _} ->

@ -58,7 +58,7 @@ defmodule BlockScoutWeb.AddressController do
items =
addresses_page
|> Enum.with_index(1)
|> Enum.map(fn {{address, tx_count}, index} ->
|> Enum.map(fn {{address, transaction_count}, index} ->
View.render_to_string(
AddressView,
"_tile.html",
@ -66,7 +66,7 @@ defmodule BlockScoutWeb.AddressController do
index: items_count + index,
exchange_rate: exchange_rate,
total_supply: total_supply,
tx_count: tx_count
transaction_count: transaction_count
)
end)

@ -9,7 +9,7 @@ defmodule BlockScoutWeb.API.RPC.TransactionController do
@api_true [api?: true]
def gettxinfo(conn, params) do
with {:txhash_param, {:ok, txhash_param}} <- fetch_txhash(params),
with {:txhash_param, {:ok, txhash_param}} <- fetch_transaction_hash(params),
{:format, {:ok, transaction_hash}} <- to_transaction_hash(txhash_param),
{:transaction, {:ok, %Transaction{revert_reason: revert_reason, error: error} = transaction}} <-
transaction_from_hash(transaction_hash),
@ -19,7 +19,7 @@ defmodule BlockScoutWeb.API.RPC.TransactionController do
transaction_updated =
if (error == "Reverted" || error == "execution reverted") && !revert_reason do
%Transaction{transaction | revert_reason: Chain.fetch_tx_revert_reason(transaction)}
%Transaction{transaction | revert_reason: Chain.fetch_transaction_revert_reason(transaction)}
else
transaction
end
@ -43,7 +43,7 @@ defmodule BlockScoutWeb.API.RPC.TransactionController do
end
def gettxreceiptstatus(conn, params) do
with {:txhash_param, {:ok, txhash_param}} <- fetch_txhash(params),
with {:txhash_param, {:ok, txhash_param}} <- fetch_transaction_hash(params),
{:format, {:ok, transaction_hash}} <- to_transaction_hash(txhash_param) do
status = to_transaction_status(transaction_hash)
render(conn, :gettxreceiptstatus, %{status: status})
@ -57,7 +57,7 @@ defmodule BlockScoutWeb.API.RPC.TransactionController do
end
def getstatus(conn, params) do
with {:txhash_param, {:ok, txhash_param}} <- fetch_txhash(params),
with {:txhash_param, {:ok, txhash_param}} <- fetch_transaction_hash(params),
{:format, {:ok, transaction_hash}} <- to_transaction_hash(txhash_param) do
error = to_transaction_error(transaction_hash)
render(conn, :getstatus, %{error: error})
@ -70,7 +70,7 @@ defmodule BlockScoutWeb.API.RPC.TransactionController do
end
end
defp fetch_txhash(params) do
defp fetch_transaction_hash(params) do
{:txhash_param, Map.fetch(params, "txhash")}
end

@ -506,12 +506,12 @@ defmodule BlockScoutWeb.API.V2.AddressController do
with {:ok, address_hash, _address} <- validate_address(address_hash_string, params) do
counter_name_to_json_field_name = %{
validations: :validations_count,
txs: :transactions_count,
transactions: :transactions_count,
token_transfers: :token_transfers_count,
token_balances: :token_balances_count,
logs: :logs_count,
withdrawals: :withdrawals_count,
internal_txs: :internal_txs_count,
internal_transactions: :internal_transactions_count,
celo_election_rewards: :celo_election_rewards_count
}

@ -191,7 +191,7 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterController do
defp extract_filters(params) do
[
tx_types: prepare_tx_types(params["tx_types"]),
transaction_types: prepare_transaction_types(params["transaction_types"]),
methods: params["methods"] |> prepare_methods(),
age: prepare_age(params["age_from"], params["age_to"]),
from_address_hashes:
@ -221,16 +221,16 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterController do
]
end
@allowed_tx_types ~w(COIN_TRANSFER ERC-20 ERC-404 ERC-721 ERC-1155)
@allowed_transaction_types ~w(COIN_TRANSFER ERC-20 ERC-404 ERC-721 ERC-1155)
defp prepare_tx_types(tx_types) when is_binary(tx_types) do
tx_types
defp prepare_transaction_types(transaction_types) when is_binary(transaction_types) do
transaction_types
|> String.upcase()
|> String.split(",")
|> Enum.filter(&(&1 in @allowed_tx_types))
|> Enum.filter(&(&1 in @allowed_transaction_types))
end
defp prepare_tx_types(_), do: nil
defp prepare_transaction_types(_), do: nil
defp prepare_methods(methods) when is_binary(methods) do
methods
@ -312,14 +312,15 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterController do
defp paging_options(%{
"block_number" => block_number_string,
"transaction_index" => tx_index_string,
"internal_transaction_index" => internal_tx_index_string,
"transaction_index" => transaction_index_string,
"internal_transaction_index" => internal_transaction_index_string,
"token_transfer_index" => token_transfer_index_string,
"token_transfer_batch_index" => token_transfer_batch_index_string
}) do
with {block_number, ""} <- block_number_string && Integer.parse(block_number_string),
{tx_index, ""} <- tx_index_string && Integer.parse(tx_index_string),
{:ok, internal_tx_index} <- parse_nullable_integer_paging_parameter(internal_tx_index_string),
{transaction_index, ""} <- transaction_index_string && Integer.parse(transaction_index_string),
{:ok, internal_transaction_index} <-
parse_nullable_integer_paging_parameter(internal_transaction_index_string),
{:ok, token_transfer_index} <- parse_nullable_integer_paging_parameter(token_transfer_index_string),
{:ok, token_transfer_batch_index} <- parse_nullable_integer_paging_parameter(token_transfer_batch_index_string) do
[
@ -327,8 +328,8 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterController do
default_paging_options()
| key: %{
block_number: block_number,
transaction_index: tx_index,
internal_transaction_index: internal_tx_index,
transaction_index: transaction_index,
internal_transaction_index: internal_transaction_index,
token_transfer_index: token_transfer_index,
token_transfer_batch_index: token_transfer_batch_index
}
@ -354,15 +355,15 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterController do
defp paging_params(%AdvancedFilter{
block_number: block_number,
transaction_index: tx_index,
internal_transaction_index: internal_tx_index,
transaction_index: transaction_index,
internal_transaction_index: internal_transaction_index,
token_transfer_index: token_transfer_index,
token_transfer_batch_index: token_transfer_batch_index
}) do
%{
block_number: block_number,
transaction_index: tx_index,
internal_transaction_index: internal_tx_index,
transaction_index: transaction_index,
internal_transaction_index: internal_transaction_index,
token_transfer_index: token_transfer_index,
token_transfer_batch_index: token_transfer_batch_index
}

@ -81,7 +81,7 @@ defmodule BlockScoutWeb.API.V2.ArbitrumController do
@doc """
Function to handle GET requests to `/api/v2/arbitrum/batches/da/:data_hash` or
`/api/v2/arbitrum/batches/da/:tx_commitment/:height` endpoints.
`/api/v2/arbitrum/batches/da/:transaction_commitment/:height` endpoints.
"""
@spec batch_by_data_availability_info(Plug.Conn.t(), map()) :: Plug.Conn.t()
def batch_by_data_availability_info(conn, %{"data_hash" => data_hash} = _params) do
@ -95,10 +95,13 @@ defmodule BlockScoutWeb.API.V2.ArbitrumController do
end
end
def batch_by_data_availability_info(conn, %{"tx_commitment" => tx_commitment, "height" => height} = _params) do
def batch_by_data_availability_info(
conn,
%{"transaction_commitment" => transaction_commitment, "height" => height} = _params
) do
# In case of Celestia, `data_key` is the hash of the height and the commitment hash
with {:ok, :hash, tx_commitment_hash} <- parse_block_hash_or_number_param(tx_commitment),
key <- calculate_celestia_data_key(height, tx_commitment_hash) do
with {:ok, :hash, transaction_commitment_hash} <- parse_block_hash_or_number_param(transaction_commitment),
key <- calculate_celestia_data_key(height, transaction_commitment_hash) do
case Reader.get_da_record_by_data_key(key, api?: true) do
{:ok, {batch_number, _}} ->
batch(conn, %{"batch_number" => batch_number})

@ -35,7 +35,7 @@ defmodule BlockScoutWeb.API.V2.BlockController do
alias Explorer.Chain.Celo.EpochReward, as: CeloEpochReward
alias Explorer.Chain.Celo.Reader, as: CeloReader
alias Explorer.Chain.InternalTransaction
alias Explorer.Chain.Optimism.TxnBatch, as: OptimismTxnBatch
alias Explorer.Chain.Optimism.TransactionBatch, as: OptimismTransactionBatch
case Application.compile_env(:explorer, :chain_type) do
:ethereum ->
@ -212,7 +212,7 @@ defmodule BlockScoutWeb.API.V2.BlockController do
{blocks, next_page} =
batch_number
|> OptimismTxnBatch.batch_blocks(full_options)
|> OptimismTransactionBatch.batch_blocks(full_options)
|> split_list_by_page()
next_page_params = next_page |> next_page_params(blocks, delete_parameters_from_next_page_params(params))

@ -30,7 +30,7 @@ defmodule BlockScoutWeb.API.V2.FallbackController do
@vyper_smart_contract_is_not_supported "Vyper smart-contracts are not supported by SolidityScan"
@unverified_smart_contract "Smart-contract is unverified"
@empty_response "Empty response"
@tx_interpreter_service_disabled "Transaction Interpretation Service is disabled"
@transaction_interpreter_service_disabled "Transaction Interpretation Service is disabled"
@disabled "API endpoint is disabled"
@service_disabled "Service is disabled"
@ -296,11 +296,11 @@ defmodule BlockScoutWeb.API.V2.FallbackController do
|> render(:message, %{message: @empty_response})
end
def call(conn, {:tx_interpreter_enabled, false}) do
def call(conn, {:transaction_interpreter_enabled, false}) do
conn
|> put_status(:forbidden)
|> put_view(ApiView)
|> render(:message, %{message: @tx_interpreter_service_disabled})
|> render(:message, %{message: @transaction_interpreter_service_disabled})
end
def call(conn, {:disabled, _}) do

@ -70,11 +70,11 @@ defmodule BlockScoutWeb.API.V2.ImportController do
{:not_found, {:ok, address}} <- {:not_found, Chain.hash_to_address(address_hash, @api_true, false)},
{:already_verified, smart_contract} when is_nil(smart_contract) <-
{:already_verified, SmartContract.address_hash_to_smart_contract(address_hash, @api_true)} do
creation_tx_input = contract_creation_input(address.hash)
creation_transaction_input = contract_creation_input(address.hash)
with {:ok, %{"sourceType" => type} = source} <-
%{}
|> prepare_bytecode_for_microservice(creation_tx_input, Data.to_string(address.contract_code))
|> prepare_bytecode_for_microservice(creation_transaction_input, Data.to_string(address.contract_code))
|> EthBytecodeDBInterface.search_contract_in_eth_bytecode_internal_db(
address_hash_string,
params_to_contract_search_options(params)

@ -22,7 +22,7 @@ defmodule BlockScoutWeb.API.V2.OptimismController do
FrameSequence,
FrameSequenceBlob,
OutputRoot,
TxnBatch,
TransactionBatch,
Withdrawal
}
@ -32,22 +32,22 @@ defmodule BlockScoutWeb.API.V2.OptimismController do
Function to handle GET requests to `/api/v2/optimism/txn-batches` and
`/api/v2/optimism/txn-batches/:l2_block_range_start/:l2_block_range_end` endpoints.
"""
@spec txn_batches(Plug.Conn.t(), map()) :: Plug.Conn.t()
def txn_batches(conn, params) do
@spec transaction_batches(Plug.Conn.t(), map()) :: Plug.Conn.t()
def transaction_batches(conn, params) do
{batches, next_page} =
params
|> paging_options()
|> Keyword.put(:api?, true)
|> Keyword.put(:l2_block_range_start, Map.get(params, "l2_block_range_start"))
|> Keyword.put(:l2_block_range_end, Map.get(params, "l2_block_range_end"))
|> TxnBatch.list()
|> TransactionBatch.list()
|> split_list_by_page()
next_page_params = next_page_params(next_page, batches, delete_parameters_from_next_page_params(params))
conn
|> put_status(200)
|> render(:optimism_txn_batches, %{
|> render(:optimism_transaction_batches, %{
batches: batches,
next_page_params: next_page_params
})
@ -56,9 +56,9 @@ defmodule BlockScoutWeb.API.V2.OptimismController do
@doc """
Function to handle GET requests to `/api/v2/optimism/txn-batches/count` endpoint.
"""
@spec txn_batches_count(Plug.Conn.t(), map()) :: Plug.Conn.t()
def txn_batches_count(conn, _params) do
items_count(conn, TxnBatch)
@spec transaction_batches_count(Plug.Conn.t(), map()) :: Plug.Conn.t()
def transaction_batches_count(conn, _params) do
items_count(conn, TransactionBatch)
end
@doc """
@ -80,14 +80,14 @@ defmodule BlockScoutWeb.API.V2.OptimismController do
batches
|> Enum.map(fn fs ->
Task.async(fn ->
l2_block_number_from = TxnBatch.edge_l2_block_number(fs.id, :min)
l2_block_number_to = TxnBatch.edge_l2_block_number(fs.id, :max)
tx_count = Transaction.tx_count_for_block_range(l2_block_number_from..l2_block_number_to)
l2_block_number_from = TransactionBatch.edge_l2_block_number(fs.id, :min)
l2_block_number_to = TransactionBatch.edge_l2_block_number(fs.id, :max)
transaction_count = Transaction.transaction_count_for_block_range(l2_block_number_from..l2_block_number_to)
{batch_data_container, _} = FrameSequenceBlob.list(fs.id, api?: true)
fs
|> Map.put(:l2_block_range, l2_block_number_from..l2_block_number_to)
|> Map.put(:tx_count, tx_count)
|> Map.put(:transaction_count, transaction_count)
|> Map.put(:batch_data_container, batch_data_container)
end)
end)

@ -24,7 +24,7 @@ defmodule BlockScoutWeb.API.V2.Proxy.AccountAbstractionController do
Function to handle GET requests to `/api/v2/proxy/account-abstraction/operations/:user_operation_hash_param/summary` endpoint.
"""
@spec summary(Plug.Conn.t(), map()) ::
{:error | :format | :tx_interpreter_enabled | non_neg_integer(), any()} | Plug.Conn.t()
{:error | :format | :transaction_interpreter_enabled | non_neg_integer(), any()} | Plug.Conn.t()
def summary(conn, %{"operation_hash_param" => operation_hash_string, "just_request_body" => "true"}) do
with {:format, {:ok, _operation_hash}} <- {:format, Chain.string_to_transaction_hash(operation_hash_string)},
{200, %{"hash" => _} = user_op} <- AccountAbstraction.get_user_ops_by_hash(operation_hash_string) do
@ -35,12 +35,13 @@ defmodule BlockScoutWeb.API.V2.Proxy.AccountAbstractionController do
def summary(conn, %{"operation_hash_param" => operation_hash_string}) do
with {:format, {:ok, _operation_hash}} <- {:format, Chain.string_to_transaction_hash(operation_hash_string)},
{:tx_interpreter_enabled, true} <- {:tx_interpreter_enabled, TransactionInterpretationService.enabled?()},
{:transaction_interpreter_enabled, true} <-
{:transaction_interpreter_enabled, TransactionInterpretationService.enabled?()},
{200, %{"hash" => _} = user_op} <- AccountAbstraction.get_user_ops_by_hash(operation_hash_string) do
{response, code} =
case TransactionInterpretationService.interpret_user_operation(user_op) do
{:ok, response} -> {response, 200}
{:error, %Jason.DecodeError{}} -> {%{error: "Error while tx interpreter response decoding"}, 500}
{:error, %Jason.DecodeError{}} -> {%{error: "Error while transaction interpreter response decoding"}, 500}
{{:error, error}, code} -> {%{error: error}, code}
end
@ -233,10 +234,10 @@ defmodule BlockScoutWeb.API.V2.Proxy.AccountAbstractionController do
defp try_to_decode_call_data(%{"call_data" => _call_data} = user_op) do
user_op_hash = user_op["hash"]
{_mock_tx, _decoded_call_data, decoded_call_data_json} =
{_mock_transaction, _decoded_call_data, decoded_call_data_json} =
TransactionInterpretationService.decode_user_op_calldata(user_op_hash, user_op["call_data"])
{_mock_tx, _decoded_execute_call_data, decoded_execute_call_data_json} =
{_mock_transaction, _decoded_execute_call_data, decoded_execute_call_data_json} =
TransactionInterpretationService.decode_user_op_calldata(user_op_hash, user_op["execute_call_data"])
user_op

@ -16,7 +16,7 @@ defmodule BlockScoutWeb.API.V2.Proxy.NovesFiController do
necessity_by_association: %{},
api?: true
),
url = NovesFi.tx_url(transaction_hash_string),
url = NovesFi.transaction_url(transaction_hash_string),
{response, status} <- NovesFi.api_request(url, conn),
{:is_empty_response, false} <- {:is_empty_response, is_nil(response)} do
conn
@ -31,7 +31,7 @@ defmodule BlockScoutWeb.API.V2.Proxy.NovesFiController do
@spec address_transactions(Plug.Conn.t(), map()) :: Plug.Conn.t() | {atom(), any()}
def address_transactions(conn, %{"address_hash_param" => address_hash_string} = params) do
with {:ok, _address_hash, _address} <- AddressController.validate_address(address_hash_string, params),
url = NovesFi.address_txs_url(address_hash_string),
url = NovesFi.address_transactions_url(address_hash_string),
{response, status} <- NovesFi.api_request(url, conn),
{:is_empty_response, false} <- {:is_empty_response, is_nil(response)} do
conn
@ -45,7 +45,7 @@ defmodule BlockScoutWeb.API.V2.Proxy.NovesFiController do
"""
@spec describe_transactions(Plug.Conn.t(), map()) :: Plug.Conn.t() | {atom(), any()}
def describe_transactions(conn, _) do
url = NovesFi.describe_txs_url()
url = NovesFi.describe_transactions_url()
with {response, status} <- NovesFi.api_request(url, conn, :post_transactions),
{:is_empty_response, false} <- {:is_empty_response, is_nil(response)} do

@ -109,7 +109,7 @@ defmodule BlockScoutWeb.API.V2.StatsController do
transaction_history_data =
date_range
|> Enum.map(fn row ->
%{date: row.date, tx_count: row.number_of_transactions}
%{date: row.date, transaction_count: row.number_of_transactions}
end)
json(conn, %{

@ -42,7 +42,7 @@ defmodule BlockScoutWeb.API.V2.TransactionController do
alias Explorer.Chain.Arbitrum.Reader, as: ArbitrumReader
alias Explorer.Chain.Beacon.Reader, as: BeaconReader
alias Explorer.Chain.{Hash, InternalTransaction, Transaction}
alias Explorer.Chain.Optimism.TxnBatch, as: OptimismTxnBatch
alias Explorer.Chain.Optimism.TransactionBatch, as: OptimismTransactionBatch
alias Explorer.Chain.PolygonZkevm.Reader, as: PolygonZkevmReader
alias Explorer.Chain.ZkSync.Reader, as: ZkSyncReader
alias Explorer.Counters.{FreshPendingTransactionsCounter, Transactions24hStats}
@ -95,7 +95,7 @@ defmodule BlockScoutWeb.API.V2.TransactionController do
[to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional
}
@token_transfers_in_tx_necessity_by_association %{
@token_transfers_in_transaction_necessity_by_association %{
[from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional,
[to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional,
token: :required
@ -160,7 +160,12 @@ defmodule BlockScoutWeb.API.V2.TransactionController do
api?: true
),
preloaded <-
Chain.preload_token_transfers(transaction, @token_transfers_in_tx_necessity_by_association, @api_true, false) do
Chain.preload_token_transfers(
transaction,
@token_transfers_in_transaction_necessity_by_association,
@api_true,
false
) do
conn
|> put_status(200)
|> render(:transaction, %{
@ -208,7 +213,7 @@ defmodule BlockScoutWeb.API.V2.TransactionController do
transactions =
batch_number
|> PolygonZkevmReader.batch_transactions(api?: true)
|> Enum.map(fn tx -> tx.hash end)
|> Enum.map(fn transaction -> transaction.hash end)
|> Chain.hashes_to_transactions(api?: true, necessity_by_association: @transaction_necessity_by_association)
conn
@ -245,8 +250,8 @@ defmodule BlockScoutWeb.API.V2.TransactionController do
def optimism_batch(conn, %{"batch_number" => batch_number_string} = params) do
{batch_number, ""} = Integer.parse(batch_number_string)
l2_block_number_from = OptimismTxnBatch.edge_l2_block_number(batch_number, :min)
l2_block_number_to = OptimismTxnBatch.edge_l2_block_number(batch_number, :max)
l2_block_number_from = OptimismTransactionBatch.edge_l2_block_number(batch_number, :min)
l2_block_number_to = OptimismTransactionBatch.edge_l2_block_number(batch_number, :max)
transactions_plus_one =
if is_nil(l2_block_number_from) or is_nil(l2_block_number_to) do
@ -307,7 +312,7 @@ defmodule BlockScoutWeb.API.V2.TransactionController do
transactions_plus_one =
batch_number
|> batch_transactions_fun.(@api_true)
|> Enum.map(fn tx -> tx.tx_hash end)
|> Enum.map(fn transaction -> transaction.transaction_hash end)
|> Chain.hashes_to_transactions(full_options)
{transactions, next_page} = split_list_by_page(transactions_plus_one)
@ -462,7 +467,7 @@ defmodule BlockScoutWeb.API.V2.TransactionController do
conn
|> put_status(200)
|> render(:logs, %{
tx_hash: transaction_hash,
transaction_hash: transaction_hash,
logs: logs |> maybe_preload_ens() |> maybe_preload_metadata(),
next_page_params: next_page_params
})
@ -520,7 +525,8 @@ defmodule BlockScoutWeb.API.V2.TransactionController do
end
def summary(conn, %{"transaction_hash_param" => transaction_hash_string, "just_request_body" => "true"} = params) do
with {:tx_interpreter_enabled, true} <- {:tx_interpreter_enabled, TransactionInterpretationService.enabled?()},
with {:transaction_interpreter_enabled, true} <-
{:transaction_interpreter_enabled, TransactionInterpretationService.enabled?()},
{:ok, transaction, _transaction_hash} <-
validate_transaction(transaction_hash_string, params,
necessity_by_association: %{
@ -541,10 +547,11 @@ defmodule BlockScoutWeb.API.V2.TransactionController do
{:format, :error}
| {:not_found, {:error, :not_found}}
| {:restricted_access, true}
| {:tx_interpreter_enabled, boolean}
| {:transaction_interpreter_enabled, boolean}
| Plug.Conn.t()
def summary(conn, %{"transaction_hash_param" => transaction_hash_string} = params) do
with {:tx_interpreter_enabled, true} <- {:tx_interpreter_enabled, TransactionInterpretationService.enabled?()},
with {:transaction_interpreter_enabled, true} <-
{:transaction_interpreter_enabled, TransactionInterpretationService.enabled?()},
{:ok, transaction, _transaction_hash} <-
validate_transaction(transaction_hash_string, params,
necessity_by_association: %{
@ -556,7 +563,7 @@ defmodule BlockScoutWeb.API.V2.TransactionController do
{response, code} =
case TransactionInterpretationService.interpret(transaction) do
{:ok, response} -> {response, 200}
{:error, %Jason.DecodeError{}} -> {%{error: "Error while tx interpreter response decoding"}, 500}
{:error, %Jason.DecodeError{}} -> {%{error: "Error while transaction interpreter response decoding"}, 500}
{{:error, error}, code} -> {%{error: error}, code}
end

@ -97,13 +97,13 @@ defmodule BlockScoutWeb.ChainController do
encoded_results =
results
|> Enum.map(fn item ->
tx_hash_bytes = Map.get(item, :tx_hash)
transaction_hash_bytes = Map.get(item, :transaction_hash)
block_hash_bytes = Map.get(item, :block_hash)
item =
if tx_hash_bytes do
if transaction_hash_bytes do
item
|> Map.replace(:tx_hash, "0x" <> Base.encode16(tx_hash_bytes, case: :lower))
|> Map.replace(:transaction_hash, "0x" <> Base.encode16(transaction_hash_bytes, case: :lower))
else
item
end

@ -167,7 +167,7 @@ defmodule BlockScoutWeb.TransactionController do
transaction: transaction,
from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)),
to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)),
tx_tags:
transaction_tags:
get_transaction_with_addresses_tags(
transaction,
current_user(conn)
@ -196,7 +196,7 @@ defmodule BlockScoutWeb.TransactionController do
transaction: transaction,
from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)),
to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)),
tx_tags:
transaction_tags:
get_transaction_with_addresses_tags(
transaction,
current_user(conn)

@ -110,7 +110,7 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do
transaction: transaction,
from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)),
to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)),
tx_tags:
transaction_tags:
get_transaction_with_addresses_tags(
transaction,
current_user(conn)

@ -101,7 +101,7 @@ defmodule BlockScoutWeb.TransactionLogController do
exchange_rate: Market.get_coin_exchange_rate(),
from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)),
to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)),
tx_tags:
transaction_tags:
get_transaction_with_addresses_tags(
transaction,
current_user(conn)

@ -60,7 +60,7 @@ defmodule BlockScoutWeb.TransactionRawTraceController do
transaction: transaction,
from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)),
to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)),
tx_tags:
transaction_tags:
get_transaction_with_addresses_tags(
transaction,
current_user(conn)

@ -104,7 +104,7 @@ defmodule BlockScoutWeb.TransactionStateController do
transaction: transaction,
from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)),
to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)),
tx_tags:
transaction_tags:
get_transaction_with_addresses_tags(
transaction,
current_user(conn)

@ -113,7 +113,7 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do
transaction: transaction,
from_tags: get_address_tags(transaction.from_address_hash, current_user(conn)),
to_tags: get_address_tags(transaction.to_address_hash, current_user(conn)),
tx_tags:
transaction_tags:
get_transaction_with_addresses_tags(
transaction,
current_user(conn)

@ -1149,7 +1149,7 @@ defmodule BlockScoutWeb.Etherscan do
confirmations: @confirmation_type,
success: %{
type: "boolean",
definition: "Flag for success during tx execution",
definition: "Flag for success during transaction execution",
example: ~s(true)
},
from: @address_hash_type,

@ -9,7 +9,7 @@ defmodule BlockScoutWeb.GraphQL.Celo.Resolvers.TokenTransfer do
def get_by(%{transaction_hash: hash}, args, _) do
hash
|> GraphQL.token_tx_transfers_query_by_txhash()
|> GraphQL.token_transaction_transfers_query_by_transaction_hash()
|> Connection.from_query(&Repo.all/1, args, options(args))
end

@ -1,4 +1,4 @@
defmodule BlockScoutWeb.GraphQL.Celo.Resolvers.TokenTransferTx do
defmodule BlockScoutWeb.GraphQL.Celo.Resolvers.TokenTransferTransaction do
@moduledoc false
alias Absinthe.Relay.Connection
@ -15,7 +15,7 @@ defmodule BlockScoutWeb.GraphQL.Celo.Resolvers.TokenTransferTx do
end
address_hash
|> GraphQL.token_tx_transfers_query_for_address(offset, limit)
|> GraphQL.token_transaction_transfers_query_for_address(offset, limit)
|> Connection.from_query(&Repo.all/1, connection_args, options(args))
end

@ -3,7 +3,7 @@ defmodule BlockScoutWeb.GraphQL.Celo.QueryFields do
Query fields for the CELO schema.
"""
alias BlockScoutWeb.GraphQL.Celo.Resolvers.TokenTransferTx
alias BlockScoutWeb.GraphQL.Celo.Resolvers.TokenTransferTransaction
use Absinthe.Schema.Notation
use Absinthe.Relay.Schema, :modern
@ -11,11 +11,11 @@ defmodule BlockScoutWeb.GraphQL.Celo.QueryFields do
defmacro generate do
quote do
@desc "Gets token transfer transactions."
connection field(:token_transfer_txs, node_type: :transfer_tx) do
connection field(:token_transfer_txs, node_type: :transfer_transaction) do
arg(:address_hash, :address_hash)
arg(:count, :integer)
resolve(&TokenTransferTx.get_by/3)
resolve(&TokenTransferTransaction.get_by/3)
complexity(fn
%{first: first}, child_complexity -> first * child_complexity

@ -35,7 +35,7 @@ defmodule BlockScoutWeb.GraphQL.Celo.Schema.Types do
@desc """
Represents a CELO token transfer between addresses.
"""
node object(:transfer_tx, id_fetcher: &transfer_tx_id_fetcher/2) do
node object(:transfer_transaction, id_fetcher: &transfer_transaction_id_fetcher/2) do
field(:gateway_fee_recipient, :address_hash)
field(:gateway_fee, :address_hash)
field(:fee_currency, :address_hash)
@ -62,10 +62,10 @@ defmodule BlockScoutWeb.GraphQL.Celo.Schema.Types do
end
end
connection(node_type: :transfer_tx)
connection(node_type: :transfer_transaction)
connection(node_type: :celo_transfer)
defp transfer_tx_id_fetcher(
defp transfer_transaction_id_fetcher(
%{transaction_hash: transaction_hash, address_hash: address_hash},
_
) do

@ -42,7 +42,7 @@ defmodule BlockScoutWeb.GraphQL.Schema.Transaction do
field(:max_priority_fee_per_gas, :wei)
field(:max_fee_per_gas, :wei)
field(:type, :integer)
field(:has_error_in_internal_txs, :boolean)
field(:has_error_in_internal_transactions, :boolean)
field :block, :block do
resolve(&Block.get_by/3)

@ -57,7 +57,7 @@ defmodule BlockScoutWeb.MicroserviceInterfaces.TransactionInterpretation do
end
@doc """
Build the request body as for the tx interpreter POST request.
Build the request body as for the transaction interpreter POST request.
"""
@spec get_request_body(Transaction.t()) :: map()
def get_request_body(transaction) do
@ -65,7 +65,7 @@ defmodule BlockScoutWeb.MicroserviceInterfaces.TransactionInterpretation do
end
@doc """
Build the request body as for the tx interpreter POST request.
Build the request body as for the transaction interpreter POST request.
"""
@spec get_user_op_request_body(map()) :: map()
def get_user_op_request_body(user_op) do
@ -160,7 +160,7 @@ defmodule BlockScoutWeb.MicroserviceInterfaces.TransactionInterpretation do
value: transaction_with_meta.value,
method: Transaction.method_name(transaction_with_meta, Transaction.format_decoded_input(decoded_input)),
status: transaction_with_meta.status,
tx_types: TransactionView.tx_types(transaction_with_meta),
transaction_types: TransactionView.transaction_types(transaction_with_meta),
raw_input: transaction_with_meta.input,
decoded_input: decoded_input_data,
token_transfers: prepare_token_transfers(token_transfers_with_meta, decoded_input),
@ -333,7 +333,7 @@ defmodule BlockScoutWeb.MicroserviceInterfaces.TransactionInterpretation do
user_op_from = user_op["sender"]
user_op_to = user_op["execute_target"] || user_op["sender"]
{mock_tx, decoded_input, decoded_input_json} = decode_user_op_calldata(user_op_hash, user_op_call_data)
{mock_transaction, decoded_input, decoded_input_json} = decode_user_op_calldata(user_op_hash, user_op_call_data)
{prepared_logs, prepared_token_transfers} = user_op_to_logs_and_token_transfers(user_op, decoded_input)
@ -352,10 +352,10 @@ defmodule BlockScoutWeb.MicroserviceInterfaces.TransactionInterpretation do
hash: user_op_hash,
type: 0,
value: "0",
method: Transaction.method_name(mock_tx, Transaction.format_decoded_input(decoded_input), true),
method: Transaction.method_name(mock_transaction, Transaction.format_decoded_input(decoded_input), true),
status: user_op["status"],
actions: [],
tx_types: [],
transaction_types: [],
raw_input: user_op_call_data,
decoded_input: decoded_input_json,
token_transfers: prepared_token_transfers
@ -365,7 +365,7 @@ defmodule BlockScoutWeb.MicroserviceInterfaces.TransactionInterpretation do
end
@doc """
Decodes user_op["call_data"] and return {mock_tx, decoded_input, decoded_input_json}
Decodes user_op["call_data"] and return {mock_transaction, decoded_input, decoded_input_json}
"""
@spec decode_user_op_calldata(binary(), binary() | nil) :: {Transaction.t(), tuple(), map()} | {nil, nil, nil}
def decode_user_op_calldata(_user_op_hash, nil), do: {nil, nil, nil}
@ -375,7 +375,7 @@ defmodule BlockScoutWeb.MicroserviceInterfaces.TransactionInterpretation do
{:ok, op_hash} = Chain.string_to_transaction_hash(user_op_hash)
mock_tx = %Transaction{
mock_transaction = %Transaction{
to_address: %NotLoaded{},
input: input,
hash: op_hash
@ -383,8 +383,9 @@ defmodule BlockScoutWeb.MicroserviceInterfaces.TransactionInterpretation do
skip_sig_provider? = false
decoded_input = Transaction.decoded_input_data(mock_tx, skip_sig_provider?, @api_true)
decoded_input = Transaction.decoded_input_data(mock_transaction, skip_sig_provider?, @api_true)
{mock_tx, decoded_input, decoded_input |> Transaction.format_decoded_input() |> TransactionView.decoded_input()}
{mock_transaction, decoded_input,
decoded_input |> Transaction.format_decoded_input() |> TransactionView.decoded_input()}
end
end

@ -13,9 +13,9 @@ defmodule BlockScoutWeb.Models.GetTransactionTags do
%Transaction{} = transaction,
%{id: identity_id, watchlist_id: watchlist_id}
) do
tx_tag = get_transaction_tags(transaction.hash, %{id: identity_id})
transaction_tag = get_transaction_tags(transaction.hash, %{id: identity_id})
addresses_tags = get_addresses_tags_for_transaction(transaction, %{id: identity_id, watchlist_id: watchlist_id})
Map.put(addresses_tags, :personal_tx_tag, tx_tag)
Map.put(addresses_tags, :personal_transaction_tag, transaction_tag)
end
def get_transaction_with_addresses_tags(%Transaction{} = transaction, _),
@ -23,11 +23,11 @@ defmodule BlockScoutWeb.Models.GetTransactionTags do
common_tags: get_tags_on_address(transaction.to_address_hash),
personal_tags: [],
watchlist_names: [],
personal_tx_tag: nil
personal_transaction_tag: nil
}
def get_transaction_tags(transaction_hash, %{id: identity_id}) do
Repo.account_repo().get_by(TagTransaction, tx_hash_hash: transaction_hash, identity_id: identity_id)
Repo.account_repo().get_by(TagTransaction, transaction_hash_hash: transaction_hash, identity_id: identity_id)
end
def get_transaction_tags(_, _), do: nil

@ -55,7 +55,7 @@ defmodule BlockScoutWeb.Models.TransactionStateHelper do
end
defp do_state_changes(%Transaction{} = transaction, options) do
block_txs =
block_transactions =
transaction.block_hash
|> Chain.block_to_transactions(
paging_options: %PagingOptions{key: nil, page_size: nil},
@ -65,7 +65,7 @@ defmodule BlockScoutWeb.Models.TransactionStateHelper do
|> Repo.preload([:token_transfers, :internal_transactions])
transaction =
block_txs
block_transactions
|> Enum.find(&(&1.hash == transaction.hash))
|> Repo.preload(
token_transfers: [
@ -85,14 +85,15 @@ defmodule BlockScoutWeb.Models.TransactionStateHelper do
coin_balances_before_block = transaction_to_coin_balances(transaction, previous_block_number, options)
coin_balances_before_tx = StateChange.coin_balances_before(transaction, block_txs, coin_balances_before_block)
coin_balances_before_transaction =
StateChange.coin_balances_before(transaction, block_transactions, coin_balances_before_block)
native_coin_entries = StateChange.native_coin_entries(transaction, coin_balances_before_tx)
native_coin_entries = StateChange.native_coin_entries(transaction, coin_balances_before_transaction)
token_balances_before =
transaction.token_transfers
|> Enum.reduce(%{}, &token_transfers_to_balances_reducer(&1, &2, previous_block_number, options))
|> StateChange.token_balances_before(transaction, block_txs)
|> StateChange.token_balances_before(transaction, block_transactions)
tokens_entries = StateChange.token_entries(transaction.token_transfers, token_balances_before)

@ -163,7 +163,7 @@ defmodule BlockScoutWeb.Notifier do
Endpoint.broadcast("transactions:#{transaction_hash}", "raw_trace", %{raw_trace_origin: transaction_hash})
end
# internal txs broadcast disabled on the indexer level, therefore it out of scope of the refactoring within https://github.com/blockscout/blockscout/pull/7474
# internal transactions broadcast disabled on the indexer level, therefore it out of scope of the refactoring within https://github.com/blockscout/blockscout/pull/7474
def handle_event({:chain_event, :internal_transactions, :realtime, internal_transactions}) do
internal_transactions
|> Stream.map(
@ -215,9 +215,9 @@ defmodule BlockScoutWeb.Notifier do
transactions
|> Repo.preload(preloads)
|> broadcast_transactions_websocket_v2()
|> Enum.map(fn tx ->
|> Enum.map(fn transaction ->
# Disable parsing of token transfers from websocket for transaction tab because we display token transfers at a separate tab
Map.put(tx, :token_transfers, [])
Map.put(transaction, :token_transfers, [])
end)
|> Enum.each(&broadcast_transaction/1)
end

@ -52,7 +52,7 @@ defmodule BlockScoutWeb.PagingHelper do
def paging_options(%{"inserted_at" => inserted_at_string, "hash" => hash_string}, [:pending | _]) do
with {:ok, inserted_at, _} <- DateTime.from_iso8601(inserted_at_string),
{:ok, hash} <- string_to_transaction_hash(hash_string) do
[paging_options: %{@default_paging_options | key: {inserted_at, hash}, is_pending_tx: true}]
[paging_options: %{@default_paging_options | key: {inserted_at, hash}, is_pending_transaction: true}]
else
_ ->
[paging_options: @default_paging_options]
@ -274,8 +274,8 @@ defmodule BlockScoutWeb.PagingHelper do
defp do_smart_contracts_sorting("balance", "asc"), do: [{:asc_nulls_first, :fetched_coin_balance, :address}]
defp do_smart_contracts_sorting("balance", "desc"), do: [{:desc_nulls_last, :fetched_coin_balance, :address}]
defp do_smart_contracts_sorting("txs_count", "asc"), do: [{:asc_nulls_first, :transactions_count, :address}]
defp do_smart_contracts_sorting("txs_count", "desc"), do: [{:desc_nulls_last, :transactions_count, :address}]
defp do_smart_contracts_sorting("transactions_count", "asc"), do: [{:asc_nulls_first, :transactions_count, :address}]
defp do_smart_contracts_sorting("transactions_count", "desc"), do: [{:desc_nulls_last, :transactions_count, :address}]
defp do_smart_contracts_sorting(_, _), do: []
@spec address_transactions_sorting(%{required(String.t()) => String.t()}) :: [

@ -247,9 +247,9 @@ defmodule BlockScoutWeb.Routers.ApiRouter do
scope "/optimism" do
if Application.compile_env(:explorer, :chain_type) == :optimism do
get("/txn-batches", V2.OptimismController, :txn_batches)
get("/txn-batches/count", V2.OptimismController, :txn_batches_count)
get("/txn-batches/:l2_block_range_start/:l2_block_range_end", V2.OptimismController, :txn_batches)
get("/txn-batches", V2.OptimismController, :transaction_batches)
get("/txn-batches/count", V2.OptimismController, :transaction_batches_count)
get("/txn-batches/:l2_block_range_start/:l2_block_range_end", V2.OptimismController, :transaction_batches)
get("/batches", V2.OptimismController, :batches)
get("/batches/count", V2.OptimismController, :batches_count)
get("/batches/da/celestia/:height/:commitment", V2.OptimismController, :batch_by_celestia_blob)
@ -388,7 +388,12 @@ defmodule BlockScoutWeb.Routers.ApiRouter do
get("/batches/count", V2.ArbitrumController, :batches_count)
get("/batches/:batch_number", V2.ArbitrumController, :batch)
get("/batches/da/anytrust/:data_hash", V2.ArbitrumController, :batch_by_data_availability_info)
get("/batches/da/celestia/:height/:tx_commitment", V2.ArbitrumController, :batch_by_data_availability_info)
get(
"/batches/da/celestia/:height/:transaction_commitment",
V2.ArbitrumController,
:batch_by_data_availability_info
)
end
end

@ -8,9 +8,9 @@
<div class="col-sm-10 card-body-account">
<%= form_for @tag_transaction, tag_transaction_path(@conn, :create), fn f -> %>
<div class="form-group">
<%= label f, :tx_hash, gettext("Transaction"), class: "control-label", style: "font-size: 14px" %>
<%= text_input f, :tx_hash, class: "form-control", placeholder: "0x0000000000000000000000000000000000000000000000000000000000000000", maxlength: 66 %>
<%= error_tag f, :tx_hash, class: "text-danger form-error" %>
<%= label f, :transaction_hash, gettext("Transaction"), class: "control-label", style: "font-size: 14px" %>
<%= text_input f, :transaction_hash, class: "form-control", placeholder: "0x0000000000000000000000000000000000000000000000000000000000000000", maxlength: 66 %>
<%= error_tag f, :transaction_hash, class: "text-danger form-error" %>
<%= error_tag f, :identity_id, class: "text-danger form-error" %>
</div>

@ -8,7 +8,7 @@
<br>
<div class="col-sm">
<div class="mb-3 row o-flow-x">
<%= if @tx_tags == [] do %>
<%= if @transaction_tags == [] do %>
<div style="min-width: 100%;">
<div class="tile tile-muted text-center" data-selector="empty-coin-balances-list">
<%= gettext "You don't have transaction tags yet" %>
@ -25,7 +25,7 @@
</tr>
</thead>
<tbody style="font-size: 15px; color: #6c757d" >
<%= Enum.map(@tx_tags, fn at ->
<%= Enum.map(@transaction_tags, fn at ->
render("row.html", tx_tag: at, conn: @conn)
end) %>
</tbody>
@ -33,7 +33,7 @@
<% end %>
</div>
</div>
<%= if Enum.count(@tx_tags) < TagTransaction.get_max_tags_count() do %>
<%= if Enum.count(@transaction_tags) < TagTransaction.get_max_tags_count() do %>
<a class="add-transaction-tag-button button button-primary button-sm" href="<%= tag_transaction_path(@conn, :new) %>"><%= gettext "Add transaction tag" %></a>
<% end %>
</div>

@ -1,14 +1,14 @@
<%= if @tx_tag.tx_hash do %>
<%= if @tx_tag.transaction_hash do %>
<tr>
<td><%= @tx_tag.name %></td>
<td>
<div>
<%= link(@tx_tag.tx_hash,
to: transaction_path(BlockScoutWeb.Endpoint, :show, @tx_tag.tx_hash),
<%= link(@tx_tag.transaction_hash,
to: transaction_path(BlockScoutWeb.Endpoint, :show, @tx_tag.transaction_hash),
"data-test": "transaction_hash_link",
class: "text-truncate") %>
<%= render BlockScoutWeb.CommonComponentsView, "_btn_copy.html",
additional_classes: ["btn-copy-icon-small", "btn-copy-icon-custom", "btn-copy-icon-no-borders"], clipboard_text: @tx_tag.tx_hash, aria_label: gettext("Copy Address"), title: gettext("Copy Address"), style: "display: inline-block; vertical-align: text-bottom; position: initial; margin-top: 1px;" %>
additional_classes: ["btn-copy-icon-small", "btn-copy-icon-custom", "btn-copy-icon-no-borders"], clipboard_text: @tx_tag.transaction_hash, aria_label: gettext("Copy Address"), title: gettext("Copy Address"), style: "display: inline-block; vertical-align: text-bottom; position: initial; margin-top: 1px;" %>
</div>
</td>
<td>

@ -27,7 +27,7 @@
<td class="stakes-td">
<span class="mr-4">
<span data-test="transaction_count">
<%= @tx_count %>
<%= @transaction_count %>
</span> <%= gettext "Transactions" %>
</span>
</td>

@ -19,10 +19,10 @@
</url>
<% end %>
<% txs = Chain.recent_transactions(params, [:validated]) %>
<%= for tx <- txs do %>
<% transactions = Chain.recent_transactions(params, [:validated]) %>
<%= for transaction <- transactions do %>
<url>
<loc><%= host %>/tx/<%= to_string(tx.hash) %></loc>
<loc><%= host %>/tx/<%= to_string(transaction.hash) %></loc>
<lastmod><%= date %></lastmod>
</url>
<% end %>

@ -1,4 +1,4 @@
<tr data-identifier-hash="<%= @result.address_hash %>-<%= if @result.tx_hash, do: Base.encode16(@result.tx_hash, case: :lower), else: "" %>-<%= if @result.block_hash, do: Base.encode16(@result.block_hash, case: :lower), else: "" %>">
<tr data-identifier-hash="<%= @result.address_hash %>-<%= if @result.transaction_hash, do: Base.encode16(@result.transaction_hash, case: :lower), else: "" %>-<%= if @result.block_hash, do: Base.encode16(@result.block_hash, case: :lower), else: "" %>">
<!-- incremented number by order in the list -->
<%= render BlockScoutWeb.SearchView, "_empty_td.html" %>
<%= case @result.type do %>
@ -79,7 +79,7 @@
<% "transaction" -> %>
<%= render BlockScoutWeb.TransactionView,
"_link.html",
transaction_hash: "0x" <> Base.encode16(@result.tx_hash, case: :lower) %>
transaction_hash: "0x" <> Base.encode16(@result.transaction_hash, case: :lower) %>
<% "user_operation" -> %>
<%= "0x" <> Base.encode16(@result.user_operation_hash, case: :lower) %>
<% "blob" -> %>

@ -1,5 +1,5 @@
<% status = transaction_status(@transaction) %>
<% error_in_internal_tx = @transaction.has_error_in_internal_txs %>
<% error_in_internal_transaction = @transaction.has_error_in_internal_transactions %>
<% current_user = AuthController.current_user(@conn) %>
<% tx_tags = BlockScoutWeb.Models.GetTransactionTags.get_transaction_with_addresses_tags(@transaction, current_user) %>
<div class="tile tile-type-<%= type_suffix(@transaction) %> fade-in <%= status_class(@transaction) %>" data-test="<%= type_suffix(@transaction) %>" data-identifier-hash="<%= @transaction.hash %>">
@ -7,7 +7,7 @@
<!-- Color Block -->
<div class="tile-transaction-type-block col-md-2 d-flex flex-row flex-md-column">
<div>
<%= if error_in_internal_tx do %>
<%= if error_in_internal_transaction do %>
<%= render BlockScoutWeb.CommonComponentsView, "_i_tooltip_2.html", text: gettext("Error in internal transactions"), additional_classes: ["color-inherit"] %>
<% end %>
<span class="tile-label" data-test="transaction_type">
@ -33,8 +33,8 @@
<%= if method_name do %>
<%= render BlockScoutWeb.FormView, "_tag.html", text: method_name, additional_classes: ["method", "ml-1"] %>
<% end %>
<%= if tx_tags.personal_tx_tag && tx_tags.personal_tx_tag.name !== :error do %>
<%= render BlockScoutWeb.FormView, "_tag.html", text: tx_tags.personal_tx_tag.name, additional_classes: [tag_name_to_label(tx_tags.personal_tx_tag.name), "ml-1"] %>
<%= if tx_tags.personal_transaction_tag && tx_tags.personal_transaction_tag.name !== :error do %>
<%= render BlockScoutWeb.FormView, "_tag.html", text: tx_tags.personal_transaction_tag.name, additional_classes: [tag_name_to_label(tx_tags.personal_transaction_tag.name), "ml-1"] %>
<% end %>
<%= render BlockScoutWeb.AddressView, "_labels.html", tags: tx_tags %>
</div>

@ -48,11 +48,11 @@
<h1 class="card-title">
<div style="display: inline-block; vertical-align: bottom; line-height: 25px;">
<%= gettext "Transaction Details" %>
<% personal_tx_tag = if assigns[:tx_tags], do: @tx_tags.personal_tx_tag, else: nil %>
<%= if personal_tx_tag && personal_tx_tag.name !== :error do %>
<%= render BlockScoutWeb.FormView, "_tag.html", text: personal_tx_tag.name, additional_classes: [tag_name_to_label(personal_tx_tag.name), "ml-1"] %>
<% personal_transaction_tag = if assigns[:tx_tags], do: @transaction_tags.personal_transaction_tag, else: nil %>
<%= if personal_transaction_tag && personal_transaction_tag.name !== :error do %>
<%= render BlockScoutWeb.FormView, "_tag.html", text: personal_transaction_tag.name, additional_classes: [tag_name_to_label(personal_transaction_tag.name), "ml-1"] %>
<% end %>
<%= render BlockScoutWeb.AddressView, "_labels.html", tags: @tx_tags %>
<%= render BlockScoutWeb.AddressView, "_labels.html", tags: @transaction_tags %>
</div>
</h1>
<%= if status == :pending do %>

@ -7,12 +7,14 @@ defmodule BlockScoutWeb.Account.Api.V2.TagsView do
tags_map: %{
personal_tags: personal_tags,
watchlist_names: watchlist_names,
personal_tx_tag: personal_tx_tag,
personal_transaction_tag: personal_transaction_tag,
common_tags: common_tags
}
}) do
%{
personal_tx_tag: prepare_transaction_tag(personal_tx_tag),
personal_transaction_tag: prepare_transaction_tag(personal_transaction_tag),
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `personal_transaction_tag` property
personal_tx_tag: prepare_transaction_tag(personal_transaction_tag),
personal_tags: personal_tags,
watchlist_names: watchlist_names,
common_tags: common_tags

@ -161,7 +161,11 @@ defmodule BlockScoutWeb.Account.Api.V2.UserView do
def prepare_transaction_tag(nil), do: nil
def prepare_transaction_tag(transaction_tag) do
%{"id" => transaction_tag.id, "transaction_hash" => transaction_tag.tx_hash, "name" => transaction_tag.name}
%{
"id" => transaction_tag.id,
"transaction_hash" => transaction_tag.transaction_hash,
"name" => transaction_tag.name
}
end
def prepare_public_tags_request(public_tags_request) do

@ -267,13 +267,13 @@ defmodule BlockScoutWeb.API.RPC.ContractView do
defp address_to_response(address) do
creator_hash = AddressView.from_address_hash(address)
creation_tx = creator_hash && AddressView.transaction_hash(address)
creation_transaction = creator_hash && AddressView.transaction_hash(address)
creation_tx &&
creation_transaction &&
%{
"contractAddress" => to_string(address.hash),
"contractCreator" => to_string(creator_hash),
"txHash" => to_string(creation_tx)
"txHash" => to_string(creation_transaction)
}
end
end

@ -15,7 +15,7 @@ defmodule BlockScoutWeb.API.RPC.TransactionView do
end
def render("gettxreceiptstatus.json", %{status: status}) do
prepared_status = prepare_tx_receipt_status(status)
prepared_status = prepare_transaction_receipt_status(status)
RPCView.render("show.json", data: %{"status" => prepared_status})
end
@ -27,13 +27,13 @@ defmodule BlockScoutWeb.API.RPC.TransactionView do
RPCView.render("error.json", assigns)
end
defp prepare_tx_receipt_status(""), do: ""
defp prepare_transaction_receipt_status(""), do: ""
defp prepare_tx_receipt_status(nil), do: ""
defp prepare_transaction_receipt_status(nil), do: ""
defp prepare_tx_receipt_status(:ok), do: "1"
defp prepare_transaction_receipt_status(:ok), do: "1"
defp prepare_tx_receipt_status(_), do: "0"
defp prepare_transaction_receipt_status(_), do: "0"
defp prepare_error("") do
%{

@ -73,11 +73,15 @@ defmodule BlockScoutWeb.API.V2.AddressView do
@spec prepare_address(
{atom() | %{:fetched_coin_balance => any(), :hash => any(), optional(any()) => any()}, any()}
| Explorer.Chain.Address.t()
) :: %{optional(:coin_balance) => any(), optional(:tx_count) => binary(), optional(<<_::32, _::_*8>>) => any()}
def prepare_address({address, tx_count}) do
) :: %{
optional(:coin_balance) => any(),
optional(:transaction_count) => binary(),
optional(<<_::32, _::_*8>>) => any()
}
def prepare_address({address, transaction_count}) do
nil
|> Helper.address_with_info(address, address.hash, true)
|> Map.put(:tx_count, to_string(tx_count))
|> Map.put(:transaction_count, to_string(transaction_count))
|> Map.put(:coin_balance, if(address.fetched_coin_balance, do: address.fetched_coin_balance.value))
end
@ -93,13 +97,15 @@ defmodule BlockScoutWeb.API.V2.AddressView do
creation_transaction = Address.creation_transaction(address)
creator_hash = creation_transaction && creation_transaction.from_address_hash
creation_tx = creator_hash && AddressView.transaction_hash(address)
creation_transaction_hash = creator_hash && AddressView.transaction_hash(address)
token = address.token && TokenView.render("token.json", %{token: address.token})
extended_info =
Map.merge(base_info, %{
"creator_address_hash" => creator_hash && Address.checksum(creator_hash),
"creation_tx_hash" => creation_tx,
"creation_transaction_hash" => creation_transaction_hash,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `creation_transaction_hash` property
"creation_tx_hash" => creation_transaction_hash,
"token" => token,
"coin_balance" => balance,
"exchange_rate" => exchange_rate,

@ -70,7 +70,7 @@ defmodule BlockScoutWeb.API.V2.ArbitrumView do
"before_acc" => batch.before_acc,
"after_acc" => batch.after_acc
}
|> add_l1_tx_info(batch)
|> add_l1_transaction_info(batch)
|> add_da_info(batch)
end
@ -170,7 +170,7 @@ defmodule BlockScoutWeb.API.V2.ArbitrumView do
"blocks_count" => batch.end_block - batch.start_block + 1,
"batch_data_container" => batch.batch_container
}
|> add_l1_tx_info(batch)
|> add_l1_transaction_info(batch)
end
@doc """
@ -245,7 +245,7 @@ defmodule BlockScoutWeb.API.V2.ArbitrumView do
}) :: map()
defp extend_with_settlement_info(out_json, arbitrum_entity) do
out_json
|> add_l1_txs_info_and_status(%{
|> add_l1_transactions_info_and_status(%{
batch_number: get_batch_number(arbitrum_entity),
commitment_transaction: arbitrum_entity.arbitrum_commitment_transaction,
confirmation_transaction: arbitrum_entity.arbitrum_confirmation_transaction
@ -285,25 +285,25 @@ defmodule BlockScoutWeb.API.V2.ArbitrumView do
end
# Augments an output JSON with commit transaction details and its status.
@spec add_l1_tx_info(map(), %{
@spec add_l1_transaction_info(map(), %{
:commitment_transaction => LifecycleTransaction.t() | LifecycleTransaction.to_import(),
optional(any()) => any()
}) :: map()
defp add_l1_tx_info(out_json, %L1Batch{} = batch) do
l1_tx = %{commitment_transaction: handle_associated_l1_txs_properly(batch.commitment_transaction)}
defp add_l1_transaction_info(out_json, %L1Batch{} = batch) do
l1_transaction = %{commitment_transaction: handle_associated_l1_transactions_properly(batch.commitment_transaction)}
out_json
|> Map.merge(%{
"commitment_transaction" => %{
"hash" => APIV2Helper.get_2map_data(l1_tx, :commitment_transaction, :hash),
"block_number" => APIV2Helper.get_2map_data(l1_tx, :commitment_transaction, :block),
"timestamp" => APIV2Helper.get_2map_data(l1_tx, :commitment_transaction, :ts),
"status" => APIV2Helper.get_2map_data(l1_tx, :commitment_transaction, :status)
"hash" => APIV2Helper.get_2map_data(l1_transaction, :commitment_transaction, :hash),
"block_number" => APIV2Helper.get_2map_data(l1_transaction, :commitment_transaction, :block),
"timestamp" => APIV2Helper.get_2map_data(l1_transaction, :commitment_transaction, :ts),
"status" => APIV2Helper.get_2map_data(l1_transaction, :commitment_transaction, :status)
}
})
end
defp add_l1_tx_info(out_json, %{
defp add_l1_transaction_info(out_json, %{
commitment_transaction: %{
hash: hash,
block_number: block_number,
@ -419,34 +419,36 @@ defmodule BlockScoutWeb.API.V2.ArbitrumView do
out
|> Map.merge(%{
"height" => Map.get(da_info, "height"),
"tx_commitment" => Map.get(da_info, "tx_commitment")
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `transaction_count` property
"tx_commitment" => Map.get(da_info, "transaction_commitment"),
"transaction_commitment" => Map.get(da_info, "transaction_commitment")
})
end
# Augments an output JSON with commit and confirm transaction details and their statuses.
@spec add_l1_txs_info_and_status(map(), %{
@spec add_l1_transactions_info_and_status(map(), %{
:commitment_transaction => any(),
:confirmation_transaction => any(),
optional(:batch_number) => any()
}) :: map()
defp add_l1_txs_info_and_status(out_json, arbitrum_item)
defp add_l1_transactions_info_and_status(out_json, arbitrum_item)
when is_map(arbitrum_item) and
is_map_key(arbitrum_item, :commitment_transaction) and
is_map_key(arbitrum_item, :confirmation_transaction) do
l1_txs = get_associated_l1_txs(arbitrum_item)
l1_transactions = get_associated_l1_transactions(arbitrum_item)
out_json
|> Map.merge(%{
"status" => block_or_transaction_status(arbitrum_item),
"commitment_transaction" => %{
"hash" => APIV2Helper.get_2map_data(l1_txs, :commitment_transaction, :hash),
"timestamp" => APIV2Helper.get_2map_data(l1_txs, :commitment_transaction, :ts),
"status" => APIV2Helper.get_2map_data(l1_txs, :commitment_transaction, :status)
"hash" => APIV2Helper.get_2map_data(l1_transactions, :commitment_transaction, :hash),
"timestamp" => APIV2Helper.get_2map_data(l1_transactions, :commitment_transaction, :ts),
"status" => APIV2Helper.get_2map_data(l1_transactions, :commitment_transaction, :status)
},
"confirmation_transaction" => %{
"hash" => APIV2Helper.get_2map_data(l1_txs, :confirmation_transaction, :hash),
"timestamp" => APIV2Helper.get_2map_data(l1_txs, :confirmation_transaction, :ts),
"status" => APIV2Helper.get_2map_data(l1_txs, :confirmation_transaction, :status)
"hash" => APIV2Helper.get_2map_data(l1_transactions, :confirmation_transaction, :hash),
"timestamp" => APIV2Helper.get_2map_data(l1_transactions, :confirmation_transaction, :ts),
"status" => APIV2Helper.get_2map_data(l1_transactions, :confirmation_transaction, :status)
}
})
end
@ -459,7 +461,7 @@ defmodule BlockScoutWeb.API.V2.ArbitrumView do
#
# ## Returns
# A map containing nesting maps describing corresponding L1 transactions
@spec get_associated_l1_txs(%{
@spec get_associated_l1_transactions(%{
:commitment_transaction => any(),
:confirmation_transaction => any(),
optional(any()) => any()
@ -481,15 +483,15 @@ defmodule BlockScoutWeb.API.V2.ArbitrumView do
:status => nil | :finalized | :unfinalized
}
}
defp get_associated_l1_txs(arbitrum_item) do
defp get_associated_l1_transactions(arbitrum_item) do
[:commitment_transaction, :confirmation_transaction]
|> Enum.reduce(%{}, fn key, l1_txs ->
Map.put(l1_txs, key, handle_associated_l1_txs_properly(Map.get(arbitrum_item, key)))
|> Enum.reduce(%{}, fn key, l1_transactions ->
Map.put(l1_transactions, key, handle_associated_l1_transactions_properly(Map.get(arbitrum_item, key)))
end)
end
# Returns details of an associated L1 transaction or nil if not loaded or not available.
@spec handle_associated_l1_txs_properly(LifecycleTransaction | Ecto.Association.NotLoaded.t() | nil) ::
@spec handle_associated_l1_transactions_properly(LifecycleTransaction | Ecto.Association.NotLoaded.t() | nil) ::
nil
| %{
:hash => nil | binary(),
@ -497,8 +499,8 @@ defmodule BlockScoutWeb.API.V2.ArbitrumView do
:ts => nil | DateTime.t(),
:status => nil | :finalized | :unfinalized
}
defp handle_associated_l1_txs_properly(associated_l1_tx) do
case associated_l1_tx do
defp handle_associated_l1_transactions_properly(associated_l1_transaction) do
case associated_l1_transaction do
nil -> nil
%Ecto.Association.NotLoaded{} -> nil
value -> %{hash: value.hash, block: value.block_number, ts: value.timestamp, status: value.status}
@ -531,7 +533,7 @@ defmodule BlockScoutWeb.API.V2.ArbitrumView do
# direction of the message, its status and the associated L1 transaction.
#
# ## Parameters
# - `arbitrum_tx`: An Arbitrum transaction.
# - `arbitrum_transaction`: An Arbitrum transaction.
#
# ## Returns
# - A map extended with fields indicating the direction of the message, its status
@ -542,15 +544,15 @@ defmodule BlockScoutWeb.API.V2.ArbitrumView do
:arbitrum_message_from_l2 => any(),
optional(any()) => any()
}) :: map()
defp extend_if_message(arbitrum_json, %Transaction{} = arbitrum_tx) do
defp extend_if_message(arbitrum_json, %Transaction{} = arbitrum_transaction) do
{message_type, message_data} =
case {APIV2Helper.specified?(Map.get(arbitrum_tx, :arbitrum_message_to_l2)),
APIV2Helper.specified?(Map.get(arbitrum_tx, :arbitrum_message_from_l2))} do
case {APIV2Helper.specified?(Map.get(arbitrum_transaction, :arbitrum_message_to_l2)),
APIV2Helper.specified?(Map.get(arbitrum_transaction, :arbitrum_message_from_l2))} do
{true, false} ->
{"incoming", l1_tx_and_status_for_message(arbitrum_tx, :incoming)}
{"incoming", l1_transaction_and_status_for_message(arbitrum_transaction, :incoming)}
{false, true} ->
{"outcoming", l1_tx_and_status_for_message(arbitrum_tx, :outcoming)}
{"outcoming", l1_transaction_and_status_for_message(arbitrum_transaction, :outcoming)}
_ ->
{nil, %{}}
@ -562,7 +564,7 @@ defmodule BlockScoutWeb.API.V2.ArbitrumView do
end
# Determines the associated L1 transaction and its status for the given message direction.
@spec l1_tx_and_status_for_message(
@spec l1_transaction_and_status_for_message(
%{
:__struct__ => Transaction,
:arbitrum_message_to_l2 => any(),
@ -571,20 +573,21 @@ defmodule BlockScoutWeb.API.V2.ArbitrumView do
},
:incoming | :outcoming
) :: map()
defp l1_tx_and_status_for_message(arbitrum_tx, message_direction) do
{l1_tx, status} =
defp l1_transaction_and_status_for_message(arbitrum_transaction, message_direction) do
{l1_transaction, status} =
case message_direction do
:incoming ->
l1_tx = APIV2Helper.get_2map_data(arbitrum_tx, :arbitrum_message_to_l2, :originating_transaction_hash)
l1_transaction =
APIV2Helper.get_2map_data(arbitrum_transaction, :arbitrum_message_to_l2, :originating_transaction_hash)
if is_nil(l1_tx) do
if is_nil(l1_transaction) do
{nil, "Syncing with base layer"}
else
{l1_tx, "Relayed"}
{l1_transaction, "Relayed"}
end
:outcoming ->
case APIV2Helper.get_2map_data(arbitrum_tx, :arbitrum_message_from_l2, :status) do
case APIV2Helper.get_2map_data(arbitrum_transaction, :arbitrum_message_from_l2, :status) do
:initiated ->
{nil, "Settlement pending"}
@ -595,12 +598,12 @@ defmodule BlockScoutWeb.API.V2.ArbitrumView do
{nil, "Ready for relay"}
:relayed ->
{APIV2Helper.get_2map_data(arbitrum_tx, :arbitrum_message_from_l2, :completion_transaction_hash),
{APIV2Helper.get_2map_data(arbitrum_transaction, :arbitrum_message_from_l2, :completion_transaction_hash),
"Relayed"}
end
end
%{"associated_l1_transaction" => l1_tx, "message_status" => status}
%{"associated_l1_transaction" => l1_transaction, "message_status" => status}
end
# Extends the output JSON with information from Arbitrum-specific fields of the transaction.
@ -611,14 +614,14 @@ defmodule BlockScoutWeb.API.V2.ArbitrumView do
:gas_price => Wei.t(),
optional(any()) => any()
}) :: map()
defp extend_with_transaction_info(out_json, %Transaction{} = arbitrum_tx) do
defp extend_with_transaction_info(out_json, %Transaction{} = arbitrum_transaction) do
# Map.get is only needed for the case when the module is compiled with
# chain_type different from "arbitrum", `|| 0` is used to avoid nil values
# for the transaction prior to the migration to Arbitrum specific BS build.
gas_used_for_l1 = Map.get(arbitrum_tx, :gas_used_for_l1, 0) || 0
gas_used_for_l1 = Map.get(arbitrum_transaction, :gas_used_for_l1, 0) || 0
gas_used = Map.get(arbitrum_tx, :gas_used, 0) || 0
gas_price = Map.get(arbitrum_tx, :gas_price, 0) || 0
gas_used = Map.get(arbitrum_transaction, :gas_used, 0) || 0
gas_price = Map.get(arbitrum_transaction, :gas_price, 0) || 0
gas_used_for_l2 =
gas_used

@ -36,6 +36,8 @@ defmodule BlockScoutWeb.API.V2.BlockView do
%{
"height" => block.number,
"timestamp" => block.timestamp,
"transaction_count" => count_transactions(block),
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `transaction_count` property
"tx_count" => count_transactions(block),
"miner" => Helper.address_with_info(nil, block.miner, block.miner_hash, false),
"size" => block.size,
@ -57,6 +59,8 @@ defmodule BlockScoutWeb.API.V2.BlockView do
"gas_used_percentage" => Block.gas_used_percentage(block),
"burnt_fees_percentage" => burnt_fees_percentage(burnt_fees, transaction_fees),
"type" => block |> BlockView.block_type() |> String.downcase(),
"transaction_fees" => transaction_fees,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `transaction_fees` property
"tx_fees" => transaction_fees,
"withdrawals_count" => count_withdrawals(block)
}
@ -93,7 +97,7 @@ defmodule BlockScoutWeb.API.V2.BlockView do
def burnt_fees_percentage(_, _), do: nil
def count_transactions(%Block{transactions: txs}) when is_list(txs), do: Enum.count(txs)
def count_transactions(%Block{transactions: transactions}) when is_list(transactions), do: Enum.count(transactions)
def count_transactions(_), do: nil
def count_withdrawals(%Block{withdrawals: withdrawals}) when is_list(withdrawals), do: Enum.count(withdrawals)

@ -1,9 +1,9 @@
defmodule BlockScoutWeb.API.V2.EthereumView do
alias Explorer.Chain.{Block, Transaction}
defp count_blob_transactions(%Block{transactions: txs}) when is_list(txs),
defp count_blob_transactions(%Block{transactions: transactions}) when is_list(transactions),
# EIP-2718 blob transaction type
do: Enum.count(txs, &(&1.type == 3))
do: Enum.count(transactions, &(&1.type == 3))
defp count_blob_transactions(_), do: nil

@ -83,7 +83,9 @@ defmodule BlockScoutWeb.API.V2.MudView do
defp prepare_world_for_list(%Address{} = address) do
%{
"address" => Helper.address_with_info(address, address.hash),
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `transaction_count` property
"tx_count" => address.transactions_count,
"transaction_count" => address.transactions_count,
"coin_balance" => if(address.fetched_coin_balance, do: address.fetched_coin_balance.value)
}
end

@ -13,7 +13,7 @@ defmodule BlockScoutWeb.API.V2.OptimismView do
Function to render GET requests to `/api/v2/optimism/txn-batches` endpoint.
"""
@spec render(binary(), map()) :: map() | list() | non_neg_integer()
def render("optimism_txn_batches.json", %{
def render("optimism_transaction_batches.json", %{
batches: batches,
next_page_params: next_page_params
}) do
@ -21,7 +21,7 @@ defmodule BlockScoutWeb.API.V2.OptimismView do
batches
|> Enum.map(fn batch ->
Task.async(fn ->
tx_count =
transaction_count =
Repo.replica().aggregate(
from(
t in Transaction,
@ -35,7 +35,11 @@ defmodule BlockScoutWeb.API.V2.OptimismView do
%{
"l2_block_number" => batch.l2_block_number,
"tx_count" => tx_count,
"transaction_count" => transaction_count,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `transaction_count` property
"tx_count" => transaction_count,
"l1_transaction_hashes" => batch.frame_sequence.l1_transaction_hashes,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `l1_transaction_hashes` property
"l1_tx_hashes" => batch.frame_sequence.l1_transaction_hashes,
"l1_timestamp" => batch.frame_sequence.l1_timestamp
}
@ -67,7 +71,11 @@ defmodule BlockScoutWeb.API.V2.OptimismView do
"l1_timestamp" => batch.l1_timestamp,
"l2_block_start" => from,
"l2_block_end" => to,
"tx_count" => batch.tx_count,
"transaction_count" => batch.transaction_count,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `transaction_count` property
"tx_count" => batch.transaction_count,
"l1_transaction_hashes" => batch.l1_transaction_hashes,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `l1_transaction_hashes` property
"l1_tx_hashes" => batch.l1_transaction_hashes,
"batch_data_container" => batch.batch_data_container
}
@ -100,6 +108,8 @@ defmodule BlockScoutWeb.API.V2.OptimismView do
%{
"l2_output_index" => r.l2_output_index,
"l2_block_number" => r.l2_block_number,
"l1_transaction_hash" => r.l1_transaction_hash,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `l1_transaction_hash` property
"l1_tx_hash" => r.l1_transaction_hash,
"l1_timestamp" => r.l1_timestamp,
"l1_block_number" => r.l1_block_number,
@ -155,11 +165,19 @@ defmodule BlockScoutWeb.API.V2.OptimismView do
Enum.map(deposits, fn deposit ->
%{
"l1_block_number" => deposit.l1_block_number,
"l2_transaction_hash" => deposit.l2_transaction_hash,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `l2_transaction_hash` property
"l2_tx_hash" => deposit.l2_transaction_hash,
"l1_block_timestamp" => deposit.l1_block_timestamp,
"l1_transaction_hash" => deposit.l1_transaction_hash,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `l1_transaction_hash` property
"l1_tx_hash" => deposit.l1_transaction_hash,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `l1_transaction_origin` property
"l1_tx_origin" => deposit.l1_transaction_origin,
"l2_tx_gas_limit" => deposit.l2_transaction.gas
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `l2_transaction_gas_limit` property
"l2_tx_gas_limit" => deposit.l2_transaction.gas,
"l1_transaction_origin" => deposit.l1_transaction_origin,
"l2_transaction_gas_limit" => deposit.l2_transaction.gas
}
end),
next_page_params: next_page_params
@ -174,8 +192,12 @@ defmodule BlockScoutWeb.API.V2.OptimismView do
%{
"l1_block_number" => deposit.l1_block_number,
"l1_block_timestamp" => deposit.l1_block_timestamp,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `l1_transaction_hash` property
"l1_tx_hash" => deposit.l1_transaction_hash,
"l2_tx_hash" => deposit.l2_transaction_hash
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `l2_transaction_hash` property
"l2_tx_hash" => deposit.l2_transaction_hash,
"l1_transaction_hash" => deposit.l1_transaction_hash,
"l2_transaction_hash" => deposit.l2_transaction_hash
}
end)
end
@ -228,9 +250,13 @@ defmodule BlockScoutWeb.API.V2.OptimismView do
"msg_nonce" => msg_nonce,
"msg_nonce_version" => msg_nonce_version,
"from" => Helper.address_with_info(conn, from_address, from_address_hash, w.from),
"l2_transaction_hash" => w.l2_transaction_hash,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `l2_transaction_hash` property
"l2_tx_hash" => w.l2_transaction_hash,
"l2_timestamp" => w.l2_timestamp,
"status" => status,
"l1_transaction_hash" => w.l1_transaction_hash,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `l1_transaction_hash` property
"l1_tx_hash" => w.l1_transaction_hash,
"challenge_period_end" => challenge_period_end
}
@ -275,6 +301,8 @@ defmodule BlockScoutWeb.API.V2.OptimismView do
%{
"internal_id" => frame_sequence.id,
"l1_timestamp" => frame_sequence.l1_timestamp,
"l1_transaction_hashes" => frame_sequence.l1_transaction_hashes,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `l1_transaction_hashes` property
"l1_tx_hashes" => frame_sequence.l1_transaction_hashes,
"batch_data_container" => batch_data_container
}

@ -52,10 +52,10 @@ defmodule BlockScoutWeb.API.V2.PolygonEdgeView do
count
end
def extend_transaction_json_response(out_json, tx_hash, connection) do
def extend_transaction_json_response(out_json, transaction_hash, connection) do
out_json
|> Map.put("polygon_edge_deposit", polygon_edge_deposit(tx_hash, connection))
|> Map.put("polygon_edge_withdrawal", polygon_edge_withdrawal(tx_hash, connection))
|> Map.put("polygon_edge_deposit", polygon_edge_deposit(transaction_hash, connection))
|> Map.put("polygon_edge_withdrawal", polygon_edge_withdrawal(transaction_hash, connection))
end
defp polygon_edge_deposit(transaction_hash, conn) do

@ -9,19 +9,19 @@ defmodule BlockScoutWeb.API.V2.PolygonZkevmView do
"""
@spec render(binary(), map()) :: map() | non_neg_integer()
def render("zkevm_batch.json", %{batch: batch}) do
sequence_tx_hash =
sequence_transaction_hash =
if Map.has_key?(batch, :sequence_transaction) and not is_nil(batch.sequence_transaction) do
batch.sequence_transaction.hash
end
verify_tx_hash =
verify_transaction_hash =
if Map.has_key?(batch, :verify_transaction) and not is_nil(batch.verify_transaction) do
batch.verify_transaction.hash
end
l2_transactions =
if Map.has_key?(batch, :l2_transactions) do
Enum.map(batch.l2_transactions, fn tx -> tx.hash end)
Enum.map(batch.l2_transactions, fn transaction -> transaction.hash end)
end
%{
@ -31,8 +31,12 @@ defmodule BlockScoutWeb.API.V2.PolygonZkevmView do
"transactions" => l2_transactions,
"global_exit_root" => batch.global_exit_root,
"acc_input_hash" => batch.acc_input_hash,
"sequence_tx_hash" => sequence_tx_hash,
"verify_tx_hash" => verify_tx_hash,
"sequence_transaction_hash" => sequence_transaction_hash,
"verify_transaction_hash" => verify_transaction_hash,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `sequence_transaction_hash` property
"sequence_tx_hash" => sequence_transaction_hash,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `verify_transaction_hash` property
"verify_tx_hash" => verify_transaction_hash,
"state_root" => batch.state_root
}
end
@ -141,12 +145,12 @@ defmodule BlockScoutWeb.API.V2.PolygonZkevmView do
defp render_zkevm_batches(batches) do
Enum.map(batches, fn batch ->
sequence_tx_hash =
sequence_transaction_hash =
if not is_nil(batch.sequence_transaction) do
batch.sequence_transaction.hash
end
verify_tx_hash =
verify_transaction_hash =
if not is_nil(batch.verify_transaction) do
batch.verify_transaction.hash
end
@ -155,9 +159,15 @@ defmodule BlockScoutWeb.API.V2.PolygonZkevmView do
"number" => batch.number,
"status" => batch_status(batch),
"timestamp" => batch.timestamp,
"transaction_count" => batch.l2_transactions_count,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `transaction_count` property
"tx_count" => batch.l2_transactions_count,
"sequence_tx_hash" => sequence_tx_hash,
"verify_tx_hash" => verify_tx_hash
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `sequence_transaction_hash` property
"sequence_tx_hash" => sequence_transaction_hash,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `verify_transaction_hash` property
"verify_tx_hash" => verify_transaction_hash,
"sequence_transaction_hash" => sequence_transaction_hash,
"verify_transaction_hash" => verify_transaction_hash
}
end)
end

@ -95,12 +95,14 @@ defmodule BlockScoutWeb.API.V2.SearchView do
end
def prepare_search_result(%{type: "transaction"} = search_result) do
tx_hash = hash_to_string(search_result.tx_hash)
transaction_hash = hash_to_string(search_result.transaction_hash)
%{
"type" => search_result.type,
"tx_hash" => tx_hash,
"url" => transaction_path(Endpoint, :show, tx_hash),
"transaction_hash" => transaction_hash,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `transaction_hash` property
"tx_hash" => transaction_hash,
"url" => transaction_path(Endpoint, :show, transaction_hash),
"timestamp" => search_result.timestamp,
"priority" => search_result.priority
}

@ -358,6 +358,8 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do
),
"compiler_version" => smart_contract.compiler_version,
"optimization_enabled" => smart_contract.optimization,
"transaction_count" => smart_contract.address.transactions_count,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `transaction_count` property
"tx_count" => smart_contract.address.transactions_count,
"language" => smart_contract_language(smart_contract),
"verified_at" => smart_contract.inserted_at,

@ -90,7 +90,11 @@ defmodule BlockScoutWeb.API.V2.StabilityView do
defp do_extend_with_stability_fees_info(transactions) when is_list(transactions) do
{transactions, _tokens_acc} =
Enum.map_reduce(transactions, %{}, fn transaction, tokens_acc ->
case Log.fetch_log_by_tx_hash_and_first_topic(transaction.hash, @transaction_fee_event_signature, @api_true) do
case Log.fetch_log_by_transaction_hash_and_first_topic(
transaction.hash,
@transaction_fee_event_signature,
@api_true
) do
fee_log when not is_nil(fee_log) ->
{:ok, _selector, mapping} = Log.find_and_decode(@transaction_fee_event_abi, fee_log, transaction.hash)

@ -9,7 +9,13 @@ defmodule BlockScoutWeb.API.V2.SuaveView do
@suave_bid_event "0x83481d5b04dea534715acad673a8177a46fc93882760f36bdc16ccac439d504e"
def extend_transaction_json_response(%Transaction{} = transaction, out_json, single_tx?, conn, watchlist_names) do
def extend_transaction_json_response(
%Transaction{} = transaction,
out_json,
single_transaction?,
conn,
watchlist_names
) do
if is_nil(Map.get(transaction, :execution_node_hash)) do
out_json
else
@ -48,7 +54,7 @@ defmodule BlockScoutWeb.API.V2.SuaveView do
conn,
execution_node,
execution_node_hash,
single_tx?,
single_transaction?,
watchlist_names
)
)
@ -60,7 +66,7 @@ defmodule BlockScoutWeb.API.V2.SuaveView do
conn,
wrapped_to_address,
wrapped_to_address_hash,
single_tx?,
single_transaction?,
watchlist_names
),
"gas_limit" => wrapped_gas,

@ -41,6 +41,8 @@ defmodule BlockScoutWeb.API.V2.TokenTransferView do
def prepare_token_transfer(token_transfer, _conn, decoded_input) do
%{
"transaction_hash" => token_transfer.transaction_hash,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `transaction_hash` property
"tx_hash" => token_transfer.transaction_hash,
"from" => Helper.address_with_info(nil, token_transfer.from_address, token_transfer.from_address_hash, false),
"to" => Helper.address_with_info(nil, token_transfer.to_address, token_transfer.to_address_hash, false),
@ -54,8 +56,8 @@ defmodule BlockScoutWeb.API.V2.TokenTransferView do
),
"method" => Transaction.method_name(token_transfer.transaction, decoded_input, true),
"block_hash" => to_string(token_transfer.block_hash),
"block_number" => to_string(token_transfer.block_number),
"log_index" => to_string(token_transfer.log_index)
"block_number" => token_transfer.block_number,
"log_index" => token_transfer.log_index
}
end

@ -36,8 +36,8 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
transactions
|> chain_type_transformations()
|> Enum.zip(decoded_transactions)
|> Enum.map(fn {tx, decoded_input} ->
prepare_transaction(tx, conn, false, block_height, watchlist_names, decoded_input)
|> Enum.map(fn {transaction, decoded_input} ->
prepare_transaction(transaction, conn, false, block_height, watchlist_names, decoded_input)
end),
"next_page_params" => next_page_params
}
@ -54,8 +54,8 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
transactions
|> chain_type_transformations()
|> Enum.zip(decoded_transactions)
|> Enum.map(fn {tx, decoded_input} ->
prepare_transaction(tx, conn, false, block_height, watchlist_names, decoded_input)
|> Enum.map(fn {transaction, decoded_input} ->
prepare_transaction(transaction, conn, false, block_height, watchlist_names, decoded_input)
end)
end
@ -68,7 +68,9 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
transactions
|> chain_type_transformations()
|> Enum.zip(decoded_transactions)
|> Enum.map(fn {tx, decoded_input} -> prepare_transaction(tx, conn, false, block_height, decoded_input) end),
|> Enum.map(fn {transaction, decoded_input} ->
prepare_transaction(transaction, conn, false, block_height, decoded_input)
end),
"next_page_params" => next_page_params
}
end
@ -86,7 +88,9 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
transactions
|> chain_type_transformations()
|> Enum.zip(decoded_transactions)
|> Enum.map(fn {tx, decoded_input} -> prepare_transaction(tx, conn, false, block_height, decoded_input) end)
|> Enum.map(fn {transaction, decoded_input} ->
prepare_transaction(transaction, conn, false, block_height, decoded_input)
end)
end
def render("transaction.json", %{transaction: transaction, conn: conn}) do
@ -166,12 +170,14 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
}
end
def render("logs.json", %{logs: logs, next_page_params: next_page_params, tx_hash: tx_hash}) do
def render("logs.json", %{logs: logs, next_page_params: next_page_params, transaction_hash: transaction_hash}) do
decoded_logs = decode_logs(logs, false)
%{
"items" =>
logs |> Enum.zip(decoded_logs) |> Enum.map(fn {log, decoded_log} -> prepare_log(log, tx_hash, decoded_log) end),
logs
|> Enum.zip(decoded_logs)
|> Enum.map(fn {log, decoded_log} -> prepare_log(log, transaction_hash, decoded_log) end),
"next_page_params" => next_page_params
}
end
@ -264,6 +270,8 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
false
),
"value" => internal_transaction.value,
"block_number" => internal_transaction.block_number,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `block_number` property
"block" => internal_transaction.block_number,
"timestamp" => (block && block.timestamp) || internal_transaction.block.timestamp,
"index" => internal_transaction.index,
@ -276,7 +284,9 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
decoded = process_decoded_log(decoded_log)
%{
"tx_hash" => get_tx_hash(transaction_or_hash),
"transaction_hash" => get_transaction_hash(transaction_or_hash),
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `transaction_hash` property
"tx_hash" => get_transaction_hash(transaction_or_hash),
"address" => Helper.address_with_info(nil, log.address, log.address_hash, tags_for_address_needed?),
"topics" => [
log.first_topic,
@ -315,11 +325,11 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
}
end
defp get_tx_hash(%Transaction{} = tx), do: to_string(tx.hash)
defp get_tx_hash(hash), do: to_string(hash)
defp get_transaction_hash(%Transaction{} = transaction), do: to_string(transaction.hash)
defp get_transaction_hash(hash), do: to_string(hash)
defp smart_contract_info(%Transaction{} = tx),
do: Helper.address_with_info(nil, tx.to_address, tx.to_address_hash, false)
defp smart_contract_info(%Transaction{} = transaction),
do: Helper.address_with_info(nil, transaction.to_address, transaction.to_address_hash, false)
defp smart_contract_info(_), do: nil
@ -333,12 +343,12 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
end
end
defp prepare_transaction(tx, conn, single_tx?, block_height, watchlist_names \\ nil, decoded_input)
defp prepare_transaction(transaction, conn, single_transaction?, block_height, watchlist_names \\ nil, decoded_input)
defp prepare_transaction(
{%Reward{} = emission_reward, %Reward{} = validator_reward},
conn,
single_tx?,
single_transaction?,
_block_height,
_watchlist_names,
_decoded_input
@ -347,19 +357,31 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
"emission_reward" => emission_reward.reward,
"block_hash" => validator_reward.block_hash,
"from" =>
Helper.address_with_info(single_tx? && conn, emission_reward.address, emission_reward.address_hash, single_tx?),
Helper.address_with_info(
single_transaction? && conn,
emission_reward.address,
emission_reward.address_hash,
single_transaction?
),
"to" =>
Helper.address_with_info(
single_tx? && conn,
single_transaction? && conn,
validator_reward.address,
validator_reward.address_hash,
single_tx?
single_transaction?
),
"types" => [:reward]
}
end
defp prepare_transaction(%Transaction{} = transaction, conn, single_tx?, block_height, watchlist_names, decoded_input) do
defp prepare_transaction(
%Transaction{} = transaction,
conn,
single_transaction?,
block_height,
watchlist_names,
decoded_input
) do
base_fee_per_gas = transaction.block && transaction.block.base_fee_per_gas
max_priority_fee_per_gas = transaction.max_priority_fee_per_gas
max_fee_per_gas = transaction.max_fee_per_gas
@ -378,30 +400,32 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
"hash" => transaction.hash,
"result" => status,
"status" => transaction.status,
"block_number" => transaction.block_number,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `block_number` property
"block" => transaction.block_number,
"timestamp" => block_timestamp(transaction),
"from" =>
Helper.address_with_info(
single_tx? && conn,
single_transaction? && conn,
transaction.from_address,
transaction.from_address_hash,
single_tx?,
single_transaction?,
watchlist_names
),
"to" =>
Helper.address_with_info(
single_tx? && conn,
single_transaction? && conn,
transaction.to_address,
transaction.to_address_hash,
single_tx?,
single_transaction?,
watchlist_names
),
"created_contract" =>
Helper.address_with_info(
single_tx? && conn,
single_transaction? && conn,
transaction.created_contract_address,
transaction.created_contract_address_hash,
single_tx?,
single_transaction?,
watchlist_names
),
"confirmations" => transaction.block |> Chain.confirmations(block_height: block_height) |> format_confirmations(),
@ -422,19 +446,26 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
"revert_reason" => revert_reason,
"raw_input" => transaction.input,
"decoded_input" => decoded_input_data,
"token_transfers" => token_transfers(transaction.token_transfers, conn, single_tx?),
"token_transfers_overflow" => token_transfers_overflow(transaction.token_transfers, single_tx?),
"token_transfers" => token_transfers(transaction.token_transfers, conn, single_transaction?),
"token_transfers_overflow" => token_transfers_overflow(transaction.token_transfers, single_transaction?),
"actions" => transaction_actions(transaction.transaction_actions),
"exchange_rate" => Market.get_coin_exchange_rate().usd_value,
"method" => Transaction.method_name(transaction, decoded_input),
"tx_types" => tx_types(transaction),
"tx_tag" => GetTransactionTags.get_transaction_tags(transaction.hash, current_user(single_tx? && conn)),
"has_error_in_internal_txs" => transaction.has_error_in_internal_txs,
"transaction_types" => transaction_types(transaction),
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `transaction_types` property
"tx_types" => transaction_types(transaction),
"transaction_tag" =>
GetTransactionTags.get_transaction_tags(transaction.hash, current_user(single_transaction? && conn)),
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `transaction_tag` property
"tx_tag" => GetTransactionTags.get_transaction_tags(transaction.hash, current_user(single_transaction? && conn)),
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `has_error_in_internal_transactions` property
"has_error_in_internal_txs" => transaction.has_error_in_internal_transactions,
"has_error_in_internal_transactions" => transaction.has_error_in_internal_transactions,
"authorization_list" => authorization_list(transaction.signed_authorizations)
}
result
|> chain_type_fields(transaction, single_tx?, conn, watchlist_names)
|> chain_type_fields(transaction, single_transaction?, conn, watchlist_names)
end
def token_transfers(_, _conn, false), do: nil
@ -512,7 +543,7 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
end
@doc """
Prepares decoded tx info
Prepares decoded transaction info
"""
@spec decoded_input(any()) :: map() | nil
def decoded_input(decoded_input) do
@ -589,14 +620,14 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
end
@doc """
Returns array of token types for tx.
Returns array of token types for transaction.
"""
@spec tx_types(
@spec transaction_types(
Explorer.Chain.Transaction.t(),
[tx_type],
tx_type
) :: [tx_type]
when tx_type:
[transaction_type],
transaction_type
) :: [transaction_type]
when transaction_type:
:coin_transfer
| :contract_call
| :contract_creation
@ -606,9 +637,9 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
| :token_transfer
| :blob_transaction
| :set_code_transaction
def tx_types(tx, types \\ [], stage \\ :set_code_transaction)
def transaction_types(transaction, types \\ [], stage \\ :set_code_transaction)
def tx_types(%Transaction{type: type} = tx, types, :set_code_transaction) do
def transaction_types(%Transaction{type: type} = transaction, types, :set_code_transaction) do
# EIP-7702 set code transaction type
types =
if type == 4 do
@ -617,10 +648,10 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
types
end
tx_types(tx, types, :blob_transaction)
transaction_types(transaction, types, :blob_transaction)
end
def tx_types(%Transaction{type: type} = tx, types, :blob_transaction) do
def transaction_types(%Transaction{type: type} = transaction, types, :blob_transaction) do
# EIP-2718 blob transaction type
types =
if type == 3 do
@ -629,22 +660,26 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
types
end
tx_types(tx, types, :token_transfer)
transaction_types(transaction, types, :token_transfer)
end
def tx_types(%Transaction{token_transfers: token_transfers} = tx, types, :token_transfer) do
def transaction_types(%Transaction{token_transfers: token_transfers} = transaction, types, :token_transfer) do
types =
if (!is_nil(token_transfers) && token_transfers != [] && !match?(%NotLoaded{}, token_transfers)) ||
tx.has_token_transfers do
transaction.has_token_transfers do
[:token_transfer | types]
else
types
end
tx_types(tx, types, :token_creation)
transaction_types(transaction, types, :token_creation)
end
def tx_types(%Transaction{created_contract_address: created_contract_address} = tx, types, :token_creation) do
def transaction_types(
%Transaction{created_contract_address: created_contract_address} = transaction,
types,
:token_creation
) do
types =
if match?(%Address{}, created_contract_address) && match?(%Token{}, created_contract_address.token) do
[:token_creation | types]
@ -652,11 +687,11 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
types
end
tx_types(tx, types, :contract_creation)
transaction_types(transaction, types, :contract_creation)
end
def tx_types(
%Transaction{to_address_hash: to_address_hash} = tx,
def transaction_types(
%Transaction{to_address_hash: to_address_hash} = transaction,
types,
:contract_creation
) do
@ -667,10 +702,10 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
types
end
tx_types(tx, types, :contract_call)
transaction_types(transaction, types, :contract_call)
end
def tx_types(%Transaction{to_address: to_address} = tx, types, :contract_call) do
def transaction_types(%Transaction{to_address: to_address} = transaction, types, :contract_call) do
types =
if Address.smart_contract?(to_address) do
[:contract_call | types]
@ -678,10 +713,10 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
types
end
tx_types(tx, types, :coin_transfer)
transaction_types(transaction, types, :coin_transfer)
end
def tx_types(%Transaction{value: value} = tx, types, :coin_transfer) do
def transaction_types(%Transaction{value: value} = transaction, types, :coin_transfer) do
types =
if Decimal.compare(value.value, 0) == :gt do
[:coin_transfer | types]
@ -689,22 +724,22 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
types
end
tx_types(tx, types, :rootstock_remasc)
transaction_types(transaction, types, :rootstock_remasc)
end
def tx_types(tx, types, :rootstock_remasc) do
def transaction_types(transaction, types, :rootstock_remasc) do
types =
if Transaction.rootstock_remasc_transaction?(tx) do
if Transaction.rootstock_remasc_transaction?(transaction) do
[:rootstock_remasc | types]
else
types
end
tx_types(tx, types, :rootstock_bridge)
transaction_types(transaction, types, :rootstock_bridge)
end
def tx_types(tx, types, :rootstock_bridge) do
if Transaction.rootstock_bridge_transaction?(tx) do
def transaction_types(transaction, types, :rootstock_bridge) do
if Transaction.rootstock_bridge_transaction?(transaction) do
[:rootstock_bridge | types]
else
types
@ -776,8 +811,8 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
transactions
end
defp chain_type_fields(result, transaction, single_tx?, conn, _watchlist_names) do
if single_tx? do
defp chain_type_fields(result, transaction, single_transaction?, conn, _watchlist_names) do
if single_transaction? do
# credo:disable-for-next-line Credo.Check.Design.AliasUsage
BlockScoutWeb.API.V2.PolygonEdgeView.extend_transaction_json_response(result, transaction.hash, conn)
else
@ -790,8 +825,8 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
transactions
end
defp chain_type_fields(result, transaction, single_tx?, _conn, _watchlist_names) do
if single_tx? do
defp chain_type_fields(result, transaction, single_transaction?, _conn, _watchlist_names) do
if single_transaction? do
# credo:disable-for-next-line Credo.Check.Design.AliasUsage
BlockScoutWeb.API.V2.PolygonZkevmView.extend_transaction_json_response(result, transaction)
else
@ -804,8 +839,8 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
transactions
end
defp chain_type_fields(result, transaction, single_tx?, _conn, _watchlist_names) do
if single_tx? do
defp chain_type_fields(result, transaction, single_transaction?, _conn, _watchlist_names) do
if single_transaction? do
# credo:disable-for-next-line Credo.Check.Design.AliasUsage
BlockScoutWeb.API.V2.ZkSyncView.extend_transaction_json_response(result, transaction)
else
@ -818,8 +853,8 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
transactions
end
defp chain_type_fields(result, transaction, single_tx?, _conn, _watchlist_names) do
if single_tx? do
defp chain_type_fields(result, transaction, single_transaction?, _conn, _watchlist_names) do
if single_transaction? do
# credo:disable-for-next-line Credo.Check.Design.AliasUsage
BlockScoutWeb.API.V2.ArbitrumView.extend_transaction_json_response(result, transaction)
else
@ -832,8 +867,8 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
transactions
end
defp chain_type_fields(result, transaction, single_tx?, _conn, _watchlist_names) do
if single_tx? do
defp chain_type_fields(result, transaction, single_transaction?, _conn, _watchlist_names) do
if single_transaction? do
# credo:disable-for-next-line Credo.Check.Design.AliasUsage
BlockScoutWeb.API.V2.OptimismView.extend_transaction_json_response(result, transaction)
else
@ -846,13 +881,13 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
transactions
end
defp chain_type_fields(result, transaction, single_tx?, conn, watchlist_names) do
if single_tx? do
defp chain_type_fields(result, transaction, single_transaction?, conn, watchlist_names) do
if single_transaction? do
# credo:disable-for-next-line Credo.Check.Design.AliasUsage
BlockScoutWeb.API.V2.SuaveView.extend_transaction_json_response(
transaction,
result,
single_tx?,
single_transaction?,
conn,
watchlist_names
)
@ -867,7 +902,7 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
BlockScoutWeb.API.V2.StabilityView.transform_transactions(transactions)
end
defp chain_type_fields(result, transaction, _single_tx?, _conn, _watchlist_names) do
defp chain_type_fields(result, transaction, _single_transaction?, _conn, _watchlist_names) do
# credo:disable-for-next-line Credo.Check.Design.AliasUsage
BlockScoutWeb.API.V2.StabilityView.extend_transaction_json_response(result, transaction)
end
@ -877,7 +912,7 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
transactions
end
defp chain_type_fields(result, transaction, _single_tx?, _conn, _watchlist_names) do
defp chain_type_fields(result, transaction, _single_transaction?, _conn, _watchlist_names) do
# credo:disable-for-next-line Credo.Check.Design.AliasUsage
BlockScoutWeb.API.V2.EthereumView.extend_transaction_json_response(result, transaction)
end
@ -887,7 +922,7 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
transactions
end
defp chain_type_fields(result, transaction, _single_tx?, _conn, _watchlist_names) do
defp chain_type_fields(result, transaction, _single_transaction?, _conn, _watchlist_names) do
# credo:disable-for-next-line Credo.Check.Design.AliasUsage
BlockScoutWeb.API.V2.CeloView.extend_transaction_json_response(result, transaction)
end
@ -897,7 +932,7 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
transactions
end
defp chain_type_fields(result, _transaction, _single_tx?, _conn, _watchlist_names) do
defp chain_type_fields(result, _transaction, _single_transaction?, _conn, _watchlist_names) do
result
end
end

@ -15,14 +15,18 @@ defmodule BlockScoutWeb.API.V2.ZkSyncView do
"number" => batch.number,
"timestamp" => batch.timestamp,
"root_hash" => batch.root_hash,
"l1_tx_count" => batch.l1_tx_count,
"l2_tx_count" => batch.l2_tx_count,
"l1_transaction_count" => batch.l1_transaction_count,
"l2_transaction_count" => batch.l2_transaction_count,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `l1_transaction_count` property
"l1_tx_count" => batch.l1_transaction_count,
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `l2_transaction_count` property
"l2_tx_count" => batch.l2_transaction_count,
"l1_gas_price" => batch.l1_gas_price,
"l2_fair_gas_price" => batch.l2_fair_gas_price,
"start_block" => batch.start_block,
"end_block" => batch.end_block
}
|> add_l1_txs_info_and_status(batch)
|> add_l1_transactions_info_and_status(batch)
end
@doc """
@ -64,9 +68,11 @@ defmodule BlockScoutWeb.API.V2.ZkSyncView do
%{
"number" => batch.number,
"timestamp" => batch.timestamp,
"tx_count" => batch.l1_tx_count + batch.l2_tx_count
# todo: keep next line for compatibility with frontend and remove when new frontend is bound to `transaction_count` property
"tx_count" => batch.l1_transaction_count + batch.l2_transaction_count,
"transaction_count" => batch.l1_transaction_count + batch.l2_transaction_count
}
|> add_l1_txs_info_and_status(batch)
|> add_l1_transactions_info_and_status(batch)
end)
end
@ -119,7 +125,7 @@ defmodule BlockScoutWeb.API.V2.ZkSyncView do
defp do_add_zksync_info(out_json, zksync_entity) do
res =
%{}
|> do_add_l1_txs_info_and_status(%{
|> do_add_l1_transactions_info_and_status(%{
batch_number: get_batch_number(zksync_entity),
commit_transaction: zksync_entity.zksync_commit_transaction,
prove_transaction: zksync_entity.zksync_prove_transaction,
@ -138,22 +144,22 @@ defmodule BlockScoutWeb.API.V2.ZkSyncView do
end
end
defp add_l1_txs_info_and_status(out_json, %TransactionBatch{} = batch) do
do_add_l1_txs_info_and_status(out_json, batch)
defp add_l1_transactions_info_and_status(out_json, %TransactionBatch{} = batch) do
do_add_l1_transactions_info_and_status(out_json, batch)
end
defp do_add_l1_txs_info_and_status(out_json, zksync_item) do
l1_txs = get_associated_l1_txs(zksync_item)
defp do_add_l1_transactions_info_and_status(out_json, zksync_item) do
l1_transactions = get_associated_l1_transactions(zksync_item)
out_json
|> Map.merge(%{
"status" => batch_status(zksync_item),
"commit_transaction_hash" => APIV2Helper.get_2map_data(l1_txs, :commit_transaction, :hash),
"commit_transaction_timestamp" => APIV2Helper.get_2map_data(l1_txs, :commit_transaction, :ts),
"prove_transaction_hash" => APIV2Helper.get_2map_data(l1_txs, :prove_transaction, :hash),
"prove_transaction_timestamp" => APIV2Helper.get_2map_data(l1_txs, :prove_transaction, :ts),
"execute_transaction_hash" => APIV2Helper.get_2map_data(l1_txs, :execute_transaction, :hash),
"execute_transaction_timestamp" => APIV2Helper.get_2map_data(l1_txs, :execute_transaction, :ts)
"commit_transaction_hash" => APIV2Helper.get_2map_data(l1_transactions, :commit_transaction, :hash),
"commit_transaction_timestamp" => APIV2Helper.get_2map_data(l1_transactions, :commit_transaction, :ts),
"prove_transaction_hash" => APIV2Helper.get_2map_data(l1_transactions, :prove_transaction, :hash),
"prove_transaction_timestamp" => APIV2Helper.get_2map_data(l1_transactions, :prove_transaction, :ts),
"execute_transaction_hash" => APIV2Helper.get_2map_data(l1_transactions, :execute_transaction, :hash),
"execute_transaction_timestamp" => APIV2Helper.get_2map_data(l1_transactions, :execute_transaction, :ts)
})
end
@ -165,13 +171,13 @@ defmodule BlockScoutWeb.API.V2.ZkSyncView do
#
# ## Returns
# A map containing nesting maps describing corresponding L1 transactions
defp get_associated_l1_txs(zksync_item) do
defp get_associated_l1_transactions(zksync_item) do
[:commit_transaction, :prove_transaction, :execute_transaction]
|> Enum.reduce(%{}, fn key, l1_txs ->
|> Enum.reduce(%{}, fn key, l1_transactions ->
case Map.get(zksync_item, key) do
nil -> Map.put(l1_txs, key, nil)
%Ecto.Association.NotLoaded{} -> Map.put(l1_txs, key, nil)
value -> Map.put(l1_txs, key, %{hash: value.hash, ts: value.timestamp})
nil -> Map.put(l1_transactions, key, nil)
%Ecto.Association.NotLoaded{} -> Map.put(l1_transactions, key, nil)
value -> Map.put(l1_transactions, key, %{hash: value.hash, ts: value.timestamp})
end
end)
end

@ -24,7 +24,7 @@ defmodule BlockScoutWeb.TabHelper do
"active"
else
case request_path do
"/tx/" <> "0x" <> <<_tx_hash::binary-size(64)>> ->
"/tx/" <> "0x" <> <<_transaction_hash::binary-size(64)>> ->
tab_status_selector(tab_name, show_token_transfers)
_ ->

@ -22,8 +22,8 @@ defmodule BlockScoutWeb.TransactionStateView do
Decimal.abs(val)
end
def has_state_changes?(tx) do
has_diff?(from_loss(tx)) or has_diff?(to_profit(tx))
def has_state_changes?(transaction) do
has_diff?(from_loss(transaction)) or has_diff?(to_profit(transaction))
end
def display_value(balance, :coin, _token_id) do

@ -237,9 +237,9 @@ defmodule BlockScoutWeb.WebsocketV2Test do
Subscriber.to(:transactions, :realtime)
Import.all(@import_data)
assert_receive {:chain_event, :transactions, :realtime, txs}, :timer.seconds(5)
assert_receive {:chain_event, :transactions, :realtime, transactions}, :timer.seconds(5)
Notifier.handle_event({:chain_event, :transactions, :realtime, txs})
Notifier.handle_event({:chain_event, :transactions, :realtime, transactions})
assert_receive %Phoenix.Socket.Message{
payload: %{transaction: 2},
@ -280,7 +280,7 @@ defmodule BlockScoutWeb.WebsocketV2Test do
:timer.seconds(5)
end
test "broadcast array of txs to address" do
test "broadcast array of transactions to address" do
topic = "addresses:0x8bf38d4764929064f2d4d3a56520a76ab3df415b"
{:ok, _reply, _socket} =
@ -291,34 +291,34 @@ defmodule BlockScoutWeb.WebsocketV2Test do
Subscriber.to(:transactions, :realtime)
Import.all(@import_data)
assert_receive {:chain_event, :transactions, :realtime, txs}, :timer.seconds(5)
Notifier.handle_event({:chain_event, :transactions, :realtime, txs})
assert_receive {:chain_event, :transactions, :realtime, transactions}, :timer.seconds(5)
Notifier.handle_event({:chain_event, :transactions, :realtime, transactions})
assert_receive %Phoenix.Socket.Message{
payload: %{transactions: [tx_1, tx_2]},
payload: %{transactions: [transaction_1, transaction_2]},
event: "transaction",
topic: ^topic
},
:timer.seconds(5)
tx_1 = tx_1 |> Jason.encode!() |> Jason.decode!()
compare_item(Repo.get_by(Transaction, %{hash: tx_1["hash"]}), tx_1)
transaction_1 = transaction_1 |> Jason.encode!() |> Jason.decode!()
compare_item(Repo.get_by(Transaction, %{hash: transaction_1["hash"]}), transaction_1)
tx_2 = tx_2 |> Jason.encode!() |> Jason.decode!()
compare_item(Repo.get_by(Transaction, %{hash: tx_2["hash"]}), tx_2)
transaction_2 = transaction_2 |> Jason.encode!() |> Jason.decode!()
compare_item(Repo.get_by(Transaction, %{hash: transaction_2["hash"]}), transaction_2)
assert_receive %Phoenix.Socket.Message{
payload: %{transactions: [tx_1, tx_2]},
payload: %{transactions: [transaction_1, transaction_2]},
event: "pending_transaction",
topic: ^topic
},
:timer.seconds(5)
tx_1 = tx_1 |> Jason.encode!() |> Jason.decode!()
compare_item(Repo.get_by(Transaction, %{hash: tx_1["hash"]}), tx_1)
transaction_1 = transaction_1 |> Jason.encode!() |> Jason.decode!()
compare_item(Repo.get_by(Transaction, %{hash: transaction_1["hash"]}), transaction_1)
tx_2 = tx_2 |> Jason.encode!() |> Jason.decode!()
compare_item(Repo.get_by(Transaction, %{hash: tx_2["hash"]}), tx_2)
transaction_2 = transaction_2 |> Jason.encode!() |> Jason.decode!()
compare_item(Repo.get_by(Transaction, %{hash: transaction_2["hash"]}), transaction_2)
end
test "broadcast array of transfers to address" do
@ -369,17 +369,17 @@ defmodule BlockScoutWeb.WebsocketV2Test do
defp compare_item(%TokenTransfer{} = token_transfer, json) do
assert Address.checksum(token_transfer.from_address_hash) == json["from"]["hash"]
assert Address.checksum(token_transfer.to_address_hash) == json["to"]["hash"]
assert to_string(token_transfer.transaction_hash) == json["tx_hash"]
assert to_string(token_transfer.transaction_hash) == json["transaction_hash"]
assert json["timestamp"] != nil
assert json["method"] != nil
assert to_string(token_transfer.block_hash) == json["block_hash"]
assert to_string(token_transfer.log_index) == json["log_index"]
assert token_transfer.log_index == json["log_index"]
assert check_total(Repo.preload(token_transfer, [{:token, :contract_address}]).token, json["total"], token_transfer)
end
defp compare_item(%Transaction{} = transaction, json) do
assert to_string(transaction.hash) == json["hash"]
assert transaction.block_number == json["block"]
assert transaction.block_number == json["block_number"]
assert to_string(transaction.value.value) == json["value"]
assert Address.checksum(transaction.from_address_hash) == json["from"]["hash"]
assert Address.checksum(transaction.to_address_hash) == json["to"]["hash"]

@ -274,32 +274,32 @@ defmodule BlockScoutWeb.Account.Api.V2.UserControllerTest do
end
test "post private transaction tag", %{conn: conn} do
tx_hash_non_existing = to_string(build(:transaction).hash)
tx_hash = to_string(insert(:transaction).hash)
transaction_hash_non_existing = to_string(build(:transaction).hash)
transaction_hash = to_string(insert(:transaction).hash)
assert conn
|> post("/api/account/v2/user/tags/transaction", %{
"transaction_hash" => tx_hash_non_existing,
"transaction_hash" => transaction_hash_non_existing,
"name" => "MyName"
})
|> doc(description: "Error on try to create private transaction tag for tx does not exist")
|> json_response(422) == %{"errors" => %{"tx_hash" => ["Transaction does not exist"]}}
|> doc(description: "Error on try to create private transaction tag for transaction does not exist")
|> json_response(422) == %{"errors" => %{"transaction_hash" => ["Transaction does not exist"]}}
tag_transaction_response =
conn
|> post("/api/account/v2/user/tags/transaction", %{
"transaction_hash" => tx_hash,
"transaction_hash" => transaction_hash,
"name" => "MyName"
})
|> doc(description: "Create private transaction tag")
|> json_response(200)
conn
|> get("/api/account/v2/tags/transaction/#{tx_hash}")
|> get("/api/account/v2/tags/transaction/#{transaction_hash}")
|> doc(description: "Get tags for transaction")
|> json_response(200)
assert tag_transaction_response["transaction_hash"] == tx_hash
assert tag_transaction_response["transaction_hash"] == transaction_hash
assert tag_transaction_response["name"] == "MyName"
assert tag_transaction_response["id"]
end
@ -349,11 +349,11 @@ defmodule BlockScoutWeb.Account.Api.V2.UserControllerTest do
end
test "edit private transaction tag", %{conn: conn} do
tx_tag = build(:tag_transaction)
transaction_tag = build(:tag_transaction)
tag_response =
conn
|> post("/api/account/v2/user/tags/transaction", tx_tag)
|> post("/api/account/v2/user/tags/transaction", transaction_tag)
|> json_response(200)
_response =
@ -361,20 +361,20 @@ defmodule BlockScoutWeb.Account.Api.V2.UserControllerTest do
|> get("/api/account/v2/user/tags/transaction")
|> json_response(200) == [tag_response]
assert tag_response["address_hash"] == tx_tag["address_hash"]
assert tag_response["name"] == tx_tag["name"]
assert tag_response["address_hash"] == transaction_tag["address_hash"]
assert tag_response["name"] == transaction_tag["name"]
assert tag_response["id"]
new_tx_tag = build(:tag_transaction)
new_transaction_tag = build(:tag_transaction)
new_tag_response =
conn
|> put("/api/account/v2/user/tags/transaction/#{tag_response["id"]}", new_tx_tag)
|> put("/api/account/v2/user/tags/transaction/#{tag_response["id"]}", new_transaction_tag)
|> doc(description: "Edit private transaction tag")
|> json_response(200)
assert new_tag_response["address_hash"] == new_tx_tag["address_hash"]
assert new_tag_response["name"] == new_tx_tag["name"]
assert new_tag_response["address_hash"] == new_transaction_tag["address_hash"]
assert new_tag_response["name"] == new_transaction_tag["name"]
assert new_tag_response["id"] == tag_response["id"]
end
@ -384,25 +384,25 @@ defmodule BlockScoutWeb.Account.Api.V2.UserControllerTest do
zipped = Enum.zip(transactions, names)
created =
Enum.map(zipped, fn {tx_hash, name} ->
Enum.map(zipped, fn {transaction_hash, name} ->
id =
(conn
|> post("/api/account/v2/user/tags/transaction", %{
"transaction_hash" => tx_hash,
"transaction_hash" => transaction_hash,
"name" => name
})
|> json_response(200))["id"]
{tx_hash, %{"label" => name}, %{"transaction_hash" => tx_hash, "id" => id, "name" => name}}
{transaction_hash, %{"label" => name}, %{"transaction_hash" => transaction_hash, "id" => id, "name" => name}}
end)
assert Enum.all?(created, fn {tx_hash, map_tag, _} ->
assert Enum.all?(created, fn {transaction_hash, map_tag, _} ->
response =
conn
|> get("/api/account/v2/tags/transaction/#{tx_hash}")
|> get("/api/account/v2/tags/transaction/#{transaction_hash}")
|> json_response(200)
response["personal_tx_tag"] == map_tag
response["personal_transaction_tag"] == map_tag
end)
response =
@ -421,25 +421,25 @@ defmodule BlockScoutWeb.Account.Api.V2.UserControllerTest do
zipped = Enum.zip(transactions, names)
created =
Enum.map(zipped, fn {tx_hash, name} ->
Enum.map(zipped, fn {transaction_hash, name} ->
id =
(conn
|> post("/api/account/v2/user/tags/transaction", %{
"transaction_hash" => tx_hash,
"transaction_hash" => transaction_hash,
"name" => name
})
|> json_response(200))["id"]
{tx_hash, %{"label" => name}, %{"transaction_hash" => tx_hash, "id" => id, "name" => name}}
{transaction_hash, %{"label" => name}, %{"transaction_hash" => transaction_hash, "id" => id, "name" => name}}
end)
assert Enum.all?(created, fn {tx_hash, map_tag, _} ->
assert Enum.all?(created, fn {transaction_hash, map_tag, _} ->
response =
conn
|> get("/api/account/v2/tags/transaction/#{tx_hash}")
|> get("/api/account/v2/tags/transaction/#{transaction_hash}")
|> json_response(200)
response["personal_tx_tag"] == map_tag
response["personal_transaction_tag"] == map_tag
end)
response =
@ -475,7 +475,7 @@ defmodule BlockScoutWeb.Account.Api.V2.UserControllerTest do
|> json_response(200)
|> Map.get("items")
response["personal_tx_tag"] == nil
response["personal_transaction_tag"] == nil
end)
end
@ -1227,7 +1227,7 @@ defmodule BlockScoutWeb.Account.Api.V2.UserControllerTest do
end
defp compare_item(%TagTransaction{} = tag_transaction, json) do
assert json["transaction_hash"] == to_string(tag_transaction.tx_hash)
assert json["transaction_hash"] == to_string(tag_transaction.transaction_hash)
assert json["name"] == tag_transaction.name
assert json["id"] == tag_transaction.id
end

@ -2572,12 +2572,12 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
erc_721_tt =
for x <- 0..50 do
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block()
transaction = insert(:transaction, input: "0xabcd010203040506") |> with_block()
insert(:token_transfer,
transaction: tx,
block: tx.block,
block_number: tx.block_number,
transaction: transaction,
block: transaction.block,
block_number: transaction.block_number,
from_address: address,
token_contract_address: erc_721_token.contract_address,
token_ids: [x]

@ -611,7 +611,7 @@ defmodule BlockScoutWeb.API.RPC.ContractControllerTest do
implementation_contract_address_hash_string =
Base.encode16(implementation_contract.address_hash.bytes, case: :lower)
proxy_tx_input =
proxy_transaction_input =
"0x11b804ab000000000000000000000000" <>
implementation_contract_address_hash_string <>
"000000000000000000000000000000000000000000000000000000000000006035323031313537360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000284e159163400000000000000000000000034420c13696f4ac650b9fafe915553a1abcd7dd30000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000220000000000000000000000000ff5ae9b0a7522736299d797d80b8fc6f31d61100000000000000000000000000ff5ae9b0a7522736299d797d80b8fc6f31d6110000000000000000000000000000000000000000000000000000000000000003e8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034420c13696f4ac650b9fafe915553a1abcd7dd300000000000000000000000000000000000000000000000000000000000000184f7074696d69736d2053756273637269626572204e465473000000000000000000000000000000000000000000000000000000000000000000000000000000054f504e46540000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037697066733a2f2f516d66544e504839765651334b5952346d6b52325a6b757756424266456f5a5554545064395538666931503332752f300000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c82bbe41f2cf04e3a8efa18f7032bdd7f6d98a81000000000000000000000000efba8a2a82ec1fb1273806174f5e28fbb917cf9500000000000000000000000000000000000000000000000000000000"
@ -732,16 +732,16 @@ defmodule BlockScoutWeb.API.RPC.ContractControllerTest do
abi: proxy_abi
)
tx =
transaction =
insert(:transaction,
created_contract_address_hash: proxy_address.hash,
input: proxy_tx_input
input: proxy_transaction_input
)
|> with_block(status: :ok)
name = implementation_contract.name
from = Address.checksum(tx.from_address_hash)
tx_hash = to_string(tx.hash)
from = Address.checksum(transaction.from_address_hash)
transaction_hash = to_string(transaction.hash)
address_hash = Address.checksum(proxy_address.hash)
{:ok, implementation_contract_address_hash} =
@ -1170,7 +1170,7 @@ defmodule BlockScoutWeb.API.RPC.ContractControllerTest do
%{
"contractAddress" => contract_address,
"contractCreator" => contract_creator,
"txHash" => tx_hash
"txHash" => transaction_hash
}
]
} =
@ -1180,7 +1180,7 @@ defmodule BlockScoutWeb.API.RPC.ContractControllerTest do
assert contract_address == to_string(address.hash)
assert contract_creator == to_string(transaction.from_address_hash)
assert tx_hash == to_string(transaction.hash)
assert transaction_hash == to_string(transaction.hash)
end
end

@ -15,13 +15,13 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
end
test "get and paginate advanced filter (transactions split between pages)", %{conn: conn} do
first_tx = :transaction |> insert() |> with_block()
insert_list(3, :token_transfer, transaction: first_tx)
first_transaction = :transaction |> insert() |> with_block()
insert_list(3, :token_transfer, transaction: first_transaction)
for i <- 0..2 do
insert(:internal_transaction,
transaction: first_tx,
block_hash: first_tx.block_hash,
transaction: first_transaction,
block_hash: first_transaction.block_hash,
index: i,
block_index: i
)
@ -38,20 +38,20 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
end
test "get and paginate advanced filter (token transfers split between pages)", %{conn: conn} do
first_tx = :transaction |> insert() |> with_block()
insert_list(3, :token_transfer, transaction: first_tx)
first_transaction = :transaction |> insert() |> with_block()
insert_list(3, :token_transfer, transaction: first_transaction)
for i <- 0..2 do
insert(:internal_transaction,
transaction: first_tx,
block_hash: first_tx.block_hash,
transaction: first_transaction,
block_hash: first_transaction.block_hash,
index: i,
block_index: i
)
end
second_tx = :transaction |> insert() |> with_block()
insert_list(50, :token_transfer, transaction: second_tx, block_number: second_tx.block_number)
second_transaction = :transaction |> insert() |> with_block()
insert_list(50, :token_transfer, transaction: second_transaction, block_number: second_transaction.block_number)
request = get(conn, "/api/v2/advanced-filters")
assert response = json_response(request, 200)
@ -62,23 +62,23 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
end
test "get and paginate advanced filter (batch token transfers split between pages)", %{conn: conn} do
first_tx = :transaction |> insert() |> with_block()
insert_list(3, :token_transfer, transaction: first_tx)
first_transaction = :transaction |> insert() |> with_block()
insert_list(3, :token_transfer, transaction: first_transaction)
for i <- 0..2 do
insert(:internal_transaction,
transaction: first_tx,
block_hash: first_tx.block_hash,
transaction: first_transaction,
block_hash: first_transaction.block_hash,
index: i,
block_index: i
)
end
second_tx = :transaction |> insert() |> with_block()
second_transaction = :transaction |> insert() |> with_block()
insert_list(5, :token_transfer,
transaction: second_tx,
block_number: second_tx.block_number,
transaction: second_transaction,
block_number: second_transaction.block_number,
token_type: "ERC-1155",
token_ids: 0..10 |> Enum.to_list(),
amounts: 10..20 |> Enum.to_list()
@ -93,24 +93,24 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
end
test "get and paginate advanced filter (internal transactions split between pages)", %{conn: conn} do
first_tx = :transaction |> insert() |> with_block()
insert_list(3, :token_transfer, transaction: first_tx)
first_transaction = :transaction |> insert() |> with_block()
insert_list(3, :token_transfer, transaction: first_transaction)
for i <- 0..2 do
insert(:internal_transaction,
transaction: first_tx,
block_hash: first_tx.block_hash,
transaction: first_transaction,
block_hash: first_transaction.block_hash,
index: i,
block_index: i
)
end
second_tx = :transaction |> insert() |> with_block()
second_transaction = :transaction |> insert() |> with_block()
for i <- 0..49 do
insert(:internal_transaction,
transaction: second_tx,
block_hash: second_tx.block_hash,
transaction: second_transaction,
block_hash: second_transaction.block_hash,
index: i,
block_index: i
)
@ -124,49 +124,51 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
check_paginated_response(AdvancedFilter.list(), response["items"], response_2nd_page["items"])
end
test "filter by tx_type", %{conn: conn} do
test "filter by transaction_type", %{conn: conn} do
30 |> insert_list(:transaction) |> with_block()
tx = insert(:transaction) |> with_block()
transaction = insert(:transaction) |> with_block()
for token_type <- ~w(ERC-20 ERC-404 ERC-721 ERC-1155),
_ <- 0..4 do
insert(:token_transfer, transaction: tx, token_type: token_type)
insert(:token_transfer, transaction: transaction, token_type: token_type)
end
tx = :transaction |> insert() |> with_block()
transaction = :transaction |> insert() |> with_block()
for i <- 0..29 do
insert(:internal_transaction,
transaction: tx,
block_hash: tx.block_hash,
transaction: transaction,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
end
for tx_type_filter_string <-
for transaction_type_filter_string <-
~w(COIN_TRANSFER COIN_TRANSFER,ERC-404 ERC-721,ERC-1155 ERC-20,COIN_TRANSFER,ERC-1155) do
tx_type_filter = tx_type_filter_string |> String.split(",")
request = get(conn, "/api/v2/advanced-filters", %{"tx_types" => tx_type_filter_string})
transaction_type_filter = transaction_type_filter_string |> String.split(",")
request = get(conn, "/api/v2/advanced-filters", %{"transaction_types" => transaction_type_filter_string})
assert response = json_response(request, 200)
assert Enum.all?(response["items"], fn item -> String.upcase(item["type"]) in tx_type_filter end)
assert Enum.all?(response["items"], fn item -> String.upcase(item["type"]) in transaction_type_filter end)
if response["next_page_params"] do
request_2nd_page =
get(
conn,
"/api/v2/advanced-filters",
Map.merge(%{"tx_types" => tx_type_filter_string}, response["next_page_params"])
Map.merge(%{"transaction_types" => transaction_type_filter_string}, response["next_page_params"])
)
assert response_2nd_page = json_response(request_2nd_page, 200)
assert Enum.all?(response_2nd_page["items"], fn item -> String.upcase(item["type"]) in tx_type_filter end)
assert Enum.all?(response_2nd_page["items"], fn item ->
String.upcase(item["type"]) in transaction_type_filter
end)
check_paginated_response(
AdvancedFilter.list(tx_types: tx_type_filter),
AdvancedFilter.list(transaction_types: transaction_type_filter),
response["items"],
response_2nd_page["items"]
)
@ -177,7 +179,7 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
test "filter by methods", %{conn: conn} do
TestHelper.get_eip1967_implementation_zero_addresses()
tx = :transaction |> insert() |> with_block()
transaction = :transaction |> insert() |> with_block()
smart_contract = build(:smart_contract)
@ -201,10 +203,10 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
for i <- 0..4 do
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
to_address_hash: contract_address.hash,
to_address: contract_address,
block_hash: tx.block_hash,
block_hash: transaction.block_hash,
index: i,
block_index: i,
input: method1
@ -213,10 +215,10 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
for i <- 5..9 do
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
to_address_hash: contract_address.hash,
to_address: contract_address,
block_hash: tx.block_hash,
block_hash: transaction.block_hash,
index: i,
block_index: i,
input: method2
@ -258,16 +260,16 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
first_timestamp = ~U[2023-12-12 00:00:00.000000Z]
for i <- 0..4 do
tx = :transaction |> insert() |> with_block(block_timestamp: Timex.shift(first_timestamp, days: i))
transaction = :transaction |> insert() |> with_block(block_timestamp: Timex.shift(first_timestamp, days: i))
insert(:internal_transaction,
transaction: tx,
block_hash: tx.block_hash,
transaction: transaction,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
insert(:token_transfer, transaction: tx, block_number: tx.block_number, log_index: i)
insert(:token_transfer, transaction: transaction, block_number: transaction.block_number, log_index: i)
end
request =
@ -285,16 +287,16 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
address = insert(:address)
for i <- 0..4 do
tx = :transaction |> insert() |> with_block()
transaction = :transaction |> insert() |> with_block()
if i < 2 do
:transaction |> insert(from_address_hash: address.hash, from_address: address) |> with_block()
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
from_address_hash: address.hash,
from_address: address,
block_hash: tx.block_hash,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
@ -302,19 +304,19 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
insert(:token_transfer,
from_address_hash: address.hash,
from_address: address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: i
)
else
insert(:internal_transaction,
transaction: tx,
block_hash: tx.block_hash,
transaction: transaction,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
insert(:token_transfer, transaction: tx, block_number: tx.block_number, log_index: i)
insert(:token_transfer, transaction: transaction, block_number: transaction.block_number, log_index: i)
end
end
@ -329,16 +331,16 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
address = insert(:address)
for i <- 0..4 do
tx = :transaction |> insert() |> with_block()
transaction = :transaction |> insert() |> with_block()
if i < 4 do
:transaction |> insert(from_address_hash: address.hash, from_address: address) |> with_block()
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
from_address_hash: address.hash,
from_address: address,
block_hash: tx.block_hash,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
@ -346,19 +348,19 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
insert(:token_transfer,
from_address_hash: address.hash,
from_address: address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: i
)
else
insert(:internal_transaction,
transaction: tx,
block_hash: tx.block_hash,
transaction: transaction,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
insert(:token_transfer, transaction: tx, block_number: tx.block_number, log_index: i)
insert(:token_transfer, transaction: transaction, block_number: transaction.block_number, log_index: i)
end
end
@ -374,7 +376,7 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
address_to_exclude = insert(:address)
for i <- 0..2 do
tx =
transaction =
:transaction
|> insert(from_address_hash: address_to_exclude.hash, from_address: address_to_exclude)
|> with_block()
@ -385,10 +387,10 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
|> with_block()
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
from_address_hash: address_to_include.hash,
from_address: address_to_include,
block_hash: tx.block_hash,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
@ -396,19 +398,19 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
insert(:token_transfer,
from_address_hash: address_to_include.hash,
from_address: address_to_include,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: i
)
else
insert(:internal_transaction,
transaction: tx,
block_hash: tx.block_hash,
transaction: transaction,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
insert(:token_transfer, transaction: tx, block_number: tx.block_number, log_index: i)
insert(:token_transfer, transaction: transaction, block_number: transaction.block_number, log_index: i)
end
end
@ -427,16 +429,16 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
address = insert(:address)
for i <- 0..4 do
tx = :transaction |> insert() |> with_block()
transaction = :transaction |> insert() |> with_block()
if i < 2 do
:transaction |> insert(to_address_hash: address.hash, to_address: address) |> with_block()
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
to_address_hash: address.hash,
to_address: address,
block_hash: tx.block_hash,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
@ -444,19 +446,19 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
insert(:token_transfer,
to_address_hash: address.hash,
to_address: address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: i
)
else
insert(:internal_transaction,
transaction: tx,
block_hash: tx.block_hash,
transaction: transaction,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
insert(:token_transfer, transaction: tx, block_number: tx.block_number, log_index: i)
insert(:token_transfer, transaction: transaction, block_number: transaction.block_number, log_index: i)
end
end
@ -471,16 +473,16 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
address = insert(:address)
for i <- 0..4 do
tx = :transaction |> insert() |> with_block()
transaction = :transaction |> insert() |> with_block()
if i < 4 do
:transaction |> insert(to_address_hash: address.hash, to_address: address) |> with_block()
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
to_address_hash: address.hash,
to_address: address,
block_hash: tx.block_hash,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
@ -488,19 +490,19 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
insert(:token_transfer,
to_address_hash: address.hash,
to_address: address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: i
)
else
insert(:internal_transaction,
transaction: tx,
block_hash: tx.block_hash,
transaction: transaction,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
insert(:token_transfer, transaction: tx, block_number: tx.block_number, log_index: i)
insert(:token_transfer, transaction: transaction, block_number: transaction.block_number, log_index: i)
end
end
@ -516,7 +518,7 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
address_to_exclude = insert(:address)
for i <- 0..2 do
tx =
transaction =
:transaction
|> insert(to_address_hash: address_to_exclude.hash, to_address: address_to_exclude)
|> with_block()
@ -527,10 +529,10 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
|> with_block()
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
to_address_hash: address_to_include.hash,
to_address: address_to_include,
block_hash: tx.block_hash,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
@ -538,19 +540,19 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
insert(:token_transfer,
to_address_hash: address_to_include.hash,
to_address: address_to_include,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: i
)
else
insert(:internal_transaction,
transaction: tx,
block_hash: tx.block_hash,
transaction: transaction,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
insert(:token_transfer, transaction: tx, block_number: tx.block_number, log_index: i)
insert(:token_transfer, transaction: transaction, block_number: transaction.block_number, log_index: i)
end
end
@ -570,17 +572,17 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
to_address = insert(:address)
for i <- 0..8 do
tx = :transaction |> insert() |> with_block()
transaction = :transaction |> insert() |> with_block()
cond do
i < 2 ->
:transaction |> insert(from_address_hash: from_address.hash, from_address: from_address) |> with_block()
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
from_address_hash: from_address.hash,
from_address: from_address,
block_hash: tx.block_hash,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
@ -588,8 +590,8 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
insert(:token_transfer,
from_address_hash: from_address.hash,
from_address: from_address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: i
)
@ -597,10 +599,10 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
:transaction |> insert(to_address_hash: to_address.hash, to_address: to_address) |> with_block()
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
to_address_hash: to_address.hash,
to_address: to_address,
block_hash: tx.block_hash,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
@ -608,8 +610,8 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
insert(:token_transfer,
to_address_hash: to_address.hash,
to_address: to_address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: i
)
@ -624,12 +626,12 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
|> with_block()
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
to_address_hash: to_address.hash,
to_address: to_address,
from_address_hash: from_address.hash,
from_address: from_address,
block_hash: tx.block_hash,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
@ -639,20 +641,20 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
to_address: to_address,
from_address_hash: from_address.hash,
from_address: from_address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: i
)
true ->
insert(:internal_transaction,
transaction: tx,
block_hash: tx.block_hash,
transaction: transaction,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
insert(:token_transfer, transaction: tx, block_number: tx.block_number, log_index: i)
insert(:token_transfer, transaction: transaction, block_number: transaction.block_number, log_index: i)
end
end
@ -673,17 +675,17 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
to_address = insert(:address)
for i <- 0..8 do
tx = :transaction |> insert() |> with_block()
transaction = :transaction |> insert() |> with_block()
cond do
i < 2 ->
:transaction |> insert(from_address_hash: from_address.hash, from_address: from_address) |> with_block()
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
from_address_hash: from_address.hash,
from_address: from_address,
block_hash: tx.block_hash,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
@ -691,8 +693,8 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
insert(:token_transfer,
from_address_hash: from_address.hash,
from_address: from_address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: i
)
@ -700,10 +702,10 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
:transaction |> insert(to_address_hash: to_address.hash, to_address: to_address) |> with_block()
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
to_address_hash: to_address.hash,
to_address: to_address,
block_hash: tx.block_hash,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
@ -711,8 +713,8 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
insert(:token_transfer,
to_address_hash: to_address.hash,
to_address: to_address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: i
)
@ -727,12 +729,12 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
|> with_block()
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
to_address_hash: to_address.hash,
to_address: to_address,
from_address_hash: from_address.hash,
from_address: from_address,
block_hash: tx.block_hash,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
@ -742,20 +744,20 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
to_address: to_address,
from_address_hash: from_address.hash,
from_address: from_address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: i
)
true ->
insert(:internal_transaction,
transaction: tx,
block_hash: tx.block_hash,
transaction: transaction,
block_hash: transaction.block_hash,
index: i,
block_index: i
)
insert(:token_transfer, transaction: tx, block_number: tx.block_number, log_index: i)
insert(:token_transfer, transaction: transaction, block_number: transaction.block_number, log_index: i)
end
end
@ -772,11 +774,11 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
test "filter by amount", %{conn: conn} do
for i <- 0..4 do
tx = :transaction |> insert(value: i * 10 ** 18) |> with_block()
transaction = :transaction |> insert(value: i * 10 ** 18) |> with_block()
insert(:internal_transaction,
transaction: tx,
block_hash: tx.block_hash,
transaction: transaction,
block_hash: transaction.block_hash,
index: 0,
block_index: 0,
value: i * 10 ** 18
@ -787,8 +789,8 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
insert(:token_transfer,
amount: i * 10 ** 10,
token_contract_address: token.contract_address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: 0
)
end
@ -804,13 +806,13 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
token_b = insert(:token)
token_c = insert(:token)
tx = :transaction |> insert() |> with_block()
transaction = :transaction |> insert() |> with_block()
for token <- [token_a, token_b, token_c, token_a, token_b, token_c, token_a, token_b, token_c] do
insert(:token_transfer,
token_contract_address: token.contract_address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: 0
)
end
@ -831,13 +833,13 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
token_b = insert(:token)
token_c = insert(:token)
tx = :transaction |> insert() |> with_block()
transaction = :transaction |> insert() |> with_block()
for token <- [token_a, token_b, token_c, token_a, token_b, token_c, token_a, token_b, token_c] do
insert(:token_transfer,
token_contract_address: token.contract_address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: 0
)
end
@ -858,13 +860,13 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
token_b = insert(:token)
token_c = insert(:token)
tx = :transaction |> insert() |> with_block()
transaction = :transaction |> insert() |> with_block()
for token <- [token_a, token_b, token_c, token_a, token_b, token_c, token_a, token_b, token_c] do
insert(:token_transfer,
token_contract_address: token.contract_address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: 0
)
end
@ -885,13 +887,13 @@ defmodule BlockScoutWeb.API.V2.AdvancedFilterControllerTest do
token_b = insert(:token)
token_c = insert(:token)
tx = :transaction |> insert() |> with_block()
transaction = :transaction |> insert() |> with_block()
for token <- [token_a, token_b, token_c, token_a, token_b, token_c, token_a, token_b, token_c] do
insert(:token_transfer,
token_contract_address: token.contract_address,
transaction: tx,
block_number: tx.block_number,
transaction: transaction,
block_number: transaction.block_number,
log_index: 0
)
end

@ -282,14 +282,14 @@ defmodule BlockScoutWeb.API.V2.BlockControllerTest do
assert response["next_page_params"] == nil
end
test "get relevant tx", %{conn: conn} do
test "get relevant transaction", %{conn: conn} do
10
|> insert_list(:transaction)
|> with_block()
block = insert(:block)
tx =
transaction =
:transaction
|> insert()
|> with_block(block)
@ -298,21 +298,21 @@ defmodule BlockScoutWeb.API.V2.BlockControllerTest do
assert response = json_response(request, 200)
assert Enum.count(response["items"]) == 1
assert response["next_page_params"] == nil
compare_item(tx, Enum.at(response["items"], 0))
compare_item(transaction, Enum.at(response["items"], 0))
request = get(conn, "/api/v2/blocks/#{block.hash}/transactions")
assert response_1 = json_response(request, 200)
assert response_1 == response
end
test "get txs with working next_page_params", %{conn: conn} do
test "get transactions with working next_page_params", %{conn: conn} do
2
|> insert_list(:transaction)
|> with_block()
block = insert(:block)
txs =
transactions =
51
|> insert_list(:transaction)
|> with_block(block)
@ -324,7 +324,7 @@ defmodule BlockScoutWeb.API.V2.BlockControllerTest do
request_2nd_page = get(conn, "/api/v2/blocks/#{block.number}/transactions", response["next_page_params"])
assert response_2nd_page = json_response(request_2nd_page, 200)
check_paginated_response(response, response_2nd_page, txs)
check_paginated_response(response, response_2nd_page, transactions)
request_1 = get(conn, "/api/v2/blocks/#{block.hash}/transactions")
assert response_1 = json_response(request_1, 200)
@ -443,34 +443,34 @@ defmodule BlockScoutWeb.API.V2.BlockControllerTest do
request = get(conn, "/api/v2/blocks/#{block.hash}/internal-transactions")
assert %{"items" => [], "next_page_params" => nil} = json_response(request, 200)
tx =
transaction =
:transaction
|> insert()
|> with_block(block)
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
index: 0,
block_number: tx.block_number,
transaction_index: tx.index,
block_hash: tx.block_hash,
block_number: transaction.block_number,
transaction_index: transaction.index,
block_hash: transaction.block_hash,
block_index: 0
)
internal_txs =
internal_transactions =
51..1
|> Enum.map(fn index ->
tx =
transaction =
:transaction
|> insert()
|> with_block(block)
insert(:internal_transaction,
transaction: tx,
transaction: transaction,
index: index,
block_number: tx.block_number,
transaction_index: tx.index,
block_hash: tx.block_hash,
block_number: transaction.block_number,
transaction_index: transaction.index,
block_hash: transaction.block_hash,
block_index: index
)
end)
@ -482,7 +482,7 @@ defmodule BlockScoutWeb.API.V2.BlockControllerTest do
assert response_2nd_page = json_response(request_2nd_page, 200)
check_paginated_response(response, response_2nd_page, internal_txs)
check_paginated_response(response, response_2nd_page, internal_transactions)
end
end
@ -493,7 +493,7 @@ defmodule BlockScoutWeb.API.V2.BlockControllerTest do
defp compare_item(%Transaction{} = transaction, json) do
assert to_string(transaction.hash) == json["hash"]
assert transaction.block_number == json["block"]
assert transaction.block_number == json["block_number"]
assert to_string(transaction.value.value) == json["value"]
assert Address.checksum(transaction.from_address_hash) == json["from"]["hash"]
assert Address.checksum(transaction.to_address_hash) == json["to"]["hash"]
@ -503,13 +503,13 @@ defmodule BlockScoutWeb.API.V2.BlockControllerTest do
assert withdrawal.index == json["index"]
end
defp compare_item(%InternalTransaction{} = internal_tx, json) do
assert internal_tx.block_number == json["block"]
assert to_string(internal_tx.gas) == json["gas_limit"]
assert internal_tx.index == json["index"]
assert to_string(internal_tx.transaction_hash) == json["transaction_hash"]
assert Address.checksum(internal_tx.from_address_hash) == json["from"]["hash"]
assert Address.checksum(internal_tx.to_address_hash) == json["to"]["hash"]
defp compare_item(%InternalTransaction{} = internal_transaction, json) do
assert internal_transaction.block_number == json["block_number"]
assert to_string(internal_transaction.gas) == json["gas_limit"]
assert internal_transaction.index == json["index"]
assert to_string(internal_transaction.transaction_hash) == json["transaction_hash"]
assert Address.checksum(internal_transaction.from_address_hash) == json["from"]["hash"]
assert Address.checksum(internal_transaction.to_address_hash) == json["to"]["hash"]
end
defp check_paginated_response(first_page_resp, second_page_resp, list) do

@ -37,20 +37,20 @@ defmodule BlockScoutWeb.API.V2.MainPageControllerTest do
end
describe "/main-page/transactions" do
test "get empty list when no txs", %{conn: conn} do
test "get empty list when no transactions", %{conn: conn} do
request = get(conn, "/api/v2/main-page/transactions")
assert [] = json_response(request, 200)
end
test "get last 6 txs", %{conn: conn} do
txs = insert_list(10, :transaction) |> with_block() |> Enum.take(-6) |> Enum.reverse()
test "get last 6 transactions", %{conn: conn} do
transactions = insert_list(10, :transaction) |> with_block() |> Enum.take(-6) |> Enum.reverse()
request = get(conn, "/api/v2/main-page/transactions")
assert response = json_response(request, 200)
assert Enum.count(response) == 6
for i <- 0..5 do
compare_item(Enum.at(txs, i), Enum.at(response, i))
compare_item(Enum.at(transactions, i), Enum.at(response, i))
end
end
end
@ -61,7 +61,7 @@ defmodule BlockScoutWeb.API.V2.MainPageControllerTest do
assert %{"message" => "Unauthorized"} = json_response(request, 401)
end
test "get last 6 txs", %{conn: conn} do
test "get last 6 transactions", %{conn: conn} do
insert_list(10, :transaction) |> with_block()
auth = build(:auth)
@ -107,17 +107,17 @@ defmodule BlockScoutWeb.API.V2.MainPageControllerTest do
notify_email: true
})
txs_1 = insert_list(2, :transaction, from_address: address_1) |> with_block()
txs_2 = insert_list(1, :transaction, from_address: address_2, to_address: address_1) |> with_block()
txs_3 = insert_list(3, :transaction, to_address: address_2) |> with_block()
txs = (txs_1 ++ txs_2 ++ txs_3) |> Enum.reverse()
transactions_1 = insert_list(2, :transaction, from_address: address_1) |> with_block()
transactions_2 = insert_list(1, :transaction, from_address: address_2, to_address: address_1) |> with_block()
transactions_3 = insert_list(3, :transaction, to_address: address_2) |> with_block()
transactions = (transactions_1 ++ transactions_2 ++ transactions_3) |> Enum.reverse()
request = get(conn, "/api/v2/main-page/transactions/watchlist")
assert response = json_response(request, 200)
assert Enum.count(response) == 6
for i <- 0..5 do
compare_item(Enum.at(txs, i), Enum.at(response, i), %{
compare_item(Enum.at(transactions, i), Enum.at(response, i), %{
address_1.hash => watchlist_address_1.name,
address_2.hash => watchlist_address_2.name
})
@ -144,7 +144,7 @@ defmodule BlockScoutWeb.API.V2.MainPageControllerTest do
defp compare_item(%Transaction{} = transaction, json) do
assert to_string(transaction.hash) == json["hash"]
assert transaction.block_number == json["block"]
assert transaction.block_number == json["block_number"]
assert to_string(transaction.value.value) == json["value"]
assert Address.checksum(transaction.from_address_hash) == json["from"]["hash"]
assert Address.checksum(transaction.to_address_hash) == json["to"]["hash"]
@ -152,7 +152,7 @@ defmodule BlockScoutWeb.API.V2.MainPageControllerTest do
defp compare_item(%Transaction{} = transaction, json, wl_names) do
assert to_string(transaction.hash) == json["hash"]
assert transaction.block_number == json["block"]
assert transaction.block_number == json["block_number"]
assert to_string(transaction.value.value) == json["value"]
assert Address.checksum(transaction.from_address_hash) == json["from"]["hash"]
assert Address.checksum(transaction.to_address_hash) == json["to"]["hash"]

@ -202,9 +202,9 @@ defmodule BlockScoutWeb.API.V2.SearchControllerTest do
end
test "search transaction", %{conn: conn} do
tx = insert(:transaction, block_timestamp: nil)
transaction = insert(:transaction, block_timestamp: nil)
request = get(conn, "/api/v2/search?q=#{tx.hash}")
request = get(conn, "/api/v2/search?q=#{transaction.hash}")
assert response = json_response(request, 200)
assert Enum.count(response["items"]) == 1
@ -213,15 +213,15 @@ defmodule BlockScoutWeb.API.V2.SearchControllerTest do
item = Enum.at(response["items"], 0)
assert item["type"] == "transaction"
assert item["tx_hash"] == to_string(tx.hash)
assert item["url"] =~ to_string(tx.hash)
assert item["transaction_hash"] == to_string(transaction.hash)
assert item["url"] =~ to_string(transaction.hash)
assert item["timestamp"] == nil
end
test "search transaction with timestamp", %{conn: conn} do
tx = :transaction |> insert() |> with_block()
transaction = :transaction |> insert() |> with_block()
request = get(conn, "/api/v2/search?q=#{tx.hash}")
request = get(conn, "/api/v2/search?q=#{transaction.hash}")
assert response = json_response(request, 200)
assert Enum.count(response["items"]) == 1
@ -230,9 +230,11 @@ defmodule BlockScoutWeb.API.V2.SearchControllerTest do
item = Enum.at(response["items"], 0)
assert item["type"] == "transaction"
assert item["tx_hash"] == to_string(tx.hash)
assert item["url"] =~ to_string(tx.hash)
assert item["timestamp"] == Repo.preload(tx, [:block]).block.timestamp |> to_string() |> String.replace(" ", "T")
assert item["transaction_hash"] == to_string(transaction.hash)
assert item["url"] =~ to_string(transaction.hash)
assert item["timestamp"] ==
Repo.preload(transaction, [:block]).block.timestamp |> to_string() |> String.replace(" ", "T")
end
test "search tags", %{conn: conn} do

@ -455,7 +455,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
implementation_contract_address_hash_string =
Base.encode16(implementation_contract.address_hash.bytes, case: :lower)
proxy_tx_input =
proxy_transaction_input =
"0x11b804ab000000000000000000000000" <>
implementation_contract_address_hash_string <>
"000000000000000000000000000000000000000000000000000000000000006035323031313537360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000284e159163400000000000000000000000034420c13696f4ac650b9fafe915553a1abcd7dd30000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000220000000000000000000000000ff5ae9b0a7522736299d797d80b8fc6f31d61100000000000000000000000000ff5ae9b0a7522736299d797d80b8fc6f31d6110000000000000000000000000000000000000000000000000000000000000003e8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034420c13696f4ac650b9fafe915553a1abcd7dd300000000000000000000000000000000000000000000000000000000000000184f7074696d69736d2053756273637269626572204e465473000000000000000000000000000000000000000000000000000000000000000000000000000000054f504e46540000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037697066733a2f2f516d66544e504839765651334b5952346d6b52325a6b757756424266456f5a5554545064395538666931503332752f300000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c82bbe41f2cf04e3a8efa18f7032bdd7f6d98a81000000000000000000000000efba8a2a82ec1fb1273806174f5e28fbb917cf9500000000000000000000000000000000000000000000000000000000"
@ -470,7 +470,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
insert(:transaction,
created_contract_address_hash: proxy_address.hash,
input: proxy_tx_input
input: proxy_transaction_input
)
|> with_block(status: :ok)
@ -479,7 +479,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
"has_custom_methods_write" => false,
"is_self_destructed" => false,
"deployed_bytecode" => proxy_deployed_bytecode,
"creation_bytecode" => proxy_tx_input,
"creation_bytecode" => proxy_transaction_input,
"proxy_type" => "eip1167",
"implementations" => [
%{
@ -618,7 +618,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
implementation_contract_address_hash_string =
Base.encode16(implementation_contract.address_hash.bytes, case: :lower)
proxy_tx_input =
proxy_transaction_input =
"0x684fbe55000000000000000000000000af1caf51d49b0e63d1ff7e5d4ed6ea26d15f3f9d000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003"
proxy_deployed_bytecode =
@ -633,7 +633,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
insert(:transaction,
created_contract_address_hash: proxy_address.hash,
input: proxy_tx_input
input: proxy_transaction_input
)
|> with_block(status: :ok)
@ -648,7 +648,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
"has_custom_methods_write" => false,
"is_self_destructed" => false,
"deployed_bytecode" => proxy_deployed_bytecode,
"creation_bytecode" => proxy_tx_input
"creation_bytecode" => proxy_transaction_input
}
request = get(conn, "/api/v2/smart-contracts/#{Address.checksum(proxy_address.hash)}")
@ -3580,7 +3580,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
end
|> Enum.reverse()
ordering_params = %{"sort" => "txs_count", "order" => "asc"}
ordering_params = %{"sort" => "transactions_count", "order" => "asc"}
request = get(conn, "/api/v2/smart-contracts", ordering_params)
assert response = json_response(request, 200)
@ -3600,7 +3600,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
insert(:smart_contract, address_hash: address.hash, address: address)
end
ordering_params = %{"sort" => "txs_count", "order" => "desc"}
ordering_params = %{"sort" => "transactions_count", "order" => "desc"}
request = get(conn, "/api/v2/smart-contracts", ordering_params)
assert response = json_response(request, 200)

@ -131,12 +131,12 @@ defmodule BlockScoutWeb.API.V2.TokenControllerTest do
token_transfers =
for _ <- 0..50 do
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block()
transaction = insert(:transaction, input: "0xabcd010203040506") |> with_block()
insert(:token_transfer,
transaction: tx,
block: tx.block,
block_number: tx.block_number,
transaction: transaction,
block: transaction.block,
block_number: transaction.block_number,
token_contract_address: token.contract_address
)
end
@ -161,12 +161,12 @@ defmodule BlockScoutWeb.API.V2.TokenControllerTest do
tt =
for _ <- 0..50 do
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block()
transaction = insert(:transaction, input: "0xabcd010203040506") |> with_block()
insert(:token_transfer,
transaction: tx,
block: tx.block,
block_number: tx.block_number,
transaction: transaction,
block: transaction.block,
block_number: transaction.block_number,
token_contract_address: token.contract_address,
token_ids: Enum.map(0..50, fn _x -> id end),
token_type: "ERC-1155",
@ -195,12 +195,12 @@ defmodule BlockScoutWeb.API.V2.TokenControllerTest do
token_transfers =
for i <- 0..50 do
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block()
transaction = insert(:transaction, input: "0xabcd010203040506") |> with_block()
insert(:token_transfer,
transaction: tx,
block: tx.block,
block_number: tx.block_number,
transaction: transaction,
block: transaction.block,
block_number: transaction.block_number,
token_contract_address: token.contract_address,
token_ids: [i],
token_type: "ERC-721"
@ -220,13 +220,13 @@ defmodule BlockScoutWeb.API.V2.TokenControllerTest do
test "check that pagination works fine with 1155 batches #1 (large batch)", %{conn: conn} do
token = insert(:token, type: "ERC-1155")
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block()
transaction = insert(:transaction, input: "0xabcd010203040506") |> with_block()
tt =
insert(:token_transfer,
transaction: tx,
block: tx.block,
block_number: tx.block_number,
transaction: transaction,
block: transaction.block,
block_number: transaction.block_number,
token_contract_address: token.contract_address,
token_ids: Enum.map(0..50, fn x -> x end),
token_type: "ERC-1155",
@ -253,13 +253,13 @@ defmodule BlockScoutWeb.API.V2.TokenControllerTest do
%{conn: conn} do
token = insert(:token, type: "ERC-1155")
tx_1 = insert(:transaction, input: "0xabcd010203040506") |> with_block()
transaction_1 = insert(:transaction, input: "0xabcd010203040506") |> with_block()
tt_1 =
insert(:token_transfer,
transaction: tx_1,
block: tx_1.block,
block_number: tx_1.block_number,
transaction: transaction_1,
block: transaction_1.block,
block_number: transaction_1.block_number,
token_contract_address: token.contract_address,
token_ids: Enum.map(0..24, fn x -> x end),
token_type: "ERC-1155",
@ -271,13 +271,13 @@ defmodule BlockScoutWeb.API.V2.TokenControllerTest do
%TokenTransfer{tt_1 | token_ids: [i], amount: i}
end
tx_2 = insert(:transaction, input: "0xabcd010203040506") |> with_block()
transaction_2 = insert(:transaction, input: "0xabcd010203040506") |> with_block()
tt_2 =
insert(:token_transfer,
transaction: tx_2,
block: tx_2.block,
block_number: tx_2.block_number,
transaction: transaction_2,
block: transaction_2.block,
block_number: transaction_2.block_number,
token_contract_address: token.contract_address,
token_ids: Enum.map(25..49, fn x -> x end),
token_type: "ERC-1155",
@ -291,9 +291,9 @@ defmodule BlockScoutWeb.API.V2.TokenControllerTest do
tt_3 =
insert(:token_transfer,
transaction: tx_2,
block: tx_2.block,
block_number: tx_2.block_number,
transaction: transaction_2,
block: transaction_2.block,
block_number: transaction_2.block_number,
token_contract_address: token.contract_address,
token_ids: [50],
token_type: "ERC-1155",
@ -314,13 +314,13 @@ defmodule BlockScoutWeb.API.V2.TokenControllerTest do
test "check that pagination works fine with 1155 batches #3", %{conn: conn} do
token = insert(:token, type: "ERC-1155")
tx_1 = insert(:transaction, input: "0xabcd010203040506") |> with_block()
transaction_1 = insert(:transaction, input: "0xabcd010203040506") |> with_block()
tt_1 =
insert(:token_transfer,
transaction: tx_1,
block: tx_1.block,
block_number: tx_1.block_number,
transaction: transaction_1,
block: transaction_1.block,
block_number: transaction_1.block_number,
token_contract_address: token.contract_address,
token_ids: Enum.map(0..24, fn x -> x end),
token_type: "ERC-1155",
@ -332,13 +332,13 @@ defmodule BlockScoutWeb.API.V2.TokenControllerTest do
%TokenTransfer{tt_1 | token_ids: [i], amount: i}
end
tx_2 = insert(:transaction, input: "0xabcd010203040506") |> with_block()
transaction_2 = insert(:transaction, input: "0xabcd010203040506") |> with_block()
tt_2 =
insert(:token_transfer,
transaction: tx_2,
block: tx_2.block,
block_number: tx_2.block_number,
transaction: transaction_2,
block: transaction_2.block,
block_number: transaction_2.block_number,
token_contract_address: token.contract_address,
token_ids: Enum.map(25..50, fn x -> x end),
token_type: "ERC-1155",
@ -1237,12 +1237,12 @@ defmodule BlockScoutWeb.API.V2.TokenControllerTest do
token_transfers =
for _i <- 0..50 do
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block()
transaction = insert(:transaction, input: "0xabcd010203040506") |> with_block()
insert(:token_transfer,
transaction: tx,
block: tx.block,
block_number: tx.block_number,
transaction: transaction,
block: transaction.block,
block_number: transaction.block_number,
token_contract_address: token.contract_address,
token_ids: [id],
token_type: "ERC-721"
@ -1271,13 +1271,13 @@ defmodule BlockScoutWeb.API.V2.TokenControllerTest do
insert(:token_instance, token_id: id, token_contract_address_hash: token.contract_address_hash)
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block()
transaction = insert(:transaction, input: "0xabcd010203040506") |> with_block()
tt =
insert(:token_transfer,
transaction: tx,
block: tx.block,
block_number: tx.block_number,
transaction: transaction,
block: transaction.block,
block_number: transaction.block_number,
token_contract_address: token.contract_address,
token_ids: Enum.map(0..50, fn _x -> id end),
token_type: "ERC-1155",
@ -1299,14 +1299,14 @@ defmodule BlockScoutWeb.API.V2.TokenControllerTest do
amount = 101
insert(:token_instance, token_id: id, token_contract_address_hash: token.contract_address_hash)
tx = insert(:transaction, input: "0xabcd010203040506") |> with_block()
transaction = insert(:transaction, input: "0xabcd010203040506") |> with_block()
tt =
for _ <- 0..50 do
insert(:token_transfer,
transaction: tx,
block: tx.block,
block_number: tx.block_number,
transaction: transaction,
block: transaction.block,
block_number: transaction.block_number,
token_contract_address: token.contract_address,
token_ids: Enum.map(0..50, fn x -> x end) ++ [id],
token_type: "ERC-1155",
@ -1636,11 +1636,11 @@ defmodule BlockScoutWeb.API.V2.TokenControllerTest do
def compare_item(%TokenTransfer{} = token_transfer, json) do
assert Address.checksum(token_transfer.from_address_hash) == json["from"]["hash"]
assert Address.checksum(token_transfer.to_address_hash) == json["to"]["hash"]
assert to_string(token_transfer.transaction_hash) == json["tx_hash"]
assert to_string(token_transfer.transaction_hash) == json["transaction_hash"]
assert json["timestamp"] != nil
assert json["method"] != nil
assert to_string(token_transfer.block_hash) == json["block_hash"]
assert to_string(token_transfer.log_index) == json["log_index"]
assert token_transfer.log_index == json["log_index"]
assert check_total(Repo.preload(token_transfer, [{:token, :contract_address}]).token, json["total"], token_transfer)
end

@ -13,12 +13,12 @@ defmodule BlockScoutWeb.API.V2.TokenTransferControllerTest do
end
test "non empty list", %{conn: conn} do
tx =
transaction =
:transaction
|> insert()
|> with_block()
1 |> insert_list(:token_transfer, transaction: tx)
1 |> insert_list(:token_transfer, transaction: transaction)
request = get(conn, "/api/v2/token-transfers")
@ -28,7 +28,7 @@ defmodule BlockScoutWeb.API.V2.TokenTransferControllerTest do
end
test "filters by type", %{conn: conn} do
tx =
transaction =
:transaction
|> insert()
|> with_block()
@ -36,7 +36,7 @@ defmodule BlockScoutWeb.API.V2.TokenTransferControllerTest do
token = insert(:token, type: "ERC-721")
insert(:token_transfer,
transaction: tx,
transaction: transaction,
token: token,
token_type: "ERC-721"
)
@ -49,7 +49,7 @@ defmodule BlockScoutWeb.API.V2.TokenTransferControllerTest do
end
test "returns all transfers if filter is incorrect", %{conn: conn} do
tx =
transaction =
:transaction
|> insert()
|> with_block()
@ -57,13 +57,13 @@ defmodule BlockScoutWeb.API.V2.TokenTransferControllerTest do
token = insert(:token, type: "ERC-100500")
insert(:token_transfer,
transaction: tx,
transaction: transaction,
token: token,
token_type: "ERC-721"
)
insert(:token_transfer,
transaction: tx,
transaction: transaction,
token: token,
token_type: "ERC-20"
)
@ -78,12 +78,12 @@ defmodule BlockScoutWeb.API.V2.TokenTransferControllerTest do
test "token transfers with next_page_params", %{conn: conn} do
token_transfers =
for _i <- 0..50 do
tx = insert(:transaction) |> with_block()
transaction = insert(:transaction) |> with_block()
insert(:token_transfer,
transaction: tx,
block: tx.block,
block_number: tx.block_number
transaction: transaction,
block: transaction.block,
block_number: transaction.block_number
)
end
@ -97,12 +97,12 @@ defmodule BlockScoutWeb.API.V2.TokenTransferControllerTest do
end
test "flatten erc1155 batch token transfer", %{conn: conn} do
tx = insert(:transaction) |> with_block()
transaction = insert(:transaction) |> with_block()
insert(:token_transfer,
transaction: tx,
block: tx.block,
block_number: tx.block_number,
transaction: transaction,
block: transaction.block,
block_number: transaction.block_number,
token_ids: [1, 2, 3],
amounts: [500, 600, 700],
token_type: "ERC-1155"
@ -117,12 +117,12 @@ defmodule BlockScoutWeb.API.V2.TokenTransferControllerTest do
test "paginates erc1155 batch token transfers", %{conn: conn} do
token_transfers =
for _i <- 0..50 do
tx = insert(:transaction) |> with_block()
transaction = insert(:transaction) |> with_block()
insert(:token_transfer,
transaction: tx,
block: tx.block,
block_number: tx.block_number,
transaction: transaction,
block: transaction.block,
block_number: transaction.block_number,
token_ids: [1, 2],
amounts: [500, 600],
token_type: "ERC-1155"
@ -145,11 +145,11 @@ defmodule BlockScoutWeb.API.V2.TokenTransferControllerTest do
defp compare_item(%TokenTransfer{} = token_transfer, json) do
assert Address.checksum(token_transfer.from_address_hash) == json["from"]["hash"]
assert Address.checksum(token_transfer.to_address_hash) == json["to"]["hash"]
assert to_string(token_transfer.transaction_hash) == json["tx_hash"]
assert to_string(token_transfer.transaction_hash) == json["transaction_hash"]
assert token_transfer.transaction.block_timestamp == Timex.parse!(json["timestamp"], "{ISO:Extended:Z}")
assert json["method"] == nil
assert to_string(token_transfer.block_number) == json["block_number"]
assert to_string(token_transfer.log_index) == json["log_index"]
assert token_transfer.block_number == json["block_number"]
assert token_transfer.log_index == json["log_index"]
end
defp check_paginated_response(first_page_resp, second_page_resp, third_page_resp, token_transfers) do

@ -127,7 +127,7 @@ defmodule BlockScoutWeb.TransactionControllerTest do
assert html_response(conn, 422)
end
test "no redirect from tx page", %{conn: conn} do
test "no redirect from transaction page", %{conn: conn} do
transaction = insert(:transaction)
conn = get(conn, transaction_path(BlockScoutWeb.Endpoint, :show, transaction))

@ -67,7 +67,7 @@ defmodule BlockScoutWeb.VerifiedContractsControllerTest do
coin_balance: nil,
items_count: "50",
smart_contract_id: id,
tx_count: nil
transaction_count: nil
)
assert Map.get(json_response(conn, 200), "next_page_path") == expected_path

@ -28,7 +28,7 @@ defmodule BlockScoutWeb.ViewingTransactionsTest do
taft = insert(:address)
# From Lincoln to Taft.
txn_from_lincoln =
transaction_from_lincoln =
:transaction
|> insert(from_address: lincoln, to_address: taft)
|> with_block(block)
@ -66,7 +66,7 @@ defmodule BlockScoutWeb.ViewingTransactionsTest do
lincoln: lincoln,
taft: taft,
transaction: transaction,
txn_from_lincoln: txn_from_lincoln
transaction_from_lincoln: transaction_from_lincoln
}}
end

@ -617,23 +617,23 @@ defmodule EthereumJSONRPC.Filecoin do
end
defp to_transactions_params(blocks_responses, id_to_params) do
Enum.reduce(blocks_responses, [], fn %{id: id, result: tx_result}, blocks_acc ->
extract_transactions_params(Map.fetch!(id_to_params, id), tx_result) ++ blocks_acc
Enum.reduce(blocks_responses, [], fn %{id: id, result: transaction_result}, blocks_acc ->
extract_transactions_params(Map.fetch!(id_to_params, id), transaction_result) ++ blocks_acc
end)
end
defp extract_transactions_params(block_number, tx_result) do
tx_result
defp extract_transactions_params(block_number, transaction_result) do
transaction_result
|> Enum.reduce(
{[], 0},
# counter is the index of the internal transaction in transaction
fn %{"transactionHash" => tx_hash, "transactionPosition" => transaction_index} = calls_result,
{tx_acc, counter} ->
last_tx_response_from_accumulator = List.first(tx_acc)
fn %{"transactionHash" => transaction_hash, "transactionPosition" => transaction_index} = calls_result,
{transaction_acc, counter} ->
last_transaction_response_from_accumulator = List.first(transaction_acc)
next_counter =
with {:empty_accumulator, false} <- {:empty_accumulator, is_nil(last_tx_response_from_accumulator)},
true <- tx_hash !== last_tx_response_from_accumulator["transactionHash"] do
with {:empty_accumulator, false} <- {:empty_accumulator, is_nil(last_transaction_response_from_accumulator)},
true <- transaction_hash !== last_transaction_response_from_accumulator["transactionHash"] do
0
else
{:empty_accumulator, true} ->
@ -648,13 +648,13 @@ defmodule EthereumJSONRPC.Filecoin do
Map.merge(
%{
"blockNumber" => block_number,
"transactionHash" => tx_hash,
"transactionHash" => transaction_hash,
"transactionIndex" => transaction_index,
"index" => next_counter
},
calls_result
)
| tx_acc
| transaction_acc
],
next_counter
}

@ -152,23 +152,23 @@ defmodule EthereumJSONRPC.Geth do
def to_transactions_params(blocks_responses, id_to_params) do
blocks_responses
|> Enum.reduce({[], 0}, fn %{id: id, result: tx_result}, {blocks_acc, counter} ->
|> Enum.reduce({[], 0}, fn %{id: id, result: transaction_result}, {blocks_acc, counter} ->
{transactions_params, _, new_counter} =
extract_transactions_params(Map.fetch!(id_to_params, id), tx_result, counter)
extract_transactions_params(Map.fetch!(id_to_params, id), transaction_result, counter)
{transactions_params ++ blocks_acc, new_counter}
end)
|> elem(0)
end
defp extract_transactions_params(block_number, tx_result, counter) do
Enum.reduce(tx_result, {[], 0, counter}, fn %{"txHash" => tx_hash, "result" => calls_result},
{tx_acc, inner_counter, counter} ->
defp extract_transactions_params(block_number, transaction_result, counter) do
Enum.reduce(transaction_result, {[], 0, counter}, fn %{"txHash" => transaction_hash, "result" => calls_result},
{transaction_acc, inner_counter, counter} ->
{
[
{%{block_number: block_number, hash_data: tx_hash, transaction_index: inner_counter, id: counter},
{%{block_number: block_number, hash_data: transaction_hash, transaction_index: inner_counter, id: counter},
%{id: counter, result: calls_result}}
| tx_acc
| transaction_acc
],
inner_counter + 1,
counter + 1
@ -261,14 +261,14 @@ defmodule EthereumJSONRPC.Geth do
request(%{id: id, method: "eth_getTransactionReceipt", params: [hash_data]})
end)
|> json_rpc(json_rpc_named_arguments),
{:ok, txs} <-
{:ok, transactions} <-
id_to_params
|> Enum.map(fn {id, %{hash_data: hash_data}} ->
request(%{id: id, method: "eth_getTransactionByHash", params: [hash_data]})
end)
|> json_rpc(json_rpc_named_arguments) do
receipts_map = Enum.into(receipts, %{}, fn %{id: id, result: receipt} -> {id, receipt} end)
txs_map = Enum.into(txs, %{}, fn %{id: id, result: tx} -> {id, tx} end)
transactions_map = Enum.into(transactions, %{}, fn %{id: id, result: transaction} -> {id, transaction} end)
tracer =
if Application.get_env(:ethereum_jsonrpc, __MODULE__)[:tracer] == "polygon_edge",
@ -282,7 +282,7 @@ defmodule EthereumJSONRPC.Geth do
%{id: id, result: %{"structLogs" => _} = result} ->
debug_trace_transaction_response_to_internal_transactions_params(
%{id: id, result: tracer.replay(result, Map.fetch!(receipts_map, id), Map.fetch!(txs_map, id))},
%{id: id, result: tracer.replay(result, Map.fetch!(receipts_map, id), Map.fetch!(transactions_map, id))},
id_to_params
)
end)

@ -6,10 +6,14 @@ defmodule EthereumJSONRPC.Geth.Tracer do
import EthereumJSONRPC, only: [integer_to_quantity: 1, quantity_to_integer: 1]
def replay(%{"structLogs" => logs, "gas" => top_call_gas, "returnValue" => return_value} = result, receipt, tx)
def replay(
%{"structLogs" => logs, "gas" => top_call_gas, "returnValue" => return_value} = result,
receipt,
transaction
)
when is_list(logs) do
%{"contractAddress" => contract_address} = receipt
%{"from" => from, "to" => to, "value" => value, "input" => input} = tx
%{"from" => from, "to" => to, "value" => value, "input" => input} = transaction
top =
to

@ -30,7 +30,7 @@ defmodule EthereumJSONRPC.Transaction do
:optimism ->
@chain_type_fields quote(
do: [
l1_tx_origin: EthereumJSONRPC.hash(),
l1_transaction_origin: EthereumJSONRPC.hash(),
l1_block_number: non_neg_integer()
]
)
@ -343,7 +343,7 @@ defmodule EthereumJSONRPC.Transaction do
])
end
# txpool_content method on Erigon node returns tx data
# txpool_content method on Erigon node returns transaction data
# without gas price
def do_elixir_to_params(
%{
@ -390,7 +390,7 @@ defmodule EthereumJSONRPC.Transaction do
])
end
# for legacy txs without maxPriorityFeePerGas and maxFeePerGas
# for legacy transactions without maxPriorityFeePerGas and maxFeePerGas
def do_elixir_to_params(
%{
"blockHash" => block_hash,
@ -432,7 +432,7 @@ defmodule EthereumJSONRPC.Transaction do
])
end
# for legacy txs without type, maxPriorityFeePerGas and maxFeePerGas
# for legacy transactions without type, maxPriorityFeePerGas and maxFeePerGas
def do_elixir_to_params(
%{
"blockHash" => block_hash,
@ -472,7 +472,7 @@ defmodule EthereumJSONRPC.Transaction do
])
end
# for txs without gasPrice, maxPriorityFeePerGas and maxFeePerGas
# for transactions without gasPrice, maxPriorityFeePerGas and maxFeePerGas
def do_elixir_to_params(
%{
"blockHash" => block_hash,
@ -522,9 +522,9 @@ defmodule EthereumJSONRPC.Transaction do
])
:optimism ->
# we need to put blobVersionedHashes for Indexer.Fetcher.Optimism.TxnBatch module
# we need to put blobVersionedHashes for Indexer.Fetcher.Optimism.TransactionBatch module
put_if_present(params, elixir, [
{"l1TxOrigin", :l1_tx_origin},
{"l1TxOrigin", :l1_transaction_origin},
{"l1BlockNumber", :l1_block_number},
{"blobVersionedHashes", :blob_versioned_hashes}
])

@ -8,7 +8,7 @@ defmodule EthereumJSONRPC.Geth.TracerTest do
test "same as callTracer" do
struct_logs = File.read!(File.cwd!() <> "/test/support/fixture/geth/trace/struct_logger.json") |> Jason.decode!()
tx = "0xa0a5c30c5c5ec22b3346e0ae5ce09f8f41faf54f68a2a113eb15e363af90e9ab"
transaction = "0xa0a5c30c5c5ec22b3346e0ae5ce09f8f41faf54f68a2a113eb15e363af90e9ab"
sl_calls =
Tracer.replay(struct_logs["result"], struct_logs["receipt"], struct_logs["tx"])
@ -18,7 +18,7 @@ defmodule EthereumJSONRPC.Geth.TracerTest do
"blockNumber" => 0,
"index" => index,
"transactionIndex" => 0,
"transactionHash" => tx
"transactionHash" => transaction
})
end)
|> Calls.to_internal_transactions_params()
@ -40,7 +40,7 @@ defmodule EthereumJSONRPC.Geth.TracerTest do
"blockNumber" => 0,
"index" => index,
"transactionIndex" => 0,
"transactionHash" => tx
"transactionHash" => transaction
})
end)
|> Calls.to_internal_transactions_params()

@ -359,11 +359,12 @@ defmodule EthereumJSONRPC.GethTest do
Application.put_env(:ethereum_jsonrpc, Geth, tracer: "call_tracer", debug_trace_timeout: "5s")
call_tracer_internal_txs = Geth.fetch_internal_transactions([transaction_params], json_rpc_named_arguments)
call_tracer_internal_transactions =
Geth.fetch_internal_transactions([transaction_params], json_rpc_named_arguments)
Application.put_env(:ethereum_jsonrpc, Geth, tracer: "js", debug_trace_timeout: "5s")
assert call_tracer_internal_txs ==
assert call_tracer_internal_transactions ==
Geth.fetch_internal_transactions([transaction_params], json_rpc_named_arguments)
end
@ -431,11 +432,12 @@ defmodule EthereumJSONRPC.GethTest do
Application.put_env(:ethereum_jsonrpc, Geth, tracer: "call_tracer", debug_trace_timeout: "5s")
call_tracer_internal_txs = Geth.fetch_internal_transactions([transaction_params], json_rpc_named_arguments)
call_tracer_internal_transactions =
Geth.fetch_internal_transactions([transaction_params], json_rpc_named_arguments)
Application.put_env(:ethereum_jsonrpc, Geth, tracer: "js", debug_trace_timeout: "5s")
assert call_tracer_internal_txs ==
assert call_tracer_internal_transactions ==
Geth.fetch_internal_transactions([transaction_params], json_rpc_named_arguments)
end

@ -54,8 +54,8 @@ defmodule Mix.Tasks.Encrypt do
element
|> Changeset.change(%{
encrypted_name: element.name,
encrypted_tx_hash: element.tx_hash,
tx_hash_hash: element.tx_hash |> to_string() |> String.downcase()
encrypted_transaction_hash: element.transaction_hash,
transaction_hash_hash: element.transaction_hash |> to_string() |> String.downcase()
})
|> Account.update!()
end)

@ -35,7 +35,7 @@ defmodule Explorer.Account.Notifier.Email do
|> add_dynamic_field("block_number", notification.block_number)
|> add_dynamic_field("amount", amount(notification))
|> add_dynamic_field("name", notification.name)
|> add_dynamic_field("tx_fee", notification.tx_fee)
|> add_dynamic_field("transaction_fee", notification.transaction_fee)
|> add_dynamic_field("direction", direction(notification))
|> add_dynamic_field("method", notification.method)
|> add_dynamic_field("transaction_url", transaction_url(notification))

@ -129,7 +129,7 @@ defmodule Explorer.Account.Notifier.Notify do
block_number: summary.block_number,
amount: summary.amount,
subject: summary.subject,
tx_fee: summary.tx_fee,
transaction_fee: summary.transaction_fee,
name: summary.name,
type: summary.type,
from_address_hash_hash: hash_to_lower_case_string(summary.from_address_hash),

@ -19,7 +19,7 @@ defmodule Explorer.Account.Notifier.Summary do
:method,
:block_number,
:amount,
:tx_fee,
:transaction_fee,
:name,
:subject,
:type
@ -81,7 +81,7 @@ defmodule Explorer.Account.Notifier.Summary do
to_address_hash: transaction.to_address_hash,
block_number: transaction.block_number,
amount: amount(transaction),
tx_fee: fee(transaction),
transaction_fee: fee(transaction),
name: Explorer.coin_name(),
subject: "Coin transaction",
type: "COIN"
@ -96,7 +96,7 @@ defmodule Explorer.Account.Notifier.Summary do
to_address_hash: transaction.created_contract_address_hash,
block_number: transaction.block_number,
amount: amount(transaction),
tx_fee: fee(transaction),
transaction_fee: fee(transaction),
name: Explorer.coin_name(),
subject: "Contract creation",
type: "COIN"
@ -121,7 +121,7 @@ defmodule Explorer.Account.Notifier.Summary do
block_number: transfer.block_number,
amount: amount(transfer),
subject: transfer.token.type,
tx_fee: fee(transaction),
transaction_fee: fee(transaction),
name: token_name(transfer),
type: transfer.token.type
}
@ -135,7 +135,7 @@ defmodule Explorer.Account.Notifier.Summary do
to_address_hash: transfer.to_address_hash,
block_number: transfer.block_number,
subject: to_string(transfer.token_ids && List.first(transfer.token_ids)),
tx_fee: fee(transaction),
transaction_fee: fee(transaction),
name: token_name(transfer),
type: transfer.token.type
}
@ -149,7 +149,7 @@ defmodule Explorer.Account.Notifier.Summary do
to_address_hash: transfer.to_address_hash,
block_number: transfer.block_number,
subject: token_ids(transfer),
tx_fee: fee(transaction),
transaction_fee: fee(transaction),
name: token_name(transfer),
type: transfer.token.type
}
@ -165,7 +165,7 @@ defmodule Explorer.Account.Notifier.Summary do
to_address_hash: transfer.to_address_hash,
block_number: transfer.block_number,
subject: if(token_ids_string == "", do: transfer.token.type, else: token_ids_string),
tx_fee: fee(transaction),
transaction_fee: fee(transaction),
name: token_name(transfer),
type: transfer.token.type
}

@ -13,16 +13,16 @@ defmodule Explorer.Account.TagTransaction do
import Explorer.Chain, only: [hash_to_lower_case_string: 1]
typed_schema "account_tag_transactions" do
field(:tx_hash_hash, Cloak.Ecto.SHA256) :: binary() | nil
field(:transaction_hash_hash, Cloak.Ecto.SHA256) :: binary() | nil
field(:name, Explorer.Encrypted.Binary, null: false)
field(:tx_hash, Explorer.Encrypted.TransactionHash, null: false)
field(:transaction_hash, Explorer.Encrypted.TransactionHash, null: false)
belongs_to(:identity, Identity, null: false)
timestamps()
end
@attrs ~w(name identity_id tx_hash)a
@attrs ~w(name identity_id transaction_hash)a
def changeset do
%__MODULE__{}
@ -36,7 +36,7 @@ defmodule Explorer.Account.TagTransaction do
|> validate_required(@attrs, message: "Required")
|> validate_length(:name, min: 1, max: 35)
|> put_hashed_fields()
|> unique_constraint([:identity_id, :tx_hash_hash], message: "Transaction tag already exists")
|> unique_constraint([:identity_id, :transaction_hash_hash], message: "Transaction tag already exists")
|> tag_transaction_count_constraint()
|> check_transaction_existence()
end
@ -50,20 +50,20 @@ defmodule Explorer.Account.TagTransaction do
defp put_hashed_fields(changeset) do
# Using force_change instead of put_change due to https://github.com/danielberkompas/cloak_ecto/issues/53
changeset
|> force_change(:tx_hash_hash, hash_to_lower_case_string(get_field(changeset, :tx_hash)))
|> force_change(:transaction_hash_hash, hash_to_lower_case_string(get_field(changeset, :transaction_hash)))
end
defp check_transaction_existence(%Changeset{changes: %{tx_hash: tx_hash}} = changeset) do
check_transaction_existence_inner(changeset, tx_hash)
defp check_transaction_existence(%Changeset{changes: %{transaction_hash: transaction_hash}} = changeset) do
check_transaction_existence_inner(changeset, transaction_hash)
end
defp check_transaction_existence(changeset), do: changeset
defp check_transaction_existence_inner(changeset, tx_hash) do
if match?({:ok, _}, Chain.hash_to_transaction(tx_hash)) do
defp check_transaction_existence_inner(changeset, transaction_hash) do
if match?({:ok, _}, Chain.hash_to_transaction(transaction_hash)) do
changeset
else
add_error(changeset, :tx_hash, "Transaction does not exist")
add_error(changeset, :transaction_hash, "Transaction does not exist")
end
end
@ -122,17 +122,17 @@ defmodule Explorer.Account.TagTransaction do
defp page_transaction_tags(query, _), do: query
def tag_transaction_by_transaction_hash_and_identity_id_query(tx_hash, identity_id)
when not is_nil(tx_hash) and not is_nil(identity_id) do
def tag_transaction_by_transaction_hash_and_identity_id_query(transaction_hash, identity_id)
when not is_nil(transaction_hash) and not is_nil(identity_id) do
__MODULE__
|> where([tag], tag.identity_id == ^identity_id and tag.tx_hash == ^tx_hash)
|> where([tag], tag.identity_id == ^identity_id and tag.transaction_hash == ^transaction_hash)
end
def tag_transaction_by_transaction_hash_and_identity_id_query(_, _), do: nil
def get_tag_transaction_by_transaction_hash_and_identity_id(tx_hash, identity_id)
when not is_nil(tx_hash) and not is_nil(identity_id) do
tx_hash
def get_tag_transaction_by_transaction_hash_and_identity_id(transaction_hash, identity_id)
when not is_nil(transaction_hash) and not is_nil(identity_id) do
transaction_hash
|> hash_to_lower_case_string()
|> tag_transaction_by_transaction_hash_and_identity_id_query(identity_id)
|> Repo.account_repo().one()
@ -179,7 +179,7 @@ defmodule Explorer.Account.TagTransaction do
end
defimpl Jason.Encoder, for: Explorer.Account.TagTransaction do
def encode(tx_tag, opts) do
Jason.Encode.string(tx_tag.name, opts)
def encode(transaction_tag, opts) do
Jason.Encode.string(transaction_tag.name, opts)
end
end

@ -17,7 +17,7 @@ defmodule Explorer.Account.WatchlistNotification do
field(:block_number, :integer, null: false)
field(:direction, :string, null: false)
field(:method, :string, null: false)
field(:tx_fee, :decimal, null: false)
field(:transaction_fee, :decimal, null: false)
field(:type, :string, null: false)
field(:viewed_at, :integer, null: false)
field(:name, Explorer.Encrypted.Binary, null: false)
@ -41,7 +41,18 @@ defmodule Explorer.Account.WatchlistNotification do
@doc false
def changeset(watchlist_notifications, attrs) do
watchlist_notifications
|> cast(attrs, [:amount, :direction, :name, :type, :method, :block_number, :tx_fee, :value, :decimals, :viewed_at])
|> cast(attrs, [
:amount,
:direction,
:name,
:type,
:method,
:block_number,
:transaction_fee,
:value,
:decimals,
:viewed_at
])
|> validate_required([
:amount,
:direction,
@ -49,7 +60,7 @@ defmodule Explorer.Account.WatchlistNotification do
:type,
:method,
:block_number,
:tx_fee,
:transaction_fee,
:value,
:decimals,
:viewed_at

@ -257,6 +257,7 @@ defmodule Explorer.Chain do
defp common_where_limit_order(query, paging_options) do
query
|> InternalTransaction.where_is_different_from_parent_transaction()
# todo: replace `index_int_tx_desc_order` with `index_internal_transaction_desc_order` in the next line when new frontend is bound to `index_internal_transaction_desc_order` property
|> page_internal_transaction(paging_options, %{index_int_tx_desc_order: true})
|> limit(^paging_options.page_size)
|> order_by(
@ -286,7 +287,7 @@ defmodule Explorer.Chain do
|> Transaction.address_to_transactions_tasks_query(true)
|> Transaction.not_pending_transactions()
|> join_associations(necessity_by_association)
|> Transaction.put_has_token_transfers_to_tx(false)
|> Transaction.put_has_token_transfers_to_transaction(false)
|> Transaction.matching_address_queries_list(direction, address_hashes)
|> Enum.map(fn query -> Task.async(fn -> select_repo(options).all(query) end) end)
end
@ -569,15 +570,17 @@ defmodule Explorer.Chain do
|> fetch_transactions_in_ascending_order_by_index()
|> join(:inner, [transaction], block in assoc(transaction, :block))
|> where([_, block], block.hash == ^block_hash)
|> apply_filter_by_tx_type_to_transactions(type_filter)
|> apply_filter_by_type_to_transactions(type_filter)
|> join_associations(necessity_by_association)
|> Transaction.put_has_token_transfers_to_tx(old_ui?)
|> Transaction.put_has_token_transfers_to_transaction(old_ui?)
|> (&if(old_ui?, do: preload(&1, [{:token_transfers, [:token, :from_address, :to_address]}]), else: &1)).()
|> select_repo(options).all()
|> (&if(old_ui?,
do: &1,
else:
Enum.map(&1, fn tx -> preload_token_transfers(tx, @token_transfers_necessity_by_association, options) end)
Enum.map(&1, fn transaction ->
preload_token_transfers(transaction, @token_transfers_necessity_by_association, options)
end)
)).()
end
@ -591,10 +594,12 @@ defmodule Explorer.Chain do
|> fetch_transactions_in_descending_order_by_block_and_index()
|> where(execution_node_hash: ^execution_node_hash)
|> join_associations(necessity_by_association)
|> Transaction.put_has_token_transfers_to_tx(false)
|> Transaction.put_has_token_transfers_to_transaction(false)
|> (& &1).()
|> select_repo(options).all()
|> (&Enum.map(&1, fn tx -> preload_token_transfers(tx, @token_transfers_necessity_by_association, options) end)).()
|> (&Enum.map(&1, fn transaction ->
preload_token_transfers(transaction, @token_transfers_necessity_by_association, options)
end)).()
end
@spec block_to_withdrawals(
@ -613,15 +618,15 @@ defmodule Explorer.Chain do
end
@doc """
Finds sum of gas_used for new (EIP-1559) txs belongs to block
Finds sum of gas_used for new (EIP-1559) transactions belongs to block
"""
@spec block_to_gas_used_by_1559_txs(Hash.Full.t()) :: non_neg_integer()
def block_to_gas_used_by_1559_txs(block_hash) do
@spec block_to_gas_used_by_1559_transactions(Hash.Full.t()) :: non_neg_integer()
def block_to_gas_used_by_1559_transactions(block_hash) do
query =
from(
tx in Transaction,
where: tx.block_hash == ^block_hash,
select: sum(tx.gas_used)
transaction in Transaction,
where: transaction.block_hash == ^block_hash,
select: sum(transaction.gas_used)
)
result = Repo.one(query)
@ -629,18 +634,18 @@ defmodule Explorer.Chain do
end
@doc """
Finds sum of priority fee for new (EIP-1559) txs belongs to block
Finds sum of priority fee for new (EIP-1559) transactions belongs to block
"""
@spec block_to_priority_fee_of_1559_txs(Hash.Full.t()) :: Decimal.t()
def block_to_priority_fee_of_1559_txs(block_hash) do
@spec block_to_priority_fee_of_1559_transactions(Hash.Full.t()) :: Decimal.t()
def block_to_priority_fee_of_1559_transactions(block_hash) do
block = Repo.get_by(Block, hash: block_hash)
case block.base_fee_per_gas do
%Wei{value: base_fee_per_gas} ->
query =
from(
tx in Transaction,
where: tx.block_hash == ^block_hash,
transaction in Transaction,
where: transaction.block_hash == ^block_hash,
select:
sum(
fragment(
@ -648,20 +653,20 @@ defmodule Explorer.Chain do
WHEN COALESCE(?,?) = 0 THEN 0
WHEN COALESCE(?,?) - ? < COALESCE(?,?) THEN (COALESCE(?,?) - ?) * ?
ELSE COALESCE(?,?) * ? END",
tx.max_fee_per_gas,
tx.gas_price,
tx.max_fee_per_gas,
tx.gas_price,
transaction.max_fee_per_gas,
transaction.gas_price,
transaction.max_fee_per_gas,
transaction.gas_price,
^base_fee_per_gas,
tx.max_priority_fee_per_gas,
tx.gas_price,
tx.max_fee_per_gas,
tx.gas_price,
transaction.max_priority_fee_per_gas,
transaction.gas_price,
transaction.max_fee_per_gas,
transaction.gas_price,
^base_fee_per_gas,
tx.gas_used,
tx.max_priority_fee_per_gas,
tx.gas_price,
tx.gas_used
transaction.gas_used,
transaction.max_priority_fee_per_gas,
transaction.gas_price,
transaction.gas_used
)
)
)
@ -1348,9 +1353,9 @@ defmodule Explorer.Chain do
end
end
# preload_to_detect_tt?: we don't need to preload more than one token transfer in case the tx inside the list (we don't show any token transfers on tx tile in new UI)
# preload_to_detect_tt?: we don't need to preload more than one token transfer in case the transaction inside the list (we don't show any token transfers on transaction tile in new UI)
def preload_token_transfers(
%Transaction{hash: tx_hash, block_hash: block_hash} = transaction,
%Transaction{hash: transaction_hash, block_hash: block_hash} = transaction,
necessity_by_association,
options,
preload_to_detect_tt? \\ true
@ -1363,12 +1368,12 @@ defmodule Explorer.Chain do
token_transfers =
TokenTransfer
|> (&if(is_nil(block_hash),
do: where(&1, [token_transfer], token_transfer.transaction_hash == ^tx_hash),
do: where(&1, [token_transfer], token_transfer.transaction_hash == ^transaction_hash),
else:
where(
&1,
[token_transfer],
token_transfer.transaction_hash == ^tx_hash and token_transfer.block_hash == ^block_hash
token_transfer.transaction_hash == ^transaction_hash and token_transfer.block_hash == ^block_hash
)
)).()
|> limit(^limit)
@ -1505,9 +1510,9 @@ defmodule Explorer.Chain do
full_blocks_range =
max_saved_block_number - min_blockchain_trace_block_number - BlockNumberHelper.null_rounds_count() + 1
processed_int_txs_for_blocks_count = max(0, full_blocks_range - pbo_count)
processed_int_transactions_for_blocks_count = max(0, full_blocks_range - pbo_count)
ratio = get_ratio(processed_int_txs_for_blocks_count, full_blocks_range)
ratio = get_ratio(processed_int_transactions_for_blocks_count, full_blocks_range)
ratio
|> (&if(
@ -2683,16 +2688,16 @@ defmodule Explorer.Chain do
|> Transaction.fetch_transactions()
|> where([transaction], not is_nil(transaction.block_number) and not is_nil(transaction.index))
|> apply_filter_by_method_id_to_transactions(method_id_filter)
|> apply_filter_by_tx_type_to_transactions(type_filter)
|> apply_filter_by_type_to_transactions(type_filter)
|> join_associations(necessity_by_association)
|> Transaction.put_has_token_transfers_to_tx(old_ui?)
|> Transaction.put_has_token_transfers_to_transaction(old_ui?)
|> (&if(old_ui?, do: preload(&1, [{:token_transfers, [:token, :from_address, :to_address]}]), else: &1)).()
|> select_repo(options).all()
|> (&if(old_ui?,
do: &1,
else:
Enum.map(&1, fn tx ->
preload_token_transfers(tx, @token_transfers_necessity_by_association, options)
Enum.map(&1, fn transaction ->
preload_token_transfers(transaction, @token_transfers_necessity_by_association, options)
end)
)).()
end
@ -2737,7 +2742,7 @@ defmodule Explorer.Chain do
|> limit(^paging_options.page_size)
|> pending_transactions_query()
|> apply_filter_by_method_id_to_transactions(method_id_filter)
|> apply_filter_by_tx_type_to_transactions(type_filter)
|> apply_filter_by_type_to_transactions(type_filter)
|> order_by([transaction], desc: transaction.inserted_at, asc: transaction.hash)
|> join_associations(necessity_by_association)
|> (&if(old_ui?, do: preload(&1, [{:token_transfers, [:token, :from_address, :to_address]}]), else: &1)).()
@ -2976,13 +2981,13 @@ defmodule Explorer.Chain do
%Transaction{revert_reason: revert_reason} = transaction
if revert_reason == nil do
fetch_tx_revert_reason(transaction)
fetch_transaction_revert_reason(transaction)
else
revert_reason
end
end
def fetch_tx_revert_reason(transaction) do
def fetch_transaction_revert_reason(transaction) do
json_rpc_named_arguments = Application.get_env(:explorer, :json_rpc_named_arguments)
hash_string = to_string(transaction.hash)
@ -3007,13 +3012,13 @@ defmodule Explorer.Chain do
{:error, reason} ->
Logger.error(fn ->
["Error while fetching first trace for tx: #{hash_string} error reason: ", inspect(reason)]
["Error while fetching first trace for transaction: #{hash_string} error reason: ", inspect(reason)]
end)
fetch_tx_revert_reason_using_call(transaction)
fetch_transaction_revert_reason_using_call(transaction)
:ignore ->
fetch_tx_revert_reason_using_call(transaction)
fetch_transaction_revert_reason_using_call(transaction)
end
if !is_nil(revert_reason) do
@ -3025,7 +3030,7 @@ defmodule Explorer.Chain do
revert_reason
end
defp fetch_tx_revert_reason_using_call(%Transaction{
defp fetch_transaction_revert_reason_using_call(%Transaction{
block_number: block_number,
to_address_hash: to_address_hash,
from_address_hash: from_address_hash,
@ -3142,29 +3147,29 @@ defmodule Explorer.Chain do
|> Data.to_string()
end
def smart_contract_creation_tx_bytecode(address_hash) do
creation_tx_query =
def smart_contract_creation_transaction_bytecode(address_hash) do
creation_transaction_query =
from(
tx in Transaction,
transaction in Transaction,
left_join: a in Address,
on: tx.created_contract_address_hash == a.hash,
where: tx.created_contract_address_hash == ^address_hash,
where: tx.status == ^1,
select: %{init: tx.input, created_contract_code: a.contract_code},
order_by: [desc: tx.block_number],
on: transaction.created_contract_address_hash == a.hash,
where: transaction.created_contract_address_hash == ^address_hash,
where: transaction.status == ^1,
select: %{init: transaction.input, created_contract_code: a.contract_code},
order_by: [desc: transaction.block_number],
limit: ^1
)
tx_input =
creation_tx_query
transaction_input =
creation_transaction_query
|> Repo.one()
if tx_input do
with %{init: input, created_contract_code: created_contract_code} <- tx_input do
if transaction_input do
with %{init: input, created_contract_code: created_contract_code} <- transaction_input do
%{init: Data.to_string(input), created_contract_code: Data.to_string(created_contract_code)}
end
else
creation_int_tx_query =
creation_int_transaction_query =
from(
itx in InternalTransaction,
join: t in assoc(itx, :transaction),
@ -3175,7 +3180,7 @@ defmodule Explorer.Chain do
limit: ^1
)
res = creation_int_tx_query |> Repo.one()
res = creation_int_transaction_query |> Repo.one()
case res do
%{init: init, created_contract_code: created_contract_code} ->
@ -3430,16 +3435,25 @@ defmodule Explorer.Chain do
where(query, [coin_balance], coin_balance.block_number < ^block_number)
end
# todo: replace `index_int_tx_desc_order` with `index_internal_transaction_desc_order` in the next clause when new frontend is bound to `index_internal_transaction_desc_order` property
def page_internal_transaction(_, _, _ \\ %{index_int_tx_desc_order: false})
def page_internal_transaction(query, %PagingOptions{key: nil}, _), do: query
# todo: keep next clause for compatibility with frontend and remove when new frontend is bound to `index_internal_transaction_desc_order` property
def 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)
hardcoded_where_for_page_internal_transaction(query, block_number, transaction_index, index, desc)
end
def page_internal_transaction(query, %PagingOptions{key: {block_number, transaction_index, index}}, %{
index_internal_transaction_desc_order: desc
}) do
hardcoded_where_for_page_internal_transaction(query, block_number, transaction_index, index, desc)
end
# todo: keep next clause for compatibility with frontend and remove when new frontend is bound to `index_internal_transaction_desc_order` property
def page_internal_transaction(query, %PagingOptions{key: {0}}, %{index_int_tx_desc_order: desc}) do
if desc do
query
@ -3448,6 +3462,15 @@ defmodule Explorer.Chain do
end
end
def page_internal_transaction(query, %PagingOptions{key: {0}}, %{index_internal_transaction_desc_order: desc}) do
if desc do
query
else
where(query, [internal_transaction], internal_transaction.index > 0)
end
end
# todo: keep next clause for compatibility with frontend and remove when new frontend is bound to `index_internal_transaction_desc_order` property
def 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)
@ -3456,7 +3479,15 @@ defmodule Explorer.Chain do
end
end
defp hardcoded_where_for_page_int_tx(query, 0, 0, index, false),
def page_internal_transaction(query, %PagingOptions{key: {index}}, %{index_internal_transaction_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_internal_transaction(query, 0, 0, index, false),
do:
where(
query,
@ -3465,7 +3496,7 @@ defmodule Explorer.Chain do
internal_transaction.transaction_index == 0 and internal_transaction.index > ^index
)
defp hardcoded_where_for_page_int_tx(query, block_number, 0, index, false),
defp hardcoded_where_for_page_internal_transaction(query, block_number, 0, index, false),
do:
where(
query,
@ -3475,7 +3506,7 @@ defmodule Explorer.Chain do
internal_transaction.transaction_index == 0 and internal_transaction.index > ^index)
)
defp hardcoded_where_for_page_int_tx(query, block_number, transaction_index, index, false),
defp hardcoded_where_for_page_internal_transaction(query, block_number, transaction_index, index, false),
do:
where(
query,
@ -3487,7 +3518,7 @@ defmodule Explorer.Chain do
internal_transaction.transaction_index == ^transaction_index and internal_transaction.index > ^index)
)
defp hardcoded_where_for_page_int_tx(query, 0, 0, index, true),
defp hardcoded_where_for_page_internal_transaction(query, 0, 0, index, true),
do:
where(
query,
@ -3496,7 +3527,7 @@ defmodule Explorer.Chain do
internal_transaction.transaction_index == 0 and internal_transaction.index < ^index
)
defp hardcoded_where_for_page_int_tx(query, block_number, 0, 0, true),
defp hardcoded_where_for_page_internal_transaction(query, block_number, 0, 0, true),
do:
where(
query,
@ -3504,7 +3535,7 @@ defmodule Explorer.Chain do
internal_transaction.block_number < ^block_number
)
defp hardcoded_where_for_page_int_tx(query, block_number, 0, index, true),
defp hardcoded_where_for_page_internal_transaction(query, block_number, 0, index, true),
do:
where(
query,
@ -3514,7 +3545,7 @@ defmodule Explorer.Chain do
internal_transaction.transaction_index == 0 and internal_transaction.index < ^index)
)
defp hardcoded_where_for_page_int_tx(query, block_number, transaction_index, 0, true),
defp hardcoded_where_for_page_internal_transaction(query, block_number, transaction_index, 0, true),
do:
where(
query,
@ -3524,7 +3555,7 @@ defmodule Explorer.Chain do
internal_transaction.transaction_index < ^transaction_index)
)
defp hardcoded_where_for_page_int_tx(query, block_number, transaction_index, index, true),
defp hardcoded_where_for_page_internal_transaction(query, block_number, transaction_index, index, true),
do:
where(
query,
@ -4194,18 +4225,20 @@ defmodule Explorer.Chain do
end
end
# Here we fetch from DB one tx per one coin balance. It's much more faster than LEFT OUTER JOIN which was before.
# Here we fetch from DB one transaction per one coin balance. It's much more faster than LEFT OUTER JOIN which was before.
defp preload_transactions(balances, options) do
tasks =
Enum.map(balances, fn balance ->
Task.async(fn ->
Transaction
|> where(
[tx],
tx.block_number == ^balance.block_number and (tx.value > ^0 or (tx.gas_price > ^0 and tx.gas_used > ^0)) and
(tx.to_address_hash == ^balance.address_hash or tx.from_address_hash == ^balance.address_hash)
[transaction],
transaction.block_number == ^balance.block_number and
(transaction.value > ^0 or (transaction.gas_price > ^0 and transaction.gas_used > ^0)) and
(transaction.to_address_hash == ^balance.address_hash or
transaction.from_address_hash == ^balance.address_hash)
)
|> select([tx], tx.hash)
|> select([transaction], transaction.hash)
|> limit(1)
|> select_repo(options).one()
end)
@ -4217,7 +4250,7 @@ defmodule Explorer.Chain do
|> Enum.map(fn {{task, res}, balance} ->
case res do
{:ok, hash} ->
put_tx_hash(hash, balance)
put_transaction_hash(hash, balance)
{:exit, _reason} ->
balance
@ -4229,7 +4262,7 @@ defmodule Explorer.Chain do
end)
end
defp put_tx_hash(hash, coin_balance),
defp put_transaction_hash(hash, coin_balance),
do: if(hash, do: %CoinBalance{coin_balance | transaction_hash: hash}, else: coin_balance)
defp add_block_timestamp_to_balances(
@ -4840,7 +4873,7 @@ defmodule Explorer.Chain do
def fetch_first_trace(transactions_params, json_rpc_named_arguments) do
case EthereumJSONRPC.fetch_first_trace(transactions_params, json_rpc_named_arguments) do
{:ok, [%{first_trace: first_trace, block_hash: block_hash, json_rpc_named_arguments: json_rpc_named_arguments}]} ->
format_tx_first_trace(first_trace, block_hash, json_rpc_named_arguments)
format_transaction_first_trace(first_trace, block_hash, json_rpc_named_arguments)
{:error, error} ->
{:error, error}
@ -4850,7 +4883,7 @@ defmodule Explorer.Chain do
end
end
defp format_tx_first_trace(first_trace, block_hash, json_rpc_named_arguments) do
defp format_transaction_first_trace(first_trace, block_hash, json_rpc_named_arguments) do
{:ok, to_address_hash} =
if Map.has_key?(first_trace, :to_address_hash) do
Chain.string_to_address_hash(first_trace.to_address_hash)
@ -5089,7 +5122,7 @@ defmodule Explorer.Chain do
if method_ids != [] do
query
|> where([tx], fragment("SUBSTRING(? FOR 4)", tx.input) in ^method_ids)
|> where([transaction], fragment("SUBSTRING(? FOR 4)", transaction.input) in ^method_ids)
else
query
end
@ -5120,49 +5153,49 @@ defmodule Explorer.Chain do
end
end
def apply_filter_by_tx_type_to_transactions(query, [_ | _] = filter) do
{dynamic, modified_query} = apply_filter_by_tx_type_to_transactions_inner(filter, query)
def apply_filter_by_type_to_transactions(query, [_ | _] = filter) do
{dynamic, modified_query} = apply_filter_by_type_to_transactions_inner(filter, query)
modified_query
|> where(^dynamic)
end
def apply_filter_by_tx_type_to_transactions(query, _filter), do: query
def apply_filter_by_type_to_transactions(query, _filter), do: query
def apply_filter_by_tx_type_to_transactions_inner(dynamic \\ dynamic(false), filter, query)
def apply_filter_by_type_to_transactions_inner(dynamic \\ dynamic(false), filter, query)
def apply_filter_by_tx_type_to_transactions_inner(dynamic, [type | remain], query) do
def apply_filter_by_type_to_transactions_inner(dynamic, [type | remain], query) do
case type do
:contract_call ->
dynamic
|> filter_contract_call_dynamic()
|> apply_filter_by_tx_type_to_transactions_inner(
|> apply_filter_by_type_to_transactions_inner(
remain,
join(query, :inner, [tx], address in assoc(tx, :to_address), as: :to_address)
join(query, :inner, [transaction], address in assoc(transaction, :to_address), as: :to_address)
)
:contract_creation ->
dynamic
|> filter_contract_creation_dynamic()
|> apply_filter_by_tx_type_to_transactions_inner(remain, query)
|> apply_filter_by_type_to_transactions_inner(remain, query)
:coin_transfer ->
dynamic
|> filter_transaction_dynamic()
|> apply_filter_by_tx_type_to_transactions_inner(remain, query)
|> apply_filter_by_type_to_transactions_inner(remain, query)
:token_transfer ->
dynamic
|> filter_token_transfer_dynamic()
|> apply_filter_by_tx_type_to_transactions_inner(remain, query)
|> apply_filter_by_type_to_transactions_inner(remain, query)
:token_creation ->
dynamic
|> filter_token_creation_dynamic()
|> apply_filter_by_tx_type_to_transactions_inner(
|> apply_filter_by_type_to_transactions_inner(
remain,
join(query, :inner, [tx], token in Token,
on: token.contract_address_hash == tx.created_contract_address_hash,
join(query, :inner, [transaction], token in Token,
on: token.contract_address_hash == transaction.created_contract_address_hash,
as: :created_token
)
)
@ -5170,43 +5203,43 @@ defmodule Explorer.Chain do
:blob_transaction ->
dynamic
|> filter_blob_transaction_dynamic()
|> apply_filter_by_tx_type_to_transactions_inner(remain, query)
|> apply_filter_by_type_to_transactions_inner(remain, query)
end
end
def apply_filter_by_tx_type_to_transactions_inner(dynamic_query, _, query), do: {dynamic_query, query}
def apply_filter_by_type_to_transactions_inner(dynamic_query, _, query), do: {dynamic_query, query}
def filter_contract_creation_dynamic(dynamic) do
dynamic([tx], ^dynamic or is_nil(tx.to_address_hash))
dynamic([transaction], ^dynamic or is_nil(transaction.to_address_hash))
end
def filter_transaction_dynamic(dynamic) do
dynamic([tx], ^dynamic or tx.value > ^0)
dynamic([transaction], ^dynamic or transaction.value > ^0)
end
def filter_contract_call_dynamic(dynamic) do
dynamic([tx, to_address: to_address], ^dynamic or not is_nil(to_address.contract_code))
dynamic([transaction, to_address: to_address], ^dynamic or not is_nil(to_address.contract_code))
end
def filter_token_transfer_dynamic(dynamic) do
# TokenTransfer.__struct__.__meta__.source
dynamic(
[tx],
[transaction],
^dynamic or
fragment(
"NOT (SELECT transaction_hash FROM token_transfers WHERE transaction_hash = ? LIMIT 1) IS NULL",
tx.hash
transaction.hash
)
)
end
def filter_token_creation_dynamic(dynamic) do
dynamic([tx, created_token: created_token], ^dynamic or not is_nil(created_token))
dynamic([transaction, created_token: created_token], ^dynamic or not is_nil(created_token))
end
def filter_blob_transaction_dynamic(dynamic) do
# EIP-2718 blob transaction type
dynamic([tx], ^dynamic or tx.type == 3)
dynamic([transaction], ^dynamic or transaction.type == 3)
end
def count_verified_contracts do
@ -5237,11 +5270,14 @@ defmodule Explorer.Chain do
def count_new_contracts do
query =
from(tx in Transaction,
select: tx,
from(transaction in Transaction,
select: transaction,
where:
tx.status == ^:ok and
fragment("NOW() - ? at time zone 'UTC' <= interval '24 hours'", tx.created_contract_code_indexed_at)
transaction.status == ^:ok and
fragment(
"NOW() - ? at time zone 'UTC' <= interval '24 hours'",
transaction.created_contract_code_indexed_at
)
)
query

@ -38,8 +38,8 @@ defmodule Explorer.Chain.Address.Counters do
@typep counter :: non_neg_integer() | nil
@counters_limit 51
@types [:validations, :txs, :token_transfers, :token_balances, :logs, :withdrawals, :internal_txs]
@txs_types [:txs_from, :txs_to, :txs_contract]
@types [:validations, :transactions, :token_transfers, :token_balances, :logs, :withdrawals, :internal_transactions]
@transactions_types [:transactions_from, :transactions_to, :transactions_contract]
defp address_hash_to_logs_query(address_hash) do
from(l in Log, where: l.address_hash == ^address_hash)
@ -293,7 +293,7 @@ defmodule Explorer.Chain.Address.Counters do
end
end
defp address_hash_to_internal_txs_limited_count_query(address_hash) do
defp address_hash_to_internal_transactions_limited_count_query(address_hash) do
query_to_address_hash_wrapped =
InternalTransaction
|> InternalTransaction.where_nonpending_block()
@ -400,7 +400,7 @@ defmodule Explorer.Chain.Address.Counters do
)
transactions_from_count_task =
run_or_ignore(cached_counters[:txs], :txs_from, address_hash, fn ->
run_or_ignore(cached_counters[:transactions], :transactions_from, address_hash, fn ->
result =
Transaction
|> where([t], t.from_address_hash == ^address_hash)
@ -414,14 +414,18 @@ defmodule Explorer.Chain.Address.Counters do
Logger.info("Time consumed for transactions_from_count_task for #{address_hash} is #{diff}ms")
AddressesTabsCounters.save_txs_counter_progress(address_hash, %{txs_types: [:txs_from], txs_from: result})
AddressesTabsCounters.drop_task(:txs_from, address_hash)
AddressesTabsCounters.save_transactions_counter_progress(address_hash, %{
transactions_types: [:transactions_from],
transactions_from: result
})
AddressesTabsCounters.drop_task(:transactions_from, address_hash)
{:txs_from, result}
{:transactions_from, result}
end)
transactions_to_count_task =
run_or_ignore(cached_counters[:txs], :txs_to, address_hash, fn ->
run_or_ignore(cached_counters[:transactions], :transactions_to, address_hash, fn ->
result =
Transaction
|> where([t], t.to_address_hash == ^address_hash)
@ -435,14 +439,18 @@ defmodule Explorer.Chain.Address.Counters do
Logger.info("Time consumed for transactions_to_count_task for #{address_hash} is #{diff}ms")
AddressesTabsCounters.save_txs_counter_progress(address_hash, %{txs_types: [:txs_to], txs_to: result})
AddressesTabsCounters.drop_task(:txs_to, address_hash)
AddressesTabsCounters.save_transactions_counter_progress(address_hash, %{
transactions_types: [:transactions_to],
transactions_to: result
})
AddressesTabsCounters.drop_task(:transactions_to, address_hash)
{:txs_to, result}
{:transactions_to, result}
end)
transactions_created_contract_count_task =
run_or_ignore(cached_counters[:txs], :txs_contract, address_hash, fn ->
run_or_ignore(cached_counters[:transactions], :transactions_contract, address_hash, fn ->
result =
Transaction
|> where([t], t.created_contract_address_hash == ^address_hash)
@ -456,14 +464,14 @@ defmodule Explorer.Chain.Address.Counters do
Logger.info("Time consumed for transactions_created_contract_count_task for #{address_hash} is #{diff}ms")
AddressesTabsCounters.save_txs_counter_progress(address_hash, %{
txs_types: [:txs_contract],
txs_contract: result
AddressesTabsCounters.save_transactions_counter_progress(address_hash, %{
transactions_types: [:transactions_contract],
transactions_contract: result
})
AddressesTabsCounters.drop_task(:txs_contract, address_hash)
AddressesTabsCounters.drop_task(:transactions_contract, address_hash)
{:txs_contract, result}
{:transactions_contract, result}
end)
token_transfers_count_task =
@ -502,11 +510,11 @@ defmodule Explorer.Chain.Address.Counters do
options
)
internal_txs_count_task =
internal_transactions_count_task =
configure_task(
:internal_txs,
:internal_transactions,
cached_counters,
address_hash_to_internal_txs_limited_count_query(address_hash),
address_hash_to_internal_transactions_limited_count_query(address_hash),
address_hash,
options
)
@ -534,18 +542,19 @@ defmodule Explorer.Chain.Address.Counters do
token_balances_count_task,
logs_count_task,
withdrawals_count_task,
internal_txs_count_task,
internal_transactions_count_task,
celo_election_rewards_count_task
]
|> Enum.reject(&is_nil/1)
|> Task.yield_many(:timer.seconds(1))
|> Enum.reduce(Map.merge(prepare_cache_values(cached_counters), %{txs_types: [], txs_hashes: []}), fn {task, res},
acc ->
|> Enum.reduce(
Map.merge(prepare_cache_values(cached_counters), %{transactions_types: [], transactions_hashes: []}),
fn {task, res}, acc ->
case res do
{:ok, {txs_type, txs_hashes}} when txs_type in @txs_types ->
{:ok, {transactions_type, transactions_hashes}} when transactions_type in @transactions_types ->
acc
|> (&Map.put(&1, :txs_types, [txs_type | &1[:txs_types]])).()
|> (&Map.put(&1, :txs_hashes, &1[:txs_hashes] ++ txs_hashes)).()
|> (&Map.put(&1, :transactions_types, [transactions_type | &1[:transactions_types]])).()
|> (&Map.put(&1, :transactions_hashes, &1[:transactions_hashes] ++ transactions_hashes)).()
{:ok, {type, counter}} ->
Map.put(acc, type, counter)
@ -570,8 +579,9 @@ defmodule Explorer.Chain.Address.Counters do
acc
end
end)
|> process_txs_counter()
end
)
|> process_transactions_counter()
map
end
@ -608,17 +618,19 @@ defmodule Explorer.Chain.Address.Counters do
end)
end
defp process_txs_counter(%{txs_types: [_ | _] = txs_types, txs_hashes: hashes} = map) do
defp process_transactions_counter(
%{transactions_types: [_ | _] = transactions_types, transactions_hashes: hashes} = map
) do
counter = hashes |> Enum.uniq() |> Enum.count() |> min(@counters_limit)
if Enum.count(txs_types) == 3 || counter == @counters_limit do
map |> Map.put(:txs, counter)
if Enum.count(transactions_types) == 3 || counter == @counters_limit do
map |> Map.put(:transactions, counter)
else
map
end
end
defp process_txs_counter(map), do: map
defp process_transactions_counter(map), do: map
defp prepare_cache_values(cached_counters) do
Enum.reduce(cached_counters, %{}, fn
@ -633,8 +645,8 @@ defmodule Explorer.Chain.Address.Counters do
@doc """
Returns all possible transactions type
"""
@spec txs_types :: list(atom)
def txs_types, do: @txs_types
@spec transactions_types :: list(atom)
def transactions_types, do: @transactions_types
@doc """
Returns max counter value

@ -200,12 +200,12 @@ defmodule Explorer.Chain.Address.MetadataPreloader do
to_address_hash: to_address_hash,
created_contract_address_hash: created_contract_address_hash,
from_address_hash: from_address_hash
} = tx,
} = transaction,
names,
field_to_put_info
) do
token_transfers =
case tx.token_transfers do
case transaction.token_transfers do
token_transfers_list when is_list(token_transfers_list) ->
Enum.map(token_transfers_list, &put_meta_to_item(&1, names, field_to_put_info))
@ -214,11 +214,11 @@ defmodule Explorer.Chain.Address.MetadataPreloader do
end
%Transaction{
tx
| to_address: alter_address(tx.to_address, to_address_hash, names, field_to_put_info),
transaction
| to_address: alter_address(transaction.to_address, to_address_hash, names, field_to_put_info),
created_contract_address:
alter_address(tx.created_contract_address, created_contract_address_hash, names, field_to_put_info),
from_address: alter_address(tx.from_address, from_address_hash, names, field_to_put_info),
alter_address(transaction.created_contract_address, created_contract_address_hash, names, field_to_put_info),
from_address: alter_address(transaction.from_address, from_address_hash, names, field_to_put_info),
token_transfers: token_transfers
}
end
@ -243,16 +243,16 @@ defmodule Explorer.Chain.Address.MetadataPreloader do
to_address_hash: to_address_hash,
created_contract_address_hash: created_contract_address_hash,
from_address_hash: from_address_hash
} = tx,
} = transaction,
names,
field_to_put_info
) do
%InternalTransaction{
tx
| to_address: alter_address(tx.to_address, to_address_hash, names, field_to_put_info),
transaction
| to_address: alter_address(transaction.to_address, to_address_hash, names, field_to_put_info),
created_contract_address:
alter_address(tx.created_contract_address, created_contract_address_hash, names, field_to_put_info),
from_address: alter_address(tx.from_address, from_address_hash, names, field_to_put_info)
alter_address(transaction.created_contract_address, created_contract_address_hash, names, field_to_put_info),
from_address: alter_address(transaction.from_address, from_address_hash, names, field_to_put_info)
}
end

@ -54,7 +54,7 @@ defmodule Explorer.Chain.AdvancedFilter do
field(:token_transfer_batch_index, :integer, null: true)
end
@typep tx_types :: {:tx_types, [String.t()] | nil}
@typep transaction_types :: {:transaction_types, [String.t()] | nil}
@typep methods :: {:methods, [String.t()] | nil}
@typep age :: {:age, [{:from, DateTime.t() | nil} | {:to, DateTime.t() | nil}] | nil}
@typep from_address_hashes :: {:from_address_hashes, [Hash.Address.t()] | nil}
@ -64,7 +64,7 @@ defmodule Explorer.Chain.AdvancedFilter do
@typep token_contract_address_hashes ::
{:token_contract_address_hashes, [{:include, [Hash.Address.t()]} | {:include, [Hash.Address.t()]}] | nil}
@type options :: [
tx_types()
transaction_types()
| methods()
| age()
| from_address_hashes()
@ -122,14 +122,14 @@ defmodule Explorer.Chain.AdvancedFilter do
end
defp only_transactions?(options) do
transaction_types = options[:tx_types]
transaction_types = options[:transaction_types]
tokens_to_include = options[:token_contract_address_hashes][:include]
transaction_types == ["COIN_TRANSFER"] or tokens_to_include == ["native"]
end
defp only_token_transfers?(options) do
transaction_types = options[:tx_types]
transaction_types = options[:transaction_types]
tokens_to_include = options[:token_contract_address_hashes][:include]
tokens_to_exclude = options[:token_contract_address_hashes][:exclude]
@ -270,11 +270,14 @@ defmodule Explorer.Chain.AdvancedFilter do
defp page_transactions(query, %PagingOptions{
key: %{
block_number: block_number,
transaction_index: tx_index
transaction_index: transaction_index
}
}) do
dynamic_condition =
dynamic(^page_block_number_dynamic(:transaction, block_number) or ^page_tx_index_dynamic(block_number, tx_index))
dynamic(
^page_block_number_dynamic(:transaction, block_number) or
^page_transaction_index_dynamic(block_number, transaction_index)
)
query |> where(^dynamic_condition)
end
@ -309,17 +312,17 @@ defmodule Explorer.Chain.AdvancedFilter do
defp page_internal_transactions(query, %PagingOptions{
key: %{
block_number: block_number,
transaction_index: tx_index,
transaction_index: transaction_index,
internal_transaction_index: nil
}
}) do
case {block_number, tx_index} do
case {block_number, transaction_index} do
{0, 0} ->
query |> where(as(:transaction).block_number == ^block_number and as(:transaction).index == ^tx_index)
query |> where(as(:transaction).block_number == ^block_number and as(:transaction).index == ^transaction_index)
{0, tx_index} ->
{0, transaction_index} ->
query
|> where(as(:transaction).block_number == ^block_number and as(:transaction).index <= ^tx_index)
|> where(as(:transaction).block_number == ^block_number and as(:transaction).index <= ^transaction_index)
{block_number, 0} ->
query |> where(as(:transaction).block_number < ^block_number)
@ -328,7 +331,7 @@ defmodule Explorer.Chain.AdvancedFilter do
query
|> where(
as(:transaction).block_number < ^block_number or
(as(:transaction).block_number == ^block_number and as(:transaction).index <= ^tx_index)
(as(:transaction).block_number == ^block_number and as(:transaction).index <= ^transaction_index)
)
end
end
@ -336,14 +339,15 @@ defmodule Explorer.Chain.AdvancedFilter do
defp page_internal_transactions(query, %PagingOptions{
key: %{
block_number: block_number,
transaction_index: tx_index,
transaction_index: transaction_index,
internal_transaction_index: it_index
}
}) do
dynamic_condition =
dynamic(
^page_block_number_dynamic(:transaction, block_number) or ^page_tx_index_dynamic(block_number, tx_index) or
^page_it_index_dynamic(block_number, tx_index, it_index)
^page_block_number_dynamic(:transaction, block_number) or
^page_transaction_index_dynamic(block_number, transaction_index) or
^page_it_index_dynamic(block_number, transaction_index, it_index)
)
query
@ -386,28 +390,31 @@ defmodule Explorer.Chain.AdvancedFilter do
defp page_token_transfers(query, %PagingOptions{
key: %{
block_number: block_number,
transaction_index: tx_index,
transaction_index: transaction_index,
token_transfer_index: nil,
internal_transaction_index: nil
}
}) do
case {block_number, tx_index} do
case {block_number, transaction_index} do
{0, 0} ->
query |> where(as(:transaction).block_number == ^block_number and as(:transaction).index == ^tx_index)
query |> where(as(:transaction).block_number == ^block_number and as(:transaction).index == ^transaction_index)
{0, tx_index} ->
{0, transaction_index} ->
query
|> where([token_transfer], token_transfer.block_number == ^block_number and as(:transaction).index < ^tx_index)
|> where(
[token_transfer],
token_transfer.block_number == ^block_number and as(:transaction).index < ^transaction_index
)
{block_number, 0} ->
query |> where([token_transfer], token_transfer.block_number < ^block_number)
{block_number, tx_index} ->
{block_number, transaction_index} ->
query
|> where(
[token_transfer],
token_transfer.block_number < ^block_number or
(token_transfer.block_number == ^block_number and as(:transaction).index <= ^tx_index)
(token_transfer.block_number == ^block_number and as(:transaction).index <= ^transaction_index)
)
end
end
@ -415,13 +422,14 @@ defmodule Explorer.Chain.AdvancedFilter do
defp page_token_transfers(query, %PagingOptions{
key: %{
block_number: block_number,
transaction_index: tx_index,
transaction_index: transaction_index,
token_transfer_index: nil
}
}) do
dynamic_condition =
dynamic(
^page_block_number_dynamic(:token_transfer, block_number) or ^page_tx_index_dynamic(block_number, tx_index)
^page_block_number_dynamic(:token_transfer, block_number) or
^page_transaction_index_dynamic(block_number, transaction_index)
)
query |> where(^dynamic_condition)
@ -463,18 +471,21 @@ defmodule Explorer.Chain.AdvancedFilter do
dynamic(false)
end
defp page_tx_index_dynamic(block_number, tx_index) when tx_index > 0 do
dynamic([transaction: tx], tx.block_number == ^block_number and tx.index < ^tx_index)
defp page_transaction_index_dynamic(block_number, transaction_index) when transaction_index > 0 do
dynamic(
[transaction: transaction],
transaction.block_number == ^block_number and transaction.index < ^transaction_index
)
end
defp page_tx_index_dynamic(_, _) do
defp page_transaction_index_dynamic(_, _) do
dynamic(false)
end
defp page_it_index_dynamic(block_number, tx_index, it_index) when it_index > 0 do
defp page_it_index_dynamic(block_number, transaction_index, it_index) when it_index > 0 do
dynamic(
[transaction: tx, internal_transaction: it],
tx.block_number == ^block_number and tx.index == ^tx_index and
[transaction: transaction, internal_transaction: it],
transaction.block_number == ^block_number and transaction.index == ^transaction_index and
it.index < ^it_index
)
end
@ -520,7 +531,7 @@ defmodule Explorer.Chain.AdvancedFilter do
defp apply_token_transfers_filters(query, options) do
query
|> filter_by_tx_type(options[:tx_types])
|> filter_by_transaction_type(options[:transaction_types])
|> filter_token_transfers_by_methods(options[:methods])
|> filter_by_token(options[:token_contract_address_hashes][:include], :include)
|> filter_by_token(options[:token_contract_address_hashes][:exclude], :exclude)
@ -545,11 +556,11 @@ defmodule Explorer.Chain.AdvancedFilter do
query |> where(not is_nil(as(:transaction).block_number) and not is_nil(as(:transaction).index))
end
defp filter_by_tx_type(query, [_ | _] = tx_types) do
query |> where([token_transfer], token_transfer.token_type in ^tx_types)
defp filter_by_transaction_type(query, [_ | _] = transaction_types) do
query |> where([token_transfer], token_transfer.token_type in ^transaction_types)
end
defp filter_by_tx_type(query, _), do: query
defp filter_by_transaction_type(query, _), do: query
defp filter_transactions_by_methods(query, [_ | _] = methods) do
prepared_methods = prepare_methods(methods)

@ -14,21 +14,21 @@ defmodule Explorer.Chain.Arbitrum.BatchTransaction do
alias Explorer.Chain.Arbitrum.L1Batch
alias Explorer.Chain.{Hash, Transaction}
@required_attrs ~w(batch_number tx_hash)a
@required_attrs ~w(batch_number transaction_hash)a
@typedoc """
Descriptor of the rollup transaction included in an Arbitrum batch:
* `batch_number` - The number of the Arbitrum batch.
* `tx_hash` - The hash of the rollup transaction.
* `transaction_hash` - The hash of the rollup transaction.
"""
@type to_import :: %{
:batch_number => non_neg_integer(),
:tx_hash => binary()
:transaction_hash => binary()
}
@typedoc """
* `tx_hash` - The hash of the rollup transaction.
* `l2_transaction` - An instance of `Explorer.Chain.Transaction` referenced by `tx_hash`.
* `transaction_hash` - The hash of the rollup transaction.
* `l2_transaction` - An instance of `Explorer.Chain.Transaction` referenced by `transaction_hash`.
* `batch_number` - The number of the Arbitrum batch.
* `batch` - An instance of `Explorer.Chain.Arbitrum.L1Batch` referenced by `batch_number`.
"""
@ -37,7 +37,7 @@ defmodule Explorer.Chain.Arbitrum.BatchTransaction do
belongs_to(:batch, L1Batch, foreign_key: :batch_number, references: :number, type: :integer)
belongs_to(:l2_transaction, Transaction,
foreign_key: :tx_hash,
foreign_key: :transaction_hash,
primary_key: true,
references: :hash,
type: Hash.Full
@ -56,6 +56,6 @@ defmodule Explorer.Chain.Arbitrum.BatchTransaction do
|> validate_required(@required_attrs)
|> foreign_key_constraint(:batch_number)
|> foreign_key_constraint(:block_hash)
|> unique_constraint(:tx_hash)
|> unique_constraint(:transaction_hash)
end
end

@ -84,22 +84,23 @@ defmodule Explorer.Chain.Arbitrum.DaMultiPurposeRecord.Helper do
## Parameters
- `height`: The height of the block in the Celestia network.
- `tx_commitment`: The transaction commitment.
- `transaction_commitment`: The transaction commitment.
## Returns
- A binary representing the calculated data key for the record containing
Celestia blob data.
"""
@spec calculate_celestia_data_key(binary() | non_neg_integer(), binary() | Explorer.Chain.Hash.t()) :: binary()
def calculate_celestia_data_key(height, tx_commitment) when is_binary(height) do
calculate_celestia_data_key(String.to_integer(height), tx_commitment)
def calculate_celestia_data_key(height, transaction_commitment) when is_binary(height) do
calculate_celestia_data_key(String.to_integer(height), transaction_commitment)
end
def calculate_celestia_data_key(height, %Hash{} = tx_commitment) when is_integer(height) do
calculate_celestia_data_key(height, tx_commitment.bytes)
def calculate_celestia_data_key(height, %Hash{} = transaction_commitment) when is_integer(height) do
calculate_celestia_data_key(height, transaction_commitment.bytes)
end
def calculate_celestia_data_key(height, tx_commitment) when is_integer(height) and is_binary(tx_commitment) do
:crypto.hash(:sha256, :binary.encode_unsigned(height) <> tx_commitment)
def calculate_celestia_data_key(height, transaction_commitment)
when is_integer(height) and is_binary(transaction_commitment) do
:crypto.hash(:sha256, :binary.encode_unsigned(height) <> transaction_commitment)
end
end

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save