add logs pagination stub

pull/2366/head
Ayrat Badykov 5 years ago
parent 50d57ee839
commit 60cd238adf
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 18
      apps/explorer/lib/explorer/etherscan/logs.ex

@ -38,6 +38,8 @@ defmodule Explorer.Etherscan.Logs do
:type :type
] ]
@default_paging_options %{block_number: nil, transaction_index: nil}
@doc """ @doc """
Gets a list of logs that meet the criteria in a given filter map. Gets a list of logs that meet the criteria in a given filter map.
@ -68,7 +70,9 @@ defmodule Explorer.Etherscan.Logs do
""" """
@spec list_logs(map()) :: [map()] @spec list_logs(map()) :: [map()]
def list_logs(%{address_hash: address_hash} = filter) when not is_nil(address_hash) do def list_logs(filter, paging_options \\ @default_paging_options)
def list_logs(%{address_hash: address_hash} = filter, paging_options) when not is_nil(address_hash) do
prepared_filter = Map.merge(@base_filter, filter) prepared_filter = Map.merge(@base_filter, filter)
logs_query = where_topic_match(Log, prepared_filter) logs_query = where_topic_match(Log, prepared_filter)
@ -134,14 +138,16 @@ defmodule Explorer.Etherscan.Logs do
) )
end end
Repo.all(query_with_consensus) query_with_consensus
|> page_logs(paging_options)
|> Repo.all()
end end
# Since address_hash was not present, we know that a # Since address_hash was not present, we know that a
# topic filter has been applied, so we use a different # topic filter has been applied, so we use a different
# query that is optimized for a logs filter over an # query that is optimized for a logs filter over an
# address_hash # address_hash
def list_logs(filter) do def list_logs(filter, paging_options) do
prepared_filter = Map.merge(@base_filter, filter) prepared_filter = Map.merge(@base_filter, filter)
logs_query = where_topic_match(Log, prepared_filter) logs_query = where_topic_match(Log, prepared_filter)
@ -182,7 +188,9 @@ defmodule Explorer.Etherscan.Logs do
select_merge: map(log, ^@log_fields) select_merge: map(log, ^@log_fields)
) )
Repo.all(query_with_block_transaction_data) query_with_block_transaction_data
|> page_logs(paging_options)
|> Repo.all()
end end
@topics [ @topics [
@ -231,4 +239,6 @@ defmodule Explorer.Etherscan.Logs do
end end
defp where_multiple_topics_match(query, _, _, _), do: query defp where_multiple_topics_match(query, _, _, _), do: query
defp page_logs(query, _paging_options), do: query
end end

Loading…
Cancel
Save