Struct cosmwasm_std::SubMsg
source · pub struct SubMsg<T = Empty> {
pub id: u64,
pub payload: Binary,
pub msg: CosmosMsg<T>,
pub gas_limit: Option<u64>,
pub reply_on: ReplyOn,
}
Expand description
A submessage that will guarantee a reply
call on success or error, depending on
the reply_on
setting. If you do not need to process the result, use regular messages instead.
Note: On error the submessage execution will revert any partial state changes due to this message,
but not revert any state changes in the calling contract. If this is required, it must be done
manually in the reply
entry point.
Fields§
§id: u64
An arbitrary ID chosen by the contract.
This is typically used to match Reply
s in the reply
entry point to the submessage.
payload: Binary
Some arbirary data that the contract can set in an application specific way.
This is just passed into the reply
entry point and is not stored to state.
Any encoding can be used. If id
is used to identify a particular action,
the encoding can also be different for each of those actions since you can match id
first and then start processing the payload
.
The environment restricts the length of this field in order to avoid abuse. The limit is environment specific and can change over time. The initial default is 128 KiB.
Unset/nil/null cannot be differentiated from empty data.
On chains running CosmWasm 1.x this field will be ignored.
msg: CosmosMsg<T>
§gas_limit: Option<u64>
Gas limit measured in Cosmos SDK gas.
Setting this to None
means unlimited. Then the submessage execution can consume all gas of the
current execution context.
reply_on: ReplyOn
Implementations§
source§impl<T> SubMsg<T>
impl<T> SubMsg<T>
sourcepub fn new(msg: impl Into<CosmosMsg<T>>) -> Self
pub fn new(msg: impl Into<CosmosMsg<T>>) -> Self
Creates a “fire and forget” message with the pre-0.14 semantics.
Since this is just an alias for SubMsg::reply_never
it is somewhat recommended
to use the latter in order to make the behaviour more explicit in the caller code.
But that’s up to you for now.
By default, the submessage’s gas limit will be unlimited. Use SubMsg::with_gas_limit
to change it.
Setting payload
is not advised as this will never be used.
sourcepub fn reply_on_success(msg: impl Into<CosmosMsg<T>>, id: u64) -> Self
pub fn reply_on_success(msg: impl Into<CosmosMsg<T>>, id: u64) -> Self
Creates a SubMsg
that will provide a reply
with the given id
if the message returns Ok
.
By default, the submessage’s payload
will be empty and the gas limit will be unlimited. Use
SubMsg::with_payload
and SubMsg::with_gas_limit
to change those.
sourcepub fn reply_on_error(msg: impl Into<CosmosMsg<T>>, id: u64) -> Self
pub fn reply_on_error(msg: impl Into<CosmosMsg<T>>, id: u64) -> Self
Creates a SubMsg
that will provide a reply
with the given id
if the message returns Err
.
By default, the submessage’s payload
will be empty and the gas limit will be unlimited. Use
SubMsg::with_payload
and SubMsg::with_gas_limit
to change those.
sourcepub fn reply_always(msg: impl Into<CosmosMsg<T>>, id: u64) -> Self
pub fn reply_always(msg: impl Into<CosmosMsg<T>>, id: u64) -> Self
Create a SubMsg
that will always provide a reply
with the given id
.
By default, the submessage’s payload
will be empty and the gas limit will be unlimited. Use
SubMsg::with_payload
and SubMsg::with_gas_limit
to change those.
sourcepub fn reply_never(msg: impl Into<CosmosMsg<T>>) -> Self
pub fn reply_never(msg: impl Into<CosmosMsg<T>>) -> Self
Create a SubMsg
that will never reply
. This is equivalent to standard message semantics.
By default, the submessage’s gas limit will be unlimited. Use SubMsg::with_gas_limit
to change it.
Setting payload
is not advised as this will never be used.
sourcepub fn with_gas_limit(self, limit: u64) -> Self
pub fn with_gas_limit(self, limit: u64) -> Self
Add a gas limit to the submessage. This gas limit measured in Cosmos SDK gas.
§Examples
let sub_msg: SubMsg = SubMsg::reply_always(msg, 1234).with_gas_limit(60_000);
assert_eq!(sub_msg.id, 1234);
assert_eq!(sub_msg.gas_limit, Some(60_000));
assert_eq!(sub_msg.reply_on, ReplyOn::Always);
sourcepub fn with_payload(self, payload: impl Into<Binary>) -> Self
pub fn with_payload(self, payload: impl Into<Binary>) -> Self
Add a payload to the submessage.
§Examples
let sub_msg: SubMsg = SubMsg::reply_always(msg, 1234)
.with_payload(vec![1, 2, 3, 4]);
assert_eq!(sub_msg.id, 1234);
assert_eq!(sub_msg.payload, Binary::new(vec![1, 2, 3, 4]));
assert_eq!(sub_msg.reply_on, ReplyOn::Always);
Trait Implementations§
source§impl<'de, T> Deserialize<'de> for SubMsg<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for SubMsg<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 SubMsg<T>
impl<T: JsonSchema> JsonSchema for SubMsg<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 more