Skip to content

Instantly share code, notes, and snippets.

@TheFredStar1
Last active February 4, 2022 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheFredStar1/9f6f72ce6df32fab8077673c5957f7ca to your computer and use it in GitHub Desktop.
Save TheFredStar1/9f6f72ce6df32fab8077673c5957f7ca to your computer and use it in GitHub Desktop.
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>
}
@TheFredStar1
Copy link
Author

Program Derived Address for Solana Account Example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment