Skip to content

Commit 3af2438

Browse files
authored
fix: event macro (AztecProtocol#3784)
Fixes AztecProtocol#3655
1 parent c29e4ee commit 3af2438

File tree

2 files changed

+18
-9
lines changed
  • noir/aztec_macros/src
  • yarn-project/noir-contracts/src/contracts/test_contract/src

2 files changed

+18
-9
lines changed

noir/aztec_macros/src/lib.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ const SIGNATURE_PLACEHOLDER: &str = "SIGNATURE_PLACEHOLDER";
486486
/// Inserts the following code:
487487
/// ```noir
488488
/// impl SomeStruct {
489-
/// fn selector() -> Field {
490-
/// aztec::oracle::compute_selector::compute_selector("SIGNATURE_PLACEHOLDER")
489+
/// fn selector() -> FunctionSelector {
490+
/// aztec::selector::compute_selector("SIGNATURE_PLACEHOLDER")
491491
/// }
492492
/// }
493493
/// ```
@@ -503,13 +503,18 @@ fn generate_selector_impl(structure: &NoirStruct) -> TypeImpl {
503503
vec![expression(ExpressionKind::Literal(Literal::Str(SIGNATURE_PLACEHOLDER.to_string())))],
504504
)))]);
505505

506+
// Define `FunctionSelector` return type
507+
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/3590): Make this point to aztec-nr once the issue is fixed.
508+
let return_type_path = chained_path!("protocol_types", "abis", "function_selector", "FunctionSelector");
509+
let return_type = FunctionReturnType::Ty(make_type(UnresolvedTypeData::Named(return_type_path, vec![])));
510+
506511
let mut selector_fn_def = FunctionDefinition::normal(
507512
&ident("selector"),
508513
&vec![],
509514
&[],
510515
&selector_fun_body,
511516
&[],
512-
&FunctionReturnType::Ty(make_type(UnresolvedTypeData::FieldElement)),
517+
&return_type,
513518
);
514519

515520
selector_fn_def.visibility = FunctionVisibility::Public;

yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr

+10-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ contract Test {
66
AztecAddress,
77
EthAddress,
88
};
9+
// The following import is here in order to make the event macro work because the macro doesn't add the import.
10+
// It doesn't add the import because in the future we will re-export all the types via aztec-nr and aztec-nr is
11+
// already auto-imported by the macros.
12+
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/3590): Remove this once the issue is fixed.
13+
use dep::protocol_types;
914
// docs:start:unencrypted_import
1015
use dep::aztec::log::emit_unencrypted_log;
1116
// docs:end:unencrypted_import
@@ -32,18 +37,17 @@ contract Test {
3237
use dep::token_portal_content_hash_lib::{get_mint_private_content_hash, get_mint_public_content_hash};
3338
use dep::field_note::field_note::{FieldNote, FieldNoteMethods, FIELD_NOTE_LEN};
3439

35-
// TODO(benesjan) https://github.com/AztecProtocol/aztec-packages/issues/3655
36-
// #[event]
37-
// struct ExampleEvent {
38-
// value: Field,
39-
// }
40+
#[event]
41+
struct ExampleEvent {
42+
value: Field,
43+
}
4044

4145
struct Storage {
4246
example_constant: ImmutableSingleton<FieldNote, FIELD_NOTE_LEN>,
4347
}
4448

4549
impl Storage {
46-
fn init(context: Context) -> pub Self {
50+
fn init(context: Context) -> Self {
4751
Storage {
4852
example_constant: ImmutableSingleton::new(context, 1, FieldNoteMethods),
4953
}

0 commit comments

Comments
 (0)