Created
December 26, 2022 10:04
-
-
Save dharniel45/69bd889abd6179c9bfa94b00ab1247f6 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 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