mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: simplify examples recipient matching (#7385)
This commit is contained in:
@ -28,7 +28,6 @@ use reth::{
|
||||
transaction_pool::TransactionPool,
|
||||
};
|
||||
use reth_node_ethereum::node::EthereumNode;
|
||||
use std::collections::HashSet;
|
||||
|
||||
fn main() {
|
||||
Cli::<RethCliTxpoolExt>::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::<HashSet<_>>();
|
||||
|
||||
// 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<Address>,
|
||||
}
|
||||
|
||||
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)]
|
||||
|
||||
@ -23,7 +23,6 @@ use reth::{
|
||||
transaction_pool::TransactionPool,
|
||||
};
|
||||
use reth_node_ethereum::node::EthereumNode;
|
||||
use std::collections::HashSet;
|
||||
|
||||
fn main() {
|
||||
Cli::<RethCliTxpoolExt>::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::<HashSet<_>>();
|
||||
|
||||
// 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<Address>,
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user