Skip to content

Commit

Permalink
feat(ucs01-relay): use sequence for indexing pfm
Browse files Browse the repository at this point in the history
  • Loading branch information
PoisonPhang authored and aeryz committed Jun 5, 2024
1 parent 9958aca commit cba7aaf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
21 changes: 19 additions & 2 deletions cosmwasm/ucs01-relay-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub enum PacketReturnInfo {
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
pub struct PacketId {
pub height: u64,
pub index: u32,
pub index: u64,
}

/// Information about an in flight packet, used to process retries and refunds.
Expand All @@ -71,7 +71,7 @@ pub struct InFlightPfmPacket {
#[serde(untagged)]
pub enum Memo {
Forward { forward: PacketForward },
None {},
None { balls: String },
}

#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -134,3 +134,20 @@ impl<T: Into<String> + From<String>> Validate<T> for NotEmptyString {
}
}
}

#[cfg(test)]
mod tests {
use super::Memo;

#[test]
fn serde_parses_memo() {
// let memo = "\"balls\": \"string\"";
let memo = "{\"forward\": {\"receiver\": \"[eth_addr]\",\"port\": \"[union-eth port]\",\"channel\": \"[unioneth channel]\",\"timeout\": \"1000000\",\"retries\": 0}}";

let parsed = serde_json_wasm::from_str::<Memo>(memo).expect("works");

dbg!(parsed);

// panic!()
}
}
2 changes: 1 addition & 1 deletion cosmwasm/ucs01-relay-api/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ pub trait TransferProtocol {
false,
))
}
Memo::None {} => {}
Memo::None { .. } => {}
};
}

Expand Down
30 changes: 6 additions & 24 deletions cosmwasm/ucs01-relay/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,30 +536,21 @@ impl<'a> TransferProtocol for Ics20Protocol<'a> {
.expect("can normalize denom");
Coin {
denom: transfer_token.denom,
amount: transfer_token
.amount
.try_into()
.expect("CosmWasm require transferred amount to be Uint128..."),
amount: transfer_token.amount,
}
})
.collect();

// Forward the packet
let forward_response = self.forward_transfer_packet(
tokens,
original_packet,
original_packet.clone(),
forward,
override_addr,
false,
PacketReturnInfo::NewPacket(PacketId {
height: self.common.env.block.height,
index: self
.common
.env
.transaction
.clone()
.expect("transaction has tx info")
.index,
index: original_packet.sequence,
}),
);
let forward_response_messages = forward_response
Expand Down Expand Up @@ -951,30 +942,21 @@ impl<'a> TransferProtocol for Ucs01Protocol<'a> {
.expect("can normalize denom");
Coin {
denom: transfer_token.denom,
amount: transfer_token
.amount
.try_into()
.expect("CosmWasm require transferred amount to be Uint128..."),
amount: transfer_token.amount,
}
})
.collect();

// Forward the packet
let forward_response = self.forward_transfer_packet(
tokens,
original_packet,
original_packet.clone(),
forward,
override_addr,
false,
PacketReturnInfo::NewPacket(PacketId {
height: self.common.env.block.height,
index: self
.common
.env
.transaction
.clone()
.expect("transaction has tx info")
.index,
index: original_packet.sequence,
}),
);
let forward_response_messages = forward_response
Expand Down
2 changes: 1 addition & 1 deletion cosmwasm/ucs01-relay/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct PfmRefundPacketKey {
// Block height of the original transaction
pub height: u64,
// Index of the original transaction from `cosmwasm_std::types::TransactionInfo`
pub index: u32,
pub index: u64,
}

impl<'a> Prefixer<'a> for PfmRefundPacketKey {
Expand Down

0 comments on commit cba7aaf

Please sign in to comment.