@@ -26,7 +26,7 @@ contract Token {
26
26
note_header::NoteHeader ,
27
27
utils as note_utils ,
28
28
},
29
- context ::{PrivateContext , PublicContext },
29
+ context ::{PrivateContext , PublicContext , Context },
30
30
state_vars ::{map::Map , public_state::PublicState , set::Set },
31
31
types::type_serialisation:: field_serialisation ::{
32
32
FieldSerialisationMethods , FIELD_SERIALISED_LEN ,
@@ -48,53 +48,43 @@ contract Token {
48
48
}
49
49
50
50
impl Storage {
51
- fn init (
52
- private_context : Option <&mut PrivateContext >,
53
- public_context : Option <&mut PublicContext >,
54
- ) -> pub Self {
51
+ fn init (context : Context ) -> pub Self {
55
52
Storage {
56
53
admin : PublicState ::new (
57
- private_context ,
58
- public_context ,
54
+ context ,
59
55
1 ,
60
56
FieldSerialisationMethods ,
61
57
),
62
58
minters : Map ::new (
63
- private_context ,
64
- public_context ,
59
+ context ,
65
60
2 ,
66
- |private_context , public_context , slot | {
61
+ |context , slot | {
67
62
PublicState ::new (
68
- private_context ,
69
- public_context ,
63
+ context ,
70
64
slot ,
71
65
FieldSerialisationMethods ,
72
66
)
73
67
},
74
68
),
75
69
balances : Map ::new (
76
- private_context ,
77
- public_context ,
70
+ context ,
78
71
3 ,
79
- |private_context , public_context , slot | {
80
- Set ::new (private_context , public_context , slot , ValueNoteMethods )
72
+ |context , slot | {
73
+ Set ::new (context , slot , ValueNoteMethods )
81
74
},
82
75
),
83
76
total_supply : PublicState ::new (
84
- private_context ,
85
- public_context ,
77
+ context ,
86
78
4 ,
87
79
FieldSerialisationMethods ,
88
80
),
89
- pending_shields : Set ::new (private_context , public_context , 5 , TransparentNoteMethods ),
81
+ pending_shields : Set ::new (context , 5 , TransparentNoteMethods ),
90
82
public_balances : Map ::new (
91
- private_context ,
92
- public_context ,
83
+ context ,
93
84
6 ,
94
- |private_context , public_context , slot | {
85
+ |context , slot | {
95
86
PublicState ::new (
96
- private_context ,
97
- public_context ,
87
+ context ,
98
88
slot ,
99
89
FieldSerialisationMethods ,
100
90
)
@@ -115,7 +105,7 @@ contract Token {
115
105
fn set_admin (
116
106
new_admin : AztecAddress ,
117
107
) {
118
- let storage = Storage ::init (Option :: none (), Option :: some (&mut context ));
108
+ let storage = Storage ::init (Context :: public (&mut context ));
119
109
assert (storage .admin .read () == context .msg_sender (), "caller is not admin" );
120
110
storage .admin .write (new_admin .address );
121
111
}
@@ -126,7 +116,7 @@ contract Token {
126
116
approve : Field ,
127
117
) {
128
118
assert ((approve == 1 ) | (approve == 0 ), "not providing boolean" );
129
- let storage = Storage ::init (Option :: none (), Option :: some (&mut context ));
119
+ let storage = Storage ::init (Context :: public (&mut context ));
130
120
assert (storage .admin .read () == context .msg_sender (), "caller is not admin" );
131
121
storage .minters .at (minter .address ).write (approve as Field );
132
122
}
@@ -136,7 +126,7 @@ contract Token {
136
126
to : AztecAddress ,
137
127
amount : Field ,
138
128
) -> Field {
139
- let storage = Storage ::init (Option :: none (), Option :: some (&mut context ));
129
+ let storage = Storage ::init (Context :: public (&mut context ));
140
130
assert (storage .minters .at (context .msg_sender ()).read () == 1 , "caller is not minter" );
141
131
let amount = SafeU120 ::new (amount );
142
132
let new_balance = SafeU120 ::new (storage .public_balances .at (to .address ).read ()).add (amount );
@@ -152,7 +142,7 @@ contract Token {
152
142
amount : Field ,
153
143
secret_hash : Field ,
154
144
) -> Field {
155
- let storage = Storage ::init (Option :: none (), Option :: some (&mut context ));
145
+ let storage = Storage ::init (Context :: public (&mut context ));
156
146
assert (storage .minters .at (context .msg_sender ()).read () == 1 , "caller is not minter" );
157
147
let pending_shields = storage .pending_shields ;
158
148
let mut note = TransparentNote ::new (amount , secret_hash );
@@ -170,7 +160,7 @@ contract Token {
170
160
secret_hash : Field ,
171
161
nonce : Field ,
172
162
) -> Field {
173
- let storage = Storage ::init (Option :: none (), Option :: some (&mut context ));
163
+ let storage = Storage ::init (Context :: public (&mut context ));
174
164
175
165
if (from .address != context .msg_sender ()) {
176
166
// The redeem is only spendable once, so we need to ensure that you cannot insert multiple shields from the same message.
@@ -200,7 +190,7 @@ contract Token {
200
190
amount : Field ,
201
191
nonce : Field ,
202
192
) -> Field {
203
- let storage = Storage ::init (Option :: none (), Option :: some (&mut context ));
193
+ let storage = Storage ::init (Context :: public (&mut context ));
204
194
205
195
if (from .address != context .msg_sender ()) {
206
196
let selector = compute_selector ("transfer_public((Field),(Field),Field,Field)" );
@@ -226,7 +216,7 @@ contract Token {
226
216
secret : Field ,
227
217
) -> Field {
228
218
// @todo @lherskind consider Altering the value note as well to be safemath
229
- let storage = Storage ::init (Option :: some (&mut context ), Option :: none ( ));
219
+ let storage = Storage ::init (Context :: private (&mut context ));
230
220
let pending_shields = storage .pending_shields ;
231
221
let balance = storage .balances .at (to .address );
232
222
let public_note = TransparentNote ::new_from_secret (amount , secret );
@@ -242,7 +232,7 @@ contract Token {
242
232
amount : Field ,
243
233
nonce : Field ,
244
234
) -> Field {
245
- let storage = Storage ::init (Option :: some (&mut context ), Option :: none ( ));
235
+ let storage = Storage ::init (Context :: private (&mut context ));
246
236
247
237
if (from .address != context .msg_sender ()) {
248
238
let selector = compute_selector ("unshield((Field),(Field),Field,Field)" );
@@ -267,7 +257,7 @@ contract Token {
267
257
amount : Field ,
268
258
nonce : Field ,
269
259
) -> Field {
270
- let storage = Storage ::init (Option :: some (&mut context ), Option :: none ( ));
260
+ let storage = Storage ::init (Context :: private (&mut context ));
271
261
272
262
if (from .address != context .msg_sender ()) {
273
263
let selector = compute_selector ("transfer((Field),(Field),Field,Field)" );
@@ -294,7 +284,7 @@ contract Token {
294
284
fn _initialize (
295
285
new_admin : AztecAddress ,
296
286
) {
297
- let storage = Storage ::init (Option :: none (), Option :: some (&mut context ));
287
+ let storage = Storage ::init (Context :: public (&mut context ));
298
288
storage .admin .write (new_admin .address );
299
289
storage .minters .at (new_admin .address ).write (1 );
300
290
}
@@ -306,34 +296,34 @@ contract Token {
306
296
to : AztecAddress ,
307
297
amount : Field ,
308
298
) {
309
- let storage = Storage ::init (Option :: none (), Option :: some (&mut context ));
299
+ let storage = Storage ::init (Context :: public (&mut context ));
310
300
let new_balance = SafeU120 ::new (storage .public_balances .at (to .address ).read ()).add (SafeU120 ::new (amount ));
311
301
storage .public_balances .at (to .address ).write (new_balance .value as Field );
312
302
}
313
303
314
304
/// Unconstrained ///
315
305
316
306
unconstrained fn admin () -> Field {
317
- let storage = Storage ::init (Option :: none (), Option ::none ());
307
+ let storage = Storage ::init (Context ::none ());
318
308
storage .admin .read ()
319
309
}
320
310
321
311
unconstrained fn is_minter (
322
312
minter : AztecAddress ,
323
313
) -> bool {
324
- let storage = Storage ::init (Option :: none (), Option ::none ());
314
+ let storage = Storage ::init (Context ::none ());
325
315
storage .minters .at (minter .address ).read () as bool
326
316
}
327
317
328
318
unconstrained fn total_supply () -> Field {
329
- let storage = Storage ::init (Option :: none (), Option ::none ());
319
+ let storage = Storage ::init (Context ::none ());
330
320
storage .total_supply .read ()
331
321
}
332
322
333
323
unconstrained fn balance_of_private (
334
324
owner : AztecAddress ,
335
325
) -> Field {
336
- let storage = Storage ::init (Option :: none (), Option ::none ());
326
+ let storage = Storage ::init (Context ::none ());
337
327
let owner_balance = storage .balances .at (owner .address );
338
328
339
329
balance_utils:: get_balance (owner_balance )
@@ -342,7 +332,7 @@ contract Token {
342
332
unconstrained fn balance_of_public (
343
333
owner : AztecAddress ,
344
334
) -> Field {
345
- let storage = Storage ::init (Option :: none (), Option ::none ());
335
+ let storage = Storage ::init (Context ::none ());
346
336
storage .public_balances .at (owner .address ).read ()
347
337
}
348
338
0 commit comments