|
|
@ -40,7 +40,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
query |
|
|
|
|> Repo.one() |
|
|
|
|> Repo.one(timeout: :infinity) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -60,7 +60,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
query |
|
|
|
|> Repo.one() |
|
|
|
|> Repo.one(timeout: :infinity) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -86,7 +86,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
|> order_by(desc: :block_number) |
|
|
|
|> order_by(desc: :block_number) |
|
|
|
|> limit(1) |
|
|
|
|> limit(1) |
|
|
|
|> select([log], log.block_number) |
|
|
|
|> select([log], log.block_number) |
|
|
|
|> Repo.one() |
|
|
|
|> Repo.one(timeout: :infinity) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -107,7 +107,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
|> order_by(desc: :block_number) |
|
|
|
|> order_by(desc: :block_number) |
|
|
|
|> limit(1) |
|
|
|
|> limit(1) |
|
|
|
|> select([rollup_tx], rollup_tx.block_number) |
|
|
|
|> select([rollup_tx], rollup_tx.block_number) |
|
|
|
|> Repo.one() |
|
|
|
|> Repo.one(timeout: :infinity) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -132,7 +132,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
case query |
|
|
|
case query |
|
|
|
# :required is used since the situation when commit transaction is not found is not possible |
|
|
|
# :required is used since the situation when commit transaction is not found is not possible |
|
|
|
|> Chain.join_associations(%{:commitment_transaction => :required}) |
|
|
|
|> Chain.join_associations(%{:commitment_transaction => :required}) |
|
|
|
|> Repo.one() do |
|
|
|
|> Repo.one(timeout: :infinity) do |
|
|
|
nil -> nil |
|
|
|
nil -> nil |
|
|
|
batch -> batch.commitment_transaction.block_number |
|
|
|
batch -> batch.commitment_transaction.block_number |
|
|
|
end |
|
|
|
end |
|
|
@ -160,7 +160,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
case query |
|
|
|
case query |
|
|
|
# :required is used since the situation when commit transaction is not found is not possible |
|
|
|
# :required is used since the situation when commit transaction is not found is not possible |
|
|
|
|> Chain.join_associations(%{:commitment_transaction => :required}) |
|
|
|
|> Chain.join_associations(%{:commitment_transaction => :required}) |
|
|
|
|> Repo.one() do |
|
|
|
|> Repo.one(timeout: :infinity) do |
|
|
|
nil -> nil |
|
|
|
nil -> nil |
|
|
|
batch -> batch.commitment_transaction.block_number |
|
|
|
batch -> batch.commitment_transaction.block_number |
|
|
|
end |
|
|
|
end |
|
|
@ -205,7 +205,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
where: lt.hash in ^l1_tx_hashes |
|
|
|
where: lt.hash in ^l1_tx_hashes |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
Repo.all(query, timeout: :infinity) |
|
|
|
Repo.all(query) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -227,7 +227,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
where: lt.hash in ^l1_tx_hashes |
|
|
|
where: lt.hash in ^l1_tx_hashes |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
Repo.all(query, timeout: :infinity) |
|
|
|
Repo.all(query) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -253,7 +253,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
# :required is used since execution records in the table are created only when |
|
|
|
# :required is used since execution records in the table are created only when |
|
|
|
# the corresponding execution transaction is indexed |
|
|
|
# the corresponding execution transaction is indexed |
|
|
|
|> Chain.join_associations(%{:execution_transaction => :required}) |
|
|
|
|> Chain.join_associations(%{:execution_transaction => :required}) |
|
|
|
|> Repo.all(timeout: :infinity) |
|
|
|
|> Repo.all() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -305,7 +305,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
where: lt.block_number <= ^finalized_block and lt.status == :unfinalized |
|
|
|
where: lt.block_number <= ^finalized_block and lt.status == :unfinalized |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
Repo.all(query, timeout: :infinity) |
|
|
|
Repo.all(query) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -357,7 +357,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
query |
|
|
|
|> Repo.all(timeout: :infinity) |
|
|
|
|> Repo.all() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -426,7 +426,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
case query |
|
|
|
case query |
|
|
|
# :required is used since existence of the confirmation id is checked above |
|
|
|
# :required is used since existence of the confirmation id is checked above |
|
|
|
|> Chain.join_associations(%{:confirmation_transaction => :required}) |
|
|
|
|> Chain.join_associations(%{:confirmation_transaction => :required}) |
|
|
|
|> Repo.one() do |
|
|
|
|> Repo.one(timeout: :infinity) do |
|
|
|
nil -> |
|
|
|
nil -> |
|
|
|
nil |
|
|
|
nil |
|
|
|
|
|
|
|
|
|
|
@ -480,7 +480,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
query |
|
|
|
|> Repo.one() |
|
|
|
|> Repo.one(timeout: :infinity) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -502,7 +502,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
query |
|
|
|
|> Repo.one() |
|
|
|
|> Repo.one(timeout: :infinity) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -532,7 +532,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
order_by: [asc: rb.block_number] |
|
|
|
order_by: [asc: rb.block_number] |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
Repo.all(query, timeout: :infinity) |
|
|
|
Repo.all(query) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -553,7 +553,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
where: rb.batch_number == ^batch_number and not is_nil(rb.confirmation_id) |
|
|
|
where: rb.batch_number == ^batch_number and not is_nil(rb.confirmation_id) |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
Repo.aggregate(query, :count, timeout: :infinity) |
|
|
|
Repo.aggregate(query, :count) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -588,7 +588,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
order_by: [desc: msg.message_id] |
|
|
|
order_by: [desc: msg.message_id] |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
Repo.all(query, timeout: :infinity) |
|
|
|
Repo.all(query) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def l2_to_l1_messages(status, nil) when status in [:initiated, :sent, :confirmed, :relayed] do |
|
|
|
def l2_to_l1_messages(status, nil) when status in [:initiated, :sent, :confirmed, :relayed] do |
|
|
@ -598,7 +598,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
order_by: [desc: msg.message_id] |
|
|
|
order_by: [desc: msg.message_id] |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
Repo.all(query, timeout: :infinity) |
|
|
|
Repo.all(query) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -704,7 +704,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
defp do_messages_count(direction, options) do |
|
|
|
defp do_messages_count(direction, options) do |
|
|
|
Message |
|
|
|
Message |
|
|
|
|> where([msg], msg.direction == ^direction) |
|
|
|
|> where([msg], msg.direction == ^direction) |
|
|
|
|> select_repo(options).aggregate(:count, timeout: :infinity) |
|
|
|
|> select_repo(options).aggregate(:count) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -1223,7 +1223,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
query |
|
|
|
|> Repo.all(timeout: :infinity) |
|
|
|
|> Repo.all() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -1248,7 +1248,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
query |
|
|
|
|> Repo.all(timeout: :infinity) |
|
|
|
|> Repo.all() |
|
|
|
|> Enum.reduce(%{}, fn {batch_number, l1_block_number}, acc -> |
|
|
|
|> Enum.reduce(%{}, fn {batch_number, l1_block_number}, acc -> |
|
|
|
Map.put(acc, batch_number, l1_block_number) |
|
|
|
Map.put(acc, batch_number, l1_block_number) |
|
|
|
end) |
|
|
|
end) |
|
|
@ -1267,6 +1267,63 @@ defmodule Explorer.Chain.Arbitrum.Reader do |
|
|
|
select: {min(batch.number), max(batch.number)} |
|
|
|
select: {min(batch.number), max(batch.number)} |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
Repo.one(query) |
|
|
|
Repo.one(query, timeout: :infinity) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##################################################################################### |
|
|
|
|
|
|
|
### Below are the functions that implement functionality not specific to Arbitrum ### |
|
|
|
|
|
|
|
##################################################################################### |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
|
|
|
Checks if a block with the given block number exists. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This function queries the database to determine if a block with the specified |
|
|
|
|
|
|
|
block number exists and has been marked as having reached consensus. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Parameters |
|
|
|
|
|
|
|
- `block_number`: The number of the block to check. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Returns |
|
|
|
|
|
|
|
- `true` if the block exists and has reached consensus. |
|
|
|
|
|
|
|
- `false` otherwise. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
@spec rollup_block_exists?(FullBlock.block_number()) :: boolean() |
|
|
|
|
|
|
|
def rollup_block_exists?(block_number) do |
|
|
|
|
|
|
|
query = |
|
|
|
|
|
|
|
from( |
|
|
|
|
|
|
|
block in FullBlock, |
|
|
|
|
|
|
|
where: block.number == ^block_number and block.consensus == true |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Repo.exists?(query, timeout: :infinity) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
|
|
|
Retrieves full details of rollup blocks, including associated transactions, for each |
|
|
|
|
|
|
|
block number specified in the input list. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Parameters |
|
|
|
|
|
|
|
- `list_of_block_numbers`: A list of block numbers for which full block details are to be retrieved. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Returns |
|
|
|
|
|
|
|
- A list of `Explorer.Chain.Block` instances containing detailed information for each |
|
|
|
|
|
|
|
block number in the input list. Returns an empty list if no blocks are found for the given numbers. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
@spec rollup_blocks([FullBlock.block_number()]) :: [FullBlock.t()] |
|
|
|
|
|
|
|
def rollup_blocks(list_of_block_numbers) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rollup_blocks([]), do: [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rollup_blocks(list_of_block_numbers) do |
|
|
|
|
|
|
|
query = |
|
|
|
|
|
|
|
from( |
|
|
|
|
|
|
|
block in FullBlock, |
|
|
|
|
|
|
|
where: block.number in ^list_of_block_numbers |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query |
|
|
|
|
|
|
|
# :optional is used since a block may not have any transactions |
|
|
|
|
|
|
|
|> Chain.join_associations(%{:transactions => :optional}) |
|
|
|
|
|
|
|
|> Repo.all() |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|