Skip to content

Commit

Permalink
Add middleware impl for pfm
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Dec 5, 2024
1 parent 9c8155b commit 0ab9bfa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 171 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/packet-forward/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ unexpected_cfgs = { level = "warn", check-cfg = ["cfg(coverage_nightly)"] }
borsh = ["dep:borsh"]

[dependencies]
ibc-middleware-module = { path = "../module" }
ibc-middleware-module-macros = { path = "../module-macros" }

borsh = { workspace = true, optional = true }
dur.workspace = true
either.workspace = true
Expand Down
196 changes: 25 additions & 171 deletions crates/packet-forward/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ use ibc_core_host_types::identifiers::{ChannelId, ConnectionId, PortId, Sequence
use ibc_core_router::module::Module as IbcCoreModule;
use ibc_core_router_types::event::{ModuleEvent, ModuleEventAttribute};
use ibc_core_router_types::module::ModuleExtras;
use ibc_middleware_module::MiddlewareModule;
use ibc_middleware_module_macros::from_middleware;
use ibc_primitives::prelude::*;
use ibc_primitives::Signer;

Expand Down Expand Up @@ -686,12 +688,31 @@ where
}
}

from_middleware! {
#[cfg_attr(coverage_nightly, coverage(off))]
impl<M> IbcCoreModule for PacketForwardMiddleware<M>
where
M: IbcCoreModule + PfmContext,
}

#[cfg_attr(coverage_nightly, coverage(off))]
impl<M> IbcCoreModule for PacketForwardMiddleware<M>
impl<M> MiddlewareModule for PacketForwardMiddleware<M>
where
M: IbcCoreModule + PfmContext,
{
fn on_recv_packet_execute(
type NextMiddleware = M;

#[inline]
fn next_middleware(&self) -> &M {
self.next()
}

#[inline]
fn next_middleware_mut(&mut self) -> &mut M {
self.next_mut()
}

fn middleware_on_recv_packet_execute(
&mut self,
packet: &Packet,
relayer: &Signer,
Expand All @@ -707,7 +728,7 @@ where
}
}

fn on_acknowledgement_packet_execute(
fn middleware_on_acknowledgement_packet_execute(
&mut self,
packet: &Packet,
acknowledgement: &Acknowledgement,
Expand All @@ -724,7 +745,7 @@ where
}
}

fn on_timeout_packet_execute(
fn middleware_on_timeout_packet_execute(
&mut self,
packet: &Packet,
relayer: &Signer,
Expand All @@ -739,173 +760,6 @@ where
Err(MiddlewareError::Message(err)) => (extras, new_packet_error(err)),
}
}

// =========================================================================
// the calls below are simply forwarded to the next middleware
// =========================================================================

fn on_acknowledgement_packet_validate(
&self,
packet: &Packet,
acknowledgement: &Acknowledgement,
relayer: &Signer,
) -> Result<(), PacketError> {
self.next
.on_acknowledgement_packet_validate(packet, acknowledgement, relayer)
}

fn on_timeout_packet_validate(
&self,
packet: &Packet,
relayer: &Signer,
) -> Result<(), PacketError> {
self.next.on_timeout_packet_validate(packet, relayer)
}

fn on_chan_open_init_validate(
&self,
order: Order,
connection_hops: &[ConnectionId],
port_id: &PortId,
channel_id: &ChannelId,
counterparty: &Counterparty,
version: &Version,
) -> Result<Version, ChannelError> {
self.next.on_chan_open_init_validate(
order,
connection_hops,
port_id,
channel_id,
counterparty,
version,
)
}

fn on_chan_open_init_execute(
&mut self,
order: Order,
connection_hops: &[ConnectionId],
port_id: &PortId,
channel_id: &ChannelId,
counterparty: &Counterparty,
version: &Version,
) -> Result<(ModuleExtras, Version), ChannelError> {
self.next.on_chan_open_init_execute(
order,
connection_hops,
port_id,
channel_id,
counterparty,
version,
)
}

fn on_chan_open_try_validate(
&self,
order: Order,
connection_hops: &[ConnectionId],
port_id: &PortId,
channel_id: &ChannelId,
counterparty: &Counterparty,
counterparty_version: &Version,
) -> Result<Version, ChannelError> {
self.next.on_chan_open_try_validate(
order,
connection_hops,
port_id,
channel_id,
counterparty,
counterparty_version,
)
}

fn on_chan_open_try_execute(
&mut self,
order: Order,
connection_hops: &[ConnectionId],
port_id: &PortId,
channel_id: &ChannelId,
counterparty: &Counterparty,
counterparty_version: &Version,
) -> Result<(ModuleExtras, Version), ChannelError> {
self.next.on_chan_open_try_execute(
order,
connection_hops,
port_id,
channel_id,
counterparty,
counterparty_version,
)
}

fn on_chan_open_ack_validate(
&self,
port_id: &PortId,
channel_id: &ChannelId,
counterparty_version: &Version,
) -> Result<(), ChannelError> {
self.next
.on_chan_open_ack_validate(port_id, channel_id, counterparty_version)
}

fn on_chan_open_ack_execute(
&mut self,
port_id: &PortId,
channel_id: &ChannelId,
counterparty_version: &Version,
) -> Result<ModuleExtras, ChannelError> {
self.next
.on_chan_open_ack_execute(port_id, channel_id, counterparty_version)
}

fn on_chan_open_confirm_validate(
&self,
port_id: &PortId,
channel_id: &ChannelId,
) -> Result<(), ChannelError> {
self.next.on_chan_open_confirm_validate(port_id, channel_id)
}

fn on_chan_open_confirm_execute(
&mut self,
port_id: &PortId,
channel_id: &ChannelId,
) -> Result<ModuleExtras, ChannelError> {
self.next.on_chan_open_confirm_execute(port_id, channel_id)
}

fn on_chan_close_init_validate(
&self,
port_id: &PortId,
channel_id: &ChannelId,
) -> Result<(), ChannelError> {
self.next.on_chan_close_init_validate(port_id, channel_id)
}

fn on_chan_close_init_execute(
&mut self,
port_id: &PortId,
channel_id: &ChannelId,
) -> Result<ModuleExtras, ChannelError> {
self.next.on_chan_close_init_execute(port_id, channel_id)
}

fn on_chan_close_confirm_validate(
&self,
port_id: &PortId,
channel_id: &ChannelId,
) -> Result<(), ChannelError> {
self.next
.on_chan_close_confirm_validate(port_id, channel_id)
}

fn on_chan_close_confirm_execute(
&mut self,
port_id: &PortId,
channel_id: &ChannelId,
) -> Result<ModuleExtras, ChannelError> {
self.next.on_chan_close_confirm_execute(port_id, channel_id)
}
}

#[inline]
Expand Down

0 comments on commit 0ab9bfa

Please sign in to comment.