parent
937b5bd24a
commit
1751d1aed4
@ -0,0 +1,21 @@ |
||||
defmodule Explorer.SkippedBalances do |
||||
@moduledoc "Gets a list of Addresses that do not have balances." |
||||
|
||||
alias Explorer.Address |
||||
alias Explorer.Repo |
||||
|
||||
import Ecto.Query, only: [from: 2] |
||||
|
||||
def fetch(count) do |
||||
query = |
||||
from( |
||||
address in Address, |
||||
select: address.hash, |
||||
where: is_nil(address.balance), |
||||
limit: ^count |
||||
) |
||||
|
||||
query |
||||
|> Repo.all() |
||||
end |
||||
end |
@ -0,0 +1,26 @@ |
||||
defmodule Mix.Tasks.Scrape.Balances do |
||||
@moduledoc "Populate Address balances." |
||||
|
||||
use Mix.Task |
||||
|
||||
alias Explorer.Repo |
||||
alias Explorer.SkippedBalances |
||||
alias Explorer.BalanceImporter |
||||
|
||||
def run([]), do: run(1) |
||||
|
||||
def run(count) do |
||||
[:postgrex, :ecto, :ethereumex, :tzdata] |
||||
|> Enum.each(&Application.ensure_all_started/1) |
||||
|
||||
Repo.start_link() |
||||
Exq.start_link(mode: :enqueuer) |
||||
|
||||
"#{count}" |
||||
|> String.to_integer() |
||||
|> SkippedBalances.fetch() |
||||
|> Flow.from_enumerable() |
||||
|> Flow.map(&BalanceImporter.import/1) |
||||
|> Enum.to_list() |
||||
end |
||||
end |
@ -0,0 +1,18 @@ |
||||
defmodule Explorer.SkippedBalancesTest do |
||||
use Explorer.DataCase |
||||
|
||||
alias Explorer.SkippedBalances |
||||
|
||||
describe "fetch/1" do |
||||
test "returns a list of address hashes that do not have balances" do |
||||
insert(:address, hash: "0xcashews", balance: nil) |
||||
assert SkippedBalances.fetch(1) == ["0xcashews"] |
||||
end |
||||
|
||||
test "only get a limited set of addresses" do |
||||
insert_list(10, :address, balance: nil) |
||||
insert_list(5, :address, balance: 55) |
||||
assert length(SkippedBalances.fetch(7)) == 7 |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue