mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 18:41:05 +00:00
frame: Enable GenesisConfig in no_std (#14108)
* frame: Default for GenesisConfig in no_std
`Default` for `GenesisConfig` will be required for no_std in no native
runtime world. It must be possible to instantiate default GenesisConfig
for pallets and runtime.
* ".git/.scripts/commands/fmt/fmt.sh"
* hash69 in no_std reverted
* derive(DefaultNoBound) for GenesisConfig used when possible
* treasury: derive(Default)
* Cargo.lock update
* genesis_config: compiler error improved
When std feature is not enabled for pallet, the GenesisConfig will be
defined, but serde::{Serialize,Deserialize} traits will not be
implemented.
The compiler error indicates the reason of latter errors.
This is temporary and serde traits will be enabled with together with
`serde` support in frame.
---------
Co-authored-by: command-bot <>
This commit is contained in:
committed by
GitHub
parent
5100a0376e
commit
613420a035
@@ -94,15 +94,24 @@ pub fn expand_genesis_config(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
"]
|
||||
));
|
||||
}
|
||||
attrs.push(syn::parse_quote!( #[cfg(feature = "std")] ));
|
||||
attrs.push(syn::parse_quote!(
|
||||
#[derive(#frame_support::Serialize, #frame_support::Deserialize)]
|
||||
#[cfg_attr(feature = "std", derive(#frame_support::Serialize, #frame_support::Deserialize))]
|
||||
));
|
||||
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)] ));
|
||||
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))] ),
|
||||
);
|
||||
},
|
||||
_ => unreachable!("Checked by genesis_config parser"),
|
||||
}
|
||||
@@ -126,7 +135,7 @@ pub fn expand_genesis_config(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
stringify!($pallet_name),
|
||||
"` does not have the std feature enabled, this will cause the `",
|
||||
$pallet_path,
|
||||
"::GenesisConfig` type to be undefined."
|
||||
"::GenesisConfig` type to not implement serde traits."
|
||||
));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ pub mod pallet {
|
||||
pub type Value<T> = StorageValue<_, u32>;
|
||||
|
||||
#[pallet::genesis_config]
|
||||
#[cfg_attr(feature = "std", derive(Default))]
|
||||
#[derive(Default)]
|
||||
pub struct GenesisConfig {}
|
||||
|
||||
#[pallet::genesis_build]
|
||||
|
||||
+104
-5
@@ -1,4 +1,4 @@
|
||||
error: `Pallet` does not have the std feature enabled, this will cause the `test_pallet::GenesisConfig` type to be undefined.
|
||||
error: `Pallet` does not have the std feature enabled, this will cause the `test_pallet::GenesisConfig` type to not implement serde traits.
|
||||
--> tests/construct_runtime_ui/no_std_genesis_config.rs:40:1
|
||||
|
|
||||
40 | / construct_runtime! {
|
||||
@@ -12,7 +12,7 @@ error: `Pallet` does not have the std feature enabled, this will cause the `test
|
||||
|
|
||||
= note: this error originates in the macro `test_pallet::__substrate_genesis_config_check::is_std_enabled_for_genesis` which comes from the expansion of the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0412]: cannot find type `GenesisConfig` in crate `test_pallet`
|
||||
error[E0277]: the trait bound `frame_support_test_pallet::GenesisConfig: Serialize` is not satisfied
|
||||
--> tests/construct_runtime_ui/no_std_genesis_config.rs:40:1
|
||||
|
|
||||
40 | / construct_runtime! {
|
||||
@@ -22,10 +22,109 @@ error[E0412]: cannot find type `GenesisConfig` in crate `test_pallet`
|
||||
... |
|
||||
48 | | }
|
||||
49 | | }
|
||||
| |_^ not found in `test_pallet`
|
||||
| |_^ the trait `Serialize` is not implemented for `frame_support_test_pallet::GenesisConfig`
|
||||
|
|
||||
= help: the following other types implement trait `Serialize`:
|
||||
&'a T
|
||||
&'a mut T
|
||||
()
|
||||
(T0, T1)
|
||||
(T0, T1, T2)
|
||||
(T0, T1, T2, T3)
|
||||
(T0, T1, T2, T3, T4)
|
||||
(T0, T1, T2, T3, T4, T5)
|
||||
and $N others
|
||||
note: required by a bound in `hidden_include::serde::ser::SerializeStruct::serialize_field`
|
||||
--> $CARGO/serde-1.0.162/src/ser/mod.rs
|
||||
|
|
||||
| T: Serialize;
|
||||
| ^^^^^^^^^ required by this bound in `SerializeStruct::serialize_field`
|
||||
= note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: consider importing this struct
|
||||
|
||||
error[E0277]: the trait bound `frame_support_test_pallet::GenesisConfig: Deserialize<'_>` is not satisfied
|
||||
--> tests/construct_runtime_ui/no_std_genesis_config.rs:47:3
|
||||
|
|
||||
1 | use frame_system::GenesisConfig;
|
||||
47 | Pallet: test_pallet::{Pallet, Config},
|
||||
| ^^^^^^ the trait `Deserialize<'_>` is not implemented for `frame_support_test_pallet::GenesisConfig`
|
||||
|
|
||||
= help: the following other types implement trait `Deserialize<'de>`:
|
||||
<&'a [u8] as Deserialize<'de>>
|
||||
<&'a std::path::Path as Deserialize<'de>>
|
||||
<&'a str as Deserialize<'de>>
|
||||
<() as Deserialize<'de>>
|
||||
<(T0, T1) as Deserialize<'de>>
|
||||
<(T0, T1, T2) as Deserialize<'de>>
|
||||
<(T0, T1, T2, T3) as Deserialize<'de>>
|
||||
<(T0, T1, T2, T3, T4) as Deserialize<'de>>
|
||||
and $N others
|
||||
note: required by a bound in `next_element`
|
||||
--> $CARGO/serde-1.0.162/src/de/mod.rs
|
||||
|
|
||||
| T: Deserialize<'de>,
|
||||
| ^^^^^^^^^^^^^^^^ required by this bound in `SeqAccess::next_element`
|
||||
|
||||
error[E0277]: the trait bound `frame_support_test_pallet::GenesisConfig: Deserialize<'_>` is not satisfied
|
||||
--> tests/construct_runtime_ui/no_std_genesis_config.rs:47:3
|
||||
|
|
||||
47 | Pallet: test_pallet::{Pallet, Config},
|
||||
| ^^^^^^ the trait `Deserialize<'_>` is not implemented for `frame_support_test_pallet::GenesisConfig`
|
||||
|
|
||||
= help: the following other types implement trait `Deserialize<'de>`:
|
||||
<&'a [u8] as Deserialize<'de>>
|
||||
<&'a std::path::Path as Deserialize<'de>>
|
||||
<&'a str as Deserialize<'de>>
|
||||
<() as Deserialize<'de>>
|
||||
<(T0, T1) as Deserialize<'de>>
|
||||
<(T0, T1, T2) as Deserialize<'de>>
|
||||
<(T0, T1, T2, T3) as Deserialize<'de>>
|
||||
<(T0, T1, T2, T3, T4) as Deserialize<'de>>
|
||||
and $N others
|
||||
note: required by a bound in `next_value`
|
||||
--> $CARGO/serde-1.0.162/src/de/mod.rs
|
||||
|
|
||||
| V: Deserialize<'de>,
|
||||
| ^^^^^^^^^^^^^^^^ required by this bound in `MapAccess::next_value`
|
||||
|
||||
error[E0277]: the trait bound `frame_support_test_pallet::GenesisConfig: Deserialize<'_>` is not satisfied
|
||||
--> tests/construct_runtime_ui/no_std_genesis_config.rs:40:1
|
||||
|
|
||||
40 | / construct_runtime! {
|
||||
41 | | pub struct Runtime where
|
||||
42 | | Block = Block,
|
||||
43 | | NodeBlock = Block,
|
||||
... |
|
||||
48 | | }
|
||||
49 | | }
|
||||
| |_^ the trait `Deserialize<'_>` is not implemented for `frame_support_test_pallet::GenesisConfig`
|
||||
|
|
||||
= help: the following other types implement trait `Deserialize<'de>`:
|
||||
<&'a [u8] as Deserialize<'de>>
|
||||
<&'a std::path::Path as Deserialize<'de>>
|
||||
<&'a str as Deserialize<'de>>
|
||||
<() as Deserialize<'de>>
|
||||
<(T0, T1) as Deserialize<'de>>
|
||||
<(T0, T1, T2) as Deserialize<'de>>
|
||||
<(T0, T1, T2, T3) as Deserialize<'de>>
|
||||
<(T0, T1, T2, T3, T4) as Deserialize<'de>>
|
||||
and $N others
|
||||
note: required by a bound in `hidden_include::serde::__private::de::missing_field`
|
||||
--> $CARGO/serde-1.0.162/src/private/de.rs
|
||||
|
|
||||
| V: Deserialize<'de>,
|
||||
| ^^^^^^^^^^^^^^^^ required by this bound in `missing_field`
|
||||
= note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0277]: the trait bound `frame_support_test_pallet::GenesisConfig: BuildModuleGenesisStorage<Runtime, ()>` is not satisfied
|
||||
--> tests/construct_runtime_ui/no_std_genesis_config.rs:40:1
|
||||
|
|
||||
40 | / construct_runtime! {
|
||||
41 | | pub struct Runtime where
|
||||
42 | | Block = Block,
|
||||
43 | | NodeBlock = Block,
|
||||
... |
|
||||
48 | | }
|
||||
49 | | }
|
||||
| |_^ the trait `BuildModuleGenesisStorage<Runtime, ()>` is not implemented for `frame_support_test_pallet::GenesisConfig`
|
||||
|
|
||||
= help: the trait `BuildModuleGenesisStorage<T, ()>` is implemented for `frame_system::GenesisConfig`
|
||||
= note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
+3
-1
@@ -28,7 +28,9 @@ error[E0412]: cannot find type `GenesisConfig` in module `pallet`
|
||||
| |_^ not found in `pallet`
|
||||
|
|
||||
= note: this error originates in the macro `construct_runtime` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: consider importing this struct
|
||||
help: consider importing one of these items
|
||||
|
|
||||
1 | use frame_system::GenesisConfig;
|
||||
|
|
||||
1 | use test_pallet::GenesisConfig;
|
||||
|
|
||||
|
||||
Reference in New Issue
Block a user