diff --git a/Cargo.lock b/Cargo.lock index 9f2bc335d0..2a705cb3e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1991,7 +1991,6 @@ dependencies = [ "pallet-balances", "parity-scale-codec", "scale-info", - "serde", "sp-core", "sp-io", "sp-keystore", @@ -2008,7 +2007,6 @@ dependencies = [ "kilt-support", "parity-scale-codec", "scale-info", - "serde", "sp-api", "sp-std", ] @@ -3681,8 +3679,6 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "serde", - "serde_json", "sp-core", "sp-runtime", "sp-std", @@ -5484,7 +5480,6 @@ dependencies = [ "frame-support", "frame-system", "hex", - "impl-serde", "kilt-support", "libsecp256k1", "log", @@ -5492,7 +5487,6 @@ dependencies = [ "parity-scale-codec", "rand 0.8.5", "scale-info", - "serde", "sha3 0.10.2", "sp-core", "sp-io", diff --git a/pallets/did/Cargo.toml b/pallets/did/Cargo.toml index b2d51f1d56..d8297f18b8 100644 --- a/pallets/did/Cargo.toml +++ b/pallets/did/Cargo.toml @@ -14,7 +14,6 @@ substrate-wasm-builder = {git = "https://github.com/paritytech/substrate", branc [dev-dependencies] env_logger = "0.9.0" -serde = "1.0.144" ctype = {features = ["mock"], path = "../ctype"} @@ -27,7 +26,6 @@ sp-keystore = {branch = "polkadot-v0.9.29", git = "https://github.com/paritytech ctype = {path = "../ctype", optional = true} kilt-support = {default-features = false, path = "../../support"} log = "0.4.17" -serde = {version = "1.0.142", optional = true, features = ["derive"]} codec = {package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"]} frame-support = {branch = "polkadot-v0.9.29", default-features = false, git = "https://github.com/paritytech/substrate"} @@ -67,7 +65,6 @@ std = [ "log/std", "pallet-balances/std", "scale-info/std", - "serde", "sp-core/std", "sp-io/std", "sp-keystore/std", diff --git a/pallets/did/src/did_details.rs b/pallets/did/src/did_details.rs index e3203c54d5..bf0ed121c7 100644 --- a/pallets/did/src/did_details.rs +++ b/pallets/did/src/did_details.rs @@ -38,7 +38,6 @@ use crate::{ /// Types of verification keys a DID can control. #[derive(Clone, Decode, RuntimeDebug, Encode, Eq, Ord, PartialEq, PartialOrd, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] pub enum DidVerificationKey { /// An Ed25519 public key. Ed25519(ed25519::Public), @@ -90,7 +89,6 @@ impl From for DidVerificationKey { /// Types of encryption keys a DID can control. #[derive(Clone, Copy, Decode, RuntimeDebug, Encode, Eq, Ord, PartialEq, PartialOrd, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] pub enum DidEncryptionKey { /// An X25519 public key. X25519([u8; 32]), @@ -98,7 +96,6 @@ pub enum DidEncryptionKey { /// A general public key under the control of the DID. #[derive(Clone, Decode, RuntimeDebug, Encode, Eq, Ord, PartialEq, PartialOrd, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] pub enum DidPublicKey { /// A verification key, used to generate and verify signatures. PublicVerificationKey(DidVerificationKey), @@ -237,7 +234,6 @@ impl> DidVerifiableIdentifier for I { #[derive(Clone, RuntimeDebug, Decode, Encode, PartialEq, Ord, PartialOrd, Eq, TypeInfo, MaxEncodedLen)] #[scale_info(skip_type_params(T))] #[codec(mel_bound())] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] pub struct DidPublicKeyDetails { /// A public key the DID controls. pub key: DidPublicKey, diff --git a/pallets/pallet-did-lookup/Cargo.toml b/pallets/pallet-did-lookup/Cargo.toml index cc748e04fd..93ee1efde7 100644 --- a/pallets/pallet-did-lookup/Cargo.toml +++ b/pallets/pallet-did-lookup/Cargo.toml @@ -40,10 +40,6 @@ sp-std = {branch = "polkadot-v0.9.29", default-features = false, git = "https:// # benchmarking frame-benchmarking = {branch = "polkadot-v0.9.29", optional = true, default-features = false, git = "https://github.com/paritytech/substrate"} -# optional dependencies -impl-serde = {version = "0.3.1", optional = true} -serde = {version = "1.0.101", optional = true} - [features] default = ["std"] @@ -59,10 +55,8 @@ std = [ "frame-benchmarking/std", "frame-support/std", "frame-system/std", - "impl-serde", "log/std", "scale-info/std", - "serde", "sha3/std", "sp-core/std", "sp-io/std", diff --git a/pallets/pallet-did-lookup/src/account.rs b/pallets/pallet-did-lookup/src/account.rs index 9ab02692b5..b6eb29a938 100644 --- a/pallets/pallet-did-lookup/src/account.rs +++ b/pallets/pallet-did-lookup/src/account.rs @@ -29,9 +29,6 @@ use scale_info::TypeInfo; use sha3::{Digest, Keccak256}; use sp_core::{ecdsa, H160, H256}; -#[cfg(feature = "std")] -pub use serde::{de::DeserializeOwned, Deserialize, Serialize}; - /// The AccountId20 type. /// It is a 20-byte Ethereum address. #[derive( @@ -39,9 +36,6 @@ pub use serde::{de::DeserializeOwned, Deserialize, Serialize}; )] pub struct AccountId20(pub [u8; 20]); -#[cfg(feature = "std")] -impl_serde::impl_fixed_hash_serde!(AccountId20, 20); - #[cfg(feature = "std")] impl std::fmt::Display for AccountId20 { //TODO This is a pretty quck-n-dirty implementation. Perhaps we should add @@ -88,7 +82,6 @@ impl std::str::FromStr for AccountId20 { /// Public key for an Ethereum / Moonbeam compatible account #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct EthereumSigner([u8; 20]); impl sp_runtime::traits::IdentifyAccount for EthereumSigner { @@ -130,7 +123,6 @@ impl std::fmt::Display for EthereumSigner { } } -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] #[derive(Eq, PartialEq, Clone, Encode, Decode, MaxEncodedLen, RuntimeDebug, TypeInfo)] pub struct EthereumSignature(ecdsa::Signature); diff --git a/pallets/pallet-did-lookup/src/linkable_account.rs b/pallets/pallet-did-lookup/src/linkable_account.rs index c69e5f6d2d..927ebffa8a 100644 --- a/pallets/pallet-did-lookup/src/linkable_account.rs +++ b/pallets/pallet-did-lookup/src/linkable_account.rs @@ -22,8 +22,6 @@ use sp_runtime::AccountId32; use crate::account::AccountId20; -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, MaxEncodedLen, TypeInfo)] pub enum LinkableAccountId { AccountId20(AccountId20), diff --git a/pallets/parachain-staking/Cargo.toml b/pallets/parachain-staking/Cargo.toml index 9239069cbf..d93e7d581d 100644 --- a/pallets/parachain-staking/Cargo.toml +++ b/pallets/parachain-staking/Cargo.toml @@ -15,7 +15,7 @@ sp-io = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0. [dependencies] 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"]} +scale-info = {version = "2.1.1", default-features = false, features = ["derive", "serde"]} serde = {version = "1.0.144", optional = true} frame-support = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false} diff --git a/rpc/did/runtime-api/Cargo.toml b/rpc/did/runtime-api/Cargo.toml index dd2fb5886a..6740a7e149 100644 --- a/rpc/did/runtime-api/Cargo.toml +++ b/rpc/did/runtime-api/Cargo.toml @@ -8,7 +8,6 @@ version = "1.8.0" [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.142", optional = true, features = ["derive"] } sp-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29"} sp-std = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29"} @@ -19,7 +18,6 @@ kilt-support = {path = "../../../support", default-features = false} [features] default = ["std"] std = [ - "serde", "codec/std", "sp-api/std", "sp-std/std", diff --git a/rpc/did/runtime-api/src/did_details.rs b/rpc/did/runtime-api/src/did_details.rs index 00d7319384..985e28b090 100644 --- a/rpc/did/runtime-api/src/did_details.rs +++ b/rpc/did/runtime-api/src/did_details.rs @@ -16,9 +16,6 @@ // If you feel like getting in touch with us, you can do so at info@botlabs.org -#[cfg(feature = "std")] -use serde::{Deserialize, Serialize}; - use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet}; @@ -26,8 +23,7 @@ use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet}; use did::{did_details::DidPublicKeyDetails, AccountIdOf, BalanceOf, BlockNumberOf, KeyIdOf}; use kilt_support::deposit::Deposit; -#[derive(Encode, Decode, TypeInfo, Clone, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +#[derive(Encode, Decode, TypeInfo, Clone, Debug, Eq, PartialEq, MaxEncodedLen)] pub struct DidDetails { pub authentication_key: Key, pub key_agreement_keys: BTreeSet, @@ -35,13 +31,6 @@ 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 172c127cf6..fb216eb58d 100644 --- a/rpc/did/runtime-api/src/lib.rs +++ b/rpc/did/runtime-api/src/lib.rs @@ -17,9 +17,6 @@ // If you feel like getting in touch with us, you can do so at info@botlabs.org #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -use serde::{Deserialize, Serialize}; - use codec::{Codec, Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_std::vec::Vec; @@ -31,34 +28,6 @@ pub use did_details::*; pub use service_endpoint::*; #[derive(Encode, Decode, TypeInfo, Eq, 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,13 +44,6 @@ 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/rpc/did/runtime-api/src/service_endpoint.rs b/rpc/did/runtime-api/src/service_endpoint.rs index 0653229b06..9f2ab6ef2b 100644 --- a/rpc/did/runtime-api/src/service_endpoint.rs +++ b/rpc/did/runtime-api/src/service_endpoint.rs @@ -20,7 +20,6 @@ use scale_info::TypeInfo; use sp_std::vec::Vec; #[derive(Encode, Decode, TypeInfo, Eq, PartialEq)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] pub struct ServiceEndpoint { pub id: Id, pub service_types: Vec, diff --git a/support/Cargo.toml b/support/Cargo.toml index bf935fae23..ae2d5e38cf 100644 --- a/support/Cargo.toml +++ b/support/Cargo.toml @@ -10,7 +10,6 @@ version = "1.8.0" # External 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.142", optional = true, features = ["derive"]} frame-support = {branch = "polkadot-v0.9.29", default-features = false, git = "https://github.com/paritytech/substrate"} frame-system = {branch = "polkadot-v0.9.29", default-features = false, git = "https://github.com/paritytech/substrate"} @@ -18,9 +17,6 @@ sp-core = {branch = "polkadot-v0.9.29", default-features = false, git = "https:/ sp-runtime = {branch = "polkadot-v0.9.29", default-features = false, git = "https://github.com/paritytech/substrate"} sp-std = {branch = "polkadot-v0.9.29", default-features = false, git = "https://github.com/paritytech/substrate"} -[dev-dependencies] -serde_json = "1.0.83" - [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -37,7 +33,6 @@ std = [ "frame-support/std", "frame-system/std", "scale-info/std", - "serde", "sp-core/std", "sp-runtime/std", "sp-std/std", diff --git a/support/src/deposit.rs b/support/src/deposit.rs index 5d2b51529e..f02288ed6c 100644 --- a/support/src/deposit.rs +++ b/support/src/deposit.rs @@ -23,14 +23,8 @@ use sp_runtime::{traits::Zero, DispatchError}; /// An amount of balance reserved by the specified address. #[derive(Clone, Debug, Encode, Decode, Eq, PartialEq, Ord, PartialOrd, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] 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, } @@ -49,57 +43,3 @@ pub fn free_deposit>(deposit: &De let err_amount = Currency::unreserve(&deposit.owner, deposit.amount); debug_assert!(err_amount.is_zero()); } - -// 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_json out of the box. -#[cfg(feature = "std")] -mod serde_balance { - use serde::{Deserialize, Deserializer, Serializer}; - - pub fn serialize(t: &T, serializer: S) -> Result { - serializer.serialize_str(&t.to_string()) - } - - pub fn deserialize<'de, D: Deserializer<'de>, T: std::str::FromStr>(deserializer: D) -> Result { - let s = String::deserialize(deserializer)?; - s.parse::() - .map_err(|_| serde::de::Error::custom("Parse from string failed")) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn should_serialize_and_deserialize_properly_with_string() { - let deposit = Deposit { - owner: 0_u8, - amount: 0_u128, - }; - - 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); - - // should not panic - serde_json::to_value(&deposit).unwrap(); - } - - #[test] - fn should_serialize_and_deserialize_properly_large_value() { - let deposit = Deposit { - owner: 0_u8, - amount: u128::MAX, - }; - - 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); - - // should not panic - serde_json::to_value(&deposit).unwrap(); - } -}