diff --git a/noir-projects/noir-contracts/contracts/docs_example_contract/src/main.nr b/noir-projects/noir-contracts/contracts/docs_example_contract/src/main.nr index 9893521cebf5..4f0af33be71a 100644 --- a/noir-projects/noir-contracts/contracts/docs_example_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/docs_example_contract/src/main.nr @@ -16,13 +16,56 @@ contract DocsExample { use dep::aztec::prelude::{ AztecAddress, FunctionSelector, NoteHeader, NoteGetterOptions, NoteViewerOptions, PrivateContext, Map, PublicMutable, PublicImmutable, PrivateMutable, PrivateImmutable, - PrivateSet, SharedImmutable + PrivateSet, SharedImmutable, Storable, StorableNote }; use dep::aztec::{note::note_getter_options::Comparator, context::{PublicContext, Context}}; // how to import methods from other files/folders within your workspace use crate::options::create_account_card_getter_options; use crate::types::{card_note::{CardNote, CARD_NOTE_LEN}, leader::Leader}; + struct StorageFields { + leader: Storable, + legendary_card: Storable, + profiles: Storable, + set: Storable, + private_immutable: Storable, + shared_immutable: Storable, + minters: Storable, + public_immutable: Storable, + } + + struct StorageNotes { + card_note: StorableNote, + } + + struct StorageLayout { + fields: StorageFields, + notes: StorageNotes, + } + + #[abi(event)] + struct WithdrawalProcessed { + who: AztecAddress, + amount: u64, + } + + #[abi(storage)] + global STORAGE_LAYOUT = StorageLayout { + fields: StorageFields { + leader: Storable { slot: 1, typ: "PublicMutable" }, + legendary_card: Storable { slot: 3, typ: "PrivateMutable" }, + profiles: Storable { slot: 4, typ: "Map>" }, + set: Storable { slot: 5, typ: "PrivateSet" }, + private_immutable: Storable { slot: 6, typ: "PrivateImmutable" }, + shared_immutable: Storable { slot: 7, typ: "SharedImmutable" }, + minters: Storable { slot: 8, typ: "Map" }, + public_immutable: Storable { slot: 9, typ: "PublicImmutable" } + }, + notes: StorageNotes { + card_note: StorableNote { id: 2, typ: "CardNote" } + } + }; + #[aztec(storage)] struct Storage { // Shows how to create a custom struct in PublicMutable diff --git a/noir/noir-repo/aztec_macros/src/transforms/storage.rs b/noir/noir-repo/aztec_macros/src/transforms/storage.rs index c07506cca2db..df865f3d3a26 100644 --- a/noir/noir-repo/aztec_macros/src/transforms/storage.rs +++ b/noir/noir-repo/aztec_macros/src/transforms/storage.rs @@ -399,45 +399,5 @@ pub fn generate_storage_layout( storable_fields.join(",\n") ); - let field_constructors = definition - .fields - .iter() - .flat_map(|field| { - generate_storage_field_constructor(field, slot_zero.clone()) - .map(|expression| (field.0.clone(), expression)) - }) - .collect(); - - let storage_constructor_statement = make_statement(StatementKind::Expression(expression( - ExpressionKind::constructor((chained_path!(storage_struct_name), field_constructors)), - ))); - - let init = NoirFunction::normal(FunctionDefinition::normal( - &ident("init"), - &vec![], - &[( - ident("context"), - make_type(UnresolvedTypeData::Named( - chained_dep!("aztec", "context", "Context"), - vec![], - true, - )), - )], - &BlockExpression(vec![storage_constructor_statement]), - &[], - &return_type(chained_path!("Self")), - )); - - let storage_impl = TypeImpl { - object_type: UnresolvedType { - typ: UnresolvedTypeData::Named(chained_path!(storage_struct_name), vec![], true), - span: Some(Span::default()), - }, - type_span: Span::default(), - generics: vec![], - methods: vec![(init, Span::default())], - }; - module.impls.push(storage_impl); - Ok(()) }