-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessor.rs
36 lines (33 loc) · 1.17 KB
/
processor.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use borsh::{BorshDeserialize, BorshSerialize};
use common::instruction::CounterInstruction;
use common::state::Counter;
use solana_program::{
account_info::{next_account_info, AccountInfo},
entrypoint::ProgramResult,
msg,
program_error::ProgramError,
pubkey::Pubkey,
};
pub struct Processor {}
impl Processor {
pub fn process_instruction(
_program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
let instruction = CounterInstruction::try_from_slice(instruction_data)
.map_err(|_| ProgramError::InvalidInstructionData)?;
match instruction {
CounterInstruction::Increament => {
msg!("Instruction increament");
let accounts_iter = &mut accounts.iter();
let counter_acc_info = next_account_info(accounts_iter)?;
let mut counter = Counter::try_from_slice(&counter_acc_info.data.borrow())?;
counter.count += 1;
msg!("Updating counter {}", counter.count);
counter.serialize(&mut *counter_acc_info.data.borrow_mut())?;
}
}
Ok(())
}
}