Struct cosmwasm_std::IbcReceiveResponse
source · #[non_exhaustive]pub struct IbcReceiveResponse<T = Empty> {
pub acknowledgement: Option<Binary>,
pub messages: Vec<SubMsg<T>>,
pub attributes: Vec<Attribute>,
pub events: Vec<Event>,
}
Expand description
This defines the return value on packet response processing. This “success” case should be returned even in application-level errors, Where the acknowledgement bytes contain an encoded error message to be returned to the calling chain. (Returning ContractResult::Err will abort processing of this packet and not inform the calling chain).
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.acknowledgement: Option<Binary>
The bytes we return to the contract that sent the packet.
This may represent a success or error of execution.
In case of None
, no acknowledgement is written.
messages: Vec<SubMsg<T>>
Optional list of messages to pass. These will be executed in order.
If the ReplyOn member is set, they will invoke this contract’s reply
entry point
after execution. Otherwise, they act like “fire and forget”.
Use call
or msg.into()
to create messages with the older “fire and forget” semantics.
attributes: Vec<Attribute>
The attributes that will be emitted as part of a “wasm” event.
More info about events (and their attributes) can be found in Cosmos SDK docs.
events: Vec<Event>
Extra, custom events separate from the main wasm
one. These will have
wasm-
prepended to the type.
More info about events can be found in Cosmos SDK docs.
Implementations§
source§impl<T> IbcReceiveResponse<T>
impl<T> IbcReceiveResponse<T>
sourcepub fn new(ack: impl Into<Binary>) -> Self
pub fn new(ack: impl Into<Binary>) -> Self
Create a new response with the given acknowledgement.
§Examples
use cosmwasm_std::{StdAck, IbcReceiveResponse};
// 0x01 is a FungibleTokenPacketSuccess from ICS-20.
let resp: IbcReceiveResponse = IbcReceiveResponse::new(StdAck::success(b"\x01"));
assert_eq!(resp.acknowledgement.unwrap(), b"{\"result\":\"AQ==\"}");
sourcepub fn without_ack() -> Self
pub fn without_ack() -> Self
Creates a new response without an acknowledgement.
This allows you to send the acknowledgement asynchronously later using [IbcMsg::WriteAcknowledgement
].
If you want to send the acknowledgement immediately, use IbcReceiveResponse::new
.
sourcepub fn add_attribute(
self,
key: impl Into<String>,
value: impl Into<String>
) -> Self
pub fn add_attribute( self, key: impl Into<String>, value: impl Into<String> ) -> Self
Add an attribute included in the main wasm
event.
sourcepub fn add_message(self, msg: impl Into<CosmosMsg<T>>) -> Self
pub fn add_message(self, msg: impl Into<CosmosMsg<T>>) -> Self
This creates a “fire and forget” message, by using SubMsg::new()
to wrap it,
and adds it to the list of messages to process.
sourcepub fn add_submessage(self, msg: SubMsg<T>) -> Self
pub fn add_submessage(self, msg: SubMsg<T>) -> Self
This takes an explicit SubMsg (creates via e.g. reply_on_error
)
and adds it to the list of messages to process.
sourcepub fn add_event(self, event: Event) -> Self
pub fn add_event(self, event: Event) -> Self
Adds an extra event to the response, separate from the main wasm
event
that is always created.
The wasm-
prefix will be appended by the runtime to the provided type
of event.
sourcepub fn add_attributes<A: Into<Attribute>>(
self,
attrs: impl IntoIterator<Item = A>
) -> Self
pub fn add_attributes<A: Into<Attribute>>( self, attrs: impl IntoIterator<Item = A> ) -> Self
Bulk add attributes included in the main wasm
event.
Anything that can be turned into an iterator and yields something
that can be converted into an Attribute
is accepted.
§Examples
use cosmwasm_std::{attr, IbcReceiveResponse, StdAck};
let attrs = vec![
("action", "reaction"),
("answer", "42"),
("another", "attribute"),
];
let res: IbcReceiveResponse = IbcReceiveResponse::new(StdAck::success(b"\x01")).add_attributes(attrs.clone());
assert_eq!(res.attributes, attrs);
sourcepub fn add_messages<M: Into<CosmosMsg<T>>>(
self,
msgs: impl IntoIterator<Item = M>
) -> Self
pub fn add_messages<M: Into<CosmosMsg<T>>>( self, msgs: impl IntoIterator<Item = M> ) -> Self
Bulk add “fire and forget” messages to the list of messages to process.
§Examples
use cosmwasm_std::{CosmosMsg, IbcReceiveResponse, StdAck};
fn make_response_with_msgs(msgs: Vec<CosmosMsg>) -> IbcReceiveResponse {
IbcReceiveResponse::new(StdAck::success(b"\x01")).add_messages(msgs)
}
sourcepub fn add_submessages(self, msgs: impl IntoIterator<Item = SubMsg<T>>) -> Self
pub fn add_submessages(self, msgs: impl IntoIterator<Item = SubMsg<T>>) -> Self
Bulk add explicit SubMsg structs to the list of messages to process.
§Examples
use cosmwasm_std::{SubMsg, StdAck, IbcReceiveResponse};
fn make_response_with_submsgs(msgs: Vec<SubMsg>) -> IbcReceiveResponse {
IbcReceiveResponse::new(StdAck::success(b"\x01")).add_submessages(msgs)
}
sourcepub fn add_events(self, events: impl IntoIterator<Item = Event>) -> Self
pub fn add_events(self, events: impl IntoIterator<Item = Event>) -> Self
Bulk add custom events to the response. These are separate from the main
wasm
event.
The wasm-
prefix will be appended by the runtime to the provided types
of events.
Trait Implementations§
source§impl<T: Clone> Clone for IbcReceiveResponse<T>
impl<T: Clone> Clone for IbcReceiveResponse<T>
source§fn clone(&self) -> IbcReceiveResponse<T>
fn clone(&self) -> IbcReceiveResponse<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: Debug> Debug for IbcReceiveResponse<T>
impl<T: Debug> Debug for IbcReceiveResponse<T>
source§impl<'de, T> Deserialize<'de> for IbcReceiveResponse<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for IbcReceiveResponse<T>where
T: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<T: JsonSchema> JsonSchema for IbcReceiveResponse<T>
impl<T: JsonSchema> JsonSchema for IbcReceiveResponse<T>
source§fn schema_name() -> String
fn schema_name() -> String
source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresource§impl<T: PartialEq> PartialEq for IbcReceiveResponse<T>
impl<T: PartialEq> PartialEq for IbcReceiveResponse<T>
source§fn eq(&self, other: &IbcReceiveResponse<T>) -> bool
fn eq(&self, other: &IbcReceiveResponse<T>) -> bool
self
and other
values to be equal, and is used
by ==
.