@ -28,6 +28,7 @@ defmodule Indexer.Fetcher.Optimism.Deposit do
:safe_block ,
:safe_block ,
:optimism_portal ,
:optimism_portal ,
:json_rpc_named_arguments ,
:json_rpc_named_arguments ,
:transaction_type ,
mode : :catch_up ,
mode : :catch_up ,
filter_id : nil ,
filter_id : nil ,
check_interval : nil
check_interval : nil
@ -78,7 +79,7 @@ defmodule Indexer.Fetcher.Optimism.Deposit do
{ last_l1_block_number , last_l1_tx_hash } <- get_last_l1_item ( ) ,
{ last_l1_block_number , last_l1_tx_hash } <- get_last_l1_item ( ) ,
{ :ok , last_l1_tx } <- Optimism . get_transaction_by_hash ( last_l1_tx_hash , json_rpc_named_arguments ) ,
{ :ok , last_l1_tx } <- Optimism . get_transaction_by_hash ( last_l1_tx_hash , json_rpc_named_arguments ) ,
{ :l1_tx_not_found , false } <- { :l1_tx_not_found , ! is_nil ( last_l1_tx_hash ) && is_nil ( last_l1_tx ) } ,
{ :l1_tx_not_found , false } <- { :l1_tx_not_found , ! is_nil ( last_l1_tx_hash ) && is_nil ( last_l1_tx ) } ,
{ safe_block , _ } = Optimism . get_safe_block ( json_rpc_named_arguments ) ,
{ safe_block , _ } = Helper . get_safe_block ( json_rpc_named_arguments ) ,
{ :start_block_l1_valid , true } <-
{ :start_block_l1_valid , true } <-
{ :start_block_l1_valid ,
{ :start_block_l1_valid ,
( start_block_l1 <= last_l1_block_number || last_l1_block_number == 0 ) && start_block_l1 <= safe_block } do
( start_block_l1 <= last_l1_block_number || last_l1_block_number == 0 ) && start_block_l1 <= safe_block } do
@ -97,7 +98,8 @@ defmodule Indexer.Fetcher.Optimism.Deposit do
safe_block : safe_block ,
safe_block : safe_block ,
optimism_portal : optimism_portal ,
optimism_portal : optimism_portal ,
json_rpc_named_arguments : json_rpc_named_arguments ,
json_rpc_named_arguments : json_rpc_named_arguments ,
batch_size : parse_integer ( env [ :batch_size ] ) || @batch_size
batch_size : parse_integer ( env [ :batch_size ] ) || @batch_size ,
transaction_type : env [ :transaction_type ]
} }
} }
else
else
{ :start_block_l1_valid , false } ->
{ :start_block_l1_valid , false } ->
@ -144,7 +146,8 @@ defmodule Indexer.Fetcher.Optimism.Deposit do
optimism_portal : optimism_portal ,
optimism_portal : optimism_portal ,
json_rpc_named_arguments : json_rpc_named_arguments ,
json_rpc_named_arguments : json_rpc_named_arguments ,
mode : :catch_up ,
mode : :catch_up ,
batch_size : batch_size
batch_size : batch_size ,
transaction_type : transaction_type
} = state
} = state
) do
) do
to_block = min ( from_block + batch_size , safe_block )
to_block = min ( from_block + batch_size , safe_block )
@ -160,7 +163,7 @@ defmodule Indexer.Fetcher.Optimism.Deposit do
3
3
) } ,
) } ,
_ = Helper . log_blocks_chunk_handling ( from_block , to_block , start_block , safe_block , nil , :L1 ) ,
_ = Helper . log_blocks_chunk_handling ( from_block , to_block , start_block , safe_block , nil , :L1 ) ,
deposits = events_to_deposits ( logs , json_rpc_named_arguments ) ,
deposits = events_to_deposits ( logs , transaction_type , json_rpc_named_arguments ) ,
{ :import , { :ok , _imported } } <-
{ :import , { :ok , _imported } } <-
{ :import , Chain . import ( %{ optimism_deposits : %{ params : deposits } , timeout : :infinity } ) } do
{ :import , Chain . import ( %{ optimism_deposits : %{ params : deposits } , timeout : :infinity } ) } do
Publisher . broadcast ( %{ optimism_deposits : deposits } , :realtime )
Publisher . broadcast ( %{ optimism_deposits : deposits } , :realtime )
@ -212,7 +215,8 @@ defmodule Indexer.Fetcher.Optimism.Deposit do
optimism_portal : optimism_portal ,
optimism_portal : optimism_portal ,
json_rpc_named_arguments : json_rpc_named_arguments ,
json_rpc_named_arguments : json_rpc_named_arguments ,
batch_size : batch_size ,
batch_size : batch_size ,
mode : :catch_up
mode : :catch_up ,
transaction_type : transaction_type
} = state
} = state
) do
) do
with { :check_interval , { :ok , check_interval , new_safe } } <-
with { :check_interval , { :ok , check_interval , new_safe } } <-
@ -236,7 +240,7 @@ defmodule Indexer.Fetcher.Optimism.Deposit do
@transaction_deposited_event ,
@transaction_deposited_event ,
json_rpc_named_arguments
json_rpc_named_arguments
) do
) do
handle_new_logs ( logs , json_rpc_named_arguments )
handle_new_logs ( logs , transaction_type , json_rpc_named_arguments )
Process . send ( self ( ) , :fetch , [ ] )
Process . send ( self ( ) , :fetch , [ ] )
{ :noreply , %{ state | mode : :realtime , filter_id : filter_id , check_interval : check_interval } }
{ :noreply , %{ state | mode : :realtime , filter_id : filter_id , check_interval : check_interval } }
else
else
@ -268,12 +272,13 @@ defmodule Indexer.Fetcher.Optimism.Deposit do
json_rpc_named_arguments : json_rpc_named_arguments ,
json_rpc_named_arguments : json_rpc_named_arguments ,
mode : :realtime ,
mode : :realtime ,
filter_id : filter_id ,
filter_id : filter_id ,
check_interval : check_interval
check_interval : check_interval ,
transaction_type : transaction_type
} = state
} = state
) do
) do
case get_filter_changes ( filter_id , json_rpc_named_arguments ) do
case get_filter_changes ( filter_id , json_rpc_named_arguments ) do
{ :ok , logs } ->
{ :ok , logs } ->
handle_new_logs ( logs , json_rpc_named_arguments )
handle_new_logs ( logs , transaction_type , json_rpc_named_arguments )
Process . send_after ( self ( ) , :fetch , check_interval )
Process . send_after ( self ( ) , :fetch , check_interval )
{ :noreply , state }
{ :noreply , state }
@ -342,7 +347,7 @@ defmodule Indexer.Fetcher.Optimism.Deposit do
:ok
:ok
end
end
defp handle_new_logs ( logs , json_rpc_named_arguments ) do
defp handle_new_logs ( logs , transaction_type , json_rpc_named_arguments ) do
{ reorgs , logs_to_parse , min_block , max_block , cnt } =
{ reorgs , logs_to_parse , min_block , max_block , cnt } =
logs
logs
|> Enum . reduce ( { MapSet . new ( ) , [ ] , nil , 0 , 0 } , fn
|> Enum . reduce ( { MapSet . new ( ) , [ ] , nil , 0 , 0 } , fn
@ -362,7 +367,7 @@ defmodule Indexer.Fetcher.Optimism.Deposit do
handle_reorgs ( reorgs )
handle_reorgs ( reorgs )
unless Enum . empty? ( logs_to_parse ) do
unless Enum . empty? ( logs_to_parse ) do
deposits = events_to_deposits ( logs_to_parse , json_rpc_named_arguments )
deposits = events_to_deposits ( logs_to_parse , transaction_type , json_rpc_named_arguments )
{ :ok , _imported } = Chain . import ( %{ optimism_deposits : %{ params : deposits } , timeout : :infinity } )
{ :ok , _imported } = Chain . import ( %{ optimism_deposits : %{ params : deposits } , timeout : :infinity } )
Publisher . broadcast ( %{ optimism_deposits : deposits } , :realtime )
Publisher . broadcast ( %{ optimism_deposits : deposits } , :realtime )
@ -378,7 +383,7 @@ defmodule Indexer.Fetcher.Optimism.Deposit do
end
end
end
end
defp events_to_deposits ( logs , json_rpc_named_arguments ) do
defp events_to_deposits ( logs , transaction_type , json_rpc_named_arguments ) do
timestamps =
timestamps =
logs
logs
|> Enum . reduce ( MapSet . new ( ) , fn %{ " blockNumber " = > block_number_quantity } , acc ->
|> Enum . reduce ( MapSet . new ( ) , fn %{ " blockNumber " = > block_number_quantity } , acc ->
@ -399,7 +404,7 @@ defmodule Indexer.Fetcher.Optimism.Deposit do
%{ }
%{ }
end
end
Enum . map ( logs , & event_to_deposit ( &1 , timestamps ) )
Enum . map ( logs , & event_to_deposit ( &1 , timestamps , transaction_type ) )
end
end
defp event_to_deposit (
defp event_to_deposit (
@ -411,7 +416,8 @@ defmodule Indexer.Fetcher.Optimism.Deposit do
" topics " = > [ _ , @address_prefix <> from_stripped , @address_prefix <> to_stripped , _ ] ,
" topics " = > [ _ , @address_prefix <> from_stripped , @address_prefix <> to_stripped , _ ] ,
" data " = > opaque_data
" data " = > opaque_data
} ,
} ,
timestamps
timestamps ,
transaction_type
) do
) do
{ _ , prefixed_block_hash } = ( String . pad_leading ( " " , 64 , " 0 " ) <> stripped_block_hash ) |> String . split_at ( - 64 )
{ _ , prefixed_block_hash } = ( String . pad_leading ( " " , 64 , " 0 " ) <> stripped_block_hash ) |> String . split_at ( - 64 )
{ _ , prefixed_log_index } = ( String . pad_leading ( " " , 64 , " 0 " ) <> stripped_log_index ) |> String . split_at ( - 64 )
{ _ , prefixed_log_index } = ( String . pad_leading ( " " , 64 , " 0 " ) <> stripped_log_index ) |> String . split_at ( - 64 )
@ -452,8 +458,17 @@ defmodule Indexer.Fetcher.Optimism.Deposit do
encoding : :hex
encoding : :hex
)
)
transaction_type =
transaction_type
|> Integer . to_string ( 16 )
|> String . downcase ( )
l2_tx_hash =
l2_tx_hash =
" 0x " <> ( " 7e #{ rlp_encoded } " |> Base . decode16! ( case : :mixed ) |> ExKeccak . hash_256 ( ) |> Base . encode16 ( case : :lower ) )
" 0x " <>
( ( transaction_type <> " #{ rlp_encoded } " )
|> Base . decode16! ( case : :mixed )
|> ExKeccak . hash_256 ( )
|> Base . encode16 ( case : :lower ) )
block_number = quantity_to_integer ( block_number_quantity )
block_number = quantity_to_integer ( block_number_quantity )