mirror of
https://github.com/pezkuwichain/pezframe-metadata.git
synced 2026-04-22 17:07:56 +00:00
add no_std support (#42)
* Metadata supporting scale-info can be decoded and serialized in no_std (#2) * Metadata supporting scale-info can be decoded and serialized in no_std (feature flag scale_info) * Changes from review: rename feature flag into full_derive * Changes from review: std implies full-derive * Changes from review: optimization Co-authored-by: echevrier <edith.chevrier@scs.ch> * split full_derive into decode and sered_codec features. (drop new Debug impls) * cargo fmt * rename serde_codec to serde_full * Prior to v14 everything was Debug. Are there any downsides? Unused debug impls will just get optimised away won't they? * rust fmt * Debug for the masses. Make it work for no_std * check all combos of features (if this plays well with ci then we should double up, doing the same again but target wasm32) * all wasm feature combos Co-authored-by: echevrier <84318241+echevrier@users.noreply.github.com> Co-authored-by: echevrier <edith.chevrier@scs.ch>
This commit is contained in:
+52
-41
@@ -15,12 +15,10 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "std")] {
|
||||
use codec::Decode;
|
||||
use serde::Serialize;
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "decode")]
|
||||
use codec::Decode;
|
||||
#[cfg(feature = "serde_full")]
|
||||
use serde::Serialize;
|
||||
|
||||
use super::RuntimeMetadataPrefixed;
|
||||
use codec::Encode;
|
||||
@@ -43,8 +41,9 @@ impl From<RuntimeMetadataLastVersion> for super::RuntimeMetadataPrefixed {
|
||||
}
|
||||
|
||||
/// The metadata of a runtime.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
|
||||
#[cfg_attr(feature = "decode", derive(Decode))]
|
||||
#[cfg_attr(feature = "serde_full", derive(Serialize))]
|
||||
pub struct RuntimeMetadataV14 {
|
||||
/// Type registry containing all types used in the metadata.
|
||||
pub types: PortableRegistry,
|
||||
@@ -77,10 +76,11 @@ impl RuntimeMetadataV14 {
|
||||
}
|
||||
|
||||
/// Metadata of the extrinsic used by the runtime.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
|
||||
#[cfg_attr(feature = "decode", derive(Decode))]
|
||||
#[cfg_attr(feature = "serde_full", derive(Serialize))]
|
||||
#[cfg_attr(
|
||||
feature = "std",
|
||||
feature = "serde_full",
|
||||
serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
|
||||
)]
|
||||
pub struct ExtrinsicMetadata<T: Form = MetaForm> {
|
||||
@@ -105,10 +105,11 @@ impl IntoPortable for ExtrinsicMetadata {
|
||||
}
|
||||
|
||||
/// Metadata of an extrinsic's signed extension.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
|
||||
#[cfg_attr(feature = "decode", derive(Decode))]
|
||||
#[cfg_attr(feature = "serde_full", derive(Serialize))]
|
||||
#[cfg_attr(
|
||||
feature = "std",
|
||||
feature = "serde_full",
|
||||
serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
|
||||
)]
|
||||
pub struct SignedExtensionMetadata<T: Form = MetaForm> {
|
||||
@@ -133,10 +134,11 @@ impl IntoPortable for SignedExtensionMetadata {
|
||||
}
|
||||
|
||||
/// All metadata about an runtime pallet.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
|
||||
#[cfg_attr(feature = "decode", derive(Decode))]
|
||||
#[cfg_attr(feature = "serde_full", derive(Serialize))]
|
||||
#[cfg_attr(
|
||||
feature = "std",
|
||||
feature = "serde_full",
|
||||
serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
|
||||
)]
|
||||
pub struct PalletMetadata<T: Form = MetaForm> {
|
||||
@@ -174,10 +176,11 @@ impl IntoPortable for PalletMetadata {
|
||||
}
|
||||
|
||||
/// All metadata of the pallet's storage.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
|
||||
#[cfg_attr(feature = "decode", derive(Decode))]
|
||||
#[cfg_attr(feature = "serde_full", derive(Serialize))]
|
||||
#[cfg_attr(
|
||||
feature = "std",
|
||||
feature = "serde_full",
|
||||
serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
|
||||
)]
|
||||
pub struct PalletStorageMetadata<T: Form = MetaForm> {
|
||||
@@ -199,10 +202,11 @@ impl IntoPortable for PalletStorageMetadata {
|
||||
}
|
||||
|
||||
/// Metadata about one storage entry.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
|
||||
#[cfg_attr(feature = "decode", derive(Decode))]
|
||||
#[cfg_attr(feature = "serde_full", derive(Serialize))]
|
||||
#[cfg_attr(
|
||||
feature = "std",
|
||||
feature = "serde_full",
|
||||
serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
|
||||
)]
|
||||
pub struct StorageEntryMetadata<T: Form = MetaForm> {
|
||||
@@ -237,8 +241,9 @@ impl IntoPortable for StorageEntryMetadata {
|
||||
///
|
||||
/// `Optional` means you should expect an `Option<T>`, with `None` returned if the key is not present.
|
||||
/// `Default` means you should expect a `T` with the default value of default if the key is not present.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
|
||||
#[cfg_attr(feature = "decode", derive(Decode))]
|
||||
#[cfg_attr(feature = "serde_full", derive(Serialize))]
|
||||
pub enum StorageEntryModifier {
|
||||
/// The storage entry returns an `Option<T>`, with `None` if the key is not present.
|
||||
Optional,
|
||||
@@ -247,8 +252,9 @@ pub enum StorageEntryModifier {
|
||||
}
|
||||
|
||||
/// Hasher used by storage maps
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
|
||||
#[cfg_attr(feature = "decode", derive(Decode))]
|
||||
#[cfg_attr(feature = "serde_full", derive(Serialize))]
|
||||
pub enum StorageHasher {
|
||||
/// 128-bit Blake2 hash.
|
||||
Blake2_128,
|
||||
@@ -267,10 +273,11 @@ pub enum StorageHasher {
|
||||
}
|
||||
|
||||
/// A type of storage value.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
|
||||
#[cfg_attr(feature = "decode", derive(Decode))]
|
||||
#[cfg_attr(feature = "serde_full", derive(Serialize))]
|
||||
#[cfg_attr(
|
||||
feature = "std",
|
||||
feature = "serde_full",
|
||||
serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
|
||||
)]
|
||||
pub enum StorageEntryType<T: Form = MetaForm> {
|
||||
@@ -307,10 +314,11 @@ impl IntoPortable for StorageEntryType {
|
||||
}
|
||||
|
||||
/// Metadata for all calls in a pallet
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
|
||||
#[cfg_attr(feature = "decode", derive(Decode))]
|
||||
#[cfg_attr(feature = "serde_full", derive(Serialize))]
|
||||
#[cfg_attr(
|
||||
feature = "std",
|
||||
feature = "serde_full",
|
||||
serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
|
||||
)]
|
||||
pub struct PalletCallMetadata<T: Form = MetaForm> {
|
||||
@@ -335,8 +343,9 @@ impl From<MetaType> for PalletCallMetadata {
|
||||
}
|
||||
|
||||
/// Metadata about the pallet Event type.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
|
||||
#[cfg_attr(feature = "decode", derive(Decode))]
|
||||
#[cfg_attr(feature = "serde_full", derive(Serialize))]
|
||||
pub struct PalletEventMetadata<T: Form = MetaForm> {
|
||||
/// The Event type.
|
||||
pub ty: T::Type,
|
||||
@@ -359,10 +368,11 @@ impl From<MetaType> for PalletEventMetadata {
|
||||
}
|
||||
|
||||
/// Metadata about one pallet constant.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
|
||||
#[cfg_attr(feature = "decode", derive(Decode))]
|
||||
#[cfg_attr(feature = "serde_full", derive(Serialize))]
|
||||
#[cfg_attr(
|
||||
feature = "std",
|
||||
feature = "serde_full",
|
||||
serde(bound(serialize = "T::Type: Serialize, T::String: Serialize"))
|
||||
)]
|
||||
pub struct PalletConstantMetadata<T: Form = MetaForm> {
|
||||
@@ -390,9 +400,10 @@ impl IntoPortable for PalletConstantMetadata {
|
||||
}
|
||||
|
||||
/// Metadata about a pallet error.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
|
||||
#[cfg_attr(feature = "std", serde(bound(serialize = "T::Type: Serialize")))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
|
||||
#[cfg_attr(feature = "decode", derive(Decode))]
|
||||
#[cfg_attr(feature = "serde_full", derive(Serialize))]
|
||||
#[cfg_attr(feature = "serde_full", serde(bound(serialize = "T::Type: Serialize")))]
|
||||
pub struct PalletErrorMetadata<T: Form = MetaForm> {
|
||||
/// The error type information.
|
||||
pub ty: T::Type,
|
||||
|
||||
Reference in New Issue
Block a user