diff --git a/examples/custom-inspector/src/main.rs b/examples/custom-inspector/src/main.rs index e8c9c52463..b0fe4fbb8c 100644 --- a/examples/custom-inspector/src/main.rs +++ b/examples/custom-inspector/src/main.rs @@ -28,7 +28,6 @@ use reth::{ transaction_pool::TransactionPool, }; use reth_node_ethereum::node::EthereumNode; -use std::collections::HashSet; fn main() { Cli::::parse() @@ -37,8 +36,6 @@ fn main() { let NodeHandle { mut node, node_exit_future } = builder.node(EthereumNode::default()).launch().await?; - let recipients = args.recipients.iter().copied().collect::>(); - // create a new subscription to pending transactions let mut pending_transactions = node.pool.new_pending_pool_transactions_listener(); @@ -54,42 +51,45 @@ fn main() { let tx = event.transaction; println!("Transaction received: {tx:?}"); - if recipients.is_empty() { - // convert the pool transaction - let call_request = - transaction_to_call_request(tx.to_recovered_transaction()); + if let Some(recipient) = tx.to() { + if args.is_match(&recipient) { + // convert the pool transaction + let call_request = + transaction_to_call_request(tx.to_recovered_transaction()); - let result = eth_api - .spawn_with_call_at( - call_request, - BlockNumberOrTag::Latest.into(), - EvmOverrides::default(), - move |db, env| { - let mut dummy_inspector = DummyInspector::default(); - { - // configure the evm with the custom inspector - let mut evm = Evm::builder() - .with_db(db) - .with_external_context(&mut dummy_inspector) - .with_env_with_handler_cfg(env) - .append_handler_register(inspector_handle_register) - .build(); - // execute the transaction on a blocking task and await the - // inspector result - let _ = evm.transact()?; - } - Ok(dummy_inspector) - }, - ) - .await; + let result = eth_api + .spawn_with_call_at( + call_request, + BlockNumberOrTag::Latest.into(), + EvmOverrides::default(), + move |db, env| { + let mut dummy_inspector = DummyInspector::default(); + { + // configure the evm with the custom inspector + let mut evm = Evm::builder() + .with_db(db) + .with_external_context(&mut dummy_inspector) + .with_env_with_handler_cfg(env) + .append_handler_register(inspector_handle_register) + .build(); + // execute the transaction on a blocking task and await + // the + // inspector result + let _ = evm.transact()?; + } + Ok(dummy_inspector) + }, + ) + .await; - if let Ok(ret_val) = result { - let hash = tx.hash(); - println!( - "Inspector result for transaction {}: \n {}", - hash, - ret_val.ret_val.join("\n") - ); + if let Ok(ret_val) = result { + let hash = tx.hash(); + println!( + "Inspector result for transaction {}: \n {}", + hash, + ret_val.ret_val.join("\n") + ); + } } } } @@ -108,6 +108,13 @@ struct RethCliTxpoolExt { pub recipients: Vec
, } +impl RethCliTxpoolExt { + /// Check if the recipient is in the list of recipients to trace. + pub fn is_match(&self, recipient: &Address) -> bool { + self.recipients.is_empty() || self.recipients.contains(recipient) + } +} + /// A dummy inspector that logs the opcodes and their corresponding program counter for a /// transaction #[derive(Default, Debug, Clone)] diff --git a/examples/trace-transaction-cli/src/main.rs b/examples/trace-transaction-cli/src/main.rs index 7a4fde6af5..ab72c27200 100644 --- a/examples/trace-transaction-cli/src/main.rs +++ b/examples/trace-transaction-cli/src/main.rs @@ -23,7 +23,6 @@ use reth::{ transaction_pool::TransactionPool, }; use reth_node_ethereum::node::EthereumNode; -use std::collections::HashSet; fn main() { Cli::::parse() @@ -32,8 +31,6 @@ fn main() { let NodeHandle { mut node, node_exit_future } = builder.node(EthereumNode::default()).launch().await?; - let recipients = args.recipients.iter().copied().collect::>(); - // create a new subscription to pending transactions let mut pending_transactions = node.pool.new_pending_pool_transactions_listener(); @@ -48,8 +45,8 @@ fn main() { let tx = event.transaction; println!("Transaction received: {tx:?}"); - if let Some(tx_recipient_address) = tx.to() { - if recipients.is_empty() || recipients.contains(&tx_recipient_address) { + if let Some(recipient) = tx.to() { + if args.is_match(&recipient) { // trace the transaction with `trace_call` let callrequest = transaction_to_call_request(tx.to_recovered_transaction()); @@ -76,3 +73,10 @@ struct RethCliTxpoolExt { #[arg(long, value_delimiter = ',')] pub recipients: Vec
, } + +impl RethCliTxpoolExt { + /// Check if the recipient is in the list of recipients to trace. + pub fn is_match(&self, recipient: &Address) -> bool { + self.recipients.is_empty() || self.recipients.contains(recipient) + } +}