Skip to content

Commit

Permalink
Fixed ack for ics20
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayanski committed Oct 10, 2024
1 parent 4912195 commit 2da941e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/interchain/interchain-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-interchain-core"
version = "0.8.4"
version = "0.8.5"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
37 changes: 20 additions & 17 deletions packages/interchain/interchain-core/src/ack_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,12 @@ impl IbcAckParser {
///
/// Returns an error if there was an error in the parsing process
pub fn ics20_ack(ack: &Binary) -> Result<(), InterchainError> {
let decoded_fungible_packet: Result<FungibleTokenPacketAcknowledgement, _> = from_json(ack);
if let Ok(decoded_fungible_packet) = decoded_fungible_packet {
match decoded_fungible_packet {
FungibleTokenPacketAcknowledgement::Result(_) => return Ok(()),
FungibleTokenPacketAcknowledgement::Error(e) => {
return Err(InterchainError::FailedAckReceived(e))
}
}
let successful_ics20_packet = Binary::new(vec![0x01]);

if ack == &successful_ics20_packet {
return Ok(());
}

Err(decode_ack_error(ack))
}

Expand Down Expand Up @@ -118,15 +115,6 @@ pub(crate) fn decode_ack_error(ack: &Binary) -> InterchainError {
)
}

#[cw_serde]
/// Taken from https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md#data-structures
pub enum FungibleTokenPacketAcknowledgement {
/// Successful packet
Result(Binary),
/// Error packet
Error(String),
}

/// This is copied from https://github.com/cosmos/cosmos-rust/blob/4f2e3bbf9c67c8ffef44ef1e485a327fd66f060a/cosmos-sdk-proto/src/prost/ibc-go/ibc.core.channel.v1.rs#L164
/// This is the ICS-004 standard proposal
pub mod acknowledgement {
Expand Down Expand Up @@ -210,3 +198,18 @@ pub mod polytone_callback {
FatalError(String),
}
}

#[cfg(test)]
mod test {
use cosmwasm_std::Binary;

use super::IbcAckParser;

#[test]
fn ics20_ack_test() -> cw_orch::anyhow::Result<()> {
let success_ack = Binary::from_base64("AQ==")?;

IbcAckParser::ics20_ack(&success_ack)?;
Ok(())
}
}

0 comments on commit 2da941e

Please sign in to comment.