From 3573a036fce3f38cf268a60f9915fa63cf9761b2 Mon Sep 17 00:00:00 2001 From: poisonphang <17688291+PoisonPhang@users.noreply.github.com> Date: Wed, 15 May 2024 04:11:41 -0500 Subject: [PATCH] feat(ucs01-relay): process pfm refund --- cosmwasm/ucs01-relay-api/src/protocol.rs | 6 ++-- cosmwasm/ucs01-relay/src/protocol.rs | 37 +++++++++++++++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/cosmwasm/ucs01-relay-api/src/protocol.rs b/cosmwasm/ucs01-relay-api/src/protocol.rs index 22d42b0ffa..2a23fad031 100644 --- a/cosmwasm/ucs01-relay-api/src/protocol.rs +++ b/cosmwasm/ucs01-relay-api/src/protocol.rs @@ -190,7 +190,7 @@ pub trait TransferProtocol { let memo: String = packet.extension().clone().into(); if let Ok(Memo::Forward { forward }) = serde_json_wasm::from_str::(&memo) { - return self.pfm_ack(ack, forward); + return self.pfm_ack(ack, forward, packet.sender(), packet.tokens()); } let (ack_msgs, ack_attr) = match ack { @@ -242,7 +242,7 @@ pub trait TransferProtocol { let memo = Into::::into(packet.extension().clone()); if let Ok(Memo::Forward { forward }) = serde_json_wasm::from_str::(&memo) { let ack = GenericAck::Err("giving up on forwarded packet after timeout".to_owned()); - return self.pfm_ack(ack, forward); + return self.pfm_ack(ack, forward, packet.sender(), packet.tokens()); } let timeout_event = if memo.is_empty() { @@ -358,6 +358,8 @@ pub trait TransferProtocol { &mut self, ack: GenericAck, original_forward_packet: PacketForward, + sender: &::Addr, + tokens: Vec, ) -> Result, Self::Error>; } diff --git a/cosmwasm/ucs01-relay/src/protocol.rs b/cosmwasm/ucs01-relay/src/protocol.rs index 63111f6aba..8b1af085f9 100644 --- a/cosmwasm/ucs01-relay/src/protocol.rs +++ b/cosmwasm/ucs01-relay/src/protocol.rs @@ -1,6 +1,6 @@ use cosmwasm_std::{ - wasm_execute, Addr, BankMsg, Coin, CosmosMsg, DepsMut, Env, HexBinary, IbcBasicResponse, - IbcEndpoint, IbcOrder, IbcReceiveResponse, MessageInfo, Uint128, Uint512, + wasm_execute, Addr, AnyMsg, BankMsg, Coin, CosmosMsg, DepsMut, Env, HexBinary, + IbcBasicResponse, IbcEndpoint, IbcOrder, IbcReceiveResponse, MessageInfo, Uint128, Uint512, }; use sha2::{Digest, Sha256}; use token_factory_api::TokenFactoryMsg; @@ -664,6 +664,8 @@ impl<'a> TransferProtocol for Ics20Protocol<'a> { &mut self, ack: GenericAck, original_forward_packet: PacketForward, + sender: &::Addr, + tokens: Vec, ) -> Result, Self::Error> { todo!() } @@ -990,6 +992,8 @@ impl<'a> TransferProtocol for Ucs01Protocol<'a> { &mut self, ack: GenericAck, original_forward_packet: PacketForward, + sender: &::Addr, + tokens: Vec, ) -> Result, Self::Error> { let packet_sequence = original_forward_packet @@ -1010,8 +1014,33 @@ impl<'a> TransferProtocol for Ucs01Protocol<'a> { })?; let (ack_msgs, ack_attr) = match ack { - Ok(_) => todo!(), - Err(_) => todo!(), + Ok(value) => { + let value_string = value.to_string(); + ( + self.send_tokens_success( + sender, + &original_forward_packet.receiver.value().as_bytes().into(), + tokens, + )?, + (!value_string.is_empty()).then_some(("success", value_string)), + ) + } + Err(error) => { + let error_string = error.to_string(); + ( + self.send_tokens_failure( + sender, + &original_forward_packet.receiver.as_bytes().into(), + tokens, + )?, + (!error_string.is_empty()).then_some(("error", error_string)), + ) + } + }; + + let diferred_ack_msg = AnyMsg { + type_url: "/diferredack.v1beta1.tx.MsgWriteDiferredAck".to_owned(), + value: todo!(), }; todo!()