Skip to content

Commit 092382d

Browse files
authored
Rename ics context (#247)
* Rename Ics26Context to RouterContext * Rename Ics20Context to TransferContext * Rename Ics20Keeper to TransferKepper, Ics20Reader to TransferReader * fix test * Create 245-rename-ics-context.md * fmt code * Rename Ics18Context to RelayerContext * Rename Ics25Envelop to MsgEnvelop and Rename it's variants * update .changelog * Rename Ics20Context to TokenTransferContext Signed-off-by: Davirain <[email protected]>
1 parent 145d3f2 commit 092382d

File tree

18 files changed

+142
-153
lines changed

18 files changed

+142
-153
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Rename Ics* names to something more descriptive
2+
([#245](https://github.com/cosmos/ibc-rs/issues/245))

crates/ibc/src/applications/transfer/context.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,16 @@ pub trait BankKeeper {
147147

148148
/// Captures all the dependencies which the ICS20 module requires to be able to dispatch and
149149
/// process IBC messages.
150-
pub trait Ics20Context:
151-
TokenTransferKeeper<AccountId = <Self as Ics20Context>::AccountId>
152-
+ TokenTransferReader<AccountId = <Self as Ics20Context>::AccountId>
150+
pub trait TokenTransferContext:
151+
TokenTransferKeeper<AccountId = <Self as TokenTransferContext>::AccountId>
152+
+ TokenTransferReader<AccountId = <Self as TokenTransferContext>::AccountId>
153153
{
154154
type AccountId: TryFrom<Signer>;
155155
}
156156

157157
#[allow(clippy::too_many_arguments)]
158158
pub fn on_chan_open_init(
159-
ctx: &mut impl Ics20Context,
159+
ctx: &mut impl TokenTransferContext,
160160
order: Order,
161161
_connection_hops: &[ConnectionId],
162162
port_id: &PortId,
@@ -181,7 +181,7 @@ pub fn on_chan_open_init(
181181

182182
#[allow(clippy::too_many_arguments)]
183183
pub fn on_chan_open_try(
184-
_ctx: &mut impl Ics20Context,
184+
_ctx: &mut impl TokenTransferContext,
185185
order: Order,
186186
_connection_hops: &[ConnectionId],
187187
_port_id: &PortId,
@@ -202,7 +202,7 @@ pub fn on_chan_open_try(
202202
}
203203

204204
pub fn on_chan_open_ack(
205-
_ctx: &mut impl Ics20Context,
205+
_ctx: &mut impl TokenTransferContext,
206206
_port_id: &PortId,
207207
_channel_id: &ChannelId,
208208
counterparty_version: &Version,
@@ -217,30 +217,30 @@ pub fn on_chan_open_ack(
217217
}
218218

219219
pub fn on_chan_open_confirm(
220-
_ctx: &mut impl Ics20Context,
220+
_ctx: &mut impl TokenTransferContext,
221221
_port_id: &PortId,
222222
_channel_id: &ChannelId,
223223
) -> Result<ModuleExtras, Ics20Error> {
224224
Ok(ModuleExtras::empty())
225225
}
226226

227227
pub fn on_chan_close_init(
228-
_ctx: &mut impl Ics20Context,
228+
_ctx: &mut impl TokenTransferContext,
229229
_port_id: &PortId,
230230
_channel_id: &ChannelId,
231231
) -> Result<ModuleExtras, Ics20Error> {
232232
Err(Ics20Error::cant_close_channel())
233233
}
234234

235235
pub fn on_chan_close_confirm(
236-
_ctx: &mut impl Ics20Context,
236+
_ctx: &mut impl TokenTransferContext,
237237
_port_id: &PortId,
238238
_channel_id: &ChannelId,
239239
) -> Result<ModuleExtras, Ics20Error> {
240240
Ok(ModuleExtras::empty())
241241
}
242242

243-
pub fn on_recv_packet<Ctx: 'static + Ics20Context>(
243+
pub fn on_recv_packet<Ctx: 'static + TokenTransferContext>(
244244
ctx: &Ctx,
245245
output: &mut ModuleOutputBuilder,
246246
packet: &Packet,
@@ -272,7 +272,7 @@ pub fn on_recv_packet<Ctx: 'static + Ics20Context>(
272272
}
273273

274274
pub fn on_acknowledgement_packet(
275-
ctx: &mut impl Ics20Context,
275+
ctx: &mut impl TokenTransferContext,
276276
output: &mut ModuleOutputBuilder,
277277
packet: &Packet,
278278
acknowledgement: &GenericAcknowledgement,
@@ -299,7 +299,7 @@ pub fn on_acknowledgement_packet(
299299
}
300300

301301
pub fn on_timeout_packet(
302-
ctx: &mut impl Ics20Context,
302+
ctx: &mut impl TokenTransferContext,
303303
output: &mut ModuleOutputBuilder,
304304
packet: &Packet,
305305
_relayer: &Signer,

crates/ibc/src/applications/transfer/relay.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! This module implements the processing logic for ICS20 (token transfer) message.
2-
use crate::applications::transfer::context::Ics20Context;
2+
use crate::applications::transfer::context::TokenTransferContext;
33
use crate::applications::transfer::error::Error as Ics20Error;
44
use crate::applications::transfer::is_sender_chain_source;
55
use crate::applications::transfer::packet::PacketData;
@@ -12,7 +12,7 @@ pub mod on_timeout_packet;
1212
pub mod send_transfer;
1313

1414
fn refund_packet_token(
15-
ctx: &mut impl Ics20Context,
15+
ctx: &mut impl TokenTransferContext,
1616
packet: &Packet,
1717
data: &PacketData,
1818
) -> Result<(), Ics20Error> {

crates/ibc/src/applications/transfer/relay/on_ack_packet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::applications::transfer::acknowledgement::Acknowledgement;
2-
use crate::applications::transfer::context::Ics20Context;
2+
use crate::applications::transfer::context::TokenTransferContext;
33
use crate::applications::transfer::error::Error as Ics20Error;
44
use crate::applications::transfer::packet::PacketData;
55
use crate::applications::transfer::relay::refund_packet_token;
66
use crate::core::ics04_channel::packet::Packet;
77

88
pub fn process_ack_packet(
9-
ctx: &mut impl Ics20Context,
9+
ctx: &mut impl TokenTransferContext,
1010
packet: &Packet,
1111
data: &PacketData,
1212
ack: &Acknowledgement,

crates/ibc/src/applications/transfer/relay/on_recv_packet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::applications::transfer::context::Ics20Context;
1+
use crate::applications::transfer::context::TokenTransferContext;
22
use crate::applications::transfer::error::Error as Ics20Error;
33
use crate::applications::transfer::events::DenomTraceEvent;
44
use crate::applications::transfer::packet::PacketData;
@@ -7,7 +7,7 @@ use crate::core::ics04_channel::packet::Packet;
77
use crate::core::ics26_routing::context::{ModuleOutputBuilder, WriteFn};
88
use crate::prelude::*;
99

10-
pub fn process_recv_packet<Ctx: 'static + Ics20Context>(
10+
pub fn process_recv_packet<Ctx: 'static + TokenTransferContext>(
1111
ctx: &Ctx,
1212
output: &mut ModuleOutputBuilder,
1313
packet: &Packet,

crates/ibc/src/applications/transfer/relay/on_timeout_packet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crate::applications::transfer::context::Ics20Context;
1+
use crate::applications::transfer::context::TokenTransferContext;
22
use crate::applications::transfer::error::Error as Ics20Error;
33
use crate::applications::transfer::packet::PacketData;
44
use crate::applications::transfer::relay::refund_packet_token;
55
use crate::core::ics04_channel::packet::Packet;
66

77
pub fn process_timeout_packet(
8-
ctx: &mut impl Ics20Context,
8+
ctx: &mut impl TokenTransferContext,
99
packet: &Packet,
1010
data: &PacketData,
1111
) -> Result<(), Ics20Error> {

crates/ibc/src/applications/transfer/relay/send_transfer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::applications::transfer::context::Ics20Context;
1+
use crate::applications::transfer::context::TokenTransferContext;
22
use crate::applications::transfer::error::Error;
33
use crate::applications::transfer::events::TransferEvent;
44
use crate::applications::transfer::msgs::transfer::MsgTransfer;
@@ -19,7 +19,7 @@ pub fn send_transfer<Ctx, C>(
1919
msg: MsgTransfer<C>,
2020
) -> Result<(), Error>
2121
where
22-
Ctx: Ics20Context,
22+
Ctx: TokenTransferContext,
2323
C: TryInto<PrefixedCoin>,
2424
{
2525
if !ctx.is_send_enabled() {

crates/ibc/src/core/context.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use super::ics24_host::path::{
1414
ClientConnectionsPath, ClientConsensusStatePath, ClientStatePath, ClientTypePath,
1515
CommitmentsPath, ConnectionsPath, ReceiptsPath,
1616
};
17-
use super::ics26_routing::msgs::Ics26Envelope;
17+
use super::ics26_routing::msgs::MsgEnvelope;
1818
use super::{
1919
ics02_client::{
2020
client_state::ClientState, consensus_state::ConsensusState, error::Error as ClientError,
@@ -43,19 +43,19 @@ pub trait ValidationContext {
4343
where
4444
Self: Sized,
4545
{
46-
let envelope: Ics26Envelope = message.try_into()?;
46+
let envelope: MsgEnvelope = message.try_into()?;
4747

4848
match envelope {
49-
Ics26Envelope::Ics2Msg(message) => match message {
49+
MsgEnvelope::ClientMsg(message) => match message {
5050
ClientMsg::CreateClient(message) => create_client::validate(self, message),
5151
ClientMsg::UpdateClient(message) => update_client::validate(self, message),
5252
ClientMsg::Misbehaviour(_message) => unimplemented!(),
5353
ClientMsg::UpgradeClient(message) => upgrade_client::validate(self, message),
5454
}
5555
.map_err(RouterError::ics02_client),
56-
Ics26Envelope::Ics3Msg(_message) => todo!(),
57-
Ics26Envelope::Ics4ChannelMsg(_message) => todo!(),
58-
Ics26Envelope::Ics4PacketMsg(_message) => todo!(),
56+
MsgEnvelope::ConnectionMsg(_message) => todo!(),
57+
MsgEnvelope::ChannelMsg(_message) => todo!(),
58+
MsgEnvelope::PacketMsg(_message) => todo!(),
5959
}
6060
}
6161

@@ -246,19 +246,19 @@ pub trait ExecutionContext: ValidationContext {
246246
where
247247
Self: Sized,
248248
{
249-
let envelope: Ics26Envelope = message.try_into()?;
249+
let envelope: MsgEnvelope = message.try_into()?;
250250

251251
match envelope {
252-
Ics26Envelope::Ics2Msg(message) => match message {
252+
MsgEnvelope::ClientMsg(message) => match message {
253253
ClientMsg::CreateClient(message) => create_client::execute(self, message),
254254
ClientMsg::UpdateClient(message) => update_client::execute(self, message),
255255
ClientMsg::Misbehaviour(_message) => unimplemented!(),
256256
ClientMsg::UpgradeClient(message) => upgrade_client::execute(self, message),
257257
}
258258
.map_err(RouterError::ics02_client),
259-
Ics26Envelope::Ics3Msg(_message) => todo!(),
260-
Ics26Envelope::Ics4ChannelMsg(_message) => todo!(),
261-
Ics26Envelope::Ics4PacketMsg(_message) => todo!(),
259+
MsgEnvelope::ConnectionMsg(_message) => todo!(),
260+
MsgEnvelope::ChannelMsg(_message) => todo!(),
261+
MsgEnvelope::PacketMsg(_message) => todo!(),
262262
}
263263
}
264264

crates/ibc/src/core/ics04_channel/handler.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::core::ics04_channel::packet::Packet;
1010
use crate::core::ics04_channel::{msgs::PacketMsg, packet::PacketResult};
1111
use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId};
1212
use crate::core::ics26_routing::context::{
13-
Acknowledgement, Ics26Context, ModuleId, ModuleOutputBuilder, OnRecvPacketAck, Router,
13+
Acknowledgement, ModuleId, ModuleOutputBuilder, OnRecvPacketAck, Router, RouterContext,
1414
};
1515
use crate::handler::{HandlerOutput, HandlerOutputBuilder};
1616

@@ -67,7 +67,7 @@ impl ModuleExtras {
6767

6868
pub fn channel_validate<Ctx>(ctx: &Ctx, msg: &ChannelMsg) -> Result<ModuleId, Error>
6969
where
70-
Ctx: Ics26Context,
70+
Ctx: RouterContext,
7171
{
7272
let module_id = msg.lookup_module(ctx)?;
7373
if ctx.router().has_route(&module_id) {
@@ -106,7 +106,7 @@ pub fn channel_callback<Ctx>(
106106
result: &mut ChannelResult,
107107
) -> Result<ModuleExtras, Error>
108108
where
109-
Ctx: Ics26Context,
109+
Ctx: RouterContext,
110110
{
111111
let cb = ctx
112112
.router_mut()
@@ -224,7 +224,7 @@ pub fn channel_events(
224224

225225
pub fn get_module_for_packet_msg<Ctx>(ctx: &Ctx, msg: &PacketMsg) -> Result<ModuleId, Error>
226226
where
227-
Ctx: Ics26Context,
227+
Ctx: RouterContext,
228228
{
229229
let module_id = match msg {
230230
PacketMsg::RecvPacket(msg) => ctx
@@ -278,7 +278,7 @@ pub fn packet_callback<Ctx>(
278278
output: &mut HandlerOutputBuilder<()>,
279279
) -> Result<(), Error>
280280
where
281-
Ctx: Ics26Context,
281+
Ctx: RouterContext,
282282
{
283283
let mut module_output = ModuleOutputBuilder::new();
284284
let mut core_output = HandlerOutputBuilder::new();
@@ -291,7 +291,7 @@ where
291291
}
292292

293293
fn do_packet_callback(
294-
ctx: &mut impl Ics26Context,
294+
ctx: &mut impl RouterContext,
295295
module_id: &ModuleId,
296296
msg: &PacketMsg,
297297
module_output: &mut ModuleOutputBuilder,
@@ -335,7 +335,7 @@ fn do_packet_callback(
335335
}
336336

337337
fn process_write_ack(
338-
ctx: &mut impl Ics26Context,
338+
ctx: &mut impl RouterContext,
339339
packet: Packet,
340340
acknowledgement: &dyn Acknowledgement,
341341
core_output: &mut HandlerOutputBuilder<()>,

crates/ibc/src/core/ics04_channel/handler/recv_packet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ mod tests {
169169
use crate::core::ics04_channel::Version;
170170
use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId};
171171
use crate::mock::context::MockContext;
172-
use crate::relayer::ics18_relayer::context::Ics18Context;
172+
use crate::relayer::ics18_relayer::context::RelayerContext;
173173
use crate::test_utils::get_dummy_account_id;
174174
use crate::timestamp::Timestamp;
175175
use crate::timestamp::ZERO_DURATION;

crates/ibc/src/core/ics04_channel/msgs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::core::ics04_channel::msgs::chan_open_try::MsgChannelOpenTry;
1212
use crate::core::ics04_channel::msgs::recv_packet::MsgRecvPacket;
1313
use crate::core::ics04_channel::msgs::timeout::MsgTimeout;
1414
use crate::core::ics04_channel::msgs::timeout_on_close::MsgTimeoutOnClose;
15-
use crate::core::ics26_routing::context::{Ics26Context, ModuleId};
15+
use crate::core::ics26_routing::context::{ModuleId, RouterContext};
1616

1717
// Opening handshake messages.
1818
pub mod chan_open_ack;
@@ -42,7 +42,7 @@ pub enum ChannelMsg {
4242
}
4343

4444
impl ChannelMsg {
45-
pub(super) fn lookup_module(&self, ctx: &impl Ics26Context) -> Result<ModuleId, Error> {
45+
pub(super) fn lookup_module(&self, ctx: &impl RouterContext) -> Result<ModuleId, Error> {
4646
let module_id = match self {
4747
ChannelMsg::ChannelOpenInit(msg) => ctx
4848
.lookup_module_by_port(&msg.port_id_on_a)

crates/ibc/src/core/ics26_routing/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::signer::Signer;
2727
/// This trait captures all the functional dependencies (i.e., context) which the ICS26 module
2828
/// requires to be able to dispatch and process IBC messages. In other words, this is the
2929
/// representation of a chain from the perspective of the IBC module of that chain.
30-
pub trait Ics26Context:
30+
pub trait RouterContext:
3131
ClientReader
3232
+ ClientKeeper
3333
+ ConnectionReader

0 commit comments

Comments
 (0)