Last active
November 28, 2021 17:47
-
-
Save vedantroy/bbc23a19a5e5126198590cd7fd4f9d09 to your computer and use it in GitHub Desktop.
Creating singleton / global state for Solana program
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!("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