Skip to content

Commit

Permalink
feat: Impl SubMsg trait on CosmosMsg
Browse files Browse the repository at this point in the history
  • Loading branch information
jawoznia committed Sep 30, 2024
1 parent 8140714 commit 99a2189
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
23 changes: 14 additions & 9 deletions sylvia-derive/src/contract/communication/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,24 @@ impl<'a> Reply<'a> {
}
}
});
let cosmosmsg_methods_implementation = wasmmsg_methods_implementation.clone();

quote! {
pub trait SubMsgMethods<CustomMsgT> {
#(#methods_declaration)*
}
pub trait SubMsgMethods<CustomMsgT> {
#(#methods_declaration)*
}

impl<CustomMsgT> SubMsgMethods<CustomMsgT> for #sylvia ::cw_std::SubMsg<CustomMsgT> {
#(#submsg_methods_implementation)*
}
impl<CustomMsgT> SubMsgMethods<CustomMsgT> for #sylvia ::cw_std::SubMsg<CustomMsgT> {
#(#submsg_methods_implementation)*
}

impl<CustomMsgT> SubMsgMethods<CustomMsgT> for #sylvia ::cw_std::WasmMsg {
#(#wasmmsg_methods_implementation)*
}
impl<CustomMsgT> SubMsgMethods<CustomMsgT> for #sylvia ::cw_std::WasmMsg {
#(#wasmmsg_methods_implementation)*
}

impl<CustomMsgT> SubMsgMethods<CustomMsgT> for #sylvia ::cw_std::CosmosMsg<CustomMsgT> {
#(#cosmosmsg_methods_implementation)*
}
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion sylvia/tests/reply.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -246,6 +246,17 @@ where

Ok(Response::new())
}

#[sv::msg(exec)]
fn send_cosmos_messages(&self, ctx: ExecCtx<Q>) -> Result<Response<M>, 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![],

Check warning on line 255 in sylvia/tests/reply.rs

View check run for this annotation

Codecov / codecov/patch

sylvia/tests/reply.rs#L251-L255

Added lines #L251 - L255 were not covered by tests
});
let submsg = cosmos_msg.always();
Ok(Response::new().add_submessage(submsg))

Check warning on line 258 in sylvia/tests/reply.rs

View check run for this annotation

Codecov / codecov/patch

sylvia/tests/reply.rs#L257-L258

Added lines #L257 - L258 were not covered by tests
}
}

mod tests {
Expand Down

0 comments on commit 99a2189

Please sign in to comment.