|
|
@ -11,7 +11,7 @@ defmodule Explorer.Chain.Address.CurrentTokenBalance do |
|
|
|
import Ecto.Changeset |
|
|
|
import Ecto.Changeset |
|
|
|
import Ecto.Query, only: [from: 2, limit: 2, offset: 2, order_by: 3, preload: 2] |
|
|
|
import Ecto.Query, only: [from: 2, limit: 2, offset: 2, order_by: 3, preload: 2] |
|
|
|
|
|
|
|
|
|
|
|
alias Explorer.{Chain, PagingOptions} |
|
|
|
alias Explorer.{Chain, PagingOptions, Repo} |
|
|
|
alias Explorer.Chain.{Address, Block, BridgedToken, Hash, Token} |
|
|
|
alias Explorer.Chain.{Address, Block, BridgedToken, Hash, Token} |
|
|
|
|
|
|
|
|
|
|
|
@default_paging_options %PagingOptions{page_size: 50} |
|
|
|
@default_paging_options %PagingOptions{page_size: 50} |
|
|
@ -188,25 +188,33 @@ defmodule Explorer.Chain.Address.CurrentTokenBalance do |
|
|
|
Builds an `t:Ecto.Query.t/0` to fetch the current balance of the given address for the given token. |
|
|
|
Builds an `t:Ecto.Query.t/0` to fetch the current balance of the given address for the given token. |
|
|
|
""" |
|
|
|
""" |
|
|
|
def last_token_balance(address_hash, token_contract_address_hash) do |
|
|
|
def last_token_balance(address_hash, token_contract_address_hash) do |
|
|
|
from( |
|
|
|
query = |
|
|
|
tb in __MODULE__, |
|
|
|
from( |
|
|
|
where: tb.token_contract_address_hash == ^token_contract_address_hash, |
|
|
|
tb in __MODULE__, |
|
|
|
where: tb.address_hash == ^address_hash, |
|
|
|
where: tb.token_contract_address_hash == ^token_contract_address_hash, |
|
|
|
select: tb.value |
|
|
|
where: tb.address_hash == ^address_hash, |
|
|
|
) |
|
|
|
select: tb.value |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
|
|
|
|
|> Repo.one() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|
Builds an `t:Ecto.Query.t/0` to fetch the current balance of the given address for the given token and token_id |
|
|
|
Builds an `t:Ecto.Query.t/0` to fetch the current balance of the given address for the given token and token_id |
|
|
|
""" |
|
|
|
""" |
|
|
|
def last_token_balance_1155(address_hash, token_contract_address_hash, token_id) do |
|
|
|
def last_token_balance_1155(address_hash, token_contract_address_hash, token_id) do |
|
|
|
from( |
|
|
|
query = |
|
|
|
ctb in __MODULE__, |
|
|
|
from( |
|
|
|
where: ctb.token_contract_address_hash == ^token_contract_address_hash, |
|
|
|
ctb in __MODULE__, |
|
|
|
where: ctb.address_hash == ^address_hash, |
|
|
|
where: ctb.token_contract_address_hash == ^token_contract_address_hash, |
|
|
|
where: ctb.token_id == ^token_id, |
|
|
|
where: ctb.address_hash == ^address_hash, |
|
|
|
select: ctb.value |
|
|
|
where: ctb.token_id == ^token_id, |
|
|
|
) |
|
|
|
select: ctb.value |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
|
|
|
|
|> Repo.one() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|