|
|
@ -24,7 +24,8 @@ defmodule Explorer.Chain.Search do |
|
|
|
DenormalizationHelper, |
|
|
|
DenormalizationHelper, |
|
|
|
SmartContract, |
|
|
|
SmartContract, |
|
|
|
Token, |
|
|
|
Token, |
|
|
|
Transaction |
|
|
|
Transaction, |
|
|
|
|
|
|
|
UserOperation |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -39,38 +40,7 @@ defmodule Explorer.Chain.Search do |
|
|
|
result = |
|
|
|
result = |
|
|
|
case prepare_search_term(string) do |
|
|
|
case prepare_search_term(string) do |
|
|
|
{:some, term} -> |
|
|
|
{:some, term} -> |
|
|
|
tokens_query = search_token_query(string, term) |
|
|
|
query = base_joint_query(string, term) |
|
|
|
contracts_query = search_contract_query(term) |
|
|
|
|
|
|
|
labels_query = search_label_query(term) |
|
|
|
|
|
|
|
tx_query = search_tx_query(string) |
|
|
|
|
|
|
|
address_query = search_address_query(string) |
|
|
|
|
|
|
|
block_query = search_block_query(string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
basic_query = |
|
|
|
|
|
|
|
from( |
|
|
|
|
|
|
|
tokens in subquery(tokens_query), |
|
|
|
|
|
|
|
union: ^contracts_query, |
|
|
|
|
|
|
|
union: ^labels_query |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query = |
|
|
|
|
|
|
|
cond do |
|
|
|
|
|
|
|
address_query -> |
|
|
|
|
|
|
|
basic_query |
|
|
|
|
|
|
|
|> union(^address_query) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tx_query -> |
|
|
|
|
|
|
|
basic_query |
|
|
|
|
|
|
|
|> union(^tx_query) |
|
|
|
|
|
|
|
|> union(^block_query) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
block_query -> |
|
|
|
|
|
|
|
basic_query |
|
|
|
|
|
|
|
|> union(^block_query) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
true -> |
|
|
|
|
|
|
|
basic_query |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ordered_query = |
|
|
|
ordered_query = |
|
|
|
from(items in subquery(query), |
|
|
|
from(items in subquery(query), |
|
|
@ -109,6 +79,50 @@ defmodule Explorer.Chain.Search do |
|
|
|
result ++ ens_result |
|
|
|
result ++ ens_result |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def base_joint_query(string, term) do |
|
|
|
|
|
|
|
tokens_query = search_token_query(string, term) |
|
|
|
|
|
|
|
contracts_query = search_contract_query(term) |
|
|
|
|
|
|
|
labels_query = search_label_query(term) |
|
|
|
|
|
|
|
address_query = search_address_query(string) |
|
|
|
|
|
|
|
block_query = search_block_query(string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
basic_query = |
|
|
|
|
|
|
|
from( |
|
|
|
|
|
|
|
tokens in subquery(tokens_query), |
|
|
|
|
|
|
|
union: ^contracts_query, |
|
|
|
|
|
|
|
union: ^labels_query |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cond do |
|
|
|
|
|
|
|
address_query -> |
|
|
|
|
|
|
|
basic_query |
|
|
|
|
|
|
|
|> union(^address_query) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
valid_full_hash?(string) -> |
|
|
|
|
|
|
|
tx_query = search_tx_query(string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if UserOperation.user_operations_enabled?() do |
|
|
|
|
|
|
|
user_operation_query = search_user_operation_query(string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
basic_query |
|
|
|
|
|
|
|
|> union(^tx_query) |
|
|
|
|
|
|
|
|> union(^user_operation_query) |
|
|
|
|
|
|
|
|> union(^block_query) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
basic_query |
|
|
|
|
|
|
|
|> union(^tx_query) |
|
|
|
|
|
|
|
|> union(^block_query) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
block_query -> |
|
|
|
|
|
|
|
basic_query |
|
|
|
|
|
|
|
|> union(^block_query) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
true -> |
|
|
|
|
|
|
|
basic_query |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp maybe_run_ens_task(%PagingOptions{key: nil}, query_string, options) do |
|
|
|
defp maybe_run_ens_task(%PagingOptions{key: nil}, query_string, options) do |
|
|
|
Task.async(fn -> search_ens_name(query_string, options) end) |
|
|
|
Task.async(fn -> search_ens_name(query_string, options) end) |
|
|
|
end |
|
|
|
end |
|
|
@ -158,8 +172,18 @@ defmodule Explorer.Chain.Search do |
|
|
|
|> select_repo(options).all() |
|
|
|
|> select_repo(options).all() |
|
|
|
|
|
|
|
|
|
|
|
tx_result = |
|
|
|
tx_result = |
|
|
|
if query = search_tx_query(search_query) do |
|
|
|
if valid_full_hash?(search_query) do |
|
|
|
query |
|
|
|
search_query |
|
|
|
|
|
|
|
|> search_tx_query() |
|
|
|
|
|
|
|
|> select_repo(options).all() |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
[] |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
op_result = |
|
|
|
|
|
|
|
if valid_full_hash?(search_query) && UserOperation.user_operations_enabled?() do |
|
|
|
|
|
|
|
search_query |
|
|
|
|
|
|
|
|> search_user_operation_query() |
|
|
|
|> select_repo(options).all() |
|
|
|
|> select_repo(options).all() |
|
|
|
else |
|
|
|
else |
|
|
|
[] |
|
|
|
[] |
|
|
@ -185,7 +209,16 @@ defmodule Explorer.Chain.Search do |
|
|
|
ens_result = await_ens_task(ens_task) |
|
|
|
ens_result = await_ens_task(ens_task) |
|
|
|
|
|
|
|
|
|
|
|
non_empty_lists = |
|
|
|
non_empty_lists = |
|
|
|
[tokens_result, contracts_result, labels_result, tx_result, address_result, blocks_result, ens_result] |
|
|
|
[ |
|
|
|
|
|
|
|
tokens_result, |
|
|
|
|
|
|
|
contracts_result, |
|
|
|
|
|
|
|
labels_result, |
|
|
|
|
|
|
|
tx_result, |
|
|
|
|
|
|
|
op_result, |
|
|
|
|
|
|
|
address_result, |
|
|
|
|
|
|
|
blocks_result, |
|
|
|
|
|
|
|
ens_result |
|
|
|
|
|
|
|
] |
|
|
|
|> Enum.filter(fn list -> Enum.count(list) > 0 end) |
|
|
|
|> Enum.filter(fn list -> Enum.count(list) > 0 end) |
|
|
|
|> Enum.sort_by(fn list -> Enum.count(list) end, :asc) |
|
|
|
|> Enum.sort_by(fn list -> Enum.count(list) end, :asc) |
|
|
|
|
|
|
|
|
|
|
@ -232,26 +265,14 @@ defmodule Explorer.Chain.Search do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp search_label_query(term) do |
|
|
|
defp search_label_query(term) do |
|
|
|
label_search_fields = %{ |
|
|
|
label_search_fields = |
|
|
|
address_hash: dynamic([att, _, _], att.address_hash), |
|
|
|
search_fields() |
|
|
|
tx_hash: dynamic([_, _, _], type(^nil, :binary)), |
|
|
|
|> Map.put(:address_hash, dynamic([att, _, _], att.address_hash)) |
|
|
|
block_hash: dynamic([_, _, _], type(^nil, :binary)), |
|
|
|
|> Map.put(:type, "label") |
|
|
|
type: "label", |
|
|
|
|> Map.put(:name, dynamic([_, at, _], at.display_name)) |
|
|
|
name: dynamic([_, at, _], at.display_name), |
|
|
|
|> Map.put(:inserted_at, dynamic([att, _, _], att.inserted_at)) |
|
|
|
symbol: nil, |
|
|
|
|> Map.put(:verified, dynamic([_, _, smart_contract], not is_nil(smart_contract))) |
|
|
|
holder_count: nil, |
|
|
|
|> Map.put(:priority, 1) |
|
|
|
inserted_at: dynamic([att, _, _], att.inserted_at), |
|
|
|
|
|
|
|
block_number: 0, |
|
|
|
|
|
|
|
icon_url: nil, |
|
|
|
|
|
|
|
token_type: nil, |
|
|
|
|
|
|
|
timestamp: dynamic([_, _, _], type(^nil, :utc_datetime_usec)), |
|
|
|
|
|
|
|
verified: dynamic([_, _, smart_contract], not is_nil(smart_contract)), |
|
|
|
|
|
|
|
exchange_rate: nil, |
|
|
|
|
|
|
|
total_supply: nil, |
|
|
|
|
|
|
|
circulating_market_cap: nil, |
|
|
|
|
|
|
|
priority: 1, |
|
|
|
|
|
|
|
is_verified_via_admin_panel: nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inner_query = |
|
|
|
inner_query = |
|
|
|
from(tag in AddressTag, |
|
|
|
from(tag in AddressTag, |
|
|
@ -269,26 +290,21 @@ defmodule Explorer.Chain.Search do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp search_token_query(string, term) do |
|
|
|
defp search_token_query(string, term) do |
|
|
|
token_search_fields = %{ |
|
|
|
token_search_fields = |
|
|
|
address_hash: dynamic([token, _], token.contract_address_hash), |
|
|
|
search_fields() |
|
|
|
tx_hash: dynamic([_, _], type(^nil, :binary)), |
|
|
|
|> Map.put(:address_hash, dynamic([token, _], token.contract_address_hash)) |
|
|
|
block_hash: dynamic([_, _], type(^nil, :binary)), |
|
|
|
|> Map.put(:type, "token") |
|
|
|
type: "token", |
|
|
|
|> Map.put(:name, dynamic([token, _], token.name)) |
|
|
|
name: dynamic([token, _], token.name), |
|
|
|
|> Map.put(:symbol, dynamic([token, _], token.symbol)) |
|
|
|
symbol: dynamic([token, _], token.symbol), |
|
|
|
|> Map.put(:holder_count, dynamic([token, _], token.holder_count)) |
|
|
|
holder_count: dynamic([token, _], token.holder_count), |
|
|
|
|> Map.put(:inserted_at, dynamic([token, _], token.inserted_at)) |
|
|
|
inserted_at: dynamic([token, _], token.inserted_at), |
|
|
|
|> Map.put(:icon_url, dynamic([token, _], token.icon_url)) |
|
|
|
block_number: 0, |
|
|
|
|> Map.put(:token_type, dynamic([token, _], token.type)) |
|
|
|
icon_url: dynamic([token, _], token.icon_url), |
|
|
|
|> Map.put(:verified, dynamic([_, smart_contract], not is_nil(smart_contract))) |
|
|
|
token_type: dynamic([token, _], token.type), |
|
|
|
|> Map.put(:exchange_rate, dynamic([token, _], token.fiat_value)) |
|
|
|
timestamp: dynamic([_, _], type(^nil, :utc_datetime_usec)), |
|
|
|
|> Map.put(:total_supply, dynamic([token, _], token.total_supply)) |
|
|
|
verified: dynamic([_, smart_contract], not is_nil(smart_contract)), |
|
|
|
|> Map.put(:circulating_market_cap, dynamic([token, _], token.circulating_market_cap)) |
|
|
|
exchange_rate: dynamic([token, _], token.fiat_value), |
|
|
|
|> Map.put(:is_verified_via_admin_panel, dynamic([token, _], token.is_verified_via_admin_panel)) |
|
|
|
total_supply: dynamic([token, _], token.total_supply), |
|
|
|
|
|
|
|
circulating_market_cap: dynamic([token, _], token.circulating_market_cap), |
|
|
|
|
|
|
|
priority: 0, |
|
|
|
|
|
|
|
is_verified_via_admin_panel: dynamic([token, _], token.is_verified_via_admin_panel) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case Chain.string_to_address_hash(string) do |
|
|
|
case Chain.string_to_address_hash(string) do |
|
|
|
{:ok, address_hash} -> |
|
|
|
{:ok, address_hash} -> |
|
|
@ -310,26 +326,13 @@ defmodule Explorer.Chain.Search do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp search_contract_query(term) do |
|
|
|
defp search_contract_query(term) do |
|
|
|
contract_search_fields = %{ |
|
|
|
contract_search_fields = |
|
|
|
address_hash: dynamic([smart_contract, _], smart_contract.address_hash), |
|
|
|
search_fields() |
|
|
|
tx_hash: dynamic([_, _], type(^nil, :binary)), |
|
|
|
|> Map.put(:address_hash, dynamic([smart_contract, _], smart_contract.address_hash)) |
|
|
|
block_hash: dynamic([_, _], type(^nil, :binary)), |
|
|
|
|> Map.put(:type, "contract") |
|
|
|
type: "contract", |
|
|
|
|> Map.put(:name, dynamic([smart_contract, _], smart_contract.name)) |
|
|
|
name: dynamic([smart_contract, _], smart_contract.name), |
|
|
|
|> Map.put(:inserted_at, dynamic([_, address], address.inserted_at)) |
|
|
|
symbol: nil, |
|
|
|
|> Map.put(:verified, true) |
|
|
|
holder_count: nil, |
|
|
|
|
|
|
|
inserted_at: dynamic([_, address], address.inserted_at), |
|
|
|
|
|
|
|
block_number: 0, |
|
|
|
|
|
|
|
icon_url: nil, |
|
|
|
|
|
|
|
token_type: nil, |
|
|
|
|
|
|
|
timestamp: dynamic([_, _], type(^nil, :utc_datetime_usec)), |
|
|
|
|
|
|
|
verified: true, |
|
|
|
|
|
|
|
exchange_rate: nil, |
|
|
|
|
|
|
|
total_supply: nil, |
|
|
|
|
|
|
|
circulating_market_cap: nil, |
|
|
|
|
|
|
|
priority: 0, |
|
|
|
|
|
|
|
is_verified_via_admin_panel: nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from(smart_contract in SmartContract, |
|
|
|
from(smart_contract in SmartContract, |
|
|
|
left_join: address in Address, |
|
|
|
left_join: address in Address, |
|
|
@ -342,26 +345,13 @@ defmodule Explorer.Chain.Search do |
|
|
|
defp search_address_query(term) do |
|
|
|
defp search_address_query(term) do |
|
|
|
case Chain.string_to_address_hash(term) do |
|
|
|
case Chain.string_to_address_hash(term) do |
|
|
|
{:ok, address_hash} -> |
|
|
|
{:ok, address_hash} -> |
|
|
|
address_search_fields = %{ |
|
|
|
address_search_fields = |
|
|
|
address_hash: dynamic([address, _], address.hash), |
|
|
|
search_fields() |
|
|
|
block_hash: dynamic([_, _], type(^nil, :binary)), |
|
|
|
|> Map.put(:address_hash, dynamic([address, _], address.hash)) |
|
|
|
tx_hash: dynamic([_, _], type(^nil, :binary)), |
|
|
|
|> Map.put(:type, "address") |
|
|
|
type: "address", |
|
|
|
|> Map.put(:name, dynamic([_, address_name], address_name.name)) |
|
|
|
name: dynamic([_, address_name], address_name.name), |
|
|
|
|> Map.put(:inserted_at, dynamic([_, address_name], address_name.inserted_at)) |
|
|
|
symbol: nil, |
|
|
|
|> Map.put(:verified, dynamic([address, _], address.verified)) |
|
|
|
holder_count: nil, |
|
|
|
|
|
|
|
inserted_at: dynamic([address, _], address.inserted_at), |
|
|
|
|
|
|
|
block_number: 0, |
|
|
|
|
|
|
|
icon_url: nil, |
|
|
|
|
|
|
|
token_type: nil, |
|
|
|
|
|
|
|
timestamp: dynamic([_, _], type(^nil, :utc_datetime_usec)), |
|
|
|
|
|
|
|
verified: dynamic([address, _], address.verified), |
|
|
|
|
|
|
|
exchange_rate: nil, |
|
|
|
|
|
|
|
total_supply: nil, |
|
|
|
|
|
|
|
circulating_market_cap: nil, |
|
|
|
|
|
|
|
priority: 0, |
|
|
|
|
|
|
|
is_verified_via_admin_panel: nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from(address in Address, |
|
|
|
from(address in Address, |
|
|
|
left_join: |
|
|
|
left_join: |
|
|
@ -382,97 +372,73 @@ defmodule Explorer.Chain.Search do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp valid_full_hash?(string_input) do |
|
|
|
|
|
|
|
case Chain.string_to_transaction_hash(string_input) do |
|
|
|
|
|
|
|
{:ok, _tx_hash} -> true |
|
|
|
|
|
|
|
_ -> false |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp search_tx_query(term) do |
|
|
|
defp search_tx_query(term) do |
|
|
|
if DenormalizationHelper.denormalization_finished?() do |
|
|
|
if DenormalizationHelper.denormalization_finished?() do |
|
|
|
case Chain.string_to_transaction_hash(term) do |
|
|
|
transaction_search_fields = |
|
|
|
{:ok, tx_hash} -> |
|
|
|
search_fields() |
|
|
|
transaction_search_fields = %{ |
|
|
|
|> Map.put(:tx_hash, dynamic([transaction], transaction.hash)) |
|
|
|
address_hash: dynamic([_], type(^nil, :binary)), |
|
|
|
|> Map.put(:block_hash, dynamic([transaction], transaction.block_hash)) |
|
|
|
tx_hash: dynamic([transaction], transaction.hash), |
|
|
|
|> Map.put(:type, "transaction") |
|
|
|
block_hash: dynamic([_], type(^nil, :binary)), |
|
|
|
|> Map.put(:block_number, dynamic([transaction], transaction.block_number)) |
|
|
|
type: "transaction", |
|
|
|
|> Map.put(:inserted_at, dynamic([transaction], transaction.inserted_at)) |
|
|
|
name: nil, |
|
|
|
|> Map.put(:timestamp, dynamic([transaction], transaction.block_timestamp)) |
|
|
|
symbol: nil, |
|
|
|
|
|
|
|
holder_count: nil, |
|
|
|
from(transaction in Transaction, |
|
|
|
inserted_at: dynamic([transaction], transaction.inserted_at), |
|
|
|
where: transaction.hash == ^term, |
|
|
|
block_number: 0, |
|
|
|
select: ^transaction_search_fields |
|
|
|
icon_url: nil, |
|
|
|
) |
|
|
|
token_type: nil, |
|
|
|
|
|
|
|
timestamp: dynamic([transaction], transaction.block_timestamp), |
|
|
|
|
|
|
|
verified: nil, |
|
|
|
|
|
|
|
exchange_rate: nil, |
|
|
|
|
|
|
|
total_supply: nil, |
|
|
|
|
|
|
|
circulating_market_cap: nil, |
|
|
|
|
|
|
|
priority: 0, |
|
|
|
|
|
|
|
is_verified_via_admin_panel: nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from(transaction in Transaction, |
|
|
|
|
|
|
|
where: transaction.hash == ^tx_hash, |
|
|
|
|
|
|
|
select: ^transaction_search_fields |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
|
|
|
|
nil |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
else |
|
|
|
else |
|
|
|
case Chain.string_to_transaction_hash(term) do |
|
|
|
transaction_search_fields = |
|
|
|
{:ok, tx_hash} -> |
|
|
|
search_fields() |
|
|
|
transaction_search_fields = %{ |
|
|
|
|> Map.put(:tx_hash, dynamic([transaction, _], transaction.hash)) |
|
|
|
address_hash: dynamic([_, _], type(^nil, :binary)), |
|
|
|
|> Map.put(:block_hash, dynamic([transaction, _], transaction.block_hash)) |
|
|
|
tx_hash: dynamic([transaction, _], transaction.hash), |
|
|
|
|> Map.put(:type, "transaction") |
|
|
|
block_hash: dynamic([_, _], type(^nil, :binary)), |
|
|
|
|> Map.put(:block_number, dynamic([transaction, _], transaction.block_number)) |
|
|
|
type: "transaction", |
|
|
|
|> Map.put(:inserted_at, dynamic([transaction, _], transaction.inserted_at)) |
|
|
|
name: nil, |
|
|
|
|> Map.put(:timestamp, dynamic([_, block], block.timestamp)) |
|
|
|
symbol: nil, |
|
|
|
|
|
|
|
holder_count: nil, |
|
|
|
from(transaction in Transaction, |
|
|
|
inserted_at: dynamic([transaction, _], transaction.inserted_at), |
|
|
|
left_join: block in Block, |
|
|
|
block_number: 0, |
|
|
|
on: transaction.block_hash == block.hash, |
|
|
|
icon_url: nil, |
|
|
|
where: transaction.hash == ^term, |
|
|
|
token_type: nil, |
|
|
|
select: ^transaction_search_fields |
|
|
|
timestamp: dynamic([_, block], block.timestamp), |
|
|
|
) |
|
|
|
verified: nil, |
|
|
|
|
|
|
|
exchange_rate: nil, |
|
|
|
|
|
|
|
total_supply: nil, |
|
|
|
|
|
|
|
circulating_market_cap: nil, |
|
|
|
|
|
|
|
priority: 0, |
|
|
|
|
|
|
|
is_verified_via_admin_panel: nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from(transaction in Transaction, |
|
|
|
|
|
|
|
left_join: block in Block, |
|
|
|
|
|
|
|
on: transaction.block_hash == block.hash, |
|
|
|
|
|
|
|
where: transaction.hash == ^tx_hash, |
|
|
|
|
|
|
|
select: ^transaction_search_fields |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
|
|
|
|
nil |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp search_user_operation_query(term) do |
|
|
|
|
|
|
|
user_operation_search_fields = |
|
|
|
|
|
|
|
search_fields() |
|
|
|
|
|
|
|
|> Map.put(:user_operation_hash, dynamic([user_operation, _], user_operation.hash)) |
|
|
|
|
|
|
|
|> Map.put(:block_hash, dynamic([user_operation, _], user_operation.block_hash)) |
|
|
|
|
|
|
|
|> Map.put(:type, "user_operation") |
|
|
|
|
|
|
|
|> Map.put(:inserted_at, dynamic([user_operation, _], user_operation.inserted_at)) |
|
|
|
|
|
|
|
|> Map.put(:block_number, dynamic([user_operation, _], user_operation.block_number)) |
|
|
|
|
|
|
|
|> Map.put(:timestamp, dynamic([_, block], block.timestamp)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from(user_operation in UserOperation, |
|
|
|
|
|
|
|
left_join: block in Block, |
|
|
|
|
|
|
|
on: user_operation.block_hash == block.hash, |
|
|
|
|
|
|
|
where: user_operation.hash == ^term, |
|
|
|
|
|
|
|
select: ^user_operation_search_fields |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp search_block_query(term) do |
|
|
|
defp search_block_query(term) do |
|
|
|
block_search_fields = %{ |
|
|
|
block_search_fields = |
|
|
|
address_hash: dynamic([_], type(^nil, :binary)), |
|
|
|
search_fields() |
|
|
|
tx_hash: dynamic([_], type(^nil, :binary)), |
|
|
|
|> Map.put(:block_hash, dynamic([block], block.hash)) |
|
|
|
block_hash: dynamic([block], block.hash), |
|
|
|
|> Map.put(:type, "block") |
|
|
|
type: "block", |
|
|
|
|> Map.put(:block_number, dynamic([block], block.number)) |
|
|
|
name: nil, |
|
|
|
|> Map.put(:inserted_at, dynamic([block], block.inserted_at)) |
|
|
|
symbol: nil, |
|
|
|
|> Map.put(:timestamp, dynamic([block], block.timestamp)) |
|
|
|
holder_count: nil, |
|
|
|
|
|
|
|
inserted_at: dynamic([block], block.inserted_at), |
|
|
|
|
|
|
|
block_number: dynamic([block], block.number), |
|
|
|
|
|
|
|
icon_url: nil, |
|
|
|
|
|
|
|
token_type: nil, |
|
|
|
|
|
|
|
timestamp: dynamic([block], block.timestamp), |
|
|
|
|
|
|
|
verified: nil, |
|
|
|
|
|
|
|
exchange_rate: nil, |
|
|
|
|
|
|
|
total_supply: nil, |
|
|
|
|
|
|
|
circulating_market_cap: nil, |
|
|
|
|
|
|
|
priority: 0, |
|
|
|
|
|
|
|
is_verified_via_admin_panel: nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case Chain.string_to_block_hash(term) do |
|
|
|
case Chain.string_to_block_hash(term) do |
|
|
|
{:ok, block_hash} -> |
|
|
|
{:ok, block_hash} -> |
|
|
@ -605,11 +571,23 @@ defmodule Explorer.Chain.Search do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp merge_address_search_result_with_ens_info([], ens_info) do |
|
|
|
defp merge_address_search_result_with_ens_info([], ens_info) do |
|
|
|
|
|
|
|
search_fields() |
|
|
|
|
|
|
|
|> Map.put(:address_hash, ens_info[:address_hash]) |
|
|
|
|
|
|
|
|> Map.put(:type, "address") |
|
|
|
|
|
|
|
|> Map.put(:ens_info, ens_info) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp merge_address_search_result_with_ens_info([address], ens_info) do |
|
|
|
|
|
|
|
Map.put(address |> compose_result_checksummed_address_hash(), :ens_info, ens_info) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp search_fields do |
|
|
|
%{ |
|
|
|
%{ |
|
|
|
address_hash: ens_info[:address_hash], |
|
|
|
address_hash: dynamic([_], type(^nil, :binary)), |
|
|
|
block_hash: nil, |
|
|
|
tx_hash: dynamic([_], type(^nil, :binary)), |
|
|
|
tx_hash: nil, |
|
|
|
user_operation_hash: dynamic([_], type(^nil, :binary)), |
|
|
|
type: "address", |
|
|
|
block_hash: dynamic([_], type(^nil, :binary)), |
|
|
|
|
|
|
|
type: nil, |
|
|
|
name: nil, |
|
|
|
name: nil, |
|
|
|
symbol: nil, |
|
|
|
symbol: nil, |
|
|
|
holder_count: nil, |
|
|
|
holder_count: nil, |
|
|
@ -617,18 +595,13 @@ defmodule Explorer.Chain.Search do |
|
|
|
block_number: 0, |
|
|
|
block_number: 0, |
|
|
|
icon_url: nil, |
|
|
|
icon_url: nil, |
|
|
|
token_type: nil, |
|
|
|
token_type: nil, |
|
|
|
timestamp: nil, |
|
|
|
timestamp: dynamic([_, _], type(^nil, :utc_datetime_usec)), |
|
|
|
verified: false, |
|
|
|
verified: nil, |
|
|
|
exchange_rate: nil, |
|
|
|
exchange_rate: nil, |
|
|
|
total_supply: nil, |
|
|
|
total_supply: nil, |
|
|
|
circulating_market_cap: nil, |
|
|
|
circulating_market_cap: nil, |
|
|
|
priority: 0, |
|
|
|
priority: 0, |
|
|
|
is_verified_via_admin_panel: nil, |
|
|
|
is_verified_via_admin_panel: nil |
|
|
|
ens_info: ens_info |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp merge_address_search_result_with_ens_info([address], ens_info) do |
|
|
|
|
|
|
|
Map.put(address |> compose_result_checksummed_address_hash(), :ens_info, ens_info) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|