@@ -2,84 +2,84 @@ use aztec::macros::aztec;
22
33#[aztec]
44pub contract StarterToken {
5- use aztec::macros:: {
6- functions ::{initializer , private , public , utility , internal },
7- storage:: storage ,
8- };
9- use aztec::state_vars:: {PublicMutable , Map };
10- use aztec::protocol_types::address::AztecAddress ;
11-
12- use easy_private_state::EasyPrivateUint ;
13-
14- #[storage]
15- struct Storage <Context > {
16- owner : PublicMutable <AztecAddress , Context >,
17- balances : Map <AztecAddress , PublicMutable <u128 , Context >, Context >,
18- // ===============
19- private_balances : Map <AztecAddress , EasyPrivateUint <Context >, Context >
20- }
21-
22- #[initializer]
23- #[public]
24- fn setup () {
25- // The deployer becomes the owner
26- storage .owner .write (context .msg_sender ());
27- }
28-
29- #[public]
30- fn mint (to : AztecAddress , amount : u128 ) {
31- assert_eq (context .msg_sender (), storage .owner .read ());
32-
33- let recipient_balance = storage .balances .at (to ).read ();
34- storage .balances .at (to ).write (recipient_balance + amount );
35- }
36-
37- #[public]
38- fn transfer (to : AztecAddress , amount : u128 ) {
39- let sender = context .msg_sender ();
40- let sender_balance = storage .balances .at (sender ).read ();
5+ use aztec::macros:: {
6+ functions ::{initializer , private , public , utility , internal },
7+ storage:: storage ,
8+ };
9+ use aztec::state_vars:: {PublicMutable , Map };
10+ use aztec::protocol_types::address::AztecAddress ;
11+
12+ use easy_private_state::EasyPrivateUint ;
13+
14+ #[storage]
15+ struct Storage <Context > {
16+ owner : PublicMutable <AztecAddress , Context >,
17+ balances : Map <AztecAddress , PublicMutable <u128 , Context >, Context >,
18+ // ===============
19+ private_balances : Map <AztecAddress , EasyPrivateUint <Context >, Context >
20+ }
21+
22+ #[initializer]
23+ #[public]
24+ fn setup () {
25+ // The deployer becomes the owner
26+ storage .owner .write (context .msg_sender ());
27+ }
28+
29+ #[public]
30+ fn mint (to : AztecAddress , amount : u128 ) {
31+ assert_eq (context .msg_sender (), storage .owner .read ());
32+
33+ let recipient_balance = storage .balances .at (to ).read ();
34+ storage .balances .at (to ).write (recipient_balance + amount );
35+ }
36+
37+ #[public]
38+ fn transfer (to : AztecAddress , amount : u128 ) {
39+ let sender = context .msg_sender ();
40+ let sender_balance = storage .balances .at (sender ).read ();
41+
42+ assert (sender_balance >= amount , "Insufficient balance" );
43+
44+ storage .balances .at (sender ).write (sender_balance - amount );
45+
46+ let recipient_balance = storage .balances .at (to ).read ();
47+ storage .balances .at (to ).write (recipient_balance + amount );
48+ }
49+
50+ #[public]
51+ fn transfer_ownership (new_owner : AztecAddress ) {
52+ assert_eq (context .msg_sender (), storage .owner .read ());
53+ storage .owner .write (new_owner );
54+ }
4155
42- assert (sender_balance >= amount , "Insufficient balance" );
43-
44- storage .balances .at (sender ).write (sender_balance - amount );
45-
46- let recipient_balance = storage .balances .at (to ).read ();
47- storage .balances .at (to ).write (recipient_balance + amount );
48- }
49-
50- #[public]
51- fn transfer_ownership (new_owner : AztecAddress ) {
52- assert_eq (context .msg_sender (), storage .owner .read ());
53- storage .owner .write (new_owner );
54- }
55-
56- // ===============
56+ // ===============
5757
58- #[private]
59- fn mint_private (to : AztecAddress , amount : u64 ) {
60- // Enqueue public validation
61- StarterToken ::at (context .this_address ())._assert_is_owner (context .msg_sender ()).enqueue (&mut context );
58+ #[private]
59+ fn mint_private (to : AztecAddress , amount : u64 ) {
60+ // Enqueue public validation
61+ StarterToken ::at (context .this_address ())._assert_is_owner (context .msg_sender ()).enqueue (&mut context );
6262
63- storage .private_balances .at (to ).add (amount , to );
64- }
63+ storage .private_balances .at (to ).add (amount , to );
64+ }
6565
66- #[private]
67- fn transfer_private (to : AztecAddress , amount : u64 ) {
68- let sender = context .msg_sender ();
66+ #[private]
67+ fn transfer_private (to : AztecAddress , amount : u64 ) {
68+ let sender = context .msg_sender ();
6969
70- storage .private_balances .at (sender ).sub (amount , sender );
70+ storage .private_balances .at (sender ).sub (amount , sender );
7171
72- storage .private_balances .at (to ).add (amount , to );
73- }
72+ storage .private_balances .at (to ).add (amount , to );
73+ }
7474
75- #[utility]
76- unconstrained fn view_private_balance (owner : AztecAddress ) -> Field {
77- storage .private_balances .at (owner ).get_value ()
78- }
75+ #[utility]
76+ unconstrained fn view_private_balance (owner : AztecAddress ) -> Field {
77+ storage .private_balances .at (owner ).get_value ()
78+ }
7979
80- #[public]
81- #[internal]
82- fn _assert_is_owner (maybe_owner : AztecAddress ) {
83- assert_eq (maybe_owner , storage .owner .read ());
84- }
80+ #[public]
81+ #[internal]
82+ fn _assert_is_owner (maybe_owner : AztecAddress ) {
83+ assert_eq (maybe_owner , storage .owner .read ());
84+ }
8585}
0 commit comments