From 3f97ef7e3d9a204b6d01aaef5a5d1fb6d77392f6 Mon Sep 17 00:00:00 2001 From: Tomasz Kulik Date: Wed, 7 Aug 2024 19:37:52 +0200 Subject: [PATCH] TODO --- .../interfaces/custom-and-generic/src/lib.rs | 149 +++++++++-------- examples/interfaces/generic/src/lib.rs | 157 ++++++++++-------- .../src/interface/communication/api.rs | 11 +- .../src/interface/communication/executor.rs | 3 +- .../src/interface/communication/querier.rs | 3 +- sylvia-derive/src/interface/mt.rs | 2 +- sylvia/src/types.rs | 8 - 7 files changed, 166 insertions(+), 167 deletions(-) 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..bf0d3d1d 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/communication/api.rs b/sylvia-derive/src/interface/communication/api.rs index ebe777e0..c4b6aed4 100644 --- a/sylvia-derive/src/interface/communication/api.rs +++ b/sylvia-derive/src/interface/communication/api.rs @@ -39,6 +39,7 @@ impl<'a> Api<'a> { .without_error() .map(ItemType::as_name) .collect(); + let exec_variants = MsgVariants::new( source.as_variants(), MsgType::Exec, @@ -77,26 +78,18 @@ impl<'a> Api<'a> { 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..42190288 100644 --- a/sylvia-derive/src/interface/communication/executor.rs +++ b/sylvia-derive/src/interface/communication/executor.rs @@ -53,8 +53,7 @@ where 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..5f348fe5 100644 --- a/sylvia-derive/src/interface/communication/querier.rs +++ b/sylvia-derive/src/interface/communication/querier.rs @@ -52,8 +52,7 @@ where .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..31563ed8 100644 --- a/sylvia-derive/src/interface/mt.rs +++ b/sylvia-derive/src/interface/mt.rs @@ -97,7 +97,7 @@ impl<'a> MtHelpers<'a> { .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;