Skip to content

Commit

Permalink
Fix destination chain types
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Apr 16, 2024
1 parent d2196a2 commit 2ea0c1f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 10 deletions.
27 changes: 25 additions & 2 deletions contracts/ibc-callbacks/schema/ibc-callbacks.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@
"additionalProperties": false
},
"IbcDestinationChainCallbackMsg": {
"description": "The message type of the IBC destination chain callback.\n\nThe IBC destination chain callback is needed for cases where someone triggers the sending of an IBC packet through some other message (i.e. not through [`IbcMsg::SendPacket`]) and your contract needs to know that it received this. The callback is called after the packet was successfully acknowledged on the destination chain. A prominent example is the [`IbcMsg::Transfer`] message. Without callbacks, you cannot know that someone sent you IBC coins.\n\nNote that there are some prerequisites that need to be fulfilled to receive source chain callbacks: - The contract must implement the `ibc_destination_chain_callback` entrypoint. - The module that receives the packet must be wrapped by an `IBCMiddleware` (i.e. the destination chain needs to support callbacks for the message you are being sent). - You have to add json-encoded [`IbcCallbackData`] to a specific field of the message. For `IbcMsg::Transfer`, this is the `memo` field.",
"description": "The message type of the IBC destination chain callback.\n\nThe IBC destination chain callback is needed for cases where someone triggers the sending of an IBC packet through some other message (i.e. not through [`IbcMsg::SendPacket`]) and your contract needs to know that it received this. A prominent example is the [`IbcMsg::Transfer`] message. Without callbacks, you cannot know that someone sent you IBC coins.\n\nThe callback is called after the packet was acknowledged on the destination chain, as follows: - If the acknowledgement is synchronous (i.e. returned immediately when the packet is received), the callback is called only if the acknowledgement was successful. - If the acknowledgement is asynchronous (i.e. written later using `WriteAcknowledgement`), the callback is called regardless of the success of the acknowledgement.\n\nNote that there are some prerequisites that need to be fulfilled to receive source chain callbacks: - The contract must implement the `ibc_destination_chain_callback` entrypoint. - The module that receives the packet must be wrapped by an `IBCMiddleware` (i.e. the destination chain needs to support callbacks for the message you are being sent). - You have to add json-encoded [`IbcCallbackData`] to a specific field of the message. For `IbcMsg::Transfer`, this is the `memo` field.",
"type": "object",
"required": [
"ack",
"packet"
],
"properties": {
"ack": {
"$ref": "#/definitions/IbcAcknowledgement"
"$ref": "#/definitions/IbcFullAcknowledgement"
},
"packet": {
"$ref": "#/definitions/IbcPacket"
Expand All @@ -186,6 +186,29 @@
},
"additionalProperties": false
},
"IbcFullAcknowledgement": {
"description": "The acknowledgement written by the module on the destination chain. It is different from the [`IbcAcknowledgement`] as it can be unsuccessful.",
"type": "object",
"required": [
"data",
"success"
],
"properties": {
"data": {
"description": "The acknowledgement data returned by the module.",
"allOf": [
{
"$ref": "#/definitions/Binary"
}
]
},
"success": {
"description": "Whether the acknowledgement was successful or not.",
"type": "boolean"
}
},
"additionalProperties": false
},
"IbcPacket": {
"type": "object",
"required": [
Expand Down
27 changes: 25 additions & 2 deletions contracts/ibc-callbacks/schema/raw/response_to_callback_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
"additionalProperties": false
},
"IbcDestinationChainCallbackMsg": {
"description": "The message type of the IBC destination chain callback.\n\nThe IBC destination chain callback is needed for cases where someone triggers the sending of an IBC packet through some other message (i.e. not through [`IbcMsg::SendPacket`]) and your contract needs to know that it received this. The callback is called after the packet was successfully acknowledged on the destination chain. A prominent example is the [`IbcMsg::Transfer`] message. Without callbacks, you cannot know that someone sent you IBC coins.\n\nNote that there are some prerequisites that need to be fulfilled to receive source chain callbacks: - The contract must implement the `ibc_destination_chain_callback` entrypoint. - The module that receives the packet must be wrapped by an `IBCMiddleware` (i.e. the destination chain needs to support callbacks for the message you are being sent). - You have to add json-encoded [`IbcCallbackData`] to a specific field of the message. For `IbcMsg::Transfer`, this is the `memo` field.",
"description": "The message type of the IBC destination chain callback.\n\nThe IBC destination chain callback is needed for cases where someone triggers the sending of an IBC packet through some other message (i.e. not through [`IbcMsg::SendPacket`]) and your contract needs to know that it received this. A prominent example is the [`IbcMsg::Transfer`] message. Without callbacks, you cannot know that someone sent you IBC coins.\n\nThe callback is called after the packet was acknowledged on the destination chain, as follows: - If the acknowledgement is synchronous (i.e. returned immediately when the packet is received), the callback is called only if the acknowledgement was successful. - If the acknowledgement is asynchronous (i.e. written later using `WriteAcknowledgement`), the callback is called regardless of the success of the acknowledgement.\n\nNote that there are some prerequisites that need to be fulfilled to receive source chain callbacks: - The contract must implement the `ibc_destination_chain_callback` entrypoint. - The module that receives the packet must be wrapped by an `IBCMiddleware` (i.e. the destination chain needs to support callbacks for the message you are being sent). - You have to add json-encoded [`IbcCallbackData`] to a specific field of the message. For `IbcMsg::Transfer`, this is the `memo` field.",
"type": "object",
"required": [
"ack",
"packet"
],
"properties": {
"ack": {
"$ref": "#/definitions/IbcAcknowledgement"
"$ref": "#/definitions/IbcFullAcknowledgement"
},
"packet": {
"$ref": "#/definitions/IbcPacket"
Expand All @@ -83,6 +83,29 @@
},
"additionalProperties": false
},
"IbcFullAcknowledgement": {
"description": "The acknowledgement written by the module on the destination chain. It is different from the [`IbcAcknowledgement`] as it can be unsuccessful.",
"type": "object",
"required": [
"data",
"success"
],
"properties": {
"data": {
"description": "The acknowledgement data returned by the module.",
"allOf": [
{
"$ref": "#/definitions/Binary"
}
]
},
"success": {
"description": "Whether the acknowledgement was successful or not.",
"type": "boolean"
}
},
"additionalProperties": false
},
"IbcPacket": {
"type": "object",
"required": [
Expand Down
22 changes: 19 additions & 3 deletions packages/std/src/ibc/callbacks.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! This module contains types for the IBC callbacks defined in
//! [ADR-8](https://github.com/cosmos/ibc-go/blob/main/docs/architecture/adr-008-app-caller-cbs.md).

use cosmwasm_core::Binary;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::{Addr, IbcAcknowledgement, IbcPacket, IbcPacketAckMsg, IbcPacketTimeoutMsg, Uint64};
use crate::{Addr, IbcPacket, IbcPacketAckMsg, IbcPacketTimeoutMsg, Uint64};

/// This is just a type representing the data that has to be sent with the IBC message to receive
/// callbacks. It should be serialized to JSON and sent with the IBC message.
Expand Down Expand Up @@ -117,10 +118,15 @@ pub enum IbcSourceChainCallbackMsg {
/// The IBC destination chain callback is needed for cases where someone triggers the sending of an
/// IBC packet through some other message (i.e. not through [`IbcMsg::SendPacket`]) and
/// your contract needs to know that it received this.
/// The callback is called after the packet was successfully acknowledged on the destination chain.
/// A prominent example is the [`IbcMsg::Transfer`] message. Without callbacks, you cannot know
/// that someone sent you IBC coins.
///
/// The callback is called after the packet was acknowledged on the destination chain, as follows:
/// - If the acknowledgement is synchronous (i.e. returned immediately when the packet is received),
/// the callback is called only if the acknowledgement was successful.
/// - If the acknowledgement is asynchronous (i.e. written later using `WriteAcknowledgement`),
/// the callback is called regardless of the success of the acknowledgement.
///
/// Note that there are some prerequisites that need to be fulfilled to receive source chain callbacks:
/// - The contract must implement the `ibc_destination_chain_callback` entrypoint.
/// - The module that receives the packet must be wrapped by an `IBCMiddleware`
Expand All @@ -130,7 +136,17 @@ pub enum IbcSourceChainCallbackMsg {
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]

Check warning on line 136 in packages/std/src/ibc/callbacks.rs

View check run for this annotation

Codecov / codecov/patch

packages/std/src/ibc/callbacks.rs#L136

Added line #L136 was not covered by tests
pub struct IbcDestinationChainCallbackMsg {
pub packet: IbcPacket,
pub ack: IbcAcknowledgement,
pub ack: IbcFullAcknowledgement,
}

/// The acknowledgement written by the module on the destination chain.
/// It is different from the [`IbcAcknowledgement`] as it can be unsuccessful.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]

Check warning on line 144 in packages/std/src/ibc/callbacks.rs

View check run for this annotation

Codecov / codecov/patch

packages/std/src/ibc/callbacks.rs#L144

Added line #L144 was not covered by tests
pub struct IbcFullAcknowledgement {
/// The acknowledgement data returned by the module.
pub data: Binary,
/// Whether the acknowledgement was successful or not.
pub success: bool,
}

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions packages/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ pub use crate::ibc::IbcChannelOpenResponse;
pub use crate::ibc::{
Ibc3ChannelOpenResponse, IbcAcknowledgement, IbcBasicResponse, IbcCallbackData, IbcChannel,
IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcDestinationChainCallbackMsg,
IbcDstCallback, IbcEndpoint, IbcMsg, IbcOrder, IbcPacket, IbcPacketAckMsg, IbcPacketReceiveMsg,
IbcPacketTimeoutMsg, IbcReceiveResponse, IbcSourceChainCallbackMsg, IbcSrcCallback, IbcTimeout,
IbcTimeoutBlock,
IbcDstCallback, IbcEndpoint, IbcFullAcknowledgement, IbcMsg, IbcOrder, IbcPacket,
IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse,
IbcSourceChainCallbackMsg, IbcSrcCallback, IbcTimeout, IbcTimeoutBlock,
};
#[cfg(feature = "iterator")]
pub use crate::iterator::{Order, Record};
Expand Down
Binary file modified packages/vm/testdata/ibc_callbacks.wasm
Binary file not shown.

0 comments on commit 2ea0c1f

Please sign in to comment.