Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions frame-metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
cfg-if = "1.0.0"
scale-info = { git = "https://github.com/paritytech/scale-info", default-features = false, optional = true, features = ["derive"] }
scale-info = { version = "0.6.0", default-features = false, optional = true, features = ["derive"] }
serde = { version = "1.0.101", optional = true, features = ["derive"] }

[features]
Expand All @@ -26,5 +26,6 @@ std = [
"codec/std",
"scale-info/std",
"scale-info/serde",
"scale-info/decode",
"serde",
]
28 changes: 6 additions & 22 deletions frame-metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,10 @@ pub mod v12;
#[cfg(feature = "v13")]
pub mod v13;

cfg_if::cfg_if! {
if #[cfg(not(feature = "v13"))] {
/// Dummy trait in place of `scale_info::form::FormString`.
/// Since the `scale-info` crate is only imported for the `v13` feature.
pub trait FormString {}

impl FormString for &'static str {}
#[cfg(feature = "std")]
impl FormString for String {}
} else {
pub(crate) use scale_info::form::FormString;
}
}

/// Metadata prefixed by a u32 for reserved usage
#[derive(Eq, Encode, PartialEq)]
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
#[cfg_attr(feature = "std", serde(bound(serialize = "S: Serialize")))]
pub struct RuntimeMetadataPrefixed<S: FormString = &'static str>(pub u32, pub RuntimeMetadata<S>);
pub struct RuntimeMetadataPrefixed(pub u32, pub RuntimeMetadata);

impl Into<Vec<u8>> for RuntimeMetadataPrefixed {
fn into(self) -> Vec<u8> {
Expand All @@ -71,10 +56,9 @@ impl Into<Vec<u8>> for RuntimeMetadataPrefixed {
/// the enum nature of `RuntimeMetadata`.
#[derive(Eq, Encode, PartialEq)]
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
#[cfg_attr(feature = "std", serde(bound(serialize = "S: Serialize")))]
pub enum RuntimeMetadata<S: FormString = &'static str> {
pub enum RuntimeMetadata {
/// Unused; enum filler.
V0(core::marker::PhantomData<S>),
V0(RuntimeMetadataDeprecated),
/// Version 1 for runtime metadata. No longer used.
V1(RuntimeMetadataDeprecated),
/// Version 2 for runtime metadata. No longer used.
Expand All @@ -99,13 +83,13 @@ pub enum RuntimeMetadata<S: FormString = &'static str> {
V11(RuntimeMetadataDeprecated),
/// Version 12 for runtime metadata
#[cfg(feature = "v12")]
V12(v12::RuntimeMetadataV12<S>),
V12(v12::RuntimeMetadataV12),
/// Version 12 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "v12"))]
V12(OpaqueMetadata),
/// Version 13 for runtime metadata.
#[cfg(feature = "v13")]
V13(v13::RuntimeMetadataV13<S>),
V13(v13::RuntimeMetadataV13),
/// Version 13 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "v13"))]
V13(OpaqueMetadata),
Expand All @@ -122,7 +106,7 @@ pub struct OpaqueMetadata(pub Vec<u8>);
pub enum RuntimeMetadataDeprecated {}

impl Encode for RuntimeMetadataDeprecated {
fn encode_to<W: Output>(&self, _dest: &mut W) {}
fn encode_to<W: Output + ?Sized>(&self, _dest: &mut W) {}
}

impl codec::EncodeLike for RuntimeMetadataDeprecated {}
Expand Down
7 changes: 3 additions & 4 deletions frame-metadata/src/v12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ where
B: Encode + 'static,
O: Encode + 'static,
{
fn encode_to<W: Output>(&self, dest: &mut W) {
fn encode_to<W: Output + ?Sized>(&self, dest: &mut W) {
match self {
DecodeDifferent::Encode(b) => b.encode_to(dest),
DecodeDifferent::Decoded(o) => o.encode_to(dest),
Expand Down Expand Up @@ -160,7 +160,7 @@ where
E: Encode + 'static;

impl<E: Encode> Encode for FnEncode<E> {
fn encode_to<W: Output>(&self, dest: &mut W) {
fn encode_to<W: Output + ?Sized>(&self, dest: &mut W) {
self.0().encode_to(dest);
}
}
Expand Down Expand Up @@ -262,7 +262,7 @@ pub struct DefaultByteGetter(pub &'static dyn DefaultByte);
pub type ByteGetter = DecodeDifferent<DefaultByteGetter, Vec<u8>>;

impl Encode for DefaultByteGetter {
fn encode_to<W: Output>(&self, dest: &mut W) {
fn encode_to<W: Output + ?Sized>(&self, dest: &mut W) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what lies behind the relaxed bounds requirement here, i.e. ?Sized? I know it came with scale 2.0 but I'm hazy on why.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that the output can be unsized. So you could for example have some boxed output.

self.0.default_byte().encode_to(dest)
}
}
Expand Down Expand Up @@ -359,7 +359,6 @@ pub struct ExtrinsicMetadata {
/// The metadata of a runtime.
#[derive(Eq, Encode, PartialEq)]
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
#[cfg_attr(feature = "std", serde(bound(serialize = "S: Serialize")))]
pub struct RuntimeMetadataV12<S = ()> {
/// Metadata of all the modules.
pub modules: DecodeDifferentArray<ModuleMetadata>,
Expand Down
11 changes: 5 additions & 6 deletions frame-metadata/src/v13.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use super::RuntimeMetadataPrefixed;
use codec::Encode;
use scale_info::prelude::vec::Vec;
use scale_info::{
form::{Form, FormString, MetaForm, PortableForm},
form::{Form, MetaForm, PortableForm},
meta_type, IntoPortable, PortableRegistry, Registry, TypeInfo,
};

Expand All @@ -48,13 +48,12 @@ impl From<RuntimeMetadataLastVersion> for super::RuntimeMetadataPrefixed {
// todo: [AJ] add back clone derive if required (requires PortableRegistry to implement clone)
#[derive(PartialEq, Eq, Encode)]
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
#[cfg_attr(feature = "std", serde(bound(serialize = "S: Serialize")))]
pub struct RuntimeMetadataV13<S: FormString = &'static str> {
pub types: PortableRegistry<S>,
pub struct RuntimeMetadataV13 {
pub types: PortableRegistry,
/// Metadata of all the modules.
pub modules: Vec<ModuleMetadata<PortableForm<S>>>,
pub modules: Vec<ModuleMetadata<PortableForm>>,
/// Metadata of the extrinsic.
pub extrinsic: ExtrinsicMetadata<PortableForm<S>>,
pub extrinsic: ExtrinsicMetadata<PortableForm>,
}

impl RuntimeMetadataV13 {
Expand Down