|
|
|
@ -10,6 +10,8 @@ defmodule BlockScoutWeb.TransactionView do |
|
|
|
|
|
|
|
|
|
defguardp is_transaction_type(mod) when mod in [InternalTransaction, Transaction] |
|
|
|
|
|
|
|
|
|
defdelegate formatted_timestamp(block), to: BlockView |
|
|
|
|
|
|
|
|
|
def confirmations(%Transaction{block: block}, named_arguments) when is_list(named_arguments) do |
|
|
|
|
case block do |
|
|
|
|
nil -> 0 |
|
|
|
@ -17,22 +19,19 @@ defmodule BlockScoutWeb.TransactionView do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def from_or_to_address?(_token_transfer, nil), do: false |
|
|
|
|
|
|
|
|
|
def from_or_to_address?(%{from_address_hash: from_hash, to_address_hash: to_hash}, %Address{hash: hash}) do |
|
|
|
|
from_hash == hash || to_hash == hash |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# This is the address to be shown in the to field |
|
|
|
|
def to_address_hash(%Transaction{to_address_hash: nil, created_contract_address_hash: address_hash}), do: address_hash |
|
|
|
|
def contract_creation?(%Transaction{to_address: nil}), do: true |
|
|
|
|
|
|
|
|
|
def to_address_hash(%Transaction{to_address: %Address{hash: address_hash}}), do: address_hash |
|
|
|
|
def contract_creation?(_), do: false |
|
|
|
|
|
|
|
|
|
def fee(%Transaction{} = transaction) do |
|
|
|
|
{_, value} = Chain.fee(transaction, :wei) |
|
|
|
|
value |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def format_gas_limit(gas) do |
|
|
|
|
Number.to_string!(gas) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def formatted_fee(%Transaction{} = transaction, opts) do |
|
|
|
|
transaction |
|
|
|
|
|> Chain.fee(:wei) |
|
|
|
@ -43,34 +42,6 @@ defmodule BlockScoutWeb.TransactionView do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def gas_used(%Transaction{gas_used: nil}), do: gettext("Pending") |
|
|
|
|
|
|
|
|
|
def gas_used(%Transaction{gas_used: gas_used}) do |
|
|
|
|
Number.to_string!(gas_used) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def involves_contract?(%Transaction{from_address: from_address, to_address: to_address}) do |
|
|
|
|
AddressView.contract?(from_address) || AddressView.contract?(to_address) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def involves_token_transfers?(%Transaction{token_transfers: []}), do: false |
|
|
|
|
def involves_token_transfers?(%Transaction{token_transfers: transfers}) when is_list(transfers), do: true |
|
|
|
|
|
|
|
|
|
def contract_creation?(%Transaction{to_address: nil}), do: true |
|
|
|
|
|
|
|
|
|
def contract_creation?(_), do: false |
|
|
|
|
|
|
|
|
|
def qr_code(%Transaction{hash: hash}) do |
|
|
|
|
hash |
|
|
|
|
|> to_string() |
|
|
|
|
|> QRCode.to_png() |
|
|
|
|
|> Base.encode64() |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def format_gas_limit(gas) do |
|
|
|
|
Number.to_string!(gas) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def formatted_status(transaction) do |
|
|
|
|
transaction |
|
|
|
|
|> Chain.transaction_to_status() |
|
|
|
@ -82,7 +53,11 @@ defmodule BlockScoutWeb.TransactionView do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defdelegate formatted_timestamp(block), to: BlockView |
|
|
|
|
def from_or_to_address?(_token_transfer, nil), do: false |
|
|
|
|
|
|
|
|
|
def from_or_to_address?(%{from_address_hash: from_hash, to_address_hash: to_hash}, %Address{hash: hash}) do |
|
|
|
|
from_hash == hash || to_hash == hash |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def gas(%type{gas: gas}) when is_transaction_type(type) do |
|
|
|
|
Cldr.Number.to_string!(gas) |
|
|
|
@ -95,22 +70,38 @@ defmodule BlockScoutWeb.TransactionView do |
|
|
|
|
format_wei_value(gas_price, unit) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def gas_used(%Transaction{gas_used: nil}), do: gettext("Pending") |
|
|
|
|
|
|
|
|
|
def gas_used(%Transaction{gas_used: gas_used}) do |
|
|
|
|
Number.to_string!(gas_used) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def hash(%Transaction{hash: hash}) do |
|
|
|
|
to_string(hash) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def involves_contract?(%Transaction{from_address: from_address, to_address: to_address}) do |
|
|
|
|
AddressView.contract?(from_address) || AddressView.contract?(to_address) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def involves_token_transfers?(%Transaction{token_transfers: []}), do: false |
|
|
|
|
def involves_token_transfers?(%Transaction{token_transfers: transfers}) when is_list(transfers), do: true |
|
|
|
|
|
|
|
|
|
def qr_code(%Transaction{hash: hash}) do |
|
|
|
|
hash |
|
|
|
|
|> to_string() |
|
|
|
|
|> QRCode.to_png() |
|
|
|
|
|> Base.encode64() |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def status(transaction) do |
|
|
|
|
Chain.transaction_to_status(transaction) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def type_suffix(%Transaction{} = transaction) do |
|
|
|
|
cond do |
|
|
|
|
involves_token_transfers?(transaction) -> "token-transfer" |
|
|
|
|
contract_creation?(transaction) -> "contract-creation" |
|
|
|
|
involves_contract?(transaction) -> "contract-call" |
|
|
|
|
true -> "transaction" |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
# This is the address to be shown in the to field |
|
|
|
|
def to_address_hash(%Transaction{to_address_hash: nil, created_contract_address_hash: address_hash}), do: address_hash |> IO.inspect |
|
|
|
|
|
|
|
|
|
def to_address_hash(%Transaction{to_address: %Address{hash: address_hash}}), do: address_hash |
|
|
|
|
|
|
|
|
|
def transaction_display_type(%Transaction{} = transaction) do |
|
|
|
|
cond do |
|
|
|
@ -121,6 +112,15 @@ defmodule BlockScoutWeb.TransactionView do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def type_suffix(%Transaction{} = transaction) do |
|
|
|
|
cond do |
|
|
|
|
involves_token_transfers?(transaction) -> "token-transfer" |
|
|
|
|
contract_creation?(transaction) -> "contract-creation" |
|
|
|
|
involves_contract?(transaction) -> "contract-call" |
|
|
|
|
true -> "transaction" |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Converts a transaction's Wei value to Ether and returns a formatted display value. |
|
|
|
|
|
|
|
|
|