@@ -3,11 +3,12 @@ use solana_zk_token_sdk::encryption::{auth_encryption::AeCiphertext, elgamal::El
33pub use solana_zk_token_sdk:: zk_token_proof_instruction:: * ;
44use {
55 crate :: {
6- check_program_account, extension:: confidential_transfer:: * , instruction:: TokenInstruction ,
6+ check_program_account,
7+ extension:: confidential_transfer:: * ,
8+ instruction:: { encode_instruction, TokenInstruction } ,
79 } ,
810 bytemuck:: { Pod , Zeroable } ,
9- num_derive:: { FromPrimitive , ToPrimitive } ,
10- num_traits:: { FromPrimitive , ToPrimitive } ,
11+ num_enum:: { IntoPrimitive , TryFromPrimitive } ,
1112 solana_program:: {
1213 instruction:: { AccountMeta , Instruction } ,
1314 program_error:: ProgramError ,
1920} ;
2021
2122/// Confidential Transfer extension instructions
22- #[ derive( Clone , Copy , Debug , FromPrimitive , ToPrimitive ) ]
23+ #[ derive( Clone , Copy , Debug , TryFromPrimitive , IntoPrimitive ) ]
2324#[ repr( u8 ) ]
2425pub enum ConfidentialTransferInstruction {
2526 /// Initializes confidential transfers for a mint.
@@ -434,40 +435,6 @@ pub struct WithdrawWithheldTokensFromAccountsData {
434435 pub proof_instruction_offset : i8 ,
435436}
436437
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-
471438/// Create a `InitializeMint` instruction
472439pub fn initialize_mint (
473440 token_program_id : & Pubkey ,
@@ -479,6 +446,7 @@ pub fn initialize_mint(
479446 Ok ( encode_instruction (
480447 token_program_id,
481448 accounts,
449+ TokenInstruction :: ConfidentialTransferExtension ,
482450 ConfidentialTransferInstruction :: InitializeMint ,
483451 ct_mint,
484452 ) )
@@ -503,6 +471,7 @@ pub fn update_mint(
503471 Ok ( encode_instruction (
504472 token_program_id,
505473 accounts,
474+ TokenInstruction :: ConfidentialTransferExtension ,
506475 ConfidentialTransferInstruction :: UpdateMint ,
507476 new_ct_mint,
508477 ) )
@@ -533,6 +502,7 @@ pub fn configure_account(
533502 Ok ( encode_instruction (
534503 token_program_id,
535504 accounts,
505+ TokenInstruction :: ConfidentialTransferExtension ,
536506 ConfidentialTransferInstruction :: ConfigureAccount ,
537507 & ConfigureAccountInstructionData {
538508 encryption_pubkey : encryption_pubkey. into ( ) ,
@@ -557,6 +527,7 @@ pub fn approve_account(
557527 Ok ( encode_instruction (
558528 token_program_id,
559529 accounts,
530+ TokenInstruction :: ConfidentialTransferExtension ,
560531 ConfidentialTransferInstruction :: ApproveAccount ,
561532 & ( ) ,
562533 ) )
@@ -586,6 +557,7 @@ pub fn inner_empty_account(
586557 Ok ( encode_instruction (
587558 token_program_id,
588559 accounts,
560+ TokenInstruction :: ConfidentialTransferExtension ,
589561 ConfidentialTransferInstruction :: EmptyAccount ,
590562 & EmptyAccountInstructionData {
591563 proof_instruction_offset,
@@ -640,6 +612,7 @@ pub fn deposit(
640612 Ok ( encode_instruction (
641613 token_program_id,
642614 accounts,
615+ TokenInstruction :: ConfidentialTransferExtension ,
643616 ConfidentialTransferInstruction :: Deposit ,
644617 & DepositInstructionData {
645618 amount : amount. into ( ) ,
@@ -680,6 +653,7 @@ pub fn inner_withdraw(
680653 Ok ( encode_instruction (
681654 token_program_id,
682655 accounts,
656+ TokenInstruction :: ConfidentialTransferExtension ,
683657 ConfidentialTransferInstruction :: Withdraw ,
684658 & WithdrawInstructionData {
685659 amount : amount. into ( ) ,
@@ -752,6 +726,7 @@ pub fn inner_transfer(
752726 Ok ( encode_instruction (
753727 token_program_id,
754728 accounts,
729+ TokenInstruction :: ConfidentialTransferExtension ,
755730 ConfidentialTransferInstruction :: Transfer ,
756731 & TransferInstructionData {
757732 new_source_decryptable_available_balance,
@@ -812,6 +787,7 @@ pub fn inner_apply_pending_balance(
812787 Ok ( encode_instruction (
813788 token_program_id,
814789 accounts,
790+ TokenInstruction :: ConfidentialTransferExtension ,
815791 ConfidentialTransferInstruction :: ApplyPendingBalance ,
816792 & ApplyPendingBalanceData {
817793 expected_pending_balance_credit_counter : expected_pending_balance_credit_counter. into ( ) ,
@@ -860,6 +836,7 @@ fn enable_or_disable_balance_credits(
860836 Ok ( encode_instruction (
861837 token_program_id,
862838 accounts,
839+ TokenInstruction :: ConfidentialTransferExtension ,
863840 instruction,
864841 & ( ) ,
865842 ) )
@@ -923,6 +900,7 @@ pub fn inner_withdraw_withheld_tokens_from_mint(
923900 Ok ( encode_instruction (
924901 token_program_id,
925902 accounts,
903+ TokenInstruction :: ConfidentialTransferExtension ,
926904 ConfidentialTransferInstruction :: WithdrawWithheldTokensFromMint ,
927905 & WithdrawWithheldTokensFromMintData {
928906 proof_instruction_offset,
@@ -985,6 +963,7 @@ pub fn inner_withdraw_withheld_tokens_from_accounts(
985963 Ok ( encode_instruction (
986964 token_program_id,
987965 accounts,
966+ TokenInstruction :: ConfidentialTransferExtension ,
988967 ConfidentialTransferInstruction :: WithdrawWithheldTokensFromAccounts ,
989968 & WithdrawWithheldTokensFromAccountsData {
990969 proof_instruction_offset,
@@ -1033,6 +1012,7 @@ pub fn harvest_withheld_tokens_to_mint(
10331012 Ok ( encode_instruction (
10341013 token_program_id,
10351014 accounts,
1015+ TokenInstruction :: ConfidentialTransferExtension ,
10361016 ConfidentialTransferInstruction :: HarvestWithheldTokensToMint ,
10371017 & ( ) ,
10381018 ) )
0 commit comments