Skip to content

Add Serde feature #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/ibc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ std = [
clock = ["tendermint/clock", "time/std"]
parity-scale-codec = ["dep:parity-scale-codec", "dep:scale-info"]
borsh = ["dep:borsh"]
serde = ["dep:serde"]

# This feature guards the unfinished implementation of ADR 5.
val_exec_ctx = []
Expand All @@ -52,8 +53,8 @@ mocks = ["tendermint-testgen", "clock", "std"]
ibc-proto = { version = "0.24.0", default-features = false }
ics23 = { version = "0.9.0", default-features = false, features = ["host-functions"] }
time = { version = ">=0.3.0, <0.3.18", default-features = false }
serde_derive = { version = "1.0.104", default-features = false }
serde = { version = "1.0", default-features = false }
serde_derive = { version = "1.0.104", default-features = false, optional = true }
serde = { version = "1.0", default-features = false, optional = true }
serde_json = { version = "1", default-features = false }
erased-serde = { version = "0.3", default-features = false, features = ["alloc"] }
tracing = { version = "0.1.36", default-features = false }
Expand Down
8 changes: 4 additions & 4 deletions crates/ibc/src/applications/transfer/acknowledgement.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use core::fmt::{Display, Error as FmtError, Formatter};

use serde::{Deserialize, Serialize};

use super::error::TokenTransferError;
use crate::core::ics26_routing::context::Acknowledgement as AckTrait;
use crate::prelude::*;
Expand All @@ -13,13 +11,15 @@ pub const ACK_ERR_STR: &str = "error handling packet on destination chain: see e
/// A successful acknowledgement, equivalent to `base64::encode(0x01)`.
pub const ACK_SUCCESS_B64: &str = "AQ==";

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ConstAckSuccess {
#[serde(rename = "AQ==")]
Success,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Acknowledgement {
/// Successful Acknowledgement
/// e.g. `{"result":"AQ=="}`
Expand Down
6 changes: 2 additions & 4 deletions crates/ibc/src/applications/transfer/amount.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use core::str::FromStr;
use derive_more::{Display, From, Into};
use serde::{Deserialize, Serialize};

use super::error::TokenTransferError;
use crate::bigint::U256;

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

impl Amount {
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/applications/transfer/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use core::fmt::{Display, Error as FmtError, Formatter};
use core::str::{from_utf8, FromStr};
use ibc_proto::cosmos::base::v1beta1::Coin as ProtoCoin;
use safe_regex::regex;
use serde::{Deserialize, Serialize};

use super::amount::Amount;
use super::denom::{BaseDenom, PrefixedDenom};
Expand All @@ -19,7 +18,8 @@ pub type BaseCoin = Coin<BaseDenom>;
pub type RawCoin = Coin<String>;

/// Coin defines a token with a denomination and an amount.
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub struct Coin<D> {
/// Denomination
pub denom: D,
Expand Down
7 changes: 4 additions & 3 deletions crates/ibc/src/applications/transfer/denom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use core::str::FromStr;

use derive_more::{Display, From};
use ibc_proto::ibc::applications::transfer::v1::DenomTrace as RawDenomTrace;
use serde::{Deserialize, Serialize};

use super::error::TokenTransferError;
use crate::core::ics24_host::identifier::{ChannelId, PortId};
use crate::prelude::*;
use crate::serializers::serde_string;

/// Base denomination type
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize, Display)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Display)]
#[serde(transparent)]
pub struct BaseDenom(String);

Expand Down Expand Up @@ -147,7 +147,8 @@ impl Display for TracePath {
}

/// A type that contains the base denomination for ICS20 and the source tracing information path.
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[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.
#[serde(with = "serde_string")]
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/applications/transfer/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use core::convert::TryFrom;
use core::str::FromStr;

use ibc_proto::ibc::applications::transfer::v2::FungibleTokenPacketData as RawPacketData;
use serde::{Deserialize, Serialize};

use super::error::TokenTransferError;
use super::{Amount, PrefixedCoin, PrefixedDenom};
use crate::signer::Signer;

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
#[serde(try_from = "RawPacketData", into = "RawPacketData")]
pub struct PacketData {
pub token: PrefixedCoin,
Expand Down
10 changes: 6 additions & 4 deletions crates/ibc/src/clients/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use ibc_proto::ibc::core::commitment::v1::MerkleProof as RawMerkleProof;
use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawTmClientState;
use ibc_proto::protobuf::Protobuf;
use prost::Message;
use serde::{Deserialize, Serialize};
use tendermint::chain::id::MAX_LENGTH as MaxChainIdLen;
use tendermint::trust_threshold::TrustThresholdFraction as TendermintTrustThresholdFraction;
use tendermint_light_client_verifier::options::Options;
Expand Down Expand Up @@ -55,7 +54,8 @@ use crate::core::ValidationContext;

pub const TENDERMINT_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ClientState";

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ClientState {
pub chain_id: ChainId,
pub trust_level: TrustThreshold,
Expand All @@ -71,7 +71,8 @@ pub struct ClientState {
verifier: ProdVerifier,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct AllowUpdate {
pub after_expiry: bool,
pub after_misbehaviour: bool,
Expand Down Expand Up @@ -350,7 +351,8 @@ impl ClientState {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct UpgradeOptions {
pub unbonding_period: Duration,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/clients/ics07_tendermint/consensus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::prelude::*;
use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawConsensusState;
use ibc_proto::protobuf::Protobuf;
use serde::{Deserialize, Serialize};
use tendermint::{hash::Algorithm, time::Time, Hash};
use tendermint_proto::google::protobuf as tpb;

Expand All @@ -19,7 +18,8 @@ use super::client_type as tm_client_type;
pub const TENDERMINT_CONSENSUS_STATE_TYPE_URL: &str =
"/ibc.lightclients.tendermint.v1.ConsensusState";

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ConsensusState {
pub timestamp: Time,
pub root: CommitmentRoot,
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/clients/ics07_tendermint/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::lightclients::tendermint::v1::Header as RawHeader;
use ibc_proto::protobuf::Protobuf;
use prost::Message;
use serde_derive::{Deserialize, Serialize};
use tendermint::block::signed_header::SignedHeader;
use tendermint::chain::Id as TmChainId;
use tendermint::validator::Set as ValidatorSet;
Expand All @@ -26,8 +25,9 @@ use super::client_type as tm_client_type;

pub const TENDERMINT_HEADER_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.Header";

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Tendermint consensus header
#[derive(Clone, PartialEq, Eq, Deserialize, Serialize)]
#[derive(Clone, PartialEq, Eq)]
pub struct Header {
pub signed_header: SignedHeader, // contains the commitment root
pub validator_set: ValidatorSet, // the validator set that signed Header
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/clients/ics07_tendermint/misbehaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::lightclients::tendermint::v1::Misbehaviour as RawMisbehaviour;
use ibc_proto::protobuf::Protobuf;
use prost::Message;
use serde::{Deserialize, Serialize};
use tendermint_light_client_verifier::ProdVerifier;

use crate::clients::ics07_tendermint::error::{Error, IntoResult};
Expand All @@ -16,7 +15,8 @@ use crate::Height;

pub const TENDERMINT_MISBEHAVIOUR_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.Misbehaviour";

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Misbehaviour {
client_id: ClientId,
header1: Header,
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/core/ics02_client/client_type.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prelude::*;
use core::fmt::{Display, Error as FmtError, Formatter};
use serde_derive::{Deserialize, Serialize};

#[cfg_attr(
feature = "parity-scale-codec",
Expand All @@ -14,8 +13,9 @@ use serde_derive::{Deserialize, Serialize};
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Type of the client, depending on the specific consensus algorithm.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ClientType(String);

impl ClientType {
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/core/ics02_client/height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use core::str::FromStr;

use displaydoc::Display;
use ibc_proto::protobuf::Protobuf;
use serde_derive::{Deserialize, Serialize};

use ibc_proto::ibc::core::client::v1::Height as RawHeight;

Expand All @@ -24,7 +23,8 @@ use crate::core::ics02_client::error::ClientError;
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct Height {
/// Previously known as "epoch"
revision_number: u64,
Expand Down
7 changes: 3 additions & 4 deletions crates/ibc/src/core/ics02_client/trust_threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ use core::{
fmt::{Display, Error as FmtError, Formatter},
};

use ibc_proto::protobuf::Protobuf;
use serde::{Deserialize, Serialize};

use ibc_proto::ibc::lightclients::tendermint::v1::Fraction;
use ibc_proto::protobuf::Protobuf;
use tendermint::trust_threshold::TrustThresholdFraction;

use crate::core::ics02_client::error::ClientError;
Expand All @@ -35,7 +33,8 @@ use crate::core::ics02_client::error::ClientError;
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct TrustThreshold {
numerator: u64,
denominator: u64,
Expand Down
13 changes: 8 additions & 5 deletions crates/ibc/src/core/ics03_connection/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use core::{
};

use ibc_proto::protobuf::Protobuf;
use serde::{Deserialize, Serialize};

use ibc_proto::ibc::core::connection::v1::{
ConnectionEnd as RawConnectionEnd, Counterparty as RawCounterparty,
Expand All @@ -35,7 +34,8 @@ use crate::timestamp::ZERO_DURATION;
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct IdentifiedConnectionEnd {
pub connection_id: ConnectionId,
pub connection_end: ConnectionEnd,
Expand Down Expand Up @@ -104,7 +104,8 @@ impl From<IdentifiedConnectionEnd> for RawIdentifiedConnection {
feature = "parity-scale-codec",
derive(parity_scale_codec::Encode, parity_scale_codec::Decode,)
)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct ConnectionEnd {
pub state: State,
client_id: ClientId,
Expand Down Expand Up @@ -368,7 +369,8 @@ impl ConnectionEnd {
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Counterparty {
client_id: ClientId,
pub connection_id: Option<ConnectionId>,
Expand Down Expand Up @@ -462,7 +464,8 @@ impl Counterparty {
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum State {
Uninitialized = 0isize,
Init = 1isize,
Expand Down
17 changes: 10 additions & 7 deletions crates/ibc/src/core/ics03_connection/events.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! Types for the IBC events emitted from Tendermint Websocket by the connection module.

use serde_derive::{Deserialize, Serialize};
use tendermint::abci;

use crate::core::ics24_host::identifier::{ClientId, ConnectionId};
Expand All @@ -13,7 +11,8 @@ pub const CLIENT_ID_ATTRIBUTE_KEY: &str = "client_id";
pub const COUNTERPARTY_CONN_ID_ATTRIBUTE_KEY: &str = "counterparty_connection_id";
pub const COUNTERPARTY_CLIENT_ID_ATTRIBUTE_KEY: &str = "counterparty_client_id";

#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct Attributes {
pub connection_id: ConnectionId,
pub client_id: ClientId,
Expand Down Expand Up @@ -51,7 +50,8 @@ impl From<Attributes> for Vec<abci::EventAttribute> {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OpenInit(Attributes);

impl OpenInit {
Expand Down Expand Up @@ -92,7 +92,8 @@ impl From<OpenInit> for abci::Event {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OpenTry(Attributes);

impl OpenTry {
Expand Down Expand Up @@ -134,7 +135,8 @@ impl From<OpenTry> for abci::Event {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OpenAck(Attributes);

impl OpenAck {
Expand Down Expand Up @@ -176,7 +178,8 @@ impl From<OpenAck> for abci::Event {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OpenConfirm(Attributes);

impl OpenConfirm {
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/core/ics03_connection/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::utils::pretty::PrettySlice;

use ibc_proto::ibc::core::connection::v1::Version as RawVersion;
use ibc_proto::protobuf::Protobuf;
use serde::{Deserialize, Serialize};

use crate::core::ics03_connection::error::ConnectionError;
use crate::core::ics04_channel::channel::Order;
Expand All @@ -23,7 +22,8 @@ use crate::core::ics04_channel::channel::Order;
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Version {
/// unique version identifier
identifier: String,
Expand Down
Loading