Created
April 9, 2022 17:13
-
-
Save 0xPratik/8ed850699e9842a7aa9e0a854c9f8e83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use anchor_lang::prelude::*; | |
declare_id!("FxzpC2SfGDzCRa5Y1e3ya39nL8UdoNZnq1225pMdthWF"); | |
#[program] | |
pub mod brianxyz { | |
use super::*; | |
pub fn initialize(ctx: Context<Initialize>) -> Result<()> { | |
let vote_account = &mut ctx.accounts.vote_account; | |
vote_account.bump = *ctx.bumps.get("vote_account").unwrap(); | |
vote_account.super_man = 0; | |
vote_account.iron_man = 0; | |
Ok(()) | |
} | |
pub fn vote_super_man(ctx: Context<Vote>) -> Result<()> { | |
let vote_account = &mut ctx.accounts.vote_account; | |
vote_account.super_man += 1; | |
Ok(()) | |
} | |
pub fn vote_iron_man(ctx: Context<Vote>) -> Result<()> { | |
let vote_account = &mut ctx.accounts.vote_account; | |
vote_account.iron_man += 1; | |
Ok(()) | |
} | |
} | |
#[derive(Accounts)] | |
pub struct Initialize<'info> { | |
#[account(init,payer=user,seeds=[b"vote_account".as_ref()],bump,space=100)] | |
pub vote_account: Account<'info, VoteAccount>, | |
#[account(mut)] | |
pub user: Signer<'info>, | |
pub system_program: Program<'info, System>, | |
} | |
#[derive(Accounts)] | |
pub struct Vote<'info> { | |
#[account(mut)] | |
pub vote_account: Account<'info, VoteAccount>, | |
} | |
#[account] | |
#[derive(Default)] | |
pub struct VoteAccount { | |
pub super_man: u64, | |
pub iron_man: u64, | |
pub bump: u8, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment