|
|
|
@ -66,6 +66,47 @@ defmodule Indexer.Fetcher.TransactionAction do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@impl true |
|
|
|
|
def handle_continue({opts, first_block, last_block}, _state) do |
|
|
|
|
logger_metadata = Logger.metadata() |
|
|
|
|
Logger.metadata(fetcher: :transaction_action) |
|
|
|
|
|
|
|
|
|
max_block_number = Chain.fetch_max_block_number() |
|
|
|
|
|
|
|
|
|
if last_block > max_block_number do |
|
|
|
|
Logger.warning( |
|
|
|
|
"Note, that the last block number (#{last_block}) provided to #{__MODULE__} exceeds max block number available in DB (#{max_block_number})." |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
supported_protocols = |
|
|
|
|
TransactionAction.supported_protocols() |
|
|
|
|
|> Enum.map(&Atom.to_string(&1)) |
|
|
|
|
|
|
|
|
|
protocols = |
|
|
|
|
opts |
|
|
|
|
|> Keyword.get(:reindex_protocols, "") |
|
|
|
|
|> String.trim() |
|
|
|
|
|> String.split(",") |
|
|
|
|
|> Enum.map(&String.trim(&1)) |
|
|
|
|
|> Enum.filter(&Enum.member?(supported_protocols, &1)) |
|
|
|
|
|
|
|
|
|
next_block = get_next_block(first_block, last_block, protocols) |
|
|
|
|
|
|
|
|
|
state = |
|
|
|
|
%__MODULE__{ |
|
|
|
|
first_block: first_block, |
|
|
|
|
next_block: next_block, |
|
|
|
|
last_block: last_block, |
|
|
|
|
protocols: protocols |
|
|
|
|
} |
|
|
|
|
|> run_fetch() |
|
|
|
|
|
|
|
|
|
Logger.reset_metadata(logger_metadata) |
|
|
|
|
|
|
|
|
|
{:noreply, state} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@impl GenServer |
|
|
|
|
def handle_info(:fetch, %__MODULE__{} = state) do |
|
|
|
|
task = Task.Supervisor.async_nolink(Indexer.Fetcher.TransactionAction.TaskSupervisor, fn -> task(state) end) |
|
|
|
@ -195,53 +236,14 @@ defmodule Indexer.Fetcher.TransactionAction do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp init_fetching(opts, first_block, last_block) do |
|
|
|
|
logger_metadata = Logger.metadata() |
|
|
|
|
Logger.metadata(fetcher: :transaction_action) |
|
|
|
|
|
|
|
|
|
first_block = parse_integer(first_block) |
|
|
|
|
last_block = parse_integer(last_block) |
|
|
|
|
|
|
|
|
|
return = |
|
|
|
|
if is_nil(first_block) or is_nil(last_block) or first_block <= 0 or last_block <= 0 or first_block > last_block do |
|
|
|
|
{:stop, "Correct block range must be provided to #{__MODULE__}."} |
|
|
|
|
else |
|
|
|
|
max_block_number = Chain.fetch_max_block_number() |
|
|
|
|
|
|
|
|
|
if last_block > max_block_number do |
|
|
|
|
Logger.warning( |
|
|
|
|
"Note, that the last block number (#{last_block}) provided to #{__MODULE__} exceeds max block number available in DB (#{max_block_number})." |
|
|
|
|
) |
|
|
|
|
{:ok, %{}, {:continue, {opts, first_block, last_block}}} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
supported_protocols = |
|
|
|
|
TransactionAction.supported_protocols() |
|
|
|
|
|> Enum.map(&Atom.to_string(&1)) |
|
|
|
|
|
|
|
|
|
protocols = |
|
|
|
|
opts |
|
|
|
|
|> Keyword.get(:reindex_protocols, "") |
|
|
|
|
|> String.trim() |
|
|
|
|
|> String.split(",") |
|
|
|
|
|> Enum.map(&String.trim(&1)) |
|
|
|
|
|> Enum.filter(&Enum.member?(supported_protocols, &1)) |
|
|
|
|
|
|
|
|
|
next_block = get_next_block(first_block, last_block, protocols) |
|
|
|
|
|
|
|
|
|
state = |
|
|
|
|
%__MODULE__{ |
|
|
|
|
first_block: first_block, |
|
|
|
|
next_block: next_block, |
|
|
|
|
last_block: last_block, |
|
|
|
|
protocols: protocols |
|
|
|
|
} |
|
|
|
|
|> run_fetch() |
|
|
|
|
|
|
|
|
|
{:ok, state} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
Logger.reset_metadata(logger_metadata) |
|
|
|
|
|
|
|
|
|
return |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp get_next_block(first_block, last_block, protocols) do |
|
|
|
|