join check

This commit is contained in:
Sewmina Dilshan 2025-04-04 15:01:12 +05:30
parent b745747acd
commit 5e0e4b48e2
6 changed files with 12 additions and 10 deletions

View File

@ -5,7 +5,7 @@ resolution = true
skip-lint = false
[programs.localnet]
bets = "HxsDuhD7wcPxcMsrYdteMYxkffuwff8HoxhZ7NuFtM37"
bets = "JAf3ZkQ469okXAzA6BKJeKBb9ZkCtZanULaUsapskoyn"
[registry]
url = "https://api.apr.dev"

View File

@ -11,10 +11,8 @@ pub enum ErrorCode {
pub enum BettingError {
#[msg("Bet is not filled yet!")]
BetNotFilled,
}
#[error_code]
pub enum BetError {
#[msg("Bet is already filled")]
BetAlreadyFilled,
#[msg("The winner must be either the owner or the joiner of the bet.")]
InvalidWinner,
}

View File

@ -1,11 +1,11 @@
use anchor_lang::prelude::*;
use crate::{error::BetError, *};
use crate::{error::BettingError, *};
pub fn close(ctx: Context<CloseBet>, winner:Pubkey)->Result<()>{
let bet_vault = &mut ctx.accounts.bet_vault;
require!(
bet_vault.owner == winner || bet_vault.joiner == winner,
BetError::InvalidWinner
BettingError::InvalidWinner
);
let bets_list = &mut ctx.accounts.bets_list;

View File

@ -29,7 +29,7 @@ pub fn create(ctx: Context<CreateBet>, wager: u64, user_id:String, game_id:Strin
}
#[derive(Accounts)]
#[instruction(wager: u64, game_id: String, _nonce:u64)]
#[instruction(wager: u64,user_id:String, game_id: String, _nonce:u64)]
pub struct CreateBet<'info> {
#[account(mut)]
pub payer: Signer<'info>,

View File

@ -1,8 +1,12 @@
use anchor_lang::prelude::*;
use crate::*;
use crate::{error::BettingError, *};
pub fn join(ctx: Context<JoinBet>,user_id:String, _game_id:String) ->Result<()>{
let bet_vault = &mut ctx.accounts.bet_vault;
require!(
bet_vault.joiner == Pubkey::default(),
BettingError::BetAlreadyFilled
);
let payer= &ctx.accounts.payer;
let ix = anchor_lang::solana_program::system_instruction::transfer(

View File

@ -9,7 +9,7 @@ pub use constants::*;
pub use instructions::*;
pub use state::*;
declare_id!("HxsDuhD7wcPxcMsrYdteMYxkffuwff8HoxhZ7NuFtM37");
declare_id!("JAf3ZkQ469okXAzA6BKJeKBb9ZkCtZanULaUsapskoyn");
#[program]
pub mod bets {