Skip to content

Commit

Permalink
Added ics hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayanski committed Nov 12, 2024
1 parent dbec346 commit 1c1a53d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/interchain/interchain-core/src/ack_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ impl IbcAckParser {
Err(decode_ack_error(ack))
}

/// Verifies if the given ack is an ibc-hooks type and returns the ack result if it is
///
/// Returns an error if there was an error in the parsing process
///
/// The structure can be found here : https://github.com/cosmos/ibc-apps/blob/8cb681e31589bc90b47e0ab58173a579825fd56d/modules/ibc-hooks/wasm_hook.go#L119C1-L119C86
pub fn ics_hooks_ack(ack: &Binary) -> Result<IbcHooksAck, InterchainError> {
if let Ok(decoded_ics_ack) = from_json::<IbcHooksAck>(ack) {
return Ok(decoded_ics_ack);
}

Err(decode_ack_error(ack))
}

/// Verifies if the given ack is an ICS004 type with json parsing and returns the ack result if it is
///
/// Returns an error if there was an error in the parsing process
Expand Down Expand Up @@ -176,6 +189,15 @@ pub enum StdAck {
Error(String),
}

/// This is the ibc-hooks acknowledgment formated in json
/// https://github.com/cosmos/ibc-apps/blob/8cb681e31589bc90b47e0ab58173a579825fd56d/modules/ibc-hooks/wasm_hook.go#L119C1-L119C86

#[cw_serde]
pub struct IbcHooksAck {
contract_result: Option<Binary>,
ibc_ack: Binary,
}

pub mod polytone_callback {
use super::*;

Expand Down
6 changes: 6 additions & 0 deletions packages/interchain/interchain-core/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,25 @@ impl<Chain: CwEnv> IndexResponse for NestedPacketsFlow<Chain> {
}

pub mod success {
use crate::ack_parser::IbcHooksAck;
use crate::{ack_parser::polytone_callback::Callback, tx::TxId};
use cosmwasm_std::{Binary, Empty, StdError};
use cw_orch_core::environment::CwEnv;
use cw_orch_core::environment::IndexResponse;

/// Contains the result (ack success) associated with various Ibc applications
#[derive(Debug, PartialEq, Clone)]
#[non_exhaustive]
pub enum IbcAppResult<CustomResult = Empty> {
/// Contains a successful result for Polytone
Polytone(Callback),
/// Signals a successful result for ICS20 (token transfer)
Ics20,
/// Contains a successful result according to the ICS004 standard
Ics004(Vec<u8>),
/// Contains a successful result according to the ibc hooks standard
/// https://github.com/cosmos/ibc-apps/blob/8cb681e31589bc90b47e0ab58173a579825fd56d/modules/ibc-hooks/wasm_hook.go#L119C1-L119C86
IbcHooks(IbcHooksAck),
/// Contains a custom result. This is only used if a custom parsing function is specified
Custom(CustomResult),
}
Expand All @@ -195,6 +200,7 @@ pub mod success {
IbcAppResult::Polytone(callback) => IbcAppResult::Polytone(callback),
IbcAppResult::Ics20 => IbcAppResult::Ics20,
IbcAppResult::Ics004(vec) => IbcAppResult::Ics004(vec),
IbcAppResult::IbcHooks(ibc_hooks_ack) => IbcAppResult::IbcHooks(ibc_hooks_ack),
IbcAppResult::Custom(_) => unreachable!(),
}
}
Expand Down

0 comments on commit 1c1a53d

Please sign in to comment.