diff --git a/aztec/src/state_vars.nr b/aztec/src/state_vars.nr index d8213bb1..177844f7 100644 --- a/aztec/src/state_vars.nr +++ b/aztec/src/state_vars.nr @@ -4,3 +4,4 @@ mod public_state; mod set; mod singleton; mod stable_public_state; +mod storage; diff --git a/aztec/src/state_vars/immutable_singleton.nr b/aztec/src/state_vars/immutable_singleton.nr index 187feca4..9d595081 100644 --- a/aztec/src/state_vars/immutable_singleton.nr +++ b/aztec/src/state_vars/immutable_singleton.nr @@ -16,6 +16,7 @@ use crate::note::{ note_viewer_options::NoteViewerOptions, }; use crate::oracle::notes::check_nullifier_exists; +use crate::state_vars::storage::Storage; // docs:start:struct struct ImmutableSingleton { @@ -24,6 +25,8 @@ struct ImmutableSingleton { } // docs:end:struct +impl Storage for ImmutableSingleton {} + impl ImmutableSingleton { // docs:start:new pub fn new( diff --git a/aztec/src/state_vars/map.nr b/aztec/src/state_vars/map.nr index fefa84ea..7e38552e 100644 --- a/aztec/src/state_vars/map.nr +++ b/aztec/src/state_vars/map.nr @@ -4,6 +4,7 @@ use dep::protocol_types::{ hash::pedersen_hash, traits::{ToField} }; +use crate::state_vars::storage::Storage; // docs:start:map struct Map { @@ -13,6 +14,8 @@ struct Map { } // docs:end:map +impl Storage for Map {} + impl Map { // docs:start:new pub fn new( diff --git a/aztec/src/state_vars/public_state.nr b/aztec/src/state_vars/public_state.nr index 9309f3d9..081b0d59 100644 --- a/aztec/src/state_vars/public_state.nr +++ b/aztec/src/state_vars/public_state.nr @@ -3,6 +3,7 @@ use crate::oracle::storage::storage_read; use crate::oracle::storage::storage_write; use dep::std::option::Option; use dep::protocol_types::traits::{Deserialize, Serialize}; +use crate::state_vars::storage::Storage; // docs:start:public_state_struct struct PublicState { @@ -11,6 +12,8 @@ struct PublicState { } // docs:end:public_state_struct +impl Storage for PublicState {} + impl PublicState { // docs:start:public_state_struct_new pub fn new( diff --git a/aztec/src/state_vars/set.nr b/aztec/src/state_vars/set.nr index 03e53b33..6813a9fa 100644 --- a/aztec/src/state_vars/set.nr +++ b/aztec/src/state_vars/set.nr @@ -15,6 +15,7 @@ use crate::note::{ note_viewer_options::NoteViewerOptions, utils::compute_note_hash_for_consumption, }; +use crate::state_vars::storage::Storage; // docs:start:struct struct Set { @@ -23,6 +24,8 @@ struct Set { } // docs:end:struct +impl Storage for Set {} + impl Set { // docs:start:new pub fn new( @@ -36,7 +39,6 @@ impl Set { } } // docs:end:new - // docs:start:insert pub fn insert(self, note: &mut Note, diff --git a/aztec/src/state_vars/singleton.nr b/aztec/src/state_vars/singleton.nr index 19b4e91b..47d8aef5 100644 --- a/aztec/src/state_vars/singleton.nr +++ b/aztec/src/state_vars/singleton.nr @@ -20,6 +20,7 @@ use crate::oracle::{ nullifier_key::get_nullifier_secret_key, notes::check_nullifier_exists, }; +use crate::state_vars::storage::Storage; // docs:start:struct struct Singleton { @@ -28,6 +29,8 @@ struct Singleton { } // docs:end:struct +impl Storage for Singleton {} + impl Singleton { // docs:start:new pub fn new( diff --git a/aztec/src/state_vars/stable_public_state.nr b/aztec/src/state_vars/stable_public_state.nr index 013f059a..af4925f4 100644 --- a/aztec/src/state_vars/stable_public_state.nr +++ b/aztec/src/state_vars/stable_public_state.nr @@ -5,12 +5,15 @@ use crate::oracle::{ use crate::history::public_value_inclusion::prove_public_value_inclusion; use dep::std::option::Option; use dep::protocol_types::traits::{Deserialize, Serialize}; +use crate::state_vars::storage::Storage; struct StablePublicState{ context: Context, storage_slot: Field, } +impl Storage for StablePublicState {} + impl StablePublicState { pub fn new( // Note: Passing the contexts to new(...) just to have an interface compatible with a Map. diff --git a/aztec/src/state_vars/storage.nr b/aztec/src/state_vars/storage.nr new file mode 100644 index 00000000..5f28b55f --- /dev/null +++ b/aztec/src/state_vars/storage.nr @@ -0,0 +1,8 @@ +use crate::context::{Context}; +use dep::protocol_types::traits::{Deserialize, Serialize}; + +trait Storage where T: Serialize + Deserialize { + fn get_storage_slot(self) -> Field { + self.storage_slot + } +}