Add some methods and datastructures to contract implementation
This commit is contained in:
parent
634c0af85b
commit
eb3fed171d
|
@ -5,39 +5,88 @@ declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
|
||||||
#[program]
|
#[program]
|
||||||
pub mod dpm {
|
pub mod dpm {
|
||||||
use super::*;
|
use super::*;
|
||||||
pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
|
|
||||||
|
pub fn create_contract(ctx: Context<CreateContract>, props: NewContractProps) -> ProgramResult {
|
||||||
let contract = &mut ctx.accounts.contract;
|
let contract = &mut ctx.accounts.contract;
|
||||||
contract.bets = 0;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_bet(ctx: Context<AddBet>) -> ProgramResult {
|
pub fn place_bet(ctx: Context<PlaceBet>, props: BetProps) -> ProgramResult {
|
||||||
let contract = &mut ctx.accounts.contract;
|
|
||||||
contract.bets += 1;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
|
||||||
|
pub struct NewContractProps {
|
||||||
|
pub id: String,
|
||||||
|
pub creator_id: String,
|
||||||
|
pub question: String,
|
||||||
|
pub description: String,
|
||||||
|
pub seed_amounts: SeedAmounts,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Accounts)]
|
#[derive(Accounts)]
|
||||||
pub struct Initialize<'info> {
|
pub struct CreateContract<'info> {
|
||||||
#[account(init, payer = user, space = 9000)]
|
#[account(init, payer = creator, space = 9000)]
|
||||||
pub contract: Account<'info, Contract>,
|
pub contract: Account<'info, Contract>,
|
||||||
|
|
||||||
#[account(mut)]
|
#[account(mut)]
|
||||||
pub user: Signer<'info>,
|
pub creator: Signer<'info>,
|
||||||
|
|
||||||
pub system_program: Program<'info, System>,
|
pub system_program: Program<'info, System>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
|
||||||
|
pub struct BetProps {
|
||||||
|
pub amount: u64,
|
||||||
|
pub user_id: String,
|
||||||
|
pub outcome: BetOutcome,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Accounts)]
|
#[derive(Accounts)]
|
||||||
pub struct AddBet<'info> {
|
pub struct PlaceBet<'info> {
|
||||||
#[account(mut)]
|
#[account(mut)]
|
||||||
pub contract: Account<'info, Contract>,
|
pub contract: Account<'info, Contract>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
|
||||||
|
pub enum BetOutcome {
|
||||||
|
Yes,
|
||||||
|
No,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
|
||||||
|
pub enum ResolutionOutcome {
|
||||||
|
Yes,
|
||||||
|
No,
|
||||||
|
Cancel,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
|
||||||
|
pub struct SeedAmounts {
|
||||||
|
yes: u64,
|
||||||
|
no: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
|
||||||
|
pub struct Resolution {
|
||||||
|
time: u64,
|
||||||
|
outcome: ResolutionOutcome,
|
||||||
|
}
|
||||||
|
|
||||||
#[account]
|
#[account]
|
||||||
pub struct Contract {
|
pub struct Contract {
|
||||||
pub bets: u64,
|
pub id: String,
|
||||||
|
pub creator_id: String,
|
||||||
|
pub question: String,
|
||||||
|
pub description: String,
|
||||||
|
pub seed_amounts: SeedAmounts,
|
||||||
|
|
||||||
|
pub created_time: u64,
|
||||||
|
pub last_updated_time: u64,
|
||||||
|
|
||||||
|
pub resolution: Option<Resolution>
|
||||||
|
|
||||||
|
// pub bets: Vec<Bet>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user