|
|
@ -955,7 +955,7 @@ defmodule Explorer.Chain do |
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|
Counts all of the block validations and groups by the `miner_hash`. |
|
|
|
Counts all of the block validations and groups by the `miner_hash`. |
|
|
|
""" |
|
|
|
""" |
|
|
|
def group_block_validations_by_address do |
|
|
|
def each_address_block_validation_count(fun) when is_function(fun, 1) do |
|
|
|
query = |
|
|
|
query = |
|
|
|
from( |
|
|
|
from( |
|
|
|
b in Block, |
|
|
|
b in Block, |
|
|
@ -965,7 +965,7 @@ defmodule Explorer.Chain do |
|
|
|
group_by: b.miner_hash |
|
|
|
group_by: b.miner_hash |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
Repo.all(query) |
|
|
|
Repo.stream_each(query, fun) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -1007,21 +1007,14 @@ defmodule Explorer.Chain do |
|
|
|
) :: {:ok, accumulator} |
|
|
|
) :: {:ok, accumulator} |
|
|
|
when accumulator: term() |
|
|
|
when accumulator: term() |
|
|
|
def stream_unfetched_balances(initial, reducer) when is_function(reducer, 2) do |
|
|
|
def stream_unfetched_balances(initial, reducer) when is_function(reducer, 2) do |
|
|
|
Repo.transaction( |
|
|
|
query = |
|
|
|
fn -> |
|
|
|
from( |
|
|
|
query = |
|
|
|
balance in CoinBalance, |
|
|
|
from( |
|
|
|
where: is_nil(balance.value_fetched_at), |
|
|
|
balance in CoinBalance, |
|
|
|
select: %{address_hash: balance.address_hash, block_number: balance.block_number} |
|
|
|
where: is_nil(balance.value_fetched_at), |
|
|
|
) |
|
|
|
select: %{address_hash: balance.address_hash, block_number: balance.block_number} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
Repo.stream_reduce(query, initial, reducer) |
|
|
|
|> Repo.stream(timeout: :infinity) |
|
|
|
|
|
|
|
|> Enum.reduce(initial, reducer) |
|
|
|
|
|
|
|
end, |
|
|
|
|
|
|
|
timeout: :infinity |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -1033,16 +1026,8 @@ defmodule Explorer.Chain do |
|
|
|
) :: {:ok, accumulator} |
|
|
|
) :: {:ok, accumulator} |
|
|
|
when accumulator: term() |
|
|
|
when accumulator: term() |
|
|
|
def stream_unfetched_token_balances(initial, reducer) when is_function(reducer, 2) do |
|
|
|
def stream_unfetched_token_balances(initial, reducer) when is_function(reducer, 2) do |
|
|
|
Repo.transaction( |
|
|
|
TokenBalance.unfetched_token_balances() |
|
|
|
fn -> |
|
|
|
|> Repo.stream_reduce(initial, reducer) |
|
|
|
query = TokenBalance.unfetched_token_balances() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
|
|
|
|
|> Repo.stream(timeout: :infinity) |
|
|
|
|
|
|
|
|> Enum.reduce(initial, reducer) |
|
|
|
|
|
|
|
end, |
|
|
|
|
|
|
|
timeout: :infinity |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -1097,22 +1082,15 @@ defmodule Explorer.Chain do |
|
|
|
) :: {:ok, accumulator} |
|
|
|
) :: {:ok, accumulator} |
|
|
|
when accumulator: term() |
|
|
|
when accumulator: term() |
|
|
|
def stream_transactions_with_unfetched_internal_transactions(fields, initial, reducer) when is_function(reducer, 2) do |
|
|
|
def stream_transactions_with_unfetched_internal_transactions(fields, initial, reducer) when is_function(reducer, 2) do |
|
|
|
Repo.transaction( |
|
|
|
query = |
|
|
|
fn -> |
|
|
|
from( |
|
|
|
query = |
|
|
|
t in Transaction, |
|
|
|
from( |
|
|
|
# exclude pending transactions |
|
|
|
t in Transaction, |
|
|
|
where: not is_nil(t.block_hash) and is_nil(t.internal_transactions_indexed_at), |
|
|
|
# exclude pending transactions |
|
|
|
select: ^fields |
|
|
|
where: not is_nil(t.block_hash) and is_nil(t.internal_transactions_indexed_at), |
|
|
|
) |
|
|
|
select: ^fields |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
Repo.stream_reduce(query, initial, reducer) |
|
|
|
|> Repo.stream(timeout: :infinity) |
|
|
|
|
|
|
|
|> Enum.reduce(initial, reducer) |
|
|
|
|
|
|
|
end, |
|
|
|
|
|
|
|
timeout: :infinity |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -1129,21 +1107,14 @@ defmodule Explorer.Chain do |
|
|
|
) :: {:ok, accumulator} |
|
|
|
) :: {:ok, accumulator} |
|
|
|
when accumulator: term() |
|
|
|
when accumulator: term() |
|
|
|
def stream_unfetched_uncle_hashes(initial, reducer) when is_function(reducer, 2) do |
|
|
|
def stream_unfetched_uncle_hashes(initial, reducer) when is_function(reducer, 2) do |
|
|
|
Repo.transaction( |
|
|
|
query = |
|
|
|
fn -> |
|
|
|
from(bsdr in Block.SecondDegreeRelation, |
|
|
|
query = |
|
|
|
where: is_nil(bsdr.uncle_fetched_at), |
|
|
|
from(bsdr in Block.SecondDegreeRelation, |
|
|
|
select: bsdr.uncle_hash, |
|
|
|
where: is_nil(bsdr.uncle_fetched_at), |
|
|
|
group_by: bsdr.uncle_hash |
|
|
|
select: bsdr.uncle_hash, |
|
|
|
) |
|
|
|
group_by: bsdr.uncle_hash |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
Repo.stream_reduce(query, initial, reducer) |
|
|
|
|> Repo.stream(timeout: :infinity) |
|
|
|
|
|
|
|
|> Enum.reduce(initial, reducer) |
|
|
|
|
|
|
|
end, |
|
|
|
|
|
|
|
timeout: :infinity |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -1938,22 +1909,15 @@ defmodule Explorer.Chain do |
|
|
|
reducer :: (entry :: Hash.Address.t(), accumulator -> accumulator) |
|
|
|
reducer :: (entry :: Hash.Address.t(), accumulator -> accumulator) |
|
|
|
) :: {:ok, accumulator} |
|
|
|
) :: {:ok, accumulator} |
|
|
|
when accumulator: term() |
|
|
|
when accumulator: term() |
|
|
|
def stream_uncataloged_token_contract_address_hashes(initial_acc, reducer) when is_function(reducer, 2) do |
|
|
|
def stream_uncataloged_token_contract_address_hashes(initial, reducer) when is_function(reducer, 2) do |
|
|
|
Repo.transaction( |
|
|
|
query = |
|
|
|
fn -> |
|
|
|
from( |
|
|
|
query = |
|
|
|
token in Token, |
|
|
|
from( |
|
|
|
where: token.cataloged == false, |
|
|
|
token in Token, |
|
|
|
select: token.contract_address_hash |
|
|
|
where: token.cataloged == false, |
|
|
|
) |
|
|
|
select: token.contract_address_hash |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
Repo.stream_reduce(query, initial, reducer) |
|
|
|
|> Repo.stream(timeout: :infinity) |
|
|
|
|
|
|
|
|> Enum.reduce(initial_acc, reducer) |
|
|
|
|
|
|
|
end, |
|
|
|
|
|
|
|
timeout: :infinity |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -1964,16 +1928,10 @@ defmodule Explorer.Chain do |
|
|
|
reducer :: (entry :: Hash.Address.t(), accumulator -> accumulator) |
|
|
|
reducer :: (entry :: Hash.Address.t(), accumulator -> accumulator) |
|
|
|
) :: {:ok, accumulator} |
|
|
|
) :: {:ok, accumulator} |
|
|
|
when accumulator: term() |
|
|
|
when accumulator: term() |
|
|
|
def stream_cataloged_token_contract_address_hashes(initial_acc, reducer) when is_function(reducer, 2) do |
|
|
|
def stream_cataloged_token_contract_address_hashes(initial, reducer) when is_function(reducer, 2) do |
|
|
|
Repo.transaction( |
|
|
|
Chain.Token.cataloged_tokens() |
|
|
|
fn -> |
|
|
|
|> order_by(asc: :updated_at) |
|
|
|
Chain.Token.cataloged_tokens() |
|
|
|
|> Repo.stream_reduce(initial, reducer) |
|
|
|
|> order_by(asc: :updated_at) |
|
|
|
|
|
|
|
|> Repo.stream(timeout: :infinity) |
|
|
|
|
|
|
|
|> Enum.reduce(initial_acc, reducer) |
|
|
|
|
|
|
|
end, |
|
|
|
|
|
|
|
timeout: :infinity |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -1992,14 +1950,7 @@ defmodule Explorer.Chain do |
|
|
|
distinct: t.block_number |
|
|
|
distinct: t.block_number |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
Repo.transaction( |
|
|
|
Repo.stream_reduce(query, [], &[&1 | &2]) |
|
|
|
fn -> |
|
|
|
|
|
|
|
query |
|
|
|
|
|
|
|
|> Repo.stream(timeout: :infinity) |
|
|
|
|
|
|
|
|> Enum.reduce([], &[&1 | &2]) |
|
|
|
|
|
|
|
end, |
|
|
|
|
|
|
|
timeout: :infinity |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|