From e9de73f06d66ae5531164361ab624470230ac00e Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 14 Nov 2023 12:12:29 -0800 Subject: [PATCH 01/16] feat: restructure and split off applications codebase into ibc-apps dir --- Cargo.toml | 2 + crates/ibc-apps/transfer/Cargo.toml | 51 +++++ crates/ibc-apps/transfer/README.md | 1 + crates/ibc-apps/transfer/src/context.rs | 134 ++++++++++++ .../transfer/src/handler/mod.rs} | 16 +- .../transfer/src/handler}/on_recv_packet.rs | 17 +- .../transfer/src/handler}/send_transfer.rs | 27 +-- crates/ibc-apps/transfer/src/lib.rs | 26 +++ .../transfer/src/module.rs} | 207 ++++++------------ crates/ibc-apps/transfer/types/Cargo.toml | 57 +++++ crates/ibc-apps/transfer/types/README.md | 1 + .../transfer/types/src}/amount.rs | 4 +- .../transfer/types/src}/coin.rs | 2 +- .../transfer/types/src}/denom.rs | 8 +- .../transfer/types/src}/error.rs | 11 +- .../transfer/types/src}/events.rs | 11 +- .../transfer/types/src/lib.rs} | 34 ++- .../transfer/types/src}/memo.rs | 2 +- .../transfer/types/src/msgs/mod.rs} | 0 .../transfer/types/src}/msgs/transfer.rs | 16 +- .../transfer/types/src}/packet.rs | 4 +- crates/ibc-testkit/Cargo.toml | 6 +- .../ibc/applications/transfer/context.rs | 10 +- .../src/testapp/ibc/core/router/types.rs | 2 +- .../utils/dummies/applications/transfer.rs | 6 +- .../tests/applications/transfer.rs | 11 +- .../tests/core/ics04_channel/chan_open_ack.rs | 2 +- crates/ibc-testkit/tests/core/router.rs | 7 +- crates/ibc/Cargo.toml | 5 +- crates/ibc/src/applications/mod.rs | 4 - .../src/core/ics04_channel/acknowledgement.rs | 68 ------ crates/ibc/src/core/ics04_channel/handler.rs | 22 +- crates/ibc/src/core/ics04_channel/mod.rs | 2 +- crates/ibc/src/lib.rs | 3 +- 34 files changed, 464 insertions(+), 315 deletions(-) create mode 100644 crates/ibc-apps/transfer/Cargo.toml create mode 100644 crates/ibc-apps/transfer/README.md create mode 100644 crates/ibc-apps/transfer/src/context.rs rename crates/{ibc/src/applications/transfer/relay.rs => ibc-apps/transfer/src/handler/mod.rs} (84%) rename crates/{ibc/src/applications/transfer/relay => ibc-apps/transfer/src/handler}/on_recv_packet.rs (90%) rename crates/{ibc/src/applications/transfer/relay => ibc-apps/transfer/src/handler}/send_transfer.rs (88%) create mode 100644 crates/ibc-apps/transfer/src/lib.rs rename crates/{ibc/src/applications/transfer/context.rs => ibc-apps/transfer/src/module.rs} (62%) create mode 100644 crates/ibc-apps/transfer/types/Cargo.toml create mode 100644 crates/ibc-apps/transfer/types/README.md rename crates/{ibc/src/applications/transfer => ibc-apps/transfer/types/src}/amount.rs (97%) rename crates/{ibc/src/applications/transfer => ibc-apps/transfer/types/src}/coin.rs (99%) rename crates/{ibc/src/applications/transfer => ibc-apps/transfer/types/src}/denom.rs (99%) rename crates/{ibc/src/applications/transfer => ibc-apps/transfer/types/src}/error.rs (93%) rename crates/{ibc/src/applications/transfer => ibc-apps/transfer/types/src}/events.rs (96%) rename crates/{ibc/src/applications/transfer/mod.rs => ibc-apps/transfer/types/src/lib.rs} (66%) rename crates/{ibc/src/applications/transfer => ibc-apps/transfer/types/src}/memo.rs (98%) rename crates/{ibc/src/applications/transfer/msgs.rs => ibc-apps/transfer/types/src/msgs/mod.rs} (100%) rename crates/{ibc/src/applications/transfer => ibc-apps/transfer/types/src}/msgs/transfer.rs (91%) rename crates/{ibc/src/applications/transfer => ibc-apps/transfer/types/src}/packet.rs (98%) delete mode 100644 crates/ibc/src/applications/mod.rs diff --git a/Cargo.toml b/Cargo.toml index 7f65e463b..8ec240696 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,8 @@ resolver = "2" members = [ "crates/ibc", + "crates/ibc-apps/transfer", + "crates/ibc-apps/transfer/types", "crates/ibc-derive", "crates/ibc-testkit", "crates/ibc-query", diff --git a/crates/ibc-apps/transfer/Cargo.toml b/crates/ibc-apps/transfer/Cargo.toml new file mode 100644 index 000000000..79731a20b --- /dev/null +++ b/crates/ibc-apps/transfer/Cargo.toml @@ -0,0 +1,51 @@ +[package] +name = "ibc-app-transfer" +version = { workspace = true } +authors = { workspace = true } +edition = { workspace = true } +rust-version = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +keywords = ["blockchain", "cosmos", "ibc", "transfer", "ics20"] +readme = "README.md" +description = """ + TBD +""" + +[package.metadata.docs.rs] +all-features = true + +[dependencies] +# external dependencies +serde_json = { workspace = true, optional = true } +sha2 = { workspace = true } + +# ibc dependencies +ibc-app-transfer-types = { version = "0.47.0", path = "./types", default-features = false } +ibc = { version = "0.47.0", path = "./../../ibc", default-features = false } +ibc-derive = { version = "0.3.0", path = "./../../ibc-derive" } +ibc-proto = { workspace = true } +ics23 = { workspace = true } + +[dev-dependencies] +subtle-encoding = { workspace = true } + +[features] +default = ["std"] +std = [ + "ibc-app-transfer-types/std", + "ibc/std", + "ibc-proto/std", + "ics23/std", + "subtle-encoding/std", + "serde_json/std", + "sha2/std", +] +serde = [ + "ibc-app-transfer-types/serde", + "ibc/serde", + "ibc-proto/serde", + "ics23/serde", + "serde_json" +] + diff --git a/crates/ibc-apps/transfer/README.md b/crates/ibc-apps/transfer/README.md new file mode 100644 index 000000000..14245ef9a --- /dev/null +++ b/crates/ibc-apps/transfer/README.md @@ -0,0 +1 @@ +# `ibc-app-transfer` diff --git a/crates/ibc-apps/transfer/src/context.rs b/crates/ibc-apps/transfer/src/context.rs new file mode 100644 index 000000000..5d47d4cf0 --- /dev/null +++ b/crates/ibc-apps/transfer/src/context.rs @@ -0,0 +1,134 @@ +//! Defines the main context traits and IBC module callbacks + +use ibc::core::ics24_host::identifier::{ChannelId, PortId}; +use ibc::prelude::*; +use ibc::Signer; +use ibc_app_transfer_types::error::TokenTransferError; +use ibc_app_transfer_types::{PrefixedCoin, PrefixedDenom, VERSION}; +use sha2::{Digest, Sha256}; + +/// Methods required in token transfer validation, to be implemented by the host +pub trait TokenTransferValidationContext { + type AccountId: TryFrom; + + /// get_port returns the portID for the transfer module. + fn get_port(&self) -> Result; + + /// Returns the escrow account id for a port and channel combination + fn get_escrow_account( + &self, + port_id: &PortId, + channel_id: &ChannelId, + ) -> Result; + + /// Returns Ok() if the host chain supports sending coins. + fn can_send_coins(&self) -> Result<(), TokenTransferError>; + + /// Returns Ok() if the host chain supports receiving coins. + fn can_receive_coins(&self) -> Result<(), TokenTransferError>; + + /// Validates the sender and receiver accounts and the coin inputs + fn send_coins_validate( + &self, + from_account: &Self::AccountId, + to_account: &Self::AccountId, + coin: &PrefixedCoin, + ) -> Result<(), TokenTransferError>; + + /// Validates the receiver account and the coin input + fn mint_coins_validate( + &self, + account: &Self::AccountId, + coin: &PrefixedCoin, + ) -> Result<(), TokenTransferError>; + + /// Validates the sender account and the coin input + fn burn_coins_validate( + &self, + account: &Self::AccountId, + coin: &PrefixedCoin, + ) -> Result<(), TokenTransferError>; + + /// Returns a hash of the prefixed denom. + /// Implement only if the host chain supports hashed denominations. + fn denom_hash_string(&self, _denom: &PrefixedDenom) -> Option { + None + } +} + +/// Methods required in token transfer execution, to be implemented by the host +pub trait TokenTransferExecutionContext: TokenTransferValidationContext { + /// This function should enable sending ibc fungible tokens from one account to another + fn send_coins_execute( + &mut self, + from_account: &Self::AccountId, + to_account: &Self::AccountId, + coin: &PrefixedCoin, + ) -> Result<(), TokenTransferError>; + + /// This function to enable minting ibc tokens to a user account + fn mint_coins_execute( + &mut self, + account: &Self::AccountId, + coin: &PrefixedCoin, + ) -> Result<(), TokenTransferError>; + + /// This function should enable burning of minted tokens in a user account + fn burn_coins_execute( + &mut self, + account: &Self::AccountId, + coin: &PrefixedCoin, + ) -> Result<(), TokenTransferError>; +} + +// https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-028-public-key-addresses.md +pub fn cosmos_adr028_escrow_address(port_id: &PortId, channel_id: &ChannelId) -> Vec { + let contents = format!("{port_id}/{channel_id}"); + + let mut hasher = Sha256::new(); + hasher.update(VERSION.as_bytes()); + hasher.update([0]); + hasher.update(contents.as_bytes()); + + let mut hash = hasher.finalize().to_vec(); + hash.truncate(20); + hash +} + +#[cfg(test)] +mod tests { + use subtle_encoding::bech32; + + use super::*; + use crate::context::cosmos_adr028_escrow_address; + + #[test] + fn test_cosmos_escrow_address() { + fn assert_eq_escrow_address(port_id: &str, channel_id: &str, address: &str) { + let port_id = port_id.parse().unwrap(); + let channel_id = channel_id.parse().unwrap(); + let gen_address = { + let addr = cosmos_adr028_escrow_address(&port_id, &channel_id); + bech32::encode("cosmos", addr) + }; + assert_eq!(gen_address, address.to_owned()) + } + + // addresses obtained using `gaiad query ibc-transfer escrow-address [port-id] [channel-id]` + assert_eq_escrow_address( + "transfer", + "channel-141", + "cosmos1x54ltnyg88k0ejmk8ytwrhd3ltm84xehrnlslf", + ); + assert_eq_escrow_address( + "transfer", + "channel-207", + "cosmos1ju6tlfclulxumtt2kglvnxduj5d93a64r5czge", + ); + assert_eq_escrow_address( + "transfer", + "channel-187", + "cosmos177x69sver58mcfs74x6dg0tv6ls4s3xmmcaw53", + ); + } +} diff --git a/crates/ibc/src/applications/transfer/relay.rs b/crates/ibc-apps/transfer/src/handler/mod.rs similarity index 84% rename from crates/ibc/src/applications/transfer/relay.rs rename to crates/ibc-apps/transfer/src/handler/mod.rs index 227ac8243..730017f6d 100644 --- a/crates/ibc/src/applications/transfer/relay.rs +++ b/crates/ibc-apps/transfer/src/handler/mod.rs @@ -1,15 +1,15 @@ //! Implements the processing logic for ICS20 (token transfer) message. - -use super::context::{TokenTransferExecutionContext, TokenTransferValidationContext}; -use crate::applications::transfer::error::TokenTransferError; -use crate::applications::transfer::is_sender_chain_source; -use crate::applications::transfer::packet::PacketData; -use crate::core::ics04_channel::packet::Packet; -use crate::prelude::*; - pub mod on_recv_packet; pub mod send_transfer; +use ibc::core::ics04_channel::packet::Packet; +use ibc::prelude::*; +use ibc_app_transfer_types::error::TokenTransferError; +use ibc_app_transfer_types::is_sender_chain_source; +use ibc_app_transfer_types::packet::PacketData; + +use crate::context::{TokenTransferExecutionContext, TokenTransferValidationContext}; + pub fn refund_packet_token_execute( ctx_a: &mut impl TokenTransferExecutionContext, packet: &Packet, diff --git a/crates/ibc/src/applications/transfer/relay/on_recv_packet.rs b/crates/ibc-apps/transfer/src/handler/on_recv_packet.rs similarity index 90% rename from crates/ibc/src/applications/transfer/relay/on_recv_packet.rs rename to crates/ibc-apps/transfer/src/handler/on_recv_packet.rs index 9e9e70c2d..d150d8399 100644 --- a/crates/ibc/src/applications/transfer/relay/on_recv_packet.rs +++ b/crates/ibc-apps/transfer/src/handler/on_recv_packet.rs @@ -1,11 +1,12 @@ -use crate::applications::transfer::context::TokenTransferExecutionContext; -use crate::applications::transfer::error::TokenTransferError; -use crate::applications::transfer::events::DenomTraceEvent; -use crate::applications::transfer::packet::PacketData; -use crate::applications::transfer::{is_receiver_chain_source, TracePrefix}; -use crate::core::ics04_channel::packet::Packet; -use crate::core::router::ModuleExtras; -use crate::prelude::*; +use ibc::core::ics04_channel::packet::Packet; +use ibc::core::router::ModuleExtras; +use ibc::prelude::*; +use ibc_app_transfer_types::error::TokenTransferError; +use ibc_app_transfer_types::events::DenomTraceEvent; +use ibc_app_transfer_types::packet::PacketData; +use ibc_app_transfer_types::{is_receiver_chain_source, TracePrefix}; + +use crate::context::TokenTransferExecutionContext; /// This function handles the transfer receiving logic. /// diff --git a/crates/ibc/src/applications/transfer/relay/send_transfer.rs b/crates/ibc-apps/transfer/src/handler/send_transfer.rs similarity index 88% rename from crates/ibc/src/applications/transfer/relay/send_transfer.rs rename to crates/ibc-apps/transfer/src/handler/send_transfer.rs index 607457f48..d969bab27 100644 --- a/crates/ibc/src/applications/transfer/relay/send_transfer.rs +++ b/crates/ibc-apps/transfer/src/handler/send_transfer.rs @@ -1,18 +1,15 @@ -use crate::applications::transfer::context::{ - TokenTransferExecutionContext, TokenTransferValidationContext, -}; -use crate::applications::transfer::error::TokenTransferError; -use crate::applications::transfer::events::TransferEvent; -use crate::applications::transfer::msgs::transfer::MsgTransfer; -use crate::applications::transfer::{is_sender_chain_source, MODULE_ID_STR}; -use crate::core::events::{MessageEvent, ModuleEvent}; -use crate::core::ics04_channel::context::{ - SendPacketExecutionContext, SendPacketValidationContext, -}; -use crate::core::ics04_channel::handler::send_packet::{send_packet_execute, send_packet_validate}; -use crate::core::ics04_channel::packet::Packet; -use crate::core::ics24_host::path::{ChannelEndPath, SeqSendPath}; -use crate::prelude::*; +use ibc::core::events::{MessageEvent, ModuleEvent}; +use ibc::core::ics04_channel::context::{SendPacketExecutionContext, SendPacketValidationContext}; +use ibc::core::ics04_channel::handler::send_packet::{send_packet_execute, send_packet_validate}; +use ibc::core::ics04_channel::packet::Packet; +use ibc::core::ics24_host::path::{ChannelEndPath, SeqSendPath}; +use ibc::prelude::*; +use ibc_app_transfer_types::error::TokenTransferError; +use ibc_app_transfer_types::events::TransferEvent; +use ibc_app_transfer_types::msgs::transfer::MsgTransfer; +use ibc_app_transfer_types::{is_sender_chain_source, MODULE_ID_STR}; + +use crate::context::{TokenTransferExecutionContext, TokenTransferValidationContext}; /// Initiate a token transfer. Equivalent to calling [`send_transfer_validate`], followed by [`send_transfer_execute`]. pub fn send_transfer( diff --git a/crates/ibc-apps/transfer/src/lib.rs b/crates/ibc-apps/transfer/src/lib.rs new file mode 100644 index 000000000..995d649b5 --- /dev/null +++ b/crates/ibc-apps/transfer/src/lib.rs @@ -0,0 +1,26 @@ +//! Implementation of the [fungible token transfer module](https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md) (ICS-20) +#![cfg_attr(not(test), deny(clippy::unwrap_used))] +#![no_std] +#![deny( + warnings, + trivial_casts, + trivial_numeric_casts, + unused_import_braces, + unused_qualifications, + rust_2018_idioms +)] +#![allow(clippy::result_large_err)] +#![cfg_attr(not(test), deny(clippy::disallowed_methods, clippy::disallowed_types,))] +#![forbid(unsafe_code)] + +#[cfg(any(test, feature = "std"))] +extern crate std; + +#[doc(inline)] +pub use ibc_app_transfer_types as types; + +pub mod context; +#[cfg(feature = "serde")] +pub mod handler; +#[cfg(feature = "serde")] +pub mod module; diff --git a/crates/ibc/src/applications/transfer/context.rs b/crates/ibc-apps/transfer/src/module.rs similarity index 62% rename from crates/ibc/src/applications/transfer/context.rs rename to crates/ibc-apps/transfer/src/module.rs index 33d080f30..1c86d139e 100644 --- a/crates/ibc/src/applications/transfer/context.rs +++ b/crates/ibc-apps/transfer/src/module.rs @@ -1,112 +1,20 @@ -//! Defines the main context traits and IBC module callbacks -use sha2::{Digest, Sha256}; - -use super::ack_success_b64; -use super::error::TokenTransferError; -use crate::applications::transfer::events::{AckEvent, AckStatusEvent, RecvEvent, TimeoutEvent}; -use crate::applications::transfer::packet::PacketData; -use crate::applications::transfer::relay::on_recv_packet::process_recv_packet_execute; -use crate::applications::transfer::relay::{ - refund_packet_token_execute, refund_packet_token_validate, -}; -use crate::applications::transfer::{PrefixedCoin, PrefixedDenom, VERSION}; -use crate::core::ics04_channel::acknowledgement::{Acknowledgement, AcknowledgementStatus}; -use crate::core::ics04_channel::channel::{Counterparty, Order}; -use crate::core::ics04_channel::packet::Packet; -use crate::core::ics04_channel::Version; -use crate::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; -use crate::core::router::ModuleExtras; -use crate::core::ContextError; -use crate::prelude::*; -use crate::signer::Signer; - -/// Methods required in token transfer validation, to be implemented by the host -pub trait TokenTransferValidationContext { - type AccountId: TryFrom; - - /// get_port returns the portID for the transfer module. - fn get_port(&self) -> Result; - - /// Returns the escrow account id for a port and channel combination - fn get_escrow_account( - &self, - port_id: &PortId, - channel_id: &ChannelId, - ) -> Result; - - /// Returns Ok() if the host chain supports sending coins. - fn can_send_coins(&self) -> Result<(), TokenTransferError>; - - /// Returns Ok() if the host chain supports receiving coins. - fn can_receive_coins(&self) -> Result<(), TokenTransferError>; - - /// Validates the sender and receiver accounts and the coin inputs - fn send_coins_validate( - &self, - from_account: &Self::AccountId, - to_account: &Self::AccountId, - coin: &PrefixedCoin, - ) -> Result<(), TokenTransferError>; - - /// Validates the receiver account and the coin input - fn mint_coins_validate( - &self, - account: &Self::AccountId, - coin: &PrefixedCoin, - ) -> Result<(), TokenTransferError>; - - /// Validates the sender account and the coin input - fn burn_coins_validate( - &self, - account: &Self::AccountId, - coin: &PrefixedCoin, - ) -> Result<(), TokenTransferError>; - - /// Returns a hash of the prefixed denom. - /// Implement only if the host chain supports hashed denominations. - fn denom_hash_string(&self, _denom: &PrefixedDenom) -> Option { - None - } -} - -/// Methods required in token transfer execution, to be implemented by the host -pub trait TokenTransferExecutionContext: TokenTransferValidationContext { - /// This function should enable sending ibc fungible tokens from one account to another - fn send_coins_execute( - &mut self, - from_account: &Self::AccountId, - to_account: &Self::AccountId, - coin: &PrefixedCoin, - ) -> Result<(), TokenTransferError>; - - /// This function to enable minting ibc tokens to a user account - fn mint_coins_execute( - &mut self, - account: &Self::AccountId, - coin: &PrefixedCoin, - ) -> Result<(), TokenTransferError>; - - /// This function should enable burning of minted tokens in a user account - fn burn_coins_execute( - &mut self, - account: &Self::AccountId, - coin: &PrefixedCoin, - ) -> Result<(), TokenTransferError>; -} - -// https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-028-public-key-addresses.md -pub fn cosmos_adr028_escrow_address(port_id: &PortId, channel_id: &ChannelId) -> Vec { - let contents = format!("{port_id}/{channel_id}"); - - let mut hasher = Sha256::new(); - hasher.update(VERSION.as_bytes()); - hasher.update([0]); - hasher.update(contents.as_bytes()); - - let mut hash = hasher.finalize().to_vec(); - hash.truncate(20); - hash -} +use ibc::core::ics04_channel::acknowledgement::{Acknowledgement, AcknowledgementStatus}; +use ibc::core::ics04_channel::channel::{Counterparty, Order}; +use ibc::core::ics04_channel::packet::Packet; +use ibc::core::ics04_channel::Version; +use ibc::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; +use ibc::core::router::ModuleExtras; +use ibc::core::ContextError; +use ibc::prelude::*; +use ibc::Signer; +use ibc_app_transfer_types::error::TokenTransferError; +use ibc_app_transfer_types::events::{AckEvent, AckStatusEvent, RecvEvent, TimeoutEvent}; +use ibc_app_transfer_types::packet::PacketData; +use ibc_app_transfer_types::{ack_success_b64, VERSION}; + +use crate::context::{TokenTransferExecutionContext, TokenTransferValidationContext}; +use crate::handler::on_recv_packet::process_recv_packet_execute; +use crate::handler::{refund_packet_token_execute, refund_packet_token_validate}; pub fn on_chan_open_init_validate( ctx: &impl TokenTransferValidationContext, @@ -411,39 +319,70 @@ pub fn on_timeout_packet_execute( } #[cfg(test)] -mod tests { - use subtle_encoding::bech32; +mod test { + use ibc_app_transfer_types::ack_success_b64; + use ibc_app_transfer_types::error::TokenTransferError; use super::*; - use crate::applications::transfer::context::cosmos_adr028_escrow_address; #[test] - fn test_cosmos_escrow_address() { - fn assert_eq_escrow_address(port_id: &str, channel_id: &str, address: &str) { - let port_id = port_id.parse().unwrap(); - let channel_id = channel_id.parse().unwrap(); - let gen_address = { - let addr = cosmos_adr028_escrow_address(&port_id, &channel_id); - bech32::encode("cosmos", addr) - }; - assert_eq!(gen_address, address.to_owned()) + fn test_ack_ser() { + fn ser_json_assert_eq(ack: AcknowledgementStatus, json_str: &str) { + let ser = serde_json::to_string(&ack).unwrap(); + assert_eq!(ser, json_str) } - // addresses obtained using `gaiad query ibc-transfer escrow-address [port-id] [channel-id]` - assert_eq_escrow_address( - "transfer", - "channel-141", - "cosmos1x54ltnyg88k0ejmk8ytwrhd3ltm84xehrnlslf", + ser_json_assert_eq( + AcknowledgementStatus::success(ack_success_b64()), + r#"{"result":"AQ=="}"#, ); - assert_eq_escrow_address( - "transfer", - "channel-207", - "cosmos1ju6tlfclulxumtt2kglvnxduj5d93a64r5czge", + ser_json_assert_eq( + AcknowledgementStatus::error(TokenTransferError::PacketDataDeserialization.into()), + r#"{"error":"failed to deserialize packet data"}"#, ); - assert_eq_escrow_address( - "transfer", - "channel-187", - "cosmos177x69sver58mcfs74x6dg0tv6ls4s3xmmcaw53", + } + + #[test] + fn test_ack_success_to_vec() { + let ack_success: Vec = AcknowledgementStatus::success(ack_success_b64()).into(); + + // Check that it's the same output as ibc-go + // Note: this also implicitly checks that the ack bytes are non-empty, + // which would make the conversion to `Acknowledgement` panic + assert_eq!(ack_success, r#"{"result":"AQ=="}"#.as_bytes()); + } + + #[test] + fn test_ack_error_to_vec() { + let ack_error: Vec = + AcknowledgementStatus::error(TokenTransferError::PacketDataDeserialization.into()) + .into(); + + // Check that it's the same output as ibc-go + // Note: this also implicitly checks that the ack bytes are non-empty, + // which would make the conversion to `Acknowledgement` panic + assert_eq!( + ack_error, + r#"{"error":"failed to deserialize packet data"}"#.as_bytes() ); } + + #[test] + fn test_ack_de() { + fn de_json_assert_eq(json_str: &str, ack: AcknowledgementStatus) { + let de = serde_json::from_str::(json_str).unwrap(); + assert_eq!(de, ack) + } + + de_json_assert_eq( + r#"{"result":"AQ=="}"#, + AcknowledgementStatus::success(ack_success_b64()), + ); + de_json_assert_eq( + r#"{"error":"failed to deserialize packet data"}"#, + AcknowledgementStatus::error(TokenTransferError::PacketDataDeserialization.into()), + ); + + assert!(serde_json::from_str::(r#"{"success":"AQ=="}"#).is_err()); + } } diff --git a/crates/ibc-apps/transfer/types/Cargo.toml b/crates/ibc-apps/transfer/types/Cargo.toml new file mode 100644 index 000000000..861f55501 --- /dev/null +++ b/crates/ibc-apps/transfer/types/Cargo.toml @@ -0,0 +1,57 @@ +[package] +name = "ibc-app-transfer-types" +version = { workspace = true } +authors = { workspace = true } +edition = { workspace = true } +rust-version = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +keywords = ["blockchain", "cosmos", "ibc", "transfer", "ics20", "types"] +readme = "README.md" +description = """ + TBD +""" + +[package.metadata.docs.rs] +all-features = true + +[dependencies] +# external dependencies +borsh = { workspace = true, optional = true } +derive_more = { workspace = true } +displaydoc = { workspace = true } +primitive-types = { workspace = true } +schemars = { workspace = true, optional = true } +serde = { workspace = true, optional = true } +serde_json = { workspace = true, optional = true} +uint = { version = "0.9", default-features = false } + +# ibc dependencies +ibc = { version = "0.47.0", path = "./../../../ibc" } +ibc-derive = { version = "0.3.0", path = "./../../../ibc-derive" } +ibc-proto = { workspace = true } +ics23 = { workspace = true } + +## parity dependencies +parity-scale-codec = { workspace = true , optional = true } +scale-info = { workspace = true , optional = true } + +[dev-dependencies] +ibc-testkit = { version = "0.47.0", path = "./../../../ibc-testkit", default-features = false} +rstest = { workspace = true } + +[features] +default = ["std"] +std = [ + "ibc-proto/std", + "ics23/std", + "serde/std", + "serde_json/std", + "displaydoc/std", + "uint/std", + "primitive-types/std", +] +borsh = ["dep:borsh", "ibc-proto/borsh"] +serde = ["dep:serde", "serde_json", "ibc-proto/serde", "ics23/serde"] +schema = ["dep:schemars", "ibc-proto/json-schema", "serde", "std"] +parity-scale-codec = ["dep:parity-scale-codec", "dep:scale-info", "ibc-proto/parity-scale-codec"] \ No newline at end of file diff --git a/crates/ibc-apps/transfer/types/README.md b/crates/ibc-apps/transfer/types/README.md new file mode 100644 index 000000000..af4500a90 --- /dev/null +++ b/crates/ibc-apps/transfer/types/README.md @@ -0,0 +1 @@ +# `ibc-app-transfer-types` diff --git a/crates/ibc/src/applications/transfer/amount.rs b/crates/ibc-apps/transfer/types/src/amount.rs similarity index 97% rename from crates/ibc/src/applications/transfer/amount.rs rename to crates/ibc-apps/transfer/types/src/amount.rs index b14a1797a..9b3054952 100644 --- a/crates/ibc/src/applications/transfer/amount.rs +++ b/crates/ibc-apps/transfer/types/src/amount.rs @@ -4,6 +4,7 @@ use core::ops::Deref; use core::str::FromStr; use derive_more::{Display, From, Into}; +use ibc::prelude::*; use primitive_types::U256; use super::error::TokenTransferError; @@ -11,7 +12,6 @@ use super::error::TokenTransferError; use crate::alloc::borrow::ToOwned; #[cfg(feature = "schema")] use crate::alloc::string::String; -use crate::prelude::*; /// A type for representing token transfer amounts. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -19,7 +19,7 @@ use crate::prelude::*; #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Display, From, Into)] pub struct Amount( #[cfg_attr(feature = "schema", schemars(with = "String"))] - #[serde(serialize_with = "crate::serializers::serde_string::serialize")] + #[serde(serialize_with = "ibc::serializers::serde_string::serialize")] #[serde(deserialize_with = "deserialize")] U256, ); diff --git a/crates/ibc/src/applications/transfer/coin.rs b/crates/ibc-apps/transfer/types/src/coin.rs similarity index 99% rename from crates/ibc/src/applications/transfer/coin.rs rename to crates/ibc-apps/transfer/types/src/coin.rs index be7a41172..ed6308492 100644 --- a/crates/ibc/src/applications/transfer/coin.rs +++ b/crates/ibc-apps/transfer/types/src/coin.rs @@ -3,12 +3,12 @@ use core::fmt::{Display, Error as FmtError, Formatter}; use core::str::FromStr; +use ibc::prelude::*; use ibc_proto::cosmos::base::v1beta1::Coin as ProtoCoin; use super::amount::Amount; use super::denom::{BaseDenom, PrefixedDenom}; use super::error::TokenTransferError; -use crate::prelude::*; /// A `Coin` type with fully qualified `PrefixedDenom`. pub type PrefixedCoin = Coin; diff --git a/crates/ibc/src/applications/transfer/denom.rs b/crates/ibc-apps/transfer/types/src/denom.rs similarity index 99% rename from crates/ibc/src/applications/transfer/denom.rs rename to crates/ibc-apps/transfer/types/src/denom.rs index 855b542ae..f9a10b6c2 100644 --- a/crates/ibc/src/applications/transfer/denom.rs +++ b/crates/ibc-apps/transfer/types/src/denom.rs @@ -4,13 +4,13 @@ use core::fmt::{Display, Error as FmtError, Formatter}; use core::str::FromStr; use derive_more::{Display, From}; +use ibc::core::ics24_host::identifier::{ChannelId, PortId}; +use ibc::prelude::*; +#[cfg(feature = "serde")] +use ibc::serializers::serde_string; use ibc_proto::ibc::applications::transfer::v1::DenomTrace as RawDenomTrace; use super::error::TokenTransferError; -use crate::core::ics24_host::identifier::{ChannelId, PortId}; -use crate::prelude::*; -#[cfg(feature = "serde")] -use crate::serializers::serde_string; /// The "base" of a denomination. /// diff --git a/crates/ibc/src/applications/transfer/error.rs b/crates/ibc-apps/transfer/types/src/error.rs similarity index 93% rename from crates/ibc/src/applications/transfer/error.rs rename to crates/ibc-apps/transfer/types/src/error.rs index d47decc33..df8eee9f0 100644 --- a/crates/ibc/src/applications/transfer/error.rs +++ b/crates/ibc-apps/transfer/types/src/error.rs @@ -4,14 +4,13 @@ use core::convert::Infallible; use core::str::Utf8Error; use displaydoc::Display; +use ibc::core::ics04_channel::acknowledgement::StatusValue; +use ibc::core::ics04_channel::channel::Order; +use ibc::core::ics24_host::identifier::{ChannelId, IdentifierError, PortId}; +use ibc::core::ContextError; +use ibc::prelude::*; use uint::FromDecStrErr; -use crate::core::ics04_channel::acknowledgement::StatusValue; -use crate::core::ics04_channel::channel::Order; -use crate::core::ics24_host::identifier::{ChannelId, IdentifierError, PortId}; -use crate::core::ContextError; -use crate::prelude::*; - #[derive(Display, Debug)] pub enum TokenTransferError { /// context error: `{0}` diff --git a/crates/ibc/src/applications/transfer/events.rs b/crates/ibc-apps/transfer/types/src/events.rs similarity index 96% rename from crates/ibc/src/applications/transfer/events.rs rename to crates/ibc-apps/transfer/types/src/events.rs index 45eff108a..03a63b807 100644 --- a/crates/ibc/src/applications/transfer/events.rs +++ b/crates/ibc-apps/transfer/types/src/events.rs @@ -1,11 +1,12 @@ //! Defines all token transfer event types +use ibc::core::events::ModuleEvent; +use ibc::core::ics04_channel::acknowledgement::AcknowledgementStatus; +use ibc::prelude::*; +use ibc::Signer; + use super::Memo; -use crate::applications::transfer::{Amount, PrefixedDenom, MODULE_ID_STR}; -use crate::core::events::ModuleEvent; -use crate::core::ics04_channel::acknowledgement::AcknowledgementStatus; -use crate::prelude::*; -use crate::signer::Signer; +use crate::{Amount, PrefixedDenom, MODULE_ID_STR}; const EVENT_TYPE_PACKET: &str = "fungible_token_packet"; const EVENT_TYPE_TIMEOUT: &str = "timeout"; diff --git a/crates/ibc/src/applications/transfer/mod.rs b/crates/ibc-apps/transfer/types/src/lib.rs similarity index 66% rename from crates/ibc/src/applications/transfer/mod.rs rename to crates/ibc-apps/transfer/types/src/lib.rs index 198a9f82e..ebe153872 100644 --- a/crates/ibc/src/applications/transfer/mod.rs +++ b/crates/ibc-apps/transfer/types/src/lib.rs @@ -1,12 +1,28 @@ //! Implementation of the [fungible token transfer module](https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md) (ICS-20) - -pub mod amount; -pub mod coin; -pub mod context; -pub mod denom; +#![cfg_attr(not(test), deny(clippy::unwrap_used))] +#![no_std] +#![deny( + warnings, + trivial_casts, + trivial_numeric_casts, + unused_import_braces, + unused_qualifications, + rust_2018_idioms +)] +#![cfg_attr(not(test), deny(clippy::disallowed_methods, clippy::disallowed_types,))] +#![forbid(unsafe_code)] + +extern crate alloc; + +#[cfg(any(test, feature = "std"))] +extern crate std; + +mod amount; +mod coin; +mod denom; pub mod error; pub mod events; -pub mod memo; +mod memo; pub mod msgs; pub mod packet; @@ -15,10 +31,6 @@ pub use coin::*; pub use denom::*; pub use memo::*; -mod relay; - -pub use relay::send_transfer::{send_transfer, send_transfer_execute, send_transfer_validate}; - /// Module identifier for the ICS20 application. pub const MODULE_ID_STR: &str = "transfer"; @@ -33,7 +45,7 @@ pub const VERSION: &str = "ics20-1"; /// equivalent to `base64::encode(0x01)`. pub const ACK_SUCCESS_B64: &str = "AQ=="; -use crate::core::ics04_channel::acknowledgement::StatusValue; +use ibc::core::ics04_channel::acknowledgement::StatusValue; /// Returns a successful acknowledgement status for the token transfer application. pub fn ack_success_b64() -> StatusValue { diff --git a/crates/ibc/src/applications/transfer/memo.rs b/crates/ibc-apps/transfer/types/src/memo.rs similarity index 98% rename from crates/ibc/src/applications/transfer/memo.rs rename to crates/ibc-apps/transfer/types/src/memo.rs index 3d31f206e..de7368fa6 100644 --- a/crates/ibc/src/applications/transfer/memo.rs +++ b/crates/ibc-apps/transfer/types/src/memo.rs @@ -7,7 +7,7 @@ use core::fmt::{ }; use core::str::FromStr; -use crate::prelude::*; +use ibc::prelude::*; /// Represents the token transfer memo #[cfg_attr( diff --git a/crates/ibc/src/applications/transfer/msgs.rs b/crates/ibc-apps/transfer/types/src/msgs/mod.rs similarity index 100% rename from crates/ibc/src/applications/transfer/msgs.rs rename to crates/ibc-apps/transfer/types/src/msgs/mod.rs diff --git a/crates/ibc/src/applications/transfer/msgs/transfer.rs b/crates/ibc-apps/transfer/types/src/msgs/transfer.rs similarity index 91% rename from crates/ibc/src/applications/transfer/msgs/transfer.rs rename to crates/ibc-apps/transfer/types/src/msgs/transfer.rs index 44a8406a6..6a2797c6d 100644 --- a/crates/ibc/src/applications/transfer/msgs/transfer.rs +++ b/crates/ibc-apps/transfer/types/src/msgs/transfer.rs @@ -1,17 +1,17 @@ //! Defines the token transfer message type +use ibc::core::ics04_channel::error::PacketError; +use ibc::core::ics04_channel::timeout::TimeoutHeight; +use ibc::core::ics24_host::identifier::{ChannelId, PortId}; +use ibc::core::timestamp::Timestamp; +use ibc::core::{ContextError, Msg}; +use ibc::prelude::*; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::applications::transfer::v1::MsgTransfer as RawMsgTransfer; use ibc_proto::Protobuf; -use crate::applications::transfer::error::TokenTransferError; -use crate::applications::transfer::packet::PacketData; -use crate::core::ics04_channel::error::PacketError; -use crate::core::ics04_channel::timeout::TimeoutHeight; -use crate::core::ics24_host::identifier::{ChannelId, PortId}; -use crate::core::timestamp::Timestamp; -use crate::core::{ContextError, Msg}; -use crate::prelude::*; +use crate::error::TokenTransferError; +use crate::packet::PacketData; pub(crate) const TYPE_URL: &str = "/ibc.applications.transfer.v1.MsgTransfer"; diff --git a/crates/ibc/src/applications/transfer/packet.rs b/crates/ibc-apps/transfer/types/src/packet.rs similarity index 98% rename from crates/ibc/src/applications/transfer/packet.rs rename to crates/ibc-apps/transfer/types/src/packet.rs index 63058b2ed..343874727 100644 --- a/crates/ibc/src/applications/transfer/packet.rs +++ b/crates/ibc-apps/transfer/types/src/packet.rs @@ -4,13 +4,13 @@ use alloc::string::ToString; use core::convert::TryFrom; use core::str::FromStr; +use ibc::Signer; use ibc_proto::ibc::applications::transfer::v2::FungibleTokenPacketData as RawPacketData; use super::error::TokenTransferError; use super::{Amount, Memo, PrefixedCoin, PrefixedDenom}; #[cfg(feature = "schema")] use crate::alloc::borrow::ToOwned; -use crate::signer::Signer; /// Defines the structure of token transfers' packet bytes #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -69,7 +69,7 @@ mod tests { use primitive_types::U256; use super::*; - use crate::applications::transfer::BaseCoin; + use crate::BaseCoin; impl PacketData { pub fn new_dummy() -> Self { diff --git a/crates/ibc-testkit/Cargo.toml b/crates/ibc-testkit/Cargo.toml index 8a8c9137d..253e081f3 100644 --- a/crates/ibc-testkit/Cargo.toml +++ b/crates/ibc-testkit/Cargo.toml @@ -30,7 +30,8 @@ tracing = { workspace = true } typed-builder = { workspace = true } # ibc dependencies -ibc = { version = "0.47.0" , path = "../ibc" } # NOTE: since `ibc-testkit` does not well support `no_std` yet, we keep `ibc` default features enabled +ibc = { version = "0.47.0", path = "../ibc" } # NOTE: since `ibc-testkit` does not well support `no_std` yet, we keep `ibc` default features enabled +ibc-app-transfer = { version = "0.47.0", path = "../ibc-apps/transfer", default-features = false} # cosmos dependencies tendermint = { workspace = true } @@ -46,6 +47,7 @@ test-log = { workspace = true } default = ["std"] std = [ "ibc/std", + "ibc-app-transfer/std", "tracing/std", "prost/std", "serde/std", @@ -53,4 +55,4 @@ std = [ ] # This feature is required for token transfer (ICS-20) -serde = ["dep:serde", "ibc/serde", "serde_json"] +serde = ["dep:serde", "ibc/serde", "serde_json", "ibc-app-transfer/serde"] diff --git a/crates/ibc-testkit/src/testapp/ibc/applications/transfer/context.rs b/crates/ibc-testkit/src/testapp/ibc/applications/transfer/context.rs index f8ec4ae88..1e31a3254 100644 --- a/crates/ibc-testkit/src/testapp/ibc/applications/transfer/context.rs +++ b/crates/ibc-testkit/src/testapp/ibc/applications/transfer/context.rs @@ -1,11 +1,11 @@ -use ibc::applications::transfer::context::{ - cosmos_adr028_escrow_address, TokenTransferExecutionContext, TokenTransferValidationContext, -}; -use ibc::applications::transfer::error::TokenTransferError; -use ibc::applications::transfer::PrefixedCoin; use ibc::core::ics24_host::identifier::{ChannelId, PortId}; use ibc::prelude::*; use ibc::Signer; +use ibc_app_transfer::context::{ + cosmos_adr028_escrow_address, TokenTransferExecutionContext, TokenTransferValidationContext, +}; +use ibc_app_transfer::types::error::TokenTransferError; +use ibc_app_transfer::types::PrefixedCoin; use subtle_encoding::bech32; use super::types::DummyTransferModule; diff --git a/crates/ibc-testkit/src/testapp/ibc/core/router/types.rs b/crates/ibc-testkit/src/testapp/ibc/core/router/types.rs index b0aaaae1b..2874f43cd 100644 --- a/crates/ibc-testkit/src/testapp/ibc/core/router/types.rs +++ b/crates/ibc-testkit/src/testapp/ibc/core/router/types.rs @@ -1,10 +1,10 @@ use alloc::collections::BTreeMap; use alloc::sync::Arc; -use ibc::applications::transfer::MODULE_ID_STR; use ibc::core::ics24_host::identifier::PortId; use ibc::core::router::{Module, ModuleId}; use ibc::prelude::*; +use ibc_app_transfer::types::MODULE_ID_STR; use crate::testapp::ibc::applications::transfer::types::DummyTransferModule; diff --git a/crates/ibc-testkit/src/utils/dummies/applications/transfer.rs b/crates/ibc-testkit/src/utils/dummies/applications/transfer.rs index 0bf50c99b..49581488a 100644 --- a/crates/ibc-testkit/src/utils/dummies/applications/transfer.rs +++ b/crates/ibc-testkit/src/utils/dummies/applications/transfer.rs @@ -1,13 +1,13 @@ use alloc::string::ToString; -use ibc::applications::transfer::msgs::transfer::MsgTransfer; -use ibc::applications::transfer::packet::PacketData; -use ibc::applications::transfer::{Memo, PrefixedCoin}; use ibc::core::ics04_channel::packet::{Packet, Sequence}; use ibc::core::ics04_channel::timeout::TimeoutHeight; use ibc::core::ics24_host::identifier::{ChannelId, PortId}; use ibc::core::timestamp::Timestamp; use ibc::Signer; +use ibc_app_transfer::types::msgs::transfer::MsgTransfer; +use ibc_app_transfer::types::packet::PacketData; +use ibc_app_transfer::types::{Memo, PrefixedCoin}; use typed_builder::TypedBuilder; use crate::utils::dummies::core::signer::dummy_account_id; diff --git a/crates/ibc-testkit/tests/applications/transfer.rs b/crates/ibc-testkit/tests/applications/transfer.rs index 64d56b8c2..9ae6f664f 100644 --- a/crates/ibc-testkit/tests/applications/transfer.rs +++ b/crates/ibc-testkit/tests/applications/transfer.rs @@ -1,12 +1,13 @@ -use ibc::applications::transfer::context::{ - cosmos_adr028_escrow_address, on_chan_open_init_execute, on_chan_open_init_validate, - on_chan_open_try_execute, on_chan_open_try_validate, -}; -use ibc::applications::transfer::VERSION; use ibc::core::ics04_channel::channel::{Counterparty, Order}; use ibc::core::ics04_channel::Version; use ibc::core::ics24_host::identifier::{ChannelId, ConnectionId, PortId}; use ibc::prelude::*; +use ibc_app_transfer::context::cosmos_adr028_escrow_address; +use ibc_app_transfer::module::{ + on_chan_open_init_execute, on_chan_open_init_validate, on_chan_open_try_execute, + on_chan_open_try_validate, +}; +use ibc_app_transfer::types::VERSION; use ibc_testkit::testapp::ibc::applications::transfer::types::DummyTransferModule; use subtle_encoding::bech32; diff --git a/crates/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs b/crates/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs index 25a7d36c5..14778bc25 100644 --- a/crates/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs +++ b/crates/ibc-testkit/tests/core/ics04_channel/chan_open_ack.rs @@ -1,4 +1,3 @@ -use ibc::applications::transfer::MODULE_ID_STR; use ibc::core::events::{IbcEvent, MessageEvent}; use ibc::core::ics03_connection::connection::{ ConnectionEnd, Counterparty as ConnectionCounterparty, State as ConnectionState, @@ -13,6 +12,7 @@ use ibc::core::timestamp::ZERO_DURATION; use ibc::core::{execute, validate, MsgEnvelope}; use ibc::prelude::*; use ibc::Height; +use ibc_app_transfer::types::MODULE_ID_STR; use ibc_testkit::testapp::ibc::clients::mock::client_state::client_type as mock_client_type; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; diff --git a/crates/ibc-testkit/tests/core/router.rs b/crates/ibc-testkit/tests/core/router.rs index 94a5a0c2a..e27739858 100644 --- a/crates/ibc-testkit/tests/core/router.rs +++ b/crates/ibc-testkit/tests/core/router.rs @@ -1,6 +1,3 @@ -use ibc::applications::transfer::error::TokenTransferError; -use ibc::applications::transfer::msgs::transfer::MsgTransfer; -use ibc::applications::transfer::{send_transfer, BaseCoin}; use ibc::core::events::{IbcEvent, MessageEvent}; use ibc::core::ics02_client::msgs::create_client::MsgCreateClient; use ibc::core::ics02_client::msgs::update_client::MsgUpdateClient; @@ -23,6 +20,10 @@ use ibc::core::timestamp::Timestamp; use ibc::core::{dispatch, MsgEnvelope, RouterError, ValidationContext}; use ibc::prelude::*; use ibc::Height; +use ibc_app_transfer::handler::send_transfer::send_transfer; +use ibc_app_transfer::types::error::TokenTransferError; +use ibc_app_transfer::types::msgs::transfer::MsgTransfer; +use ibc_app_transfer::types::BaseCoin; use ibc_testkit::testapp::ibc::applications::transfer::types::DummyTransferModule; use ibc_testkit::testapp::ibc::clients::mock::client_state::MockClientState; use ibc_testkit::testapp::ibc::clients::mock::consensus_state::MockConsensusState; diff --git a/crates/ibc/Cargo.toml b/crates/ibc/Cargo.toml index 8bd87b26f..9a9cc1805 100644 --- a/crates/ibc/Cargo.toml +++ b/crates/ibc/Cargo.toml @@ -22,7 +22,6 @@ borsh = { workspace = true, optional = true } bytes = { workspace = true } derive_more = { workspace = true } displaydoc = { workspace = true } -primitive-types = { workspace = true } prost = { workspace = true } serde_derive = { workspace = true, optional = true } serde = { workspace = true, optional = true } @@ -32,9 +31,9 @@ sha2 = { workspace = true, default-features = false } time = { workspace = true, default-features = false } schemars = { workspace = true, optional = true } typed-builder = { workspace = true, optional = true } -uint = { version = "0.9", default-features = false } # ibc dependencies +# ibc-apps = { version = "0.47.0", path = "../ibc-apps" } ibc-derive = { version = "0.3.0", path = "../ibc-derive" } ibc-proto = { workspace = true } ics23 = { workspace = true, features = ["host-functions"] } @@ -70,8 +69,6 @@ std = [ "serde_json/std", "sha2/std", "displaydoc/std", - "uint/std", - "primitive-types/std", "tendermint/clock", "tendermint/std", ] diff --git a/crates/ibc/src/applications/mod.rs b/crates/ibc/src/applications/mod.rs deleted file mode 100644 index bfbfd10f6..000000000 --- a/crates/ibc/src/applications/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -//! Implementation of IBC applications - -#[cfg(feature = "serde")] -pub mod transfer; diff --git a/crates/ibc/src/core/ics04_channel/acknowledgement.rs b/crates/ibc/src/core/ics04_channel/acknowledgement.rs index c7a91c754..732234103 100644 --- a/crates/ibc/src/core/ics04_channel/acknowledgement.rs +++ b/crates/ibc/src/core/ics04_channel/acknowledgement.rs @@ -140,71 +140,3 @@ impl From for Acknowledgement { .expect("token transfer internal error: ack is never supposed to be empty") } } - -#[cfg(test)] -mod test { - use super::*; - use crate::applications::transfer::ack_success_b64; - use crate::applications::transfer::error::TokenTransferError; - - #[test] - fn test_ack_ser() { - fn ser_json_assert_eq(ack: AcknowledgementStatus, json_str: &str) { - let ser = serde_json::to_string(&ack).unwrap(); - assert_eq!(ser, json_str) - } - - ser_json_assert_eq( - AcknowledgementStatus::success(ack_success_b64()), - r#"{"result":"AQ=="}"#, - ); - ser_json_assert_eq( - AcknowledgementStatus::error(TokenTransferError::PacketDataDeserialization.into()), - r#"{"error":"failed to deserialize packet data"}"#, - ); - } - - #[test] - fn test_ack_success_to_vec() { - let ack_success: Vec = AcknowledgementStatus::success(ack_success_b64()).into(); - - // Check that it's the same output as ibc-go - // Note: this also implicitly checks that the ack bytes are non-empty, - // which would make the conversion to `Acknowledgement` panic - assert_eq!(ack_success, r#"{"result":"AQ=="}"#.as_bytes()); - } - - #[test] - fn test_ack_error_to_vec() { - let ack_error: Vec = - AcknowledgementStatus::error(TokenTransferError::PacketDataDeserialization.into()) - .into(); - - // Check that it's the same output as ibc-go - // Note: this also implicitly checks that the ack bytes are non-empty, - // which would make the conversion to `Acknowledgement` panic - assert_eq!( - ack_error, - r#"{"error":"failed to deserialize packet data"}"#.as_bytes() - ); - } - - #[test] - fn test_ack_de() { - fn de_json_assert_eq(json_str: &str, ack: AcknowledgementStatus) { - let de = serde_json::from_str::(json_str).unwrap(); - assert_eq!(de, ack) - } - - de_json_assert_eq( - r#"{"result":"AQ=="}"#, - AcknowledgementStatus::success(ack_success_b64()), - ); - de_json_assert_eq( - r#"{"error":"failed to deserialize packet data"}"#, - AcknowledgementStatus::error(TokenTransferError::PacketDataDeserialization.into()), - ); - - assert!(serde_json::from_str::(r#"{"success":"AQ=="}"#).is_err()); - } -} diff --git a/crates/ibc/src/core/ics04_channel/handler.rs b/crates/ibc/src/core/ics04_channel/handler.rs index 0950dc923..ab39f168a 100644 --- a/crates/ibc/src/core/ics04_channel/handler.rs +++ b/crates/ibc/src/core/ics04_channel/handler.rs @@ -1,13 +1,13 @@ //! This module implements the processing logic for ICS4 (channel) messages. -pub(crate) mod acknowledgement; -pub(crate) mod chan_close_confirm; -pub(crate) mod chan_close_init; -pub(crate) mod chan_open_ack; -pub(crate) mod chan_open_confirm; -pub(crate) mod chan_open_init; -pub(crate) mod chan_open_try; -pub(crate) mod recv_packet; -pub(crate) mod send_packet; -pub(crate) mod timeout; -pub(crate) mod timeout_on_close; +pub mod acknowledgement; +pub mod chan_close_confirm; +pub mod chan_close_init; +pub mod chan_open_ack; +pub mod chan_open_confirm; +pub mod chan_open_init; +pub mod chan_open_try; +pub mod recv_packet; +pub mod send_packet; +pub mod timeout; +pub mod timeout_on_close; diff --git a/crates/ibc/src/core/ics04_channel/mod.rs b/crates/ibc/src/core/ics04_channel/mod.rs index 40e6538cf..a969a9cde 100644 --- a/crates/ibc/src/core/ics04_channel/mod.rs +++ b/crates/ibc/src/core/ics04_channel/mod.rs @@ -6,7 +6,7 @@ pub mod context; pub mod error; pub mod events; -pub(crate) mod handler; +pub mod handler; pub mod msgs; pub mod packet; pub mod timeout; diff --git a/crates/ibc/src/lib.rs b/crates/ibc/src/lib.rs index 16318bdfb..b4e0bffcb 100644 --- a/crates/ibc/src/lib.rs +++ b/crates/ibc/src/lib.rs @@ -50,7 +50,6 @@ pub use signer::Signer; /// Represents a block height pub use crate::core::ics02_client::height::Height; -pub mod applications; pub mod clients; pub mod core; pub mod hosts; @@ -60,7 +59,7 @@ mod signer; pub mod utils; #[cfg(feature = "serde")] -mod serializers; +pub mod serializers; /// Re-exports pertinent ibc proto types from the `ibc-proto-rs` crate for added convenience pub mod proto { From 859e5f4ae77a6af5247294580c8c777412eff37d Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 14 Nov 2023 18:00:01 -0800 Subject: [PATCH 02/16] imp: rename transfer dir to ics20_transfer --- Cargo.toml | 4 ++-- crates/ibc-apps/{transfer => ics20_transfer}/Cargo.toml | 0 crates/ibc-apps/{transfer => ics20_transfer}/README.md | 0 crates/ibc-apps/{transfer => ics20_transfer}/src/context.rs | 0 .../ibc-apps/{transfer => ics20_transfer}/src/handler/mod.rs | 0 .../src/handler/on_recv_packet.rs | 0 .../{transfer => ics20_transfer}/src/handler/send_transfer.rs | 0 crates/ibc-apps/{transfer => ics20_transfer}/src/lib.rs | 0 crates/ibc-apps/{transfer => ics20_transfer}/src/module.rs | 0 crates/ibc-apps/{transfer => ics20_transfer}/types/Cargo.toml | 0 crates/ibc-apps/{transfer => ics20_transfer}/types/README.md | 0 .../ibc-apps/{transfer => ics20_transfer}/types/src/amount.rs | 0 .../ibc-apps/{transfer => ics20_transfer}/types/src/coin.rs | 0 .../ibc-apps/{transfer => ics20_transfer}/types/src/denom.rs | 0 .../ibc-apps/{transfer => ics20_transfer}/types/src/error.rs | 0 .../ibc-apps/{transfer => ics20_transfer}/types/src/events.rs | 0 crates/ibc-apps/{transfer => ics20_transfer}/types/src/lib.rs | 0 .../ibc-apps/{transfer => ics20_transfer}/types/src/memo.rs | 0 .../{transfer => ics20_transfer}/types/src/msgs/mod.rs | 0 .../{transfer => ics20_transfer}/types/src/msgs/transfer.rs | 0 .../ibc-apps/{transfer => ics20_transfer}/types/src/packet.rs | 0 crates/ibc-testkit/Cargo.toml | 2 +- 22 files changed, 3 insertions(+), 3 deletions(-) rename crates/ibc-apps/{transfer => ics20_transfer}/Cargo.toml (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/README.md (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/src/context.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/src/handler/mod.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/src/handler/on_recv_packet.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/src/handler/send_transfer.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/src/lib.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/src/module.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/types/Cargo.toml (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/types/README.md (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/types/src/amount.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/types/src/coin.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/types/src/denom.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/types/src/error.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/types/src/events.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/types/src/lib.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/types/src/memo.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/types/src/msgs/mod.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/types/src/msgs/transfer.rs (100%) rename crates/ibc-apps/{transfer => ics20_transfer}/types/src/packet.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 8ec240696..001863b34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,8 @@ resolver = "2" members = [ "crates/ibc", - "crates/ibc-apps/transfer", - "crates/ibc-apps/transfer/types", + "crates/ibc-apps/ics20_transfer", + "crates/ibc-apps/ics20_transfer/types", "crates/ibc-derive", "crates/ibc-testkit", "crates/ibc-query", diff --git a/crates/ibc-apps/transfer/Cargo.toml b/crates/ibc-apps/ics20_transfer/Cargo.toml similarity index 100% rename from crates/ibc-apps/transfer/Cargo.toml rename to crates/ibc-apps/ics20_transfer/Cargo.toml diff --git a/crates/ibc-apps/transfer/README.md b/crates/ibc-apps/ics20_transfer/README.md similarity index 100% rename from crates/ibc-apps/transfer/README.md rename to crates/ibc-apps/ics20_transfer/README.md diff --git a/crates/ibc-apps/transfer/src/context.rs b/crates/ibc-apps/ics20_transfer/src/context.rs similarity index 100% rename from crates/ibc-apps/transfer/src/context.rs rename to crates/ibc-apps/ics20_transfer/src/context.rs diff --git a/crates/ibc-apps/transfer/src/handler/mod.rs b/crates/ibc-apps/ics20_transfer/src/handler/mod.rs similarity index 100% rename from crates/ibc-apps/transfer/src/handler/mod.rs rename to crates/ibc-apps/ics20_transfer/src/handler/mod.rs diff --git a/crates/ibc-apps/transfer/src/handler/on_recv_packet.rs b/crates/ibc-apps/ics20_transfer/src/handler/on_recv_packet.rs similarity index 100% rename from crates/ibc-apps/transfer/src/handler/on_recv_packet.rs rename to crates/ibc-apps/ics20_transfer/src/handler/on_recv_packet.rs diff --git a/crates/ibc-apps/transfer/src/handler/send_transfer.rs b/crates/ibc-apps/ics20_transfer/src/handler/send_transfer.rs similarity index 100% rename from crates/ibc-apps/transfer/src/handler/send_transfer.rs rename to crates/ibc-apps/ics20_transfer/src/handler/send_transfer.rs diff --git a/crates/ibc-apps/transfer/src/lib.rs b/crates/ibc-apps/ics20_transfer/src/lib.rs similarity index 100% rename from crates/ibc-apps/transfer/src/lib.rs rename to crates/ibc-apps/ics20_transfer/src/lib.rs diff --git a/crates/ibc-apps/transfer/src/module.rs b/crates/ibc-apps/ics20_transfer/src/module.rs similarity index 100% rename from crates/ibc-apps/transfer/src/module.rs rename to crates/ibc-apps/ics20_transfer/src/module.rs diff --git a/crates/ibc-apps/transfer/types/Cargo.toml b/crates/ibc-apps/ics20_transfer/types/Cargo.toml similarity index 100% rename from crates/ibc-apps/transfer/types/Cargo.toml rename to crates/ibc-apps/ics20_transfer/types/Cargo.toml diff --git a/crates/ibc-apps/transfer/types/README.md b/crates/ibc-apps/ics20_transfer/types/README.md similarity index 100% rename from crates/ibc-apps/transfer/types/README.md rename to crates/ibc-apps/ics20_transfer/types/README.md diff --git a/crates/ibc-apps/transfer/types/src/amount.rs b/crates/ibc-apps/ics20_transfer/types/src/amount.rs similarity index 100% rename from crates/ibc-apps/transfer/types/src/amount.rs rename to crates/ibc-apps/ics20_transfer/types/src/amount.rs diff --git a/crates/ibc-apps/transfer/types/src/coin.rs b/crates/ibc-apps/ics20_transfer/types/src/coin.rs similarity index 100% rename from crates/ibc-apps/transfer/types/src/coin.rs rename to crates/ibc-apps/ics20_transfer/types/src/coin.rs diff --git a/crates/ibc-apps/transfer/types/src/denom.rs b/crates/ibc-apps/ics20_transfer/types/src/denom.rs similarity index 100% rename from crates/ibc-apps/transfer/types/src/denom.rs rename to crates/ibc-apps/ics20_transfer/types/src/denom.rs diff --git a/crates/ibc-apps/transfer/types/src/error.rs b/crates/ibc-apps/ics20_transfer/types/src/error.rs similarity index 100% rename from crates/ibc-apps/transfer/types/src/error.rs rename to crates/ibc-apps/ics20_transfer/types/src/error.rs diff --git a/crates/ibc-apps/transfer/types/src/events.rs b/crates/ibc-apps/ics20_transfer/types/src/events.rs similarity index 100% rename from crates/ibc-apps/transfer/types/src/events.rs rename to crates/ibc-apps/ics20_transfer/types/src/events.rs diff --git a/crates/ibc-apps/transfer/types/src/lib.rs b/crates/ibc-apps/ics20_transfer/types/src/lib.rs similarity index 100% rename from crates/ibc-apps/transfer/types/src/lib.rs rename to crates/ibc-apps/ics20_transfer/types/src/lib.rs diff --git a/crates/ibc-apps/transfer/types/src/memo.rs b/crates/ibc-apps/ics20_transfer/types/src/memo.rs similarity index 100% rename from crates/ibc-apps/transfer/types/src/memo.rs rename to crates/ibc-apps/ics20_transfer/types/src/memo.rs diff --git a/crates/ibc-apps/transfer/types/src/msgs/mod.rs b/crates/ibc-apps/ics20_transfer/types/src/msgs/mod.rs similarity index 100% rename from crates/ibc-apps/transfer/types/src/msgs/mod.rs rename to crates/ibc-apps/ics20_transfer/types/src/msgs/mod.rs diff --git a/crates/ibc-apps/transfer/types/src/msgs/transfer.rs b/crates/ibc-apps/ics20_transfer/types/src/msgs/transfer.rs similarity index 100% rename from crates/ibc-apps/transfer/types/src/msgs/transfer.rs rename to crates/ibc-apps/ics20_transfer/types/src/msgs/transfer.rs diff --git a/crates/ibc-apps/transfer/types/src/packet.rs b/crates/ibc-apps/ics20_transfer/types/src/packet.rs similarity index 100% rename from crates/ibc-apps/transfer/types/src/packet.rs rename to crates/ibc-apps/ics20_transfer/types/src/packet.rs diff --git a/crates/ibc-testkit/Cargo.toml b/crates/ibc-testkit/Cargo.toml index 253e081f3..3e21c2b8f 100644 --- a/crates/ibc-testkit/Cargo.toml +++ b/crates/ibc-testkit/Cargo.toml @@ -31,7 +31,7 @@ typed-builder = { workspace = true } # ibc dependencies ibc = { version = "0.47.0", path = "../ibc" } # NOTE: since `ibc-testkit` does not well support `no_std` yet, we keep `ibc` default features enabled -ibc-app-transfer = { version = "0.47.0", path = "../ibc-apps/transfer", default-features = false} +ibc-app-transfer = { version = "0.47.0", path = "../ibc-apps/ics20_transfer", default-features = false} # cosmos dependencies tendermint = { workspace = true } From 19adc01fbe106c4fd1ddf046cdd31b2173b842c8 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 14 Nov 2023 18:42:58 -0800 Subject: [PATCH 03/16] feat: add ibc-apps crate --- Cargo.toml | 1 + crates/ibc-apps/Cargo.toml | 29 +++++++++++++++++++ crates/ibc-apps/README.md | 1 + crates/ibc-apps/ics20_transfer/Cargo.toml | 3 +- crates/ibc-apps/ics20_transfer/README.md | 1 - crates/ibc-apps/ics20_transfer/src/lib.rs | 7 +++-- .../ibc-apps/ics20_transfer/types/Cargo.toml | 10 +++---- .../ibc-apps/ics20_transfer/types/README.md | 1 - .../ics20_transfer/types/src/amount.rs | 4 --- .../ibc-apps/ics20_transfer/types/src/lib.rs | 27 ++++++++++------- .../ics20_transfer/types/src/packet.rs | 4 +-- crates/ibc-apps/src/lib.rs | 15 ++++++++++ crates/ibc-testkit/Cargo.toml | 4 +-- 13 files changed, 76 insertions(+), 31 deletions(-) create mode 100644 crates/ibc-apps/Cargo.toml create mode 100644 crates/ibc-apps/README.md delete mode 100644 crates/ibc-apps/ics20_transfer/README.md delete mode 100644 crates/ibc-apps/ics20_transfer/types/README.md create mode 100644 crates/ibc-apps/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 001863b34..6aeb4ee9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ resolver = "2" members = [ "crates/ibc", + "crates/ibc-apps", "crates/ibc-apps/ics20_transfer", "crates/ibc-apps/ics20_transfer/types", "crates/ibc-derive", diff --git a/crates/ibc-apps/Cargo.toml b/crates/ibc-apps/Cargo.toml new file mode 100644 index 000000000..1427f1313 --- /dev/null +++ b/crates/ibc-apps/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "ibc-apps" +version = { workspace = true } +authors = { workspace = true } +edition = { workspace = true } +rust-version = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +keywords = ["blockchain", "cosmos", "ibc", "applications"] +readme = "README.md" +description = """ + TBD +""" + +[package.metadata.docs.rs] +all-features = true + +[dependencies] +# ibc dependencies +ibc-app-transfer = { version = "0.47.0", path = "./ics20_transfer", default-features = false } + +[features] +default = ["std"] +std = [ + "ibc-app-transfer/std", +] +serde = [ + "ibc-app-transfer/serde", +] diff --git a/crates/ibc-apps/README.md b/crates/ibc-apps/README.md new file mode 100644 index 000000000..5aa89288e --- /dev/null +++ b/crates/ibc-apps/README.md @@ -0,0 +1 @@ +# `ibc-apps` diff --git a/crates/ibc-apps/ics20_transfer/Cargo.toml b/crates/ibc-apps/ics20_transfer/Cargo.toml index 79731a20b..16efc3ece 100644 --- a/crates/ibc-apps/ics20_transfer/Cargo.toml +++ b/crates/ibc-apps/ics20_transfer/Cargo.toml @@ -7,7 +7,7 @@ rust-version = { workspace = true } license = { workspace = true } repository = { workspace = true } keywords = ["blockchain", "cosmos", "ibc", "transfer", "ics20"] -readme = "README.md" +readme = "./../README.md" description = """ TBD """ @@ -37,7 +37,6 @@ std = [ "ibc/std", "ibc-proto/std", "ics23/std", - "subtle-encoding/std", "serde_json/std", "sha2/std", ] diff --git a/crates/ibc-apps/ics20_transfer/README.md b/crates/ibc-apps/ics20_transfer/README.md deleted file mode 100644 index 14245ef9a..000000000 --- a/crates/ibc-apps/ics20_transfer/README.md +++ /dev/null @@ -1 +0,0 @@ -# `ibc-app-transfer` diff --git a/crates/ibc-apps/ics20_transfer/src/lib.rs b/crates/ibc-apps/ics20_transfer/src/lib.rs index 995d649b5..ae05ddda2 100644 --- a/crates/ibc-apps/ics20_transfer/src/lib.rs +++ b/crates/ibc-apps/ics20_transfer/src/lib.rs @@ -1,6 +1,8 @@ //! Implementation of the [fungible token transfer module](https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md) (ICS-20) -#![cfg_attr(not(test), deny(clippy::unwrap_used))] #![no_std] +#![forbid(unsafe_code)] +#![cfg_attr(not(test), deny(clippy::unwrap_used))] +#![cfg_attr(not(test), deny(clippy::disallowed_methods, clippy::disallowed_types,))] #![deny( warnings, trivial_casts, @@ -10,8 +12,6 @@ rust_2018_idioms )] #![allow(clippy::result_large_err)] -#![cfg_attr(not(test), deny(clippy::disallowed_methods, clippy::disallowed_types,))] -#![forbid(unsafe_code)] #[cfg(any(test, feature = "std"))] extern crate std; @@ -19,6 +19,7 @@ extern crate std; #[doc(inline)] pub use ibc_app_transfer_types as types; +#[cfg(feature = "serde")] pub mod context; #[cfg(feature = "serde")] pub mod handler; diff --git a/crates/ibc-apps/ics20_transfer/types/Cargo.toml b/crates/ibc-apps/ics20_transfer/types/Cargo.toml index 861f55501..8b4ea939f 100644 --- a/crates/ibc-apps/ics20_transfer/types/Cargo.toml +++ b/crates/ibc-apps/ics20_transfer/types/Cargo.toml @@ -7,7 +7,7 @@ rust-version = { workspace = true } license = { workspace = true } repository = { workspace = true } keywords = ["blockchain", "cosmos", "ibc", "transfer", "ics20", "types"] -readme = "README.md" +readme = "./../../README.md" description = """ TBD """ @@ -51,7 +51,7 @@ std = [ "uint/std", "primitive-types/std", ] -borsh = ["dep:borsh", "ibc-proto/borsh"] -serde = ["dep:serde", "serde_json", "ibc-proto/serde", "ics23/serde"] -schema = ["dep:schemars", "ibc-proto/json-schema", "serde", "std"] -parity-scale-codec = ["dep:parity-scale-codec", "dep:scale-info", "ibc-proto/parity-scale-codec"] \ No newline at end of file +borsh = ["dep:borsh", "ibc/borsh", "ibc-proto/borsh"] +serde = ["dep:serde", "serde_json", "ibc/serde", "ibc-proto/serde", "ics23/serde"] +schema = ["dep:schemars", "ibc/schema", "ibc-proto/json-schema", "serde", "std"] +parity-scale-codec = ["dep:parity-scale-codec", "dep:scale-info", "ibc/parity-scale-codec", "ibc-proto/parity-scale-codec"] \ No newline at end of file diff --git a/crates/ibc-apps/ics20_transfer/types/README.md b/crates/ibc-apps/ics20_transfer/types/README.md deleted file mode 100644 index af4500a90..000000000 --- a/crates/ibc-apps/ics20_transfer/types/README.md +++ /dev/null @@ -1 +0,0 @@ -# `ibc-app-transfer-types` diff --git a/crates/ibc-apps/ics20_transfer/types/src/amount.rs b/crates/ibc-apps/ics20_transfer/types/src/amount.rs index 9b3054952..59f33f512 100644 --- a/crates/ibc-apps/ics20_transfer/types/src/amount.rs +++ b/crates/ibc-apps/ics20_transfer/types/src/amount.rs @@ -8,10 +8,6 @@ use ibc::prelude::*; use primitive_types::U256; use super::error::TokenTransferError; -#[cfg(feature = "schema")] -use crate::alloc::borrow::ToOwned; -#[cfg(feature = "schema")] -use crate::alloc::string::String; /// A type for representing token transfer amounts. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/crates/ibc-apps/ics20_transfer/types/src/lib.rs b/crates/ibc-apps/ics20_transfer/types/src/lib.rs index ebe153872..296d0010f 100644 --- a/crates/ibc-apps/ics20_transfer/types/src/lib.rs +++ b/crates/ibc-apps/ics20_transfer/types/src/lib.rs @@ -1,6 +1,8 @@ //! Implementation of the [fungible token transfer module](https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md) (ICS-20) -#![cfg_attr(not(test), deny(clippy::unwrap_used))] #![no_std] +#![forbid(unsafe_code)] +#![cfg_attr(not(test), deny(clippy::unwrap_used))] +#![cfg_attr(not(test), deny(clippy::disallowed_methods, clippy::disallowed_types,))] #![deny( warnings, trivial_casts, @@ -9,26 +11,31 @@ unused_qualifications, rust_2018_idioms )] -#![cfg_attr(not(test), deny(clippy::disallowed_methods, clippy::disallowed_types,))] -#![forbid(unsafe_code)] - -extern crate alloc; #[cfg(any(test, feature = "std"))] extern crate std; +#[cfg(feature = "serde")] mod amount; +#[cfg(feature = "serde")] +pub use amount::*; +#[cfg(feature = "serde")] mod coin; +#[cfg(feature = "serde")] +pub use coin::*; +#[cfg(feature = "serde")] mod denom; -pub mod error; +#[cfg(feature = "serde")] +pub use denom::*; +#[cfg(feature = "serde")] pub mod events; -mod memo; +#[cfg(feature = "serde")] pub mod msgs; +#[cfg(feature = "serde")] pub mod packet; -pub use amount::*; -pub use coin::*; -pub use denom::*; +pub mod error; +mod memo; pub use memo::*; /// Module identifier for the ICS20 application. diff --git a/crates/ibc-apps/ics20_transfer/types/src/packet.rs b/crates/ibc-apps/ics20_transfer/types/src/packet.rs index 343874727..bb556af34 100644 --- a/crates/ibc-apps/ics20_transfer/types/src/packet.rs +++ b/crates/ibc-apps/ics20_transfer/types/src/packet.rs @@ -1,16 +1,14 @@ //! Contains the `PacketData` type that defines the structure of token transfers' packet bytes -use alloc::string::ToString; use core::convert::TryFrom; use core::str::FromStr; +use ibc::prelude::*; use ibc::Signer; use ibc_proto::ibc::applications::transfer::v2::FungibleTokenPacketData as RawPacketData; use super::error::TokenTransferError; use super::{Amount, Memo, PrefixedCoin, PrefixedDenom}; -#[cfg(feature = "schema")] -use crate::alloc::borrow::ToOwned; /// Defines the structure of token transfers' packet bytes #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/crates/ibc-apps/src/lib.rs b/crates/ibc-apps/src/lib.rs new file mode 100644 index 000000000..589f38794 --- /dev/null +++ b/crates/ibc-apps/src/lib.rs @@ -0,0 +1,15 @@ +//! Exports data structures and implementations of different IBC applications. +#![no_std] +#![forbid(unsafe_code)] +#![cfg_attr(not(test), deny(clippy::unwrap_used))] +#![cfg_attr(not(test), deny(clippy::disallowed_methods, clippy::disallowed_types,))] +#![deny( + warnings, + trivial_numeric_casts, + unused_import_braces, + unused_qualifications, + rust_2018_idioms +)] + +#[doc(inline)] +pub use ibc_app_transfer as transfer; diff --git a/crates/ibc-testkit/Cargo.toml b/crates/ibc-testkit/Cargo.toml index 3e21c2b8f..34f1e36b0 100644 --- a/crates/ibc-testkit/Cargo.toml +++ b/crates/ibc-testkit/Cargo.toml @@ -31,7 +31,7 @@ typed-builder = { workspace = true } # ibc dependencies ibc = { version = "0.47.0", path = "../ibc" } # NOTE: since `ibc-testkit` does not well support `no_std` yet, we keep `ibc` default features enabled -ibc-app-transfer = { version = "0.47.0", path = "../ibc-apps/ics20_transfer", default-features = false} +ibc-app-transfer = { version = "0.47.0", path = "../ibc-apps/ics20_transfer", default-features = false, features = ["serde"] } # cosmos dependencies tendermint = { workspace = true } @@ -55,4 +55,4 @@ std = [ ] # This feature is required for token transfer (ICS-20) -serde = ["dep:serde", "ibc/serde", "serde_json", "ibc-app-transfer/serde"] +serde = ["dep:serde", "ibc/serde", "serde_json"] From d65a62aa04fcdad398774702f68bc336d0f8f3f3 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 14 Nov 2023 18:57:53 -0800 Subject: [PATCH 04/16] fix: remove redundant dep + fix cargo doc --- crates/ibc-apps/Cargo.toml | 1 - crates/ibc-apps/ics20_transfer/Cargo.toml | 7 ------- .../ibc-apps/ics20_transfer/types/Cargo.toml | 5 +---- .../ics20_transfer/types/src/events.rs | 20 ++++++++----------- .../ibc-apps/ics20_transfer/types/src/lib.rs | 6 ++++++ crates/ibc/src/lib.rs | 4 ---- 6 files changed, 15 insertions(+), 28 deletions(-) diff --git a/crates/ibc-apps/Cargo.toml b/crates/ibc-apps/Cargo.toml index 1427f1313..5760534eb 100644 --- a/crates/ibc-apps/Cargo.toml +++ b/crates/ibc-apps/Cargo.toml @@ -16,7 +16,6 @@ description = """ all-features = true [dependencies] -# ibc dependencies ibc-app-transfer = { version = "0.47.0", path = "./ics20_transfer", default-features = false } [features] diff --git a/crates/ibc-apps/ics20_transfer/Cargo.toml b/crates/ibc-apps/ics20_transfer/Cargo.toml index 16efc3ece..bc0d7e69b 100644 --- a/crates/ibc-apps/ics20_transfer/Cargo.toml +++ b/crates/ibc-apps/ics20_transfer/Cargo.toml @@ -23,9 +23,6 @@ sha2 = { workspace = true } # ibc dependencies ibc-app-transfer-types = { version = "0.47.0", path = "./types", default-features = false } ibc = { version = "0.47.0", path = "./../../ibc", default-features = false } -ibc-derive = { version = "0.3.0", path = "./../../ibc-derive" } -ibc-proto = { workspace = true } -ics23 = { workspace = true } [dev-dependencies] subtle-encoding = { workspace = true } @@ -35,16 +32,12 @@ default = ["std"] std = [ "ibc-app-transfer-types/std", "ibc/std", - "ibc-proto/std", - "ics23/std", "serde_json/std", "sha2/std", ] serde = [ "ibc-app-transfer-types/serde", "ibc/serde", - "ibc-proto/serde", - "ics23/serde", "serde_json" ] diff --git a/crates/ibc-apps/ics20_transfer/types/Cargo.toml b/crates/ibc-apps/ics20_transfer/types/Cargo.toml index 8b4ea939f..1cbacc71c 100644 --- a/crates/ibc-apps/ics20_transfer/types/Cargo.toml +++ b/crates/ibc-apps/ics20_transfer/types/Cargo.toml @@ -28,9 +28,7 @@ uint = { version = "0.9", default-features = false } # ibc dependencies ibc = { version = "0.47.0", path = "./../../../ibc" } -ibc-derive = { version = "0.3.0", path = "./../../../ibc-derive" } ibc-proto = { workspace = true } -ics23 = { workspace = true } ## parity dependencies parity-scale-codec = { workspace = true , optional = true } @@ -44,7 +42,6 @@ rstest = { workspace = true } default = ["std"] std = [ "ibc-proto/std", - "ics23/std", "serde/std", "serde_json/std", "displaydoc/std", @@ -52,6 +49,6 @@ std = [ "primitive-types/std", ] borsh = ["dep:borsh", "ibc/borsh", "ibc-proto/borsh"] -serde = ["dep:serde", "serde_json", "ibc/serde", "ibc-proto/serde", "ics23/serde"] +serde = ["dep:serde", "serde_json", "ibc/serde", "ibc-proto/serde"] schema = ["dep:schemars", "ibc/schema", "ibc-proto/json-schema", "serde", "std"] parity-scale-codec = ["dep:parity-scale-codec", "dep:scale-info", "ibc/parity-scale-codec", "ibc-proto/parity-scale-codec"] \ No newline at end of file diff --git a/crates/ibc-apps/ics20_transfer/types/src/events.rs b/crates/ibc-apps/ics20_transfer/types/src/events.rs index 03a63b807..daaecee80 100644 --- a/crates/ibc-apps/ics20_transfer/types/src/events.rs +++ b/crates/ibc-apps/ics20_transfer/types/src/events.rs @@ -23,8 +23,8 @@ pub enum Event { Transfer(TransferEvent), } -/// Event emitted in the [`onRecvPacket`][super::context::on_recv_packet_execute] -/// module callback to indicate the that the `RecvPacket` message was processed +/// Event emitted in the `onRecvPacket` module callback to indicate the that the +/// `RecvPacket` message was processed pub struct RecvEvent { pub sender: Signer, pub receiver: Signer, @@ -59,8 +59,7 @@ impl From for ModuleEvent { } } -/// Event emitted in the [`onAcknowledgePacket`][super::context::on_acknowledgement_packet_execute] -/// module callback +/// Event emitted in the `onAcknowledgePacket` module callback pub struct AckEvent { pub sender: Signer, pub receiver: Signer, @@ -95,8 +94,8 @@ impl From for ModuleEvent { } } -/// Event emitted in the [`onAcknowledgePacket`][super::context::on_acknowledgement_packet_execute] -/// module callback to indicate whether the acknowledgement is a success or a failure +/// Event emitted in the `onAcknowledgePacket` module callback to indicate +/// whether the acknowledgement is a success or a failure pub struct AckStatusEvent { pub acknowledgement: AcknowledgementStatus, } @@ -116,8 +115,7 @@ impl From for ModuleEvent { } } -/// Event emitted in the [`onTimeoutPacket`][super::context::on_timeout_packet_execute] -/// module callback +/// Event emitted in the `onTimeoutPacket` module callback pub struct TimeoutEvent { pub refund_receiver: Signer, pub refund_denom: PrefixedDenom, @@ -146,8 +144,7 @@ impl From for ModuleEvent { } } -/// Event emitted in the [`onRecvPacket`][super::context::on_recv_packet_execute] -/// module callback when new tokens are minted +/// Event emitted in the `onRecvPacket` module callback when new tokens are minted pub struct DenomTraceEvent { pub trace_hash: Option, pub denom: PrefixedDenom, @@ -167,8 +164,7 @@ impl From for ModuleEvent { } } -/// Event emitted in [`sendTransfer`][super::send_transfer] after a successful -/// transfer +/// Event emitted after a successful `sendTransfer` pub struct TransferEvent { pub sender: Signer, pub receiver: Signer, diff --git a/crates/ibc-apps/ics20_transfer/types/src/lib.rs b/crates/ibc-apps/ics20_transfer/types/src/lib.rs index 296d0010f..c22a44f10 100644 --- a/crates/ibc-apps/ics20_transfer/types/src/lib.rs +++ b/crates/ibc-apps/ics20_transfer/types/src/lib.rs @@ -38,6 +38,12 @@ pub mod error; mod memo; pub use memo::*; +/// Re-exports ICS-20 token transfer proto types from the `ibc-proto-rs` crate +/// for added convenience +pub mod proto { + pub use ibc_proto::ibc::apps::transfer; +} + /// Module identifier for the ICS20 application. pub const MODULE_ID_STR: &str = "transfer"; diff --git a/crates/ibc/src/lib.rs b/crates/ibc/src/lib.rs index b4e0bffcb..a8f0ec7d3 100644 --- a/crates/ibc/src/lib.rs +++ b/crates/ibc/src/lib.rs @@ -24,9 +24,6 @@ //! client interface that is defined in `Core`) for specific consensus algorithms. A chain uses these //! verification algorithms to verify the state of remote chains. //! -//! + [Applications](applications) consists of implementations of some IBC applications. This is the part of -//! the protocol that abstracts away the core protocol and focuses solely on business logic. -//! //! When processing a given message `M`, if any method in this library returns an error, the runtime //! is expected to rollback all state modifications made to the context //! (e.g. [`ExecutionContext`](core::ExecutionContext)) while processing `M`. If a transaction on your @@ -64,7 +61,6 @@ pub mod serializers; /// Re-exports pertinent ibc proto types from the `ibc-proto-rs` crate for added convenience pub mod proto { pub use ibc_proto::google::protobuf::Any; - pub use ibc_proto::ibc::apps::transfer; pub use ibc_proto::ibc::lightclients::tendermint; pub use ibc_proto::ibc::{core, mock}; pub use ibc_proto::{ics23, Protobuf}; From 155e0809dd6b7b4851c39f9bb3b72dde0da2099d Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 14 Nov 2023 20:11:57 -0800 Subject: [PATCH 05/16] docs: add README and descriptions --- crates/ibc-apps/Cargo.toml | 3 +- crates/ibc-apps/README.md | 47 +++++++++++++++++++ crates/ibc-apps/ics20_transfer/Cargo.toml | 3 +- .../ibc-apps/ics20_transfer/types/Cargo.toml | 5 +- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/crates/ibc-apps/Cargo.toml b/crates/ibc-apps/Cargo.toml index 5760534eb..ad78d7ecb 100644 --- a/crates/ibc-apps/Cargo.toml +++ b/crates/ibc-apps/Cargo.toml @@ -9,7 +9,8 @@ repository = { workspace = true } keywords = ["blockchain", "cosmos", "ibc", "applications"] readme = "README.md" description = """ - TBD + `ibc-apps` provides a comprehensive set of libraries for IBC applications, + facilitating seamless integration of IBC business logic into any blockchain system. """ [package.metadata.docs.rs] diff --git a/crates/ibc-apps/README.md b/crates/ibc-apps/README.md index 5aa89288e..35ff8247e 100644 --- a/crates/ibc-apps/README.md +++ b/crates/ibc-apps/README.md @@ -1 +1,48 @@ # `ibc-apps` + +This crate is top-level library re-exports implemented Inter-Blockchain +Communication (IBC) applications in Rust serves as a centralized hub, +simplifying the process of importing and integrating various IBC applications +into your blockchain. IBC is a distributed protocol that enables communication +between distinct sovereign blockchains and IBC applications is the part of the +protocol that abstracts away the core transport and authentication layers and +focuses solely on business logics. + +The structure within the `ibc-apps` crate is designed to provide flexibility for +external users. It allows you to utilize the own `ibc-apps` crate +comprehensively or selectively import specific libraries, whether you need a +certain IBC application (e.g. `ibc-app-transfer` crate) or only their associated +data structures (e.g. `ibc-app-transfer-types`). This versatility empowers +hosts, including chain integrators, relayers, or any IBC tooling projects, to +build their solutions on top of the layers that best suit their requirements. + +## Libraries + +Currently, the `ibc-apps` crate contains the implementation of the following IBC +applications: + +### ICS-20: Fungible Token Transfer Application + +- [ibc-app-transfer](crates/ibc-apps/ics20-transfer) +- [ibc-app-transfer-types](crates/ibc-apps/ics20-transfer/types) + +## Contributing + +IBC is specified in English in the [cosmos/ibc repo][ibc]. Any +protocol changes or clarifications should be contributed there. + +If you're interested in contributing, please comment on an issue or open a new +one! + +See also [CONTRIBUTING.md](./../../CONTRIBUTING.md). + +## Resources + +- [IBC Website][ibc-homepage] +- [IBC Specification][ibc] +- [IBC Go implementation][ibc-go] + +[//]: # (general links) +[ibc]: https://github.com/cosmos/ibc +[ibc-go]: https://github.com/cosmos/ibc-go +[ibc-homepage]: https://cosmos.network/ibc diff --git a/crates/ibc-apps/ics20_transfer/Cargo.toml b/crates/ibc-apps/ics20_transfer/Cargo.toml index bc0d7e69b..9c215d0e5 100644 --- a/crates/ibc-apps/ics20_transfer/Cargo.toml +++ b/crates/ibc-apps/ics20_transfer/Cargo.toml @@ -9,7 +9,8 @@ repository = { workspace = true } keywords = ["blockchain", "cosmos", "ibc", "transfer", "ics20"] readme = "./../README.md" description = """ - TBD + Contains the core implementation of the ICS-20 token transfer application logic + along with re-exporting the data structures from `ibc-app-transfer-types` crate. """ [package.metadata.docs.rs] diff --git a/crates/ibc-apps/ics20_transfer/types/Cargo.toml b/crates/ibc-apps/ics20_transfer/types/Cargo.toml index 1cbacc71c..e7dcf7460 100644 --- a/crates/ibc-apps/ics20_transfer/types/Cargo.toml +++ b/crates/ibc-apps/ics20_transfer/types/Cargo.toml @@ -6,10 +6,11 @@ edition = { workspace = true } rust-version = { workspace = true } license = { workspace = true } repository = { workspace = true } -keywords = ["blockchain", "cosmos", "ibc", "transfer", "ics20", "types"] +keywords = ["blockchain", "cosmos", "ibc", "transfer", "ics20"] readme = "./../../README.md" description = """ - TBD + Contains the universal data structures of the ICS-20 fungible token transfer application + that can be used across various IBC implementations """ [package.metadata.docs.rs] From eb939ac02267edcd07af9f330809ea64f7022de8 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 14 Nov 2023 20:18:58 -0800 Subject: [PATCH 06/16] docs: update main README page --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6bcd01fe8..e85724edc 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ the `ibc` rust crate which defines the main data structures and on-chain logic f ## Libraries - [ibc](crates/ibc/README.md) - Data structures and on-chain logic for the IBC protocol. +- [ibc-apps](crates/ibc-apps/README.md) - Contains implementation of various IBC applications. - [ibc-derive](crates/ibc-derive/README.md) - Derive macros for `ClientState` and `ConsensusState` traits, reducing boilerplate. - [ibc-testkit](crates/ibc-testkit/README.md) - Testing toolkit to aid `ibc-rs` and host chains in writing integration tests. From 6be246b911ff202579923101e144b1a7ff9b9335 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 14 Nov 2023 20:23:41 -0800 Subject: [PATCH 07/16] nit: docstrings --- crates/ibc-apps/ics20_transfer/types/src/amount.rs | 1 - crates/ibc-apps/ics20_transfer/types/src/coin.rs | 1 - crates/ibc-apps/ics20_transfer/types/src/denom.rs | 1 - crates/ibc-apps/ics20_transfer/types/src/error.rs | 1 - crates/ibc-apps/ics20_transfer/types/src/events.rs | 1 - crates/ibc-apps/ics20_transfer/types/src/lib.rs | 2 +- crates/ibc-apps/ics20_transfer/types/src/msgs/mod.rs | 1 - crates/ibc-apps/ics20_transfer/types/src/msgs/transfer.rs | 1 - 8 files changed, 1 insertion(+), 8 deletions(-) diff --git a/crates/ibc-apps/ics20_transfer/types/src/amount.rs b/crates/ibc-apps/ics20_transfer/types/src/amount.rs index 59f33f512..765b689ec 100644 --- a/crates/ibc-apps/ics20_transfer/types/src/amount.rs +++ b/crates/ibc-apps/ics20_transfer/types/src/amount.rs @@ -1,5 +1,4 @@ //! Contains the `Amount` type, which represents amounts of tokens transferred. - use core::ops::Deref; use core::str::FromStr; diff --git a/crates/ibc-apps/ics20_transfer/types/src/coin.rs b/crates/ibc-apps/ics20_transfer/types/src/coin.rs index ed6308492..70f3d832b 100644 --- a/crates/ibc-apps/ics20_transfer/types/src/coin.rs +++ b/crates/ibc-apps/ics20_transfer/types/src/coin.rs @@ -1,5 +1,4 @@ //! Defines coin types; the objects that are being transferred. - use core::fmt::{Display, Error as FmtError, Formatter}; use core::str::FromStr; diff --git a/crates/ibc-apps/ics20_transfer/types/src/denom.rs b/crates/ibc-apps/ics20_transfer/types/src/denom.rs index f9a10b6c2..75f4223f8 100644 --- a/crates/ibc-apps/ics20_transfer/types/src/denom.rs +++ b/crates/ibc-apps/ics20_transfer/types/src/denom.rs @@ -1,5 +1,4 @@ //! Defines types to represent "denominations" [as defined in ICS-20](https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md#data-structures) - use core::fmt::{Display, Error as FmtError, Formatter}; use core::str::FromStr; diff --git a/crates/ibc-apps/ics20_transfer/types/src/error.rs b/crates/ibc-apps/ics20_transfer/types/src/error.rs index df8eee9f0..8372f8aa5 100644 --- a/crates/ibc-apps/ics20_transfer/types/src/error.rs +++ b/crates/ibc-apps/ics20_transfer/types/src/error.rs @@ -1,5 +1,4 @@ //! Defines the token transfer error type - use core::convert::Infallible; use core::str::Utf8Error; diff --git a/crates/ibc-apps/ics20_transfer/types/src/events.rs b/crates/ibc-apps/ics20_transfer/types/src/events.rs index daaecee80..b644d16ef 100644 --- a/crates/ibc-apps/ics20_transfer/types/src/events.rs +++ b/crates/ibc-apps/ics20_transfer/types/src/events.rs @@ -1,5 +1,4 @@ //! Defines all token transfer event types - use ibc::core::events::ModuleEvent; use ibc::core::ics04_channel::acknowledgement::AcknowledgementStatus; use ibc::prelude::*; diff --git a/crates/ibc-apps/ics20_transfer/types/src/lib.rs b/crates/ibc-apps/ics20_transfer/types/src/lib.rs index c22a44f10..8ef118651 100644 --- a/crates/ibc-apps/ics20_transfer/types/src/lib.rs +++ b/crates/ibc-apps/ics20_transfer/types/src/lib.rs @@ -1,4 +1,4 @@ -//! Implementation of the [fungible token transfer module](https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md) (ICS-20) +//! Implementation of the IBC [fungible token transfer](https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md) (ICS-20) data structures. #![no_std] #![forbid(unsafe_code)] #![cfg_attr(not(test), deny(clippy::unwrap_used))] diff --git a/crates/ibc-apps/ics20_transfer/types/src/msgs/mod.rs b/crates/ibc-apps/ics20_transfer/types/src/msgs/mod.rs index c019a3120..9c6780741 100644 --- a/crates/ibc-apps/ics20_transfer/types/src/msgs/mod.rs +++ b/crates/ibc-apps/ics20_transfer/types/src/msgs/mod.rs @@ -1,3 +1,2 @@ //! Defines the token transfer message type - pub mod transfer; diff --git a/crates/ibc-apps/ics20_transfer/types/src/msgs/transfer.rs b/crates/ibc-apps/ics20_transfer/types/src/msgs/transfer.rs index 12fd67ff7..eb061d9a2 100644 --- a/crates/ibc-apps/ics20_transfer/types/src/msgs/transfer.rs +++ b/crates/ibc-apps/ics20_transfer/types/src/msgs/transfer.rs @@ -1,5 +1,4 @@ //! Defines the token transfer message type - use ibc::core::ics04_channel::error::PacketError; use ibc::core::ics04_channel::timeout::TimeoutHeight; use ibc::core::ics24_host::identifier::{ChannelId, PortId}; From 5d12b42150fc3e693a9dbb11f06b0516b39eeedf Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 14 Nov 2023 20:24:11 -0800 Subject: [PATCH 08/16] nit: docstrings --- crates/ibc-apps/ics20_transfer/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ibc-apps/ics20_transfer/src/lib.rs b/crates/ibc-apps/ics20_transfer/src/lib.rs index ae05ddda2..b055ee3e7 100644 --- a/crates/ibc-apps/ics20_transfer/src/lib.rs +++ b/crates/ibc-apps/ics20_transfer/src/lib.rs @@ -1,4 +1,4 @@ -//! Implementation of the [fungible token transfer module](https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md) (ICS-20) +//! Implementation of the IBC [fungible token transfer](https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md) (ICS-20) application logic. #![no_std] #![forbid(unsafe_code)] #![cfg_attr(not(test), deny(clippy::unwrap_used))] From a6b7268c89187cfe8313e441579ad3a1f75d7648 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 14 Nov 2023 20:30:57 -0800 Subject: [PATCH 09/16] imp: rename folder to ics20-transfer --- Cargo.toml | 4 ++-- crates/ibc-apps/Cargo.toml | 2 +- crates/ibc-apps/{ics20_transfer => ics20-transfer}/Cargo.toml | 0 .../{ics20_transfer => ics20-transfer}/src/context.rs | 0 .../{ics20_transfer => ics20-transfer}/src/handler/mod.rs | 0 .../src/handler/on_recv_packet.rs | 0 .../src/handler/send_transfer.rs | 0 crates/ibc-apps/{ics20_transfer => ics20-transfer}/src/lib.rs | 0 .../ibc-apps/{ics20_transfer => ics20-transfer}/src/module.rs | 0 .../{ics20_transfer => ics20-transfer}/types/Cargo.toml | 0 .../{ics20_transfer => ics20-transfer}/types/src/amount.rs | 0 .../{ics20_transfer => ics20-transfer}/types/src/coin.rs | 0 .../{ics20_transfer => ics20-transfer}/types/src/denom.rs | 0 .../{ics20_transfer => ics20-transfer}/types/src/error.rs | 0 .../{ics20_transfer => ics20-transfer}/types/src/events.rs | 0 .../{ics20_transfer => ics20-transfer}/types/src/lib.rs | 0 .../{ics20_transfer => ics20-transfer}/types/src/memo.rs | 0 .../{ics20_transfer => ics20-transfer}/types/src/msgs/mod.rs | 0 .../types/src/msgs/transfer.rs | 0 .../{ics20_transfer => ics20-transfer}/types/src/packet.rs | 0 crates/ibc-testkit/Cargo.toml | 2 +- 21 files changed, 4 insertions(+), 4 deletions(-) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/Cargo.toml (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/src/context.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/src/handler/mod.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/src/handler/on_recv_packet.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/src/handler/send_transfer.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/src/lib.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/src/module.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/types/Cargo.toml (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/types/src/amount.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/types/src/coin.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/types/src/denom.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/types/src/error.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/types/src/events.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/types/src/lib.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/types/src/memo.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/types/src/msgs/mod.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/types/src/msgs/transfer.rs (100%) rename crates/ibc-apps/{ics20_transfer => ics20-transfer}/types/src/packet.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 6aeb4ee9d..993bc031f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,8 +3,8 @@ resolver = "2" members = [ "crates/ibc", "crates/ibc-apps", - "crates/ibc-apps/ics20_transfer", - "crates/ibc-apps/ics20_transfer/types", + "crates/ibc-apps/ics20-transfer", + "crates/ibc-apps/ics20-transfer/types", "crates/ibc-derive", "crates/ibc-testkit", "crates/ibc-query", diff --git a/crates/ibc-apps/Cargo.toml b/crates/ibc-apps/Cargo.toml index ad78d7ecb..9d9550d68 100644 --- a/crates/ibc-apps/Cargo.toml +++ b/crates/ibc-apps/Cargo.toml @@ -17,7 +17,7 @@ description = """ all-features = true [dependencies] -ibc-app-transfer = { version = "0.47.0", path = "./ics20_transfer", default-features = false } +ibc-app-transfer = { version = "0.47.0", path = "./ics20-transfer", default-features = false } [features] default = ["std"] diff --git a/crates/ibc-apps/ics20_transfer/Cargo.toml b/crates/ibc-apps/ics20-transfer/Cargo.toml similarity index 100% rename from crates/ibc-apps/ics20_transfer/Cargo.toml rename to crates/ibc-apps/ics20-transfer/Cargo.toml diff --git a/crates/ibc-apps/ics20_transfer/src/context.rs b/crates/ibc-apps/ics20-transfer/src/context.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/src/context.rs rename to crates/ibc-apps/ics20-transfer/src/context.rs diff --git a/crates/ibc-apps/ics20_transfer/src/handler/mod.rs b/crates/ibc-apps/ics20-transfer/src/handler/mod.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/src/handler/mod.rs rename to crates/ibc-apps/ics20-transfer/src/handler/mod.rs diff --git a/crates/ibc-apps/ics20_transfer/src/handler/on_recv_packet.rs b/crates/ibc-apps/ics20-transfer/src/handler/on_recv_packet.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/src/handler/on_recv_packet.rs rename to crates/ibc-apps/ics20-transfer/src/handler/on_recv_packet.rs diff --git a/crates/ibc-apps/ics20_transfer/src/handler/send_transfer.rs b/crates/ibc-apps/ics20-transfer/src/handler/send_transfer.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/src/handler/send_transfer.rs rename to crates/ibc-apps/ics20-transfer/src/handler/send_transfer.rs diff --git a/crates/ibc-apps/ics20_transfer/src/lib.rs b/crates/ibc-apps/ics20-transfer/src/lib.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/src/lib.rs rename to crates/ibc-apps/ics20-transfer/src/lib.rs diff --git a/crates/ibc-apps/ics20_transfer/src/module.rs b/crates/ibc-apps/ics20-transfer/src/module.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/src/module.rs rename to crates/ibc-apps/ics20-transfer/src/module.rs diff --git a/crates/ibc-apps/ics20_transfer/types/Cargo.toml b/crates/ibc-apps/ics20-transfer/types/Cargo.toml similarity index 100% rename from crates/ibc-apps/ics20_transfer/types/Cargo.toml rename to crates/ibc-apps/ics20-transfer/types/Cargo.toml diff --git a/crates/ibc-apps/ics20_transfer/types/src/amount.rs b/crates/ibc-apps/ics20-transfer/types/src/amount.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/types/src/amount.rs rename to crates/ibc-apps/ics20-transfer/types/src/amount.rs diff --git a/crates/ibc-apps/ics20_transfer/types/src/coin.rs b/crates/ibc-apps/ics20-transfer/types/src/coin.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/types/src/coin.rs rename to crates/ibc-apps/ics20-transfer/types/src/coin.rs diff --git a/crates/ibc-apps/ics20_transfer/types/src/denom.rs b/crates/ibc-apps/ics20-transfer/types/src/denom.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/types/src/denom.rs rename to crates/ibc-apps/ics20-transfer/types/src/denom.rs diff --git a/crates/ibc-apps/ics20_transfer/types/src/error.rs b/crates/ibc-apps/ics20-transfer/types/src/error.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/types/src/error.rs rename to crates/ibc-apps/ics20-transfer/types/src/error.rs diff --git a/crates/ibc-apps/ics20_transfer/types/src/events.rs b/crates/ibc-apps/ics20-transfer/types/src/events.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/types/src/events.rs rename to crates/ibc-apps/ics20-transfer/types/src/events.rs diff --git a/crates/ibc-apps/ics20_transfer/types/src/lib.rs b/crates/ibc-apps/ics20-transfer/types/src/lib.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/types/src/lib.rs rename to crates/ibc-apps/ics20-transfer/types/src/lib.rs diff --git a/crates/ibc-apps/ics20_transfer/types/src/memo.rs b/crates/ibc-apps/ics20-transfer/types/src/memo.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/types/src/memo.rs rename to crates/ibc-apps/ics20-transfer/types/src/memo.rs diff --git a/crates/ibc-apps/ics20_transfer/types/src/msgs/mod.rs b/crates/ibc-apps/ics20-transfer/types/src/msgs/mod.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/types/src/msgs/mod.rs rename to crates/ibc-apps/ics20-transfer/types/src/msgs/mod.rs diff --git a/crates/ibc-apps/ics20_transfer/types/src/msgs/transfer.rs b/crates/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/types/src/msgs/transfer.rs rename to crates/ibc-apps/ics20-transfer/types/src/msgs/transfer.rs diff --git a/crates/ibc-apps/ics20_transfer/types/src/packet.rs b/crates/ibc-apps/ics20-transfer/types/src/packet.rs similarity index 100% rename from crates/ibc-apps/ics20_transfer/types/src/packet.rs rename to crates/ibc-apps/ics20-transfer/types/src/packet.rs diff --git a/crates/ibc-testkit/Cargo.toml b/crates/ibc-testkit/Cargo.toml index 34f1e36b0..57b1e061b 100644 --- a/crates/ibc-testkit/Cargo.toml +++ b/crates/ibc-testkit/Cargo.toml @@ -31,7 +31,7 @@ typed-builder = { workspace = true } # ibc dependencies ibc = { version = "0.47.0", path = "../ibc" } # NOTE: since `ibc-testkit` does not well support `no_std` yet, we keep `ibc` default features enabled -ibc-app-transfer = { version = "0.47.0", path = "../ibc-apps/ics20_transfer", default-features = false, features = ["serde"] } +ibc-app-transfer = { version = "0.47.0", path = "../ibc-apps/ics20-transfer", default-features = false, features = ["serde"] } # cosmos dependencies tendermint = { workspace = true } From 6f88edb0e8755bc6977dcbfa495b1fb58b397259 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 14 Nov 2023 21:27:32 -0800 Subject: [PATCH 10/16] chore: move serializers into ics20-transfer/types --- .../ics20-transfer/types/src/amount.rs | 2 +- .../ics20-transfer/types/src/denom.rs | 5 ++-- .../ibc-apps/ics20-transfer/types/src/lib.rs | 3 ++ .../ics20-transfer/types/src/serializers.rs | 25 ++++++++++++++++ crates/ibc/src/lib.rs | 2 +- crates/ibc/src/serializers.rs | 29 ------------------- 6 files changed, 32 insertions(+), 34 deletions(-) create mode 100644 crates/ibc-apps/ics20-transfer/types/src/serializers.rs diff --git a/crates/ibc-apps/ics20-transfer/types/src/amount.rs b/crates/ibc-apps/ics20-transfer/types/src/amount.rs index 765b689ec..cc793200b 100644 --- a/crates/ibc-apps/ics20-transfer/types/src/amount.rs +++ b/crates/ibc-apps/ics20-transfer/types/src/amount.rs @@ -14,7 +14,7 @@ use super::error::TokenTransferError; #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Display, From, Into)] pub struct Amount( #[cfg_attr(feature = "schema", schemars(with = "String"))] - #[serde(serialize_with = "ibc::serializers::serde_string::serialize")] + #[serde(serialize_with = "crate::serializers::serialize")] #[serde(deserialize_with = "deserialize")] U256, ); diff --git a/crates/ibc-apps/ics20-transfer/types/src/denom.rs b/crates/ibc-apps/ics20-transfer/types/src/denom.rs index 75f4223f8..42847ceba 100644 --- a/crates/ibc-apps/ics20-transfer/types/src/denom.rs +++ b/crates/ibc-apps/ics20-transfer/types/src/denom.rs @@ -5,11 +5,10 @@ use core::str::FromStr; use derive_more::{Display, From}; use ibc::core::ics24_host::identifier::{ChannelId, PortId}; use ibc::prelude::*; -#[cfg(feature = "serde")] -use ibc::serializers::serde_string; use ibc_proto::ibc::applications::transfer::v1::DenomTrace as RawDenomTrace; use super::error::TokenTransferError; +use crate::serializers; /// The "base" of a denomination. /// @@ -217,7 +216,7 @@ impl Display for TracePath { #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] pub struct PrefixedDenom { /// A series of `{port-id}/{channel-id}`s for tracing the source of the token. - #[cfg_attr(feature = "serde", serde(with = "serde_string"))] + #[cfg_attr(feature = "serde", serde(with = "serializers"))] #[cfg_attr(feature = "schema", schemars(with = "String"))] pub trace_path: TracePath, /// Base denomination of the relayed fungible token. diff --git a/crates/ibc-apps/ics20-transfer/types/src/lib.rs b/crates/ibc-apps/ics20-transfer/types/src/lib.rs index 8ef118651..00ef67404 100644 --- a/crates/ibc-apps/ics20-transfer/types/src/lib.rs +++ b/crates/ibc-apps/ics20-transfer/types/src/lib.rs @@ -34,6 +34,9 @@ pub mod msgs; #[cfg(feature = "serde")] pub mod packet; +#[cfg(feature = "serde")] +pub(crate) mod serializers; + pub mod error; mod memo; pub use memo::*; diff --git a/crates/ibc-apps/ics20-transfer/types/src/serializers.rs b/crates/ibc-apps/ics20-transfer/types/src/serializers.rs new file mode 100644 index 000000000..8bdc589d8 --- /dev/null +++ b/crates/ibc-apps/ics20-transfer/types/src/serializers.rs @@ -0,0 +1,25 @@ +use core::fmt::Display; +use core::str::FromStr; + +use ibc::prelude::*; +use serde::{de, Deserialize, Deserializer, Serializer}; + +// Note: used String version (slower + heap) instead of str, +// because both str ser/de hit some kind of f64/f32 case when compiled into wasm +// and fails to be validated f32/f64 wasm runtimes +pub fn serialize(value: &T, serializer: S) -> Result +where + T: Display, + S: Serializer, +{ + serializer.serialize_str(value.to_string().as_ref()) +} + +pub fn deserialize<'de, T, D>(deserializer: D) -> Result +where + T: FromStr, + T::Err: Display, + D: Deserializer<'de>, +{ + T::from_str(::deserialize(deserializer)?.as_str()).map_err(de::Error::custom) +} diff --git a/crates/ibc/src/lib.rs b/crates/ibc/src/lib.rs index a8f0ec7d3..868b36c42 100644 --- a/crates/ibc/src/lib.rs +++ b/crates/ibc/src/lib.rs @@ -56,7 +56,7 @@ mod signer; pub mod utils; #[cfg(feature = "serde")] -pub mod serializers; +mod serializers; /// Re-exports pertinent ibc proto types from the `ibc-proto-rs` crate for added convenience pub mod proto { diff --git a/crates/ibc/src/serializers.rs b/crates/ibc/src/serializers.rs index a4b56473b..081cd05fe 100644 --- a/crates/ibc/src/serializers.rs +++ b/crates/ibc/src/serializers.rs @@ -12,35 +12,6 @@ where hex.serialize(serializer) } -pub mod serde_string { - use core::fmt::Display; - use core::str::FromStr; - - use serde::{de, Deserialize, Deserializer, Serializer}; - - use crate::prelude::*; - - // Note: used String version (slower + heap) instead of str, - // because both str ser/de hit some kind of f64/f32 case when compiled into wasm - // and fails to be validated f32/f64 wasm runtimes - pub fn serialize(value: &T, serializer: S) -> Result - where - T: Display, - S: Serializer, - { - serializer.serialize_str(value.to_string().as_ref()) - } - - pub fn deserialize<'de, T, D>(deserializer: D) -> Result - where - T: FromStr, - T::Err: Display, - D: Deserializer<'de>, - { - T::from_str(::deserialize(deserializer)?.as_str()).map_err(de::Error::custom) - } -} - /// Test that a struct `T` can be: /// /// - parsed out of the provided JSON data From 84b23d20936d4f2ce8282c1ff9e6345076fd7eee Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Thu, 16 Nov 2023 13:01:36 -0800 Subject: [PATCH 11/16] fix: apply reviewer comments --- README.md | 2 +- crates/ibc-apps/README.md | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e85724edc..2c5c8a8a5 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ the `ibc` rust crate which defines the main data structures and on-chain logic f ## Libraries - [ibc](crates/ibc/README.md) - Data structures and on-chain logic for the IBC protocol. -- [ibc-apps](crates/ibc-apps/README.md) - Contains implementation of various IBC applications. +- [ibc-apps](crates/ibc-apps/README.md) - Contains implementations of various IBC applications. - [ibc-derive](crates/ibc-derive/README.md) - Derive macros for `ClientState` and `ConsensusState` traits, reducing boilerplate. - [ibc-testkit](crates/ibc-testkit/README.md) - Testing toolkit to aid `ibc-rs` and host chains in writing integration tests. diff --git a/crates/ibc-apps/README.md b/crates/ibc-apps/README.md index 35ff8247e..d74d4ad46 100644 --- a/crates/ibc-apps/README.md +++ b/crates/ibc-apps/README.md @@ -1,20 +1,20 @@ # `ibc-apps` -This crate is top-level library re-exports implemented Inter-Blockchain -Communication (IBC) applications in Rust serves as a centralized hub, -simplifying the process of importing and integrating various IBC applications -into your blockchain. IBC is a distributed protocol that enables communication -between distinct sovereign blockchains and IBC applications is the part of the -protocol that abstracts away the core transport and authentication layers and -focuses solely on business logics. +This crate is a top-level library that re-exports Inter-Blockchain +Communication (IBC) applications implemented in Rust. It serves as a centralized hub, +simplifying the process of importing and integrating various IBC applications +into your blockchain. IBC is a distributed protocol that enables communication +between distinct sovereign blockchains. IBC applications abstract away the core +transport and authentication layers, letter blockchain app developers +focus solely on business logic implementation. The structure within the `ibc-apps` crate is designed to provide flexibility for -external users. It allows you to utilize the own `ibc-apps` crate -comprehensively or selectively import specific libraries, whether you need a -certain IBC application (e.g. `ibc-app-transfer` crate) or only their associated -data structures (e.g. `ibc-app-transfer-types`). This versatility empowers -hosts, including chain integrators, relayers, or any IBC tooling projects, to -build their solutions on top of the layers that best suit their requirements. +external users. It allows users to either utilize the entire `ibc-apps` crate, +or selectively import specific sub-crates, whether you need a certain IBC +application (e.g. `ibc-app-transfer` crate) or only their associated data +structures (e.g. `ibc-app-transfer-types`). This versatility empowers hosts, +including chain integrators, relayers, or any IBC tooling projects, to build +their solutions on top of the layers that best suit their requirements. ## Libraries From 520a6fc735c98dec57e965265caae40f6d21a915 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Thu, 16 Nov 2023 13:05:35 -0800 Subject: [PATCH 12/16] imp: add docstring for cosmos_adr028_escrow_address --- crates/ibc-apps/ics20-transfer/src/context.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ibc-apps/ics20-transfer/src/context.rs b/crates/ibc-apps/ics20-transfer/src/context.rs index 5d47d4cf0..80899b12b 100644 --- a/crates/ibc-apps/ics20-transfer/src/context.rs +++ b/crates/ibc-apps/ics20-transfer/src/context.rs @@ -81,7 +81,9 @@ pub trait TokenTransferExecutionContext: TokenTransferValidationContext { ) -> Result<(), TokenTransferError>; } -// https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-028-public-key-addresses.md +/// Helper function to generate an escrow address for a given port and channel +/// ids according to the format specified in the Cosmos SDK +/// [`ADR-028`](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-028-public-key-addresses.md) pub fn cosmos_adr028_escrow_address(port_id: &PortId, channel_id: &ChannelId) -> Vec { let contents = format!("{port_id}/{channel_id}"); From ccf287d07b373a0d1360e3a8b96eaa7339d82b36 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Thu, 16 Nov 2023 19:44:28 -0800 Subject: [PATCH 13/16] fix: add missing features + use workspace deps for ibc crates --- Cargo.toml | 6 +++++- clippy.toml | 9 +++++++++ crates/ibc-apps/Cargo.toml | 10 +++++++++- crates/ibc-apps/ics20-transfer/Cargo.toml | 19 ++++++++++++++++--- crates/ibc-apps/ics20-transfer/src/lib.rs | 2 +- .../ibc-apps/ics20-transfer/types/Cargo.toml | 4 ++-- .../ibc-apps/ics20-transfer/types/src/lib.rs | 2 +- crates/ibc-apps/src/lib.rs | 2 +- 8 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 clippy.toml diff --git a/Cargo.toml b/Cargo.toml index 993bc031f..a2ac8e33a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,11 @@ tracing-subscriber = { version = "0.3.17", features = ["fmt", "env-filter", "jso typed-builder = { version = "0.18.0"} # ibc dependencies -ibc-derive = { version = "0.3.0", path = "../ibc-derive" } +ibc = { version = "0.47.0", path = "./crates/ibc", default-features = false } +ibc-testkit = { version = "0.47.0", path = "./crates/ibc-testkit", default-features = false} +ibc-app-transfer = { version = "0.47.0", path = "./crates/ibc-apps/ics20-transfer", default-features = false } +ibc-app-transfer-types = { version = "0.47.0", path = "./crates/ibc-apps/ics20-transfer/types", default-features = false } +ibc-derive = { version = "0.3.0", path = "./crates/ibc-derive" } ibc-proto = { version = "0.38.0", default-features = false } ics23 = { version = "0.11", default-features = false } diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 000000000..87ee0dae3 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,9 @@ +disallowed-types = [ + # { path = "usize", reason = "variable size" }, # cannot on now, because mocks use it and serde, even if there is no usize in type + { path = "f64", reason = "not supported in CosmWasm" }, + { path = "f32", reason = "not supported in CosmWasm" }, +] + +disallowed-methods = [ + "std::time::Duration::as_secs_f64", +] diff --git a/crates/ibc-apps/Cargo.toml b/crates/ibc-apps/Cargo.toml index 9d9550d68..f0c4420cf 100644 --- a/crates/ibc-apps/Cargo.toml +++ b/crates/ibc-apps/Cargo.toml @@ -17,7 +17,7 @@ description = """ all-features = true [dependencies] -ibc-app-transfer = { version = "0.47.0", path = "./ics20-transfer", default-features = false } +ibc-app-transfer = { workspace = true } [features] default = ["std"] @@ -27,3 +27,11 @@ std = [ serde = [ "ibc-app-transfer/serde", ] +schema = [ + "ibc-app-transfer/schema", + "serde", + "std", +] +borsh = [ + "ibc-app-transfer/borsh", +] diff --git a/crates/ibc-apps/ics20-transfer/Cargo.toml b/crates/ibc-apps/ics20-transfer/Cargo.toml index 9c215d0e5..821e3381b 100644 --- a/crates/ibc-apps/ics20-transfer/Cargo.toml +++ b/crates/ibc-apps/ics20-transfer/Cargo.toml @@ -22,8 +22,8 @@ serde_json = { workspace = true, optional = true } sha2 = { workspace = true } # ibc dependencies -ibc-app-transfer-types = { version = "0.47.0", path = "./types", default-features = false } -ibc = { version = "0.47.0", path = "./../../ibc", default-features = false } +ibc = { workspace = true } +ibc-app-transfer-types = { workspace = true } [dev-dependencies] subtle-encoding = { workspace = true } @@ -41,4 +41,17 @@ serde = [ "ibc/serde", "serde_json" ] - +schema = [ + "ibc-app-transfer-types/schema", + "ibc/schema", + "serde", + "std", +] +borsh = [ + "ibc-app-transfer-types/borsh", + "ibc/borsh", +] +parity-scale-codec = [ + "ibc-app-transfer-types/parity-scale-codec", + "ibc/parity-scale-codec", +] diff --git a/crates/ibc-apps/ics20-transfer/src/lib.rs b/crates/ibc-apps/ics20-transfer/src/lib.rs index b055ee3e7..08b743f51 100644 --- a/crates/ibc-apps/ics20-transfer/src/lib.rs +++ b/crates/ibc-apps/ics20-transfer/src/lib.rs @@ -2,7 +2,7 @@ #![no_std] #![forbid(unsafe_code)] #![cfg_attr(not(test), deny(clippy::unwrap_used))] -#![cfg_attr(not(test), deny(clippy::disallowed_methods, clippy::disallowed_types,))] +#![cfg_attr(not(test), deny(clippy::disallowed_methods, clippy::disallowed_types))] #![deny( warnings, trivial_casts, diff --git a/crates/ibc-apps/ics20-transfer/types/Cargo.toml b/crates/ibc-apps/ics20-transfer/types/Cargo.toml index e7dcf7460..495a77de5 100644 --- a/crates/ibc-apps/ics20-transfer/types/Cargo.toml +++ b/crates/ibc-apps/ics20-transfer/types/Cargo.toml @@ -28,7 +28,7 @@ serde_json = { workspace = true, optional = true} uint = { version = "0.9", default-features = false } # ibc dependencies -ibc = { version = "0.47.0", path = "./../../../ibc" } +ibc = { workspace = true } ibc-proto = { workspace = true } ## parity dependencies @@ -36,7 +36,7 @@ parity-scale-codec = { workspace = true , optional = true } scale-info = { workspace = true , optional = true } [dev-dependencies] -ibc-testkit = { version = "0.47.0", path = "./../../../ibc-testkit", default-features = false} +ibc-testkit = { workspace = true } rstest = { workspace = true } [features] diff --git a/crates/ibc-apps/ics20-transfer/types/src/lib.rs b/crates/ibc-apps/ics20-transfer/types/src/lib.rs index 00ef67404..723a146d3 100644 --- a/crates/ibc-apps/ics20-transfer/types/src/lib.rs +++ b/crates/ibc-apps/ics20-transfer/types/src/lib.rs @@ -2,7 +2,7 @@ #![no_std] #![forbid(unsafe_code)] #![cfg_attr(not(test), deny(clippy::unwrap_used))] -#![cfg_attr(not(test), deny(clippy::disallowed_methods, clippy::disallowed_types,))] +#![cfg_attr(not(test), deny(clippy::disallowed_methods, clippy::disallowed_types))] #![deny( warnings, trivial_casts, diff --git a/crates/ibc-apps/src/lib.rs b/crates/ibc-apps/src/lib.rs index 589f38794..a942a2711 100644 --- a/crates/ibc-apps/src/lib.rs +++ b/crates/ibc-apps/src/lib.rs @@ -1,4 +1,4 @@ -//! Exports data structures and implementations of different IBC applications. +//! Re-exports implementations and data structures of different IBC applications. #![no_std] #![forbid(unsafe_code)] #![cfg_attr(not(test), deny(clippy::unwrap_used))] From 6614ddf3e686c2406ebbb70a8658047e8f739456 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Thu, 16 Nov 2023 20:32:55 -0800 Subject: [PATCH 14/16] imp: place re-exports under mod --- crates/ibc-apps/ics20-transfer/src/lib.rs | 9 +++++++-- crates/ibc-apps/src/lib.rs | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/ibc-apps/ics20-transfer/src/lib.rs b/crates/ibc-apps/ics20-transfer/src/lib.rs index 08b743f51..8c2c31d9c 100644 --- a/crates/ibc-apps/ics20-transfer/src/lib.rs +++ b/crates/ibc-apps/ics20-transfer/src/lib.rs @@ -16,8 +16,13 @@ #[cfg(any(test, feature = "std"))] extern crate std; -#[doc(inline)] -pub use ibc_app_transfer_types as types; +/// Re-exports the implementation of the IBC [fungible token +/// transfer](https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md) +/// (ICS-20) data structures. +pub mod types { + #[doc(inline)] + pub use ibc_app_transfer_types::*; +} #[cfg(feature = "serde")] pub mod context; diff --git a/crates/ibc-apps/src/lib.rs b/crates/ibc-apps/src/lib.rs index a942a2711..3693d65d4 100644 --- a/crates/ibc-apps/src/lib.rs +++ b/crates/ibc-apps/src/lib.rs @@ -11,5 +11,10 @@ rust_2018_idioms )] -#[doc(inline)] -pub use ibc_app_transfer as transfer; +/// Re-exports the implementation of the IBC [fungible token +/// transfer](https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md) +/// (ICS-20) application logic. +pub mod transfer { + #[doc(inline)] + pub use ibc_app_transfer::*; +} From 9402012922f4baabd4fa7d0b817a3353cf91ec1c Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Fri, 17 Nov 2023 07:20:37 -0800 Subject: [PATCH 15/16] nit: apply suggestions from code review Co-authored-by: Sean Chen Signed-off-by: Farhad Shabani --- crates/ibc-apps/ics20-transfer/types/src/events.rs | 10 +++++----- .../ibc-apps/ics20-transfer/types/src/serializers.rs | 8 +++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/ibc-apps/ics20-transfer/types/src/events.rs b/crates/ibc-apps/ics20-transfer/types/src/events.rs index b644d16ef..bee96cf72 100644 --- a/crates/ibc-apps/ics20-transfer/types/src/events.rs +++ b/crates/ibc-apps/ics20-transfer/types/src/events.rs @@ -22,7 +22,7 @@ pub enum Event { Transfer(TransferEvent), } -/// Event emitted in the `onRecvPacket` module callback to indicate the that the +/// Event emitted in the `onRecvPacket` module callback to indicate that the /// `RecvPacket` message was processed pub struct RecvEvent { pub sender: Signer, @@ -58,7 +58,7 @@ impl From for ModuleEvent { } } -/// Event emitted in the `onAcknowledgePacket` module callback +/// Event emitted by the `onAcknowledgePacket` module callback pub struct AckEvent { pub sender: Signer, pub receiver: Signer, @@ -93,7 +93,7 @@ impl From for ModuleEvent { } } -/// Event emitted in the `onAcknowledgePacket` module callback to indicate +/// Event emitted by the `onAcknowledgePacket` module callback to indicate /// whether the acknowledgement is a success or a failure pub struct AckStatusEvent { pub acknowledgement: AcknowledgementStatus, @@ -114,7 +114,7 @@ impl From for ModuleEvent { } } -/// Event emitted in the `onTimeoutPacket` module callback +/// Event emitted by the `onTimeoutPacket` module callback pub struct TimeoutEvent { pub refund_receiver: Signer, pub refund_denom: PrefixedDenom, @@ -143,7 +143,7 @@ impl From for ModuleEvent { } } -/// Event emitted in the `onRecvPacket` module callback when new tokens are minted +/// Event emitted by the `onRecvPacket` module callback when new tokens are minted pub struct DenomTraceEvent { pub trace_hash: Option, pub denom: PrefixedDenom, diff --git a/crates/ibc-apps/ics20-transfer/types/src/serializers.rs b/crates/ibc-apps/ics20-transfer/types/src/serializers.rs index 8bdc589d8..b0b3b5541 100644 --- a/crates/ibc-apps/ics20-transfer/types/src/serializers.rs +++ b/crates/ibc-apps/ics20-transfer/types/src/serializers.rs @@ -4,9 +4,11 @@ use core::str::FromStr; use ibc::prelude::*; use serde::{de, Deserialize, Deserializer, Serializer}; -// Note: used String version (slower + heap) instead of str, -// because both str ser/de hit some kind of f64/f32 case when compiled into wasm -// and fails to be validated f32/f64 wasm runtimes +// Note: This method serializes to a String instead of a str +// in order to avoid a wasm compilation issue. Specifically, +// str (de)serialization hits some kind of f64/f32 case +// when compiled into wasm, but this fails validation on +// f32/f64 wasm runtimes. pub fn serialize(value: &T, serializer: S) -> Result where T: Display, From ff32e98789c635cc19b341966e2bc2a68ce525fc Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Fri, 17 Nov 2023 07:23:22 -0800 Subject: [PATCH 16/16] fix: cargo fmt --- crates/ibc-apps/ics20-transfer/types/src/serializers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ibc-apps/ics20-transfer/types/src/serializers.rs b/crates/ibc-apps/ics20-transfer/types/src/serializers.rs index b0b3b5541..57f6e20d3 100644 --- a/crates/ibc-apps/ics20-transfer/types/src/serializers.rs +++ b/crates/ibc-apps/ics20-transfer/types/src/serializers.rs @@ -7,7 +7,7 @@ use serde::{de, Deserialize, Deserializer, Serializer}; // Note: This method serializes to a String instead of a str // in order to avoid a wasm compilation issue. Specifically, // str (de)serialization hits some kind of f64/f32 case -// when compiled into wasm, but this fails validation on +// when compiled into wasm, but this fails validation on // f32/f64 wasm runtimes. pub fn serialize(value: &T, serializer: S) -> Result where