From 99a2189f6d24caa3bd4e776e423cbb94b6e76a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wo=C5=BAniak?= Date: Mon, 30 Sep 2024 11:41:42 +0200 Subject: [PATCH] feat: Impl SubMsg trait on CosmosMsg --- .../src/contract/communication/reply.rs | 23 +++++++++++-------- sylvia/tests/reply.rs | 13 ++++++++++- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/sylvia-derive/src/contract/communication/reply.rs b/sylvia-derive/src/contract/communication/reply.rs index 7ee79ae4..5bf8f6f7 100644 --- a/sylvia-derive/src/contract/communication/reply.rs +++ b/sylvia-derive/src/contract/communication/reply.rs @@ -151,19 +151,24 @@ impl<'a> Reply<'a> { } } }); + let cosmosmsg_methods_implementation = wasmmsg_methods_implementation.clone(); quote! { - pub trait SubMsgMethods { - #(#methods_declaration)* - } + pub trait SubMsgMethods { + #(#methods_declaration)* + } - impl SubMsgMethods for #sylvia ::cw_std::SubMsg { - #(#submsg_methods_implementation)* - } + impl SubMsgMethods for #sylvia ::cw_std::SubMsg { + #(#submsg_methods_implementation)* + } - impl SubMsgMethods for #sylvia ::cw_std::WasmMsg { - #(#wasmmsg_methods_implementation)* - } + impl SubMsgMethods for #sylvia ::cw_std::WasmMsg { + #(#wasmmsg_methods_implementation)* + } + + impl SubMsgMethods for #sylvia ::cw_std::CosmosMsg { + #(#cosmosmsg_methods_implementation)* + } } } } diff --git a/sylvia/tests/reply.rs b/sylvia/tests/reply.rs index 7765e689..db94581b 100644 --- a/sylvia/tests/reply.rs +++ b/sylvia/tests/reply.rs @@ -1,6 +1,6 @@ #![cfg(feature = "sv_replies")] -use cosmwasm_std::{Empty, SubMsgResult}; +use cosmwasm_std::{BankMsg, CosmosMsg, Empty, SubMsgResult}; use cw_storage_plus::Item; use cw_utils::{parse_instantiate_response_data, ParseReplyError}; use noop_contract::sv::{Executor, NoopContractInstantiateBuilder}; @@ -246,6 +246,17 @@ where Ok(Response::new()) } + + #[sv::msg(exec)] + fn send_cosmos_messages(&self, ctx: ExecCtx) -> Result, ContractError> { + let remote_addr = self.remote.load(ctx.deps.storage)?; + let cosmos_msg = CosmosMsg::Bank(BankMsg::Send { + to_address: remote_addr.as_ref().to_string(), + amount: vec![], + }); + let submsg = cosmos_msg.always(); + Ok(Response::new().add_submessage(submsg)) + } } mod tests {