Last active
February 4, 2022 00:39
-
-
Save TheFredStar1/9f6f72ce6df32fab8077673c5957f7ca 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!("GofNwzpGJNLTk5m2ME9iYbdT2X9ofuzrDPmio8Kg6oG1"); | |
#[program] | |
pub mod crunchy_vs_smooth { | |
use super::*; | |
pub fn initialize(ctx: Context<Initialize>, vote_account_bump: u8) -> ProgramResult { | |
ctx.accounts.voteting_state.bump = vote_account_bump; | |
Ok(()) | |
} | |
pub fn vote_crunchy(ctx: Context<Vote>) -> ProgramResult { | |
ctx.accounts.voteing_state.crunchy += 1; | |
Ok(()) | |
} | |
pub fn vote_smooth(ctx: Context<Vote>) -> ProgramResult { | |
ctx.accounts.voteing_state.smooth += 1; | |
Ok(()) | |
} | |
} | |
#[derive(Accounts)] | |
#[instruction(vote_account_bump: u8)] | |
pub struct Initialize<'info> { | |
#[account(init, payer = voter, seeds = [b"vote_state".as_ref()], bump = vote_account_bump)] | |
pub voteting_state: Account<'info, VotingState>, | |
#[account(mut)] | |
pub voter: Signer<'info>, | |
pub system_program: Program<'info, System> | |
} | |
#[account] | |
#[derive(Default)] | |
pub struct VotingState { | |
pub crunchy: u64, | |
pub smooth: u64, | |
pub bump: u8 | |
} | |
#[derive(Accounts)] | |
pub struct Vote<'info> { | |
#[account(mut, seeds = [b"vote_state".as_ref()], bump = voteing_state.bump )] | |
pub voteing_state: Account<'info, VotingState> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Program Derived Address for Solana Account Example