-
Notifications
You must be signed in to change notification settings - Fork 606
feat: testing private events from Aztec.nr #20640
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
Changes from 5 commits
9982c5e
d4522ea
c71b27e
cc27052
7dc8ff2
9c9d4f3
956a329
a8f6119
fb4b18a
908c4d6
f575bfa
a013644
b720897
0e950f1
67daad1
f5cf5e6
64f920c
33300d0
f6e9915
3361896
3e68a81
6da2825
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,8 @@ | ||||||||
| use crate::{context::inputs::PrivateContextInputs, event::EventSelector, test::helpers::utils::TestAccount}; | ||||||||
| use crate::{ | ||||||||
| context::inputs::PrivateContextInputs, | ||||||||
| event::{event_interface::EventInterface, EventSelector}, | ||||||||
| test::helpers::utils::TestAccount, | ||||||||
| }; | ||||||||
|
|
||||||||
| use crate::protocol::{ | ||||||||
| abis::function_selector::FunctionSelector, | ||||||||
|
|
@@ -8,6 +12,7 @@ use crate::protocol::{ | |||||||
| }, | ||||||||
| contract_instance::ContractInstance, | ||||||||
| traits::{Deserialize, ToField}, | ||||||||
| utils::reader::Reader, | ||||||||
| }; | ||||||||
|
|
||||||||
| global MAX_PRIVATE_EVENTS_PER_TXE_QUERY: u32 = 5; | ||||||||
|
|
@@ -79,19 +84,21 @@ pub unconstrained fn get_last_tx_effects() -> (Field, BoundedVec<Field, MAX_NOTE | |||||||
| pub unconstrained fn get_default_address() -> AztecAddress {} | ||||||||
|
|
||||||||
| // experimental | ||||||||
| pub(crate) unconstrained fn get_private_events( | ||||||||
| selector: EventSelector, | ||||||||
| pub unconstrained fn get_private_events<Event>( | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We want to somehow flag this. I imagine something like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're making this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the docs in f575bfa and this how they get rendered:
Do you like it? BTW do you know if there is a way how the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I wishit were more obvious. Perhaps we could do horizontal separators with ---?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't follow. What is supposed to be more obvious? And where do you want me to place the separator? |
||||||||
| contract_address: AztecAddress, | ||||||||
| scope: AztecAddress, | ||||||||
| ) -> BoundedVec<BoundedVec<Field, MAX_EVENT_SERIALIZATION_LENGTH>, MAX_PRIVATE_EVENTS_PER_TXE_QUERY> { | ||||||||
| // This is a workaround as Noir does not currently let us return nested structs with arrays. We instead return a | ||||||||
| // raw multidimensional array in get_private_events_oracle and create the BoundedVecs here. | ||||||||
|
|
||||||||
| let (raw_array_storage, event_lengths, query_length) = get_private_events_oracle(selector, contract_address, scope); | ||||||||
| ) -> BoundedVec<Event, MAX_PRIVATE_EVENTS_PER_TXE_QUERY> | ||||||||
| where | ||||||||
| Event: EventInterface + Deserialize, | ||||||||
| { | ||||||||
| let selector = Event::get_event_type_id(); | ||||||||
| let (raw_array_storage, _event_lengths, query_length) = | ||||||||
| get_private_events_oracle(selector, contract_address, scope); | ||||||||
|
|
||||||||
| let mut events = BoundedVec::new(); | ||||||||
| for i in 0..query_length { | ||||||||
| events.push(BoundedVec::from_parts(raw_array_storage[i], event_lengths[i])); | ||||||||
| let mut reader = Reader::new(raw_array_storage[i]); | ||||||||
| events.push(Deserialize::stream_deserialize(&mut reader)); | ||||||||
|
benesjan marked this conversation as resolved.
benesjan marked this conversation as resolved.
|
||||||||
| } | ||||||||
|
|
||||||||
| events | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,10 +45,10 @@ pub contract Token { | |
| global RECURSIVE_TRANSFER_CALL_MAX_NOTES: u32 = 8; | ||
|
|
||
| #[event] | ||
| struct Transfer { | ||
| from: AztecAddress, | ||
| to: AztecAddress, | ||
| amount: u128, | ||
| pub struct Transfer { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably want to either make all of these
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documented this in 908c4d6 Is that would you meant by suggesting making them pub, right?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant that the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was originally hesitant to make the event macro apply the pub there as it makes it feel a bit more magical (events are just structs but with some extra stuff) but given that by definition they are a piece of data to be consumed by "the world out of the contract" I came to agree that it makes sense to not be annoying here and just auto-expose it. Addressed in 6da2825 But I have one question about this:
Isn't it strange to link from the event macro code docs to the doc piece I wrote given that the event macro docs are way more "low-level"? Or is that not what you meant?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| pub from: AztecAddress, | ||
| pub to: AztecAddress, | ||
| pub amount: u128, | ||
| } | ||
|
|
||
| // docs:start:storage_struct | ||
|
|
@@ -243,7 +243,7 @@ pub contract Token { | |
| self.storage.balances.at(from).add(change).deliver(MessageDelivery.ONCHAIN_UNCONSTRAINED); | ||
| self.storage.balances.at(to).add(amount).deliver(MessageDelivery.ONCHAIN_UNCONSTRAINED); | ||
|
|
||
| // We don't constrain encryption of the note log in `transfer` (unlike in `transfer_in_private`) because the transfer | ||
| // We don't constrain encryption of the event log here (unlike in `transfer_in_private`) because the transfer | ||
| // function is only designed to be used in situations where the event is not strictly necessary (e.g. payment to | ||
| // another person where the payment is considered to be successful when the other party successfully decrypts a | ||
| // note). | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.