Hey everyone please I need some help troubleshooting. I have a smart contract function entry point that looks like this
#[receive(
contract = "first_game_room",
name = "join_game_room",
parameter = "JoinGameRoomParameter",
error = "Error",
return_value="Vec<AccountAddress>",
mutable
)]
fn join_game_room(ctx: &ReceiveContext, host: &mut Host<State>) -> Result<Vec<AccountAddress>, Error> {
// check if invoker is the smart contract owner, else reject
// Get the contract owner
let owner = ctx.owner();
let sender = ctx.sender();
ensure!(sender.matches_account(&owner), Error::Unauthorized);
// check if game room alredy started, throw error geam arleeady started
let block_time = ctx.metadata().block_time(); // current time
ensure!(block_time > host.state().start, Error::JoinBeforeStartError);
// check if game room already ended, throw error game room already ended
// ensure!(block_time <= host.state().end, Error::JoinAfterEndError);
// check if participant already entered, throw error participnat already entered
let param: JoinGameRoomParameter = ctx.parameter_cursor().get()?;
host.state_mut().participants.insert(param.potential_participant);
let mut participants_vec: Vec<AccountAddress> = Vec::new();
for addr in host.state().participants.iter() {
participants_vec.push(*addr);
}
Ok(participants_vec)
}
when I call this join_game_room entrypoint everything seem to work well and the participants state update seems successful as I’m able to get back a Vector that contains the address that just got added to the participants. The problem is that I have another view_participant
entry point that looks like this
/// View function that returns the content of the state.
#[receive(contract = "first_game_room", name = "view_participants", return_value = "Vec<AccountAddress>")]
fn view_participants(_ctx: &ReceiveContext, host: &Host<State>) -> ReceiveResult<Vec<AccountAddress>> {
let mut participants_vec: Vec<AccountAddress> = Vec::new();
for addr in host.state().participants.iter() {
participants_vec.push(*addr);
}
Ok(participants_vec)
}
when I call this view_participant entry point after a successful join_game_room invocation, the view_partipicipant function returns an empty vector, so it seems as if the participant state update only happened within the join_game_room function. Any idea what might be wrong?