@@ -69,6 +69,11 @@ pub(crate) enum TransferInstruction {
69
69
CheckedWithFee { decimals : u8 , fee : u64 } ,
70
70
}
71
71
72
+ pub ( crate ) enum InstructionVariant {
73
+ Unchecked ,
74
+ Checked { decimals : u8 } ,
75
+ }
76
+
72
77
/// Program state handler.
73
78
pub struct Processor { }
74
79
impl Processor {
@@ -567,21 +572,22 @@ impl Processor {
567
572
}
568
573
569
574
/// Processes an [`Approve`](enum.TokenInstruction.html) instruction.
570
- pub fn process_approve (
575
+ pub ( crate ) fn process_approve (
571
576
program_id : & Pubkey ,
572
577
accounts : & [ AccountInfo ] ,
573
578
amount : u64 ,
574
- expected_decimals : Option < u8 > ,
579
+ instruction_variant : InstructionVariant ,
575
580
) -> ProgramResult {
576
581
let account_info_iter = & mut accounts. iter ( ) ;
577
582
578
583
let source_account_info = next_account_info ( account_info_iter) ?;
579
584
580
- let expected_mint_info = if let Some ( expected_decimals) = expected_decimals {
581
- Some ( ( next_account_info ( account_info_iter) ?, expected_decimals) )
582
- } else {
583
- None
584
- } ;
585
+ let expected_mint_info =
586
+ if let InstructionVariant :: Checked { decimals } = instruction_variant {
587
+ Some ( ( next_account_info ( account_info_iter) ?, decimals) )
588
+ } else {
589
+ None
590
+ } ;
585
591
let delegate_info = next_account_info ( account_info_iter) ?;
586
592
let owner_info = next_account_info ( account_info_iter) ?;
587
593
let owner_info_data_len = owner_info. data_len ( ) ;
@@ -965,11 +971,11 @@ impl Processor {
965
971
}
966
972
967
973
/// Processes a [`MintTo`](enum.TokenInstruction.html) instruction.
968
- pub fn process_mint_to (
974
+ pub ( crate ) fn process_mint_to (
969
975
program_id : & Pubkey ,
970
976
accounts : & [ AccountInfo ] ,
971
977
amount : u64 ,
972
- expected_decimals : Option < u8 > ,
978
+ instruction_variant : InstructionVariant ,
973
979
) -> ProgramResult {
974
980
let account_info_iter = & mut accounts. iter ( ) ;
975
981
let mint_info = next_account_info ( account_info_iter) ?;
@@ -1014,8 +1020,8 @@ impl Processor {
1014
1020
return Err ( TokenError :: IllegalMintBurnConversion . into ( ) ) ;
1015
1021
}
1016
1022
1017
- if let Some ( expected_decimals ) = expected_decimals {
1018
- if expected_decimals != mint. base . decimals {
1023
+ if let InstructionVariant :: Checked { decimals } = instruction_variant {
1024
+ if decimals != mint. base . decimals {
1019
1025
return Err ( TokenError :: MintDecimalsMismatch . into ( ) ) ;
1020
1026
}
1021
1027
}
@@ -1054,11 +1060,11 @@ impl Processor {
1054
1060
}
1055
1061
1056
1062
/// Processes a [`Burn`](enum.TokenInstruction.html) instruction.
1057
- pub fn process_burn (
1063
+ pub ( crate ) fn process_burn (
1058
1064
program_id : & Pubkey ,
1059
1065
accounts : & [ AccountInfo ] ,
1060
1066
amount : u64 ,
1061
- expected_decimals : Option < u8 > ,
1067
+ instruction_variant : InstructionVariant ,
1062
1068
) -> ProgramResult {
1063
1069
let account_info_iter = & mut accounts. iter ( ) ;
1064
1070
@@ -1086,8 +1092,8 @@ impl Processor {
1086
1092
return Err ( TokenError :: MintMismatch . into ( ) ) ;
1087
1093
}
1088
1094
1089
- if let Some ( expected_decimals ) = expected_decimals {
1090
- if expected_decimals != mint. base . decimals {
1095
+ if let InstructionVariant :: Checked { decimals } = instruction_variant {
1096
+ if decimals != mint. base . decimals {
1091
1097
return Err ( TokenError :: MintDecimalsMismatch . into ( ) ) ;
1092
1098
}
1093
1099
}
@@ -1681,7 +1687,12 @@ impl Processor {
1681
1687
PodTokenInstruction :: Approve => {
1682
1688
msg ! ( "Instruction: Approve" ) ;
1683
1689
let data = decode_instruction_data :: < AmountData > ( input) ?;
1684
- Self :: process_approve ( program_id, accounts, data. amount . into ( ) , None )
1690
+ Self :: process_approve (
1691
+ program_id,
1692
+ accounts,
1693
+ data. amount . into ( ) ,
1694
+ InstructionVariant :: Unchecked ,
1695
+ )
1685
1696
}
1686
1697
PodTokenInstruction :: Revoke => {
1687
1698
msg ! ( "Instruction: Revoke" ) ;
@@ -1701,12 +1712,22 @@ impl Processor {
1701
1712
PodTokenInstruction :: MintTo => {
1702
1713
msg ! ( "Instruction: MintTo" ) ;
1703
1714
let data = decode_instruction_data :: < AmountData > ( input) ?;
1704
- Self :: process_mint_to ( program_id, accounts, data. amount . into ( ) , None )
1715
+ Self :: process_mint_to (
1716
+ program_id,
1717
+ accounts,
1718
+ data. amount . into ( ) ,
1719
+ InstructionVariant :: Unchecked ,
1720
+ )
1705
1721
}
1706
1722
PodTokenInstruction :: Burn => {
1707
1723
msg ! ( "Instruction: Burn" ) ;
1708
1724
let data = decode_instruction_data :: < AmountData > ( input) ?;
1709
- Self :: process_burn ( program_id, accounts, data. amount . into ( ) , None )
1725
+ Self :: process_burn (
1726
+ program_id,
1727
+ accounts,
1728
+ data. amount . into ( ) ,
1729
+ InstructionVariant :: Unchecked ,
1730
+ )
1710
1731
}
1711
1732
PodTokenInstruction :: CloseAccount => {
1712
1733
msg ! ( "Instruction: CloseAccount" ) ;
@@ -1739,7 +1760,9 @@ impl Processor {
1739
1760
program_id,
1740
1761
accounts,
1741
1762
data. amount . into ( ) ,
1742
- Some ( data. decimals ) ,
1763
+ InstructionVariant :: Checked {
1764
+ decimals : data. decimals ,
1765
+ } ,
1743
1766
)
1744
1767
}
1745
1768
PodTokenInstruction :: MintToChecked => {
@@ -1749,7 +1772,9 @@ impl Processor {
1749
1772
program_id,
1750
1773
accounts,
1751
1774
data. amount . into ( ) ,
1752
- Some ( data. decimals ) ,
1775
+ InstructionVariant :: Checked {
1776
+ decimals : data. decimals ,
1777
+ } ,
1753
1778
)
1754
1779
}
1755
1780
PodTokenInstruction :: BurnChecked => {
@@ -1759,7 +1784,9 @@ impl Processor {
1759
1784
program_id,
1760
1785
accounts,
1761
1786
data. amount . into ( ) ,
1762
- Some ( data. decimals ) ,
1787
+ InstructionVariant :: Checked {
1788
+ decimals : data. decimals ,
1789
+ } ,
1763
1790
)
1764
1791
}
1765
1792
PodTokenInstruction :: SyncNative => {
0 commit comments