From 8482b3dfb6d977706293076ceb4f3da0dbcae9df Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 2 Jan 2024 13:07:55 +0000 Subject: [PATCH 1/2] macro fix --- noir/aztec_macros/src/lib.rs | 10 +++++++--- .../src/contracts/test_contract/src/main.nr | 12 ++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/noir/aztec_macros/src/lib.rs b/noir/aztec_macros/src/lib.rs index a8e8419e671..4b1ef36b704 100644 --- a/noir/aztec_macros/src/lib.rs +++ b/noir/aztec_macros/src/lib.rs @@ -486,8 +486,8 @@ const SIGNATURE_PLACEHOLDER: &str = "SIGNATURE_PLACEHOLDER"; /// Inserts the following code: /// ```noir /// impl SomeStruct { -/// fn selector() -> Field { -/// aztec::oracle::compute_selector::compute_selector("SIGNATURE_PLACEHOLDER") +/// fn selector() -> FunctionSelector { +/// aztec::selector::compute_selector("SIGNATURE_PLACEHOLDER") /// } /// } /// ``` @@ -503,13 +503,17 @@ fn generate_selector_impl(structure: &NoirStruct) -> TypeImpl { vec![expression(ExpressionKind::Literal(Literal::Str(SIGNATURE_PLACEHOLDER.to_string())))], )))]); + // Define `FunctionSelector` return type + let return_type_path = chained_path!("protocol_types", "abis", "function_selector", "FunctionSelector"); + let return_type = FunctionReturnType::Ty(make_type(UnresolvedTypeData::Named(return_type_path, vec![]))); + let mut selector_fn_def = FunctionDefinition::normal( &ident("selector"), &vec![], &[], &selector_fun_body, &[], - &FunctionReturnType::Ty(make_type(UnresolvedTypeData::FieldElement)), + &return_type, ); selector_fn_def.visibility = FunctionVisibility::Public; diff --git a/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr index c9af85309b0..52710385844 100644 --- a/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr @@ -6,6 +6,7 @@ contract Test { AztecAddress, EthAddress, }; + use dep::protocol_types; // docs:start:unencrypted_import use dep::aztec::log::emit_unencrypted_log; // docs:end:unencrypted_import @@ -32,18 +33,17 @@ contract Test { use dep::token_portal_content_hash_lib::{get_mint_private_content_hash, get_mint_public_content_hash}; use dep::field_note::field_note::{FieldNote, FieldNoteMethods, FIELD_NOTE_LEN}; - // TODO(benesjan) https://github.com/AztecProtocol/aztec-packages/issues/3655 - // #[event] - // struct ExampleEvent { - // value: Field, - // } + #[event] + struct ExampleEvent { + value: Field, + } struct Storage { example_constant: ImmutableSingleton, } impl Storage { - fn init(context: Context) -> pub Self { + fn init(context: Context) -> Self { Storage { example_constant: ImmutableSingleton::new(context, 1, FieldNoteMethods), } From a807a33a06c1acb1cbbb7409f08af26f5391aad2 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 2 Jan 2024 13:16:57 +0000 Subject: [PATCH 2/2] comments --- noir/aztec_macros/src/lib.rs | 1 + .../noir-contracts/src/contracts/test_contract/src/main.nr | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/noir/aztec_macros/src/lib.rs b/noir/aztec_macros/src/lib.rs index 4b1ef36b704..56cd700790b 100644 --- a/noir/aztec_macros/src/lib.rs +++ b/noir/aztec_macros/src/lib.rs @@ -504,6 +504,7 @@ fn generate_selector_impl(structure: &NoirStruct) -> TypeImpl { )))]); // Define `FunctionSelector` return type + // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3590): Make this point to aztec-nr once the issue is fixed. let return_type_path = chained_path!("protocol_types", "abis", "function_selector", "FunctionSelector"); let return_type = FunctionReturnType::Ty(make_type(UnresolvedTypeData::Named(return_type_path, vec![]))); diff --git a/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr index 52710385844..ed5a753c26b 100644 --- a/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr @@ -6,6 +6,10 @@ contract Test { AztecAddress, EthAddress, }; + // The following import is here in order to make the event macro work because the macro doesn't add the import. + // It doesn't add the import because in the future we will re-export all the types via aztec-nr and aztec-nr is + // already auto-imported by the macros. + // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3590): Remove this once the issue is fixed. use dep::protocol_types; // docs:start:unencrypted_import use dep::aztec::log::emit_unencrypted_log;