-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathmain.nr
42 lines (36 loc) · 1.38 KB
/
main.nr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// A contract used along with `Parent` contract to test nested calls.
contract DelegatedOn {
use dep::aztec::prelude::{
AztecAddress, FunctionSelector, NoteHeader, NoteGetterOptions, NoteViewerOptions,
emit_unencrypted_log, PublicMutable, PrivateSet, PrivateContext
};
use dep::value_note::value_note::ValueNote;
#[aztec(storage)]
struct Storage {
current_value: PublicMutable<Field>,
a_private_value: PrivateSet<ValueNote>,
}
#[aztec(private)]
fn private_set_value(new_value: Field, owner: AztecAddress) -> Field {
let mut note = ValueNote::new(new_value, owner);
storage.a_private_value.insert(&mut note, true);
new_value
}
#[aztec(public)]
fn public_set_value(new_value: Field) -> Field {
storage.current_value.write(new_value);
new_value
}
unconstrained fn view_private_value(amount: Field, owner: AztecAddress) -> pub Field {
let options = NoteViewerOptions::new().select(ValueNote::properties().value, amount, Option::none()).select(
ValueNote::properties().owner,
owner.to_field(),
Option::none()
).set_limit(1);
let notes = storage.a_private_value.view_notes(options);
notes[0].unwrap_unchecked().value
}
unconstrained fn view_public_value() -> pub Field {
storage.current_value.read()
}
}