|
|
|
@ -65,18 +65,20 @@ defmodule Explorer.Chain.Address.TokenBalance do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Builds an `Ecto.Query` to fetch the last token balances. |
|
|
|
|
Builds an `Ecto.Query` to fetch the last token balances that have value greater than 0. |
|
|
|
|
|
|
|
|
|
The last token balances from an Address is the last block indexed. |
|
|
|
|
""" |
|
|
|
|
def last_token_balances(address_hash) do |
|
|
|
|
from( |
|
|
|
|
tb in TokenBalance, |
|
|
|
|
where: tb.address_hash == ^address_hash and tb.value > 0, |
|
|
|
|
distinct: :token_contract_address_hash, |
|
|
|
|
order_by: [desc: :block_number], |
|
|
|
|
preload: :token |
|
|
|
|
) |
|
|
|
|
query = |
|
|
|
|
from( |
|
|
|
|
tb in TokenBalance, |
|
|
|
|
where: tb.address_hash == ^address_hash, |
|
|
|
|
distinct: :token_contract_address_hash, |
|
|
|
|
order_by: [desc: :block_number] |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
from(tb in subquery(query), where: tb.value > 0, preload: :token) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|