@@ -2,6 +2,7 @@ use pinocchio::{
22 account_info:: AccountInfo , default_panic_handler, no_allocator, program_entrypoint,
33 program_error:: ProgramError , pubkey:: Pubkey , ProgramResult ,
44} ;
5+ use spl_token_interface:: instruction:: TokenInstruction ;
56
67use crate :: processor:: * ;
78
@@ -36,52 +37,53 @@ pub fn process_instruction(
3637 let ( discriminator, instruction_data) = instruction_data
3738 . split_first ( )
3839 . ok_or ( ProgramError :: InvalidInstructionData ) ?;
40+ let instruction = TokenInstruction :: try_from ( * discriminator) ?;
3941
40- match * discriminator {
42+ match instruction {
4143 // 0 - InitializeMint
42- 0 => {
44+ TokenInstruction :: InitializeMint => {
4345 #[ cfg( feature = "logging" ) ]
4446 pinocchio:: msg!( "Instruction: InitializeMint" ) ;
4547
46- process_initialize_mint ( accounts, instruction_data, true )
48+ process_initialize_mint ( accounts, instruction_data)
4749 }
4850
4951 // 3 - Transfer
50- 3 => {
52+ TokenInstruction :: Transfer => {
5153 #[ cfg( feature = "logging" ) ]
5254 pinocchio:: msg!( "Instruction: Transfer" ) ;
5355
5456 process_transfer ( accounts, instruction_data)
5557 }
5658 // 7 - MintTo
57- 7 => {
59+ TokenInstruction :: MintTo => {
5860 #[ cfg( feature = "logging" ) ]
5961 pinocchio:: msg!( "Instruction: MintTo" ) ;
6062
6163 process_mint_to ( accounts, instruction_data)
6264 }
6365 // 9 - CloseAccount
64- 9 => {
66+ TokenInstruction :: CloseAccount => {
6567 #[ cfg( feature = "logging" ) ]
6668 pinocchio:: msg!( "Instruction: CloseAccount" ) ;
6769
6870 process_close_account ( accounts)
6971 }
7072 // 18 - InitializeAccount3
71- 18 => {
73+ TokenInstruction :: InitializeAccount3 => {
7274 #[ cfg( feature = "logging" ) ]
7375 pinocchio:: msg!( "Instruction: InitializeAccount3" ) ;
7476
7577 process_initialize_account3 ( accounts, instruction_data)
7678 }
7779 // 20 - InitializeMint2
78- 20 => {
80+ TokenInstruction :: InitializeMint2 => {
7981 #[ cfg( feature = "logging" ) ]
8082 pinocchio:: msg!( "Instruction: InitializeMint2" ) ;
8183
8284 process_initialize_mint2 ( accounts, instruction_data)
8385 }
84- _ => process_remaining_instruction ( accounts, instruction_data, * discriminator ) ,
86+ _ => process_remaining_instruction ( accounts, instruction_data, instruction ) ,
8587 }
8688}
8789
@@ -93,137 +95,137 @@ pub fn process_instruction(
9395fn process_remaining_instruction (
9496 accounts : & [ AccountInfo ] ,
9597 instruction_data : & [ u8 ] ,
96- discriminator : u8 ,
98+ instruction : TokenInstruction ,
9799) -> ProgramResult {
98- match discriminator {
100+ match instruction {
99101 // 1 - InitializeAccount
100- 1 => {
102+ TokenInstruction :: InitializeAccount => {
101103 #[ cfg( feature = "logging" ) ]
102104 pinocchio:: msg!( "Instruction: InitializeAccount" ) ;
103105
104106 process_initialize_account ( accounts)
105107 }
106108 // 2 - InitializeMultisig
107- 2 => {
109+ TokenInstruction :: InitializeMultisig => {
108110 #[ cfg( feature = "logging" ) ]
109111 pinocchio:: msg!( "Instruction: InitializeMultisig" ) ;
110112
111113 process_initialize_multisig ( accounts, instruction_data)
112114 }
113115 // 4 - Approve
114- 4 => {
116+ TokenInstruction :: Approve => {
115117 #[ cfg( feature = "logging" ) ]
116118 pinocchio:: msg!( "Instruction: Approve" ) ;
117119
118120 process_approve ( accounts, instruction_data)
119121 }
120122 // 5 - Revoke
121- 5 => {
123+ TokenInstruction :: Revoke => {
122124 #[ cfg( feature = "logging" ) ]
123125 pinocchio:: msg!( "Instruction: Revoke" ) ;
124126
125127 process_revoke ( accounts, instruction_data)
126128 }
127129 // 6 - SetAuthority
128- 6 => {
130+ TokenInstruction :: SetAuthority => {
129131 #[ cfg( feature = "logging" ) ]
130132 pinocchio:: msg!( "Instruction: SetAuthority" ) ;
131133
132134 process_set_authority ( accounts, instruction_data)
133135 }
134136 // 8 - Burn
135- 8 => {
137+ TokenInstruction :: Burn => {
136138 #[ cfg( feature = "logging" ) ]
137139 pinocchio:: msg!( "Instruction: Burn" ) ;
138140
139141 process_burn ( accounts, instruction_data)
140142 }
141143 // 10 - FreezeAccount
142- 10 => {
144+ TokenInstruction :: FreezeAccount => {
143145 #[ cfg( feature = "logging" ) ]
144146 pinocchio:: msg!( "Instruction: FreezeAccount" ) ;
145147
146148 process_freeze_account ( accounts)
147149 }
148150 // 11 - ThawAccount
149- 11 => {
151+ TokenInstruction :: ThawAccount => {
150152 #[ cfg( feature = "logging" ) ]
151153 pinocchio:: msg!( "Instruction: ThawAccount" ) ;
152154
153155 process_thaw_account ( accounts)
154156 }
155157 // 12 - TransferChecked
156- 12 => {
158+ TokenInstruction :: TransferChecked => {
157159 #[ cfg( feature = "logging" ) ]
158160 pinocchio:: msg!( "Instruction: TransferChecked" ) ;
159161
160162 process_transfer_checked ( accounts, instruction_data)
161163 }
162164 // 13 - ApproveChecked
163- 13 => {
165+ TokenInstruction :: ApproveChecked => {
164166 #[ cfg( feature = "logging" ) ]
165167 pinocchio:: msg!( "Instruction: ApproveChecked" ) ;
166168
167169 process_approve_checked ( accounts, instruction_data)
168170 }
169171 // 14 - MintToChecked
170- 14 => {
172+ TokenInstruction :: MintToChecked => {
171173 #[ cfg( feature = "logging" ) ]
172174 pinocchio:: msg!( "Instruction: MintToChecked" ) ;
173175
174176 process_mint_to_checked ( accounts, instruction_data)
175177 }
176178 // 15 - BurnChecked
177- 15 => {
179+ TokenInstruction :: BurnChecked => {
178180 #[ cfg( feature = "logging" ) ]
179181 pinocchio:: msg!( "Instruction: BurnChecked" ) ;
180182
181183 process_burn_checked ( accounts, instruction_data)
182184 }
183185 // 16 - InitializeAccount2
184- 16 => {
186+ TokenInstruction :: InitializeAccount2 => {
185187 #[ cfg( feature = "logging" ) ]
186188 pinocchio:: msg!( "Instruction: InitializeAccount2" ) ;
187189
188190 process_initialize_account2 ( accounts, instruction_data)
189191 }
190192 // 17 - SyncNative
191- 17 => {
193+ TokenInstruction :: SyncNative => {
192194 #[ cfg( feature = "logging" ) ]
193195 pinocchio:: msg!( "Instruction: SyncNative" ) ;
194196
195197 process_sync_native ( accounts)
196198 }
197199 // 19 - InitializeMultisig2
198- 19 => {
200+ TokenInstruction :: InitializeMultisig2 => {
199201 #[ cfg( feature = "logging" ) ]
200202 pinocchio:: msg!( "Instruction: InitializeMultisig2" ) ;
201203
202204 process_initialize_multisig2 ( accounts, instruction_data)
203205 }
204206 // 21 - GetAccountDataSize
205- 21 => {
207+ TokenInstruction :: GetAccountDataSize => {
206208 #[ cfg( feature = "logging" ) ]
207209 pinocchio:: msg!( "Instruction: GetAccountDataSize" ) ;
208210
209211 process_get_account_data_size ( accounts)
210212 }
211213 // 22 - InitializeImmutableOwner
212- 22 => {
214+ TokenInstruction :: InitializeImmutableOwner => {
213215 #[ cfg( feature = "logging" ) ]
214216 pinocchio:: msg!( "Instruction: InitializeImmutableOwner" ) ;
215217
216218 process_initialize_immutable_owner ( accounts)
217219 }
218220 // 23 - AmountToUiAmount
219- 23 => {
221+ TokenInstruction :: AmountToUiAmount => {
220222 #[ cfg( feature = "logging" ) ]
221223 pinocchio:: msg!( "Instruction: AmountToUiAmount" ) ;
222224
223225 process_amount_to_ui_amount ( accounts, instruction_data)
224226 }
225227 // 24 - UiAmountToAmount
226- 24 => {
228+ TokenInstruction :: UiAmountToAmount => {
227229 #[ cfg( feature = "logging" ) ]
228230 pinocchio:: msg!( "Instruction: UiAmountToAmount" ) ;
229231
0 commit comments