Skip to content

Commit

Permalink
fix: event macro (AztecProtocol#3784)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Jan 2, 2024
1 parent 5749139 commit 7cba7d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
11 changes: 8 additions & 3 deletions noir/aztec_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
/// }
/// }
/// ```
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<FieldNote, FIELD_NOTE_LEN>,
}

impl Storage {
fn init(context: Context) -> pub Self {
fn init(context: Context) -> Self {
Storage {
example_constant: ImmutableSingleton::new(context, 1, FieldNoteMethods),
}
Expand Down

0 comments on commit 7cba7d1

Please sign in to comment.