From 63d2ff0c365f9a653de8acbc8a8ae9dd8beba2e8 Mon Sep 17 00:00:00 2001 From: Liu-Cheng Xu Date: Mon, 8 Nov 2021 07:29:51 +0800 Subject: [PATCH] Add serde support for `Slot` type (#10204) Add serde support for the `Slot` type as we'd like to use it directly in our RPC. --- substrate/Cargo.lock | 1 + substrate/primitives/consensus/slots/Cargo.toml | 2 ++ substrate/primitives/consensus/slots/src/lib.rs | 1 + 3 files changed, 4 insertions(+) diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index eeb1012b1d..63a2d26db3 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -9325,6 +9325,7 @@ version = "0.10.0-dev" dependencies = [ "parity-scale-codec", "scale-info", + "serde", "sp-arithmetic", "sp-runtime", ] diff --git a/substrate/primitives/consensus/slots/Cargo.toml b/substrate/primitives/consensus/slots/Cargo.toml index ad83835e02..9177157bd5 100644 --- a/substrate/primitives/consensus/slots/Cargo.toml +++ b/substrate/primitives/consensus/slots/Cargo.toml @@ -15,6 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false, features = ["derive", "max-encoded-len"] } scale-info = { version = "1.0", default-features = false, features = ["derive"] } +serde = { version = "1.0", features = ["derive"], optional = true } sp-runtime = { version = "4.0.0-dev", default-features = false, path = "../../runtime" } sp-arithmetic = { version = "4.0.0-dev", default-features = false, path = "../../arithmetic" } @@ -23,6 +24,7 @@ default = ["std"] std = [ "codec/std", "scale-info/std", + "serde", "sp-runtime/std", "sp-arithmetic/std", ] diff --git a/substrate/primitives/consensus/slots/src/lib.rs b/substrate/primitives/consensus/slots/src/lib.rs index 89b57dca83..72b3c95068 100644 --- a/substrate/primitives/consensus/slots/src/lib.rs +++ b/substrate/primitives/consensus/slots/src/lib.rs @@ -24,6 +24,7 @@ use scale_info::TypeInfo; /// Unit type wrapper that represents a slot. #[derive(Debug, Encode, MaxEncodedLen, Decode, Eq, Clone, Copy, Default, Ord, TypeInfo)] +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] pub struct Slot(u64); impl core::ops::Deref for Slot {