From 4ff2a4238417816118ccf8f7456b97c489deefab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wo=C5=BAniak?= Date: Wed, 14 Aug 2024 16:59:04 +0200 Subject: [PATCH] chore: Review fixes --- sylvia-derive/src/contract.rs | 2 +- sylvia-derive/src/contract/communication/executor.rs | 5 ++++- sylvia-derive/src/contract/communication/querier.rs | 5 ++++- .../src/contract/communication/wrapper_msg.rs | 5 ++++- sylvia-derive/src/contract/mt.rs | 2 ++ sylvia-derive/src/entry_points.rs | 5 ++++- sylvia-derive/src/interface.rs | 2 +- sylvia-derive/src/interface/communication/api.rs | 4 ++++ sylvia-derive/src/interface/communication/querier.rs | 5 ++++- sylvia-derive/src/types/associated_types.rs | 12 ++++-------- 10 files changed, 32 insertions(+), 15 deletions(-) diff --git a/sylvia-derive/src/contract.rs b/sylvia-derive/src/contract.rs index 3526cac1..ac428777 100644 --- a/sylvia-derive/src/contract.rs +++ b/sylvia-derive/src/contract.rs @@ -67,7 +67,7 @@ impl<'a> ContractInput<'a> { } } - /// Process the input and generate the contract code. + /// Processes the input and generates the contract code. pub fn process(&self) -> TokenStream { let Self { item, diff --git a/sylvia-derive/src/contract/communication/executor.rs b/sylvia-derive/src/contract/communication/executor.rs index f6fa6621..bf947f81 100644 --- a/sylvia-derive/src/contract/communication/executor.rs +++ b/sylvia-derive/src/contract/communication/executor.rs @@ -10,7 +10,10 @@ use crate::types::msg_field::MsgField; use crate::types::msg_variant::{MsgVariant, MsgVariants}; use crate::utils::SvCasing; -/// Emits execute helper +/// Emits [execute helper](https://cosmwasm-docs.vercel.app/sylvia/macros/generated-types/communication#executor-helpers). +/// +/// Generates trait containing methods for each execute message variant and implements it on +/// `sylvia::types::ExecutorBuilder`. pub struct Executor<'a> { generics: Generics, self_ty: Type, diff --git a/sylvia-derive/src/contract/communication/querier.rs b/sylvia-derive/src/contract/communication/querier.rs index ddf07d0f..f1186d72 100644 --- a/sylvia-derive/src/contract/communication/querier.rs +++ b/sylvia-derive/src/contract/communication/querier.rs @@ -10,7 +10,10 @@ use crate::types::msg_field::MsgField; use crate::types::msg_variant::{MsgVariant, MsgVariants}; use crate::utils::SvCasing; -/// Emits query helper +/// Emits [query helper](https://cosmwasm-docs.vercel.app/sylvia/macros/generated-types/communication#query-helpers). +/// +/// Generates trait containing methods for each query message variant and implements it on +/// `sylvia::types::BoundQuerier`. pub struct Querier<'a> { generics: Generics, self_ty: Type, diff --git a/sylvia-derive/src/contract/communication/wrapper_msg.rs b/sylvia-derive/src/contract/communication/wrapper_msg.rs index e14f7f67..c83b5dab 100644 --- a/sylvia-derive/src/contract/communication/wrapper_msg.rs +++ b/sylvia-derive/src/contract/communication/wrapper_msg.rs @@ -10,7 +10,10 @@ use syn::spanned::Spanned; use syn::{Ident, ItemImpl, Type}; /// Glue message is the message composing Exec/Query/Sudo messages from several traits and a -/// contract +/// contract. +/// +/// It's required for the contract to receive all possible message variants in the entry points. +/// More info [here](https://cosmwasm-docs.vercel.app/sylvia/macros/generated-types/message-types). #[derive(Debug)] pub struct GlueMessage<'a> { source: &'a ItemImpl, diff --git a/sylvia-derive/src/contract/mt.rs b/sylvia-derive/src/contract/mt.rs index d4707bce..46161460 100644 --- a/sylvia-derive/src/contract/mt.rs +++ b/sylvia-derive/src/contract/mt.rs @@ -23,6 +23,8 @@ fn get_ident_from_type(contract_name: &Type) -> &Ident { } /// Emits helpers for testing contract messages using MultiTest. +/// +/// More info here: [MultiTest helpers](https://cosmwasm-docs.vercel.app/sylvia/macros/generated-types/multitest). pub struct MtHelpers<'a> { error_type: Type, contract_name: &'a Type, diff --git a/sylvia-derive/src/entry_points.rs b/sylvia-derive/src/entry_points.rs index 9ec40802..915dfe9f 100644 --- a/sylvia-derive/src/entry_points.rs +++ b/sylvia-derive/src/entry_points.rs @@ -47,7 +47,7 @@ impl<'a> EntryPointInput<'a> { Self { item, args } } - /// Process the input and generate the interface code. + /// Process the input and generate the entry points code. pub fn process(&self) -> TokenStream { let Self { item, args } = self; @@ -56,6 +56,9 @@ impl<'a> EntryPointInput<'a> { } /// Defines logic for generating entry points. +/// +/// By default generates entry points for `instantiate`, `execute`, `query` and `sudo` messages. +/// Generates `reply` and `migrate` entry points if respective messages are defined. pub struct EntryPoints<'a> { source: &'a ItemImpl, name: Type, diff --git a/sylvia-derive/src/interface.rs b/sylvia-derive/src/interface.rs index 40c47def..8909452b 100644 --- a/sylvia-derive/src/interface.rs +++ b/sylvia-derive/src/interface.rs @@ -91,7 +91,7 @@ impl<'a> InterfaceInput<'a> { } } - /// Process the input and generate the interface code. + /// Processes the input and generates the interface code. pub fn process(&self) -> TokenStream { let Self { associated_types, diff --git a/sylvia-derive/src/interface/communication/api.rs b/sylvia-derive/src/interface/communication/api.rs index e1aa2f77..082b5e2a 100644 --- a/sylvia-derive/src/interface/communication/api.rs +++ b/sylvia-derive/src/interface/communication/api.rs @@ -7,6 +7,10 @@ use quote::quote; use syn::ItemTrait; /// Emits `InterfaceMessagesApi` trait. +/// +/// The `InterfaceMessagesApi` is a helper trait to access messages generated by the `interface` +/// macro. +/// It ease the dispatch of generic types. pub struct Api<'a> { source: &'a ItemTrait, associated_types: &'a AssociatedTypes<'a>, diff --git a/sylvia-derive/src/interface/communication/querier.rs b/sylvia-derive/src/interface/communication/querier.rs index 96451a5c..64820ff6 100644 --- a/sylvia-derive/src/interface/communication/querier.rs +++ b/sylvia-derive/src/interface/communication/querier.rs @@ -11,7 +11,10 @@ use crate::types::msg_field::MsgField; use crate::types::msg_variant::{MsgVariant, MsgVariants}; use crate::utils::SvCasing; -/// Emits query helper +/// Emits [query helper](https://cosmwasm-docs.vercel.app/sylvia/macros/generated-types/communication#query-helpers). +/// +/// Generates trait containing methods for each query message variant and implements it on +/// `sylvia::types::BoundQuerier`. pub struct Querier<'a, Generic> { variants: &'a MsgVariants<'a, Generic>, associated_types: &'a AssociatedTypes<'a>, diff --git a/sylvia-derive/src/types/associated_types.rs b/sylvia-derive/src/types/associated_types.rs index 13c7caf5..0deb2c02 100644 --- a/sylvia-derive/src/types/associated_types.rs +++ b/sylvia-derive/src/types/associated_types.rs @@ -84,16 +84,12 @@ impl<'a> AssociatedTypes<'a> { trait_name: &Ident, type_name: &str, ) -> Option { - match self - .as_names() + self.as_names() .find(|name| name.to_string().as_str() == type_name) - { - Some(name) => { + .map(|name| { let type_name = Ident::new(type_name, name.span()); - Some(parse_quote! { :: #type_name}) - } - None => None, - } + parse_quote! { :: #type_name} + }) } }