Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(providers): tracing, access list methods for TempProvider #32

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 121 additions & 2 deletions crates/providers/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use crate::utils::{self, EstimatorFunction};
use alloy_primitives::{Address, BlockHash, Bytes, StorageKey, StorageValue, TxHash, U256, U64};
use alloy_rpc_client::{ClientBuilder, RpcClient};
use alloy_rpc_types::{
Block, BlockId, BlockNumberOrTag, FeeHistory, Filter, Log, RpcBlockHash, SyncStatus,
Transaction, TransactionReceipt, TransactionRequest,
trace::{GethDebugTracingOptions, GethTrace, LocalizedTransactionTrace},
AccessListWithGasUsed, Block, BlockId, BlockNumberOrTag, CallRequest,
EIP1186AccountProofResponse, FeeHistory, Filter, Log, RpcBlockHash, SyncStatus, Transaction,
TransactionReceipt, TransactionRequest,
};
use alloy_transport::{BoxTransport, Transport, TransportErrorKind, TransportResult};
use alloy_transport_http::Http;
Expand Down Expand Up @@ -201,6 +203,46 @@ pub trait TempProvider: Send + Sync {
async fn set_code(&self, address: Address, code: &'static str) -> TransportResult<()>
where
Self: Sync;

async fn get_proof(
&self,
address: Address,
keys: Vec<StorageKey>,
block: Option<BlockId>,
) -> TransportResult<EIP1186AccountProofResponse>
where
Self: Sync;

async fn create_access_list(
&self,
request: CallRequest,
block: Option<BlockId>,
) -> TransportResult<AccessListWithGasUsed>
where
Self: Sync;

/// Parity trace transaction.
async fn trace_transaction(
&self,
hash: TxHash,
) -> TransportResult<Vec<LocalizedTransactionTrace>>
where
Self: Sync;

async fn debug_trace_transaction(
&self,
hash: TxHash,
trace_options: GethDebugTracingOptions,
) -> TransportResult<GethTrace>
where
Self: Sync;

async fn trace_block(
&self,
block: BlockNumberOrTag,
) -> TransportResult<Vec<LocalizedTransactionTrace>>
where
Self: Sync;
}

impl<T: Transport + Clone + Send + Sync> Provider<T> {
Expand Down Expand Up @@ -554,6 +596,83 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
Ok((max_fee_per_gas, max_priority_fee_per_gas))
}

async fn get_proof(
&self,
address: Address,
keys: Vec<StorageKey>,
block: Option<BlockId>,
) -> TransportResult<EIP1186AccountProofResponse>
where
Self: Sync,
{
self.inner
.prepare(
"eth_getProof",
Cow::<(Address, Vec<StorageKey>, BlockId)>::Owned((
address,
keys,
block.unwrap_or(BlockNumberOrTag::Latest.into()),
)),
)
.await
}

async fn create_access_list(
&self,
request: CallRequest,
block: Option<BlockId>,
) -> TransportResult<AccessListWithGasUsed>
where
Self: Sync,
{
self.inner
.prepare(
"eth_createAccessList",
Cow::<(CallRequest, BlockId)>::Owned((
request,
block.unwrap_or(BlockNumberOrTag::Latest.into()),
)),
)
.await
}

/// Parity trace transaction.
async fn trace_transaction(
&self,
hash: TxHash,
) -> TransportResult<Vec<LocalizedTransactionTrace>>
where
Self: Sync,
{
self.inner.prepare("trace_transaction", Cow::<Vec<TxHash>>::Owned(vec![hash])).await
}

async fn debug_trace_transaction(
&self,
hash: TxHash,
trace_options: GethDebugTracingOptions,
) -> TransportResult<GethTrace>
where
Self: Sync,
{
self.inner
.prepare(
"debug_traceTransaction",
Cow::<(TxHash, GethDebugTracingOptions)>::Owned((hash, trace_options)),
)
.await
}

async fn trace_block(
&self,
block: BlockNumberOrTag,
) -> TransportResult<Vec<LocalizedTransactionTrace>>
where
Self: Sync,
{
self.inner.prepare("trace_block", Cow::<BlockNumberOrTag>::Owned(block)).await
}

#[cfg(feature = "anvil")]
async fn set_code(&self, address: Address, code: &'static str) -> TransportResult<()>
where
Expand Down