Skip to content

Instantly share code, notes, and snippets.

@vedantroy
Last active November 28, 2021 17:47
Show Gist options
  • Save vedantroy/bbc23a19a5e5126198590cd7fd4f9d09 to your computer and use it in GitHub Desktop.
Save vedantroy/bbc23a19a5e5126198590cd7fd4f9d09 to your computer and use it in GitHub Desktop.
Creating singleton / global state for Solana program
use anchor_lang::prelude::*;
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
#[program]
pub mod auction {
use super::*;
pub fn create_game_state(ctx: Context<CreateGameState>) -> ProgramResult {
Ok(())
}
}
#[derive(Accounts)]
#[instruction(bump: u8)]
pub struct CreateGameState<'info> {
#[account(init, payer=user,
space=GameState::space(),
seeds=[
b"Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS",
],
bump=bump)]
pub data: Account<'info, GameState>,
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[account]
pub struct GameState {
pub bump: u8,
}
impl GameState {
fn space() -> usize {
// discriminator + bump
8 + 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment