From 3c16d04de7accdbb8faf31635d82d5b423b0d80b Mon Sep 17 00:00:00 2001 From: Recrafter Date: Wed, 3 Jul 2024 08:40:09 +0700 Subject: [PATCH] Adjusting events --- pallets/game/src/lib.rs | 7 ++++--- pallets/game/src/properties.rs | 4 ---- pallets/game/src/tests.rs | 3 +-- pallets/game/src/types.rs | 1 - 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/pallets/game/src/lib.rs b/pallets/game/src/lib.rs index 7fbb7a9..ed617ff 100644 --- a/pallets/game/src/lib.rs +++ b/pallets/game/src/lib.rs @@ -219,7 +219,7 @@ pub mod pallet { /// A user has received points. PointsReceived { receiver: AccountIdOf, amount: u32 }, /// A game has started. - GameStarted { player: AccountIdOf, game_id: u32, ending_block: BlockNumberFor }, + GameStarted { player: AccountIdOf, game_id: u32, ending_block: BlockNumberFor, property_id: u32 }, /// An answer has been submitted. AnswerSubmitted { player: AccountIdOf, game_id: u32, guess: u32 }, /// The result has been checked. @@ -497,13 +497,14 @@ pub mod pallet { let random_number = u32_value as usize % game_properties.len(); let property = game_properties[random_number].clone(); let game_datas = - GameData { difficulty: game_type, player: signer.clone(), property, guess: None }; + GameData { difficulty: game_type, player: signer.clone(), property: property.clone(), guess: None }; game_properties.retain(|property| property.id as usize != random_number); GameProperties::::put(game_properties); GameInfo::::insert(game_id, game_datas); let next_game_id = game_id.checked_add(1).ok_or(Error::::ArithmeticOverflow)?; GameId::::put(next_game_id); - Self::deposit_event(Event::::GameStarted { player: signer, game_id, ending_block: expiry_block }); + // Submit the encrypted property data and delete the price + Self::deposit_event(Event::::GameStarted { player: signer, game_id, ending_block: expiry_block, property_id: property.id }); Ok(()) } diff --git a/pallets/game/src/properties.rs b/pallets/game/src/properties.rs index eedf82f..d85acac 100644 --- a/pallets/game/src/properties.rs +++ b/pallets/game/src/properties.rs @@ -6,28 +6,24 @@ impl Pallet { let new_property = PropertyInfoData { id: 147229391, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), - price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; GameProperties::::try_append(new_property.clone()) .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 146480642, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), - price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; GameProperties::::try_append(new_property.clone()) .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 147031382, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), - price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; GameProperties::::try_append(new_property.clone()) .map_err(|_| Error::::TooManyTest)?; let new_property = PropertyInfoData { id: 147031382, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), - price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; GameProperties::::try_append(new_property.clone()) .map_err(|_| Error::::TooManyTest)?; diff --git a/pallets/game/src/tests.rs b/pallets/game/src/tests.rs index 58246bd..d907971 100644 --- a/pallets/game/src/tests.rs +++ b/pallets/game/src/tests.rs @@ -947,7 +947,7 @@ fn handle_offer_accept_works() { crate::DifficultyLevel::Player, )); System::assert_last_event( - Event::GameStarted { player: [0; 32].into(), game_id: 6, ending_block: 9 }.into(), + Event::GameStarted { player: [0; 32].into(), game_id: 6, ending_block: 9, property_id: 147229391 }.into(), ); run_to_block(20); assert_eq!(GameModule::users::([0; 32].into()).unwrap().nfts.xorange, 3); @@ -1153,7 +1153,6 @@ fn add_property_works() { let new_property = PropertyInfoData { id: 147031382, data: "nfdjakl;fueif;janf,dnfm,dhfhfdksks".as_bytes().to_vec().try_into().unwrap(), - price: "kkjfkdjdkdjdkdjdk".as_bytes().to_vec().try_into().unwrap(), }; assert_ok!(GameModule::add_property(RuntimeOrigin::root(), new_property)); assert_eq!(GameModule::game_properties().len(), 5); diff --git a/pallets/game/src/types.rs b/pallets/game/src/types.rs index f44da95..5a514ff 100644 --- a/pallets/game/src/types.rs +++ b/pallets/game/src/types.rs @@ -104,7 +104,6 @@ pub struct OfferInfo { pub struct PropertyInfoData { pub id: u32, pub data: BoundedVec::StringLimit>, - pub price: BoundedVec::StringLimit>, } /// Struct for the user datas.