Trait cw_iper_test::Middleware
source · pub trait Middleware {
Show 13 methods
// Required method
fn get_inner(&self) -> &dyn IbcAndStargate;
// Provided methods
fn mid_handle_outgoing_packet(
&self,
api: &dyn Api,
block: &BlockInfo,
sender: Addr,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
msg: IbcMsg,
channel: IbcChannelWrapper
) -> Result<MiddlewareResponse<AppResponse, IbcMsg>, Error> { ... }
fn mid_handle_outgoing_packet_after(
&self,
api: &dyn Api,
block: &BlockInfo,
sender: Addr,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
original_msg: IbcMsg,
forwarded_msg: IbcMsg,
returning_reponse: AppResponse,
channel: IbcChannelWrapper
) -> Result<AppResponse, Error> { ... }
fn mid_packet_receive_before(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
packet: IbcPacketReceiveMsg
) -> InfallibleResult<MiddlewareResponse<PacketReceiveOk, IbcPacketReceiveMsg>, PacketReceiveFailing> { ... }
fn mid_packet_receive_after(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
original_packet: IbcPacketReceiveMsg,
forwarded_packet: IbcPacketReceiveMsg,
returning_reponse: InfallibleResult<PacketReceiveOk, PacketReceiveFailing>
) -> InfallibleResult<MidRecOk, MidRecFailing> { ... }
fn mid_packet_ack_before(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
packet: AckPacket
) -> Result<MiddlewareResponse<AppResponse, AckPacket>, Error> { ... }
fn mid_packet_ack_after(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
original_packet: AckPacket,
forwarded_packet: AckPacket,
returning_reponse: AppResponse
) -> Result<AppResponse, Error> { ... }
fn mid_packet_timeout_before(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
packet: TimeoutPacket
) -> Result<MiddlewareResponse<AppResponse, TimeoutPacket>, Error> { ... }
fn mid_packet_timeout_after(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
torage: Rc<RefCell<&mut dyn Storage>>,
original_packet: TimeoutPacket,
forwarded_packet: TimeoutPacket,
returning_reponse: AppResponse
) -> Result<AppResponse, Error> { ... }
fn mid_open_channel_before(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
msg: IbcChannelOpenMsg
) -> Result<MiddlewareResponse<AppResponse, IbcChannelOpenMsg>, Error> { ... }
fn mid_open_channel_after(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
original_msg: IbcChannelOpenMsg,
forwarded_msg: IbcChannelOpenMsg,
returning_reponse: AppResponse
) -> Result<AppResponse, Error> { ... }
fn mid_channel_connect_before(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
msg: IbcChannelConnectMsg
) -> Result<MiddlewareResponse<AppResponse, IbcChannelConnectMsg>, Error> { ... }
fn mid_channel_connect_after(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
original_msg: IbcChannelConnectMsg,
forwarded_msg: IbcChannelConnectMsg,
returning_reponse: AppResponse
) -> Result<AppResponse, Error> { ... }
}
Expand description
This trait allow to reproduce the functionality of Middleware ibc application (like IbcHook).
Middleware
allow to wrap another IbcApplication
and and alter/implement functionality when one of the various functions that the IbcApplication
implements is called.
The core logic about []
Middleware
trait alredy implements IbcApplication
and StargateApplication
by default, so implementing Middleware
implement also IbcApplication
and StargateApplication
.
§How it works
The core logic of the Middleware
involves the implementation of functions
that wrap the individual functions
of the IbcApplication
into two distinct functions
, called before
and after
. For example, considering
the IbcApplication::packet_receive
function, Middleware
managed through Middleware::mid_packet_receive_before
and Middleware::mid_packet_receive_after
to handle actions before and after the execution of IbcApplication::packet_receive
.
Specifically, the before
functions are called before the linked function
of the inner
IbcApplication
is invoked.
These before
functions return a type of MiddlewareResponse
, which offers two alternatives:
- Stop: The
inner function
will not be called, and the value is returned directly. - Continue: The
inner function
will be called. The result of theinner function
is then passed to the correspondingafter
function of the Middleware, where further actions can be performed.
§Realistic Example: Implementing IbcHook
In the IbcHook
, during Middleware::mid_packet_receive_before
, if the memo
of the [FungibleTokenPacketData
] is set
to trigger the IBC hook
, the packet
is modified, and the sender
is set according to the IBC hook standard
.
This packet
is then returned with Continue
, and passed to the inner IbcApplication
(e.g., Ics20
or
another Middleware
if there are multiple wraps).
Once Ics20
completes the execution of IbcApplication::packet_receive
, Middleware::mid_packet_receive_after
in the
IbcHook
is triggered, where the smart contract is triggered to send the tokens. This functionality is
managed in the after
function as the Ics20
module must mint the tokens first.
Required Methods§
sourcefn get_inner(&self) -> &dyn IbcAndStargate
fn get_inner(&self) -> &dyn IbcAndStargate
Return the inner IbcApplication
Provided Methods§
sourcefn mid_handle_outgoing_packet(
&self,
api: &dyn Api,
block: &BlockInfo,
sender: Addr,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
msg: IbcMsg,
channel: IbcChannelWrapper
) -> Result<MiddlewareResponse<AppResponse, IbcMsg>, Error>
fn mid_handle_outgoing_packet( &self, api: &dyn Api, block: &BlockInfo, sender: Addr, router: &RouterWrapper<'_>, storage: Rc<RefCell<&mut dyn Storage>>, msg: IbcMsg, channel: IbcChannelWrapper ) -> Result<MiddlewareResponse<AppResponse, IbcMsg>, Error>
Function triggered before the calling of inner IbcApplication::handle_outgoing_packet
.
If the return type is [MiddlewareResponse::Continue(IbcMsg)
], the returned IbcMsg
will forwarded to the inner IbcApplication::handle_outgoing_packet
.
sourcefn mid_handle_outgoing_packet_after(
&self,
api: &dyn Api,
block: &BlockInfo,
sender: Addr,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
original_msg: IbcMsg,
forwarded_msg: IbcMsg,
returning_reponse: AppResponse,
channel: IbcChannelWrapper
) -> Result<AppResponse, Error>
fn mid_handle_outgoing_packet_after( &self, api: &dyn Api, block: &BlockInfo, sender: Addr, router: &RouterWrapper<'_>, storage: Rc<RefCell<&mut dyn Storage>>, original_msg: IbcMsg, forwarded_msg: IbcMsg, returning_reponse: AppResponse, channel: IbcChannelWrapper ) -> Result<AppResponse, Error>
Function triggered after IbcApplication::handle_outgoing_packet
only if Middleware::mid_handle_outgoing_packet
returned MiddlewareResponse::Continue
sourcefn mid_packet_receive_before(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
packet: IbcPacketReceiveMsg
) -> InfallibleResult<MiddlewareResponse<PacketReceiveOk, IbcPacketReceiveMsg>, PacketReceiveFailing>
fn mid_packet_receive_before( &self, api: &dyn Api, block: &BlockInfo, router: &RouterWrapper<'_>, storage: Rc<RefCell<&mut dyn Storage>>, packet: IbcPacketReceiveMsg ) -> InfallibleResult<MiddlewareResponse<PacketReceiveOk, IbcPacketReceiveMsg>, PacketReceiveFailing>
Function triggered before the calling of inner IbcApplication::packet_receive
.
If the return type is [MiddlewareResponse::Continue(IbcPacketReceiveMsg)
], the returned IbcPacketReceiveMsg
will forwarded to the inner IbcApplication::packet_receive
.
sourcefn mid_packet_receive_after(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
original_packet: IbcPacketReceiveMsg,
forwarded_packet: IbcPacketReceiveMsg,
returning_reponse: InfallibleResult<PacketReceiveOk, PacketReceiveFailing>
) -> InfallibleResult<MidRecOk, MidRecFailing>
fn mid_packet_receive_after( &self, api: &dyn Api, block: &BlockInfo, router: &RouterWrapper<'_>, storage: Rc<RefCell<&mut dyn Storage>>, original_packet: IbcPacketReceiveMsg, forwarded_packet: IbcPacketReceiveMsg, returning_reponse: InfallibleResult<PacketReceiveOk, PacketReceiveFailing> ) -> InfallibleResult<MidRecOk, MidRecFailing>
Function triggered after IbcApplication::packet_receive
only if Middleware::mid_packet_receive_before
returned MiddlewareResponse::Continue
sourcefn mid_packet_ack_before(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
packet: AckPacket
) -> Result<MiddlewareResponse<AppResponse, AckPacket>, Error>
fn mid_packet_ack_before( &self, api: &dyn Api, block: &BlockInfo, router: &RouterWrapper<'_>, storage: Rc<RefCell<&mut dyn Storage>>, packet: AckPacket ) -> Result<MiddlewareResponse<AppResponse, AckPacket>, Error>
Function triggered before the calling of inner IbcApplication::packet_ack
.
If the return type is [MiddlewareResponse::Continue(AckPacket)
], the returned [AckPacket
] will forwarded to the inner IbcApplication::packet_ack
.
sourcefn mid_packet_ack_after(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
original_packet: AckPacket,
forwarded_packet: AckPacket,
returning_reponse: AppResponse
) -> Result<AppResponse, Error>
fn mid_packet_ack_after( &self, api: &dyn Api, block: &BlockInfo, router: &RouterWrapper<'_>, storage: Rc<RefCell<&mut dyn Storage>>, original_packet: AckPacket, forwarded_packet: AckPacket, returning_reponse: AppResponse ) -> Result<AppResponse, Error>
Function triggered after IbcApplication::packet_ack
only if Middleware::mid_packet_ack_before
returned MiddlewareResponse::Continue
sourcefn mid_packet_timeout_before(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
packet: TimeoutPacket
) -> Result<MiddlewareResponse<AppResponse, TimeoutPacket>, Error>
fn mid_packet_timeout_before( &self, api: &dyn Api, block: &BlockInfo, router: &RouterWrapper<'_>, storage: Rc<RefCell<&mut dyn Storage>>, packet: TimeoutPacket ) -> Result<MiddlewareResponse<AppResponse, TimeoutPacket>, Error>
Function triggered before the calling of inner IbcApplication::packet_timeout
.
If the return type is [MiddlewareResponse::Continue(TimeoutPacket)
], the returned [TimeoutPacket
] will forwarded to the inner IbcApplication::packet_timeout
.
sourcefn mid_packet_timeout_after(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
torage: Rc<RefCell<&mut dyn Storage>>,
original_packet: TimeoutPacket,
forwarded_packet: TimeoutPacket,
returning_reponse: AppResponse
) -> Result<AppResponse, Error>
fn mid_packet_timeout_after( &self, api: &dyn Api, block: &BlockInfo, router: &RouterWrapper<'_>, torage: Rc<RefCell<&mut dyn Storage>>, original_packet: TimeoutPacket, forwarded_packet: TimeoutPacket, returning_reponse: AppResponse ) -> Result<AppResponse, Error>
Function triggered after IbcApplication::packet_timeout
only if Middleware::mid_packet_timeout_before
returned MiddlewareResponse::Continue
sourcefn mid_open_channel_before(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
msg: IbcChannelOpenMsg
) -> Result<MiddlewareResponse<AppResponse, IbcChannelOpenMsg>, Error>
fn mid_open_channel_before( &self, api: &dyn Api, block: &BlockInfo, router: &RouterWrapper<'_>, storage: Rc<RefCell<&mut dyn Storage>>, msg: IbcChannelOpenMsg ) -> Result<MiddlewareResponse<AppResponse, IbcChannelOpenMsg>, Error>
Function triggered before the calling of inner IbcApplication::open_channel
.
If the return type is [MiddlewareResponse::Continue(IbcChannelOpenMsg)
], the returned IbcChannelOpenMsg
will forwarded to the inner IbcApplication::open_channel
.
sourcefn mid_open_channel_after(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
original_msg: IbcChannelOpenMsg,
forwarded_msg: IbcChannelOpenMsg,
returning_reponse: AppResponse
) -> Result<AppResponse, Error>
fn mid_open_channel_after( &self, api: &dyn Api, block: &BlockInfo, router: &RouterWrapper<'_>, storage: Rc<RefCell<&mut dyn Storage>>, original_msg: IbcChannelOpenMsg, forwarded_msg: IbcChannelOpenMsg, returning_reponse: AppResponse ) -> Result<AppResponse, Error>
Function triggered after IbcApplication::open_channel
only if Middleware::mid_open_channel_before
returned MiddlewareResponse::Continue
sourcefn mid_channel_connect_before(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
msg: IbcChannelConnectMsg
) -> Result<MiddlewareResponse<AppResponse, IbcChannelConnectMsg>, Error>
fn mid_channel_connect_before( &self, api: &dyn Api, block: &BlockInfo, router: &RouterWrapper<'_>, storage: Rc<RefCell<&mut dyn Storage>>, msg: IbcChannelConnectMsg ) -> Result<MiddlewareResponse<AppResponse, IbcChannelConnectMsg>, Error>
Function triggered before the calling of inner IbcApplication::channel_connect
.
If the return type is [MiddlewareResponse::Continue(IbcChannelConnectMsg)
], the returned IbcChannelConnectMsg
will forwarded to the inner IbcApplication::channel_connect
.
sourcefn mid_channel_connect_after(
&self,
api: &dyn Api,
block: &BlockInfo,
router: &RouterWrapper<'_>,
storage: Rc<RefCell<&mut dyn Storage>>,
original_msg: IbcChannelConnectMsg,
forwarded_msg: IbcChannelConnectMsg,
returning_reponse: AppResponse
) -> Result<AppResponse, Error>
fn mid_channel_connect_after( &self, api: &dyn Api, block: &BlockInfo, router: &RouterWrapper<'_>, storage: Rc<RefCell<&mut dyn Storage>>, original_msg: IbcChannelConnectMsg, forwarded_msg: IbcChannelConnectMsg, returning_reponse: AppResponse ) -> Result<AppResponse, Error>
Function triggered after IbcApplication::channel_connect
only if Middleware::mid_channel_connect_before
returned MiddlewareResponse::Continue