@@ -30,6 +30,7 @@ use crate::core::{
3030use crate :: crypto:: utils:: HashChain ;
3131use crate :: data_availability:: L1DataAvailabilityMode ;
3232use crate :: execution_resources:: GasVector ;
33+ use crate :: hash:: StarkHash ;
3334use crate :: state:: ThinStateDiff ;
3435use crate :: transaction:: fields:: { Fee , TransactionSignature } ;
3536use crate :: transaction:: { Event , MessageToL1 , TransactionExecutionStatus , TransactionHash } ;
@@ -165,6 +166,29 @@ impl TryFrom<&BlockHeader> for Option<BlockHeaderCommitments> {
165166 }
166167}
167168
169+ /// Hash of [`PartialBlockHashComponents`] only (no state root or parent hash).
170+ #[ derive( Clone , Copy , Debug , Default , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
171+ pub struct PartialBlockHash ( pub StarkHash ) ;
172+
173+ impl PartialBlockHash {
174+ const GLOBAL_ROOT_FOR_PARTIAL_BLOCK_HASH : GlobalRoot = GlobalRoot ( Felt :: ZERO ) ;
175+ const PARENT_HASH_FOR_PARTIAL_BLOCK_HASH : BlockHash = BlockHash ( Felt :: ZERO ) ;
176+
177+ /// Hash of [`PartialBlockHashComponents`].
178+ /// Uses the same formula as [`calculate_block_hash`] with the fixed constants above for the
179+ /// state root and parent hash..
180+ fn from_partial_block_hash_components (
181+ partial_block_hash_components : & PartialBlockHashComponents ,
182+ ) -> StarknetApiResult < Self > {
183+ let block_hash = calculate_block_hash (
184+ partial_block_hash_components,
185+ Self :: GLOBAL_ROOT_FOR_PARTIAL_BLOCK_HASH ,
186+ Self :: PARENT_HASH_FOR_PARTIAL_BLOCK_HASH ,
187+ ) ?;
188+ Ok ( PartialBlockHash ( block_hash. 0 ) )
189+ }
190+ }
191+
168192#[ derive( Clone , Debug , Default , PartialEq , Eq , Serialize , Deserialize ) ]
169193/// All information required to calculate a block hash except for the state root and the parent
170194/// block hash.
0 commit comments