Simplify feature-flag and use common types (#62)

* Add common types between v14 and v15

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Use common types

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Guard common types by feature flags

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Use feature flags on the imports

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Revert "Use feature flags on the imports"

This reverts commit 5988d8a221c4f8bb8b9dd095fc703d1e5e99d7ef.

Revert "Guard common types by feature flags"

This reverts commit f12cdc650765da455bf29f1eca0205662a039267.

Revert "Use common types"

This reverts commit a012d1ce2b0ff83039a8ecd7097d66fa96d62b1a.

Revert "Add common types between v14 and v15"

This reverts commit 718c9d39e9c53c5ba51ed249595f8263b8604605.

* Adjust feature flags

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Use v14 types for v15

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Rename `module_error_ty` to be consisten with `event`/`call`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Mark V15 as unstable

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust feature flags

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2023-06-27 16:11:07 +03:00
committed by GitHub
parent d6d22767e3
commit fc36bec2cb
4 changed files with 48 additions and 307 deletions
+2 -2
View File
@@ -137,7 +137,7 @@ jobs:
version: 0.5
- name: Checking wasm32 (v14)
run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --features v14 --skip legacy,v8,v9,v10,v11,v12,v13 --depth 4 --target wasm32-unknown-unknown
run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --features current --skip legacy --depth 4 --target wasm32-unknown-unknown
- name: Checking wasm32 (all features)
run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --skip decode,serde_full --depth 4 --target wasm32-unknown-unknown
@@ -167,7 +167,7 @@ jobs:
version: 0.5
- name: Checking v14 feature combinations (native)
run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --features v14 --skip legacy,v8,v9,v10,v11,v12,v13 --depth 4
run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --features current --skip legacy --depth 4
- name: Checking feature combinations excluding decode/serde_full (native)
run: cargo hack check --manifest-path ./frame-metadata/Cargo.toml --feature-powerset --no-dev-deps --skip decode,serde_full --depth 4
+11 -10
View File
@@ -19,16 +19,16 @@ scale-info = { version = "2.0.0", default-features = false, optional = true, fea
serde = { version = "1.0.101", default-features = false, optional = true, features = ["derive"] }
[features]
default = ["std", "v14"]
v8 = []
v9 = []
v10 = []
v11 = []
v12 = []
v13 = []
legacy = ["v13", "v12", "v11", "v10", "v9", "v8"]
v14 = ["scale-info"]
v15-unstable = ["scale-info"]
default = ["std", "current"]
# Feature flag for pre-V14 versions.
legacy = []
# The current stable metadata versions.
current = ["scale-info"]
# Unstable next metadata version.
unstable = ["current"]
# Serde support without relying on std features
serde_full = [
@@ -36,6 +36,7 @@ serde_full = [
"serde",
"serde/alloc",
]
# Scale decode support without relying on std features
decode = ["scale-info/decode"]
+27 -43
View File
@@ -19,15 +19,7 @@
#![warn(missing_docs)]
#[cfg(all(
any(feature = "decode", feature = "serde_full"),
any(
feature = "v13",
feature = "v12",
feature = "v11",
feature = "v10",
feature = "v9",
feature = "v8",
feature = "legacy"
),
feature = "legacy",
not(feature = "std")
))]
compile_error!("decode and serde_full features prior to v14 require std");
@@ -48,53 +40,45 @@ cfg_if::cfg_if! {
use codec::{Encode, Output};
/// A type that decodes to a different type than it encodes.
#[cfg(any(
feature = "v13",
feature = "v12",
feature = "v11",
feature = "v10",
feature = "v9",
feature = "v8",
feature = "legacy"
))]
#[cfg(feature = "legacy")]
pub mod decode_different;
/// Metadata v8
#[cfg(feature = "v8")]
#[cfg(feature = "legacy")]
pub mod v8;
/// Metadata v9
#[cfg(feature = "v9")]
#[cfg(feature = "legacy")]
pub mod v9;
/// Metadata v10
#[cfg(feature = "v10")]
#[cfg(feature = "legacy")]
pub mod v10;
/// Metadata v11
#[cfg(feature = "v11")]
#[cfg(feature = "legacy")]
pub mod v11;
/// Metadata v12
#[cfg(feature = "v12")]
#[cfg(feature = "legacy")]
pub mod v12;
/// Metadata v13
#[cfg(feature = "v13")]
#[cfg(feature = "legacy")]
pub mod v13;
/// Metadata v14
#[cfg(feature = "v14")]
#[cfg(feature = "current")]
pub mod v14;
/// Metadata v15
#[cfg(feature = "v15-unstable")]
#[cfg(feature = "unstable")]
pub mod v15;
// Reexport all the types from the latest version.
//
// When a new version becomes available, update this.
#[cfg(feature = "v14")]
#[cfg(feature = "current")]
pub use self::v14::*;
/// Metadata prefix.
@@ -136,52 +120,52 @@ pub enum RuntimeMetadata {
/// Version 7 for runtime metadata. No longer used.
V7(RuntimeMetadataDeprecated),
/// Version 8 for runtime metadata.
#[cfg(any(feature = "v8", feature = "legacy"))]
#[cfg(feature = "legacy")]
V8(v8::RuntimeMetadataV8),
/// Version 8 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "v8"))]
#[cfg(not(feature = "legacy"))]
V8(OpaqueMetadata),
/// Version 9 for runtime metadata.
#[cfg(any(feature = "v9", feature = "legacy"))]
#[cfg(feature = "legacy")]
V9(v9::RuntimeMetadataV9),
/// Version 9 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "v9"))]
#[cfg(not(feature = "legacy"))]
V9(OpaqueMetadata),
/// Version 10 for runtime metadata.
#[cfg(any(feature = "v10", feature = "legacy"))]
#[cfg(feature = "legacy")]
V10(v10::RuntimeMetadataV10),
/// Version 10 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "v10"))]
#[cfg(not(feature = "legacy"))]
V10(OpaqueMetadata),
/// Version 11 for runtime metadata.
#[cfg(any(feature = "v11", feature = "legacy"))]
#[cfg(feature = "legacy")]
V11(v11::RuntimeMetadataV11),
/// Version 11 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "v11"))]
#[cfg(not(feature = "legacy"))]
V11(OpaqueMetadata),
/// Version 12 for runtime metadata
#[cfg(any(feature = "v12", feature = "legacy"))]
#[cfg(feature = "legacy")]
V12(v12::RuntimeMetadataV12),
/// Version 12 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "v12"))]
#[cfg(not(feature = "legacy"))]
V12(OpaqueMetadata),
/// Version 13 for runtime metadata.
#[cfg(any(feature = "v13", feature = "legacy"))]
#[cfg(feature = "legacy")]
V13(v13::RuntimeMetadataV13),
/// Version 13 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "v13"))]
#[cfg(not(feature = "legacy"))]
V13(OpaqueMetadata),
/// Version 14 for runtime metadata.
#[cfg(feature = "v14")]
#[cfg(feature = "current")]
V14(v14::RuntimeMetadataV14),
/// Version 14 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "v14"))]
#[cfg(not(feature = "current"))]
V14(OpaqueMetadata),
/// Version 15 for runtime metadata.
#[cfg(feature = "v15-unstable")]
#[cfg(feature = "unstable")]
V15(v15::RuntimeMetadataV15),
/// Version 15 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "v15-unstable"))]
#[cfg(not(feature = "unstable"))]
V15(OpaqueMetadata),
}
+8 -252
View File
@@ -26,6 +26,12 @@ use scale_info::{
IntoPortable, MetaType, PortableRegistry, Registry,
};
pub use super::v14::{
PalletCallMetadata, PalletConstantMetadata, PalletErrorMetadata, PalletEventMetadata,
PalletStorageMetadata, StorageEntryMetadata, StorageEntryModifier, StorageEntryType,
StorageHasher,
};
/// Latest runtime metadata
pub type RuntimeMetadataLastVersion = RuntimeMetadataV15;
@@ -285,256 +291,6 @@ impl IntoPortable for PalletMetadata {
}
}
/// All metadata of the pallet's storage.
#[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, T::String: Serialize"))
)]
pub struct PalletStorageMetadata<T: Form = MetaForm> {
/// The common prefix used by all storage entries.
pub prefix: T::String,
/// Metadata for all storage entries.
pub entries: Vec<StorageEntryMetadata<T>>,
}
impl IntoPortable for PalletStorageMetadata {
type Output = PalletStorageMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletStorageMetadata {
prefix: self.prefix.into_portable(registry),
entries: registry.map_into_portable(self.entries),
}
}
}
/// Metadata about one storage entry.
#[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, T::String: Serialize"))
)]
pub struct StorageEntryMetadata<T: Form = MetaForm> {
/// Variable name of the storage entry.
pub name: T::String,
/// An `Option` modifier of that storage entry.
pub modifier: StorageEntryModifier,
/// Type of the value stored in the entry.
pub ty: StorageEntryType<T>,
/// Default value (SCALE encoded).
pub default: Vec<u8>,
/// Storage entry documentation.
pub docs: Vec<T::String>,
}
impl IntoPortable for StorageEntryMetadata {
type Output = StorageEntryMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
StorageEntryMetadata {
name: self.name.into_portable(registry),
modifier: self.modifier,
ty: self.ty.into_portable(registry),
default: self.default,
docs: registry.map_into_portable(self.docs),
}
}
}
/// A storage entry modifier indicates how a storage entry is returned when fetched and what the value will be if the key is not present.
/// Specifically this refers to the "return type" when fetching a storage entry, and what the value will be if the key is not present.
///
/// `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, 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,
/// The storage entry returns `T::Default` if the key is not present.
Default,
}
/// Hasher used by storage maps
#[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,
/// 256-bit Blake2 hash.
Blake2_256,
/// Multiple 128-bit Blake2 hashes concatenated.
Blake2_128Concat,
/// 128-bit XX hash.
Twox128,
/// 256-bit XX hash.
Twox256,
/// Multiple 64-bit XX hashes concatenated.
Twox64Concat,
/// Identity hashing (no hashing).
Identity,
}
/// A type of storage value.
#[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, T::String: Serialize"))
)]
pub enum StorageEntryType<T: Form = MetaForm> {
/// Plain storage entry (just the value).
Plain(T::Type),
/// A storage map.
Map {
/// One or more hashers, should be one hasher per key element.
hashers: Vec<StorageHasher>,
/// The type of the key, can be a tuple with elements for each of the hashers.
key: T::Type,
/// The type of the value.
value: T::Type,
},
}
impl IntoPortable for StorageEntryType {
type Output = StorageEntryType<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
match self {
Self::Plain(plain) => StorageEntryType::Plain(registry.register_type(&plain)),
Self::Map {
hashers,
key,
value,
} => StorageEntryType::Map {
hashers,
key: registry.register_type(&key),
value: registry.register_type(&value),
},
}
}
}
/// Metadata for all calls in a pallet
#[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, T::String: Serialize"))
)]
pub struct PalletCallMetadata<T: Form = MetaForm> {
/// The corresponding enum type for the pallet call.
pub ty: T::Type,
}
impl IntoPortable for PalletCallMetadata {
type Output = PalletCallMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletCallMetadata {
ty: registry.register_type(&self.ty),
}
}
}
impl From<MetaType> for PalletCallMetadata {
fn from(ty: MetaType) -> Self {
Self { ty }
}
}
/// Metadata about the pallet Event type.
#[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,
}
impl IntoPortable for PalletEventMetadata {
type Output = PalletEventMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletEventMetadata {
ty: registry.register_type(&self.ty),
}
}
}
impl From<MetaType> for PalletEventMetadata {
fn from(ty: MetaType) -> Self {
Self { ty }
}
}
/// Metadata about one pallet constant.
#[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, T::String: Serialize"))
)]
pub struct PalletConstantMetadata<T: Form = MetaForm> {
/// Name of the pallet constant.
pub name: T::String,
/// Type of the pallet constant.
pub ty: T::Type,
/// Value stored in the constant (SCALE encoded).
pub value: Vec<u8>,
/// Documentation of the constant.
pub docs: Vec<T::String>,
}
impl IntoPortable for PalletConstantMetadata {
type Output = PalletConstantMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletConstantMetadata {
name: self.name.into_portable(registry),
ty: registry.register_type(&self.ty),
value: self.value,
docs: registry.map_into_portable(self.docs),
}
}
}
/// Metadata about a pallet error.
#[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,
}
impl IntoPortable for PalletErrorMetadata {
type Output = PalletErrorMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletErrorMetadata {
ty: registry.register_type(&self.ty),
}
}
}
impl From<MetaType> for PalletErrorMetadata {
fn from(ty: MetaType) -> Self {
Self { ty }
}
}
/// Metadata for custom types.
///
/// This map associates a string key to a `CustomValueMetadata`.
@@ -618,7 +374,7 @@ pub struct OuterEnums<T: Form = MetaForm> {
/// chain. It provides just the information needed to decode `sp_runtime::DispatchError::Module`.
/// - Decoding the 5 error bytes into this type will not always lead to all of the bytes being consumed;
/// many error types do not require all of the bytes to represent them fully.
pub module_error_enum_ty: T::Type,
pub error_enum_ty: T::Type,
}
impl IntoPortable for OuterEnums {
@@ -628,7 +384,7 @@ impl IntoPortable for OuterEnums {
OuterEnums {
call_enum_ty: registry.register_type(&self.call_enum_ty),
event_enum_ty: registry.register_type(&self.event_enum_ty),
module_error_enum_ty: registry.register_type(&self.module_error_enum_ty),
error_enum_ty: registry.register_type(&self.error_enum_ty),
}
}
}