11use std:: sync:: LazyLock ;
22
3- use starknet_api:: core:: { ClassHash , ContractAddress , Nonce , PATRICIA_KEY_UPPER_BOUND } ;
3+ use starknet_api:: core:: { ClassHash , Nonce , PATRICIA_KEY_UPPER_BOUND } ;
44use starknet_api:: hash:: HashOutput ;
5+ use starknet_patricia:: db_layout:: TrieType ;
56use starknet_patricia:: patricia_merkle_tree:: node_data:: errors:: LeafResult ;
67use starknet_patricia:: patricia_merkle_tree:: node_data:: leaf:: Leaf ;
78use starknet_patricia_storage:: db_object:: {
@@ -16,7 +17,6 @@ use starknet_types_core::felt::Felt;
1617use crate :: block_committer:: input:: StarknetStorageValue ;
1718use crate :: patricia_merkle_tree:: leaf:: leaf_impl:: ContractState ;
1819use crate :: patricia_merkle_tree:: types:: CompiledClassHash ;
19-
2020// Wrap the leaves types so that we can implement the [DBObject] trait differently in index
2121// layout.
2222#[ derive(
@@ -46,23 +46,13 @@ static CONTRACTS_TREE_PREFIX: LazyLock<[u8; 32]> =
4646static CLASSES_TREE_PREFIX : LazyLock < [ u8 ; 32 ] > =
4747 LazyLock :: new ( || ( * FIRST_AVAILABLE_PREFIX_FELT + Felt :: ONE ) . to_bytes_be ( ) ) ;
4848
49- // TODO(Ariel): Delete this enum and use `CommitmentType` instead.
50- #[ derive( Debug , PartialEq ) ]
51- pub enum TrieType {
52- ContractsTrie ,
53- ClassesTrie ,
54- StorageTrie ( ContractAddress ) ,
55- }
56-
57- impl TrieType {
58- fn db_prefix ( & self ) -> DbKeyPrefix {
59- match self {
60- Self :: ContractsTrie => DbKeyPrefix :: new ( ( & CONTRACTS_TREE_PREFIX [ ..] ) . into ( ) ) ,
61- Self :: ClassesTrie => DbKeyPrefix :: new ( ( & CLASSES_TREE_PREFIX [ ..] ) . into ( ) ) ,
62- Self :: StorageTrie ( contract_address) => {
63- let prefix = contract_address. to_bytes_be ( ) . to_vec ( ) ;
64- DbKeyPrefix :: new ( prefix. into ( ) )
65- }
49+ fn trie_type_db_prefix ( trie_type : & TrieType ) -> DbKeyPrefix {
50+ match trie_type {
51+ TrieType :: ContractsTrie => DbKeyPrefix :: new ( ( & CONTRACTS_TREE_PREFIX [ ..] ) . into ( ) ) ,
52+ TrieType :: ClassesTrie => DbKeyPrefix :: new ( ( & CLASSES_TREE_PREFIX [ ..] ) . into ( ) ) ,
53+ TrieType :: StorageTrie ( contract_address) => {
54+ let prefix = contract_address. to_bytes_be ( ) . to_vec ( ) ;
55+ DbKeyPrefix :: new ( prefix. into ( ) )
6656 }
6757 }
6858}
@@ -73,7 +63,7 @@ macro_rules! impl_has_static_prefix_for_index_layouts {
7363 impl HasStaticPrefix for $ty {
7464 type KeyContext = TrieType ;
7565 fn get_static_prefix( key_context: & Self :: KeyContext ) -> DbKeyPrefix {
76- key_context . db_prefix ( )
66+ trie_type_db_prefix ( key_context )
7767 }
7868 }
7969 ) *
0 commit comments