1- use std:: { cmp:: Ordering , fmt:: Debug } ;
1+ use std:: { cmp:: Ordering , fmt:: Debug , marker :: PhantomData , sync :: Arc } ;
22
3- use edr_block_api:: Block as _ ;
3+ use edr_block_api:: Block ;
44use edr_block_builder_api:: {
55 BlockBuilder , BlockBuilderCreationError , BlockFinalizeError , BlockInputs ,
6- BlockTransactionError , Blockchain , PrecompileFn , WrapDatabaseRef ,
6+ BlockTransactionError , Blockchain , ExecutionResult , PrecompileFn , WrapDatabaseRef ,
77} ;
88pub use edr_block_builder_api:: { BuiltBlockAndState , BuiltBlockAndStateWithMetadata } ;
99use edr_block_header:: {
@@ -19,7 +19,7 @@ use edr_chain_spec_evm::{
1919} ;
2020use edr_database_components:: DatabaseComponents ;
2121use edr_mem_pool:: { MemPool , OrderedTransaction } ;
22- use edr_primitives:: { Address , HashMap , HashSet } ;
22+ use edr_primitives:: { Address , HashMap , HashSet , B256 } ;
2323use edr_signer:: SignatureError ;
2424use edr_state_api:: { DynState , StateError } ;
2525use serde:: { Deserialize , Serialize } ;
@@ -89,6 +89,71 @@ pub enum MineBlockError<
8989 MissingPrevrandao ,
9090}
9191
92+ /// Helper type for a chain-specific [`MineBlockResultWithMetadata`].
93+ pub type MineBlockResultWithMetadataForChainSpec < ChainSpecT , InspectorDataT = ( ) > =
94+ MineBlockResultWithMetadata <
95+ Arc < <ChainSpecT as BlockChainSpec >:: Block > ,
96+ <ChainSpecT as ChainSpec >:: HaltReason ,
97+ <ChainSpecT as ChainSpec >:: SignedTransaction ,
98+ InspectorDataT ,
99+ > ;
100+
101+ #[ derive( Debug ) ]
102+ pub struct MineBlockResultWithMetadata <
103+ BlockT ,
104+ HaltReasonT : HaltReasonTrait ,
105+ SignedTransactionT ,
106+ InspectorDataT = ( ) ,
107+ > {
108+ /// Mined block
109+ pub block : BlockT ,
110+ /// The set of precompile addresses that were available during execution.
111+ pub precompile_addresses : HashSet < Address > ,
112+ /// Data collected from inspectors during mining, indexed by transaction
113+ /// number in the block.
114+ pub transaction_inspector_data : Vec < InspectorDataT > ,
115+ /// Transaction results
116+ pub transaction_results : Vec < ExecutionResult < HaltReasonT > > ,
117+ phantom : PhantomData < SignedTransactionT > ,
118+ }
119+
120+ impl < BlockT , HaltReasonT : HaltReasonTrait , SignedTransactionT , InspectorDataT >
121+ MineBlockResultWithMetadata < BlockT , HaltReasonT , SignedTransactionT , InspectorDataT >
122+ {
123+ /// Constructs a new instance.
124+ pub fn new (
125+ block : BlockT ,
126+ precompile_addresses : HashSet < Address > ,
127+ transaction_inspector_data : Vec < InspectorDataT > ,
128+ transaction_results : Vec < ExecutionResult < HaltReasonT > > ,
129+ ) -> Self {
130+ Self {
131+ block,
132+ precompile_addresses,
133+ transaction_inspector_data,
134+ transaction_results,
135+ phantom : PhantomData ,
136+ }
137+ }
138+ }
139+
140+ impl <
141+ BlockT : Block < SignedTransactionT > ,
142+ HaltReasonT : HaltReasonTrait ,
143+ InspectorDataT ,
144+ SignedTransactionT : ExecutableTransaction ,
145+ > MineBlockResultWithMetadata < BlockT , HaltReasonT , SignedTransactionT , InspectorDataT >
146+ {
147+ /// Whether the block contains a transaction with the given hash.
148+ pub fn has_transaction ( & self , transaction_hash : & B256 ) -> bool {
149+ self . block
150+ . transactions ( )
151+ . iter ( )
152+ . any ( |tx| * tx. transaction_hash ( ) == * transaction_hash)
153+ }
154+ }
155+
156+ #[ derive( Debug ) ]
92157pub struct MineBlockResultAndStateWithMetadata <
93158 BlockT ,
94159 HaltReasonT : HaltReasonTrait ,
@@ -141,7 +206,7 @@ pub fn mine_block<ChainSpecT, BlockchainErrorT, InspectorT>(
141206 min_gas_price : u128 ,
142207 mine_ordering : MineOrdering ,
143208 reward : u128 ,
144- mut inspector : Option < InspectorT > ,
209+ mut inspector : Option < & mut InspectorT > ,
145210 custom_precompiles : & HashMap < Address , PrecompileFn > ,
146211) -> Result <
147212 MineBlockResultAndStateWithMetadata <
@@ -406,7 +471,6 @@ pub fn mine_block_with_single_transaction<
406471 ChainSpecT : BlockChainSpec ,
407472 BlockchainErrorT : std:: error:: Error ,
408473 InspectorT ,
409- InspectorResultT ,
410474> (
411475 blockchain : & dyn Blockchain <
412476 ChainSpecT :: Receipt ,
0 commit comments