Skip to content

Commit

Permalink
Move module wrapper impl
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Dec 2, 2024
1 parent abb2841 commit 0f2a755
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
27 changes: 26 additions & 1 deletion crates/ibc/src/context/middlewares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use std::fmt::Debug;
use std::marker::PhantomData;
use std::rc::Rc;

use ibc_middleware_packet_forward::PacketForwardMiddleware;
use ibc::core::host::types::identifiers::PortId;
use ibc::core::router::module::Module;
use ibc::core::router::types::module::ModuleId;
use ibc_middleware_packet_forward::{PacketForwardMiddleware, PfmContext};
use namada_core::address::Address;

use self::pfm_mod::PfmTransferModule;
Expand All @@ -34,3 +37,25 @@ where
_phantom: PhantomData,
})
}

impl<C, Params> crate::ModuleWrapper for TransferMiddlewares<C, Params>
where
C: IbcCommonContext + Debug,
PfmTransferModule<C, Params>: PfmContext,
{
fn as_module(&self) -> &dyn Module {
self
}

fn as_module_mut(&mut self) -> &mut dyn Module {
self
}

fn module_id(&self) -> ModuleId {
ModuleId::new(ibc::apps::transfer::types::MODULE_ID_STR.to_string())
}

fn port_id(&self) -> PortId {
PortId::transfer()
}
}
30 changes: 3 additions & 27 deletions crates/ibc/src/context/middlewares/pfm_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,18 @@ use ibc::core::host::types::identifiers::{
ChannelId, ConnectionId, PortId, Sequence,
};
use ibc::core::router::module::Module;
use ibc::core::router::types::module::{ModuleExtras, ModuleId};
use ibc::core::router::types::module::ModuleExtras;
use ibc::primitives::Signer;
use ibc_middleware_packet_forward::{
InFlightPacket, InFlightPacketKey, PacketForwardMiddleware, PfmContext,
InFlightPacket, InFlightPacketKey, PfmContext,
};
use namada_core::address::{IBC as IBC_ADDRESS, MULTITOKEN};
use namada_state::{StorageRead, StorageWrite};

use crate::context::transfer_mod::TransferModule;
use crate::context::IbcContext;
use crate::storage::inflight_packet_key;
use crate::{
Error, IbcCommonContext, IbcStorageContext, ModuleWrapper,
TokenTransferContext,
};
use crate::{Error, IbcCommonContext, IbcStorageContext, TokenTransferContext};

/// A wrapper around an IBC transfer module necessary to
/// build execution contexts. This allows us to implement
Expand Down Expand Up @@ -472,24 +469,3 @@ where
ctx.storage_mut().delete(&key).map_err(Error::Storage)
}
}

impl<T> ModuleWrapper for PacketForwardMiddleware<T>
where
T: Module + PfmContext,
{
fn as_module(&self) -> &dyn Module {
self
}

fn as_module_mut(&mut self) -> &mut dyn Module {
self
}

fn module_id(&self) -> ModuleId {
ModuleId::new(ibc::apps::transfer::types::MODULE_ID_STR.to_string())
}

fn port_id(&self) -> PortId {
PortId::transfer()
}
}

0 comments on commit 0f2a755

Please sign in to comment.