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 <me@gakonst.com>
This commit is contained in:
Eugene 2022-01-15 12:41:43 +02:00 committed by GitHub
parent 77dcccb7ba
commit cbfbd6052c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 4 deletions

View File

@ -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");

View File

@ -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<T: Into<TypedTransaction> + Send + Sync>(
&self,
req: Vec<(T, Vec<TraceType>)>,
block: Option<BlockNumber>,
) -> Result<Vec<BlockTrace>, 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,

View File

@ -797,6 +797,19 @@ impl<P: JsonRpcClient> Middleware for Provider<P> {
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<T: Into<TypedTransaction> + Send + Sync>(
&self,
req: Vec<(T, Vec<TraceType>)>,
block: Option<BlockNumber>,
) -> Result<Vec<BlockTrace>, ProviderError> {
let req: Vec<(TypedTransaction, Vec<TraceType>)> =
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::<H160>()
.unwrap())
.value(U256::from(10000000000000000u128)),
vec![TraceType::StateDiff],
),
(
TransactionRequest::new()
.from(
"0x0000000000000000000000000000000000000001"
.parse::<H160>()
.unwrap(),
)
.to("0x0000000000000000000000000000000000000002"
.parse::<H160>()
.unwrap())
.value(U256::from(10000000000000000u128)),
vec![TraceType::StateDiff],
),
],
None,
)
.await
.unwrap();
dbg!(traces);
}
}