here is the contract update Interaction
Code is
#[derive(Debug, Serialize, SchemaType, Clone, Copy)]
struct TransferPrize {
winner: AccountAddress,
match_id: u64,
}
#[receive(
contract = "backgammon",
name = "transfer_prize",
parameter = "TransferPrize",
enable_logger,
mutable
)]
fn transfer_prize<S: HasStateApi>(
ctx: &impl HasReceiveContext,
host: &mut impl HasHost<State<S>, StateApiType = S>,
logger: &mut impl HasLogger,
) -> ContractResult<()> {
let admin = host.state().admin;
let sender = ctx.sender();
ensure!(
sender.matches_account(&admin),
BackgammonError::Unauthorized
);
let params: TransferPrize = ctx.parameter_cursor().get()?;
// Get the contract owner, i.e. the account who initialized the contract.
let winner = ¶ms.winner;
let match_id = ¶ms.match_id;
let prize_money = host.state().get_bet_amount(match_id);
host.invoke_transfer(winner, 2 * prize_money)?;
let (state, _builder) = host.state_and_builder();
let mut instance = state.match_id.get_mut(match_id).unwrap();
ensure_eq!(
instance.status,
Status::Ongoing,
BackgammonError::Unauthorized
);
instance.winner = Winner::Player(*winner);
instance.status = Status::Completed;
logger.log(&BackgammonEvent::Winner(WinnerEvent {
winner: *winner,
amount: prize_money,
id: *match_id,
}))?;
Ok(())
// Result in a transfer of the whole balance to the contract owner.
}
What is causing interruption.
ownership of variable named “match_id” might be questionable .