|
|
@ -4,7 +4,7 @@ defmodule Explorer.Chain.Beacon.Reader do |
|
|
|
import Ecto.Query, |
|
|
|
import Ecto.Query, |
|
|
|
only: [ |
|
|
|
only: [ |
|
|
|
subquery: 1, |
|
|
|
subquery: 1, |
|
|
|
preload: 2, |
|
|
|
distinct: 3, |
|
|
|
from: 2, |
|
|
|
from: 2, |
|
|
|
limit: 2, |
|
|
|
limit: 2, |
|
|
|
order_by: 3, |
|
|
|
order_by: 3, |
|
|
@ -16,10 +16,11 @@ defmodule Explorer.Chain.Beacon.Reader do |
|
|
|
|
|
|
|
|
|
|
|
import Explorer.Chain, only: [select_repo: 1] |
|
|
|
import Explorer.Chain, only: [select_repo: 1] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alias Explorer.{Chain, Repo} |
|
|
|
|
|
|
|
alias Explorer.Chain.{DenormalizationHelper, Hash, Transaction} |
|
|
|
alias Explorer.Chain.Beacon.{Blob, BlobTransaction} |
|
|
|
alias Explorer.Chain.Beacon.{Blob, BlobTransaction} |
|
|
|
alias Explorer.{Chain, PagingOptions, Repo} |
|
|
|
|
|
|
|
alias Explorer.Chain.{Hash, Transaction} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@spec blob(Hash.Full.t(), [Chain.api?()]) :: {:error, :not_found} | {:ok, Blob.t()} |
|
|
|
def blob(hash, options) when is_list(options) do |
|
|
|
def blob(hash, options) when is_list(options) do |
|
|
|
Blob |
|
|
|
Blob |
|
|
|
|> where(hash: ^hash) |
|
|
|
|> where(hash: ^hash) |
|
|
@ -30,20 +31,48 @@ defmodule Explorer.Chain.Beacon.Reader do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@spec blob_hash_to_transactions(Hash.Full.t(), [Chain.api?()]) :: [ |
|
|
|
|
|
|
|
%{ |
|
|
|
|
|
|
|
block_consensus: boolean(), |
|
|
|
|
|
|
|
transaction_hash: Hash.Full.t() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
] |
|
|
|
def blob_hash_to_transactions(hash, options) when is_list(options) do |
|
|
|
def blob_hash_to_transactions(hash, options) when is_list(options) do |
|
|
|
BlobTransaction |
|
|
|
query = |
|
|
|
|> where(type(^hash, Hash.Full) == fragment("any(blob_versioned_hashes)")) |
|
|
|
BlobTransaction |
|
|
|
|> join(:inner, [bt], transaction in Transaction, on: bt.hash == transaction.hash) |
|
|
|
|> where(type(^hash, Hash.Full) == fragment("any(blob_versioned_hashes)")) |
|
|
|
|> order_by([bt, transaction], desc: transaction.block_consensus, desc: transaction.block_number) |
|
|
|
|> join(:inner, [bt], transaction in Transaction, on: bt.hash == transaction.hash) |
|
|
|
|> limit(10) |
|
|
|
|> order_by([bt, transaction], desc: transaction.block_consensus, desc: transaction.block_number) |
|
|
|
|> select([bt, transaction], %{ |
|
|
|
|> limit(10) |
|
|
|
block_consensus: transaction.block_consensus, |
|
|
|
|
|
|
|
transaction_hash: transaction.hash |
|
|
|
query_with_denormalization = |
|
|
|
}) |
|
|
|
if DenormalizationHelper.denormalization_finished?() do |
|
|
|
|> select_repo(options).all() |
|
|
|
query |
|
|
|
|
|
|
|
|> select([bt, transaction], %{ |
|
|
|
|
|
|
|
block_consensus: transaction.block_consensus, |
|
|
|
|
|
|
|
transaction_hash: transaction.hash |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
query |
|
|
|
|
|
|
|
|> join(:inner, [bt, transaction], block in Block, on: block.hash == transaction.block_hash) |
|
|
|
|
|
|
|
|> select([bt, transaction, block], %{ |
|
|
|
|
|
|
|
block_consensus: block.consensus, |
|
|
|
|
|
|
|
transaction_hash: transaction.hash |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query_with_denormalization |> select_repo(options).all() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def stream_missed_blob_transactions_timestamps(min_block, max_block, initial, reducer, options \\ []) |
|
|
|
@spec stream_missed_blob_transactions_timestamps( |
|
|
|
|
|
|
|
initial :: accumulator, |
|
|
|
|
|
|
|
reducer :: (entry :: Hash.Address.t(), accumulator -> accumulator), |
|
|
|
|
|
|
|
min_block :: integer() | nil, |
|
|
|
|
|
|
|
max_block :: integer() | nil, |
|
|
|
|
|
|
|
options :: [] |
|
|
|
|
|
|
|
) :: {:ok, accumulator} |
|
|
|
|
|
|
|
when accumulator: term() |
|
|
|
|
|
|
|
def stream_missed_blob_transactions_timestamps(initial, reducer, min_block, max_block, options \\ []) |
|
|
|
when is_list(options) do |
|
|
|
when is_list(options) do |
|
|
|
query = |
|
|
|
query = |
|
|
|
from( |
|
|
|
from( |
|
|
@ -58,23 +87,34 @@ defmodule Explorer.Chain.Beacon.Reader do |
|
|
|
), |
|
|
|
), |
|
|
|
inner_join: transaction in Transaction, |
|
|
|
inner_join: transaction in Transaction, |
|
|
|
on: transaction_blob.transaction_hash == transaction.hash, |
|
|
|
on: transaction_blob.transaction_hash == transaction.hash, |
|
|
|
|
|
|
|
# EIP-2718 blob transaction type |
|
|
|
where: transaction.type == 3, |
|
|
|
where: transaction.type == 3, |
|
|
|
left_join: blob in Blob, |
|
|
|
left_join: blob in Blob, |
|
|
|
on: blob.hash == transaction_blob.blob_hash, |
|
|
|
on: blob.hash == transaction_blob.blob_hash, |
|
|
|
where: is_nil(blob.hash), |
|
|
|
where: is_nil(blob.hash) |
|
|
|
distinct: transaction.block_timestamp, |
|
|
|
|
|
|
|
select: transaction.block_timestamp |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
query_with_denormalization = |
|
|
|
|
|
|
|
if DenormalizationHelper.denormalization_finished?() do |
|
|
|
|
|
|
|
query |
|
|
|
|
|
|
|
|> distinct([transaction_blob, transaction, blob], transaction.block_timestamp) |
|
|
|
|
|
|
|
|> select([transaction_blob, transaction, blob], transaction.block_timestamp) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
query |
|
|
|
|
|
|
|
|> join(:inner, [transaction_blob, transaction, blob], block in Block, on: block.hash == transaction.block_hash) |
|
|
|
|
|
|
|
|> distinct([transaction_blob, transaction, blob, block], block.timestamp) |
|
|
|
|
|
|
|
|> select([transaction_blob, transaction, blob, block], block.timestamp) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query_with_denormalization |
|
|
|
|> add_min_block_filter(min_block) |
|
|
|
|> add_min_block_filter(min_block) |
|
|
|
|> add_max_block_filter(min_block) |
|
|
|
|> add_max_block_filter(max_block) |
|
|
|
|> Repo.stream_reduce(initial, reducer) |
|
|
|
|> Repo.stream_reduce(initial, reducer) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp add_min_block_filter(query, block_number) do |
|
|
|
defp add_min_block_filter(query, block_number) do |
|
|
|
if is_integer(block_number) do |
|
|
|
if is_integer(block_number) do |
|
|
|
query |> where([_, transaction], transaction.block_number <= ^block_number) |
|
|
|
query |> where([_, transaction], transaction.block_number >= ^block_number) |
|
|
|
else |
|
|
|
else |
|
|
|
query |
|
|
|
query |
|
|
|
end |
|
|
|
end |
|
|
@ -82,7 +122,7 @@ defmodule Explorer.Chain.Beacon.Reader do |
|
|
|
|
|
|
|
|
|
|
|
defp add_max_block_filter(query, block_number) do |
|
|
|
defp add_max_block_filter(query, block_number) do |
|
|
|
if is_integer(block_number) and block_number > 0 do |
|
|
|
if is_integer(block_number) and block_number > 0 do |
|
|
|
query |> where([_, transaction], transaction.block_number >= ^block_number) |
|
|
|
query |> where([_, transaction], transaction.block_number <= ^block_number) |
|
|
|
else |
|
|
|
else |
|
|
|
query |
|
|
|
query |
|
|
|
end |
|
|
|
end |
|
|
|