Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunkar committed Mar 25, 2024
1 parent 27dc703 commit e63b35c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<N1, N2, N3, N4, N5, N6, N7, N8> {
leader: Storable<N1>,
legendary_card: Storable<N2>,
profiles: Storable<N3>,
set: Storable<N4>,
private_immutable: Storable<N5>,
shared_immutable: Storable<N6>,
minters: Storable<N7>,
public_immutable: Storable<N8>,
}

struct StorageNotes<N1> {
card_note: StorableNote<N1>,
}

struct StorageLayout<N1, N2, N3, N4, N5, N6, N7, N8, M1> {
fields: StorageFields<N1, N2, N3, N4, N5, N6, N7, N8>,
notes: StorageNotes<M1>,
}

#[abi(event)]
struct WithdrawalProcessed {
who: AztecAddress,
amount: u64,
}

#[abi(storage)]
global STORAGE_LAYOUT = StorageLayout {
fields: StorageFields {
leader: Storable { slot: 1, typ: "PublicMutable<Leader>" },
legendary_card: Storable { slot: 3, typ: "PrivateMutable<CardNote>" },
profiles: Storable { slot: 4, typ: "Map<AztecAddress, PrivateMutable<CardNote>>" },
set: Storable { slot: 5, typ: "PrivateSet<CardNote>" },
private_immutable: Storable { slot: 6, typ: "PrivateImmutable<CardNote>" },
shared_immutable: Storable { slot: 7, typ: "SharedImmutable<Leader>" },
minters: Storable { slot: 8, typ: "Map<AztecAddress, PublicMutable<bool>" },
public_immutable: Storable { slot: 9, typ: "PublicImmutable<Leader>" }
},
notes: StorageNotes {
card_note: StorableNote { id: 2, typ: "CardNote" }
}
};

#[aztec(storage)]
struct Storage {
// Shows how to create a custom struct in PublicMutable
Expand Down
40 changes: 0 additions & 40 deletions noir/noir-repo/aztec_macros/src/transforms/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

0 comments on commit e63b35c

Please sign in to comment.