Skip to content

Commit

Permalink
imp: relocate serializers.rs within the ibc-primitives (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhad-Shabani authored Jan 24, 2024
1 parent 5053973 commit 1710735
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [ibc-primitives] Relocate `serializers.rs` module to reside within the
`ibc-primitives` crate extending its utility for a broader range of IBC
applications. ([\#1055](https://github.com/cosmos/ibc-rs/issues/1055))
3 changes: 2 additions & 1 deletion ibc-apps/ics20-transfer/types/src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use core::str::FromStr;

use derive_more::{Display, From, Into};
use ibc_core::primitives::prelude::*;
use ibc_core::primitives::serializers;
use primitive_types::U256;

use super::error::TokenTransferError;
Expand All @@ -14,7 +15,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 = "crate::serializers::serialize")]
#[serde(serialize_with = "serializers::serialize")]
#[serde(deserialize_with = "deserialize")]
U256,
);
Expand Down
2 changes: 1 addition & 1 deletion ibc-apps/ics20-transfer/types/src/denom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use core::str::FromStr;
use derive_more::{Display, From};
use ibc_core::host::types::identifiers::{ChannelId, PortId};
use ibc_core::primitives::prelude::*;
use ibc_core::primitives::serializers;
use ibc_proto::ibc::applications::transfer::v1::DenomTrace as RawDenomTrace;

use super::error::TokenTransferError;
use crate::serializers;

/// The "base" of a denomination.
///
Expand Down
3 changes: 0 additions & 3 deletions ibc-apps/ics20-transfer/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ pub mod msgs;
#[cfg(feature = "serde")]
pub mod packet;

#[cfg(feature = "serde")]
pub(crate) mod serializers;

pub mod error;
mod memo;
pub use memo::*;
Expand Down
2 changes: 1 addition & 1 deletion ibc-apps/ics721-nft-transfer/types/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use derive_more::From;
use http::Uri;
use ibc_core::host::types::identifiers::{ChannelId, PortId};
use ibc_core::primitives::prelude::*;
use ibc_core::primitives::serializers;
use ibc_proto::ibc::applications::nft_transfer::v1::ClassTrace as RawClassTrace;

use crate::data::Data;
use crate::error::NftTransferError;
use crate::serializers;

/// Class ID for an NFT
#[cfg_attr(
Expand Down
3 changes: 0 additions & 3 deletions ibc-apps/ics721-nft-transfer/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ mod token;
#[cfg(feature = "serde")]
pub use token::*;

#[cfg(feature = "serde")]
pub(crate) mod serializers;

pub mod error;
mod memo;
pub use memo::*;
Expand Down
3 changes: 1 addition & 2 deletions ibc-apps/ics721-nft-transfer/types/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ use core::convert::TryFrom;
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use ibc_core::primitives::prelude::*;
use ibc_core::primitives::Signer;
use ibc_core::primitives::{serializers, Signer};
use ibc_proto::ibc::applications::nft_transfer::v1::NonFungibleTokenPacketData as RawPacketData;

use crate::class::{ClassData, ClassUri, PrefixedClassId};
use crate::error::NftTransferError;
use crate::memo::Memo;
use crate::serializers;
use crate::token::{TokenData, TokenIds, TokenUri};

/// Defines the structure of token transfers' packet bytes
Expand Down
27 changes: 0 additions & 27 deletions ibc-apps/ics721-nft-transfer/types/src/serializers.rs

This file was deleted.

2 changes: 1 addition & 1 deletion ibc-apps/ics721-nft-transfer/types/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use core::str::FromStr;

use http::Uri;
use ibc_core::primitives::prelude::*;
use ibc_core::primitives::serializers;

use crate::data::Data;
use crate::error::NftTransferError;
use crate::serializers;

/// Token ID for an NFT
#[cfg_attr(
Expand Down
5 changes: 5 additions & 0 deletions ibc-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ pub use traits::*;
mod types;
pub use types::*;

// Helper module for serializing and deserializing types through the `String`
// primarily used by IBC applications.
#[cfg(feature = "serde")]
pub mod serializers;

/// Re-export of common proto types from the `ibc-proto` crate.
pub mod proto {
pub use ibc_proto::google::protobuf::Any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use core::fmt::Display;
use core::str::FromStr;

use ibc_core::primitives::prelude::*;
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
// f32/f64 wasm runtimes.
use crate::prelude::*;

// 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<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
T: Display,
Expand Down

0 comments on commit 1710735

Please sign in to comment.