|
|
|
@ -5035,24 +5035,6 @@ defmodule Explorer.Chain do |
|
|
|
|
|> Repo.all() |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@spec erc721_token_instance_from_token_id_and_token_address(binary(), Hash.Address.t()) :: |
|
|
|
|
{:ok, TokenTransfer.t()} | {:error, :not_found} |
|
|
|
|
def erc721_token_instance_from_token_id_and_token_address(token_id, token_contract_address) do |
|
|
|
|
query = |
|
|
|
|
from(tt in TokenTransfer, |
|
|
|
|
left_join: instance in Instance, |
|
|
|
|
on: tt.token_contract_address_hash == instance.token_contract_address_hash and tt.token_id == instance.token_id, |
|
|
|
|
where: tt.token_contract_address_hash == ^token_contract_address and tt.token_id == ^token_id, |
|
|
|
|
limit: 1, |
|
|
|
|
select: %{tt | instance: instance} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
case Repo.one(query) do |
|
|
|
|
nil -> {:error, :not_found} |
|
|
|
|
token_instance -> {:ok, token_instance} |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@spec erc721_or_erc1155_token_instance_from_token_id_and_token_address(binary(), Hash.Address.t()) :: |
|
|
|
|
{:ok, Instance.t()} | {:error, :not_found} |
|
|
|
|
def erc721_or_erc1155_token_instance_from_token_id_and_token_address(token_id, token_contract_address) do |
|
|
|
@ -5265,13 +5247,13 @@ defmodule Explorer.Chain do |
|
|
|
|
Repo.one!(query, timeout: :infinity) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@spec address_to_unique_tokens(Hash.Address.t(), [paging_options]) :: [TokenTransfer.t()] |
|
|
|
|
@spec address_to_unique_tokens(Hash.Address.t(), [paging_options]) :: [Instance.t()] |
|
|
|
|
def address_to_unique_tokens(contract_address_hash, options \\ []) do |
|
|
|
|
paging_options = Keyword.get(options, :paging_options, @default_paging_options) |
|
|
|
|
|
|
|
|
|
contract_address_hash |
|
|
|
|
|> TokenTransfer.address_to_unique_tokens() |
|
|
|
|
|> TokenTransfer.page_token_transfer(paging_options) |
|
|
|
|
|> Instance.address_to_unique_token_instances() |
|
|
|
|
|> Instance.page_token_instance(paging_options) |
|
|
|
|
|> limit(^paging_options.page_size) |
|
|
|
|
|> Repo.all() |
|
|
|
|
end |
|
|
|
@ -5694,34 +5676,6 @@ defmodule Explorer.Chain do |
|
|
|
|
Repo.exists?(query) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Checks if a `t:Explorer.Chain.TokenTransfer.t/0` of type ERC-721 with the given `hash` and `token_id` exists. |
|
|
|
|
|
|
|
|
|
Returns `:ok` if found |
|
|
|
|
|
|
|
|
|
iex> contract_address = insert(:address) |
|
|
|
|
iex> token_id = 10 |
|
|
|
|
iex> insert(:token_transfer, |
|
|
|
|
...> from_address: contract_address, |
|
|
|
|
...> token_contract_address: contract_address, |
|
|
|
|
...> token_id: token_id |
|
|
|
|
...> ) |
|
|
|
|
iex> Explorer.Chain.check_erc721_token_instance_exists(token_id, contract_address.hash) |
|
|
|
|
:ok |
|
|
|
|
|
|
|
|
|
Returns `:not_found` if not found |
|
|
|
|
|
|
|
|
|
iex> {:ok, hash} = Explorer.Chain.string_to_address_hash("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed") |
|
|
|
|
iex> Explorer.Chain.check_erc721_token_instance_exists(10, hash) |
|
|
|
|
:not_found |
|
|
|
|
""" |
|
|
|
|
@spec check_erc721_token_instance_exists(binary() | non_neg_integer(), Hash.Address.t()) :: :ok | :not_found |
|
|
|
|
def check_erc721_token_instance_exists(token_id, hash) do |
|
|
|
|
token_id |
|
|
|
|
|> erc721_token_instance_exist?(hash) |
|
|
|
|
|> boolean_to_check_result() |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Checks if a `t:Explorer.Chain.TokenTransfer.t/0` of type ERC-721 or ERC-1155 with the given `hash` and `token_id` exists. |
|
|
|
|
|
|
|
|
@ -5761,37 +5715,6 @@ defmodule Explorer.Chain do |
|
|
|
|
|> boolean_to_check_result() |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Checks if a `t:Explorer.Chain.TokenTransfer.t/0` of type ERC-721 with the given `hash` and `token_id` exists. |
|
|
|
|
|
|
|
|
|
Returns `true` if found |
|
|
|
|
|
|
|
|
|
iex> contract_address = insert(:address) |
|
|
|
|
iex> token_id = 10 |
|
|
|
|
iex> insert(:token_transfer, |
|
|
|
|
...> from_address: contract_address, |
|
|
|
|
...> token_contract_address: contract_address, |
|
|
|
|
...> token_id: token_id |
|
|
|
|
...> ) |
|
|
|
|
iex> Explorer.Chain.erc721_token_instance_exist?(token_id, contract_address.hash) |
|
|
|
|
true |
|
|
|
|
|
|
|
|
|
Returns `false` if not found |
|
|
|
|
|
|
|
|
|
iex> {:ok, hash} = Explorer.Chain.string_to_address_hash("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed") |
|
|
|
|
iex> Explorer.Chain.erc721_token_instance_exist?(10, hash) |
|
|
|
|
false |
|
|
|
|
""" |
|
|
|
|
@spec erc721_token_instance_exist?(binary() | non_neg_integer(), Hash.Address.t()) :: boolean() |
|
|
|
|
def erc721_token_instance_exist?(token_id, hash) do |
|
|
|
|
query = |
|
|
|
|
from(tt in TokenTransfer, |
|
|
|
|
where: tt.token_contract_address_hash == ^hash and tt.token_id == ^token_id |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
Repo.exists?(query) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Checks if a `t:Explorer.Chain.TokenTransfer.t/0` of type ERC-721 or ERC-1155 with the given `hash` and `token_id` exists. |
|
|
|
|
|
|
|
|
|