|
|
@ -12,6 +12,7 @@ defmodule BlockScoutWeb.API.V2.AddressController do |
|
|
|
import BlockScoutWeb.PagingHelper, |
|
|
|
import BlockScoutWeb.PagingHelper, |
|
|
|
only: [delete_parameters_from_next_page_params: 1, token_transfers_types_options: 1] |
|
|
|
only: [delete_parameters_from_next_page_params: 1, token_transfers_types_options: 1] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alias BlockScoutWeb.AccessHelpers |
|
|
|
alias BlockScoutWeb.API.V2.{AddressView, BlockView, TransactionView} |
|
|
|
alias BlockScoutWeb.API.V2.{AddressView, BlockView, TransactionView} |
|
|
|
alias Explorer.{Chain, Market} |
|
|
|
alias Explorer.{Chain, Market} |
|
|
|
alias Indexer.Fetcher.TokenBalanceOnDemand |
|
|
|
alias Indexer.Fetcher.TokenBalanceOnDemand |
|
|
@ -38,8 +39,9 @@ defmodule BlockScoutWeb.API.V2.AddressController do |
|
|
|
|
|
|
|
|
|
|
|
action_fallback(BlockScoutWeb.API.V2.FallbackController) |
|
|
|
action_fallback(BlockScoutWeb.API.V2.FallbackController) |
|
|
|
|
|
|
|
|
|
|
|
def address(conn, %{"address_hash" => address_hash_string}) do |
|
|
|
def address(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)}, |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)}, |
|
|
|
|
|
|
|
{:ok, false} <- AccessHelpers.restricted_access?(address_hash_string, params), |
|
|
|
{:not_found, {:ok, address}} <- {:not_found, Chain.hash_to_address(address_hash)} do |
|
|
|
{:not_found, {:ok, address}} <- {:not_found, Chain.hash_to_address(address_hash)} do |
|
|
|
conn |
|
|
|
conn |
|
|
|
|> put_status(200) |
|
|
|
|> put_status(200) |
|
|
@ -47,8 +49,9 @@ defmodule BlockScoutWeb.API.V2.AddressController do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def counters(conn, %{"address_hash" => address_hash_string}) do |
|
|
|
def counters(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)}, |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)}, |
|
|
|
|
|
|
|
{:ok, false} <- AccessHelpers.restricted_access?(address_hash_string, params), |
|
|
|
{:not_found, {:ok, address}} <- {:not_found, Chain.hash_to_address(address_hash)} do |
|
|
|
{:not_found, {:ok, address}} <- {:not_found, Chain.hash_to_address(address_hash)} do |
|
|
|
{validation_count} = Chain.address_counters(address) |
|
|
|
{validation_count} = Chain.address_counters(address) |
|
|
|
|
|
|
|
|
|
|
@ -65,8 +68,9 @@ defmodule BlockScoutWeb.API.V2.AddressController do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def token_balances(conn, %{"address_hash" => address_hash_string}) do |
|
|
|
def token_balances(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)} do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)}, |
|
|
|
|
|
|
|
{:ok, false} <- AccessHelpers.restricted_access?(address_hash_string, params) do |
|
|
|
token_balances = |
|
|
|
token_balances = |
|
|
|
address_hash |
|
|
|
address_hash |
|
|
|
|> Chain.fetch_last_token_balances() |
|
|
|
|> Chain.fetch_last_token_balances() |
|
|
@ -86,7 +90,8 @@ defmodule BlockScoutWeb.API.V2.AddressController do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def transactions(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
def transactions(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)} do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)}, |
|
|
|
|
|
|
|
{:ok, false} <- AccessHelpers.restricted_access?(address_hash_string, params) do |
|
|
|
options = |
|
|
|
options = |
|
|
|
@transaction_necessity_by_association |
|
|
|
@transaction_necessity_by_association |
|
|
|
|> Keyword.merge(paging_options(params)) |
|
|
|
|> Keyword.merge(paging_options(params)) |
|
|
@ -106,7 +111,8 @@ defmodule BlockScoutWeb.API.V2.AddressController do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def token_transfers(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
def token_transfers(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)} do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)}, |
|
|
|
|
|
|
|
{:ok, false} <- AccessHelpers.restricted_access?(address_hash_string, params) do |
|
|
|
options = |
|
|
|
options = |
|
|
|
@token_transfer_necessity_by_association |
|
|
|
@token_transfer_necessity_by_association |
|
|
|
|> Keyword.merge(paging_options(params)) |
|
|
|
|> Keyword.merge(paging_options(params)) |
|
|
@ -132,7 +138,8 @@ defmodule BlockScoutWeb.API.V2.AddressController do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def internal_transactions(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
def internal_transactions(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)} do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)}, |
|
|
|
|
|
|
|
{:ok, false} <- AccessHelpers.restricted_access?(address_hash_string, params) do |
|
|
|
full_options = |
|
|
|
full_options = |
|
|
|
[ |
|
|
|
[ |
|
|
|
necessity_by_association: %{ |
|
|
|
necessity_by_association: %{ |
|
|
@ -164,7 +171,8 @@ defmodule BlockScoutWeb.API.V2.AddressController do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def logs(conn, %{"address_hash" => address_hash_string, "topic" => topic} = params) do |
|
|
|
def logs(conn, %{"address_hash" => address_hash_string, "topic" => topic} = params) do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)} do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)}, |
|
|
|
|
|
|
|
{:ok, false} <- AccessHelpers.restricted_access?(address_hash_string, params) do |
|
|
|
prepared_topic = String.trim(topic) |
|
|
|
prepared_topic = String.trim(topic) |
|
|
|
|
|
|
|
|
|
|
|
formatted_topic = if String.starts_with?(prepared_topic, "0x"), do: prepared_topic, else: "0x" <> prepared_topic |
|
|
|
formatted_topic = if String.starts_with?(prepared_topic, "0x"), do: prepared_topic, else: "0x" <> prepared_topic |
|
|
@ -183,7 +191,8 @@ defmodule BlockScoutWeb.API.V2.AddressController do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def logs(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
def logs(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)} do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)}, |
|
|
|
|
|
|
|
{:ok, false} <- AccessHelpers.restricted_access?(address_hash_string, params) do |
|
|
|
results_plus_one = Chain.address_to_logs(address_hash, paging_options(params)) |
|
|
|
results_plus_one = Chain.address_to_logs(address_hash, paging_options(params)) |
|
|
|
{logs, next_page} = split_list_by_page(results_plus_one) |
|
|
|
{logs, next_page} = split_list_by_page(results_plus_one) |
|
|
|
|
|
|
|
|
|
|
@ -197,7 +206,8 @@ defmodule BlockScoutWeb.API.V2.AddressController do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def blocks_validated(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
def blocks_validated(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)} do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)}, |
|
|
|
|
|
|
|
{:ok, false} <- AccessHelpers.restricted_access?(address_hash_string, params) do |
|
|
|
full_options = |
|
|
|
full_options = |
|
|
|
Keyword.merge( |
|
|
|
Keyword.merge( |
|
|
|
[ |
|
|
|
[ |
|
|
@ -225,6 +235,7 @@ defmodule BlockScoutWeb.API.V2.AddressController do |
|
|
|
|
|
|
|
|
|
|
|
def coin_balance_history(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
def coin_balance_history(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)}, |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)}, |
|
|
|
|
|
|
|
{:ok, false} <- AccessHelpers.restricted_access?(address_hash_string, params), |
|
|
|
{:not_found, {:ok, _address}, _} <- |
|
|
|
{:not_found, {:ok, _address}, _} <- |
|
|
|
{:not_found, Chain.hash_to_address(address_hash), :empty_items_with_next_page_params} do |
|
|
|
{:not_found, Chain.hash_to_address(address_hash), :empty_items_with_next_page_params} do |
|
|
|
full_options = paging_options(params) |
|
|
|
full_options = paging_options(params) |
|
|
@ -243,8 +254,9 @@ defmodule BlockScoutWeb.API.V2.AddressController do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def coin_balance_history_by_day(conn, %{"address_hash" => address_hash_string}) do |
|
|
|
def coin_balance_history_by_day(conn, %{"address_hash" => address_hash_string} = params) do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)} do |
|
|
|
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)}, |
|
|
|
|
|
|
|
{:ok, false} <- AccessHelpers.restricted_access?(address_hash_string, params) do |
|
|
|
balances_by_day = |
|
|
|
balances_by_day = |
|
|
|
address_hash |
|
|
|
address_hash |
|
|
|
|> Chain.address_to_balances_by_day(true) |
|
|
|
|> Chain.address_to_balances_by_day(true) |
|
|
|