Skip to content

Commit

Permalink
Make source chain callbacks extendable
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Apr 18, 2024
1 parent 3c55202 commit 2b44ac7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
25 changes: 19 additions & 6 deletions contracts/ibc-callbacks/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use cosmwasm_std::{
entry_point, to_json_binary, to_json_string, Binary, Deps, DepsMut, Empty, Env,
IbcBasicResponse, IbcCallbackRequest, IbcDestinationChainCallbackMsg, IbcDstCallback, IbcMsg,
IbcSourceChainCallbackMsg, IbcSrcCallback, IbcTimeout, MessageInfo, Response, StdError,
StdResult,
IbcPacketAckMsg, IbcPacketTimeoutMsg, IbcSourceChainCallbackMsg, IbcSrcCallback, IbcTimeout,
MessageInfo, Response, StdError, StdResult,
};

use crate::msg::{CallbackType, ExecuteMsg, QueryMsg};
Expand Down Expand Up @@ -82,13 +82,26 @@ pub fn ibc_source_chain_callback(
let mut counts = load_stats(deps.storage)?;

match msg {
IbcSourceChainCallbackMsg::Acknowledgement(ack) => {
IbcSourceChainCallbackMsg::Acknowledgement {
acknowledgement,
original_packet,
relayer,
..
} => {
// save the ack
counts.ibc_ack_callbacks.push(ack);
counts.ibc_ack_callbacks.push(IbcPacketAckMsg::new(
acknowledgement,
original_packet,
relayer,
));
}
IbcSourceChainCallbackMsg::Timeout(timeout) => {
IbcSourceChainCallbackMsg::Timeout {
packet, relayer, ..
} => {
// save the timeout
counts.ibc_timeout_callbacks.push(timeout);
counts
.ibc_timeout_callbacks
.push(IbcPacketTimeoutMsg::new(packet, relayer));
}
}

Expand Down
12 changes: 9 additions & 3 deletions packages/std/src/ibc/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cosmwasm_core::Binary;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::{Addr, IbcPacket, IbcPacketAckMsg, IbcPacketTimeoutMsg, Uint64};
use crate::{Addr, IbcAcknowledgement, IbcPacket, 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 and sent with the IBC message.
Expand Down Expand Up @@ -108,8 +108,14 @@ pub struct IbcDstCallback {
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum IbcSourceChainCallbackMsg {
Acknowledgement(IbcPacketAckMsg),
Timeout(IbcPacketTimeoutMsg),
#[non_exhaustive]
Acknowledgement {
acknowledgement: IbcAcknowledgement,
original_packet: IbcPacket,
relayer: Addr,
},
#[non_exhaustive]
Timeout { packet: IbcPacket, relayer: Addr },
}

/// The message type of the IBC destination chain callback.
Expand Down

0 comments on commit 2b44ac7

Please sign in to comment.