|
|
|
@ -38,6 +38,8 @@ defmodule Explorer.Etherscan.Logs do |
|
|
|
|
:type |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
@default_paging_options %{block_number: nil, transaction_index: nil} |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
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()] |
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
logs_query = where_topic_match(Log, prepared_filter) |
|
|
|
@ -134,14 +138,16 @@ defmodule Explorer.Etherscan.Logs do |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
Repo.all(query_with_consensus) |
|
|
|
|
query_with_consensus |
|
|
|
|
|> page_logs(paging_options) |
|
|
|
|
|> Repo.all() |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# Since address_hash was not present, we know that a |
|
|
|
|
# topic filter has been applied, so we use a different |
|
|
|
|
# query that is optimized for a logs filter over an |
|
|
|
|
# address_hash |
|
|
|
|
def list_logs(filter) do |
|
|
|
|
def list_logs(filter, paging_options) do |
|
|
|
|
prepared_filter = Map.merge(@base_filter, filter) |
|
|
|
|
|
|
|
|
|
logs_query = where_topic_match(Log, prepared_filter) |
|
|
|
@ -182,7 +188,9 @@ defmodule Explorer.Etherscan.Logs do |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
@topics [ |
|
|
|
@ -231,4 +239,6 @@ defmodule Explorer.Etherscan.Logs do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp where_multiple_topics_match(query, _, _, _), do: query |
|
|
|
|
|
|
|
|
|
defp page_logs(query, _paging_options), do: query |
|
|
|
|
end |
|
|
|
|