@@ -3,11 +3,12 @@ use solana_zk_token_sdk::encryption::{auth_encryption::AeCiphertext, elgamal::El
3
3
pub use solana_zk_token_sdk:: zk_token_proof_instruction:: * ;
4
4
use {
5
5
crate :: {
6
- check_program_account, extension:: confidential_transfer:: * , instruction:: TokenInstruction ,
6
+ check_program_account,
7
+ extension:: confidential_transfer:: * ,
8
+ instruction:: { encode_instruction, TokenInstruction } ,
7
9
} ,
8
10
bytemuck:: { Pod , Zeroable } ,
9
- num_derive:: { FromPrimitive , ToPrimitive } ,
10
- num_traits:: { FromPrimitive , ToPrimitive } ,
11
+ num_enum:: { IntoPrimitive , TryFromPrimitive } ,
11
12
solana_program:: {
12
13
instruction:: { AccountMeta , Instruction } ,
13
14
program_error:: ProgramError ,
19
20
} ;
20
21
21
22
/// Confidential Transfer extension instructions
22
- #[ derive( Clone , Copy , Debug , FromPrimitive , ToPrimitive ) ]
23
+ #[ derive( Clone , Copy , Debug , TryFromPrimitive , IntoPrimitive ) ]
23
24
#[ repr( u8 ) ]
24
25
pub enum ConfidentialTransferInstruction {
25
26
/// Initializes confidential transfers for a mint.
@@ -434,40 +435,6 @@ pub struct WithdrawWithheldTokensFromAccountsData {
434
435
pub proof_instruction_offset : i8 ,
435
436
}
436
437
437
- pub ( crate ) fn decode_instruction_type (
438
- input : & [ u8 ] ,
439
- ) -> Result < ConfidentialTransferInstruction , ProgramError > {
440
- if input. is_empty ( ) {
441
- Err ( ProgramError :: InvalidInstructionData )
442
- } else {
443
- FromPrimitive :: from_u8 ( input[ 0 ] ) . ok_or ( ProgramError :: InvalidInstructionData )
444
- }
445
- }
446
-
447
- pub ( crate ) fn decode_instruction_data < T : Pod > ( input : & [ u8 ] ) -> Result < & T , ProgramError > {
448
- if input. is_empty ( ) {
449
- Err ( ProgramError :: InvalidInstructionData )
450
- } else {
451
- pod_from_bytes ( & input[ 1 ..] )
452
- }
453
- }
454
-
455
- fn encode_instruction < T : Pod > (
456
- token_program_id : & Pubkey ,
457
- accounts : Vec < AccountMeta > ,
458
- instruction_type : ConfidentialTransferInstruction ,
459
- instruction_data : & T ,
460
- ) -> Instruction {
461
- let mut data = TokenInstruction :: ConfidentialTransferExtension . pack ( ) ;
462
- data. push ( ToPrimitive :: to_u8 ( & instruction_type) . unwrap ( ) ) ;
463
- data. extend_from_slice ( bytemuck:: bytes_of ( instruction_data) ) ;
464
- Instruction {
465
- program_id : * token_program_id,
466
- accounts,
467
- data,
468
- }
469
- }
470
-
471
438
/// Create a `InitializeMint` instruction
472
439
pub fn initialize_mint (
473
440
token_program_id : & Pubkey ,
@@ -479,6 +446,7 @@ pub fn initialize_mint(
479
446
Ok ( encode_instruction (
480
447
token_program_id,
481
448
accounts,
449
+ TokenInstruction :: ConfidentialTransferExtension ,
482
450
ConfidentialTransferInstruction :: InitializeMint ,
483
451
ct_mint,
484
452
) )
@@ -503,6 +471,7 @@ pub fn update_mint(
503
471
Ok ( encode_instruction (
504
472
token_program_id,
505
473
accounts,
474
+ TokenInstruction :: ConfidentialTransferExtension ,
506
475
ConfidentialTransferInstruction :: UpdateMint ,
507
476
new_ct_mint,
508
477
) )
@@ -533,6 +502,7 @@ pub fn configure_account(
533
502
Ok ( encode_instruction (
534
503
token_program_id,
535
504
accounts,
505
+ TokenInstruction :: ConfidentialTransferExtension ,
536
506
ConfidentialTransferInstruction :: ConfigureAccount ,
537
507
& ConfigureAccountInstructionData {
538
508
encryption_pubkey : encryption_pubkey. into ( ) ,
@@ -557,6 +527,7 @@ pub fn approve_account(
557
527
Ok ( encode_instruction (
558
528
token_program_id,
559
529
accounts,
530
+ TokenInstruction :: ConfidentialTransferExtension ,
560
531
ConfidentialTransferInstruction :: ApproveAccount ,
561
532
& ( ) ,
562
533
) )
@@ -586,6 +557,7 @@ pub fn inner_empty_account(
586
557
Ok ( encode_instruction (
587
558
token_program_id,
588
559
accounts,
560
+ TokenInstruction :: ConfidentialTransferExtension ,
589
561
ConfidentialTransferInstruction :: EmptyAccount ,
590
562
& EmptyAccountInstructionData {
591
563
proof_instruction_offset,
@@ -640,6 +612,7 @@ pub fn deposit(
640
612
Ok ( encode_instruction (
641
613
token_program_id,
642
614
accounts,
615
+ TokenInstruction :: ConfidentialTransferExtension ,
643
616
ConfidentialTransferInstruction :: Deposit ,
644
617
& DepositInstructionData {
645
618
amount : amount. into ( ) ,
@@ -680,6 +653,7 @@ pub fn inner_withdraw(
680
653
Ok ( encode_instruction (
681
654
token_program_id,
682
655
accounts,
656
+ TokenInstruction :: ConfidentialTransferExtension ,
683
657
ConfidentialTransferInstruction :: Withdraw ,
684
658
& WithdrawInstructionData {
685
659
amount : amount. into ( ) ,
@@ -752,6 +726,7 @@ pub fn inner_transfer(
752
726
Ok ( encode_instruction (
753
727
token_program_id,
754
728
accounts,
729
+ TokenInstruction :: ConfidentialTransferExtension ,
755
730
ConfidentialTransferInstruction :: Transfer ,
756
731
& TransferInstructionData {
757
732
new_source_decryptable_available_balance,
@@ -812,6 +787,7 @@ pub fn inner_apply_pending_balance(
812
787
Ok ( encode_instruction (
813
788
token_program_id,
814
789
accounts,
790
+ TokenInstruction :: ConfidentialTransferExtension ,
815
791
ConfidentialTransferInstruction :: ApplyPendingBalance ,
816
792
& ApplyPendingBalanceData {
817
793
expected_pending_balance_credit_counter : expected_pending_balance_credit_counter. into ( ) ,
@@ -860,6 +836,7 @@ fn enable_or_disable_balance_credits(
860
836
Ok ( encode_instruction (
861
837
token_program_id,
862
838
accounts,
839
+ TokenInstruction :: ConfidentialTransferExtension ,
863
840
instruction,
864
841
& ( ) ,
865
842
) )
@@ -923,6 +900,7 @@ pub fn inner_withdraw_withheld_tokens_from_mint(
923
900
Ok ( encode_instruction (
924
901
token_program_id,
925
902
accounts,
903
+ TokenInstruction :: ConfidentialTransferExtension ,
926
904
ConfidentialTransferInstruction :: WithdrawWithheldTokensFromMint ,
927
905
& WithdrawWithheldTokensFromMintData {
928
906
proof_instruction_offset,
@@ -985,6 +963,7 @@ pub fn inner_withdraw_withheld_tokens_from_accounts(
985
963
Ok ( encode_instruction (
986
964
token_program_id,
987
965
accounts,
966
+ TokenInstruction :: ConfidentialTransferExtension ,
988
967
ConfidentialTransferInstruction :: WithdrawWithheldTokensFromAccounts ,
989
968
& WithdrawWithheldTokensFromAccountsData {
990
969
proof_instruction_offset,
@@ -1033,6 +1012,7 @@ pub fn harvest_withheld_tokens_to_mint(
1033
1012
Ok ( encode_instruction (
1034
1013
token_program_id,
1035
1014
accounts,
1015
+ TokenInstruction :: ConfidentialTransferExtension ,
1036
1016
ConfidentialTransferInstruction :: HarvestWithheldTokensToMint ,
1037
1017
& ( ) ,
1038
1018
) )
0 commit comments