@@ -95,6 +95,8 @@ mod button_game {
95
95
pub marketplace : AccountId ,
96
96
/// scoring strategy
97
97
pub scoring : Scoring ,
98
+ /// current round number
99
+ pub round : u64 ,
98
100
}
99
101
100
102
impl AccessControlled for ButtonGame {
@@ -117,7 +119,7 @@ mod button_game {
117
119
let required_role = Role :: Initializer ( code_hash) ;
118
120
let access_control = AccountId :: from ( ACCESS_CONTROL_PUBKEY ) ;
119
121
120
- match ButtonGame :: check_role ( & access_control, & caller, required_role) {
122
+ match ButtonGame :: check_role ( access_control, caller, required_role) {
121
123
Ok ( _) => Self :: init (
122
124
ticket_token,
123
125
reward_token,
@@ -137,6 +139,12 @@ mod button_game {
137
139
self . last_press + self . button_lifetime
138
140
}
139
141
142
+ /// Returns the curent round number
143
+ #[ ink( message) ]
144
+ pub fn round ( & self ) -> u64 {
145
+ self . round
146
+ }
147
+
140
148
/// Returns the buttons status
141
149
#[ ink( message) ]
142
150
pub fn is_dead ( & self ) -> bool {
@@ -232,7 +240,7 @@ mod button_game {
232
240
pub fn reset ( & mut self ) -> ButtonResult < ( ) > {
233
241
self . ensure_dead ( ) ?;
234
242
self . reward_pressiah ( ) ?;
235
- self . reset_state ( ) ;
243
+ self . reset_state ( ) ? ;
236
244
self . transfer_tickets_to_marketplace ( ) ?;
237
245
self . reset_marketplace ( )
238
246
}
@@ -246,7 +254,7 @@ mod button_game {
246
254
let caller = self . env ( ) . caller ( ) ;
247
255
let this = self . env ( ) . account_id ( ) ;
248
256
let required_role = Role :: Owner ( this) ;
249
- ButtonGame :: check_role ( & self . access_control , & caller, required_role) ?;
257
+ ButtonGame :: check_role ( self . access_control , caller, required_role) ?;
250
258
self . access_control = new_access_control;
251
259
Ok ( ( ) )
252
260
}
@@ -259,7 +267,7 @@ mod button_game {
259
267
let caller = self . env ( ) . caller ( ) ;
260
268
let this = self . env ( ) . account_id ( ) ;
261
269
let required_role = Role :: Owner ( this) ;
262
- ButtonGame :: check_role ( & self . access_control , & caller, required_role) ?;
270
+ ButtonGame :: check_role ( self . access_control , caller, required_role) ?;
263
271
self . env ( ) . terminate_contract ( caller)
264
272
}
265
273
@@ -286,6 +294,7 @@ mod button_game {
286
294
last_presser : None ,
287
295
presses : 0 ,
288
296
total_rewards : 0 ,
297
+ round : 0 ,
289
298
} ;
290
299
291
300
Self :: emit_event (
@@ -301,15 +310,17 @@ mod button_game {
301
310
contract
302
311
}
303
312
304
- fn reset_state ( & mut self ) {
313
+ fn reset_state ( & mut self ) -> ButtonResult < ( ) > {
305
314
let now = self . env ( ) . block_number ( ) ;
306
315
307
316
self . presses = 0 ;
308
317
self . last_presser = None ;
309
318
self . last_press = now;
310
319
self . total_rewards = 0 ;
320
+ self . round . checked_add ( 1 ) . ok_or ( GameError :: Arithmethic ) ?;
311
321
312
322
Self :: emit_event ( self . env ( ) , Event :: GameReset ( GameReset { when : now } ) ) ;
323
+ Ok ( ( ) )
313
324
}
314
325
315
326
fn reward_pressiah ( & self ) -> ButtonResult < ( ) > {
@@ -323,7 +334,7 @@ mod button_game {
323
334
324
335
fn ensure_dead ( & self ) -> ButtonResult < ( ) > {
325
336
if !self . is_dead ( ) {
326
- return Err ( GameError :: BeforeDeadline ) ;
337
+ Err ( GameError :: BeforeDeadline )
327
338
} else {
328
339
Ok ( ( ) )
329
340
}
@@ -370,22 +381,18 @@ mod button_game {
370
381
Ok ( ( ) )
371
382
}
372
383
373
- fn check_role (
374
- access_control : & AccountId ,
375
- account : & AccountId ,
376
- role : Role ,
377
- ) -> ButtonResult < ( ) >
384
+ fn check_role ( access_control : AccountId , account : AccountId , role : Role ) -> ButtonResult < ( ) >
378
385
where
379
386
Self : AccessControlled ,
380
387
{
381
388
<Self as AccessControlled >:: check_role (
382
- access_control. clone ( ) ,
383
- account. clone ( ) ,
389
+ access_control,
390
+ account,
384
391
role,
385
392
|why : InkEnvError | {
386
393
GameError :: InkEnvError ( format ! ( "Calling access control has failed: {:?}" , why) )
387
394
} ,
388
- | role : Role | GameError :: MissingRole ( role ) ,
395
+ GameError :: MissingRole ,
389
396
)
390
397
}
391
398
0 commit comments