1- use batch:: process_batch;
21use pinocchio:: {
32 account_info:: AccountInfo , default_panic_handler, no_allocator, program_entrypoint,
43 program_error:: ProgramError , pubkey:: Pubkey , ProgramResult ,
@@ -12,6 +11,27 @@ no_allocator!();
1211// Use the default panic handler.
1312default_panic_handler ! ( ) ;
1413
14+ #[ inline( always) ]
15+ pub fn process_instruction (
16+ _program_id : & Pubkey ,
17+ accounts : & [ AccountInfo ] ,
18+ instruction_data : & [ u8 ] ,
19+ ) -> ProgramResult {
20+ let [ discriminator, instruction_data @ ..] = instruction_data else {
21+ return Err ( ProgramError :: InvalidInstructionData ) ;
22+ } ;
23+
24+ if * discriminator == 255 {
25+ // 255 - Batch
26+ #[ cfg( feature = "logging" ) ]
27+ pinocchio:: msg!( "Instruction: Batch" ) ;
28+
29+ return process_batch ( accounts, instruction_data) ;
30+ }
31+
32+ inner_process_instruction ( accounts, instruction_data, * discriminator)
33+ }
34+
1535/// Process an instruction.
1636///
1737/// The processor of the token program is divided into two parts to reduce the overhead
@@ -22,32 +42,35 @@ default_panic_handler!();
2242///
2343/// Instructions on the first part of the processor:
2444///
25- /// - `0`: `InitializeMint`
26- /// - `3`: `Transfer`
27- /// - `7`: `MintTo`
28- /// - `9`: `CloseAccount`
45+ /// - `0`: `InitializeMint`
46+ /// - `1`: `InitializeAccount`
47+ /// - `3`: `Transfer`
48+ /// - `7`: `MintTo`
49+ /// - `9`: `CloseAccount`
50+ /// - `18`: `InitializeAccount2`
2951/// - `18`: `InitializeAccount3`
3052/// - `20`: `InitializeMint2`
31- /// - `255`: `Batch`
3253#[ inline( always) ]
33- pub fn process_instruction (
34- _program_id : & Pubkey ,
54+ pub fn inner_process_instruction (
3555 accounts : & [ AccountInfo ] ,
3656 instruction_data : & [ u8 ] ,
57+ discriminator : u8 ,
3758) -> ProgramResult {
38- let [ discriminator, instruction_data @ ..] = instruction_data else {
39- return Err ( ProgramError :: InvalidInstructionData ) ;
40- } ;
41-
42- match * discriminator {
59+ match discriminator {
4360 // 0 - InitializeMint
4461 0 => {
4562 #[ cfg( feature = "logging" ) ]
4663 pinocchio:: msg!( "Instruction: InitializeMint" ) ;
4764
4865 process_initialize_mint ( accounts, instruction_data, true )
4966 }
67+ // 1 - InitializeAccount
68+ 1 => {
69+ #[ cfg( feature = "logging" ) ]
70+ pinocchio:: msg!( "Instruction: InitializeAccount" ) ;
5071
72+ process_initialize_account ( accounts)
73+ }
5174 // 3 - Transfer
5275 3 => {
5376 #[ cfg( feature = "logging" ) ]
@@ -69,6 +92,13 @@ pub fn process_instruction(
6992
7093 process_close_account ( accounts)
7194 }
95+ // 16 - InitializeAccount2
96+ 16 => {
97+ #[ cfg( feature = "logging" ) ]
98+ pinocchio:: msg!( "Instruction: InitializeAccount2" ) ;
99+
100+ process_initialize_account2 ( accounts, instruction_data)
101+ }
72102 // 18 - InitializeAccount3
73103 18 => {
74104 #[ cfg( feature = "logging" ) ]
@@ -83,14 +113,7 @@ pub fn process_instruction(
83113
84114 process_initialize_mint2 ( accounts, instruction_data)
85115 }
86- // 255 - Batch
87- 255 => {
88- #[ cfg( feature = "logging" ) ]
89- pinocchio:: msg!( "Instruction: Batch" ) ;
90-
91- process_batch ( accounts, instruction_data)
92- }
93- _ => process_remaining_instruction ( accounts, instruction_data, * discriminator) ,
116+ _ => inner_process_remaining_instruction ( accounts, instruction_data, discriminator) ,
94117 }
95118}
96119
@@ -99,19 +122,12 @@ pub fn process_instruction(
99122/// This function is called by the `process_instruction` function if the discriminator
100123/// does not match any of the common instructions. This function is used to reduce the
101124/// overhead of having a large `match` statement in the `process_instruction` function.
102- fn process_remaining_instruction (
125+ fn inner_process_remaining_instruction (
103126 accounts : & [ AccountInfo ] ,
104127 instruction_data : & [ u8 ] ,
105128 discriminator : u8 ,
106129) -> ProgramResult {
107130 match discriminator {
108- // 1 - InitializeAccount
109- 1 => {
110- #[ cfg( feature = "logging" ) ]
111- pinocchio:: msg!( "Instruction: InitializeAccount" ) ;
112-
113- process_initialize_account ( accounts)
114- }
115131 // 2 - InitializeMultisig
116132 2 => {
117133 #[ cfg( feature = "logging" ) ]
@@ -189,13 +205,6 @@ fn process_remaining_instruction(
189205
190206 process_burn_checked ( accounts, instruction_data)
191207 }
192- // 16 - InitializeAccount2
193- 16 => {
194- #[ cfg( feature = "logging" ) ]
195- pinocchio:: msg!( "Instruction: InitializeAccount2" ) ;
196-
197- process_initialize_account2 ( accounts, instruction_data)
198- }
199208 // 17 - SyncNative
200209 17 => {
201210 #[ cfg( feature = "logging" ) ]
0 commit comments