|
|
@ -227,60 +227,31 @@ defmodule Explorer.Chain do |
|
|
|
transaction_hashes_from_token_transfers = |
|
|
|
transaction_hashes_from_token_transfers = |
|
|
|
TokenTransfer.where_any_address_fields_match(direction, address_hash, paging_options) |
|
|
|
TokenTransfer.where_any_address_fields_match(direction, address_hash, paging_options) |
|
|
|
|
|
|
|
|
|
|
|
token_transfers_query = |
|
|
|
transactions_list = |
|
|
|
transaction_hashes_from_token_transfers |
|
|
|
|
|
|
|
|> Transaction.where_transaction_hashes_match() |
|
|
|
|
|
|
|
|> join_associations(necessity_by_association) |
|
|
|
|
|
|
|
|> order_by([transaction], desc: transaction.block_number, desc: transaction.index) |
|
|
|
|
|
|
|
|> Transaction.preload_token_transfers(address_hash) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
base_query = |
|
|
|
|
|
|
|
paging_options |
|
|
|
paging_options |
|
|
|
|> fetch_transactions() |
|
|
|
|> fetch_transactions() |
|
|
|
|
|
|
|
|> Transaction.where_transaction_matches(transaction_hashes_from_token_transfers, direction, address_hash) |
|
|
|
|> join_associations(necessity_by_association) |
|
|
|
|> join_associations(necessity_by_association) |
|
|
|
|> Transaction.preload_token_transfers(address_hash) |
|
|
|
|> Transaction.preload_token_transfers(address_hash) |
|
|
|
|
|
|
|
|> Repo.all() |
|
|
|
|
|
|
|
|
|
|
|
from_address_query = |
|
|
|
if Application.get_env(:block_scout_web, BlockScoutWeb.Chain)[:has_emission_funds] do |
|
|
|
base_query |
|
|
|
address_hash |
|
|
|
|> where([t], t.from_address_hash == ^address_hash) |
|
|
|
|> Reward.fetch_emission_rewards_tuples(paging_options) |
|
|
|
|
|
|
|
|> Enum.concat(transactions_list) |
|
|
|
to_address_query = |
|
|
|
|> Enum.sort_by(fn item -> |
|
|
|
base_query |
|
|
|
case item do |
|
|
|
|> where([t], t.to_address_hash == ^address_hash) |
|
|
|
{%Reward{} = emission_reward, _} -> |
|
|
|
|
|
|
|
{-emission_reward.block.number, 1} |
|
|
|
created_contract_query = |
|
|
|
|
|
|
|
base_query |
|
|
|
item -> |
|
|
|
|> where([t], t.created_contract_address_hash == ^address_hash) |
|
|
|
{-item.block_number, -item.index} |
|
|
|
|
|
|
|
|
|
|
|
queries = |
|
|
|
|
|
|
|
[token_transfers_query] ++ |
|
|
|
|
|
|
|
case direction do |
|
|
|
|
|
|
|
:from -> [from_address_query] |
|
|
|
|
|
|
|
:to -> [to_address_query, created_contract_query] |
|
|
|
|
|
|
|
_ -> [from_address_query, to_address_query, created_contract_query] |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end) |
|
|
|
rewards_list = |
|
|
|
|> Enum.take(paging_options.page_size) |
|
|
|
if Application.get_env(:block_scout_web, BlockScoutWeb.Chain)[:has_emission_funds] do |
|
|
|
else |
|
|
|
Reward.fetch_emission_rewards_tuples(address_hash, paging_options) |
|
|
|
transactions_list |
|
|
|
else |
|
|
|
end |
|
|
|
[] |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
queries |
|
|
|
|
|
|
|
|> Stream.flat_map(&Repo.all/1) |
|
|
|
|
|
|
|
|> Stream.uniq_by(& &1.hash) |
|
|
|
|
|
|
|
|> Stream.concat(rewards_list) |
|
|
|
|
|
|
|
|> Enum.sort_by(fn item -> |
|
|
|
|
|
|
|
case item do |
|
|
|
|
|
|
|
{%Reward{} = emission_reward, _} -> |
|
|
|
|
|
|
|
{-emission_reward.block.number, 1} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
item -> |
|
|
|
|
|
|
|
{-item.block_number, -item.index} |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
|> Enum.take(paging_options.page_size) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@spec address_to_logs(Address.t(), Keyword.t()) :: [ |
|
|
|
@spec address_to_logs(Address.t(), Keyword.t()) :: [ |
|
|
@ -703,25 +674,32 @@ defmodule Explorer.Chain do |
|
|
|
iex> Explorer.Chain.hash_to_address(hash) |
|
|
|
iex> Explorer.Chain.hash_to_address(hash) |
|
|
|
{:error, :not_found} |
|
|
|
{:error, :not_found} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Optionally accepts: |
|
|
|
|
|
|
|
- a list of bindings to preload, just like `Ecto.Query.preload/3` |
|
|
|
|
|
|
|
- a boolean to also fetch the `has_decompiled_code?` virtual field or not |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
""" |
|
|
|
@spec hash_to_address(Hash.Address.t()) :: {:ok, Address.t()} | {:error, :not_found} |
|
|
|
@spec hash_to_address(Hash.Address.t(), [Macro.t()], boolean()) :: {:ok, Address.t()} | {:error, :not_found} |
|
|
|
def hash_to_address(%Hash{byte_count: unquote(Hash.Address.byte_count())} = hash) do |
|
|
|
def hash_to_address( |
|
|
|
query = |
|
|
|
%Hash{byte_count: unquote(Hash.Address.byte_count())} = hash, |
|
|
|
from( |
|
|
|
preloads \\ [ |
|
|
|
address in Address, |
|
|
|
|
|
|
|
preload: [ |
|
|
|
|
|
|
|
:contracts_creation_internal_transaction, |
|
|
|
:contracts_creation_internal_transaction, |
|
|
|
:names, |
|
|
|
:names, |
|
|
|
:smart_contract, |
|
|
|
:smart_contract, |
|
|
|
:token, |
|
|
|
:token, |
|
|
|
:contracts_creation_transaction |
|
|
|
:contracts_creation_transaction |
|
|
|
], |
|
|
|
], |
|
|
|
|
|
|
|
query_decompiled_code_flag \\ true |
|
|
|
|
|
|
|
) do |
|
|
|
|
|
|
|
query = |
|
|
|
|
|
|
|
from( |
|
|
|
|
|
|
|
address in Address, |
|
|
|
|
|
|
|
preload: ^preloads, |
|
|
|
where: address.hash == ^hash |
|
|
|
where: address.hash == ^hash |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
query_with_decompiled_flag = with_decompiled_code_flag(query, hash) |
|
|
|
query |
|
|
|
|
|
|
|
|> with_decompiled_code_flag(hash, query_decompiled_code_flag) |
|
|
|
query_with_decompiled_flag |
|
|
|
|
|
|
|
|> Repo.one() |
|
|
|
|> Repo.one() |
|
|
|
|> case do |
|
|
|
|> case do |
|
|
|
nil -> {:error, :not_found} |
|
|
|
nil -> {:error, :not_found} |
|
|
@ -1987,7 +1965,6 @@ defmodule Explorer.Chain do |
|
|
|
|> page_pending_transaction(paging_options) |
|
|
|
|> page_pending_transaction(paging_options) |
|
|
|
|> limit(^paging_options.page_size) |
|
|
|
|> limit(^paging_options.page_size) |
|
|
|
|> pending_transactions_query() |
|
|
|
|> pending_transactions_query() |
|
|
|
|> where([transaction], is_nil(transaction.error) or transaction.error != "dropped/replaced") |
|
|
|
|
|
|
|
|> order_by([transaction], desc: transaction.inserted_at, desc: transaction.hash) |
|
|
|
|> order_by([transaction], desc: transaction.inserted_at, desc: transaction.hash) |
|
|
|
|> join_associations(necessity_by_association) |
|
|
|
|> join_associations(necessity_by_association) |
|
|
|
|> preload([{:token_transfers, [:token, :from_address, :to_address]}]) |
|
|
|
|> preload([{:token_transfers, [:token, :from_address, :to_address]}]) |
|
|
@ -1996,7 +1973,7 @@ defmodule Explorer.Chain do |
|
|
|
|
|
|
|
|
|
|
|
defp pending_transactions_query(query) do |
|
|
|
defp pending_transactions_query(query) do |
|
|
|
from(transaction in query, |
|
|
|
from(transaction in query, |
|
|
|
where: is_nil(transaction.block_hash) |
|
|
|
where: is_nil(transaction.block_hash) and (is_nil(transaction.error) or transaction.error != "dropped/replaced") |
|
|
|
) |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -3161,7 +3138,11 @@ defmodule Explorer.Chain do |
|
|
|
|
|
|
|
|
|
|
|
defp staking_pool_filter(query, _), do: query |
|
|
|
defp staking_pool_filter(query, _), do: query |
|
|
|
|
|
|
|
|
|
|
|
defp with_decompiled_code_flag(query, hash) do |
|
|
|
defp with_decompiled_code_flag(query, hash, use_option \\ true) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp with_decompiled_code_flag(query, _hash, false), do: query |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp with_decompiled_code_flag(query, hash, true) do |
|
|
|
has_decompiled_code_query = |
|
|
|
has_decompiled_code_query = |
|
|
|
from(decompiled_contract in DecompiledSmartContract, |
|
|
|
from(decompiled_contract in DecompiledSmartContract, |
|
|
|
where: decompiled_contract.address_hash == ^hash, |
|
|
|
where: decompiled_contract.address_hash == ^hash, |
|
|
|