@@ -57,6 +57,8 @@ pub fn linearize(c_group: &ConstraintGroup) -> Vec<Constraint> {
57
57
close,
58
58
address,
59
59
associated_token,
60
+ token_account,
61
+ mint,
60
62
} = c_group. clone ( ) ;
61
63
62
64
let mut constraints = Vec :: new ( ) ;
@@ -100,6 +102,12 @@ pub fn linearize(c_group: &ConstraintGroup) -> Vec<Constraint> {
100
102
if let Some ( c) = address {
101
103
constraints. push ( Constraint :: Address ( c) ) ;
102
104
}
105
+ if let Some ( c) = token_account {
106
+ constraints. push ( Constraint :: TokenAccount ( c) ) ;
107
+ }
108
+ if let Some ( c) = mint {
109
+ constraints. push ( Constraint :: Mint ( c) ) ;
110
+ }
103
111
constraints
104
112
}
105
113
@@ -120,6 +128,8 @@ fn generate_constraint(f: &Field, c: &Constraint) -> proc_macro2::TokenStream {
120
128
Constraint :: Close ( c) => generate_constraint_close ( f, c) ,
121
129
Constraint :: Address ( c) => generate_constraint_address ( f, c) ,
122
130
Constraint :: AssociatedToken ( c) => generate_constraint_associated_token ( f, c) ,
131
+ Constraint :: TokenAccount ( c) => generate_constraint_token_account ( f, c) ,
132
+ Constraint :: Mint ( c) => generate_constraint_mint ( f, c) ,
123
133
}
124
134
}
125
135
@@ -682,6 +692,63 @@ fn generate_constraint_associated_token(
682
692
}
683
693
}
684
694
695
+ fn generate_constraint_token_account (
696
+ f : & Field ,
697
+ c : & ConstraintTokenAccountGroup ,
698
+ ) -> proc_macro2:: TokenStream {
699
+ let name = & f. ident ;
700
+ let authority_check = match & c. authority {
701
+ Some ( authority) => {
702
+ quote ! { if #name. owner != #authority. key( ) { return Err ( anchor_lang:: error:: ErrorCode :: ConstraintTokenOwner . into( ) ) ; } }
703
+ }
704
+ None => quote ! { } ,
705
+ } ;
706
+ let mint_check = match & c. mint {
707
+ Some ( mint) => {
708
+ quote ! { if #name. mint != #mint. key( ) { return Err ( anchor_lang:: error:: ErrorCode :: ConstraintTokenMint . into( ) ) ; } }
709
+ }
710
+ None => quote ! { } ,
711
+ } ;
712
+ quote ! {
713
+ #authority_check
714
+ #mint_check
715
+ }
716
+ }
717
+
718
+ fn generate_constraint_mint ( f : & Field , c : & ConstraintTokenMintGroup ) -> proc_macro2:: TokenStream {
719
+ let name = & f. ident ;
720
+
721
+ let decimal_check = match & c. decimals {
722
+ Some ( decimals) => quote ! {
723
+ if #name. decimals != #decimals {
724
+ return Err ( anchor_lang:: error:: ErrorCode :: ConstraintMintDecimals . into( ) ) ;
725
+ }
726
+ } ,
727
+ None => quote ! { } ,
728
+ } ;
729
+ let mint_authority_check = match & c. mint_authority {
730
+ Some ( mint_authority) => quote ! {
731
+ if #name. mint_authority != anchor_lang:: solana_program:: program_option:: COption :: Some ( anchor_lang:: Key :: key( & #mint_authority) ) {
732
+ return Err ( anchor_lang:: error:: ErrorCode :: ConstraintMintMintAuthority . into( ) ) ;
733
+ }
734
+ } ,
735
+ None => quote ! { } ,
736
+ } ;
737
+ let freeze_authority_check = match & c. freeze_authority {
738
+ Some ( freeze_authority) => quote ! {
739
+ if #name. freeze_authority != anchor_lang:: solana_program:: program_option:: COption :: Some ( anchor_lang:: Key :: key( & #freeze_authority) ) {
740
+ return Err ( anchor_lang:: error:: ErrorCode :: ConstraintMintFreezeAuthority . into( ) ) ;
741
+ }
742
+ } ,
743
+ None => quote ! { } ,
744
+ } ;
745
+ quote ! {
746
+ #decimal_check
747
+ #mint_authority_check
748
+ #freeze_authority_check
749
+ }
750
+ }
751
+
685
752
// Generated code to create an account with with system program with the
686
753
// given `space` amount of data, owned by `owner`.
687
754
//
0 commit comments