Use 'Counters::TokenTransfer' instead of the database count

pull/867/head
Amanda Sposito 6 years ago
parent 0ed9020a96
commit 6afd0e7002
  1. 3
      apps/explorer/lib/explorer/chain.ex
  2. 12
      apps/explorer/lib/explorer/chain/token_transfer.ex
  3. 22
      apps/explorer/test/explorer/chain_test.exs

@ -38,6 +38,7 @@ defmodule Explorer.Chain do
alias Explorer.Chain.Block.Reward
alias Explorer.{PagingOptions, Repo}
alias Explorer.Counters.TokenTransferCounter
@default_paging_options %PagingOptions{page_size: 50}
@ -1922,7 +1923,7 @@ defmodule Explorer.Chain do
@spec count_token_transfers_from_token_hash(Hash.t()) :: non_neg_integer()
def count_token_transfers_from_token_hash(token_address_hash) do
TokenTransfer.count_token_transfers_from_token_hash(token_address_hash)
TokenTransferCounter.fetch(token_address_hash)
end
@spec transaction_has_token_transfers?(Hash.t()) :: boolean()

@ -127,18 +127,6 @@ defmodule Explorer.Chain.TokenTransfer do
|> Repo.all()
end
@spec count_token_transfers_from_token_hash(Hash.t()) :: non_neg_integer()
def count_token_transfers_from_token_hash(token_address_hash) do
query =
from(
tt in TokenTransfer,
where: tt.token_contract_address_hash == ^token_address_hash,
select: count(tt.id)
)
Repo.one(query)
end
def page_token_transfer(query, %PagingOptions{key: nil}), do: query
def page_token_transfer(query, %PagingOptions{key: {token_id}}) do

@ -558,28 +558,6 @@ defmodule Explorer.ChainTest do
end
end
describe "count_token_transfers_from_token_hash/1" do
test "without token transfers" do
%Token{contract_address_hash: contract_address_hash} = insert(:token)
assert Chain.count_token_transfers_from_token_hash(contract_address_hash) == 0
end
test "with token transfers" do
address = insert(:address)
transaction =
:transaction
|> insert()
|> with_block()
%TokenTransfer{token_contract_address_hash: token_contract_address_hash} =
insert(:token_transfer, to_address: address, transaction: transaction)
assert Chain.count_token_transfers_from_token_hash(token_contract_address_hash) == 1
end
end
describe "gas_price/2" do
test ":wei unit" do
assert Chain.gas_price(%Transaction{gas_price: %Wei{value: Decimal.new(1)}}, :wei) == Decimal.new(1)

Loading…
Cancel
Save