Skip to content

Commit

Permalink
Submessages for response handler
Browse files Browse the repository at this point in the history
  • Loading branch information
MissingNO57 committed Nov 14, 2024
1 parent ffdc863 commit 5b8fa45
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/events/response_handler.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
use crate::events::IntoEvent;
use cosmwasm_std::{Addr, BankMsg, Coin, CosmosMsg, Response, SubMsg};
use cosmwasm_std::{Addr, BankMsg, Coin, CosmosMsg, Empty, Response, SubMsg};

pub struct ResponseHandler {
response: Response,
pub struct ResponseHandler<T = Empty> {
response: Response<T>,
}

impl ResponseHandler {
pub fn add_event<T: IntoEvent>(&mut self, event: T) {
impl<T> ResponseHandler<T> {
pub fn add_event<E: IntoEvent>(&mut self, event: E) {
self.response.events.push(event.into_event());
}

pub fn add_msg(&mut self, msg: impl Into<CosmosMsg>) {
pub fn add_message(&mut self, msg: impl Into<CosmosMsg<T>>) {
self.response.messages.push(SubMsg::new(msg));
}

pub fn into_response(self) -> Response {
pub fn add_submessage(&mut self, msg: SubMsg<T>) {
self.response.messages.push(msg);
}

pub fn into_response(self) -> Response<T> {
self.response
}

pub fn add_bank_send_msg(&mut self, to_addr: &Addr, amount: Vec<Coin>) {
self.add_msg(BankMsg::Send {
self.add_message(BankMsg::Send {
to_address: to_addr.to_string(),
amount,
})
Expand Down

0 comments on commit 5b8fa45

Please sign in to comment.