diff --git a/docs/examples/Gaming/racingcars.md b/docs/examples/Gaming/racingcars.md index 6d0b1d1..c918446 100644 --- a/docs/examples/Gaming/racingcars.md +++ b/docs/examples/Gaming/racingcars.md @@ -152,6 +152,7 @@ service CarRacesService { events { RoundInfo: RoundInfo; + GameFinished: struct { player: actor_id }; Killed: struct { inheritor: actor_id }; } }; @@ -274,7 +275,7 @@ pub async fn player_move( game.current_turn = (game.current_turn + 1) % num_of_cars; let mut round_info: Option = None; - + let mut game_finished = false; // Continue processing car turns until the player can act or the game finishes. while !game.is_player_action_or_finished() { game.process_car_turn().await?; @@ -293,14 +294,24 @@ pub async fn player_move( // If the game is finished, a delayed message is sent to remove the game instance. if game.state == GameState::Finished { send_msg_to_remove_game_instance(player); + game_finished = true; } } } // Return the round info as an event or handle an unexpected state. match round_info { - Some(info) => Ok(Event::RoundInfo(info)), - None => Err(Error::UnexpectedState), + Some(info) => { + self.notify_on(Event::RoundInfo(info)) + .expect("Notification Error"); + if game_finished { + self.notify_on(Event::GameFinished { player: msg_src }) + .expect("Notification Error"); + } + } + None => { + panic(Error::UnexpectedState); + } } }) } diff --git a/docs/examples/Gaming/varaman.md b/docs/examples/Gaming/varaman.md index db21b5e..d8d65a9 100644 --- a/docs/examples/Gaming/varaman.md +++ b/docs/examples/Gaming/varaman.md @@ -254,6 +254,7 @@ pub enum Event { maximum_number_gold_coins: u16, maximum_number_silver_coins: u16, prize: u128, + player_address: ActorId, }, NewTournamentCreated { tournament_name: String, @@ -281,6 +282,7 @@ pub enum Event { maximum_possible_points: u128, maximum_number_gold_coins: u16, maximum_number_silver_coins: u16, + player_address: ActorId, }, GameStarted, AdminAdded(ActorId), @@ -535,6 +537,7 @@ pub fn record_tournament_result( maximum_possible_points, maximum_number_gold_coins: storage.config.max_number_gold_coins, maximum_number_silver_coins: storage.config.max_number_silver_coins, + player_address: msg_src, }) } ``` @@ -636,13 +639,8 @@ pub async fn finish_single_game( msg::send_with_gas(msg_src, "", 0, prize).expect("Error in sending value"); } else if let Status::StartedWithFungibleToken { ft_address } = storage.status { let value: U256 = prize.into(); - let request = [ - "Vft".encode(), - "Mint".to_string().encode(), - (msg_src, value).encode(), - ] - .concat(); - + let request = vft_io::Mint::encode_call(msg_src, value); + msg::send_bytes_with_gas_for_reply( ft_address, request, @@ -662,6 +660,7 @@ pub async fn finish_single_game( maximum_possible_points, maximum_number_gold_coins: storage.config.max_number_gold_coins, maximum_number_silver_coins: storage.config.max_number_silver_coins, + player_address: msg_src, }) } ```