diff --git a/examples/interfaces/custom-and-generic/src/lib.rs b/examples/interfaces/custom-and-generic/src/lib.rs index adfb57e9..d24a7f7d 100644 --- a/examples/interfaces/custom-and-generic/src/lib.rs +++ b/examples/interfaces/custom-and-generic/src/lib.rs @@ -72,7 +72,6 @@ pub trait CustomAndGeneric { mod tests { use cosmwasm_std::testing::mock_dependencies; use cosmwasm_std::{Addr, CosmosMsg, Empty, QuerierWrapper}; - use sylvia::types::InterfaceApi; use crate::sv::Querier; @@ -139,91 +138,97 @@ mod tests { querier.custom_generic_query_two(SvCustomMsg {}, SvCustomMsg {}); // Construct messages with Interface extension - let _ = as InterfaceApi>::Query::custom_generic_query_one( - SvCustomMsg {}, SvCustomMsg {} + let _ = as super::sv::InterfaceMessagesApi>::Query::custom_generic_query_one( + SvCustomMsg {}, + SvCustomMsg {}, ); - let _ = as InterfaceApi>::Exec::custom_generic_execute_one( + let _ = as super::sv::InterfaceMessagesApi>::Exec::custom_generic_execute_one( vec![CosmosMsg::Custom(SvCustomMsg {})], vec![CosmosMsg::Custom(SvCustomMsg {})], ); - let _ = as InterfaceApi>::Exec::custom_generic_execute_two( + let _ = as super::sv::InterfaceMessagesApi>::Exec::custom_generic_execute_two( vec![CosmosMsg::Custom(SvCustomMsg {})], vec![CosmosMsg::Custom(SvCustomMsg {})], ); - let _ = as InterfaceApi>::Sudo::custom_generic_sudo_one( + let _ = as super::sv::InterfaceMessagesApi>::Sudo::custom_generic_sudo_one( CosmosMsg::Custom(SvCustomMsg {}), CosmosMsg::Custom(SvCustomMsg {}), ); - let _ = as InterfaceApi>::Sudo::custom_generic_sudo_one( + let _ = as super::sv::InterfaceMessagesApi>::Sudo::custom_generic_sudo_one( CosmosMsg::Custom(SvCustomMsg {}), CosmosMsg::Custom(SvCustomMsg {}), ); diff --git a/examples/interfaces/generic/src/lib.rs b/examples/interfaces/generic/src/lib.rs index 0624268a..174ad87f 100644 --- a/examples/interfaces/generic/src/lib.rs +++ b/examples/interfaces/generic/src/lib.rs @@ -71,7 +71,6 @@ pub trait Generic { mod tests { use cosmwasm_std::testing::mock_dependencies; use cosmwasm_std::{Addr, CosmosMsg, Empty, QuerierWrapper}; - use sylvia::types::InterfaceApi; use crate::sv::Querier; @@ -129,88 +128,100 @@ mod tests { let _: Result = querier.generic_query_two(SvCustomMsg {}, SvCustomMsg {}); // Construct messages with Interface extension - let _ = as InterfaceApi>::Query::generic_query_one(SvCustomMsg {}, SvCustomMsg {}); - let _ = as InterfaceApi>::Query::generic_query_two(SvCustomMsg {}, SvCustomMsg {}); - let _ = as InterfaceApi>::Exec::generic_exec_one( + let _ = as super::sv::InterfaceMessagesApi>::Query::generic_query_one( + SvCustomMsg {}, + SvCustomMsg {}, + ); + let _ = as super::sv::InterfaceMessagesApi>::Query::generic_query_two( + SvCustomMsg {}, + SvCustomMsg {}, + ); + let _ = as super::sv::InterfaceMessagesApi>::Exec::generic_exec_one( vec![CosmosMsg::Custom(SvCustomMsg {})], vec![CosmosMsg::Custom(SvCustomMsg {})], ); - let _ = as InterfaceApi>::Exec::generic_exec_two( + let _ = as super::sv::InterfaceMessagesApi>::Exec::generic_exec_two( vec![CosmosMsg::Custom(SvCustomMsg {})], vec![CosmosMsg::Custom(SvCustomMsg {})], ); - let _ = as InterfaceApi>::Sudo::generic_sudo_one( + let _ = as super::sv::InterfaceMessagesApi>::Sudo::generic_sudo_one( CosmosMsg::Custom(SvCustomMsg {}), CosmosMsg::Custom(SvCustomMsg {}), ); - let _ = as InterfaceApi>::Sudo::generic_sudo_two( + let _ = as super::sv::InterfaceMessagesApi>::Sudo::generic_sudo_two( CosmosMsg::Custom(SvCustomMsg {}), CosmosMsg::Custom(SvCustomMsg {}), ); diff --git a/sylvia-derive/src/interface.rs b/sylvia-derive/src/interface.rs index b75bbca3..d2e387b7 100644 --- a/sylvia-derive/src/interface.rs +++ b/sylvia-derive/src/interface.rs @@ -85,7 +85,7 @@ impl<'a> InterfaceInput<'a> { let Self { associated_types, item, - custom, + .. } = self; let messages = self.emit_messages(); let associated_names: Vec<_> = associated_types @@ -102,7 +102,7 @@ impl<'a> InterfaceInput<'a> { let querier = Querier::new(&query_variants, associated_types, &item.ident).emit_querier_trait(); - let interface_messages = Api::new(item, associated_types, custom).emit(); + let interface_messages = Api::new(item, associated_types).emit(); let multitest_helpers = self.emit_multitest_helpers(); diff --git a/sylvia-derive/src/interface/communication/api.rs b/sylvia-derive/src/interface/communication/api.rs index ebe777e0..aafb43f2 100644 --- a/sylvia-derive/src/interface/communication/api.rs +++ b/sylvia-derive/src/interface/communication/api.rs @@ -1,6 +1,5 @@ -use crate::crate_module; use crate::parser::variant_descs::AsVariantDescs; -use crate::parser::{Custom, MsgType}; +use crate::parser::MsgType; use crate::types::associated_types::{AssociatedTypes, ItemType}; use crate::types::msg_variant::MsgVariants; use proc_macro2::TokenStream; @@ -9,28 +8,20 @@ use syn::ItemTrait; pub struct Api<'a> { source: &'a ItemTrait, - custom: &'a Custom, associated_types: &'a AssociatedTypes<'a>, } impl<'a> Api<'a> { - pub fn new( - source: &'a ItemTrait, - associated_types: &'a AssociatedTypes<'a>, - custom: &'a Custom, - ) -> Self { + pub fn new(source: &'a ItemTrait, associated_types: &'a AssociatedTypes<'a>) -> Self { Self { source, - custom, associated_types, } } pub fn emit(&self) -> TokenStream { - let sylvia = crate_module(); let Self { source, - custom, associated_types, } = self; @@ -58,45 +49,27 @@ impl<'a> Api<'a> { &source.generics.where_clause, ); - let where_clause = &self.associated_types.as_where_clause(); - let custom_query = custom.query_or_default(); let exec_generics = &exec_variants.used_generics(); let query_generics = &query_variants.used_generics(); let sudo_generics = &sudo_variants.used_generics(); - let phantom = if !generics.is_empty() { - quote! { - _phantom: std::marker::PhantomData<( #(#generics,)* )>, - } - } else { - quote! {} - }; - quote! { pub trait InterfaceMessagesApi { type Exec; type Query; type Sudo; - type Querier<'querier>; } impl InterfaceMessagesApi for Contract { type Exec = ExecMsg < #(:: #exec_generics,)* >; type Query = QueryMsg < #(:: #query_generics,)* >; type Sudo = SudoMsg < #(:: #sudo_generics ,)* >; - type Querier<'querier> = #sylvia ::types::BoundQuerier<'querier, #custom_query, Contract >; - } - - - pub struct Api < #(#generics,)* > { - #phantom } - impl < #(#generics,)* > #sylvia ::types::InterfaceApi for Api < #(#generics,)* > #where_clause { + impl<'a, Error, #(#generics),*> InterfaceMessagesApi for dyn #interface_name < Error = Error, #(#generics = #generics,)* > + 'a { type Exec = ExecMsg < #(#exec_generics,)* >; type Query = QueryMsg < #(#query_generics,)* >; type Sudo = SudoMsg < #(#sudo_generics,)* >; - type Querier<'querier, Contract> = #sylvia ::types::BoundQuerier<'querier, #custom_query, Contract >; } } } diff --git a/sylvia-derive/src/interface/communication/executor.rs b/sylvia-derive/src/interface/communication/executor.rs index a01cc853..b4e35c7e 100644 --- a/sylvia-derive/src/interface/communication/executor.rs +++ b/sylvia-derive/src/interface/communication/executor.rs @@ -9,7 +9,7 @@ use crate::parser::check_generics::GetPath; use crate::types::associated_types::{AssociatedTypes, ItemType}; use crate::types::msg_field::MsgField; use crate::types::msg_variant::{MsgVariant, MsgVariants}; -use crate::utils::{emit_bracketed_generics, SvCasing}; +use crate::utils::SvCasing; pub struct Executor<'a, Generic> { variants: &'a MsgVariants<'a, Generic>, @@ -46,15 +46,11 @@ where .map(ItemType::as_name) .collect(); let all_generics: Vec<_> = associated_types.all_names().collect(); - let assoc_types: Vec<_> = generics - .iter() - .map(|assoc| quote! {Self:: #assoc}) - .collect(); - let bracketed_generics = emit_bracketed_generics(&assoc_types); let accessor = MsgType::Exec.as_accessor_name(); - let executor_api_path = - quote! { < Api #bracketed_generics as #sylvia ::types::InterfaceApi>:: #accessor }; + let executor_api_path = quote! { + < dyn #interface_name < Error = (), #(#generics = Self:: #generics,)* > as InterfaceMessagesApi >:: #accessor + }; let methods_trait_impl = variants .variants() diff --git a/sylvia-derive/src/interface/communication/querier.rs b/sylvia-derive/src/interface/communication/querier.rs index 81e8e471..0f80f6cc 100644 --- a/sylvia-derive/src/interface/communication/querier.rs +++ b/sylvia-derive/src/interface/communication/querier.rs @@ -9,7 +9,7 @@ use crate::parser::check_generics::GetPath; use crate::types::associated_types::{AssociatedTypes, ItemType}; use crate::types::msg_field::MsgField; use crate::types::msg_variant::{MsgVariant, MsgVariants}; -use crate::utils::{emit_bracketed_generics, SvCasing}; +use crate::utils::SvCasing; pub struct Querier<'a, Generic> { variants: &'a MsgVariants<'a, Generic>, @@ -46,14 +46,10 @@ where .map(ItemType::as_name) .collect(); let all_generics: Vec<_> = associated_types.all_names().collect(); - let assoc_types: Vec<_> = generics - .iter() - .map(|assoc| quote! {Self:: #assoc}) - .collect(); - let bracketed_generics = emit_bracketed_generics(&assoc_types); let accessor = MsgType::Query.as_accessor_name(); - let api_path = - quote! { < Api #bracketed_generics as #sylvia ::types::InterfaceApi>:: #accessor }; + let api_path = quote! { + < dyn #interface_name < Error = (), #(#generics = Self:: #generics,)* > as InterfaceMessagesApi > :: #accessor + }; let methods_trait_impl = variants .variants() diff --git a/sylvia-derive/src/interface/mt.rs b/sylvia-derive/src/interface/mt.rs index 951bfc0b..84ae8b83 100644 --- a/sylvia-derive/src/interface/mt.rs +++ b/sylvia-derive/src/interface/mt.rs @@ -8,7 +8,7 @@ use crate::parser::attributes::msg::MsgType; use crate::parser::variant_descs::AsVariantDescs; use crate::types::associated_types::AssociatedTypes; use crate::types::msg_variant::{MsgVariant, MsgVariants}; -use crate::utils::{emit_bracketed_generics, SvCasing}; +use crate::utils::SvCasing; pub struct MtHelpers<'a> { source: &'a ItemTrait, @@ -88,16 +88,9 @@ impl<'a> MtHelpers<'a> { .map(|associated| &associated.ident) .collect(); - let associated_args_for_api: Vec<_> = associated_types - .without_error() - .map(|associated| { - let assoc = &associated.ident; - quote! { Self:: #assoc } - }) - .collect(); - - let bracketed_generics = emit_bracketed_generics(&associated_args_for_api); - let api = quote! { < Api #bracketed_generics as #sylvia ::types::InterfaceApi> }; + let api = quote! { + < dyn #interface_name < Error = (), #(#associated_args = Self:: #associated_args,)* > as InterfaceMessagesApi > + }; let associated_types_declaration = associated_types.without_error(); diff --git a/sylvia/src/types.rs b/sylvia/src/types.rs index c4f7ec1c..30a98ec8 100644 --- a/sylvia/src/types.rs +++ b/sylvia/src/types.rs @@ -562,14 +562,6 @@ pub trait CustomQuery: cosmwasm_std::CustomQuery + DeserializeOwned + JsonSchema impl CustomQuery for T where T: cosmwasm_std::CustomQuery + DeserializeOwned + JsonSchema {} -/// Api trait for easier access to generated types and messages. -pub trait InterfaceApi { - type Exec; - type Query; - type Sudo; - type Querier<'querier, Contract>; -} - /// Api trait for easier access to generated types and messages. pub trait ContractApi { type Instantiate;