Skip to content

Commit

Permalink
fix(ucs01): convert pfm ack (#2059)
Browse files Browse the repository at this point in the history
Partially addresses to #2043.

When hopping from `ics20` to `ucs01`, converts `ucs01` ack to `ics20`
before sending it back and the other way around.
  • Loading branch information
PoisonPhang authored Jun 8, 2024
2 parents 7759bba + 8eb963e commit 2a1318c
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 83 deletions.
3 changes: 3 additions & 0 deletions cosmwasm/ucs01-relay-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub struct InFlightPfmPacket {
pub src_packet_timeout: IbcTimeout,
pub forward_channel_id: String,
pub forward_port_id: String,
pub original_protocol_version: String,
}

impl InFlightPfmPacket {
Expand All @@ -83,6 +84,7 @@ impl InFlightPfmPacket {
timeout: u64,
forward_channel_id: String,
forward_port_id: String,
original_protocol_version: String,
) -> Self {
Self {
original_sender_addr,
Expand All @@ -96,6 +98,7 @@ impl InFlightPfmPacket {
packet_sequence: original_packet.sequence,
forward_channel_id,
forward_port_id,
original_protocol_version,
}
}

Expand Down
18 changes: 10 additions & 8 deletions cosmwasm/ucs01-relay-api/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,12 @@ pub trait TransferProtocol {
.add_messages(refund_msgs))
}

#[allow(clippy::type_complexity)]
fn receive_transfer(
&mut self,
receiver: &<Self::Packet as TransferPacket>::Addr,
tokens: Vec<TransferToken>,
) -> Result<Vec<CosmosMsg<Self::CustomMsg>>, Self::Error>;
) -> Result<(Vec<TransferToken>, Vec<CosmosMsg<Self::CustomMsg>>), Self::Error>;

fn receive(&mut self, original_packet: IbcPacket) -> IbcReceiveResponse<Self::CustomMsg> {
let handle = || -> Result<IbcReceiveResponse<Self::CustomMsg>, Self::Error> {
Expand All @@ -308,6 +309,7 @@ pub trait TransferProtocol {
// to be overwritten.
let transfer_msgs = self
.receive_transfer(packet.receiver(), packet.tokens())?
.1
.into_iter()
.map(|msg| SubMsg::reply_on_error(msg, Self::RECEIVE_REPLY_ID));

Expand All @@ -316,13 +318,7 @@ pub trait TransferProtocol {
if let Ok(memo) = serde_json_wasm::from_str::<Memo>(&memo) {
match memo {
Memo::Forward { forward } => {
return Ok(Self::packet_forward(
self,
packet,
original_packet,
forward,
false,
))
return Ok(self.packet_forward(packet, original_packet, forward, false))
}
Memo::None { .. } => {}
};
Expand Down Expand Up @@ -401,6 +397,12 @@ pub trait TransferProtocol {
tokens: Vec<TransferToken>,
sequence: u64,
) -> Result<Option<(Vec<CosmosMsg<Self::CustomMsg>>, Vec<(&str, String)>)>, Self::Error>;

fn convert_ack_to_foreign_protocol(
&self,
foreign_protocol: &str,
ack: GenericAck,
) -> Result<GenericAck, Self::Error>;
}

#[cfg(test)]
Expand Down
5 changes: 4 additions & 1 deletion cosmwasm/ucs01-relay/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::string::FromUtf8Error;

use cosmwasm_std::{IbcOrder, OverflowError, StdError, SubMsgResult};
use cosmwasm_std::{Binary, IbcOrder, OverflowError, StdError, SubMsgResult};
use cw_controllers::AdminError;
use thiserror::Error;
use ucs01_relay_api::{middleware::MiddlewareError, protocol::ProtocolError, types::EncodingError};
Expand Down Expand Up @@ -65,6 +65,9 @@ pub enum ContractError {

#[error("{0}")]
MiddlewareError(#[from] MiddlewareError),

#[error("invalid ack ({0})")]
InvalidAck(Binary),
}

impl From<FromUtf8Error> for ContractError {
Expand Down
Loading

0 comments on commit 2a1318c

Please sign in to comment.