From 7f8d46d97e53ae846b157edeeffe5c8d2e57a83e Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 8 Aug 2022 11:25:49 +0200 Subject: [PATCH] chore: fix serde bounds (#390) * reduce bounds for serialization and deserialization * update dependencies --- Cargo.lock | 12 ++++----- nodes/parachain/Cargo.toml | 4 +-- nodes/standalone/Cargo.toml | 4 +-- pallets/attestation/Cargo.toml | 4 +-- pallets/ctype/Cargo.toml | 4 +-- pallets/delegation/Cargo.toml | 4 +-- pallets/did/Cargo.toml | 2 +- pallets/pallet-inflation/Cargo.toml | 4 +-- pallets/parachain-staking/Cargo.toml | 2 +- rpc/did/runtime-api/src/did_details.rs | 22 ++++++----------- rpc/did/runtime-api/src/lib.rs | 34 ++++++-------------------- runtimes/common/Cargo.toml | 2 +- runtimes/peregrine/Cargo.toml | 2 +- runtimes/spiritnet/Cargo.toml | 2 +- runtimes/standalone/Cargo.toml | 2 +- support/Cargo.toml | 2 +- support/src/deposit.rs | 25 +++++++------------ 17 files changed, 48 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 04c37b67c..4ece0c0a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9706,18 +9706,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.137" +version = "1.0.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.137" +version = "1.0.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da" dependencies = [ "proc-macro2", "quote", @@ -9726,9 +9726,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" +checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" dependencies = [ "itoa 1.0.1", "ryu", diff --git a/nodes/parachain/Cargo.toml b/nodes/parachain/Cargo.toml index 2dd653be4..53d6fa0f7 100644 --- a/nodes/parachain/Cargo.toml +++ b/nodes/parachain/Cargo.toml @@ -32,8 +32,8 @@ hex-literal = "0.3.4" jsonrpsee = {version = "0.14.0", features = ["server"]} log = "0.4.17" parking_lot = "0.12.1" -serde = {version = "1.0.137", features = ["derive"]} -serde_json = "1.0.79" +serde = {version = "1.0.140", features = ["derive"]} +serde_json = "1.0.82" # Substrate dependencies frame-rpc-system = {package = "substrate-frame-rpc-system", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26"} diff --git a/nodes/standalone/Cargo.toml b/nodes/standalone/Cargo.toml index 148b776f2..ea55bec95 100644 --- a/nodes/standalone/Cargo.toml +++ b/nodes/standalone/Cargo.toml @@ -24,8 +24,8 @@ runtime-common = {path = "../../runtimes/common"} clap = {version = "3.2.10", features = ["derive"]} futures = "0.3.21" log = "0.4.17" -serde = {version = "1.0.137", features = ["derive"]} -serde_json = "1.0.79" +serde = {version = "1.0.140", features = ["derive"]} +serde_json = "1.0.82" # Substrate dependencies frame-system = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26"} diff --git a/pallets/attestation/Cargo.toml b/pallets/attestation/Cargo.toml index dad6132b7..d01aa8bda 100644 --- a/pallets/attestation/Cargo.toml +++ b/pallets/attestation/Cargo.toml @@ -17,7 +17,7 @@ ctype = {features = ["mock"], path = "../ctype"} kilt-support = {features = ["mock"], path = "../../support"} pallet-balances = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"} -serde = "1.0.137" +serde = "1.0.140" sp-core = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"} sp-io = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"} sp-keystore = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"} @@ -26,7 +26,7 @@ sp-keystore = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]} log = "0.4.17" scale-info = {version = "2.1.1", default-features = false, features = ["derive"]} -serde = {version = "1.0.137", optional = true} +serde = {version = "1.0.140", optional = true} # Internal dependencies ctype = {default-features = false, path = "../ctype"} diff --git a/pallets/ctype/Cargo.toml b/pallets/ctype/Cargo.toml index adc0d3ed4..13b4adc1f 100644 --- a/pallets/ctype/Cargo.toml +++ b/pallets/ctype/Cargo.toml @@ -15,7 +15,7 @@ substrate-wasm-builder = {git = "https://github.com/paritytech/substrate", branc [dev-dependencies] kilt-support = {features = ["mock"], path = "../../support"} pallet-balances = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"} -serde = "1.0.137" +serde = "1.0.140" sp-core = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"} sp-keystore = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"} @@ -23,7 +23,7 @@ sp-keystore = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]} log = "0.4.17" scale-info = {version = "2.1.1", default-features = false, features = ["derive"]} -serde = {version = "1.0.137", optional = true} +serde = {version = "1.0.140", optional = true} # Internal dependencies kilt-support = {default-features = false, path = "../../support"} diff --git a/pallets/delegation/Cargo.toml b/pallets/delegation/Cargo.toml index 173dd481c..e7b448e06 100644 --- a/pallets/delegation/Cargo.toml +++ b/pallets/delegation/Cargo.toml @@ -19,7 +19,7 @@ kilt-support = {features = ["mock"], path = "../../support"} # External dependencies env_logger = "0.9.0" -serde = "1.0.137" +serde = "1.0.140" # Substrate dependencies pallet-balances = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"} @@ -37,7 +37,7 @@ bitflags = {default-features = false, version = "1.3.2"} codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]} log = "0.4.17" scale-info = {version = "2.1.1", default-features = false, features = ["derive"]} -serde = {version = "1.0.137", optional = true} +serde = {version = "1.0.140", optional = true} # Substrate dependencies frame-benchmarking = {branch = "polkadot-v0.9.26", default-features = false, git = "https://github.com/paritytech/substrate", optional = true} diff --git a/pallets/did/Cargo.toml b/pallets/did/Cargo.toml index 018572b60..fce7b4eb5 100644 --- a/pallets/did/Cargo.toml +++ b/pallets/did/Cargo.toml @@ -14,7 +14,7 @@ substrate-wasm-builder = {git = "https://github.com/paritytech/substrate", branc [dev-dependencies] env_logger = "0.9.0" -serde = "1.0.137" +serde = "1.0.140" ctype = {features = ["mock"], path = "../ctype"} diff --git a/pallets/pallet-inflation/Cargo.toml b/pallets/pallet-inflation/Cargo.toml index 05bf2feb3..caa2f0629 100644 --- a/pallets/pallet-inflation/Cargo.toml +++ b/pallets/pallet-inflation/Cargo.toml @@ -10,7 +10,7 @@ version = "1.7.1" targets = ["x86_64-unknown-linux-gnu"] [dev-dependencies] -serde = "1.0.137" +serde = "1.0.140" pallet-balances = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"} sp-core = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/substrate"} @@ -19,7 +19,7 @@ sp-io = {branch = "polkadot-v0.9.26", git = "https://github.com/paritytech/subst [dependencies] codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]} scale-info = {version = "2.1.1", default-features = false, features = ["derive"]} -serde = {version = "1.0.137", optional = true} +serde = {version = "1.0.140", optional = true} # benchmarking frame-benchmarking = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false, optional = true} diff --git a/pallets/parachain-staking/Cargo.toml b/pallets/parachain-staking/Cargo.toml index dd223b026..995df8dca 100644 --- a/pallets/parachain-staking/Cargo.toml +++ b/pallets/parachain-staking/Cargo.toml @@ -16,7 +16,7 @@ sp-io = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0. log = "0.4.17" parity-scale-codec = {version = "3.1.5", default-features = false, features = ["derive"]} scale-info = {version = "2.1.1", default-features = false, features = ["derive"]} -serde = {version = "1.0.137", optional = true} +serde = {version = "1.0.140", optional = true} frame-support = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false} frame-system = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false} diff --git a/rpc/did/runtime-api/src/did_details.rs b/rpc/did/runtime-api/src/did_details.rs index e4e097265..8118bc6a2 100644 --- a/rpc/did/runtime-api/src/did_details.rs +++ b/rpc/did/runtime-api/src/did_details.rs @@ -28,21 +28,6 @@ use kilt_support::deposit::Deposit; #[derive(Encode, Decode, TypeInfo, Clone, Debug, PartialEq)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -#[cfg_attr( - feature = "std", - serde(bound( - serialize = " - Balance: std::fmt::Display, - AccountId: Serialize, - Key: Serialize, - BlockNumber: Serialize", - deserialize = " - Balance: std::str::FromStr, - AccountId: Deserialize<'de>, - Key: Deserialize<'de>, - BlockNumber: Deserialize<'de>" - )) -)] pub struct DidDetails { pub authentication_key: Key, pub key_agreement_keys: BTreeSet, @@ -50,6 +35,13 @@ pub struct DidDetails pub attestation_key: Option, pub public_keys: BTreeMap>, pub last_tx_counter: u64, + #[cfg_attr( + feature = "std", + serde(bound( + serialize = "Deposit: Serialize", + deserialize = "Deposit: Deserialize<'de>" + )) + )] pub deposit: Deposit, } diff --git a/rpc/did/runtime-api/src/lib.rs b/rpc/did/runtime-api/src/lib.rs index c3087743a..456c88913 100644 --- a/rpc/did/runtime-api/src/lib.rs +++ b/rpc/did/runtime-api/src/lib.rs @@ -32,33 +32,6 @@ pub use service_endpoint::*; #[derive(Encode, Decode, TypeInfo, PartialEq)] #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr( - feature = "std", - serde(bound( - serialize = " - Balance: std::fmt::Display, - AccountId: Serialize, - LinkableAccountId: Serialize, - Key: Serialize, - BlockNumber: Serialize, - DidIdentifier: Serialize, - Type: Serialize, - Url: Serialize, - Id: Serialize, - Web3Name: Serialize,", - deserialize = " - Balance: std::str::FromStr, - AccountId: Deserialize<'de>, - LinkableAccountId: Deserialize<'de>, - Key: Deserialize<'de>, - BlockNumber: Deserialize<'de>, - DidIdentifier: Deserialize<'de>, - Type: Deserialize<'de>, - Url: Deserialize<'de>, - Id: Deserialize<'de>, - Web3Name: Deserialize<'de>," - )) -)] pub struct DidLinkedInfo< DidIdentifier, AccountId, @@ -75,6 +48,13 @@ pub struct DidLinkedInfo< pub accounts: Vec, pub w3n: Option, pub service_endpoints: Vec>, + #[cfg_attr( + feature = "std", + serde(bound( + serialize = "DidDetails: Serialize", + deserialize = "DidDetails: Deserialize<'de>" + )) + )] pub details: DidDetails, } diff --git a/runtimes/common/Cargo.toml b/runtimes/common/Cargo.toml index bb016bd46..245fbaafe 100644 --- a/runtimes/common/Cargo.toml +++ b/runtimes/common/Cargo.toml @@ -11,7 +11,7 @@ sp-io = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0. codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]} log = "0.4.17" scale-info = {version = "2.1.1", default-features = false, features = ["derive"]} -serde = {version = "1.0.137", optional = true, features = ["derive"]} +serde = {version = "1.0.140", optional = true, features = ["derive"]} smallvec = "1.8.0" attestation = {default-features = false, path = "../../pallets/attestation"} diff --git a/runtimes/peregrine/Cargo.toml b/runtimes/peregrine/Cargo.toml index 1b91c6cc1..4d3e6485e 100644 --- a/runtimes/peregrine/Cargo.toml +++ b/runtimes/peregrine/Cargo.toml @@ -15,7 +15,7 @@ smallvec = "1.8.0" static_assertions = "1.1.0" hex-literal = {version = "0.3.4", optional = true} -serde = {version = "1.0.137", optional = true, features = ["derive"]} +serde = {version = "1.0.140", optional = true, features = ["derive"]} # RPC did-rpc-runtime-api = {path = "../../rpc/did/runtime-api", default-features = false} diff --git a/runtimes/spiritnet/Cargo.toml b/runtimes/spiritnet/Cargo.toml index 65ba4a0f2..b921fa8de 100644 --- a/runtimes/spiritnet/Cargo.toml +++ b/runtimes/spiritnet/Cargo.toml @@ -15,7 +15,7 @@ smallvec = "1.8.0" static_assertions = "1.1.0" hex-literal = {version = "0.3.4", optional = true} -serde = {version = "1.0.137", optional = true, features = ["derive"]} +serde = {version = "1.0.140", optional = true, features = ["derive"]} # RPC did-rpc-runtime-api = {path = "../../rpc/did/runtime-api", default-features = false} diff --git a/runtimes/standalone/Cargo.toml b/runtimes/standalone/Cargo.toml index 4be6c9c0c..d803a1ee9 100644 --- a/runtimes/standalone/Cargo.toml +++ b/runtimes/standalone/Cargo.toml @@ -14,7 +14,7 @@ log = "0.4.17" scale-info = {version = "2.1.1", default-features = false, features = ["derive"]} hex-literal = {version = "0.3.4", optional = true} -serde = {version = "1.0.137", optional = true, features = ["derive"]} +serde = {version = "1.0.140", optional = true, features = ["derive"]} # kilt functionality attestation = {default-features = false, path = "../../pallets/attestation"} diff --git a/support/Cargo.toml b/support/Cargo.toml index c1770eb42..1dda3d317 100644 --- a/support/Cargo.toml +++ b/support/Cargo.toml @@ -18,7 +18,7 @@ sp-runtime = {branch = "polkadot-v0.9.26", default-features = false, git = "http sp-std = {branch = "polkadot-v0.9.26", default-features = false, git = "https://github.com/paritytech/substrate"} [dev-dependencies] -serde_json = "1.0.79" +serde_json = "1.0.82" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/support/src/deposit.rs b/support/src/deposit.rs index 836898ab7..7735529e1 100644 --- a/support/src/deposit.rs +++ b/support/src/deposit.rs @@ -24,25 +24,18 @@ use serde::{Deserialize, Serialize}; /// An amount of balance reserved by the specified address. #[derive(Clone, Debug, Encode, Decode, PartialEq, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -#[cfg_attr( - feature = "std", - serde(bound( - serialize = " - Balance: std::fmt::Display, - Account: Serialize", - deserialize = " - Balance: std::str::FromStr, - Account: Deserialize<'de>" - )) -)] pub struct Deposit { pub owner: Account, + #[cfg_attr( + feature = "std", + serde(bound(serialize = "Balance: std::fmt::Display", deserialize = "Balance: std::str::FromStr")) + )] #[cfg_attr(feature = "std", serde(with = "serde_balance"))] pub amount: Balance, } // This code was copied from https://github.com/paritytech/substrate/blob/ded44948e2d5a398abcb4e342b0513cb690961bb/frame/transaction-payment/src/types.rs#L113 -// It is needed because u128 cannot be serialized by serde out of the box. +// It is needed because u128 cannot be serialized by serde_json out of the box. #[cfg(feature = "std")] mod serde_balance { use serde::{Deserialize, Deserializer, Serializer}; @@ -66,10 +59,10 @@ mod tests { fn should_serialize_and_deserialize_properly_with_string() { let deposit = Deposit { owner: 0_u8, - amount: 1_000_000_u128, + amount: 0_u128, }; - let json_str = r#"{"owner":0,"amount":"1000000"}"#; + let json_str = r#"{"owner":0,"amount":"0"}"#; assert_eq!(serde_json::to_string(&deposit).unwrap(), json_str); assert_eq!(serde_json::from_str::>(json_str).unwrap(), deposit); @@ -82,10 +75,10 @@ mod tests { fn should_serialize_and_deserialize_properly_large_value() { let deposit = Deposit { owner: 0_u8, - amount: 1_000_000_u128, + amount: u128::MAX, }; - let json_str = r#"{"owner":0,"amount":"1000000"}"#; + let json_str = r#"{"owner":0,"amount":"340282366920938463463374607431768211455"}"#; assert_eq!(serde_json::to_string(&deposit).unwrap(), json_str); assert_eq!(serde_json::from_str::>(json_str).unwrap(), deposit);