Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ics context #247

Merged
merged 12 commits into from
Nov 21, 2022
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Rename Ics* names to something more descriptive
([#245](https://github.com/cosmos/ibc-rs/issues/245))
24 changes: 12 additions & 12 deletions crates/ibc/src/applications/transfer/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,16 @@ pub trait BankKeeper {

/// Captures all the dependencies which the ICS20 module requires to be able to dispatch and
/// process IBC messages.
pub trait Ics20Context:
TokenTransferKeeper<AccountId = <Self as Ics20Context>::AccountId>
+ TokenTransferReader<AccountId = <Self as Ics20Context>::AccountId>
pub trait TokenTransferContext:
TokenTransferKeeper<AccountId = <Self as TokenTransferContext>::AccountId>
+ TokenTransferReader<AccountId = <Self as TokenTransferContext>::AccountId>
{
type AccountId: TryFrom<Signer>;
}

#[allow(clippy::too_many_arguments)]
pub fn on_chan_open_init(
ctx: &mut impl Ics20Context,
ctx: &mut impl TokenTransferContext,
order: Order,
_connection_hops: &[ConnectionId],
port_id: &PortId,
Expand All @@ -181,7 +181,7 @@ pub fn on_chan_open_init(

#[allow(clippy::too_many_arguments)]
pub fn on_chan_open_try(
_ctx: &mut impl Ics20Context,
_ctx: &mut impl TokenTransferContext,
order: Order,
_connection_hops: &[ConnectionId],
_port_id: &PortId,
Expand All @@ -202,7 +202,7 @@ pub fn on_chan_open_try(
}

pub fn on_chan_open_ack(
_ctx: &mut impl Ics20Context,
_ctx: &mut impl TokenTransferContext,
_port_id: &PortId,
_channel_id: &ChannelId,
counterparty_version: &Version,
Expand All @@ -217,30 +217,30 @@ pub fn on_chan_open_ack(
}

pub fn on_chan_open_confirm(
_ctx: &mut impl Ics20Context,
_ctx: &mut impl TokenTransferContext,
_port_id: &PortId,
_channel_id: &ChannelId,
) -> Result<ModuleExtras, Ics20Error> {
Ok(ModuleExtras::empty())
}

pub fn on_chan_close_init(
_ctx: &mut impl Ics20Context,
_ctx: &mut impl TokenTransferContext,
_port_id: &PortId,
_channel_id: &ChannelId,
) -> Result<ModuleExtras, Ics20Error> {
Err(Ics20Error::cant_close_channel())
}

pub fn on_chan_close_confirm(
_ctx: &mut impl Ics20Context,
_ctx: &mut impl TokenTransferContext,
_port_id: &PortId,
_channel_id: &ChannelId,
) -> Result<ModuleExtras, Ics20Error> {
Ok(ModuleExtras::empty())
}

pub fn on_recv_packet<Ctx: 'static + Ics20Context>(
pub fn on_recv_packet<Ctx: 'static + TokenTransferContext>(
ctx: &Ctx,
output: &mut ModuleOutputBuilder,
packet: &Packet,
Expand Down Expand Up @@ -272,7 +272,7 @@ pub fn on_recv_packet<Ctx: 'static + Ics20Context>(
}

pub fn on_acknowledgement_packet(
ctx: &mut impl Ics20Context,
ctx: &mut impl TokenTransferContext,
output: &mut ModuleOutputBuilder,
packet: &Packet,
acknowledgement: &GenericAcknowledgement,
Expand All @@ -299,7 +299,7 @@ pub fn on_acknowledgement_packet(
}

pub fn on_timeout_packet(
ctx: &mut impl Ics20Context,
ctx: &mut impl TokenTransferContext,
output: &mut ModuleOutputBuilder,
packet: &Packet,
_relayer: &Signer,
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/applications/transfer/relay.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! This module implements the processing logic for ICS20 (token transfer) message.
use crate::applications::transfer::context::Ics20Context;
use crate::applications::transfer::context::TokenTransferContext;
use crate::applications::transfer::error::Error as Ics20Error;
use crate::applications::transfer::is_sender_chain_source;
use crate::applications::transfer::packet::PacketData;
Expand All @@ -12,7 +12,7 @@ pub mod on_timeout_packet;
pub mod send_transfer;

fn refund_packet_token(
ctx: &mut impl Ics20Context,
ctx: &mut impl TokenTransferContext,
packet: &Packet,
data: &PacketData,
) -> Result<(), Ics20Error> {
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/applications/transfer/relay/on_ack_packet.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::applications::transfer::acknowledgement::Acknowledgement;
use crate::applications::transfer::context::Ics20Context;
use crate::applications::transfer::context::TokenTransferContext;
use crate::applications::transfer::error::Error as Ics20Error;
use crate::applications::transfer::packet::PacketData;
use crate::applications::transfer::relay::refund_packet_token;
use crate::core::ics04_channel::packet::Packet;

pub fn process_ack_packet(
ctx: &mut impl Ics20Context,
ctx: &mut impl TokenTransferContext,
packet: &Packet,
data: &PacketData,
ack: &Acknowledgement,
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/applications/transfer/relay/on_recv_packet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::applications::transfer::context::Ics20Context;
use crate::applications::transfer::context::TokenTransferContext;
use crate::applications::transfer::error::Error as Ics20Error;
use crate::applications::transfer::events::DenomTraceEvent;
use crate::applications::transfer::packet::PacketData;
Expand All @@ -7,7 +7,7 @@ use crate::core::ics04_channel::packet::Packet;
use crate::core::ics26_routing::context::{ModuleOutputBuilder, WriteFn};
use crate::prelude::*;

pub fn process_recv_packet<Ctx: 'static + Ics20Context>(
pub fn process_recv_packet<Ctx: 'static + TokenTransferContext>(
ctx: &Ctx,
output: &mut ModuleOutputBuilder,
packet: &Packet,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::applications::transfer::context::Ics20Context;
use crate::applications::transfer::context::TokenTransferContext;
use crate::applications::transfer::error::Error as Ics20Error;
use crate::applications::transfer::packet::PacketData;
use crate::applications::transfer::relay::refund_packet_token;
use crate::core::ics04_channel::packet::Packet;

pub fn process_timeout_packet(
ctx: &mut impl Ics20Context,
ctx: &mut impl TokenTransferContext,
packet: &Packet,
data: &PacketData,
) -> Result<(), Ics20Error> {
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/applications/transfer/relay/send_transfer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::applications::transfer::context::Ics20Context;
use crate::applications::transfer::context::TokenTransferContext;
use crate::applications::transfer::error::Error;
use crate::applications::transfer::events::TransferEvent;
use crate::applications::transfer::msgs::transfer::MsgTransfer;
Expand All @@ -19,7 +19,7 @@ pub fn send_transfer<Ctx, C>(
msg: MsgTransfer<C>,
) -> Result<(), Error>
where
Ctx: Ics20Context,
Ctx: TokenTransferContext,
C: TryInto<PrefixedCoin>,
{
if !ctx.is_send_enabled() {
Expand Down
22 changes: 11 additions & 11 deletions crates/ibc/src/core/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::ics24_host::path::{
ClientConnectionsPath, ClientConsensusStatePath, ClientStatePath, ClientTypePath,
CommitmentsPath, ConnectionsPath, ReceiptsPath,
};
use super::ics26_routing::msgs::Ics26Envelope;
use super::ics26_routing::msgs::MsgEnvelope;
use super::{
ics02_client::{
client_state::ClientState, consensus_state::ConsensusState, error::Error as ClientError,
Expand Down Expand Up @@ -43,19 +43,19 @@ pub trait ValidationContext {
where
Self: Sized,
{
let envelope: Ics26Envelope = message.try_into()?;
let envelope: MsgEnvelope = message.try_into()?;

match envelope {
Ics26Envelope::Ics2Msg(message) => match message {
MsgEnvelope::ClientMsg(message) => match message {
ClientMsg::CreateClient(message) => create_client::validate(self, message),
ClientMsg::UpdateClient(message) => update_client::validate(self, message),
ClientMsg::Misbehaviour(_message) => unimplemented!(),
ClientMsg::UpgradeClient(message) => upgrade_client::validate(self, message),
}
.map_err(RouterError::ics02_client),
Ics26Envelope::Ics3Msg(_message) => todo!(),
Ics26Envelope::Ics4ChannelMsg(_message) => todo!(),
Ics26Envelope::Ics4PacketMsg(_message) => todo!(),
MsgEnvelope::ConnectionMsg(_message) => todo!(),
MsgEnvelope::ChannelMsg(_message) => todo!(),
MsgEnvelope::PacketMsg(_message) => todo!(),
}
}

Expand Down Expand Up @@ -246,19 +246,19 @@ pub trait ExecutionContext: ValidationContext {
where
Self: Sized,
{
let envelope: Ics26Envelope = message.try_into()?;
let envelope: MsgEnvelope = message.try_into()?;

match envelope {
Ics26Envelope::Ics2Msg(message) => match message {
MsgEnvelope::ClientMsg(message) => match message {
ClientMsg::CreateClient(message) => create_client::execute(self, message),
ClientMsg::UpdateClient(message) => update_client::execute(self, message),
ClientMsg::Misbehaviour(_message) => unimplemented!(),
ClientMsg::UpgradeClient(message) => upgrade_client::execute(self, message),
}
.map_err(RouterError::ics02_client),
Ics26Envelope::Ics3Msg(_message) => todo!(),
Ics26Envelope::Ics4ChannelMsg(_message) => todo!(),
Ics26Envelope::Ics4PacketMsg(_message) => todo!(),
MsgEnvelope::ConnectionMsg(_message) => todo!(),
MsgEnvelope::ChannelMsg(_message) => todo!(),
MsgEnvelope::PacketMsg(_message) => todo!(),
}
}

Expand Down
14 changes: 7 additions & 7 deletions crates/ibc/src/core/ics04_channel/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::core::ics04_channel::packet::Packet;
use crate::core::ics04_channel::{msgs::PacketMsg, packet::PacketResult};
use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId};
use crate::core::ics26_routing::context::{
Acknowledgement, Ics26Context, ModuleId, ModuleOutputBuilder, OnRecvPacketAck, Router,
Acknowledgement, ModuleId, ModuleOutputBuilder, OnRecvPacketAck, Router, RouterContext,
};
use crate::handler::{HandlerOutput, HandlerOutputBuilder};

Expand Down Expand Up @@ -67,7 +67,7 @@ impl ModuleExtras {

pub fn channel_validate<Ctx>(ctx: &Ctx, msg: &ChannelMsg) -> Result<ModuleId, Error>
where
Ctx: Ics26Context,
Ctx: RouterContext,
{
let module_id = msg.lookup_module(ctx)?;
if ctx.router().has_route(&module_id) {
Expand Down Expand Up @@ -106,7 +106,7 @@ pub fn channel_callback<Ctx>(
result: &mut ChannelResult,
) -> Result<ModuleExtras, Error>
where
Ctx: Ics26Context,
Ctx: RouterContext,
{
let cb = ctx
.router_mut()
Expand Down Expand Up @@ -224,7 +224,7 @@ pub fn channel_events(

pub fn get_module_for_packet_msg<Ctx>(ctx: &Ctx, msg: &PacketMsg) -> Result<ModuleId, Error>
where
Ctx: Ics26Context,
Ctx: RouterContext,
{
let module_id = match msg {
PacketMsg::RecvPacket(msg) => ctx
Expand Down Expand Up @@ -278,7 +278,7 @@ pub fn packet_callback<Ctx>(
output: &mut HandlerOutputBuilder<()>,
) -> Result<(), Error>
where
Ctx: Ics26Context,
Ctx: RouterContext,
{
let mut module_output = ModuleOutputBuilder::new();
let mut core_output = HandlerOutputBuilder::new();
Expand All @@ -291,7 +291,7 @@ where
}

fn do_packet_callback(
ctx: &mut impl Ics26Context,
ctx: &mut impl RouterContext,
module_id: &ModuleId,
msg: &PacketMsg,
module_output: &mut ModuleOutputBuilder,
Expand Down Expand Up @@ -335,7 +335,7 @@ fn do_packet_callback(
}

fn process_write_ack(
ctx: &mut impl Ics26Context,
ctx: &mut impl RouterContext,
packet: Packet,
acknowledgement: &dyn Acknowledgement,
core_output: &mut HandlerOutputBuilder<()>,
Expand Down
2 changes: 1 addition & 1 deletion crates/ibc/src/core/ics04_channel/handler/recv_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mod tests {
use crate::core::ics04_channel::Version;
use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId};
use crate::mock::context::MockContext;
use crate::relayer::ics18_relayer::context::Ics18Context;
use crate::relayer::ics18_relayer::context::RelayerContext;
use crate::test_utils::get_dummy_account_id;
use crate::timestamp::Timestamp;
use crate::timestamp::ZERO_DURATION;
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/core/ics04_channel/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::core::ics04_channel::msgs::chan_open_try::MsgChannelOpenTry;
use crate::core::ics04_channel::msgs::recv_packet::MsgRecvPacket;
use crate::core::ics04_channel::msgs::timeout::MsgTimeout;
use crate::core::ics04_channel::msgs::timeout_on_close::MsgTimeoutOnClose;
use crate::core::ics26_routing::context::{Ics26Context, ModuleId};
use crate::core::ics26_routing::context::{ModuleId, RouterContext};

// Opening handshake messages.
pub mod chan_open_ack;
Expand Down Expand Up @@ -42,7 +42,7 @@ pub enum ChannelMsg {
}

impl ChannelMsg {
pub(super) fn lookup_module(&self, ctx: &impl Ics26Context) -> Result<ModuleId, Error> {
pub(super) fn lookup_module(&self, ctx: &impl RouterContext) -> Result<ModuleId, Error> {
let module_id = match self {
ChannelMsg::ChannelOpenInit(msg) => ctx
.lookup_module_by_port(&msg.port_id_on_a)
Expand Down
2 changes: 1 addition & 1 deletion crates/ibc/src/core/ics26_routing/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::signer::Signer;
/// This trait captures all the functional dependencies (i.e., context) which the ICS26 module
/// requires to be able to dispatch and process IBC messages. In other words, this is the
/// representation of a chain from the perspective of the IBC module of that chain.
pub trait Ics26Context:
pub trait RouterContext:
ClientReader
+ ClientKeeper
+ ConnectionReader
Expand Down
Loading