Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: event macro #3784

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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