frame: support for serde added (#14261)

* frame: support for serde added

- enabled `serde` features in dependent crates, no gate feature introduced, linker should do the job and strip unused code.

- frame::staking: added impl of `serde::Serialize, serde::Deserialize` for `enum Forcing`

- primitives::runtime: impl_opaque_keys macro provides `Serialize/Deserialize` impl if `serde` is enabled

- primitives::staking: added impl of `serde::Serialize`, `serde::Deserialize` for `enum StakerStatus`

* frame::support: serde for pallets' GenesisConfig enabled in no-std

* Cargo.lock updated

* Update primitives/staking/Cargo.toml

Co-authored-by: Bastian Köcher <git@kchr.de>

* fix

* Cargo.lock update + missed serde/std in beefy

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Michal Kucharczyk
2023-06-01 16:35:34 +01:00
committed by GitHub
parent 372708d7a2
commit dc7161276d
16 changed files with 70 additions and 71 deletions
+2 -2
View File
@@ -13,7 +13,7 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
serde = { version = "1.0.163", optional = true, features = ["derive"] }
serde = { version = "1.0.163", default-features = false, features = ["alloc", "derive"] }
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
frame-metadata = { version = "15.1.0", default-features = false, features = ["v14", "v15-unstable"] }
@@ -54,7 +54,7 @@ std = [
"sp-core/std",
"k256/std",
"once_cell",
"serde",
"serde/std",
"sp-api/std",
"sp-io/std",
"codec/std",
@@ -95,23 +95,13 @@ pub fn expand_genesis_config(def: &mut Def) -> proc_macro2::TokenStream {
));
}
attrs.push(syn::parse_quote!(
#[cfg_attr(feature = "std", derive(#frame_support::Serialize, #frame_support::Deserialize))]
#[derive(#frame_support::Serialize, #frame_support::Deserialize)]
));
attrs.push(
syn::parse_quote!( #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] ),
);
attrs.push(
syn::parse_quote!( #[cfg_attr(feature = "std", serde(deny_unknown_fields))] ),
);
attrs.push(
syn::parse_quote!( #[cfg_attr(feature = "std", serde(bound(serialize = "")))] ),
);
attrs.push(
syn::parse_quote!( #[cfg_attr(feature = "std", serde(bound(deserialize = "")))] ),
);
attrs.push(
syn::parse_quote!( #[cfg_attr(feature = "std", serde(crate = #serde_crate))] ),
);
attrs.push(syn::parse_quote!( #[serde(rename_all = "camelCase")] ));
attrs.push(syn::parse_quote!( #[serde(deny_unknown_fields)] ));
attrs.push(syn::parse_quote!( #[serde(bound(serialize = ""))] ));
attrs.push(syn::parse_quote!( #[serde(bound(deserialize = ""))] ));
attrs.push(syn::parse_quote!( #[serde(crate = #serde_crate)] ));
},
_ => unreachable!("Checked by genesis_config parser"),
}
-2
View File
@@ -48,7 +48,6 @@ pub use once_cell;
pub use paste;
#[doc(hidden)]
pub use scale_info;
#[cfg(feature = "std")]
pub use serde;
pub use sp_api::metadata_ir;
pub use sp_core::{OpaqueMetadata, Void};
@@ -821,7 +820,6 @@ macro_rules! assert_error_encoded_size {
} => {};
}
#[cfg(feature = "std")]
#[doc(hidden)]
pub use serde::{Deserialize, Serialize};