-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(starknet_patricia,starknet_committer): stop using custom Compile…
…dClassHash type
- Loading branch information
1 parent
6743852
commit f7b5c78
Showing
17 changed files
with
73 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
crates/starknet_committer_and_os_cli/src/committer_cli/parse_input/cast.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod errors; | ||
pub mod inner_node; | ||
pub mod leaf; | ||
pub mod leaf_impls; |
50 changes: 50 additions & 0 deletions
50
crates/starknet_patricia/src/patricia_merkle_tree/node_data/leaf_impls.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::collections::HashMap; | ||
|
||
use starknet_api::core::CompiledClassHash; | ||
use starknet_types_core::felt::Felt; | ||
|
||
use crate::patricia_merkle_tree::node_data::errors::LeafResult; | ||
use crate::patricia_merkle_tree::node_data::leaf::Leaf; | ||
use crate::storage::db_object::{DBObject, Deserializable}; | ||
use crate::storage::errors::DeserializationError; | ||
use crate::storage::storage_trait::{StarknetPrefix, StorageValue}; | ||
|
||
impl Deserializable for CompiledClassHash { | ||
fn deserialize(value: &StorageValue) -> Result<Self, DeserializationError> { | ||
let json_str = std::str::from_utf8(&value.0)?; | ||
let map: HashMap<String, String> = serde_json::from_str(json_str)?; | ||
let hash_as_hex = map | ||
.get("compiled_class_hash") | ||
.ok_or(DeserializationError::NonExistingKey("compiled_class_hash".to_string()))?; | ||
Ok(Self(Felt::from_hex(hash_as_hex)?)) | ||
} | ||
|
||
fn prefix() -> Vec<u8> { | ||
StarknetPrefix::CompiledClassLeaf.to_storage_prefix() | ||
} | ||
} | ||
|
||
impl DBObject for CompiledClassHash { | ||
/// Creates a json string describing the leaf and casts it into a byte vector. | ||
fn serialize(&self) -> StorageValue { | ||
let json_string = format!(r#"{{"compiled_class_hash": "{}"}}"#, self.0.to_hex_string()); | ||
StorageValue(json_string.into_bytes()) | ||
} | ||
|
||
fn get_prefix(&self) -> Vec<u8> { | ||
StarknetPrefix::CompiledClassLeaf.to_storage_prefix() | ||
} | ||
} | ||
|
||
impl Leaf for CompiledClassHash { | ||
type Input = Self; | ||
type Output = (); | ||
|
||
fn is_empty(&self) -> bool { | ||
self.0 == Felt::ZERO | ||
} | ||
|
||
async fn create(input: Self::Input) -> LeafResult<(Self, Self::Output)> { | ||
Ok((input, ())) | ||
} | ||
} |