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