|
|
@ -15,8 +15,6 @@ defmodule BlockScoutWeb.Chain do |
|
|
|
token_contract_address_from_token_name: 1 |
|
|
|
token_contract_address_from_token_name: 1 |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
alias Explorer.Chain.UserOperation |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import Explorer.Helper, only: [parse_integer: 1] |
|
|
|
import Explorer.Helper, only: [parse_integer: 1] |
|
|
|
|
|
|
|
|
|
|
|
alias Ecto.Association.NotLoaded |
|
|
|
alias Ecto.Association.NotLoaded |
|
|
@ -27,6 +25,8 @@ defmodule BlockScoutWeb.Chain do |
|
|
|
Address, |
|
|
|
Address, |
|
|
|
Address.CoinBalance, |
|
|
|
Address.CoinBalance, |
|
|
|
Address.CurrentTokenBalance, |
|
|
|
Address.CurrentTokenBalance, |
|
|
|
|
|
|
|
Beacon, |
|
|
|
|
|
|
|
Beacon.Blob, |
|
|
|
Block, |
|
|
|
Block, |
|
|
|
Hash, |
|
|
|
Hash, |
|
|
|
InternalTransaction, |
|
|
|
InternalTransaction, |
|
|
@ -37,6 +37,7 @@ defmodule BlockScoutWeb.Chain do |
|
|
|
TokenTransfer, |
|
|
|
TokenTransfer, |
|
|
|
Transaction, |
|
|
|
Transaction, |
|
|
|
Transaction.StateChange, |
|
|
|
Transaction.StateChange, |
|
|
|
|
|
|
|
UserOperation, |
|
|
|
Wei, |
|
|
|
Wei, |
|
|
|
Withdrawal |
|
|
|
Withdrawal |
|
|
|
} |
|
|
|
} |
|
|
@ -56,7 +57,7 @@ defmodule BlockScoutWeb.Chain do |
|
|
|
@page_size 50 |
|
|
|
@page_size 50 |
|
|
|
@default_paging_options %PagingOptions{page_size: @page_size + 1} |
|
|
|
@default_paging_options %PagingOptions{page_size: @page_size + 1} |
|
|
|
@address_hash_len 40 |
|
|
|
@address_hash_len 40 |
|
|
|
@tx_block_op_hash_len 64 |
|
|
|
@full_hash_len 64 |
|
|
|
|
|
|
|
|
|
|
|
def default_paging_options do |
|
|
|
def default_paging_options do |
|
|
|
@default_paging_options |
|
|
|
@default_paging_options |
|
|
@ -83,20 +84,20 @@ defmodule BlockScoutWeb.Chain do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@spec from_param(String.t()) :: |
|
|
|
@spec from_param(String.t()) :: |
|
|
|
{:ok, Address.t() | Block.t() | Transaction.t() | UserOperation.t()} | {:error, :not_found} |
|
|
|
{:ok, Address.t() | Block.t() | Transaction.t() | UserOperation.t() | Blob.t()} | {:error, :not_found} |
|
|
|
def from_param(param) |
|
|
|
def from_param(param) |
|
|
|
|
|
|
|
|
|
|
|
def from_param("0x" <> number_string = param) when byte_size(number_string) == @address_hash_len, |
|
|
|
def from_param("0x" <> number_string = param) when byte_size(number_string) == @address_hash_len, |
|
|
|
do: address_from_param(param) |
|
|
|
do: address_from_param(param) |
|
|
|
|
|
|
|
|
|
|
|
def from_param("0x" <> number_string = param) when byte_size(number_string) == @tx_block_op_hash_len, |
|
|
|
def from_param("0x" <> number_string = param) when byte_size(number_string) == @full_hash_len, |
|
|
|
do: block_or_transaction_or_operation_from_param(param) |
|
|
|
do: block_or_transaction_or_operation_or_blob_from_param(param) |
|
|
|
|
|
|
|
|
|
|
|
def from_param(param) when byte_size(param) == @address_hash_len, |
|
|
|
def from_param(param) when byte_size(param) == @address_hash_len, |
|
|
|
do: address_from_param("0x" <> param) |
|
|
|
do: address_from_param("0x" <> param) |
|
|
|
|
|
|
|
|
|
|
|
def from_param(param) when byte_size(param) == @tx_block_op_hash_len, |
|
|
|
def from_param(param) when byte_size(param) == @full_hash_len, |
|
|
|
do: block_or_transaction_or_operation_from_param("0x" <> param) |
|
|
|
do: block_or_transaction_or_operation_or_blob_from_param("0x" <> param) |
|
|
|
|
|
|
|
|
|
|
|
def from_param(string) when is_binary(string) do |
|
|
|
def from_param(string) when is_binary(string) do |
|
|
|
case param_to_block_number(string) do |
|
|
|
case param_to_block_number(string) do |
|
|
@ -673,31 +674,32 @@ defmodule BlockScoutWeb.Chain do |
|
|
|
%{"fiat_value" => ctb.fiat_value, "value" => value, "id" => id} |
|
|
|
%{"fiat_value" => ctb.fiat_value, "value" => value, "id" => id} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp block_or_transaction_or_operation_from_param(param) do |
|
|
|
defp block_or_transaction_or_operation_or_blob_from_param(param) do |
|
|
|
with {:error, :not_found} <- transaction_from_param(param) do |
|
|
|
with {:ok, hash} <- string_to_transaction_hash(param), |
|
|
|
hash_string_to_block_or_operation(param) |
|
|
|
{:error, :not_found} <- hash_to_transaction(hash), |
|
|
|
|
|
|
|
{:error, :not_found} <- hash_to_block(hash), |
|
|
|
|
|
|
|
{:error, :not_found} <- hash_to_user_operation(hash), |
|
|
|
|
|
|
|
{:error, :not_found} <- hash_to_blob(hash) do |
|
|
|
|
|
|
|
{:error, :not_found} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
:error -> {:error, :not_found} |
|
|
|
|
|
|
|
res -> res |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp transaction_from_param(param) do |
|
|
|
defp hash_to_user_operation(hash) do |
|
|
|
case string_to_transaction_hash(param) do |
|
|
|
if UserOperation.user_operations_enabled?() do |
|
|
|
{:ok, hash} -> |
|
|
|
UserOperation.hash_to_user_operation(hash) |
|
|
|
hash_to_transaction(hash) |
|
|
|
else |
|
|
|
|
|
|
|
|
|
|
|
:error -> |
|
|
|
|
|
|
|
{:error, :not_found} |
|
|
|
{:error, :not_found} |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp hash_string_to_block_or_operation(hash_string) do |
|
|
|
defp hash_to_blob(hash) do |
|
|
|
with {:ok, hash} <- string_to_block_hash(hash_string), |
|
|
|
if Application.get_env(:explorer, :chain_type) == "ethereum" do |
|
|
|
{:error, :not_found} <- hash_to_block(hash), |
|
|
|
Beacon.Reader.blob(hash, false) |
|
|
|
{:user_operations_enabled, true} <- {:user_operations_enabled, UserOperation.user_operations_enabled?()} do |
|
|
|
|
|
|
|
UserOperation.hash_to_user_operation(hash) |
|
|
|
|
|
|
|
else |
|
|
|
else |
|
|
|
{:user_operations_enabled, false} -> {:error, :not_found} |
|
|
|
{:error, :not_found} |
|
|
|
:error -> {:error, :not_found} |
|
|
|
|
|
|
|
res -> res |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|