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
2 changes: 2 additions & 0 deletions .changelog/unreleased/enhancement/245-rename-ics-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Rename Ics* names to something more descriptive
plafer marked this conversation as resolved.
Show resolved Hide resolved
([#245](https://github.com/cosmos/ibc-rs/issues/245))
32 changes: 16 additions & 16 deletions crates/ibc/src/applications/transfer/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ use crate::core::ics26_routing::context::{ModuleOutputBuilder, OnRecvPacketAck};
use crate::prelude::*;
use crate::signer::Signer;

pub trait Ics20Keeper:
ChannelKeeper + BankKeeper<AccountId = <Self as Ics20Keeper>::AccountId>
pub trait TransferKeeper:
ChannelKeeper + BankKeeper<AccountId = <Self as TransferKeeper>::AccountId>
{
type AccountId;
}

pub trait Ics20Reader: ChannelReader {
pub trait TransferReader: ChannelReader {
type AccountId: TryFrom<Signer>;

/// get_port returns the portID for the transfer module.
Expand All @@ -36,7 +36,7 @@ pub trait Ics20Reader: ChannelReader {
&self,
port_id: &PortId,
channel_id: &ChannelId,
) -> Result<<Self as Ics20Reader>::AccountId, Ics20Error>;
) -> Result<<Self as TransferReader>::AccountId, Ics20Error>;

/// Returns true iff send is enabled.
fn is_send_enabled(&self) -> bool;
Expand Down Expand Up @@ -93,16 +93,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:
Ics20Keeper<AccountId = <Self as Ics20Context>::AccountId>
+ Ics20Reader<AccountId = <Self as Ics20Context>::AccountId>
pub trait TransferContext:
plafer marked this conversation as resolved.
Show resolved Hide resolved
TransferKeeper<AccountId = <Self as TransferContext>::AccountId>
+ TransferReader<AccountId = <Self as TransferContext>::AccountId>
{
type AccountId: TryFrom<Signer>;
}

#[allow(clippy::too_many_arguments)]
pub fn on_chan_open_init(
ctx: &mut impl Ics20Context,
ctx: &mut impl TransferContext,
order: Order,
_connection_hops: &[ConnectionId],
port_id: &PortId,
Expand All @@ -127,7 +127,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 TransferContext,
order: Order,
_connection_hops: &[ConnectionId],
_port_id: &PortId,
Expand All @@ -148,7 +148,7 @@ pub fn on_chan_open_try(
}

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

pub fn on_chan_open_confirm(
_ctx: &mut impl Ics20Context,
_ctx: &mut impl TransferContext,
_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 TransferContext,
_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 TransferContext,
_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 + TransferContext>(
ctx: &Ctx,
output: &mut ModuleOutputBuilder,
packet: &Packet,
Expand Down Expand Up @@ -218,7 +218,7 @@ pub fn on_recv_packet<Ctx: 'static + Ics20Context>(
}

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

pub fn on_timeout_packet(
ctx: &mut impl Ics20Context,
ctx: &mut impl TransferContext,
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::TransferContext;
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 TransferContext,
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::TransferContext;
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 TransferContext,
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::TransferContext;
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 + TransferContext>(
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::TransferContext;
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 TransferContext,
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::TransferContext;
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: TransferContext,
C: TryInto<PrefixedCoin>,
{
if !ctx.is_send_enabled() {
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
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
8 changes: 4 additions & 4 deletions crates/ibc/src/core/ics26_routing/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::core::ics04_channel::handler::{
packet_dispatch as ics4_packet_msg_dispatcher,
};
use crate::core::ics04_channel::packet::PacketResult;
use crate::core::ics26_routing::context::Ics26Context;
use crate::core::ics26_routing::context::RouterContext;
use crate::core::ics26_routing::error::Error;
use crate::core::ics26_routing::msgs::Ics26Envelope::{
self, Ics2Msg, Ics3Msg, Ics4ChannelMsg, Ics4PacketMsg,
Expand All @@ -32,7 +32,7 @@ pub struct MsgReceipt {
/// Returns a vector of all events that got generated as a byproduct of processing `message`.
pub fn deliver<Ctx>(ctx: &mut Ctx, message: Any) -> Result<MsgReceipt, Error>
where
Ctx: Ics26Context,
Ctx: RouterContext,
{
// Decode the proto message into a domain message, creating an ICS26 envelope.
let envelope = decode(message)?;
Expand All @@ -55,7 +55,7 @@ pub fn decode(message: Any) -> Result<Ics26Envelope, Error> {
/// the `Ctx` caused by all messages from the transaction that this `msg` is a part of.
pub fn dispatch<Ctx>(ctx: &mut Ctx, msg: Ics26Envelope) -> Result<HandlerOutput<()>, Error>
where
Ctx: Ics26Context,
Ctx: RouterContext,
{
let output = match msg {
Ics2Msg(msg) => {
Expand Down Expand Up @@ -202,7 +202,7 @@ mod tests {
use crate::core::ics23_commitment::commitment::test_util::get_dummy_merkle_proof;
use crate::core::ics23_commitment::commitment::CommitmentPrefix;
use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId};
use crate::core::ics26_routing::context::{Ics26Context, ModuleId, Router, RouterBuilder};
use crate::core::ics26_routing::context::{ModuleId, Router, RouterBuilder, RouterContext};
use crate::core::ics26_routing::error::Error;
use crate::core::ics26_routing::handler::dispatch;
use crate::core::ics26_routing::msgs::Ics26Envelope;
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/mock/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::core::ics05_port::error::Error as Ics05Error;
use crate::core::ics05_port::error::Error;
use crate::core::ics23_commitment::commitment::CommitmentPrefix;
use crate::core::ics24_host::identifier::{ChainId, ChannelId, ClientId, ConnectionId, PortId};
use crate::core::ics26_routing::context::{Ics26Context, Module, ModuleId, Router, RouterBuilder};
use crate::core::ics26_routing::context::{Module, ModuleId, Router, RouterBuilder, RouterContext};
use crate::core::ics26_routing::handler::{deliver, dispatch, MsgReceipt};
use crate::core::ics26_routing::msgs::Ics26Envelope;
use crate::events::IbcEvent;
Expand Down Expand Up @@ -647,7 +647,7 @@ impl Router for MockRouter {
}
}

impl Ics26Context for MockContext {
impl RouterContext for MockContext {
type Router = MockRouter;

fn router(&self) -> &Self::Router {
Expand Down
10 changes: 5 additions & 5 deletions crates/ibc/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use subtle_encoding::bech32;
use tendermint::{block, consensus, evidence, public_key::Algorithm};

use crate::applications::transfer::context::{
cosmos_adr028_escrow_address, BankKeeper, Ics20Context, Ics20Keeper, Ics20Reader,
cosmos_adr028_escrow_address, BankKeeper, TransferContext, TransferKeeper, TransferReader,
};
use crate::applications::transfer::{error::Error as Ics20Error, PrefixedCoin};
use crate::core::ics02_client::client_state::ClientState;
Expand Down Expand Up @@ -117,7 +117,7 @@ impl Module for DummyTransferModule {
}
}

impl Ics20Keeper for DummyTransferModule {
impl TransferKeeper for DummyTransferModule {
type AccountId = Signer;
}

Expand Down Expand Up @@ -271,7 +271,7 @@ impl BankKeeper for DummyTransferModule {
}
}

impl Ics20Reader for DummyTransferModule {
impl TransferReader for DummyTransferModule {
type AccountId = Signer;

fn get_port(&self) -> Result<PortId, Ics20Error> {
Expand All @@ -282,7 +282,7 @@ impl Ics20Reader for DummyTransferModule {
&self,
port_id: &PortId,
channel_id: &ChannelId,
) -> Result<<Self as Ics20Reader>::AccountId, Ics20Error> {
) -> Result<<Self as TransferReader>::AccountId, Ics20Error> {
let addr = cosmos_adr028_escrow_address(port_id, channel_id);
Ok(bech32::encode("cosmos", addr).parse().unwrap())
}
Expand Down Expand Up @@ -465,6 +465,6 @@ impl ChannelReader for DummyTransferModule {
}
}

impl Ics20Context for DummyTransferModule {
impl TransferContext for DummyTransferModule {
type AccountId = Signer;
}