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

ICS20 API improvements #2280

Merged
merged 6 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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