use pina::*;
declare_id!("GJQcuWrT2f3f4KNuJcXhhwUa1ZQTYbxzzJ1hotzKu8hS");
#[discriminator(entrypoint)]
pub enum CounterInstruction {
Initialize = 0,
Increment = 1,
}
#[discriminator]
pub enum CounterAccountType {
CounterState = 1,
}
// 11 bytes on-chain: discriminator, version, bump, count.
#[account(discriminator = CounterAccountType)]
#[pda(seeds = [SEED_COUNTER, authority: Address], bump = bump)]
pub struct CounterState {
pub bump: u8,
pub count: u64,
}
#[instruction(discriminator = CounterInstruction::Increment)]
pub struct IncrementInstruction {}
#[derive(Accounts, Debug)]
pub struct IncrementAccounts<'a> {
pub authority: &'a AccountView,
pub counter: &'a mut AccountView,
}
impl<'a> ProcessAccountInfos<'a> for IncrementAccounts<'a> {
fn process(self, data: &[u8]) -> ProgramResult {
let _ = IncrementInstruction::try_from_bytes(data)?;
self.authority.assert_signer()?;
let mut counter = CounterState::load_pda_mut(
self.counter, self.authority.address(), &ID,
)?;
let next = counter.count.get()
.checked_add(1)
.ok_or(ProgramError::ArithmeticOverflow)?;
counter.count.set(next);
Ok(())
}
}
dispatch_entrypoint!(CounterInstruction);
$ npm install --global @pina-rs/cli
$ pina init my_program && cd my_program
$ pina doctor # check every prerequisite
$ pina build # SBF binary and Codama IDL
$ pina test # Mollusk and Surfpool suites
$ pina lint # security lints on your source
$ pina profile # static compute-unit estimate
$ pina generate # Rust, TypeScript and Dart clients
$ pina deploy --rehearse # replay real traffic first