11//! Handler that can get current storage related data
22
33use crate :: mem:: Backend ;
4- use alloy_network:: AnyRpcBlock ;
4+ use alloy_network:: { AnyRpcBlock , Network } ;
55use alloy_primitives:: B256 ;
66use anvil_core:: eth:: block:: Block ;
77use foundry_primitives:: { FoundryNetwork , FoundryReceiptEnvelope } ;
@@ -13,30 +13,20 @@ use std::{fmt, sync::Arc};
1313/// fetch ethereum storage related data
1414// TODO(mattsee): once we have multiple Backend types, this should be turned into a trait
1515#[ derive( Clone ) ]
16- pub struct StorageInfo {
17- backend : Arc < Backend < FoundryNetwork > > ,
16+ pub struct StorageInfo < N : Network > {
17+ backend : Arc < Backend < N > > ,
1818}
1919
20- impl StorageInfo {
21- pub ( crate ) fn new ( backend : Arc < Backend < FoundryNetwork > > ) -> Self {
20+ impl < N : Network > StorageInfo < N > {
21+ pub ( crate ) fn new ( backend : Arc < Backend < N > > ) -> Self {
2222 Self { backend }
2323 }
2424
25- /// Returns the receipts of the current block
26- pub fn current_receipts ( & self ) -> Option < Vec < FoundryReceiptEnvelope > > {
27- self . backend . mined_receipts ( self . backend . best_hash ( ) )
28- }
29-
3025 /// Returns the current block
3126 pub fn current_block ( & self ) -> Option < Block > {
3227 self . backend . get_block ( self . backend . best_number ( ) )
3328 }
3429
35- /// Returns the receipts of the block with the given hash
36- pub fn receipts ( & self , hash : B256 ) -> Option < Vec < FoundryReceiptEnvelope > > {
37- self . backend . mined_receipts ( hash)
38- }
39-
4030 /// Returns the block with the given hash
4131 pub fn block ( & self , hash : B256 ) -> Option < Block > {
4232 self . backend . get_block_by_hash ( hash)
@@ -49,7 +39,21 @@ impl StorageInfo {
4939 }
5040}
5141
52- impl fmt:: Debug for StorageInfo {
42+ impl StorageInfo < FoundryNetwork > {
43+ // TODO: receipts methods require N::ReceiptEnvelope generalization
44+
45+ /// Returns the receipts of the current block
46+ pub fn current_receipts ( & self ) -> Option < Vec < FoundryReceiptEnvelope > > {
47+ self . backend . mined_receipts ( self . backend . best_hash ( ) )
48+ }
49+
50+ /// Returns the receipts of the block with the given hash
51+ pub fn receipts ( & self , hash : B256 ) -> Option < Vec < FoundryReceiptEnvelope > > {
52+ self . backend . mined_receipts ( hash)
53+ }
54+ }
55+
56+ impl < N : Network > fmt:: Debug for StorageInfo < N > {
5357 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
5458 f. debug_struct ( "StorageInfo" ) . finish_non_exhaustive ( )
5559 }
0 commit comments