Update to latest scale-info & codec, remove string parameterization (#7)

* Update to latest scale-info & codec, remove string parameterization

* Remove redundant bound

* Remove more redundant S bounds

* Use substrate branch

* Use latest scale-info release
This commit is contained in:
Andrew Jones
2021-02-11 09:38:06 +00:00
committed by GitHub
parent 1aaf5ba7fa
commit be8092d7bf
4 changed files with 17 additions and 34 deletions
+6 -22
View File
@@ -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> {
@@ -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.
@@ -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),
@@ -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 {}
+3 -4
View File
@@ -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),
@@ -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);
}
}
@@ -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) {
self.0.default_byte().encode_to(dest)
}
}
@@ -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>,
+5 -6
View File
@@ -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,
};
@@ -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 {