Enum cosmwasm_std::StdAck 
source · pub enum StdAck {
    Success(Binary),
    Error(String),
}Expand description
This is a standard IBC acknowledgement type. IBC application are free to use any acknowledgement format they want. However, for compatibility purposes it is recommended to use this.
The original proto definition can be found at https://github.com/cosmos/cosmos-sdk/blob/v0.42.0/proto/ibc/core/channel/v1/channel.proto#L141-L147 and https://github.com/cosmos/ibc/tree/ed849c7bac/spec/core/ics-004-channel-and-packet-semantics#acknowledgement-envelope.
In contrast to the original idea, ICS-20 and CosmWasm IBC protocols use JSON instead of a protobuf serialization.
For compatibility, we use the field name “result” for the success case in JSON. However, all Rust APIs use the term “success” for clarity and discriminability from Result.
If ibc_receive_packet returns Err(), then x/wasm runtime will rollback the state and return an error message in this format.
§Examples
For your convenience, there are success and error constructors.
use cosmwasm_std::StdAck;
let ack1 = StdAck::success(b"\x01"); // 0x01 is a FungibleTokenPacketSuccess from ICS-20.
assert!(ack1.is_success());
let ack2 = StdAck::error("kaputt"); // Some free text error message
assert!(ack2.is_error());Variants§
Implementations§
source§impl StdAck
 
impl StdAck
pub const fn is_success(&self) -> bool
pub const fn is_error(&self) -> bool
sourcepub fn to_binary(&self) -> Binary
 
pub fn to_binary(&self) -> Binary
Serialized the ack to binary using JSON. This used for setting the acknowledgement field in IbcReceiveResponse.
§Examples
Show how the acknowledgement looks on the write:
let ack1 = StdAck::success(b"\x01"); // 0x01 is a FungibleTokenPacketSuccess from ICS-20.
assert_eq!(ack1.to_binary(), br#"{"result":"AQ=="}"#);
let ack2 = StdAck::error("kaputt"); // Some free text error message
assert_eq!(ack2.to_binary(), br#"{"error":"kaputt"}"#);Set acknowledgement field in IbcReceiveResponse:
use cosmwasm_std::{StdAck, IbcReceiveResponse};
let ack = StdAck::success(b"\x01"); // 0x01 is a FungibleTokenPacketSuccess from ICS-20.
let res: IbcReceiveResponse = IbcReceiveResponse::new().set_ack(ack.to_binary());
let res: IbcReceiveResponse = IbcReceiveResponse::new().set_ack(ack); // Does the same but consumes the instancepub fn unwrap(self) -> Binary
pub fn unwrap_err(self) -> String
Trait Implementations§
source§impl<'de> Deserialize<'de> for StdAck
 
impl<'de> Deserialize<'de> for StdAck
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 JsonSchema for StdAck
 
impl JsonSchema for StdAck
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 moreimpl Eq for StdAck
impl StructuralPartialEq for StdAck
Auto Trait Implementations§
impl Freeze for StdAck
impl RefUnwindSafe for StdAck
impl Send for StdAck
impl Sync for StdAck
impl Unpin for StdAck
impl UnwindSafe for StdAck
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
 
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)