|
|
@ -65,18 +65,20 @@ defmodule Explorer.Chain.Address.TokenBalance do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@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. |
|
|
|
The last token balances from an Address is the last block indexed. |
|
|
|
""" |
|
|
|
""" |
|
|
|
def last_token_balances(address_hash) do |
|
|
|
def last_token_balances(address_hash) do |
|
|
|
from( |
|
|
|
query = |
|
|
|
tb in TokenBalance, |
|
|
|
from( |
|
|
|
where: tb.address_hash == ^address_hash and tb.value > 0, |
|
|
|
tb in TokenBalance, |
|
|
|
distinct: :token_contract_address_hash, |
|
|
|
where: tb.address_hash == ^address_hash, |
|
|
|
order_by: [desc: :block_number], |
|
|
|
distinct: :token_contract_address_hash, |
|
|
|
preload: :token |
|
|
|
order_by: [desc: :block_number] |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from(tb in subquery(query), where: tb.value > 0, preload: :token) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|