Skip to content

Instantly share code, notes, and snippets.

@dharniel45
Created December 26, 2022 10:04
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 dharniel45/69bd889abd6179c9bfa94b00ab1247f6 to your computer and use it in GitHub Desktop.
Save dharniel45/69bd889abd6179c9bfa94b00ab1247f6 to your computer and use it in GitHub Desktop.
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::{
account_info::{next_account_info, AccountInfo},
entrypoint,
program_error::ProgramError,
pubkey::Pubkey,
};
#[derive(BorshSerialize, BorshDeserialize, Debug)]
pub struct GreetingAccount {
pub counter: u32,
}
#[cfg(not(feature = "exclude_entrypoint"))]
entrypoint!(process_instruction);
pub fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> entrypoint::ProgramResult {
let accounts_iter = &mut accounts.iter();
let account = next_account_info(accounts_iter)?;
if account.owner != program_id {
return Err(ProgramError::IncorrectProgramId);
}
let mut greeting = GreetingAccount::try_from_slice(&account.data.borrow())?;
greeting.counter += 1;
greeting.serialize(&mut &mut account.data.borrow_mut()[..])?;
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment