@@ -99,6 +99,13 @@ impl MainNodeClient for Box<DynClient<L2>> {
9999 }
100100}
101101
102+ pub fn get_param ( log_params : & [ ethabi:: LogParam ] , name : & str ) -> Option < ethabi:: Token > {
103+ log_params
104+ . iter ( )
105+ . find ( |param| param. name == name)
106+ . map ( |param| param. value . clone ( ) )
107+ }
108+
102109/// Verifies the L1 transaction against the database and the SL.
103110#[ derive( Debug ) ]
104111struct L1TransactionVerifier {
@@ -172,22 +179,15 @@ impl L1TransactionVerifier {
172179 return None ;
173180 }
174181 let parsed_log = event
175- . parse_log_whole ( ethabi:: RawLog {
176- topics : log. topics ,
177- data : log. data . 0 ,
178- } )
182+ . parse_log_whole ( log. into ( ) )
183+
179184 . ok ( ) ?; // Skip logs that are of different event type
180185
181- let block_number_from_log = parsed_log. params . iter ( ) . find_map ( |param| {
182- ( param. name == "batchNumber" )
183- . then_some ( param. value . clone ( ) )
186+ let block_number_from_log = get_param ( & parsed_log. params , "batchNumber" )
184187 . and_then ( ethabi:: Token :: into_uint)
185- . and_then ( |batch_number_from_log| {
186- u32:: try_from ( batch_number_from_log)
187- . ok ( )
188- . map ( L1BatchNumber )
189- } )
190- } ) . expect ( "Missing expected `batchNumber` parameter in `BlockCommit` event log" ) ;
188+ . and_then ( |x| u32:: try_from ( x) . ok ( ) )
189+ . map ( L1BatchNumber )
190+ . expect ( "Missing expected `batchNumber` parameter in `BlockCommit` event log" ) ;
191191
192192 if block_number_from_log != batch_number {
193193 tracing:: warn!(
@@ -197,17 +197,13 @@ impl L1TransactionVerifier {
197197 return None ;
198198 }
199199
200- let batch_hash = parsed_log. params . iter ( ) . find_map ( |param| {
201- ( param. name == "batchHash" )
202- . then_some ( param. value . clone ( ) )
200+ let batch_hash = get_param ( & parsed_log. params , "batchHash" )
203201 . and_then ( ethabi:: Token :: into_fixed_bytes) . map ( |bytes| H256 :: from_slice ( & bytes) )
204- } ) . expect ( "Missing expected `batchHash` parameter in `BlockCommit` event log" ) ;
202+ . expect ( "Missing expected `batchHash` parameter in `BlockCommit` event log" ) ;
205203
206- let commitment = parsed_log. params . into_iter ( ) . find_map ( |param| {
207- ( param. name == "commitment" )
208- . then_some ( param. value )
204+ let commitment = get_param ( & parsed_log. params , "commitment" )
209205 . and_then ( ethabi:: Token :: into_fixed_bytes) . map ( |bytes| H256 :: from_slice ( & bytes) )
210- } ) . expect ( "Missing expected `commitment` parameter in `BlockCommit` event log" ) ;
206+ . expect ( "Missing expected `commitment` parameter in `BlockCommit` event log" ) ;
211207
212208 tracing:: debug!(
213209 "Commit transaction {commit_tx_hash:?} has `BlockCommit` event log with batch_hash={batch_hash:?} and commitment={commitment:?}"
@@ -284,28 +280,21 @@ impl L1TransactionVerifier {
284280 return None ;
285281 }
286282 let parsed_log = event
287- . parse_log_whole ( ethabi:: RawLog {
288- topics : log. topics ,
289- data : log. data . 0 ,
290- } )
283+ . parse_log_whole ( log. into ( ) )
291284 . ok ( ) ?; // Skip logs that are of different event type
292285
293- let block_number_from = parsed_log. params . iter ( ) . find_map ( |param| {
294- ( param. name == "previousLastVerifiedBatch" )
295- . then_some ( param. value . clone ( ) )
286+ let block_number_from = get_param ( & parsed_log. params , "previousLastVerifiedBatch" )
296287 . and_then ( ethabi:: Token :: into_uint)
297288 . and_then ( |batch_number_from_log| {
298289 u32:: try_from ( batch_number_from_log) . ok ( )
299290 } )
300- } ) . expect ( "Missing expected `previousLastVerifiedBatch` parameter in `BlocksVerification` event log" ) ;
301- let block_number_to = parsed_log. params . iter ( ) . find_map ( |param| {
302- ( param. name == "currentLastVerifiedBatch" )
303- . then_some ( param. value . clone ( ) )
291+ . expect ( "Missing expected `previousLastVerifiedBatch` parameter in `BlocksVerification` event log" ) ;
292+ let block_number_to = get_param ( & parsed_log. params , "currentLastVerifiedBatch" )
304293 . and_then ( ethabi:: Token :: into_uint)
305294 . and_then ( |batch_number_to_log| {
306295 u32:: try_from ( batch_number_to_log) . ok ( )
307296 } )
308- } ) . expect ( "Missing expected `currentLastVerifiedBatch` parameter in `BlocksVerification` event log" ) ;
297+ . expect ( "Missing expected `currentLastVerifiedBatch` parameter in `BlocksVerification` event log" ) ;
309298 Some ( (
310299 block_number_from,
311300 block_number_to,
@@ -392,22 +381,18 @@ impl L1TransactionVerifier {
392381 return None ;
393382 }
394383 let parsed_log = event
395- . parse_log_whole ( ethabi:: RawLog {
396- topics : log. topics ,
397- data : log. data . 0 ,
398- } )
384+ . parse_log_whole ( log. into ( ) )
385+
399386 . ok ( ) ?; // Skip logs that are of different event type
400387
401- let block_number_from_log = parsed_log. params . iter ( ) . find_map ( |param| {
402- ( param. name == "batchNumber" )
403- . then_some ( param. value . clone ( ) )
388+ let block_number_from_log = get_param ( & parsed_log. params , "batchNumber" )
404389 . and_then ( ethabi:: Token :: into_uint)
405390 . and_then ( |batch_number_from_log| {
406391 u32:: try_from ( batch_number_from_log)
407392 . ok ( )
408393 . map ( L1BatchNumber )
409394 } )
410- } ) . expect ( "Missing expected `batchNumber` parameter in `BlockExecution` event log" ) ;
395+ . expect ( "Missing expected `batchNumber` parameter in `BlockExecution` event log" ) ;
411396
412397 if block_number_from_log != batch_number {
413398 tracing:: debug!(
@@ -417,17 +402,15 @@ impl L1TransactionVerifier {
417402 return None ;
418403 }
419404
420- let batch_hash = parsed_log. params . iter ( ) . find_map ( |param| {
421- ( param. name == "batchHash" )
422- . then_some ( param. value . clone ( ) )
423- . and_then ( ethabi:: Token :: into_fixed_bytes) . map ( |bytes| H256 :: from_slice ( & bytes) )
424- } ) . expect ( "Missing expected `batchHash` parameter in `BlockExecution` event log" ) ;
405+ let batch_hash = get_param ( & parsed_log. params , "batchHash" )
406+ . and_then ( ethabi:: Token :: into_fixed_bytes)
407+ . map ( |bytes| H256 :: from_slice ( & bytes) )
408+ . expect ( "Missing expected `batchHash` parameter in `BlockExecution` event log" ) ;
425409
426- let commitment = parsed_log. params . into_iter ( ) . find_map ( |param| {
427- ( param. name == "commitment" )
428- . then_some ( param. value )
429- . and_then ( ethabi:: Token :: into_fixed_bytes) . map ( |bytes| H256 :: from_slice ( & bytes) )
430- } ) . expect ( "Missing expected `commitment` parameter in `BlockExecution` event log" ) ;
410+ let commitment = get_param ( & parsed_log. params , "commitment" )
411+ . and_then ( ethabi:: Token :: into_fixed_bytes)
412+ . map ( |bytes| H256 :: from_slice ( & bytes) )
413+ . expect ( "Missing expected `commitment` parameter in `BlockExecution` event log" ) ;
431414
432415 tracing:: debug!(
433416 "Execute transaction {execute_tx_hash:?} has `BlockExecution` event log with batch_hash={batch_hash:?} and commitment={commitment:?}"
0 commit comments