-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add example for trace_call_many and debug_trace_call_many (#163)
* feat: add example for trace_call_many and debug_trace_call_many * update examples to use Reth bindings, ignore from CI, add to examples list --------- Co-authored-by: Adegbite Ademola Kelvin <adegbiteademolakelvin@Adegbites-MacBook-Pro.local> Co-authored-by: zerosnacks <zerosnacks@protonmail.com>
- Loading branch information
1 parent
85f3dd1
commit e650725
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//! Example of how to trace a transaction using `debug_trace_call_many`. | ||
use alloy::{ | ||
network::TransactionBuilder, | ||
node_bindings::Reth, | ||
primitives::{address, U256}, | ||
providers::{ext::DebugApi, ProviderBuilder}, | ||
rpc::types::{ | ||
trace::geth::GethDebugTracingCallOptions, Bundle, StateContext, TransactionRequest, | ||
}, | ||
}; | ||
use eyre::Result; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
// Spin up a local Reth node. | ||
// Ensure `reth` is available in $PATH. | ||
let reth = Reth::new().dev().disable_discovery().instance(1).spawn(); | ||
let provider = ProviderBuilder::new().on_http(reth.endpoint().parse()?); | ||
|
||
// Get users, these have allocated balances in the dev genesis block. | ||
let alice = address!("70997970C51812dc3A010C7d01b50e0d17dc79C8"); | ||
let bob = address!("3C44CdDdB6a900fa2b585dd299e03d12FA4293BC"); | ||
let charlie = address!("90F79bf6EB2c4f870365E785982E1f101E93b906"); | ||
let dan = address!("15d34AAf54267DB7D7c367839AAf71A00a2C6A65"); | ||
|
||
// Define transactions | ||
let tx1 = | ||
TransactionRequest::default().with_from(alice).with_to(bob).with_value(U256::from(150)); | ||
let tx2 = | ||
TransactionRequest::default().with_from(charlie).with_to(dan).with_value(U256::from(250)); | ||
|
||
// Create the bundle of transactions. | ||
let bundles = vec![Bundle { transactions: vec![tx1, tx2], block_override: None }]; | ||
|
||
// Define the State context and trace option | ||
let state_context = StateContext::default(); | ||
let trace_options = GethDebugTracingCallOptions::default(); | ||
|
||
//Call `debug_trace_call_many` on the provider. | ||
let result = provider.debug_trace_call_many(bundles, state_context, trace_options).await; | ||
|
||
match result { | ||
Ok(traces) => { | ||
println!("Traces:\n{:?}", traces); | ||
} | ||
Err(err) => { | ||
println!("Error tracing transactions: {:?}", err); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! Example of how to trace a transaction using `trace_call_many`. | ||
use alloy::{ | ||
network::TransactionBuilder, | ||
node_bindings::Reth, | ||
primitives::{address, U256}, | ||
providers::{ext::TraceApi, ProviderBuilder}, | ||
rpc::types::{trace::parity::TraceType, TransactionRequest}, | ||
}; | ||
|
||
use eyre::{Ok, Result}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
// Spin up a local Reth node. | ||
// Ensure `reth` is available in $PATH. | ||
let reth = Reth::new().dev().disable_discovery().instance(1).spawn(); | ||
let provider = ProviderBuilder::new().on_http(reth.endpoint().parse()?); | ||
|
||
// Get users, these have allocated balances in the dev genesis block. | ||
let alice = address!("70997970C51812dc3A010C7d01b50e0d17dc79C8"); | ||
let bob = address!("3C44CdDdB6a900fa2b585dd299e03d12FA4293BC"); | ||
let charlie = address!("90F79bf6EB2c4f870365E785982E1f101E93b906"); | ||
let dan = address!("15d34AAf54267DB7D7c367839AAf71A00a2C6A65"); | ||
|
||
// Define transactions | ||
let tx1 = | ||
TransactionRequest::default().with_from(alice).with_to(bob).with_value(U256::from(150)); | ||
let tx2 = | ||
TransactionRequest::default().with_from(charlie).with_to(dan).with_value(U256::from(250)); | ||
|
||
// Define the trace for the trace_list | ||
let trace_type: &[TraceType] = &[TraceType::Trace]; | ||
|
||
// Trace the transaction on top of the latest block. | ||
let trace_call_list = &[(tx1, trace_type), (tx2, trace_type)]; | ||
|
||
let result = provider.trace_call_many(trace_call_list).await?; | ||
|
||
// Print the trace results. | ||
for (index, trace_result) in result.iter().enumerate() { | ||
println!("Trace result for transaction {}: {:?}", index, trace_result); | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters