Skip to content

Commit

Permalink
feat(ucs01-relay): process pfm refund
Browse files Browse the repository at this point in the history
  • Loading branch information
PoisonPhang authored and aeryz committed Jun 5, 2024
1 parent d2446c5 commit 3573a03
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
6 changes: 4 additions & 2 deletions cosmwasm/ucs01-relay-api/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(&memo) {
return self.pfm_ack(ack, forward);
return self.pfm_ack(ack, forward, packet.sender(), packet.tokens());
}

let (ack_msgs, ack_attr) = match ack {
Expand Down Expand Up @@ -242,7 +242,7 @@ pub trait TransferProtocol {
let memo = Into::<String>::into(packet.extension().clone());
if let Ok(Memo::Forward { forward }) = serde_json_wasm::from_str::<Memo>(&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() {
Expand Down Expand Up @@ -358,6 +358,8 @@ pub trait TransferProtocol {
&mut self,
ack: GenericAck,
original_forward_packet: PacketForward,
sender: &<Self::Packet as TransferPacket>::Addr,
tokens: Vec<TransferToken>,
) -> Result<IbcBasicResponse<Self::CustomMsg>, Self::Error>;
}

Expand Down
37 changes: 33 additions & 4 deletions cosmwasm/ucs01-relay/src/protocol.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -664,6 +664,8 @@ impl<'a> TransferProtocol for Ics20Protocol<'a> {
&mut self,
ack: GenericAck,
original_forward_packet: PacketForward,
sender: &<Self::Packet as TransferPacket>::Addr,
tokens: Vec<TransferToken>,
) -> Result<IbcBasicResponse<Self::CustomMsg>, Self::Error> {
todo!()
}
Expand Down Expand Up @@ -990,6 +992,8 @@ impl<'a> TransferProtocol for Ucs01Protocol<'a> {
&mut self,
ack: GenericAck,
original_forward_packet: PacketForward,
sender: &<Self::Packet as TransferPacket>::Addr,
tokens: Vec<TransferToken>,
) -> Result<IbcBasicResponse<Self::CustomMsg>, Self::Error> {
let packet_sequence =
original_forward_packet
Expand All @@ -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!()
Expand Down

0 comments on commit 3573a03

Please sign in to comment.