|
|
@ -32,6 +32,7 @@ defmodule Explorer.Chain do |
|
|
|
Block, |
|
|
|
Block, |
|
|
|
BlockCountCache, |
|
|
|
BlockCountCache, |
|
|
|
BlockNumberCache, |
|
|
|
BlockNumberCache, |
|
|
|
|
|
|
|
BlocksCache, |
|
|
|
Data, |
|
|
|
Data, |
|
|
|
DecompiledSmartContract, |
|
|
|
DecompiledSmartContract, |
|
|
|
Hash, |
|
|
|
Hash, |
|
|
@ -1148,9 +1149,14 @@ defmodule Explorer.Chain do |
|
|
|
@spec list_blocks([paging_options | necessity_by_association_option]) :: [Block.t()] |
|
|
|
@spec list_blocks([paging_options | necessity_by_association_option]) :: [Block.t()] |
|
|
|
def list_blocks(options \\ []) when is_list(options) do |
|
|
|
def list_blocks(options \\ []) when is_list(options) do |
|
|
|
necessity_by_association = Keyword.get(options, :necessity_by_association, %{}) |
|
|
|
necessity_by_association = Keyword.get(options, :necessity_by_association, %{}) |
|
|
|
paging_options = Keyword.get(options, :paging_options, @default_paging_options) |
|
|
|
paging_options = Keyword.get(options, :paging_options) || @default_paging_options |
|
|
|
block_type = Keyword.get(options, :block_type, "Block") |
|
|
|
block_type = Keyword.get(options, :block_type, "Block") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if block_type == "Block" && !paging_options.key && BlocksCache.enough_elements?(paging_options.page_size) do |
|
|
|
|
|
|
|
cached_blocks = BlocksCache.blocks() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Enum.slice(cached_blocks, 0, paging_options.page_size) |
|
|
|
|
|
|
|
else |
|
|
|
Block |
|
|
|
Block |
|
|
|
|> Block.block_type_filter(block_type) |
|
|
|
|> Block.block_type_filter(block_type) |
|
|
|
|> page_blocks(paging_options) |
|
|
|
|> page_blocks(paging_options) |
|
|
@ -1159,6 +1165,7 @@ defmodule Explorer.Chain do |
|
|
|
|> join_associations(necessity_by_association) |
|
|
|
|> join_associations(necessity_by_association) |
|
|
|
|> Repo.all() |
|
|
|
|> Repo.all() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|
Map `block_number`s to their `t:Explorer.Chain.Block.t/0` `hash` `t:Explorer.Chain.Hash.Full.t/0`. |
|
|
|
Map `block_number`s to their `t:Explorer.Chain.Block.t/0` `hash` `t:Explorer.Chain.Hash.Full.t/0`. |
|
|
|