Skip to content

Commit

Permalink
feat(ucs01-relay): emit event on pfm hop
Browse files Browse the repository at this point in the history
  • Loading branch information
PoisonPhang committed Jun 7, 2024
1 parent e795c11 commit ce251fd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
23 changes: 22 additions & 1 deletion cosmwasm/ucs01-relay-api/src/middleware.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{Addr, Binary, IbcPacket, IbcTimeout};
use cosmwasm_std::{Addr, Binary, Event, IbcPacket, IbcTimeout};
use serde::{Deserialize, Serialize};
use thiserror::Error;
use unionlabs::{
Expand All @@ -8,8 +8,19 @@ use unionlabs::{

pub const DEFAULT_PFM_TIMEOUT: &str = "1m";
pub const DEFAULT_PFM_RETRIES: u8 = 0;

pub const PFM_MODULE_NAME: &str = "packetforwardmiddleware";

pub const PFM_ERROR_EVENT: &str = "packet_forward_error";
pub const PFM_HOP_EVENT: &str = "packet_forward_hop";

pub const RECV_SEQUENCE_ATTR: &str = "recv_sequence";
pub const SENT_SEQUENCE_ATTR: &str = "sent_sequence";
pub const DEST_CHANNEL_ATTR: &str = "dest_channel";
pub const DEST_PORT_ATTR: &str = "dest_port";
pub const SRC_CHANNEL_ATTR: &str = "src_channel";
pub const SRC_PORT_ATTR: &str = "src_port";

#[derive(Error, Debug, PartialEq)]
pub enum MiddlewareError {
#[error("{0}")]
Expand Down Expand Up @@ -87,6 +98,16 @@ impl InFlightPfmPacket {
forward_port_id,
}
}

pub fn create_hop_event(&self, sent_sequence: u64) -> Event {
Event::new(PFM_HOP_EVENT)
.add_attribute(RECV_SEQUENCE_ATTR, self.packet_sequence.to_string())
.add_attribute(DEST_CHANNEL_ATTR, self.forward_channel_id.clone())
.add_attribute(DEST_PORT_ATTR, self.forward_port_id.clone())
.add_attribute(SENT_SEQUENCE_ATTR, sent_sequence.to_string())
.add_attribute(SRC_CHANNEL_ATTR, self.packet_src_channel_id.clone())
.add_attribute(SRC_PORT_ATTR, self.packet_src_port_id.clone())
}
}

#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
Expand Down
3 changes: 1 addition & 2 deletions cosmwasm/ucs01-relay/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ pub fn reply(
.save(deps.storage, refund_packet_key.clone(), &in_flight_packet)
.expect("infallible update");

Ok(Response::new()
.add_attribute("pfm_store_inclusion", format!("{refund_packet_key:?}")))
Ok(Response::new().add_event(in_flight_packet.create_hop_event(send_res.sequence)))
}
(_, result) => Err(ContractError::UnknownReply {
id: reply.id,
Expand Down

0 comments on commit ce251fd

Please sign in to comment.