Skip to content

Commit

Permalink
Make callback type configurable for ibc-callbacks contract
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Apr 8, 2024
1 parent a97c52c commit 173b410
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
21 changes: 15 additions & 6 deletions contracts/ibc-callbacks/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use cosmwasm_std::{
entry_point, to_json_binary, to_json_string, Binary, Deps, DepsMut, Empty, Env,
IbcBasicResponse, IbcCallbackData, IbcDestinationChainCallbackMsg, IbcMsg,
IbcBasicResponse, IbcCallbackData, IbcDestinationChainCallbackMsg, IbcDstCallback, IbcMsg,
IbcSourceChainCallbackMsg, IbcSrcCallback, IbcTimeout, MessageInfo, Response, StdError,
StdResult,
};

use crate::msg::{ExecuteMsg, QueryMsg};
use crate::msg::{CallbackType, ExecuteMsg, QueryMsg};
use crate::state::{load_stats, save_stats, CallbackStats};

#[entry_point]
Expand All @@ -30,6 +30,14 @@ pub fn execute(
info: MessageInfo,
msg: ExecuteMsg,
) -> StdResult<Response> {
let src_callback = IbcSrcCallback {
address: env.contract.address,
gas_limit: None,
};
let dst_callback = IbcDstCallback {
address: msg.to_address.clone(),
gas_limit: None,
};
let transfer_msg = match &*info.funds {
[coin] if !coin.amount.is_zero() => IbcMsg::Transfer {
to_address: msg.to_address,
Expand All @@ -38,10 +46,11 @@ pub fn execute(
),
channel_id: msg.channel_id,
amount: coin.clone(),
memo: Some(to_json_string(&IbcCallbackData::source(IbcSrcCallback {
address: env.contract.address,
gas_limit: None,
}))?),
memo: Some(to_json_string(&match msg.callback_type {
CallbackType::Both => IbcCallbackData::both(src_callback, dst_callback),
CallbackType::Src => IbcCallbackData::source(src_callback),
CallbackType::Dst => IbcCallbackData::destination(dst_callback),
})?),
},
_ => {
return Err(StdError::generic_err(
Expand Down
15 changes: 15 additions & 0 deletions contracts/ibc-callbacks/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,19 @@ pub struct ExecuteMsg {
pub channel_id: String,
/// The amount of seconds from now the transfer should timeout at
pub timeout_seconds: Uint64,
/// Who should receive callbacks for the message
#[serde(default)]
pub callback_type: CallbackType,
}

#[cw_serde]
#[derive(Default)]
pub enum CallbackType {
/// Only this contract on the source chain should receive callbacks
Src,
/// Only the destination address should receive callbacks
Dst,
/// Both the source contract and the destination address should receive callbacks
#[default]
Both,
}

0 comments on commit 173b410

Please sign in to comment.