@@ -2,6 +2,7 @@ use pinocchio::{
2
2
account_info:: AccountInfo , default_panic_handler, no_allocator, program_entrypoint,
3
3
program_error:: ProgramError , pubkey:: Pubkey , ProgramResult ,
4
4
} ;
5
+ use spl_token_interface:: instruction:: TokenInstruction ;
5
6
6
7
use crate :: processor:: * ;
7
8
@@ -36,52 +37,53 @@ pub fn process_instruction(
36
37
let ( discriminator, instruction_data) = instruction_data
37
38
. split_first ( )
38
39
. ok_or ( ProgramError :: InvalidInstructionData ) ?;
40
+ let instruction = TokenInstruction :: try_from ( * discriminator) ?;
39
41
40
- match * discriminator {
42
+ match instruction {
41
43
// 0 - InitializeMint
42
- 0 => {
44
+ TokenInstruction :: InitializeMint => {
43
45
#[ cfg( feature = "logging" ) ]
44
46
pinocchio:: msg!( "Instruction: InitializeMint" ) ;
45
47
46
- process_initialize_mint ( accounts, instruction_data, true )
48
+ process_initialize_mint ( accounts, instruction_data)
47
49
}
48
50
49
51
// 3 - Transfer
50
- 3 => {
52
+ TokenInstruction :: Transfer => {
51
53
#[ cfg( feature = "logging" ) ]
52
54
pinocchio:: msg!( "Instruction: Transfer" ) ;
53
55
54
56
process_transfer ( accounts, instruction_data)
55
57
}
56
58
// 7 - MintTo
57
- 7 => {
59
+ TokenInstruction :: MintTo => {
58
60
#[ cfg( feature = "logging" ) ]
59
61
pinocchio:: msg!( "Instruction: MintTo" ) ;
60
62
61
63
process_mint_to ( accounts, instruction_data)
62
64
}
63
65
// 9 - CloseAccount
64
- 9 => {
66
+ TokenInstruction :: CloseAccount => {
65
67
#[ cfg( feature = "logging" ) ]
66
68
pinocchio:: msg!( "Instruction: CloseAccount" ) ;
67
69
68
70
process_close_account ( accounts)
69
71
}
70
72
// 18 - InitializeAccount3
71
- 18 => {
73
+ TokenInstruction :: InitializeAccount3 => {
72
74
#[ cfg( feature = "logging" ) ]
73
75
pinocchio:: msg!( "Instruction: InitializeAccount3" ) ;
74
76
75
77
process_initialize_account3 ( accounts, instruction_data)
76
78
}
77
79
// 20 - InitializeMint2
78
- 20 => {
80
+ TokenInstruction :: InitializeMint2 => {
79
81
#[ cfg( feature = "logging" ) ]
80
82
pinocchio:: msg!( "Instruction: InitializeMint2" ) ;
81
83
82
84
process_initialize_mint2 ( accounts, instruction_data)
83
85
}
84
- _ => process_remaining_instruction ( accounts, instruction_data, * discriminator ) ,
86
+ _ => process_remaining_instruction ( accounts, instruction_data, instruction ) ,
85
87
}
86
88
}
87
89
@@ -93,137 +95,137 @@ pub fn process_instruction(
93
95
fn process_remaining_instruction (
94
96
accounts : & [ AccountInfo ] ,
95
97
instruction_data : & [ u8 ] ,
96
- discriminator : u8 ,
98
+ instruction : TokenInstruction ,
97
99
) -> ProgramResult {
98
- match discriminator {
100
+ match instruction {
99
101
// 1 - InitializeAccount
100
- 1 => {
102
+ TokenInstruction :: InitializeAccount => {
101
103
#[ cfg( feature = "logging" ) ]
102
104
pinocchio:: msg!( "Instruction: InitializeAccount" ) ;
103
105
104
106
process_initialize_account ( accounts)
105
107
}
106
108
// 2 - InitializeMultisig
107
- 2 => {
109
+ TokenInstruction :: InitializeMultisig => {
108
110
#[ cfg( feature = "logging" ) ]
109
111
pinocchio:: msg!( "Instruction: InitializeMultisig" ) ;
110
112
111
113
process_initialize_multisig ( accounts, instruction_data)
112
114
}
113
115
// 4 - Approve
114
- 4 => {
116
+ TokenInstruction :: Approve => {
115
117
#[ cfg( feature = "logging" ) ]
116
118
pinocchio:: msg!( "Instruction: Approve" ) ;
117
119
118
120
process_approve ( accounts, instruction_data)
119
121
}
120
122
// 5 - Revoke
121
- 5 => {
123
+ TokenInstruction :: Revoke => {
122
124
#[ cfg( feature = "logging" ) ]
123
125
pinocchio:: msg!( "Instruction: Revoke" ) ;
124
126
125
127
process_revoke ( accounts, instruction_data)
126
128
}
127
129
// 6 - SetAuthority
128
- 6 => {
130
+ TokenInstruction :: SetAuthority => {
129
131
#[ cfg( feature = "logging" ) ]
130
132
pinocchio:: msg!( "Instruction: SetAuthority" ) ;
131
133
132
134
process_set_authority ( accounts, instruction_data)
133
135
}
134
136
// 8 - Burn
135
- 8 => {
137
+ TokenInstruction :: Burn => {
136
138
#[ cfg( feature = "logging" ) ]
137
139
pinocchio:: msg!( "Instruction: Burn" ) ;
138
140
139
141
process_burn ( accounts, instruction_data)
140
142
}
141
143
// 10 - FreezeAccount
142
- 10 => {
144
+ TokenInstruction :: FreezeAccount => {
143
145
#[ cfg( feature = "logging" ) ]
144
146
pinocchio:: msg!( "Instruction: FreezeAccount" ) ;
145
147
146
148
process_freeze_account ( accounts)
147
149
}
148
150
// 11 - ThawAccount
149
- 11 => {
151
+ TokenInstruction :: ThawAccount => {
150
152
#[ cfg( feature = "logging" ) ]
151
153
pinocchio:: msg!( "Instruction: ThawAccount" ) ;
152
154
153
155
process_thaw_account ( accounts)
154
156
}
155
157
// 12 - TransferChecked
156
- 12 => {
158
+ TokenInstruction :: TransferChecked => {
157
159
#[ cfg( feature = "logging" ) ]
158
160
pinocchio:: msg!( "Instruction: TransferChecked" ) ;
159
161
160
162
process_transfer_checked ( accounts, instruction_data)
161
163
}
162
164
// 13 - ApproveChecked
163
- 13 => {
165
+ TokenInstruction :: ApproveChecked => {
164
166
#[ cfg( feature = "logging" ) ]
165
167
pinocchio:: msg!( "Instruction: ApproveChecked" ) ;
166
168
167
169
process_approve_checked ( accounts, instruction_data)
168
170
}
169
171
// 14 - MintToChecked
170
- 14 => {
172
+ TokenInstruction :: MintToChecked => {
171
173
#[ cfg( feature = "logging" ) ]
172
174
pinocchio:: msg!( "Instruction: MintToChecked" ) ;
173
175
174
176
process_mint_to_checked ( accounts, instruction_data)
175
177
}
176
178
// 15 - BurnChecked
177
- 15 => {
179
+ TokenInstruction :: BurnChecked => {
178
180
#[ cfg( feature = "logging" ) ]
179
181
pinocchio:: msg!( "Instruction: BurnChecked" ) ;
180
182
181
183
process_burn_checked ( accounts, instruction_data)
182
184
}
183
185
// 16 - InitializeAccount2
184
- 16 => {
186
+ TokenInstruction :: InitializeAccount2 => {
185
187
#[ cfg( feature = "logging" ) ]
186
188
pinocchio:: msg!( "Instruction: InitializeAccount2" ) ;
187
189
188
190
process_initialize_account2 ( accounts, instruction_data)
189
191
}
190
192
// 17 - SyncNative
191
- 17 => {
193
+ TokenInstruction :: SyncNative => {
192
194
#[ cfg( feature = "logging" ) ]
193
195
pinocchio:: msg!( "Instruction: SyncNative" ) ;
194
196
195
197
process_sync_native ( accounts)
196
198
}
197
199
// 19 - InitializeMultisig2
198
- 19 => {
200
+ TokenInstruction :: InitializeMultisig2 => {
199
201
#[ cfg( feature = "logging" ) ]
200
202
pinocchio:: msg!( "Instruction: InitializeMultisig2" ) ;
201
203
202
204
process_initialize_multisig2 ( accounts, instruction_data)
203
205
}
204
206
// 21 - GetAccountDataSize
205
- 21 => {
207
+ TokenInstruction :: GetAccountDataSize => {
206
208
#[ cfg( feature = "logging" ) ]
207
209
pinocchio:: msg!( "Instruction: GetAccountDataSize" ) ;
208
210
209
211
process_get_account_data_size ( accounts)
210
212
}
211
213
// 22 - InitializeImmutableOwner
212
- 22 => {
214
+ TokenInstruction :: InitializeImmutableOwner => {
213
215
#[ cfg( feature = "logging" ) ]
214
216
pinocchio:: msg!( "Instruction: InitializeImmutableOwner" ) ;
215
217
216
218
process_initialize_immutable_owner ( accounts)
217
219
}
218
220
// 23 - AmountToUiAmount
219
- 23 => {
221
+ TokenInstruction :: AmountToUiAmount => {
220
222
#[ cfg( feature = "logging" ) ]
221
223
pinocchio:: msg!( "Instruction: AmountToUiAmount" ) ;
222
224
223
225
process_amount_to_ui_amount ( accounts, instruction_data)
224
226
}
225
227
// 24 - UiAmountToAmount
226
- 24 => {
228
+ TokenInstruction :: UiAmountToAmount => {
227
229
#[ cfg( feature = "logging" ) ]
228
230
pinocchio:: msg!( "Instruction: UiAmountToAmount" ) ;
229
231
0 commit comments