there is a game account created by the contract. the contract is the creator of this account, but it is not authorized to make transactions. why?
...
#[derive(Accounts)]
pub struct ResultGameMatchContext<'info> {
#[account(mut)]
pub game: Account<'info, Game>,
#[account(mut)]
pub game_match: Account<'info, GameMatch>,
/// CHECK: we will check this in the instruction
#[account(mut)]
pub player: AccountInfo<'info>,
/// CHECK: we will check this in the instruction
#[account(mut)]
pub admin: Signer<'info>,
/// CHECK: sysvar address check is hardcoded, we want to avoid the default deserialization
#[account(address = sysvar::recent_blockhashes::ID)]
pub recent_blockhashes: UncheckedAccount<'info>,
pub system_program: Program<'info, System>,
}
...
if ctx.accounts.game_match.won {
msg!("you won!");
ctx.accounts.game_match.status = GameMatchStatus::Won;
ctx.accounts.game.win_count += 1;
ctx.accounts.game_match.won_amount = (ctx.accounts.game_match.bet_amount
* ctx.accounts.game.multiplier as u64)
/ 1000 as u64;
msg!("won_amount: {}", ctx.accounts.game_match.won_amount);
// Error
let transfer_to_player = solana_program::system_instruction::transfer(
&ctx.accounts.game.key(),
&ctx.accounts.player.key(),
ctx.accounts.game_match.won_amount,
);
solana_program::program::invoke(
&transfer_to_player,
&[
ctx.accounts.game.to_account_info(),
ctx.accounts.player.to_account_info(),
ctx.accounts.system_program.to_account_info(),
],
)?;
}
...