@@ -45,6 +45,7 @@ pub struct LevelProgress {
4545 pub is_completed : bool ,
4646 pub attempts : u32 ,
4747 pub nft_minted : bool ,
48+ pub last_attempt_ledger : u32 ,
4849}
4950
5051// ---------------------------------------------------------------------
@@ -82,6 +83,8 @@ pub enum Error {
8283 WrongLevel = 7 ,
8384 QuestionPerLevelLimit = 8 ,
8485 MissingNftContract = 9 ,
86+ AttemptTooSoon = 10 ,
87+ LevelImmutable = 11 ,
8588}
8689
8790// ---------------------------------------------------------------------
@@ -259,7 +262,14 @@ impl StellarHunts {
259262 is_completed : false ,
260263 attempts : 0 ,
261264 nft_minted : false ,
265+ last_attempt_ledger : 0 ,
262266 } ) ;
267+
268+ let current_ledger = env. ledger ( ) . sequence ( ) ;
269+ if lp. last_attempt_ledger == current_ledger {
270+ panic_with_error ! ( & env, Error :: AttemptTooSoon ) ;
271+ }
272+ lp. last_attempt_ledger = current_ledger;
263273 lp. attempts += 1 ;
264274
265275 let hashed: BytesN < 32 > = env. crypto ( ) . sha256 ( & answer) . into ( ) ;
@@ -332,6 +342,25 @@ impl StellarHunts {
332342 panic_with_error ! ( & env, Error :: WrongLevel ) ;
333343 }
334344
345+ let lp_key = DataKey :: PlayerLevelProgress ( caller. clone ( ) , q. level . clone ( ) ) ;
346+ let lp: LevelProgress = env
347+ . storage ( )
348+ . persistent ( )
349+ . get ( & lp_key)
350+ . unwrap_or ( LevelProgress {
351+ player : caller. clone ( ) ,
352+ level : q. level . clone ( ) ,
353+ last_question_index : 0 ,
354+ is_completed : false ,
355+ attempts : 0 ,
356+ nft_minted : false ,
357+ last_attempt_ledger : 0 ,
358+ } ) ;
359+
360+ if lp. attempts == 0 {
361+ panic_with_error ! ( & env, Error :: NotInitialized ) ;
362+ }
363+
335364 env. events ( ) . publish (
336365 ( Symbol :: new ( & env, "hint_requested" ) , ) ,
337366 ( caller. clone ( ) , question_id, q. level . clone ( ) ) ,
@@ -457,6 +486,7 @@ impl StellarHunts {
457486 is_completed : false ,
458487 attempts : 0 ,
459488 nft_minted : false ,
489+ last_attempt_ledger : 0 ,
460490 } )
461491 }
462492
@@ -485,6 +515,7 @@ impl StellarHunts {
485515 is_completed : false ,
486516 attempts : 0 ,
487517 nft_minted : false ,
518+ last_attempt_ledger : 0 ,
488519 } ;
489520 env. storage ( ) . persistent ( ) . set (
490521 & DataKey :: PlayerLevelProgress ( player. clone ( ) , Levels :: Easy ) ,
0 commit comments