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
impl<'de, T> Deserialize<'de> for Response<T> where
T: Clone + Debug + PartialEq + JsonSchema,
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Response<T> where
T: Clone + Debug + PartialEq + JsonSchema,
T: Deserialize<'de>,
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>,
Deserialize this value from the given Serde deserializer. Read more
impl<T: JsonSchema> JsonSchema for Response<T> where
T: Clone + Debug + PartialEq + JsonSchema,
impl<T: JsonSchema> JsonSchema for Response<T> where
T: Clone + Debug + PartialEq + JsonSchema,
Auto Trait Implementations
impl<T> RefUnwindSafe for Response<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Response<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
type Output = T
type Output = T
Should always be Self