From cbfbd6052c61dedabd05ccb4d2fe2730105d2534 Mon Sep 17 00:00:00 2001 From: Eugene Date: Sat, 15 Jan 2022 12:41:43 +0200 Subject: [PATCH] Implement trace_callMany (#792) * Implement trace_callMany * cargo fix and ignore flaky test for now * Update ethers-providers/src/provider.rs Co-authored-by: Georgios Konstantopoulos --- ethers-contract/tests/contract.rs | 8 ++--- ethers-providers/src/lib.rs | 8 +++++ ethers-providers/src/provider.rs | 51 +++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/ethers-contract/tests/contract.rs b/ethers-contract/tests/contract.rs index 8748af2b..17bfe11e 100644 --- a/ethers-contract/tests/contract.rs +++ b/ethers-contract/tests/contract.rs @@ -570,12 +570,12 @@ mod eth_tests { }; let derived_foo_bar = deriveeip712test_mod::FooBar { - foo: foo_bar.foo.clone(), - bar: foo_bar.bar.clone(), + foo: foo_bar.foo, + bar: foo_bar.bar, fizz: foo_bar.fizz.clone(), - buzz: foo_bar.buzz.clone(), + buzz: foo_bar.buzz, far: foo_bar.far.clone(), - out: foo_bar.out.clone(), + out: foo_bar.out, }; let sig = wallet.sign_typed_data(&foo_bar).await.expect("failed to sign typed data"); diff --git a/ethers-providers/src/lib.rs b/ethers-providers/src/lib.rs index 66547cec..696fa8c4 100644 --- a/ethers-providers/src/lib.rs +++ b/ethers-providers/src/lib.rs @@ -480,6 +480,14 @@ pub trait Middleware: Sync + Send + Debug { self.inner().trace_call(req, trace_type, block).await.map_err(FromErr::from) } + async fn trace_call_many + Send + Sync>( + &self, + req: Vec<(T, Vec)>, + block: Option, + ) -> Result, Self::Error> { + self.inner().trace_call_many(req, block).await.map_err(FromErr::from) + } + /// Traces a call to `eth_sendRawTransaction` without making the call, returning the traces async fn trace_raw_transaction( &self, diff --git a/ethers-providers/src/provider.rs b/ethers-providers/src/provider.rs index 8d2617cb..516986e8 100644 --- a/ethers-providers/src/provider.rs +++ b/ethers-providers/src/provider.rs @@ -797,6 +797,19 @@ impl Middleware for Provider

{ self.request("trace_call", [req, trace_type, block]).await } + /// Executes given calls and returns a number of possible traces for each call + async fn trace_call_many + Send + Sync>( + &self, + req: Vec<(T, Vec)>, + block: Option, + ) -> Result, ProviderError> { + let req: Vec<(TypedTransaction, Vec)> = + req.into_iter().map(|(tx, trace_type)| (tx.into(), trace_type)).collect(); + let req = utils::serialize(&req); + let block = utils::serialize(&block.unwrap_or(BlockNumber::Latest)); + self.request("trace_callMany", [req, block]).await + } + /// Traces a call to `eth_sendRawTransaction` without making the call, returning the traces async fn trace_raw_transaction( &self, @@ -1434,4 +1447,42 @@ mod tests { provider.fee_history(10u64, BlockNumber::Latest, &[10.0, 40.0]).await.unwrap(); dbg!(&history); } + + #[tokio::test] + #[ignore] + async fn test_trace_call_many() { + // TODO: Implement ErigonInstance, so it'd be possible to test this. + let provider = Provider::new(Ws::connect("ws://127.0.0.1:8545").await.unwrap()); + let traces = provider + .trace_call_many( + vec![ + ( + TransactionRequest::new() + .from(Address::zero()) + .to("0x0000000000000000000000000000000000000001" + .parse::() + .unwrap()) + .value(U256::from(10000000000000000u128)), + vec![TraceType::StateDiff], + ), + ( + TransactionRequest::new() + .from( + "0x0000000000000000000000000000000000000001" + .parse::() + .unwrap(), + ) + .to("0x0000000000000000000000000000000000000002" + .parse::() + .unwrap()) + .value(U256::from(10000000000000000u128)), + vec![TraceType::StateDiff], + ), + ], + None, + ) + .await + .unwrap(); + dbg!(traces); + } }