|
|
|
@ -1486,13 +1486,15 @@ defmodule Explorer.Chain do |
|
|
|
|
def search_label_query(term) do |
|
|
|
|
inner_query = |
|
|
|
|
from(tag in AddressTag, |
|
|
|
|
where: fragment("to_tsvector('english', display_name ) @@ to_tsquery(?)", ^term), |
|
|
|
|
where: fragment("to_tsvector('english', ?) @@ to_tsquery(?)", tag.display_name, ^term), |
|
|
|
|
select: tag |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
from(att in AddressToTag, |
|
|
|
|
inner_join: at in subquery(inner_query), |
|
|
|
|
on: att.tag_id == at.id, |
|
|
|
|
left_join: smart_contract in SmartContract, |
|
|
|
|
on: att.address_hash == smart_contract.address_hash, |
|
|
|
|
select: %{ |
|
|
|
|
address_hash: att.address_hash, |
|
|
|
|
tx_hash: fragment("CAST(NULL AS bytea)"), |
|
|
|
@ -1503,14 +1505,21 @@ defmodule Explorer.Chain do |
|
|
|
|
holder_count: ^nil, |
|
|
|
|
inserted_at: att.inserted_at, |
|
|
|
|
block_number: 0, |
|
|
|
|
icon_url: nil |
|
|
|
|
icon_url: nil, |
|
|
|
|
token_type: nil, |
|
|
|
|
timestamp: fragment("NULL::timestamp without time zone"), |
|
|
|
|
verified: not is_nil(smart_contract), |
|
|
|
|
exchange_rate: nil, |
|
|
|
|
total_supply: nil |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp search_token_query(term) do |
|
|
|
|
from(token in Token, |
|
|
|
|
where: fragment("to_tsvector('english', symbol || ' ' || name ) @@ to_tsquery(?)", ^term), |
|
|
|
|
left_join: smart_contract in SmartContract, |
|
|
|
|
on: token.contract_address_hash == smart_contract.address_hash, |
|
|
|
|
where: fragment("to_tsvector('english', ? || ' ' || ?) @@ to_tsquery(?)", token.symbol, token.name, ^term), |
|
|
|
|
select: %{ |
|
|
|
|
address_hash: token.contract_address_hash, |
|
|
|
|
tx_hash: fragment("CAST(NULL AS bytea)"), |
|
|
|
@ -1521,7 +1530,12 @@ defmodule Explorer.Chain do |
|
|
|
|
holder_count: token.holder_count, |
|
|
|
|
inserted_at: token.inserted_at, |
|
|
|
|
block_number: 0, |
|
|
|
|
icon_url: token.icon_url |
|
|
|
|
icon_url: token.icon_url, |
|
|
|
|
token_type: token.type, |
|
|
|
|
timestamp: fragment("NULL::timestamp without time zone"), |
|
|
|
|
verified: not is_nil(smart_contract), |
|
|
|
|
exchange_rate: token.fiat_value, |
|
|
|
|
total_supply: token.total_supply |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
@ -1530,7 +1544,7 @@ defmodule Explorer.Chain do |
|
|
|
|
from(smart_contract in SmartContract, |
|
|
|
|
left_join: address in Address, |
|
|
|
|
on: smart_contract.address_hash == address.hash, |
|
|
|
|
where: fragment("to_tsvector('english', name) @@ to_tsquery(?)", ^term), |
|
|
|
|
where: fragment("to_tsvector('english', ?) @@ to_tsquery(?)", smart_contract.name, ^term), |
|
|
|
|
select: %{ |
|
|
|
|
address_hash: smart_contract.address_hash, |
|
|
|
|
tx_hash: fragment("CAST(NULL AS bytea)"), |
|
|
|
@ -1541,7 +1555,12 @@ defmodule Explorer.Chain do |
|
|
|
|
holder_count: ^nil, |
|
|
|
|
inserted_at: address.inserted_at, |
|
|
|
|
block_number: 0, |
|
|
|
|
icon_url: nil |
|
|
|
|
icon_url: nil, |
|
|
|
|
token_type: nil, |
|
|
|
|
timestamp: fragment("NULL::timestamp without time zone"), |
|
|
|
|
verified: true, |
|
|
|
|
exchange_rate: nil, |
|
|
|
|
total_supply: nil |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
@ -1570,7 +1589,12 @@ defmodule Explorer.Chain do |
|
|
|
|
holder_count: ^nil, |
|
|
|
|
inserted_at: address.inserted_at, |
|
|
|
|
block_number: 0, |
|
|
|
|
icon_url: nil |
|
|
|
|
icon_url: nil, |
|
|
|
|
token_type: nil, |
|
|
|
|
timestamp: fragment("NULL::timestamp without time zone"), |
|
|
|
|
verified: address.verified, |
|
|
|
|
exchange_rate: nil, |
|
|
|
|
total_supply: nil |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -1583,6 +1607,8 @@ defmodule Explorer.Chain do |
|
|
|
|
case Chain.string_to_transaction_hash(term) do |
|
|
|
|
{:ok, tx_hash} -> |
|
|
|
|
from(transaction in Transaction, |
|
|
|
|
left_join: block in Block, |
|
|
|
|
on: transaction.block_hash == block.hash, |
|
|
|
|
where: transaction.hash == ^tx_hash, |
|
|
|
|
select: %{ |
|
|
|
|
address_hash: fragment("CAST(NULL AS bytea)"), |
|
|
|
@ -1594,7 +1620,12 @@ defmodule Explorer.Chain do |
|
|
|
|
holder_count: ^nil, |
|
|
|
|
inserted_at: transaction.inserted_at, |
|
|
|
|
block_number: 0, |
|
|
|
|
icon_url: nil |
|
|
|
|
icon_url: nil, |
|
|
|
|
token_type: nil, |
|
|
|
|
timestamp: block.timestamp, |
|
|
|
|
verified: nil, |
|
|
|
|
exchange_rate: nil, |
|
|
|
|
total_supply: nil |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -1618,7 +1649,12 @@ defmodule Explorer.Chain do |
|
|
|
|
holder_count: ^nil, |
|
|
|
|
inserted_at: block.inserted_at, |
|
|
|
|
block_number: block.number, |
|
|
|
|
icon_url: nil |
|
|
|
|
icon_url: nil, |
|
|
|
|
token_type: nil, |
|
|
|
|
timestamp: block.timestamp, |
|
|
|
|
verified: nil, |
|
|
|
|
exchange_rate: nil, |
|
|
|
|
total_supply: nil |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -1637,7 +1673,12 @@ defmodule Explorer.Chain do |
|
|
|
|
holder_count: ^nil, |
|
|
|
|
inserted_at: block.inserted_at, |
|
|
|
|
block_number: block.number, |
|
|
|
|
icon_url: nil |
|
|
|
|
icon_url: nil, |
|
|
|
|
token_type: nil, |
|
|
|
|
timestamp: block.timestamp, |
|
|
|
|
verified: nil, |
|
|
|
|
exchange_rate: nil, |
|
|
|
|
total_supply: nil |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -1700,7 +1741,9 @@ defmodule Explorer.Chain do |
|
|
|
|
|
|
|
|
|
search_results |
|
|
|
|
|> Enum.map(fn result -> |
|
|
|
|
compose_result_checksummed_address_hash(result) |
|
|
|
|
result |
|
|
|
|
|> compose_result_checksummed_address_hash() |
|
|
|
|
|> format_timestamp() |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
@ -1717,80 +1760,13 @@ defmodule Explorer.Chain do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def search_tx(term) do |
|
|
|
|
case Chain.string_to_transaction_hash(term) do |
|
|
|
|
{:ok, tx_hash} -> |
|
|
|
|
query = |
|
|
|
|
from(transaction in Transaction, |
|
|
|
|
where: transaction.hash == ^tx_hash, |
|
|
|
|
select: %{ |
|
|
|
|
link: transaction.hash, |
|
|
|
|
type: "transaction" |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
Repo.all(query) |
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
|
[] |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def search_address(term) do |
|
|
|
|
case Chain.string_to_address_hash(term) do |
|
|
|
|
{:ok, address_hash} -> |
|
|
|
|
query = |
|
|
|
|
from(address in Address, |
|
|
|
|
left_join: address_name in Address.Name, |
|
|
|
|
on: address.hash == address_name.address_hash, |
|
|
|
|
where: address.hash == ^address_hash, |
|
|
|
|
select: %{ |
|
|
|
|
name: address_name.name, |
|
|
|
|
link: address.hash, |
|
|
|
|
type: "address" |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
Repo.all(query) |
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
|
[] |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def search_block(term) do |
|
|
|
|
case Chain.string_to_block_hash(term) do |
|
|
|
|
{:ok, block_hash} -> |
|
|
|
|
query = |
|
|
|
|
from(block in Block, |
|
|
|
|
where: block.hash == ^block_hash, |
|
|
|
|
select: %{ |
|
|
|
|
link: block.hash, |
|
|
|
|
block_number: block.number, |
|
|
|
|
type: "block" |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
Repo.all(query) |
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
|
case Integer.parse(term) do |
|
|
|
|
{block_number, _} -> |
|
|
|
|
query = |
|
|
|
|
from(block in Block, |
|
|
|
|
where: block.number == ^block_number, |
|
|
|
|
select: %{ |
|
|
|
|
link: block.hash, |
|
|
|
|
block_number: block.number, |
|
|
|
|
type: "block" |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
Repo.all(query) |
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
|
[] |
|
|
|
|
end |
|
|
|
|
# For some reasons timestamp for blocks and txs returns as ~N[2023-06-25 19:39:47.339493] |
|
|
|
|
defp format_timestamp(result) do |
|
|
|
|
if result.timestamp do |
|
|
|
|
result |
|
|
|
|
|> Map.put(:timestamp, DateTime.from_naive!(result.timestamp, "Etc/UTC")) |
|
|
|
|
else |
|
|
|
|
result |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|