@@ -303,7 +303,7 @@ impl<'a> EnumMessage<'a> {
303
303
#[ allow( clippy:: derive_partial_eq_without_eq) ]
304
304
#[ derive( #sylvia :: serde:: Serialize , #sylvia :: serde:: Deserialize , Clone , Debug , PartialEq , #sylvia :: schemars:: JsonSchema , cosmwasm_schema:: QueryResponses ) ]
305
305
#[ serde( rename_all="snake_case" ) ]
306
- pub enum #unique_enum_name #generics #where_clause {
306
+ pub enum #unique_enum_name #generics {
307
307
#( #variants, ) *
308
308
}
309
309
pub type #name #generics = #unique_enum_name #generics;
@@ -314,7 +314,7 @@ impl<'a> EnumMessage<'a> {
314
314
#[ allow( clippy:: derive_partial_eq_without_eq) ]
315
315
#[ derive( #sylvia :: serde:: Serialize , #sylvia :: serde:: Deserialize , Clone , Debug , PartialEq , #sylvia :: schemars:: JsonSchema ) ]
316
316
#[ serde( rename_all="snake_case" ) ]
317
- pub enum #unique_enum_name #generics #where_clause {
317
+ pub enum #unique_enum_name #generics {
318
318
#( #variants, ) *
319
319
}
320
320
pub type #name #generics = #unique_enum_name #generics;
@@ -506,7 +506,9 @@ impl<'a> MsgVariant<'a> {
506
506
507
507
let return_type = if let MsgAttr :: Query { resp_type } = msg_attr {
508
508
match resp_type {
509
- Some ( resp_type) => quote ! { #resp_type} ,
509
+ Some ( resp_type) => {
510
+ quote ! { #resp_type}
511
+ }
510
512
None => {
511
513
let return_type = extract_return_type ( & sig. output ) ;
512
514
quote ! { #return_type}
@@ -667,12 +669,20 @@ impl<'a> MsgVariant<'a> {
667
669
}
668
670
}
669
671
670
- pub struct MsgVariants < ' a > ( Vec < MsgVariant < ' a > > ) ;
672
+ pub struct MsgVariants < ' a > {
673
+ variants : Vec < MsgVariant < ' a > > ,
674
+ unbonded_generics : Vec < & ' a GenericParam > ,
675
+ where_clause : Option < WhereClause > ,
676
+ }
671
677
672
678
impl < ' a > MsgVariants < ' a > {
673
- pub fn new ( source : VariantDescs < ' a > , generics : & [ & ' a GenericParam ] ) -> Self {
679
+ pub fn new (
680
+ source : VariantDescs < ' a > ,
681
+ msg_type : MsgType ,
682
+ generics : & ' a Vec < & ' a GenericParam > ,
683
+ unfiltered_where_clause : & ' a Option < WhereClause > ,
684
+ ) -> Self {
674
685
let mut generics_checker = CheckGenerics :: new ( generics) ;
675
-
676
686
let variants: Vec < _ > = source
677
687
. filter_map ( |variant_desc| {
678
688
let msg_attr = variant_desc. attr_msg ( ) ?;
@@ -684,19 +694,49 @@ impl<'a> MsgVariants<'a> {
684
694
}
685
695
} ;
686
696
697
+ if attr. msg_type ( ) != msg_type {
698
+ return None ;
699
+ }
700
+
687
701
Some ( MsgVariant :: new (
688
702
variant_desc. into_sig ( ) ,
689
703
& mut generics_checker,
690
704
attr,
691
705
) )
692
706
} )
693
707
. collect ( ) ;
694
- Self ( variants)
708
+
709
+ let ( unbonded_generics, _) = generics_checker. used_unused ( ) ;
710
+ let wheres = filter_wheres (
711
+ unfiltered_where_clause,
712
+ generics. as_slice ( ) ,
713
+ & unbonded_generics,
714
+ ) ;
715
+ let where_clause = if !wheres. is_empty ( ) {
716
+ Some ( parse_quote ! { where #( #wheres) , * } )
717
+ } else {
718
+ None
719
+ } ;
720
+
721
+ Self {
722
+ variants,
723
+ unbonded_generics,
724
+ where_clause,
725
+ }
726
+ }
727
+
728
+ pub fn variants ( & self ) -> & Vec < MsgVariant < ' a > > {
729
+ & self . variants
695
730
}
696
731
697
732
pub fn emit_querier ( & self ) -> TokenStream {
698
733
let sylvia = crate_module ( ) ;
699
- let variants = & self . 0 ;
734
+ let Self {
735
+ variants,
736
+ unbonded_generics,
737
+ where_clause,
738
+ ..
739
+ } = self ;
700
740
701
741
let methods_impl = variants
702
742
. iter ( )
@@ -708,6 +748,12 @@ impl<'a> MsgVariants<'a> {
708
748
. filter ( |variant| variant. msg_type == MsgType :: Query )
709
749
. map ( MsgVariant :: emit_querier_declaration) ;
710
750
751
+ let querier = if !unbonded_generics. is_empty ( ) {
752
+ quote ! { Querier < #( #unbonded_generics, ) * > }
753
+ } else {
754
+ quote ! { Querier }
755
+ } ;
756
+
711
757
#[ cfg( not( tarpaulin_include) ) ]
712
758
{
713
759
quote ! {
@@ -730,12 +776,11 @@ impl<'a> MsgVariants<'a> {
730
776
}
731
777
}
732
778
733
- impl <' a, C : #sylvia :: cw_std:: CustomQuery > Querier for BoundQuerier <' a, C > {
779
+ impl <' a, C : #sylvia :: cw_std:: CustomQuery , # ( #unbonded_generics , ) * > #querier for BoundQuerier <' a, C > #where_clause {
734
780
#( #methods_impl) *
735
781
}
736
782
737
-
738
- pub trait Querier {
783
+ pub trait #querier {
739
784
#( #methods_declaration) *
740
785
}
741
786
}
@@ -748,24 +793,33 @@ impl<'a> MsgVariants<'a> {
748
793
contract_module : Option < & Path > ,
749
794
) -> TokenStream {
750
795
let sylvia = crate_module ( ) ;
751
- let variants = & self . 0 ;
796
+ let Self {
797
+ variants,
798
+ unbonded_generics,
799
+ where_clause,
800
+ ..
801
+ } = self ;
752
802
753
803
let methods_impl = variants
754
804
. iter ( )
755
805
. filter ( |variant| variant. msg_type == MsgType :: Query )
756
806
. map ( |variant| variant. emit_querier_impl ( trait_module) ) ;
757
807
758
- let querier = trait_module
808
+ let mut querier = trait_module
759
809
. map ( |module| quote ! { #module :: Querier } )
760
810
. unwrap_or_else ( || quote ! { Querier } ) ;
761
811
let bound_querier = contract_module
762
812
. map ( |module| quote ! { #module :: BoundQuerier } )
763
813
. unwrap_or_else ( || quote ! { BoundQuerier } ) ;
764
814
815
+ if !unbonded_generics. is_empty ( ) {
816
+ querier = quote ! { #querier < #( #unbonded_generics, ) * > } ;
817
+ }
818
+
765
819
#[ cfg( not( tarpaulin_include) ) ]
766
820
{
767
821
quote ! {
768
- impl <' a, C : #sylvia :: cw_std:: CustomQuery > #querier for #bound_querier<' a, C > {
822
+ impl <' a, C : #sylvia :: cw_std:: CustomQuery , # ( #unbonded_generics , ) * > #querier for #bound_querier<' a, C > #where_clause {
769
823
#( #methods_impl) *
770
824
}
771
825
}
@@ -886,7 +940,7 @@ impl<'a> GlueMessage<'a> {
886
940
interfaces,
887
941
} = self ;
888
942
let contract = StripGenerics . fold_type ( ( * contract) . clone ( ) ) ;
889
- let contract_name = Ident :: new ( & format ! ( "Contract{}" , name) , name. span ( ) ) ;
943
+ let enum_name = Ident :: new ( & format ! ( "Contract{}" , name) , name. span ( ) ) ;
890
944
891
945
let variants = interfaces. emit_glue_message_variants ( msg_ty, name) ;
892
946
@@ -916,15 +970,15 @@ impl<'a> GlueMessage<'a> {
916
970
917
971
match ( msg_ty, customs. has_msg ) {
918
972
( MsgType :: Exec , true ) => quote ! {
919
- #contract_name :: #variant( msg) => #sylvia :: into_response:: IntoResponse :: into_response( msg. dispatch( contract, Into :: into( #ctx ) ) ?)
973
+ #enum_name :: #variant( msg) => #sylvia :: into_response:: IntoResponse :: into_response( msg. dispatch( contract, Into :: into( #ctx ) ) ?)
920
974
} ,
921
975
_ => quote ! {
922
- #contract_name :: #variant( msg) => msg. dispatch( contract, Into :: into( #ctx ) )
976
+ #enum_name :: #variant( msg) => msg. dispatch( contract, Into :: into( #ctx ) )
923
977
} ,
924
978
}
925
979
} ) ;
926
980
927
- let dispatch_arm = quote ! { #contract_name :: #contract ( msg) =>msg. dispatch( contract, ctx) } ;
981
+ let dispatch_arm = quote ! { #enum_name :: #contract ( msg) => msg. dispatch( contract, ctx) } ;
928
982
929
983
let interfaces_deserialization_attempts = interfaces. emit_deserialization_attempts ( name) ;
930
984
@@ -951,7 +1005,7 @@ impl<'a> GlueMessage<'a> {
951
1005
{
952
1006
quote ! {
953
1007
#[ cfg( not( target_arch = "wasm32" ) ) ]
954
- impl cosmwasm_schema :: QueryResponses for #contract_name {
1008
+ impl #sylvia :: cw_schema :: QueryResponses for #enum_name {
955
1009
fn response_schemas_impl( ) -> std:: collections:: BTreeMap <String , #sylvia :: schemars:: schema:: RootSchema > {
956
1010
let responses = [ #( #response_schemas_calls) , * ] ;
957
1011
responses. into_iter( ) . flatten( ) . collect( )
@@ -971,12 +1025,12 @@ impl<'a> GlueMessage<'a> {
971
1025
#[ allow( clippy:: derive_partial_eq_without_eq) ]
972
1026
#[ derive( #sylvia :: serde:: Serialize , Clone , Debug , PartialEq , #sylvia :: schemars:: JsonSchema ) ]
973
1027
#[ serde( rename_all="snake_case" , untagged) ]
974
- pub enum #contract_name {
1028
+ pub enum #enum_name {
975
1029
#( #variants, ) *
976
1030
#msg_name
977
1031
}
978
1032
979
- impl #contract_name {
1033
+ impl #enum_name {
980
1034
pub fn dispatch(
981
1035
self ,
982
1036
contract: & #contract,
@@ -996,7 +1050,7 @@ impl<'a> GlueMessage<'a> {
996
1050
997
1051
#response_schemas
998
1052
999
- impl <' de> serde:: Deserialize <' de> for #contract_name {
1053
+ impl <' de> serde:: Deserialize <' de> for #enum_name {
1000
1054
fn deserialize<D >( deserializer: D ) -> Result <Self , D :: Error >
1001
1055
where D : serde:: Deserializer <' de>,
1002
1056
{
@@ -1043,7 +1097,8 @@ pub struct EntryPoints<'a> {
1043
1097
error : Type ,
1044
1098
custom : Custom < ' a > ,
1045
1099
override_entry_points : OverrideEntryPoints ,
1046
- variants : MsgVariants < ' a > ,
1100
+ has_migrate : bool ,
1101
+ reply : Option < Ident > ,
1047
1102
}
1048
1103
1049
1104
impl < ' a > EntryPoints < ' a > {
@@ -1067,17 +1122,24 @@ impl<'a> EntryPoints<'a> {
1067
1122
)
1068
1123
. unwrap_or_else ( || parse_quote ! { #sylvia :: cw_std:: StdError } ) ;
1069
1124
1070
- let generics: Vec < _ > = source. generics . params . iter ( ) . collect ( ) ;
1125
+ let has_migrate = !MsgVariants :: new ( source. as_variants ( ) , MsgType :: Migrate , & vec ! [ ] , & None )
1126
+ . variants ( )
1127
+ . is_empty ( ) ;
1071
1128
1072
- let variants = MsgVariants :: new ( source. as_variants ( ) , & generics) ;
1129
+ let reply = MsgVariants :: new ( source. as_variants ( ) , MsgType :: Reply , & vec ! [ ] , & None )
1130
+ . variants ( )
1131
+ . iter ( )
1132
+ . map ( |variant| variant. function_name . clone ( ) )
1133
+ . next ( ) ;
1073
1134
let custom = Custom :: new ( & source. attrs ) ;
1074
1135
1075
1136
Self {
1076
1137
name,
1077
1138
error,
1078
1139
custom,
1079
1140
override_entry_points,
1080
- variants,
1141
+ has_migrate,
1142
+ reply,
1081
1143
}
1082
1144
}
1083
1145
@@ -1087,17 +1149,13 @@ impl<'a> EntryPoints<'a> {
1087
1149
error,
1088
1150
custom,
1089
1151
override_entry_points,
1090
- variants,
1152
+ has_migrate,
1153
+ reply,
1091
1154
} = self ;
1092
1155
let sylvia = crate_module ( ) ;
1093
1156
1094
1157
let custom_msg = custom. msg_or_default ( ) ;
1095
1158
let custom_query = custom. query_or_default ( ) ;
1096
- let reply = variants
1097
- . 0
1098
- . iter ( )
1099
- . find ( |variant| variant. msg_type == MsgType :: Reply )
1100
- . map ( |variant| variant. function_name . clone ( ) ) ;
1101
1159
1102
1160
#[ cfg( not( tarpaulin_include) ) ]
1103
1161
{
@@ -1119,12 +1177,8 @@ impl<'a> EntryPoints<'a> {
1119
1177
let migrate_not_overridden = override_entry_points
1120
1178
. get_entry_point ( MsgType :: Migrate )
1121
1179
. is_none ( ) ;
1122
- let migrate_msg_defined = variants
1123
- . 0
1124
- . iter ( )
1125
- . any ( |variant| variant. msg_type == MsgType :: Migrate ) ;
1126
1180
1127
- let migrate = if migrate_not_overridden && migrate_msg_defined {
1181
+ let migrate = if migrate_not_overridden && * has_migrate {
1128
1182
OverrideEntryPoint :: emit_default_entry_point (
1129
1183
& custom_msg,
1130
1184
& custom_query,
0 commit comments