mpl_token_auth_rules/processor/
mod.rs1mod create_or_update;
6mod puff_rule_set;
7mod validate;
8mod write_to_buffer;
9
10use borsh::BorshDeserialize;
11use solana_program::{
12 account_info::AccountInfo, entrypoint::ProgramResult, msg, program_error::ProgramError,
13 pubkey::Pubkey,
14};
15
16use crate::{
17 instruction::RuleSetInstruction,
18 processor::{
19 create_or_update::create_or_update, puff_rule_set::puff_rule_set, validate::validate,
20 write_to_buffer::write_to_buffer,
21 },
22};
23
24pub use crate::utils::cmp_pubkeys;
25
26pub struct Processor;
28impl Processor {
29 pub fn process_instruction<'a>(
31 program_id: &Pubkey,
32 accounts: &'a [AccountInfo<'a>],
33 instruction_data: &[u8],
34 ) -> ProgramResult {
35 let instruction = RuleSetInstruction::try_from_slice(instruction_data)?;
36 match instruction {
37 RuleSetInstruction::CreateOrUpdate(args) => {
38 msg!("Instruction: CreateOrUpdate");
39 create_or_update(program_id, accounts, args)
40 }
41 RuleSetInstruction::Validate(args) => {
42 msg!("Instruction: Validate");
43 validate(program_id, accounts, args)
44 }
45 RuleSetInstruction::WriteToBuffer(args) => {
46 msg!("Instruction: WriteToBuffer");
47 write_to_buffer(program_id, accounts, args)
48 }
49 RuleSetInstruction::PuffRuleSet(args) => {
50 msg!("Instruction: PuffRuleSet");
51 puff_rule_set(program_id, accounts, args)
52 }
53 }
54 }
55}
56
57pub fn next_optional_account_info<'a, 'b, I: Iterator<Item = &'a AccountInfo<'b>>>(
64 iter: &mut I,
65) -> Result<Option<I::Item>, ProgramError> {
66 let account_info = iter.next().ok_or(ProgramError::NotEnoughAccountKeys)?;
67
68 Ok(if cmp_pubkeys(account_info.key, &crate::id()) {
69 None
70 } else {
71 Some(account_info)
72 })
73}