Skip to content

Commit bce4e03

Browse files
starknet_api: add and use StateRoots::EMPTY
1 parent 85cd564 commit bce4e03

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

crates/central_systest_blobs/src/cende_blob_regression_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl BlobFactory {
427427
}
428428

429429
fn current_state_roots(&self) -> StateRoots {
430-
self.blocks.last().map(|block| block.state_roots).unwrap_or_default()
430+
self.blocks.last().map(|block| block.state_roots).unwrap_or(StateRoots::EMPTY)
431431
}
432432

433433
// =====================

crates/starknet_api/src/hash.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,26 @@ impl HashOutput {
9191
}
9292

9393
/// Output of committing a state.
94-
#[derive(Clone, Copy, Debug, Deserialize, Default, PartialEq, Eq, Hash, Serialize)]
94+
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Hash, Serialize)]
9595
pub struct StateRoots {
9696
pub contracts_trie_root_hash: HashOutput,
9797
pub classes_trie_root_hash: HashOutput,
9898
}
9999

100+
impl Default for StateRoots {
101+
fn default() -> Self {
102+
Self::EMPTY
103+
}
104+
}
105+
100106
impl StateRoots {
107+
pub const EMPTY: Self = Self {
108+
contracts_trie_root_hash: HashOutput::ROOT_OF_EMPTY_TREE,
109+
classes_trie_root_hash: HashOutput::ROOT_OF_EMPTY_TREE,
110+
};
111+
101112
pub fn global_root(&self) -> GlobalRoot {
102-
if self.contracts_trie_root_hash == HashOutput::ROOT_OF_EMPTY_TREE
103-
&& self.classes_trie_root_hash == HashOutput::ROOT_OF_EMPTY_TREE
104-
{
113+
if self == &Self::EMPTY {
105114
return GlobalRoot::ROOT_OF_EMPTY_STATE;
106115
}
107116
GlobalRoot(Poseidon::hash_array(&[

0 commit comments

Comments
 (0)