From 3af24383ced5f95b2babfdeb7d1572a8a9c28967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bene=C5=A1?= Date: Tue, 2 Jan 2024 17:52:11 +0100 Subject: [PATCH] fix: event macro (#3784) Fixes #3655 --- noir/aztec_macros/src/lib.rs | 11 ++++++++--- .../src/contracts/test_contract/src/main.nr | 16 ++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/noir/aztec_macros/src/lib.rs b/noir/aztec_macros/src/lib.rs index a8e8419e671..56cd700790b 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,18 @@ fn generate_selector_impl(structure: &NoirStruct) -> TypeImpl { vec![expression(ExpressionKind::Literal(Literal::Str(SIGNATURE_PLACEHOLDER.to_string())))], )))]); + // 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![]))); + 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..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,11 @@ 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; // docs:end:unencrypted_import @@ -32,18 +37,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), }