From 888329b8d3a6a5f42a47703b05be7b250928480d Mon Sep 17 00:00:00 2001 From: Joby Ingram-Dodd Date: Fri, 19 Nov 2021 19:56:27 +0000 Subject: [PATCH] f --- programs/myepicproject/src/lib.rs | 35 +++++++++++++++++++++++-------- tests/myepicproject.js | 4 ++-- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/programs/myepicproject/src/lib.rs b/programs/myepicproject/src/lib.rs index de44d52..2f2e7e2 100644 --- a/programs/myepicproject/src/lib.rs +++ b/programs/myepicproject/src/lib.rs @@ -17,7 +17,10 @@ pub mod myepicproject { pub fn add_gif(ctx: Context, image_link: String, pool_name: String, pool_desc: String, win_opt:String, close: u32, verify:String, fee:u8) -> ProgramResult { let base_account = &mut ctx.accounts.base_account; let wins: Vec = win_opt.split(';').map(|s| s.trim().to_string()).collect(); //chars().filter(|c| !c.is_whitespace()).collect() + // make a program address which will hold the SOL for this pool + let pool_wallet = &ctx.accounts.pool_wallet; let pool = PoolStruct{ + pool_wallet: pool_wallet.to_account_info().key.to_string(), pool_id: base_account.total_pools, image_link: image_link.to_string(), user_address: *base_account.to_account_info().key, @@ -37,8 +40,8 @@ pub mod myepicproject { Ok(()) } - pub fn add_result(ctx: Context, pool_id:u32, result:String) -> ProgramResult{ - //TODO; Make this only callable by the pool owner. + pub fn add_result(ctx: Context,result:String, pool_id:u32 ) -> ProgramResult{ + //TODO: Make this only callable by the pool owner. let base_account = &mut ctx.accounts.base_account; let mut i = 0; let mut found = false; @@ -55,11 +58,12 @@ pub mod myepicproject { }; Ok(()) } - - pub fn place_bet(ctx: Context, pool_id:u32, stake_bal:u32, user:String, pred: String) -> ProgramResult { + + pub fn place_bet(ctx: Context, pred: String, pool_id:u32, stake_bal:u32, user:String) -> ProgramResult { let base_account = &mut ctx.accounts.base_account; // TODO: check prediction is one of possible options // TODO: Add payment to this function + // TODO: make sure today is before the close date. let bet = EntryStruct{ user: user, prediction: pred, @@ -95,15 +99,22 @@ pub struct StartStuffOff<'info> { pub struct AddGif<'info> { #[account(mut)] pub base_account: Account<'info, BaseAccount>, -} -#[derive(Accounts)] -pub struct PlaceBet<'info>{ - #[account(mut)] - pub base_account: Account<'info, BaseAccount>, + #[account(init, payer = user, space=9000)] + pub pool_wallet: Account<'info, PoolWallet>, + pub user: Signer<'info>, + pub system_program: Program<'info, System> } +// #[derive(Accounts)] +// pub struct PlaceBet<'info>{ +// #[account(mut)] +// pub base_account: Account<'info, BaseAccount>, +// } + + #[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize)] pub struct PoolStruct{ + pub pool_wallet: String, pub pool_id: u32, pub image_link: String, pub user_address: Pubkey, @@ -114,6 +125,7 @@ pub struct PoolStruct{ pub close_date_time: u32, pub verify_url: String, pub owner_fee: u8, + // TODO: to allow for pools with more then 1 winning result perhaps result should be an array? pub result: String, pub closed: bool, pub entries: Vec @@ -130,4 +142,9 @@ pub struct EntryStruct{ pub struct BaseAccount { pub total_pools: u32, pub pool_list: Vec, +} + +#[account] +pub struct PoolWallet{ + pub balance: u64 } \ No newline at end of file diff --git a/tests/myepicproject.js b/tests/myepicproject.js index e4abf54..a32767f 100644 --- a/tests/myepicproject.js +++ b/tests/myepicproject.js @@ -36,12 +36,12 @@ const main = async() => { baseAccount: baseAccount.publicKey, } }); - await program.rpc.addResult(0,"winner 1",{ + await program.rpc.addResult("winner 1",0,{ accounts: { baseAccount: baseAccount.publicKey, } }); - await program.rpc.placeBet(1,125,"user", "winner 1", { + await program.rpc.placeBet("winner 1",1,125,"user", { accounts: { baseAccount: baseAccount.publicKey, }