Let’s write a native solana contract that has a
function that can be applied to a data account on the blockchain.
Assume that the data account needs to be initialised on the client before calling the client with it.
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::{
entrypoint,
account_info::{
next_account_info,
AccountInfo
},
entrypoint::ProgramResult,
pubkey::Pubkey,
program_error::ProgramError,
};
#[derive(BorshSerialize, BorshDeserialize)]
struct CounterState {
count: u32
}
#[derive(BorshSerialize, BorshDeserialize)]
enum Instruction {
Double,
Half,
Add { amount: u32 },
Subtract { amount: u32 },
}
entrypoint!(process_instruction);
fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8]
) -> ProgramResult {
}
let mut iter = accounts.iter();
let data_account = next_account_info(&mut iter)?;
if !data_account.is_signer {
return Err(ProgramError::MissingRequiredSignature);
}