From 778c5f058545343098f234fbad6a5fd5e36a22a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wo=C5=BAniak?= Date: Mon, 2 Sep 2024 16:15:39 +0200 Subject: [PATCH] chore: Store `MsgAttr` in `MsgVariant` --- sylvia-derive/src/parser/attributes/msg.rs | 4 ++-- sylvia-derive/src/types/msg_type.rs | 2 +- sylvia-derive/src/types/msg_variant.rs | 17 ++++++++--------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/sylvia-derive/src/parser/attributes/msg.rs b/sylvia-derive/src/parser/attributes/msg.rs index 446dd334..faf22436 100644 --- a/sylvia-derive/src/parser/attributes/msg.rs +++ b/sylvia-derive/src/parser/attributes/msg.rs @@ -68,7 +68,7 @@ impl Parse for ArgumentParser { } /// Representation of `reply_on` parameter in `#[sv::msg(reply(...))]` attribute. -#[derive(Default, Clone)] +#[derive(Debug, Default, Clone)] pub enum ReplyOn { Success, Failure, @@ -91,7 +91,7 @@ impl ReplyOn { } /// Parsed representation of `#[sv::msg(...)]` attribute. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct MsgAttr { msg_type: MsgType, query_resp_type: Option, diff --git a/sylvia-derive/src/types/msg_type.rs b/sylvia-derive/src/types/msg_type.rs index 182ad197..562fe396 100644 --- a/sylvia-derive/src/types/msg_type.rs +++ b/sylvia-derive/src/types/msg_type.rs @@ -19,7 +19,7 @@ impl MsgType { "migrate" => Ok(Self::Migrate), "reply" => Ok(Self::Reply ), "sudo" => Ok(Self::Sudo), - _ => return Err(Error::new( + _ => Err(Error::new( msg_type.span(), "Invalid message type, expected one of: `exec`, `query`, `instantiate`, `migrate`, `reply` or `sudo`.", )) diff --git a/sylvia-derive/src/types/msg_variant.rs b/sylvia-derive/src/types/msg_variant.rs index 55b426c5..0432f7a2 100644 --- a/sylvia-derive/src/types/msg_variant.rs +++ b/sylvia-derive/src/types/msg_variant.rs @@ -23,7 +23,7 @@ pub struct MsgVariant<'a> { /// Type extracted only in case of `Query` and used in `cosmwasm_schema::QueryResponses` /// `returns` attribute. return_type: Option, - msg_type: MsgType, + msg_attr: MsgAttr, attrs_to_forward: Vec, } @@ -42,7 +42,6 @@ impl<'a> MsgVariant<'a> { let name = function_name.to_case(Case::UpperCamel); let fields = process_fields(sig, generics_checker); - let msg_type = msg_attr.msg_type(); let return_type = if msg_attr.msg_type() == MsgType::Query { let resp_type = &msg_attr.resp_type(); @@ -68,7 +67,7 @@ impl<'a> MsgVariant<'a> { function_name, fields, return_type, - msg_type, + msg_attr, attrs_to_forward, } } @@ -78,13 +77,13 @@ impl<'a> MsgVariant<'a> { let Self { name, fields, - msg_type, + msg_attr, return_type, attrs_to_forward, .. } = self; let fields = fields.iter().map(MsgField::emit); - let returns_attribute = msg_type.emit_returns_attribute(return_type); + let returns_attribute = msg_attr.msg_type().emit_returns_attribute(return_type); let attrs_to_forward = attrs_to_forward.iter().map(|attr| &attr.attrs); quote! { @@ -104,7 +103,7 @@ impl<'a> MsgVariant<'a> { name, fields, function_name, - msg_type, + msg_attr, .. } = self; @@ -120,7 +119,7 @@ impl<'a> MsgVariant<'a> { .zip(args.clone()) .map(|(field, num_field)| quote!(#field : #num_field)); - let method_call = msg_type.emit_dispatch_leg(function_name, &args); + let method_call = msg_attr.msg_type().emit_dispatch_leg(function_name, &args); quote! { #name { @@ -167,8 +166,8 @@ impl<'a> MsgVariant<'a> { &self.fields } - pub fn msg_type(&self) -> &MsgType { - &self.msg_type + pub fn msg_type(&self) -> MsgType { + self.msg_attr.msg_type() } pub fn return_type(&self) -> &Option {