Skip to content

Commit

Permalink
Update IbcTimeout logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cwlittle committed Sep 18, 2024
1 parent 657693a commit 273c600
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
env: Env,
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
let state = State {
owner: info.sender.clone(),
channel_id: msg.channel_id.clone(),
ibc_timeout: IbcTimeout::from(Timestamp::from_seconds(msg.ibc_timeout)),
ibc_timeout_interval: msg.ibc_timeout_interval,
min_disbursal_amount: msg.min_disbursal_amount,
memo: msg.memo.clone(),
to_address: msg.to_address.clone(),
Expand Down Expand Up @@ -63,11 +63,14 @@ pub mod execute {
return Err(ContractError::InsufficientFunds {});
}

let time = env.block.time;
let timeout_timestamp = time.plus_seconds(state.ibc_timeout_interval);

let msg = CosmosMsg::Ibc(IbcMsg::Transfer {
channel_id: state.channel_id,
to_address: state.to_address,
amount: coin,
timeout: state.ibc_timeout,
timeout: IbcTimeout::with_timestamp(timeout_timestamp),
memo: Some(state.memo),
});

Expand Down Expand Up @@ -108,7 +111,7 @@ mod tests {
let msg = InstantiateMsg {
min_disbursal_amount: 0,
channel_id: "channel-0".to_string(),
ibc_timeout: 1000,
ibc_timeout_interval: 1000,
memo: "memo".to_string(),
to_address: "to_address".to_string(),
};
Expand All @@ -130,7 +133,7 @@ mod tests {
let msg = InstantiateMsg {
min_disbursal_amount: 0,
channel_id: "channel-0".to_string(),
ibc_timeout: 1000,
ibc_timeout_interval: 1000,
memo: "memo".to_string(),
to_address: "to_address".to_string(),
};
Expand Down
2 changes: 1 addition & 1 deletion src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cosmwasm_std::Coin;
pub struct InstantiateMsg {
pub min_disbursal_amount: u64,
pub channel_id: String,
pub ibc_timeout: u64,
pub ibc_timeout_interval: u64,
pub memo: String,
pub to_address: String,
}
Expand Down
2 changes: 1 addition & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cw_storage_plus::Item;
pub struct State {
pub owner: Addr,
pub channel_id: String,
pub ibc_timeout: IbcTimeout,
pub ibc_timeout_interval: u64,
pub min_disbursal_amount: u64,
pub memo: String,
pub to_address: String,
Expand Down

0 comments on commit 273c600

Please sign in to comment.