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 Replys 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>

source

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.

source

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.

source

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.

source

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.

source

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.

source

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);
source

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<T: Clone> Clone for SubMsg<T>

source§

fn clone(&self) -> SubMsg<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for SubMsg<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: JsonSchema> JsonSchema for SubMsg<T>

source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
source§

fn json_schema(gen: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
source§

impl<T: PartialEq> PartialEq for SubMsg<T>

source§

fn eq(&self, other: &SubMsg<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Serialize for SubMsg<T>
where T: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Eq> Eq for SubMsg<T>

source§

impl<T> StructuralPartialEq for SubMsg<T>

Auto Trait Implementations§

§

impl<T> Freeze for SubMsg<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for SubMsg<T>
where T: RefUnwindSafe,

§

impl<T> Send for SubMsg<T>
where T: Send,

§

impl<T> Sync for SubMsg<T>
where T: Sync,

§

impl<T> Unpin for SubMsg<T>
where T: Unpin,

§

impl<T> UnwindSafe for SubMsg<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<U> As for U

source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,