-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathmain.nr
58 lines (52 loc) · 1.92 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// A contract used along with `Parent` contract to test nested calls.
contract Delegator {
use dep::aztec::prelude::{
AztecAddress, FunctionSelector, NoteHeader, NoteViewerOptions, emit_unencrypted_log,
PublicMutable, PrivateSet
};
use dep::value_note::value_note::ValueNote;
#[aztec(storage)]
struct Storage {
current_value: PublicMutable<Field>,
a_private_value: PrivateSet<ValueNote>,
}
#[aztec(private)]
fn private_delegate_set_value(
target_contract: AztecAddress,
target_selector: FunctionSelector,
args: [Field; 2]
) {
// Call the target private function
let return_values = context.delegate_call_private_function(target_contract, target_selector, args);
// Copy the return value from the call to this function's return values
return_values[0]
}
#[aztec(private)]
fn enqueued_delegate_set_value(
target_contract: AztecAddress,
target_selector: FunctionSelector,
args: [Field; 1]
) {
context.delegate_call_public_function(target_contract, target_selector, args);
}
#[aztec(public)]
fn public_delegate_set_value(
target_contract: AztecAddress,
target_selector: FunctionSelector,
args: [Field; 1]
) {
let _ = context.delegate_call_public_function(target_contract, target_selector, args);
}
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()
}
}