Skip to content

Commit 339d5e9

Browse files
committed
add serde feature
1 parent ddb0200 commit 339d5e9

33 files changed

+259
-117
lines changed

crates/ibc/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ std = [
3939
clock = ["tendermint/clock", "time/std"]
4040
parity-scale-codec = ["dep:parity-scale-codec", "dep:scale-info"]
4141
borsh = ["dep:borsh"]
42+
serde = ["dep:serde", "dep:serde_derive"]
4243

4344
# This feature guards the unfinished implementation of ADR 5.
4445
val_exec_ctx = []
@@ -52,8 +53,8 @@ mocks = ["tendermint-testgen", "clock", "std"]
5253
ibc-proto = { version = "0.24.0", default-features = false }
5354
ics23 = { version = "0.9.0", default-features = false, features = ["host-functions"] }
5455
time = { version = ">=0.3.0, <0.3.18", default-features = false }
55-
serde_derive = { version = "1.0.104", default-features = false }
56-
serde = { version = "1.0", default-features = false }
56+
serde_derive = { version = "1.0.104", default-features = false, optional = true }
57+
serde = { version = "1.0", default-features = false, optional = true}
5758
serde_json = { version = "1", default-features = false }
5859
erased-serde = { version = "0.3", default-features = false, features = ["alloc"] }
5960
tracing = { version = "0.1.36", default-features = false }

crates/ibc/src/applications/transfer/acknowledgement.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use core::fmt::{Display, Error as FmtError, Formatter};
22

3-
use serde::{Deserialize, Serialize};
4-
53
use super::error::TokenTransferError;
64
use crate::core::ics26_routing::context::Acknowledgement as AckTrait;
75
use crate::prelude::*;
@@ -13,13 +11,21 @@ pub const ACK_ERR_STR: &str = "error handling packet on destination chain: see e
1311
/// A successful acknowledgement, equivalent to `base64::encode(0x01)`.
1412
pub const ACK_SUCCESS_B64: &str = "AQ==";
1513

16-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
14+
#[cfg_attr(
15+
feature = "serde",
16+
derive(serde_derive::Serialize, serde_derive::Deserialize)
17+
)]
18+
#[derive(Clone, Debug, PartialEq, Eq)]
1719
pub enum ConstAckSuccess {
1820
#[serde(rename = "AQ==")]
1921
Success,
2022
}
2123

22-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
24+
#[cfg_attr(
25+
feature = "serde",
26+
derive(serde_derive::Serialize, serde_derive::Deserialize)
27+
)]
28+
#[derive(Clone, Debug, PartialEq, Eq)]
2329
pub enum Acknowledgement {
2430
/// Successful Acknowledgement
2531
/// e.g. `{"result":"AQ=="}`

crates/ibc/src/applications/transfer/amount.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use core::str::FromStr;
22
use derive_more::{Display, From, Into};
3-
use serde::{Deserialize, Serialize};
43

54
use super::error::TokenTransferError;
65
use crate::bigint::U256;
76

87
/// A type for representing token transfer amounts.
9-
#[derive(
10-
Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize, Display, From, Into,
8+
#[cfg_attr(
9+
feature = "serde",
10+
derive(serde_derive::Serialize, serde_derive::Deserialize)
1111
)]
12+
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Display, From, Into)]
1213
pub struct Amount(U256);
1314

1415
impl Amount {

crates/ibc/src/applications/transfer/coin.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use core::fmt::{Display, Error as FmtError, Formatter};
22
use core::str::{from_utf8, FromStr};
33
use ibc_proto::cosmos::base::v1beta1::Coin as ProtoCoin;
44
use safe_regex::regex;
5-
use serde::{Deserialize, Serialize};
65

76
use super::amount::Amount;
87
use super::denom::{BaseDenom, PrefixedDenom};
@@ -19,7 +18,11 @@ pub type BaseCoin = Coin<BaseDenom>;
1918
pub type RawCoin = Coin<String>;
2019

2120
/// Coin defines a token with a denomination and an amount.
22-
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
21+
#[cfg_attr(
22+
feature = "serde",
23+
derive(serde_derive::Serialize, serde_derive::Deserialize)
24+
)]
25+
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
2326
pub struct Coin<D> {
2427
/// Denomination
2528
pub denom: D,

crates/ibc/src/applications/transfer/denom.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ use core::str::FromStr;
33

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

87
use super::error::TokenTransferError;
98
use crate::core::ics24_host::identifier::{ChannelId, PortId};
109
use crate::prelude::*;
1110
use crate::serializers::serde_string;
1211

1312
/// Base denomination type
14-
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize, Display)]
13+
#[cfg_attr(
14+
feature = "serde",
15+
derive(serde_derive::Serialize, serde_derive::Deserialize)
16+
)]
17+
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Display)]
1518
#[serde(transparent)]
1619
pub struct BaseDenom(String);
1720

@@ -147,7 +150,11 @@ impl Display for TracePath {
147150
}
148151

149152
/// A type that contains the base denomination for ICS20 and the source tracing information path.
150-
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
153+
#[cfg_attr(
154+
feature = "serde",
155+
derive(serde_derive::Serialize, serde_derive::Deserialize)
156+
)]
157+
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
151158
pub struct PrefixedDenom {
152159
/// A series of `{port-id}/{channel-id}`s for tracing the source of the token.
153160
#[serde(with = "serde_string")]

crates/ibc/src/applications/transfer/packet.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ use core::convert::TryFrom;
33
use core::str::FromStr;
44

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

87
use super::error::TokenTransferError;
98
use super::{Amount, PrefixedCoin, PrefixedDenom};
109
use crate::signer::Signer;
1110

12-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
11+
#[cfg_attr(
12+
feature = "serde",
13+
derive(serde_derive::Serialize, serde_derive::Deserialize)
14+
)]
15+
#[derive(Clone, Debug, PartialEq, Eq)]
1316
#[serde(try_from = "RawPacketData", into = "RawPacketData")]
1417
pub struct PacketData {
1518
pub token: PrefixedCoin,

crates/ibc/src/clients/ics07_tendermint/client_state.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use ibc_proto::ibc::core::commitment::v1::MerkleProof as RawMerkleProof;
99
use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawTmClientState;
1010
use ibc_proto::protobuf::Protobuf;
1111
use prost::Message;
12-
use serde::{Deserialize, Serialize};
12+
// use serde::{Deserialize, Serialize};
1313
use tendermint::chain::id::MAX_LENGTH as MaxChainIdLen;
1414
use tendermint::trust_threshold::TrustThresholdFraction as TendermintTrustThresholdFraction;
1515
use tendermint_light_client_verifier::options::Options;
@@ -55,7 +55,11 @@ use crate::core::ValidationContext;
5555

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

58-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
58+
#[cfg_attr(
59+
feature = "serde",
60+
derive(serde_derive::Serialize, serde_derive::Deserialize)
61+
)]
62+
#[derive(Clone, Debug, PartialEq, Eq)]
5963
pub struct ClientState {
6064
pub chain_id: ChainId,
6165
pub trust_level: TrustThreshold,
@@ -70,8 +74,11 @@ pub struct ClientState {
7074
#[serde(skip)]
7175
verifier: ProdVerifier,
7276
}
73-
74-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
77+
#[cfg_attr(
78+
feature = "serde",
79+
derive(serde_derive::Serialize, serde_derive::Deserialize)
80+
)]
81+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
7582
pub struct AllowUpdate {
7683
pub after_expiry: bool,
7784
pub after_misbehaviour: bool,
@@ -354,7 +361,11 @@ impl ClientState {
354361
}
355362
}
356363

357-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
364+
#[cfg_attr(
365+
feature = "serde",
366+
derive(serde_derive::Serialize, serde_derive::Deserialize)
367+
)]
368+
#[derive(Clone, Debug, PartialEq, Eq)]
358369
pub struct UpgradeOptions {
359370
pub unbonding_period: Duration,
360371
}

crates/ibc/src/clients/ics07_tendermint/consensus_state.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::prelude::*;
33
use ibc_proto::google::protobuf::Any;
44
use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawConsensusState;
55
use ibc_proto::protobuf::Protobuf;
6-
use serde::{Deserialize, Serialize};
76
use tendermint::{hash::Algorithm, time::Time, Hash};
87
use tendermint_proto::google::protobuf as tpb;
98

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

22-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
21+
#[cfg_attr(
22+
feature = "serde",
23+
derive(serde_derive::Serialize, serde_derive::Deserialize)
24+
)]
25+
#[derive(Clone, Debug, PartialEq, Eq)]
2326
pub struct ConsensusState {
2427
pub timestamp: Time,
2528
pub root: CommitmentRoot,

crates/ibc/src/clients/ics07_tendermint/header.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use ibc_proto::google::protobuf::Any;
77
use ibc_proto::ibc::lightclients::tendermint::v1::Header as RawHeader;
88
use ibc_proto::protobuf::Protobuf;
99
use prost::Message;
10-
use serde_derive::{Deserialize, Serialize};
1110
use tendermint::block::signed_header::SignedHeader;
1211
use tendermint::chain::Id as TmChainId;
1312
use tendermint::validator::Set as ValidatorSet;
@@ -27,7 +26,11 @@ use super::client_type as tm_client_type;
2726
pub const TENDERMINT_HEADER_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.Header";
2827

2928
/// Tendermint consensus header
30-
#[derive(Clone, PartialEq, Eq, Deserialize, Serialize)]
29+
#[cfg_attr(
30+
feature = "serde",
31+
derive(serde_derive::Serialize, serde_derive::Deserialize)
32+
)]
33+
#[derive(Clone, PartialEq, Eq)]
3134
pub struct Header {
3235
pub signed_header: SignedHeader, // contains the commitment root
3336
pub validator_set: ValidatorSet, // the validator set that signed Header

crates/ibc/src/clients/ics07_tendermint/misbehaviour.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use ibc_proto::google::protobuf::Any;
55
use ibc_proto::ibc::lightclients::tendermint::v1::Misbehaviour as RawMisbehaviour;
66
use ibc_proto::protobuf::Protobuf;
77
use prost::Message;
8-
use serde::{Deserialize, Serialize};
98
use tendermint_light_client_verifier::ProdVerifier;
109

1110
use crate::clients::ics07_tendermint::error::{Error, IntoResult};
@@ -16,7 +15,11 @@ use crate::Height;
1615

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

19-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
18+
#[cfg_attr(
19+
feature = "serde",
20+
derive(serde_derive::Serialize, serde_derive::Deserialize)
21+
)]
22+
#[derive(Clone, Debug, PartialEq, Eq)]
2023
pub struct Misbehaviour {
2124
client_id: ClientId,
2225
header1: Header,

crates/ibc/src/core/ics02_client/client_type.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::prelude::*;
22
use core::fmt::{Display, Error as FmtError, Formatter};
3-
use serde_derive::{Deserialize, Serialize};
43

54
#[cfg_attr(
65
feature = "parity-scale-codec",
@@ -14,8 +13,12 @@ use serde_derive::{Deserialize, Serialize};
1413
feature = "borsh",
1514
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
1615
)]
16+
#[cfg_attr(
17+
feature = "serde",
18+
derive(serde_derive::Serialize, serde_derive::Deserialize)
19+
)]
1720
/// Type of the client, depending on the specific consensus algorithm.
18-
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
21+
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1922
pub struct ClientType(String);
2023

2124
impl ClientType {

crates/ibc/src/core/ics02_client/height.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ use core::num::ParseIntError;
55
use core::str::FromStr;
66

77
use displaydoc::Display;
8-
use ibc_proto::protobuf::Protobuf;
9-
use serde_derive::{Deserialize, Serialize};
10-
118
use ibc_proto::ibc::core::client::v1::Height as RawHeight;
9+
use ibc_proto::protobuf::Protobuf;
1210

1311
use crate::core::ics02_client::error::ClientError;
1412

@@ -24,7 +22,11 @@ use crate::core::ics02_client::error::ClientError;
2422
feature = "borsh",
2523
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
2624
)]
27-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
25+
#[cfg_attr(
26+
feature = "serde",
27+
derive(serde_derive::Serialize, serde_derive::Deserialize)
28+
)]
29+
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
2830
pub struct Height {
2931
/// Previously known as "epoch"
3032
revision_number: u64,

crates/ibc/src/core/ics02_client/trust_threshold.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use core::{
88
};
99

1010
use ibc_proto::protobuf::Protobuf;
11-
use serde::{Deserialize, Serialize};
1211

1312
use ibc_proto::ibc::lightclients::tendermint::v1::Fraction;
1413
use tendermint::trust_threshold::TrustThresholdFraction;
@@ -35,7 +34,8 @@ use crate::core::ics02_client::error::ClientError;
3534
feature = "borsh",
3635
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
3736
)]
38-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
37+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
38+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
3939
pub struct TrustThreshold {
4040
numerator: u64,
4141
denominator: u64,

crates/ibc/src/core/ics03_connection/connection.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use core::{
88
};
99

1010
use ibc_proto::protobuf::Protobuf;
11-
use serde::{Deserialize, Serialize};
1211

1312
use ibc_proto::ibc::core::connection::v1::{
1413
ConnectionEnd as RawConnectionEnd, Counterparty as RawCounterparty,
@@ -35,7 +34,8 @@ use crate::timestamp::ZERO_DURATION;
3534
feature = "borsh",
3635
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
3736
)]
38-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
37+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
38+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
3939
pub struct IdentifiedConnectionEnd {
4040
pub connection_id: ConnectionId,
4141
pub connection_end: ConnectionEnd,
@@ -100,7 +100,8 @@ impl From<IdentifiedConnectionEnd> for RawIdentifiedConnection {
100100
}
101101
}
102102

103-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
103+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
104+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
104105
pub struct ConnectionEnd {
105106
pub state: State,
106107
client_id: ClientId,
@@ -390,7 +391,8 @@ impl ConnectionEnd {
390391
feature = "borsh",
391392
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
392393
)]
393-
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
394+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
395+
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
394396
pub struct Counterparty {
395397
client_id: ClientId,
396398
pub connection_id: Option<ConnectionId>,
@@ -484,7 +486,8 @@ impl Counterparty {
484486
feature = "borsh",
485487
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
486488
)]
487-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
489+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
490+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
488491
pub enum State {
489492
Uninitialized = 0isize,
490493
Init = 1isize,

0 commit comments

Comments
 (0)