Skip to content

Commit

Permalink
ICS20 API improvements (#2280)
Browse files Browse the repository at this point in the history
* Remove `Debug` and `'static` requirements on Module trait

* Manually implement Debug for `MockRouter`

* Remove `Ics20Reader` supertrait `PortReader`

* Use primitive_types::U256 instead of uint::construct_uint!()

* Impl serde for Amount

* Add .changelog entries
  • Loading branch information
hu55a1n1 authored Jun 13, 2022
1 parent 323a56a commit 81053ae
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Derive `serde::{Serialize, Deserialize}` for `U256`. ([#2279](https://github.com/informalsystems/ibc-rs/issues/2279))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Remove unnecessary supertraits requirements from ICS20 traits.
([#2280](https://github.com/informalsystems/ibc-rs/pull/2280))
30 changes: 30 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions modules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ flex-error = { version = "0.4.4", default-features = false }
num-traits = { version = "0.2.15", default-features = false }
derive_more = { version = "0.99.17", default-features = false, features = ["from", "into", "display"] }
uint = { version = "0.9", default-features = false }
primitive-types = { version = "0.11.1", default-features = false, features = ["serde_no_std"] }

[dependencies.tendermint]
version = "=0.23.7"
Expand Down
3 changes: 1 addition & 2 deletions modules/src/applications/transfer/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::core::ics04_channel::context::{ChannelKeeper, ChannelReader};
use crate::core::ics04_channel::msgs::acknowledgement::Acknowledgement as GenericAcknowledgement;
use crate::core::ics04_channel::packet::Packet;
use crate::core::ics04_channel::Version;
use crate::core::ics05_port::context::PortReader;
use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId};
use crate::core::ics26_routing::context::{ModuleOutputBuilder, OnRecvPacketAck};
use crate::prelude::*;
Expand All @@ -26,7 +25,7 @@ pub trait Ics20Keeper:
type AccountId;
}

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

/// get_port returns the portID for the transfer module.
Expand Down
4 changes: 3 additions & 1 deletion modules/src/applications/transfer/denom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ impl fmt::Display for PrefixedDenom {
}

/// A type for representing token transfer amounts.
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Display, From, Into)]
#[derive(
Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize, Display, From, Into,
)]
pub struct Amount(U256);

impl Amount {
Expand Down
9 changes: 1 addition & 8 deletions modules/src/bigint.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
#![allow(clippy::assign_op_pattern)]
#![allow(clippy::ptr_offset_with_cast)]

use uint::construct_uint;

construct_uint! {
pub struct U256(4);
}
pub use primitive_types::U256;
2 changes: 1 addition & 1 deletion modules/src/core/ics26_routing/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl OnRecvPacketAck {

pub type ModuleOutputBuilder = HandlerOutputBuilder<(), ModuleEvent>;

pub trait Module: Debug + Send + Sync + AsAnyMut + 'static {
pub trait Module: Send + Sync + AsAnyMut {
#[allow(clippy::too_many_arguments)]
fn on_chan_open_init(
&mut self,
Expand Down
10 changes: 8 additions & 2 deletions modules/src/mock/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use alloc::collections::btree_map::BTreeMap;
use alloc::sync::Arc;
use core::borrow::Borrow;
use core::cmp::min;
use core::fmt::Debug;
use core::fmt::{Debug, Formatter};
use core::ops::{Add, Sub};
use core::time::Duration;
use std::sync::Mutex;
Expand Down Expand Up @@ -612,9 +612,15 @@ impl RouterBuilder for MockRouterBuilder {
}
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Default)]
pub struct MockRouter(BTreeMap<ModuleId, Arc<dyn Module>>);

impl Debug for MockRouter {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "{:?}", self.0.keys().collect::<Vec<&ModuleId>>())
}
}

impl Router for MockRouter {
fn get_route_mut(&mut self, module_id: &impl Borrow<ModuleId>) -> Option<&mut dyn Module> {
self.0.get_mut(module_id.borrow()).and_then(Arc::get_mut)
Expand Down

0 comments on commit 81053ae

Please sign in to comment.