Skip to content

Commit

Permalink
feat: add tracing methods and a couple other ones (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evalir authored Nov 17, 2023
1 parent b32a3d8 commit 8b8ad07
Showing 1 changed file with 121 additions and 2 deletions.
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

0 comments on commit 8b8ad07

Please sign in to comment.