Struct cosmwasm_std::Response[][src]

pub struct Response<T = Empty> where
    T: Clone + Debug + PartialEq + JsonSchema
{ pub messages: Vec<SubMsg<T>>, pub attributes: Vec<Attribute>, pub events: Vec<Event>, pub data: Option<Binary>, }
Expand description

A response of a contract entry point, such as instantiate, execute or migrate.

This type can be constructed directly at the end of the call. Alternatively a mutable response instance can be created early in the contract’s logic and incrementally be updated.

Examples

Direct:

use cosmwasm_std::{attr, Response, StdResult};

pub fn instantiate(
    deps: DepsMut,
    _env: Env,
    _info: MessageInfo,
    msg: InstantiateMsg,
) -> StdResult<Response> {
    // ...

    Ok(Response {
        messages: vec![],
        attributes: vec![attr("action", "instantiate")],
        events: vec![],
        data: None,
    })
}

Mutating:

use cosmwasm_std::Response;

pub fn instantiate(
    deps: DepsMut,
    _env: Env,
    info: MessageInfo,
    msg: InstantiateMsg,
) -> Result<Response, MyError> {
    let mut response = Response::new();
    // ...
    response.add_attribute("Let the", "hacking begin");
    // ...
    response.add_message(BankMsg::Send {
        to_address: String::from("recipient"),
        amount: coins(128, "uint"),
    });
    response.add_attribute("foo", "bar");
    // ...
    response.set_data(Binary::from(b"the result data"));
    Ok(response)
}

Fields

messages: Vec<SubMsg<T>>

Optional list of messages to pass. These will be executed in order. If the ReplyOn variant matches the result (Always, Success on Ok, Error on Err), the runtime will invoke this contract’s reply entry point after execution. Otherwise, they act like “fire and forget”. Use SubMsg::new 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

events: Vec<Event>data: Option<Binary>

Implementations

Add an attribute included in the main wasm event.

This creates a “fire and forget” message, by using SubMsg::new() to wrap it, and adds it to the list of messages to process.

This takes an explicit SubMsg (creates via eg. reply_on_error) and adds it to the list of messages to process.

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.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

The name of the generated JSON Schema. Read more

Generates a JSON Schema for this type. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.