-
Notifications
You must be signed in to change notification settings - Fork 599
Expand file tree
/
Copy pathmain.nr
More file actions
35 lines (27 loc) · 1.1 KB
/
main.nr
File metadata and controls
35 lines (27 loc) · 1.1 KB
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
// Sample escrow contract that stores a balance of a private token on behalf of an owner.
contract Escrow {
use dep::aztec::prelude::{AztecAddress, EthAddress, FunctionSelector, NoteHeader, PrivateContext, PrivateImmutable};
use dep::aztec::context::{PublicContext, Context};
use dep::address_note::address_note::AddressNote;
use dep::token::Token;
#[aztec(storage)]
struct Storage {
owner: PrivateImmutable<AddressNote>,
}
// Creates a new instance
#[aztec(private)]
#[aztec(initializer)]
fn constructor(owner: AztecAddress) {
let mut note = AddressNote::new(owner, owner);
storage.owner.initialize(&mut note, true);
}
// Withdraws balance. Requires that msg.sender is the owner.
#[aztec(private)]
fn withdraw(token: AztecAddress, amount: Field, recipient: AztecAddress) {
let this = context.this_address();
let sender = context.msg_sender();
let note = storage.owner.get_note();
assert(note.address == sender);
Token::at(token).transfer(this, recipient, amount, 0).call(&mut context);
}
}