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