fix: Complete snowbridge pezpallet rebrand and critical bug fixes

- snowbridge-pezpallet-* → pezsnowbridge-pezpallet-* (201 refs)
- pallet/ directories → pezpallet/ (4 locations)
- Fixed pezpallet.rs self-include recursion bug
- Fixed sc-chain-spec hardcoded crate name in derive macro
- Reverted .pezpallet_by_name() to .pallet_by_name() (subxt API)
- Added BizinikiwiConfig type alias for zombienet tests
- Deleted obsolete session state files

Verified: pezsnowbridge-pezpallet-*, pezpallet-staking,
pezpallet-staking-async, pezframe-benchmarking-cli all pass cargo check
This commit is contained in:
2025-12-16 09:57:23 +03:00
parent eea003e14d
commit 3139ffa25e
3022 changed files with 42157 additions and 23579 deletions
@@ -0,0 +1,50 @@
[package]
name = "pezframe-metadata"
version = "23.0.1"
authors.workspace = true
edition = "2021"
license = "Apache-2.0"
homepage.workspace = true
repository.workspace = true
description = "Metadata types for Kurdistan SDK runtimes"
readme = "README.md"
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
cfg-if = "1.0.0"
scale-info = { version = "2.0.0", default-features = false, optional = true, features = ["derive"] }
serde = { version = "1.0.101", default-features = false, optional = true, features = ["derive"] }
[features]
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 = [
"scale-info/serde",
"codec/serde",
"serde",
"serde/alloc",
]
# Scale decode support without relying on std features
decode = ["scale-info/decode"]
std = [
"decode",
"serde_full",
"codec/std",
"scale-info/std",
"serde/std",
]
@@ -0,0 +1,7 @@
Decodable variant of the RuntimeMetadata.
This really doesn't belong here, but is necessary for the moment. In the future
it should be removed entirely to an external module for shimming on to the
codec-encoded metadata.
License: Apache-2.0
@@ -0,0 +1,167 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use codec::{Encode, Output};
cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
use codec::{Decode, Error, Input};
/// On `std` the `StringBuf` used by [`DecodeDifferent`] is just a `String`.
pub type StringBuf = String;
} else {
extern crate alloc;
use alloc::vec::Vec;
/// On `no_std` we do not support `Decode` and thus `StringBuf` is just `&'static str`.
/// So, if someone tries to decode this stuff on `no_std`, they will get a compilation error.
pub type StringBuf = &'static str;
}
}
/// A type that decodes to a different type than it encodes.
/// The user needs to make sure that both types use the same encoding.
///
/// For example a `&'static [ &'static str ]` can be decoded to a `Vec<String>`.
#[derive(Clone)]
pub enum DecodeDifferent<B, O>
where
B: 'static,
O: 'static,
{
/// Encodable variant of the value (doesn't need to be decodeable).
Encode(B),
/// Encodable & decodeable variant of the value.
Decoded(O),
}
impl<B, O> Encode for DecodeDifferent<B, O>
where
B: Encode + 'static,
O: Encode + 'static,
{
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),
}
}
}
impl<B, O> codec::EncodeLike for DecodeDifferent<B, O>
where
B: Encode + 'static,
O: Encode + 'static,
{
}
#[cfg(feature = "std")]
impl<B, O> Decode for DecodeDifferent<B, O>
where
B: 'static,
O: Decode + 'static,
{
fn decode<I: Input>(input: &mut I) -> Result<Self, Error> {
<O>::decode(input).map(|val| DecodeDifferent::Decoded(val))
}
}
impl<B, O> PartialEq for DecodeDifferent<B, O>
where
B: Encode + Eq + PartialEq + 'static,
O: Encode + Eq + PartialEq + 'static,
{
fn eq(&self, other: &Self) -> bool {
self.encode() == other.encode()
}
}
impl<B, O> Eq for DecodeDifferent<B, O>
where
B: Encode + Eq + PartialEq + 'static,
O: Encode + Eq + PartialEq + 'static,
{
}
impl<B, O> core::fmt::Debug for DecodeDifferent<B, O>
where
B: core::fmt::Debug + Eq + 'static,
O: core::fmt::Debug + Eq + 'static,
{
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
DecodeDifferent::Encode(b) => b.fmt(f),
DecodeDifferent::Decoded(o) => o.fmt(f),
}
}
}
#[cfg(feature = "std")]
impl<B, O> serde::Serialize for DecodeDifferent<B, O>
where
B: serde::Serialize + 'static,
O: serde::Serialize + 'static,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match self {
DecodeDifferent::Encode(b) => b.serialize(serializer),
DecodeDifferent::Decoded(o) => o.serialize(serializer),
}
}
}
/// An array type that decodes as a `Vec`.
pub type DecodeDifferentArray<B, O = B> = DecodeDifferent<&'static [B], Vec<O>>;
/// A string type that decodes as a [`StringBuf`].
pub type DecodeDifferentStr = DecodeDifferent<&'static str, StringBuf>;
/// Newtype wrapper for support encoding functions (actual the result of the function).
#[derive(Clone, Eq)]
pub struct FnEncode<E>(pub fn() -> E)
where
E: Encode + 'static;
impl<E: Encode> Encode for FnEncode<E> {
fn encode_to<W: Output + ?Sized>(&self, dest: &mut W) {
self.0().encode_to(dest);
}
}
impl<E: Encode> codec::EncodeLike for FnEncode<E> {}
impl<E: Encode + PartialEq> PartialEq for FnEncode<E> {
fn eq(&self, other: &Self) -> bool {
self.0().eq(&other.0())
}
}
impl<E: Encode + core::fmt::Debug> core::fmt::Debug for FnEncode<E> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
self.0().fmt(f)
}
}
#[cfg(feature = "std")]
impl<E: Encode + serde::Serialize> serde::Serialize for FnEncode<E> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.0().serialize(serializer)
}
}
@@ -0,0 +1,275 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Decodable variant of the RuntimeMetadata.
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs)]
#[cfg(all(
any(feature = "decode", feature = "serde_full"),
feature = "legacy",
not(feature = "std")
))]
compile_error!("decode and serde_full features prior to v14 require std");
#[cfg(feature = "serde_full")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "decode")]
use codec::{Decode, Error, Input};
cfg_if::cfg_if! {
if #[cfg(not(feature = "std"))] {
extern crate alloc;
use alloc::vec::Vec;
}
}
use codec::{Encode, Output};
/// A type that decodes to a different type than it encodes.
#[cfg(feature = "legacy")]
pub mod decode_different;
/// Metadata v8
#[cfg(feature = "legacy")]
pub mod v8;
/// Metadata v9
#[cfg(feature = "legacy")]
pub mod v9;
/// Metadata v10
#[cfg(feature = "legacy")]
pub mod v10;
/// Metadata v11
#[cfg(feature = "legacy")]
pub mod v11;
/// Metadata v12
#[cfg(feature = "legacy")]
pub mod v12;
/// Metadata v13
#[cfg(feature = "legacy")]
pub mod v13;
/// Metadata v14
#[cfg(feature = "current")]
pub mod v14;
/// Metadata v15
#[cfg(feature = "current")]
pub mod v15;
/// Metadata v16
#[cfg(feature = "current")]
pub mod v16;
/// Metadata prefix.
pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warning for endianness.
/// Metadata prefixed by a u32 for reserved usage
#[derive(Eq, Encode, PartialEq, Debug)]
#[cfg_attr(feature = "decode", derive(Decode))]
#[cfg_attr(feature = "serde_full", derive(Serialize))]
pub struct RuntimeMetadataPrefixed(pub u32, pub RuntimeMetadata);
impl From<RuntimeMetadataPrefixed> for Vec<u8> {
fn from(value: RuntimeMetadataPrefixed) -> Self {
value.encode()
}
}
/// The metadata of a runtime.
/// The version ID encoded/decoded through
/// the enum nature of `RuntimeMetadata`.
#[derive(Eq, Encode, PartialEq, Debug)]
#[cfg_attr(feature = "decode", derive(Decode))]
#[cfg_attr(feature = "serde_full", derive(Serialize))]
pub enum RuntimeMetadata {
/// Unused; enum filler.
V0(RuntimeMetadataDeprecated),
/// Version 1 for runtime metadata. No longer used.
V1(RuntimeMetadataDeprecated),
/// Version 2 for runtime metadata. No longer used.
V2(RuntimeMetadataDeprecated),
/// Version 3 for runtime metadata. No longer used.
V3(RuntimeMetadataDeprecated),
/// Version 4 for runtime metadata. No longer used.
V4(RuntimeMetadataDeprecated),
/// Version 5 for runtime metadata. No longer used.
V5(RuntimeMetadataDeprecated),
/// Version 6 for runtime metadata. No longer used.
V6(RuntimeMetadataDeprecated),
/// Version 7 for runtime metadata. No longer used.
V7(RuntimeMetadataDeprecated),
/// Version 8 for runtime metadata.
#[cfg(feature = "legacy")]
V8(v8::RuntimeMetadataV8),
/// Version 8 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "legacy"))]
V8(OpaqueMetadata),
/// Version 9 for runtime metadata.
#[cfg(feature = "legacy")]
V9(v9::RuntimeMetadataV9),
/// Version 9 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "legacy"))]
V9(OpaqueMetadata),
/// Version 10 for runtime metadata.
#[cfg(feature = "legacy")]
V10(v10::RuntimeMetadataV10),
/// Version 10 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "legacy"))]
V10(OpaqueMetadata),
/// Version 11 for runtime metadata.
#[cfg(feature = "legacy")]
V11(v11::RuntimeMetadataV11),
/// Version 11 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "legacy"))]
V11(OpaqueMetadata),
/// Version 12 for runtime metadata
#[cfg(feature = "legacy")]
V12(v12::RuntimeMetadataV12),
/// Version 12 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "legacy"))]
V12(OpaqueMetadata),
/// Version 13 for runtime metadata.
#[cfg(feature = "legacy")]
V13(v13::RuntimeMetadataV13),
/// Version 13 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "legacy"))]
V13(OpaqueMetadata),
/// Version 14 for runtime metadata.
#[cfg(feature = "current")]
V14(v14::RuntimeMetadataV14),
/// Version 14 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "current"))]
V14(OpaqueMetadata),
/// Version 15 for runtime metadata.
#[cfg(feature = "current")]
V15(v15::RuntimeMetadataV15),
/// Version 15 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "current"))]
V15(OpaqueMetadata),
/// Version 16 for runtime metadata.
#[cfg(feature = "current")]
V16(v16::RuntimeMetadataV16),
/// Version 16 for runtime metadata, as raw encoded bytes.
#[cfg(not(feature = "current"))]
V16(OpaqueMetadata),
}
impl RuntimeMetadata {
/// Get the version number of the metadata.
pub fn version(&self) -> u32 {
match self {
RuntimeMetadata::V0(_) => 0,
RuntimeMetadata::V1(_) => 1,
RuntimeMetadata::V2(_) => 2,
RuntimeMetadata::V3(_) => 3,
RuntimeMetadata::V4(_) => 4,
RuntimeMetadata::V5(_) => 5,
RuntimeMetadata::V6(_) => 6,
RuntimeMetadata::V7(_) => 7,
RuntimeMetadata::V8(_) => 8,
RuntimeMetadata::V9(_) => 9,
RuntimeMetadata::V10(_) => 10,
RuntimeMetadata::V11(_) => 11,
RuntimeMetadata::V12(_) => 12,
RuntimeMetadata::V13(_) => 13,
RuntimeMetadata::V14(_) => 14,
RuntimeMetadata::V15(_) => 15,
RuntimeMetadata::V16(_) => 16,
}
}
}
/// Stores the encoded `RuntimeMetadata` as raw bytes.
#[derive(Encode, Eq, PartialEq, Debug)]
#[cfg_attr(feature = "decode", derive(Decode))]
#[cfg_attr(feature = "serde_full", derive(Serialize, Deserialize))]
pub struct OpaqueMetadata(pub Vec<u8>);
/// Enum that should fail.
#[derive(Eq, PartialEq, Debug)]
#[cfg_attr(feature = "serde_full", derive(Serialize, Deserialize))]
pub enum RuntimeMetadataDeprecated {}
impl Encode for RuntimeMetadataDeprecated {
fn encode_to<W: Output + ?Sized>(&self, _dest: &mut W) {}
}
impl codec::EncodeLike for RuntimeMetadataDeprecated {}
#[cfg(feature = "decode")]
impl Decode for RuntimeMetadataDeprecated {
fn decode<I: Input>(_input: &mut I) -> Result<Self, Error> {
Err("Decoding is not supported".into())
}
}
#[cfg(test)]
mod test {
use super::*;
use std::fs;
fn load_metadata(version: u32) -> Vec<u8> {
fs::read(format!("./test_data/ksm_metadata_v{}.bin", version)).unwrap()
}
#[test]
fn should_decode_metadatav9() {
let meta: RuntimeMetadataPrefixed =
Decode::decode(&mut load_metadata(9).as_slice()).unwrap();
assert!(matches!(meta.1, RuntimeMetadata::V9(_)));
}
#[test]
fn should_decode_metadatav10() {
let meta: RuntimeMetadataPrefixed =
Decode::decode(&mut load_metadata(10).as_slice()).unwrap();
assert!(matches!(meta.1, RuntimeMetadata::V10(_)));
}
#[test]
fn should_decode_metadatav11() {
let meta: RuntimeMetadataPrefixed =
Decode::decode(&mut load_metadata(11).as_slice()).unwrap();
assert!(matches!(meta.1, RuntimeMetadata::V11(_)));
}
#[test]
fn should_decode_metadatav12() {
let meta: RuntimeMetadataPrefixed =
Decode::decode(&mut load_metadata(12).as_slice()).unwrap();
assert!(matches!(meta.1, RuntimeMetadata::V12(_)));
}
#[test]
fn should_decode_metadatav13() {
let meta: RuntimeMetadataPrefixed =
Decode::decode(&mut load_metadata(13).as_slice()).unwrap();
assert!(matches!(meta.1, RuntimeMetadata::V13(_)));
}
#[test]
fn should_decode_metadatav14() {
let meta: RuntimeMetadataPrefixed =
Decode::decode(&mut load_metadata(14).as_slice()).unwrap();
assert!(matches!(meta.1, RuntimeMetadata::V14(_)));
}
}
@@ -0,0 +1,239 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Metadata Version 10. Networks like Kusama contain this version on-chain.
//! Chains old enough to contain this metadata need a way to decode it.
#![allow(missing_docs)]
use crate::decode_different::*;
use codec::{Encode, Output};
cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
use codec::Decode;
use serde::Serialize;
type StringBuf = String;
} else {
extern crate alloc;
use alloc::vec::Vec;
/// On `no_std` we do not support `Decode` and thus `StringBuf` is just `&'static str`.
/// So, if someone tries to decode this stuff on `no_std`, they will get a compilation error.
type StringBuf = &'static str;
}
}
/// Curent prefix of metadata
pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness
/// All the metadata about a function.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct FunctionMetadata {
pub name: DecodeDifferentStr,
pub arguments: DecodeDifferentArray<FunctionArgumentMetadata>,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about a function argument.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct FunctionArgumentMetadata {
pub name: DecodeDifferentStr,
pub ty: DecodeDifferentStr,
}
/// All the metadata about an outer event.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct OuterEventMetadata {
pub name: DecodeDifferentStr,
pub events: DecodeDifferentArray<
(&'static str, FnEncode<&'static [EventMetadata]>),
(StringBuf, Vec<EventMetadata>),
>,
}
/// All the metadata about an event.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct EventMetadata {
pub name: DecodeDifferentStr,
pub arguments: DecodeDifferentArray<&'static str, StringBuf>,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about one storage entry.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct StorageEntryMetadata {
pub name: DecodeDifferentStr,
pub modifier: StorageEntryModifier,
pub ty: StorageEntryType,
pub default: ByteGetter,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about one module constant.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ModuleConstantMetadata {
pub name: DecodeDifferentStr,
pub ty: DecodeDifferentStr,
pub value: ByteGetter,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about a module error.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ErrorMetadata {
pub name: DecodeDifferentStr,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about errors in a module.
pub trait ModuleErrorMetadata {
fn metadata() -> &'static [ErrorMetadata];
}
impl ModuleErrorMetadata for &'static str {
fn metadata() -> &'static [ErrorMetadata] {
&[]
}
}
/// A technical trait to store lazy initiated vec value as static dyn pointer.
pub trait DefaultByte: Send + Sync {
fn default_byte(&self) -> Vec<u8>;
}
/// Wrapper over dyn pointer for accessing a cached once byte value.
#[derive(Clone)]
pub struct DefaultByteGetter(pub &'static dyn DefaultByte);
/// Decode different for static lazy initiated byte value.
pub type ByteGetter = DecodeDifferent<DefaultByteGetter, Vec<u8>>;
impl Encode for DefaultByteGetter {
fn encode_to<W: Output + ?Sized>(&self, dest: &mut W) {
self.0.default_byte().encode_to(dest)
}
}
impl codec::EncodeLike for DefaultByteGetter {}
impl PartialEq<DefaultByteGetter> for DefaultByteGetter {
fn eq(&self, other: &DefaultByteGetter) -> bool {
let left = self.0.default_byte();
let right = other.0.default_byte();
left.eq(&right)
}
}
impl Eq for DefaultByteGetter {}
#[cfg(feature = "std")]
impl serde::Serialize for DefaultByteGetter {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.0.default_byte().serialize(serializer)
}
}
impl core::fmt::Debug for DefaultByteGetter {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
self.0.default_byte().fmt(f)
}
}
/// Hasher used by storage maps
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub enum StorageHasher {
Blake2_128,
Blake2_256,
Blake2_128Concat,
Twox128,
Twox256,
Twox64Concat,
}
/// A storage entry type.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub enum StorageEntryType {
Plain(DecodeDifferentStr),
Map {
hasher: StorageHasher,
key: DecodeDifferentStr,
value: DecodeDifferentStr,
is_linked: bool,
},
DoubleMap {
hasher: StorageHasher,
key1: DecodeDifferentStr,
key2: DecodeDifferentStr,
value: DecodeDifferentStr,
key2_hasher: StorageHasher,
},
}
/// 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 = "std", derive(Decode, Serialize))]
pub enum StorageEntryModifier {
Optional,
Default,
}
/// All metadata of the storage.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct StorageMetadata {
/// The common prefix used by all storage entries.
pub prefix: DecodeDifferent<&'static str, StringBuf>,
pub entries: DecodeDifferent<&'static [StorageEntryMetadata], Vec<StorageEntryMetadata>>,
}
/// The metadata of a runtime.
#[derive(Eq, Encode, PartialEq, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct RuntimeMetadataV10 {
pub modules: DecodeDifferentArray<ModuleMetadata>,
}
/// All metadata about an runtime module.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ModuleMetadata {
pub name: DecodeDifferentStr,
pub storage: Option<DecodeDifferent<FnEncode<StorageMetadata>, StorageMetadata>>,
pub calls: ODFnA<FunctionMetadata>,
pub event: ODFnA<EventMetadata>,
pub constants: DFnA<ModuleConstantMetadata>,
pub errors: DFnA<ErrorMetadata>,
}
type ODFnA<T> = Option<DFnA<T>>;
type DFnA<T> = DecodeDifferent<FnEncode<&'static [T]>, Vec<T>>;
@@ -0,0 +1,254 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Metadata Version 11. Networks like Kusama contain this version on-chain.
//! Chains old enough to contain this metadata need a way to decode it.
#![allow(missing_docs)]
use crate::decode_different::*;
use codec::{Encode, Output};
cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
use codec::Decode;
use serde::Serialize;
type StringBuf = String;
} else {
extern crate alloc;
use alloc::vec::Vec;
/// On `no_std` we do not support `Decode` and thus `StringBuf` is just `&'static str`.
/// So, if someone tries to decode this stuff on `no_std`, they will get a compilation error.
type StringBuf = &'static str;
}
}
/// Current prefix of metadata
pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness
/// All the metadata about a function.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct FunctionMetadata {
pub name: DecodeDifferentStr,
pub arguments: DecodeDifferentArray<FunctionArgumentMetadata>,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about a function argument.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct FunctionArgumentMetadata {
pub name: DecodeDifferentStr,
pub ty: DecodeDifferentStr,
}
/// All the metadata about an outer event.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct OuterEventMetadata {
pub name: DecodeDifferentStr,
pub events: DecodeDifferentArray<
(&'static str, FnEncode<&'static [EventMetadata]>),
(StringBuf, Vec<EventMetadata>),
>,
}
/// All the metadata about an event.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct EventMetadata {
pub name: DecodeDifferentStr,
pub arguments: DecodeDifferentArray<&'static str, StringBuf>,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about one storage entry.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct StorageEntryMetadata {
pub name: DecodeDifferentStr,
pub modifier: StorageEntryModifier,
pub ty: StorageEntryType,
pub default: ByteGetter,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about one module constant.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ModuleConstantMetadata {
pub name: DecodeDifferentStr,
pub ty: DecodeDifferentStr,
pub value: ByteGetter,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about a module error.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ErrorMetadata {
pub name: DecodeDifferentStr,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about errors in a module.
pub trait ModuleErrorMetadata {
fn metadata() -> &'static [ErrorMetadata];
}
impl ModuleErrorMetadata for &'static str {
fn metadata() -> &'static [ErrorMetadata] {
&[]
}
}
/// A technical trait to store lazy initiated vec value as static dyn pointer.
pub trait DefaultByte: Send + Sync {
fn default_byte(&self) -> Vec<u8>;
}
/// Wrapper over dyn pointer for accessing a cached once byte value.
#[derive(Clone)]
pub struct DefaultByteGetter(pub &'static dyn DefaultByte);
/// Decode different for static lazy initiated byte value.
pub type ByteGetter = DecodeDifferent<DefaultByteGetter, Vec<u8>>;
impl Encode for DefaultByteGetter {
fn encode_to<W: Output + ?Sized>(&self, dest: &mut W) {
self.0.default_byte().encode_to(dest)
}
}
impl codec::EncodeLike for DefaultByteGetter {}
impl PartialEq<DefaultByteGetter> for DefaultByteGetter {
fn eq(&self, other: &DefaultByteGetter) -> bool {
let left = self.0.default_byte();
let right = other.0.default_byte();
left.eq(&right)
}
}
impl Eq for DefaultByteGetter {}
#[cfg(feature = "std")]
impl serde::Serialize for DefaultByteGetter {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.0.default_byte().serialize(serializer)
}
}
impl core::fmt::Debug for DefaultByteGetter {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
self.0.default_byte().fmt(f)
}
}
/// Hasher used by storage maps
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub enum StorageHasher {
Blake2_128,
Blake2_256,
Blake2_128Concat,
Twox128,
Twox256,
Twox64Concat,
Identity,
}
/// A storage entry type.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub enum StorageEntryType {
Plain(DecodeDifferentStr),
Map {
hasher: StorageHasher,
key: DecodeDifferentStr,
value: DecodeDifferentStr,
// is_linked flag previously, unused now to keep backwards compat
unused: bool,
},
DoubleMap {
hasher: StorageHasher,
key1: DecodeDifferentStr,
key2: DecodeDifferentStr,
value: DecodeDifferentStr,
key2_hasher: StorageHasher,
},
}
/// 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 = "std", derive(Decode, Serialize))]
pub enum StorageEntryModifier {
Optional,
Default,
}
/// All metadata of the storage.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct StorageMetadata {
/// The common prefix used by all storage entries.
pub prefix: DecodeDifferent<&'static str, StringBuf>,
pub entries: DecodeDifferent<&'static [StorageEntryMetadata], Vec<StorageEntryMetadata>>,
}
/// Metadata of the extrinsic used by the runtime.
#[derive(Eq, Encode, PartialEq, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ExtrinsicMetadata {
/// Extrinsic version.
pub version: u8,
/// The signed extensions in the order they appear in the extrinsic.
pub signed_extensions: Vec<DecodeDifferentStr>,
}
/// The metadata of a runtime.
#[derive(Eq, Encode, PartialEq, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct RuntimeMetadataV11 {
/// Metadata of all the modules.
pub modules: DecodeDifferentArray<ModuleMetadata>,
/// Metadata of the extrinsic.
pub extrinsic: ExtrinsicMetadata,
}
/// All metadata about an runtime module.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ModuleMetadata {
pub name: DecodeDifferentStr,
pub storage: Option<DecodeDifferent<FnEncode<StorageMetadata>, StorageMetadata>>,
pub calls: ODFnA<FunctionMetadata>,
pub event: ODFnA<EventMetadata>,
pub constants: DFnA<ModuleConstantMetadata>,
pub errors: DFnA<ErrorMetadata>,
}
type ODFnA<T> = Option<DFnA<T>>;
type DFnA<T> = DecodeDifferent<FnEncode<&'static [T]>, Vec<T>>;
@@ -0,0 +1,257 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Metadata Version 12. Networks like Kusama contain this version on-chain.
//! Chains old enough to contain this metadata need a way to decode it.
#![allow(missing_docs)]
use crate::decode_different::*;
use codec::{Encode, Output};
cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
use codec::Decode;
use serde::Serialize;
type StringBuf = String;
} else {
extern crate alloc;
use alloc::vec::Vec;
/// On `no_std` we do not support `Decode` and thus `StringBuf` is just `&'static str`.
/// So, if someone tries to decode this stuff on `no_std`, they will get a compilation error.
type StringBuf = &'static str;
}
}
/// Current prefix of metadata
pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness
/// Metadata about a function.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct FunctionMetadata {
pub name: DecodeDifferentStr,
pub arguments: DecodeDifferentArray<FunctionArgumentMetadata>,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// Metadata about a function argument.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct FunctionArgumentMetadata {
pub name: DecodeDifferentStr,
pub ty: DecodeDifferentStr,
}
/// Metadata about an outer event.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct OuterEventMetadata {
pub name: DecodeDifferentStr,
pub events: DecodeDifferentArray<
(&'static str, FnEncode<&'static [EventMetadata]>),
(StringBuf, Vec<EventMetadata>),
>,
}
/// Metadata about an event.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct EventMetadata {
pub name: DecodeDifferentStr,
pub arguments: DecodeDifferentArray<&'static str, StringBuf>,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// Metadata about one storage entry.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct StorageEntryMetadata {
pub name: DecodeDifferentStr,
pub modifier: StorageEntryModifier,
pub ty: StorageEntryType,
pub default: ByteGetter,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// Metadata about one module constant.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ModuleConstantMetadata {
pub name: DecodeDifferentStr,
pub ty: DecodeDifferentStr,
pub value: ByteGetter,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// Metadata about a module error.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ErrorMetadata {
pub name: DecodeDifferentStr,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// Metadata about errors in a module.
pub trait ModuleErrorMetadata {
fn metadata() -> &'static [ErrorMetadata];
}
impl ModuleErrorMetadata for &'static str {
fn metadata() -> &'static [ErrorMetadata] {
&[]
}
}
/// A technical trait to store lazy initiated vec value as static dyn pointer.
pub trait DefaultByte: Send + Sync {
fn default_byte(&self) -> Vec<u8>;
}
/// Wrapper over dyn pointer for accessing a cached once byte value.
#[derive(Clone)]
pub struct DefaultByteGetter(pub &'static dyn DefaultByte);
/// Decode different for static lazy initiated byte value.
pub type ByteGetter = DecodeDifferent<DefaultByteGetter, Vec<u8>>;
impl Encode for DefaultByteGetter {
fn encode_to<W: Output + ?Sized>(&self, dest: &mut W) {
self.0.default_byte().encode_to(dest)
}
}
impl codec::EncodeLike for DefaultByteGetter {}
impl PartialEq<DefaultByteGetter> for DefaultByteGetter {
fn eq(&self, other: &DefaultByteGetter) -> bool {
let left = self.0.default_byte();
let right = other.0.default_byte();
left.eq(&right)
}
}
impl Eq for DefaultByteGetter {}
#[cfg(feature = "std")]
impl serde::Serialize for DefaultByteGetter {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.0.default_byte().serialize(serializer)
}
}
impl core::fmt::Debug for DefaultByteGetter {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
self.0.default_byte().fmt(f)
}
}
/// Hasher used by storage maps
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub enum StorageHasher {
Blake2_128,
Blake2_256,
Blake2_128Concat,
Twox128,
Twox256,
Twox64Concat,
Identity,
}
/// A storage entry type.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub enum StorageEntryType {
Plain(DecodeDifferentStr),
Map {
hasher: StorageHasher,
key: DecodeDifferentStr,
value: DecodeDifferentStr,
// is_linked flag previously, unused now to keep backwards compat
unused: bool,
},
DoubleMap {
hasher: StorageHasher,
key1: DecodeDifferentStr,
key2: DecodeDifferentStr,
value: DecodeDifferentStr,
key2_hasher: StorageHasher,
},
}
/// 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 = "std", derive(Decode, Serialize))]
pub enum StorageEntryModifier {
Optional,
Default,
}
/// All metadata of the storage.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct StorageMetadata {
/// The common prefix used by all storage entries.
pub prefix: DecodeDifferent<&'static str, StringBuf>,
pub entries: DecodeDifferent<&'static [StorageEntryMetadata], Vec<StorageEntryMetadata>>,
}
/// Metadata of the extrinsic used by the runtime.
#[derive(Eq, Encode, PartialEq, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ExtrinsicMetadata {
/// Extrinsic version.
pub version: u8,
/// The signed extensions in the order they appear in the extrinsic.
pub signed_extensions: Vec<DecodeDifferentStr>,
}
/// The metadata of a runtime.
#[derive(Eq, Encode, PartialEq, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct RuntimeMetadataV12 {
/// Metadata of all the modules.
pub modules: DecodeDifferentArray<ModuleMetadata>,
/// Metadata of the extrinsic.
pub extrinsic: ExtrinsicMetadata,
}
/// All metadata about an runtime module.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ModuleMetadata {
pub name: DecodeDifferentStr,
pub storage: Option<DecodeDifferent<FnEncode<StorageMetadata>, StorageMetadata>>,
pub calls: ODFnA<FunctionMetadata>,
pub event: ODFnA<EventMetadata>,
pub constants: DFnA<ModuleConstantMetadata>,
pub errors: DFnA<ErrorMetadata>,
/// Define the index of the module, this index will be used for the encoding of module event,
/// call and origin variants.
pub index: u8,
}
type ODFnA<T> = Option<DFnA<T>>;
type DFnA<T> = DecodeDifferent<FnEncode<&'static [T]>, Vec<T>>;
@@ -0,0 +1,310 @@
// This file is part of Substrate.
// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Metadata Version 13. Networks like Kusama contain this version on-chain.
//! Chains old enough to contain this metadata need a way to decode it.
use crate::decode_different::*;
use codec::{Encode, Output};
cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
use codec::Decode;
use serde::Serialize;
} else {
extern crate alloc;
use alloc::vec::Vec;
}
}
/// Current prefix of metadata
pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness
/// Metadata about a function.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct FunctionMetadata {
/// Function name.
pub name: DecodeDifferentStr,
/// A list of arguments this function takes.
pub arguments: DecodeDifferentArray<FunctionArgumentMetadata>,
/// Function documentation.
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// Metadata about a function argument.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct FunctionArgumentMetadata {
/// Name of the variable for the argument.
pub name: DecodeDifferentStr,
/// Type of the parameter.
pub ty: DecodeDifferentStr,
}
/// Metadata about an outer event.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct OuterEventMetadata {
/// Name of the event.
pub name: DecodeDifferentStr,
/// A list of event details.
pub events: DecodeDifferentArray<
(&'static str, FnEncode<&'static [EventMetadata]>),
(StringBuf, Vec<EventMetadata>),
>,
}
/// Metadata about an event.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct EventMetadata {
/// Name of the event.
pub name: DecodeDifferentStr,
/// Arguments of the event.
pub arguments: DecodeDifferentArray<&'static str, StringBuf>,
/// Documentation of the event.
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// Metadata about one storage entry.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct StorageEntryMetadata {
/// Variable name of the storage entry.
pub name: DecodeDifferentStr,
/// A storage modifier of the storage entry (is it optional? does it have a default value?).
pub modifier: StorageEntryModifier,
/// Type of the value stored in the entry.
pub ty: StorageEntryType,
/// Default value (SCALE encoded).
pub default: ByteGetter,
/// Storage entry documentation.
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// Metadata about a module constant.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ModuleConstantMetadata {
/// Name of the module constant.
pub name: DecodeDifferentStr,
/// Type of the module constant.
pub ty: DecodeDifferentStr,
/// Value stored in the constant (SCALE encoded).
pub value: ByteGetter,
/// Documentation of the constant.
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// Metadata about a module error.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ErrorMetadata {
/// Name of the error.
pub name: DecodeDifferentStr,
/// Error variant documentation.
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// Metadata about errors in a module.
pub trait ModuleErrorMetadata {
/// Returns the error metadata.
fn metadata() -> &'static [ErrorMetadata];
}
impl ModuleErrorMetadata for &'static str {
fn metadata() -> &'static [ErrorMetadata] {
&[]
}
}
/// A technical trait to store lazy initiated vec value as static dyn pointer.
pub trait DefaultByte: Send + Sync {
/// A default value (SCALE encoded).
fn default_byte(&self) -> Vec<u8>;
}
/// Wrapper over dyn pointer for accessing a cached once byte value.
#[derive(Clone)]
pub struct DefaultByteGetter(pub &'static dyn DefaultByte);
/// Decode different for static lazy initiated byte value.
pub type ByteGetter = DecodeDifferent<DefaultByteGetter, Vec<u8>>;
impl Encode for DefaultByteGetter {
fn encode_to<W: Output + ?Sized>(&self, dest: &mut W) {
self.0.default_byte().encode_to(dest)
}
}
impl codec::EncodeLike for DefaultByteGetter {}
impl PartialEq<DefaultByteGetter> for DefaultByteGetter {
fn eq(&self, other: &DefaultByteGetter) -> bool {
let left = self.0.default_byte();
let right = other.0.default_byte();
left.eq(&right)
}
}
impl Eq for DefaultByteGetter {}
#[cfg(feature = "std")]
impl serde::Serialize for DefaultByteGetter {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.0.default_byte().serialize(serializer)
}
}
impl core::fmt::Debug for DefaultByteGetter {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
self.0.default_byte().fmt(f)
}
}
/// Hasher used by storage maps
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, 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 storage entry type.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub enum StorageEntryType {
/// Plain storage entry (just the value).
Plain(DecodeDifferentStr),
/// A storage map.
Map {
/// Hasher type for the keys.
hasher: StorageHasher,
/// Key type.
key: DecodeDifferentStr,
/// Value type.
value: DecodeDifferentStr,
/// is_linked flag previously, unused now to keep backwards compat
unused: bool,
},
/// Storage Double Map.
DoubleMap {
/// Hasher type for the keys.
hasher: StorageHasher,
/// First key type.
key1: DecodeDifferentStr,
/// Second key type.
key2: DecodeDifferentStr,
/// Value type.
value: DecodeDifferentStr,
/// Hasher for the second key.
key2_hasher: StorageHasher,
},
/// Storage multi map.
NMap {
/// Key types.
keys: DecodeDifferentArray<&'static str, StringBuf>,
/// Key hashers.
hashers: DecodeDifferentArray<StorageHasher>,
/// Value type.
value: DecodeDifferentStr,
},
}
/// 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 = "std", derive(Decode, 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,
}
/// All metadata of the storage.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct StorageMetadata {
/// The common prefix used by all storage entries.
pub prefix: DecodeDifferent<&'static str, StringBuf>,
/// Storage entries.
pub entries: DecodeDifferent<&'static [StorageEntryMetadata], Vec<StorageEntryMetadata>>,
}
/// Metadata of the extrinsic used by the runtime.
#[derive(Eq, Encode, PartialEq, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ExtrinsicMetadata {
/// Extrinsic version.
pub version: u8,
/// The signed extensions in the order they appear in the extrinsic.
pub signed_extensions: Vec<DecodeDifferentStr>,
}
/// The metadata of a runtime.
#[derive(Eq, Encode, PartialEq, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct RuntimeMetadataV13 {
/// Metadata of all the modules.
pub modules: DecodeDifferentArray<ModuleMetadata>,
/// Metadata of the extrinsic.
pub extrinsic: ExtrinsicMetadata,
}
/// All metadata about a runtime module.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ModuleMetadata {
/// Module name.
pub name: DecodeDifferentStr,
/// Module storage.
pub storage: Option<DecodeDifferent<FnEncode<StorageMetadata>, StorageMetadata>>,
/// Module calls.
pub calls: ODFnA<FunctionMetadata>,
/// Module Event type.
pub event: ODFnA<EventMetadata>,
/// Module constants.
pub constants: DFnA<ModuleConstantMetadata>,
/// Module errors.
pub errors: DFnA<ErrorMetadata>,
/// Define the index of the module, this index will be used for the encoding of module event,
/// call and origin variants.
pub index: u8,
}
type ODFnA<T> = Option<DFnA<T>>;
type DFnA<T> = DecodeDifferent<FnEncode<&'static [T]>, Vec<T>>;
@@ -0,0 +1,424 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#[cfg(feature = "decode")]
use codec::Decode;
#[cfg(feature = "serde_full")]
use serde::Serialize;
use super::RuntimeMetadataPrefixed;
use codec::Encode;
use scale_info::prelude::vec::Vec;
use scale_info::{
form::{Form, MetaForm, PortableForm},
IntoPortable, MetaType, PortableRegistry, Registry,
};
/// Current prefix of metadata
pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness
/// Latest runtime metadata
pub type RuntimeMetadataLastVersion = RuntimeMetadataV14;
impl From<RuntimeMetadataLastVersion> for super::RuntimeMetadataPrefixed {
fn from(metadata: RuntimeMetadataLastVersion) -> RuntimeMetadataPrefixed {
RuntimeMetadataPrefixed(META_RESERVED, super::RuntimeMetadata::V14(metadata))
}
}
/// The metadata of a runtime.
#[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,
/// Metadata of all the pezpallets.
pub pezpallets: Vec<PezpalletMetadata<PortableForm>>,
/// Metadata of the extrinsic.
pub extrinsic: ExtrinsicMetadata<PortableForm>,
/// The type of the `Runtime`.
pub ty: <PortableForm as Form>::Type,
}
impl RuntimeMetadataV14 {
/// Create a new instance of [`RuntimeMetadataV14`].
pub fn new(
pezpallets: Vec<PezpalletMetadata>,
extrinsic: ExtrinsicMetadata,
runtime_type: MetaType,
) -> Self {
let mut registry = Registry::new();
let pezpallets = registry.map_into_portable(pezpallets);
let extrinsic = extrinsic.into_portable(&mut registry);
let ty = registry.register_type(&runtime_type);
Self {
types: registry.into(),
pezpallets,
extrinsic,
ty,
}
}
}
/// Metadata of the extrinsic used by the runtime.
#[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 ExtrinsicMetadata<T: Form = MetaForm> {
/// The type of the extrinsic.
pub ty: T::Type,
/// Extrinsic version.
pub version: u8,
/// The signed extensions in the order they appear in the extrinsic.
pub signed_extensions: Vec<SignedExtensionMetadata<T>>,
}
impl IntoPortable for ExtrinsicMetadata {
type Output = ExtrinsicMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
ExtrinsicMetadata {
ty: registry.register_type(&self.ty),
version: self.version,
signed_extensions: registry.map_into_portable(self.signed_extensions),
}
}
}
/// Metadata of an extrinsic's signed extension.
#[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 SignedExtensionMetadata<T: Form = MetaForm> {
/// The unique signed extension identifier, which may be different from the type name.
pub identifier: T::String,
/// The type of the signed extension, with the data to be included in the extrinsic.
pub ty: T::Type,
/// The type of the additional signed data, with the data to be included in the signed payload
pub additional_signed: T::Type,
}
impl IntoPortable for SignedExtensionMetadata {
type Output = SignedExtensionMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
SignedExtensionMetadata {
identifier: self.identifier.into_portable(registry),
ty: registry.register_type(&self.ty),
additional_signed: registry.register_type(&self.additional_signed),
}
}
}
/// All metadata about an runtime pezpallet.
#[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 PezpalletMetadata<T: Form = MetaForm> {
/// Pezpallet name.
pub name: T::String,
/// Pezpallet storage metadata.
pub storage: Option<PezpalletStorageMetadata<T>>,
/// Pezpallet calls metadata.
pub calls: Option<PezpalletCallMetadata<T>>,
/// Pezpallet event metadata.
pub event: Option<PezpalletEventMetadata<T>>,
/// Pezpallet constants metadata.
pub constants: Vec<PezpalletConstantMetadata<T>>,
/// Pezpallet error metadata.
pub error: Option<PezpalletErrorMetadata<T>>,
/// Define the index of the pezpallet, this index will be used for the encoding of pezpallet event,
/// call and origin variants.
pub index: u8,
}
impl IntoPortable for PezpalletMetadata {
type Output = PezpalletMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletMetadata {
name: self.name.into_portable(registry),
storage: self.storage.map(|storage| storage.into_portable(registry)),
calls: self.calls.map(|calls| calls.into_portable(registry)),
event: self.event.map(|event| event.into_portable(registry)),
constants: registry.map_into_portable(self.constants),
error: self.error.map(|error| error.into_portable(registry)),
index: self.index,
}
}
}
/// All metadata of the pezpallet'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 PezpalletStorageMetadata<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 PezpalletStorageMetadata {
type Output = PezpalletStorageMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletStorageMetadata {
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 pezpallet
#[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 PezpalletCallMetadata<T: Form = MetaForm> {
/// The corresponding enum type for the pezpallet call.
pub ty: T::Type,
}
impl IntoPortable for PezpalletCallMetadata {
type Output = PezpalletCallMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletCallMetadata {
ty: registry.register_type(&self.ty),
}
}
}
impl From<MetaType> for PezpalletCallMetadata {
fn from(ty: MetaType) -> Self {
Self { ty }
}
}
/// Metadata about the pezpallet Event type.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "decode", derive(Decode))]
#[cfg_attr(feature = "serde_full", derive(Serialize))]
pub struct PezpalletEventMetadata<T: Form = MetaForm> {
/// The Event type.
pub ty: T::Type,
}
impl IntoPortable for PezpalletEventMetadata {
type Output = PezpalletEventMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletEventMetadata {
ty: registry.register_type(&self.ty),
}
}
}
impl From<MetaType> for PezpalletEventMetadata {
fn from(ty: MetaType) -> Self {
Self { ty }
}
}
/// Metadata about one pezpallet 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 PezpalletConstantMetadata<T: Form = MetaForm> {
/// Name of the pezpallet constant.
pub name: T::String,
/// Type of the pezpallet 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 PezpalletConstantMetadata {
type Output = PezpalletConstantMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletConstantMetadata {
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 pezpallet 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 PezpalletErrorMetadata<T: Form = MetaForm> {
/// The error type information.
pub ty: T::Type,
}
impl IntoPortable for PezpalletErrorMetadata {
type Output = PezpalletErrorMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletErrorMetadata {
ty: registry.register_type(&self.ty),
}
}
}
impl From<MetaType> for PezpalletErrorMetadata {
fn from(ty: MetaType) -> Self {
Self { ty }
}
}
@@ -0,0 +1,394 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#[cfg(feature = "decode")]
use codec::Decode;
#[cfg(feature = "serde_full")]
use serde::Serialize;
use super::{RuntimeMetadataPrefixed, META_RESERVED};
use codec::Encode;
use scale_info::{
form::{Form, MetaForm, PortableForm},
prelude::{collections::BTreeMap, vec::Vec},
IntoPortable, MetaType, PortableRegistry, Registry,
};
pub use super::v14::{
PezpalletCallMetadata, PezpalletConstantMetadata, PezpalletErrorMetadata, PezpalletEventMetadata,
PezpalletStorageMetadata, StorageEntryMetadata, StorageEntryModifier, StorageEntryType,
StorageHasher,
};
/// Latest runtime metadata
pub type RuntimeMetadataLastVersion = RuntimeMetadataV15;
impl From<RuntimeMetadataLastVersion> for super::RuntimeMetadataPrefixed {
fn from(metadata: RuntimeMetadataLastVersion) -> RuntimeMetadataPrefixed {
RuntimeMetadataPrefixed(META_RESERVED, super::RuntimeMetadata::V15(metadata))
}
}
/// The metadata of a runtime.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "decode", derive(Decode))]
#[cfg_attr(feature = "serde_full", derive(Serialize))]
pub struct RuntimeMetadataV15 {
/// Type registry containing all types used in the metadata.
pub types: PortableRegistry,
/// Metadata of all the pezpallets.
pub pezpallets: Vec<PezpalletMetadata<PortableForm>>,
/// Metadata of the extrinsic.
pub extrinsic: ExtrinsicMetadata<PortableForm>,
/// The type of the `Runtime`.
pub ty: <PortableForm as Form>::Type,
/// Metadata of the Runtime API.
pub apis: Vec<RuntimeApiMetadata<PortableForm>>,
/// The outer enums types as found in the runtime.
pub outer_enums: OuterEnums<PortableForm>,
/// Allows users to add custom types to the metadata.
pub custom: CustomMetadata<PortableForm>,
}
impl RuntimeMetadataV15 {
/// Create a new instance of [`RuntimeMetadataV15`].
pub fn new(
pezpallets: Vec<PezpalletMetadata>,
extrinsic: ExtrinsicMetadata,
runtime_type: MetaType,
apis: Vec<RuntimeApiMetadata>,
outer_enums: OuterEnums,
custom: CustomMetadata,
) -> Self {
let mut registry = Registry::new();
// extrinsic types need to be collected first to ensure CheckMetadataHash hash
// is stable across different metadata versions
let extrinsic = extrinsic.into_portable(&mut registry);
let pezpallets = registry.map_into_portable(pezpallets);
let ty = registry.register_type(&runtime_type);
let apis = registry.map_into_portable(apis);
let outer_enums = outer_enums.into_portable(&mut registry);
let custom = custom.into_portable(&mut registry);
Self {
types: registry.into(),
pezpallets,
extrinsic,
ty,
apis,
outer_enums,
custom,
}
}
}
/// Metadata of a runtime trait.
#[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 RuntimeApiMetadata<T: Form = MetaForm> {
/// Trait name.
pub name: T::String,
/// Trait methods.
pub methods: Vec<RuntimeApiMethodMetadata<T>>,
/// Trait documentation.
pub docs: Vec<T::String>,
}
impl IntoPortable for RuntimeApiMetadata {
type Output = RuntimeApiMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
RuntimeApiMetadata {
name: self.name.into_portable(registry),
methods: registry.map_into_portable(self.methods),
docs: registry.map_into_portable(self.docs),
}
}
}
/// Metadata of a runtime method.
#[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 RuntimeApiMethodMetadata<T: Form = MetaForm> {
/// Method name.
pub name: T::String,
/// Method parameters.
pub inputs: Vec<RuntimeApiMethodParamMetadata<T>>,
/// Method output.
pub output: T::Type,
/// Method documentation.
pub docs: Vec<T::String>,
}
impl IntoPortable for RuntimeApiMethodMetadata {
type Output = RuntimeApiMethodMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
RuntimeApiMethodMetadata {
name: self.name.into_portable(registry),
inputs: registry.map_into_portable(self.inputs),
output: registry.register_type(&self.output),
docs: registry.map_into_portable(self.docs),
}
}
}
/// Metadata of a runtime method parameter.
#[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 RuntimeApiMethodParamMetadata<T: Form = MetaForm> {
/// Parameter name.
pub name: T::String,
/// Parameter type.
pub ty: T::Type,
}
impl IntoPortable for RuntimeApiMethodParamMetadata {
type Output = RuntimeApiMethodParamMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
RuntimeApiMethodParamMetadata {
name: self.name.into_portable(registry),
ty: registry.register_type(&self.ty),
}
}
}
/// Metadata of the extrinsic used by the runtime.
#[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 ExtrinsicMetadata<T: Form = MetaForm> {
/// Extrinsic version.
pub version: u8,
/// The type of the address that signes the extrinsic
pub address_ty: T::Type,
/// The type of the outermost Call enum.
pub call_ty: T::Type,
/// The type of the extrinsic's signature.
pub signature_ty: T::Type,
/// The type of the outermost Extra enum.
pub extra_ty: T::Type,
/// The signed extensions in the order they appear in the extrinsic.
pub signed_extensions: Vec<SignedExtensionMetadata<T>>,
}
impl IntoPortable for ExtrinsicMetadata {
type Output = ExtrinsicMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
// the collection order needs to be stable across different metadata versions
// to ensure CheckMetadataHash hash is invariant
ExtrinsicMetadata {
version: self.version,
address_ty: registry.register_type(&self.address_ty),
call_ty: registry.register_type(&self.call_ty),
signature_ty: registry.register_type(&self.signature_ty),
signed_extensions: registry.map_into_portable(self.signed_extensions),
extra_ty: registry.register_type(&self.extra_ty),
}
}
}
/// Metadata of an extrinsic's signed extension.
#[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 SignedExtensionMetadata<T: Form = MetaForm> {
/// The unique signed extension identifier, which may be different from the type name.
pub identifier: T::String,
/// The type of the signed extension, with the data to be included in the extrinsic.
pub ty: T::Type,
/// The type of the additional signed data, with the data to be included in the signed payload
pub additional_signed: T::Type,
}
impl IntoPortable for SignedExtensionMetadata {
type Output = SignedExtensionMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
SignedExtensionMetadata {
identifier: self.identifier.into_portable(registry),
ty: registry.register_type(&self.ty),
additional_signed: registry.register_type(&self.additional_signed),
}
}
}
/// All metadata about an runtime pezpallet.
#[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 PezpalletMetadata<T: Form = MetaForm> {
/// Pezpallet name.
pub name: T::String,
/// Pezpallet storage metadata.
pub storage: Option<PezpalletStorageMetadata<T>>,
/// Pezpallet calls metadata.
pub calls: Option<PezpalletCallMetadata<T>>,
/// Pezpallet event metadata.
pub event: Option<PezpalletEventMetadata<T>>,
/// Pezpallet constants metadata.
pub constants: Vec<PezpalletConstantMetadata<T>>,
/// Pezpallet error metadata.
pub error: Option<PezpalletErrorMetadata<T>>,
/// Define the index of the pezpallet, this index will be used for the encoding of pezpallet event,
/// call and origin variants.
pub index: u8,
/// Pezpallet documentation.
pub docs: Vec<T::String>,
}
impl IntoPortable for PezpalletMetadata {
type Output = PezpalletMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletMetadata {
name: self.name.into_portable(registry),
storage: self.storage.map(|storage| storage.into_portable(registry)),
calls: self.calls.map(|calls| calls.into_portable(registry)),
event: self.event.map(|event| event.into_portable(registry)),
constants: registry.map_into_portable(self.constants),
error: self.error.map(|error| error.into_portable(registry)),
index: self.index,
docs: registry.map_into_portable(self.docs),
}
}
}
/// Metadata for custom types.
///
/// This map associates a string key to a `CustomValueMetadata`.
#[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 CustomMetadata<T: Form = MetaForm> {
/// The custom map.
pub map: BTreeMap<T::String, CustomValueMetadata<T>>,
}
impl IntoPortable for CustomMetadata {
type Output = CustomMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
let map = self
.map
.into_iter()
.map(|(key, value)| (key.into_portable(registry), value.into_portable(registry)))
.collect();
CustomMetadata { map }
}
}
/// The associated value of a custom metadata type.
#[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 CustomValueMetadata<T: Form = MetaForm> {
/// The custom type.
pub ty: T::Type,
/// The custom value of this type.
pub value: Vec<u8>,
}
impl IntoPortable for CustomValueMetadata {
type Output = CustomValueMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
CustomValueMetadata {
ty: registry.register_type(&self.ty),
value: self.value,
}
}
}
/// The type of the outer enums.
#[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 OuterEnums<T: Form = MetaForm> {
/// The type of the outer `RuntimeCall` enum.
pub call_enum_ty: T::Type,
/// The type of the outer `RuntimeEvent` enum.
pub event_enum_ty: T::Type,
/// The module error type of the
/// [`DispatchError::Module`](https://docs.rs/sp-runtime/24.0.0/sp_runtime/enum.DispatchError.html#variant.Module) variant.
///
/// The `Module` variant will be 5 scale encoded bytes which are normally decoded into
/// an `{ index: u8, error: [u8; 4] }` struct. This type ID points to an enum type which instead
/// interprets the first `index` byte as a pezpallet variant, and the remaining `error` bytes as the
/// appropriate `pezpallet::Error` type. It is an equally valid way to decode the error bytes, and
/// can be more informative.
///
/// # Note
///
/// - This type cannot be used directly to decode `sp_runtime::DispatchError` from the
/// 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 error_enum_ty: T::Type,
}
impl IntoPortable for OuterEnums {
type Output = OuterEnums<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
OuterEnums {
call_enum_ty: registry.register_type(&self.call_enum_ty),
event_enum_ty: registry.register_type(&self.event_enum_ty),
error_enum_ty: registry.register_type(&self.error_enum_ty),
}
}
}
@@ -0,0 +1,613 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#[cfg(feature = "decode")]
use codec::Decode;
#[cfg(feature = "serde_full")]
use serde::Serialize;
use super::{RuntimeMetadataPrefixed, META_RESERVED};
use codec::{Compact, Encode};
use scale_info::{
form::{Form, MetaForm, PortableForm},
prelude::{collections::BTreeMap, vec::Vec},
IntoPortable, PortableRegistry, Registry,
};
// These types have not changed, so we re-export from our v14/v15 definitions:
pub use super::v14::{StorageEntryModifier, StorageEntryType, StorageHasher, StorageEntryMetadata};
pub use super::v15::{CustomMetadata, CustomValueMetadata, OuterEnums};
/// The metadata for a method or function parameter. This is identical to
/// [`crate::v15::RuntimeApiMethodParamMetadata`].
pub type FunctionParamMetadata<T> = super::v15::RuntimeApiMethodParamMetadata<T>;
/// Latest runtime metadata.
pub type RuntimeMetadataLastVersion = RuntimeMetadataV16;
impl From<RuntimeMetadataLastVersion> for super::RuntimeMetadataPrefixed {
fn from(metadata: RuntimeMetadataLastVersion) -> RuntimeMetadataPrefixed {
RuntimeMetadataPrefixed(META_RESERVED, super::RuntimeMetadata::V16(metadata))
}
}
/// The metadata of a runtime.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "decode", derive(Decode))]
#[cfg_attr(feature = "serde_full", derive(Serialize))]
pub struct RuntimeMetadataV16 {
/// Type registry containing all types used in the metadata.
pub types: PortableRegistry,
/// Metadata of all the pallets.
pub pezpallets: Vec<PezpalletMetadata<PortableForm>>,
/// Metadata of the extrinsic.
pub extrinsic: ExtrinsicMetadata<PortableForm>,
/// Metadata of the Runtime API.
pub apis: Vec<RuntimeApiMetadata<PortableForm>>,
/// The outer enums types as found in the runtime.
pub outer_enums: OuterEnums<PortableForm>,
/// Allows users to add custom types to the metadata.
pub custom: CustomMetadata<PortableForm>,
}
impl RuntimeMetadataV16 {
/// Create a new instance of [`RuntimeMetadataV16`].
pub fn new(
pezpallets: Vec<PezpalletMetadata>,
extrinsic: ExtrinsicMetadata,
apis: Vec<RuntimeApiMetadata>,
outer_enums: OuterEnums,
custom: CustomMetadata,
) -> Self {
let mut registry = Registry::new();
// extrinsic types need to be collected first to ensure CheckMetadataHash hash
// is stable across different metadata versions
let extrinsic = extrinsic.into_portable(&mut registry);
let pezpallets = registry.map_into_portable(pezpallets);
let apis = registry.map_into_portable(apis);
let outer_enums = outer_enums.into_portable(&mut registry);
let custom = custom.into_portable(&mut registry);
Self {
types: registry.into(),
pezpallets,
extrinsic,
apis,
outer_enums,
custom,
}
}
}
/// Metadata of a runtime trait.
#[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 RuntimeApiMetadata<T: Form = MetaForm> {
/// Trait name.
pub name: T::String,
/// Trait methods.
pub methods: Vec<RuntimeApiMethodMetadata<T>>,
/// Trait documentation.
pub docs: Vec<T::String>,
/// Runtime API version.
pub version: Compact<u32>,
/// Deprecation info.
pub deprecation_info: ItemDeprecationInfo<T>,
}
impl IntoPortable for RuntimeApiMetadata {
type Output = RuntimeApiMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
RuntimeApiMetadata {
name: self.name.into_portable(registry),
methods: registry.map_into_portable(self.methods),
docs: registry.map_into_portable(self.docs),
version: self.version,
deprecation_info: self.deprecation_info.into_portable(registry),
}
}
}
/// Metadata of a runtime method.
#[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 RuntimeApiMethodMetadata<T: Form = MetaForm> {
/// Method name.
pub name: T::String,
/// Method parameters.
pub inputs: Vec<FunctionParamMetadata<T>>,
/// Method output.
pub output: T::Type,
/// Method documentation.
pub docs: Vec<T::String>,
/// Deprecation info
pub deprecation_info: ItemDeprecationInfo<T>,
}
impl IntoPortable for RuntimeApiMethodMetadata {
type Output = RuntimeApiMethodMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
RuntimeApiMethodMetadata {
name: self.name.into_portable(registry),
inputs: registry.map_into_portable(self.inputs),
output: registry.register_type(&self.output),
docs: registry.map_into_portable(self.docs),
deprecation_info: self.deprecation_info.into_portable(registry),
}
}
}
/// Metadata of the extrinsic used by the runtime.
#[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 ExtrinsicMetadata<T: Form = MetaForm> {
/// Extrinsic versions supported by the runtime.
pub versions: Vec<u8>,
/// The type of the address that signs the extrinsic
pub address_ty: T::Type,
/// The type of the outermost Call enum.
// Dev note: this is also exposed in outer_enums, but we duplicate
// it here so that ExtrinsicMetadata, on its own, provides everything
// needed to decode an extrinsic.
pub call_ty: T::Type,
/// The type of the extrinsic's signature.
pub signature_ty: T::Type,
/// A mapping of supported transaction extrinsic versions to their respective transaction extension indexes.
///
/// For each supported version number, list the indexes, in order, of the extensions used.
pub transaction_extensions_by_version: BTreeMap<u8, Vec<Compact<u32>>>,
/// The transaction extensions in the order they appear in the extrinsic.
pub transaction_extensions: Vec<TransactionExtensionMetadata<T>>,
}
impl IntoPortable for ExtrinsicMetadata {
type Output = ExtrinsicMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
// the collection order needs to be stable across different metadata versions
// to ensure CheckMetadataHash hash is invariant
ExtrinsicMetadata {
versions: self.versions,
address_ty: registry.register_type(&self.address_ty),
call_ty: registry.register_type(&self.call_ty),
signature_ty: registry.register_type(&self.signature_ty),
transaction_extensions_by_version: self.transaction_extensions_by_version,
transaction_extensions: registry.map_into_portable(self.transaction_extensions),
}
}
}
/// Metadata of an extrinsic's transaction extension.
#[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 TransactionExtensionMetadata<T: Form = MetaForm> {
/// The unique transaction extension identifier, which may be different from the type name.
pub identifier: T::String,
/// The type of the transaction extension, with the data to be included in the extrinsic.
pub ty: T::Type,
/// The type of the implicit data, with the data to be included in the signed payload.
pub implicit: T::Type,
}
impl IntoPortable for TransactionExtensionMetadata {
type Output = TransactionExtensionMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
TransactionExtensionMetadata {
identifier: self.identifier.into_portable(registry),
ty: registry.register_type(&self.ty),
implicit: registry.register_type(&self.implicit),
}
}
}
/// All metadata about an runtime pezpallet.
#[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 PezpalletMetadata<T: Form = MetaForm> {
/// Pezpallet name.
pub name: T::String,
/// Pezpallet storage metadata.
pub storage: Option<PezpalletStorageMetadata<T>>,
/// Pezpallet calls metadata.
pub calls: Option<PezpalletCallMetadata<T>>,
/// Pezpallet event metadata.
pub event: Option<PezpalletEventMetadata<T>>,
/// Pezpallet constants metadata.
pub constants: Vec<PezpalletConstantMetadata<T>>,
/// Pezpallet error metadata.
pub error: Option<PezpalletErrorMetadata<T>>,
/// Config's trait associated types.
pub associated_types: Vec<PezpalletAssociatedTypeMetadata<T>>,
/// Pezpallet view functions metadata.
pub view_functions: Vec<PezpalletViewFunctionMetadata<T>>,
/// Define the index of the pezpallet, this index will be used for the encoding of pezpallet event,
/// call and origin variants.
pub index: u8,
/// Pezpallet documentation.
pub docs: Vec<T::String>,
/// Deprecation info
pub deprecation_info: ItemDeprecationInfo<T>,
}
impl IntoPortable for PezpalletMetadata {
type Output = PezpalletMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletMetadata {
name: self.name.into_portable(registry),
storage: self.storage.map(|storage| storage.into_portable(registry)),
calls: self.calls.map(|calls| calls.into_portable(registry)),
event: self.event.map(|event| event.into_portable(registry)),
constants: registry.map_into_portable(self.constants),
error: self.error.map(|error| error.into_portable(registry)),
associated_types: registry.map_into_portable(self.associated_types),
view_functions: registry.map_into_portable(self.view_functions),
index: self.index,
docs: registry.map_into_portable(self.docs),
deprecation_info: self.deprecation_info.into_portable(registry),
}
}
}
/// Metadata for all calls in a pezpallet.
#[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 PezpalletCallMetadata<T: Form = MetaForm> {
/// The corresponding enum type for the pezpallet call.
pub ty: T::Type,
/// Deprecation status of the pezpallet call
pub deprecation_info: EnumDeprecationInfo<T>,
}
impl IntoPortable for PezpalletCallMetadata {
type Output = PezpalletCallMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletCallMetadata {
ty: registry.register_type(&self.ty),
deprecation_info: self.deprecation_info.into_portable(registry),
}
}
}
/// All metadata of the pezpallet'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 PezpalletStorageMetadata<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 PezpalletStorageMetadata {
type Output = PezpalletStorageMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletStorageMetadata {
prefix: self.prefix.into_portable(registry),
entries: registry.map_into_portable(self.entries),
}
}
}
/// Metadata about the pezpallet Event type.
#[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 PezpalletEventMetadata<T: Form = MetaForm> {
/// The Event type.
pub ty: T::Type,
/// Deprecation info
pub deprecation_info: EnumDeprecationInfo<T>,
}
impl IntoPortable for PezpalletEventMetadata {
type Output = PezpalletEventMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletEventMetadata {
ty: registry.register_type(&self.ty),
deprecation_info: self.deprecation_info.into_portable(registry),
}
}
}
/// Metadata about one pezpallet 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 PezpalletConstantMetadata<T: Form = MetaForm> {
/// Name of the pezpallet constant.
pub name: T::String,
/// Type of the pezpallet 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>,
/// Deprecation info
pub deprecation_info: ItemDeprecationInfo<T>,
}
impl IntoPortable for PezpalletConstantMetadata {
type Output = PezpalletConstantMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletConstantMetadata {
name: self.name.into_portable(registry),
ty: registry.register_type(&self.ty),
value: self.value,
docs: registry.map_into_portable(self.docs),
deprecation_info: self.deprecation_info.into_portable(registry),
}
}
}
/// Metadata about a pezpallet 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, T::String: Serialize"))
)]
pub struct PezpalletErrorMetadata<T: Form = MetaForm> {
/// The error type information.
pub ty: T::Type,
/// Deprecation info
pub deprecation_info: EnumDeprecationInfo<T>,
}
impl IntoPortable for PezpalletErrorMetadata {
type Output = PezpalletErrorMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletErrorMetadata {
ty: registry.register_type(&self.ty),
deprecation_info: self.deprecation_info.into_portable(registry),
}
}
}
/// Metadata of a pezpallet's associated type.
#[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 PezpalletAssociatedTypeMetadata<T: Form = MetaForm> {
/// The name of the associated type.
pub name: T::String,
/// The type of the associated type.
pub ty: T::Type,
/// The documentation of the associated type.
pub docs: Vec<T::String>,
}
impl IntoPortable for PezpalletAssociatedTypeMetadata {
type Output = PezpalletAssociatedTypeMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletAssociatedTypeMetadata {
name: self.name.into_portable(registry),
ty: registry.register_type(&self.ty),
docs: registry.map_into_portable(self.docs),
}
}
}
/// Metadata about a pezpallet view function.
#[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 PezpalletViewFunctionMetadata<T: Form = MetaForm> {
/// Method id.
pub id: [u8; 32],
/// Method name.
pub name: T::String,
/// Method parameters.
pub inputs: Vec<FunctionParamMetadata<T>>,
/// Method output.
pub output: T::Type,
/// Method documentation.
pub docs: Vec<T::String>,
/// Deprecation info
pub deprecation_info: ItemDeprecationInfo<T>,
}
impl IntoPortable for PezpalletViewFunctionMetadata {
type Output = PezpalletViewFunctionMetadata<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PezpalletViewFunctionMetadata {
id: self.id,
name: self.name.into_portable(registry),
inputs: registry.map_into_portable(self.inputs),
output: registry.register_type(&self.output),
docs: registry.map_into_portable(self.docs),
deprecation_info: self.deprecation_info.into_portable(registry),
}
}
}
/// Deprecation information for generic items.
#[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 ItemDeprecationInfo<T: Form = MetaForm> {
/// Item is not deprecated.
NotDeprecated,
/// Item is fully deprecated without a note.
DeprecatedWithoutNote,
/// Item is fully deprecated with a note and an optional `since` field.
Deprecated {
/// Note explaining the deprecation
note: T::String,
/// Optional value for noting the version when the deprecation occurred.
since: Option<T::String>,
},
}
impl IntoPortable for ItemDeprecationInfo {
type Output = ItemDeprecationInfo<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
match self {
Self::NotDeprecated => ItemDeprecationInfo::NotDeprecated,
Self::DeprecatedWithoutNote => ItemDeprecationInfo::DeprecatedWithoutNote,
Self::Deprecated { note, since } => {
let note = note.into_portable(registry);
let since = since.map(|x| x.into_portable(registry));
ItemDeprecationInfo::Deprecated { note, since }
}
}
}
}
/// Deprecation information for enums in which specific variants can be deprecated.
/// If the map is empty, then nothing is deprecated.
#[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 EnumDeprecationInfo<T: Form = MetaForm>(pub BTreeMap<u8, VariantDeprecationInfo<T>>);
impl<T: Form> EnumDeprecationInfo<T> {
/// Construct an instance in which nothing is marked for deprecation.
pub fn nothing_deprecated() -> Self {
Self(BTreeMap::new())
}
/// Are any variants deprecated?
pub fn has_deprecated_variants(&self) -> bool {
!self.0.is_empty()
}
/// Is a specific variant deprecated?
pub fn is_variant_deprecated(&self, variant_index: u8) -> bool {
self.0.contains_key(&variant_index)
}
}
impl IntoPortable for EnumDeprecationInfo {
type Output = EnumDeprecationInfo<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
let entries = self
.0
.into_iter()
.map(|(k, entry)| (k, entry.into_portable(registry)));
EnumDeprecationInfo(entries.collect())
}
}
/// Deprecation information for an item or variant in the metadata.
// Dev note: we use #[codec(index)] here to align the indexes with those
// of ItemDeprecationInfo, allowing both can decode into this asa convenience.
#[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 VariantDeprecationInfo<T: Form = MetaForm> {
/// Variant is deprecated without a note.
#[codec(index = 1)]
DeprecatedWithoutNote,
/// Variant is deprecated with a note and an optional `since` field.
#[codec(index = 2)]
Deprecated {
/// Note explaining the deprecation
note: T::String,
/// Optional value for noting the version when the deprecation occurred.
since: Option<T::String>,
},
}
impl IntoPortable for VariantDeprecationInfo {
type Output = VariantDeprecationInfo<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
match self {
Self::Deprecated { note, since } => {
let note = note.into_portable(registry);
let since = since.map(|x| x.into_portable(registry));
VariantDeprecationInfo::Deprecated { note, since }
}
Self::DeprecatedWithoutNote => VariantDeprecationInfo::DeprecatedWithoutNote,
}
}
}
@@ -0,0 +1,282 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Metadata Version 8. Chains old enough to contain this metadata need a way to decode it.
#![allow(missing_docs)]
use crate::decode_different::*;
use codec::{Encode, Output};
cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
use codec::Decode;
use serde::Serialize;
type StringBuf = String;
} else {
extern crate alloc;
use alloc::vec::Vec;
/// On `no_std` we do not support `Decode` and thus `StringBuf` is just `&'static str`.
/// So, if someone tries to decode this stuff on `no_std`, they will get a compilation error.
type StringBuf = &'static str;
}
}
/// Curent prefix of metadata
pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness
/// All the metadata about a function.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct FunctionMetadata {
/// Function name.
pub name: DecodeDifferentStr,
/// A list of arguments this function takes.
pub arguments: DecodeDifferentArray<FunctionArgumentMetadata>,
/// Function documentation.
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about a function argument.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct FunctionArgumentMetadata {
/// Name of the variable for the argument.
pub name: DecodeDifferentStr,
/// Type of the parameter.
pub ty: DecodeDifferentStr,
}
/// All the metadata about an outer event.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct OuterEventMetadata {
/// Name of the event.
pub name: DecodeDifferentStr,
/// A list of event details.
pub events: DecodeDifferentArray<
(&'static str, FnEncode<&'static [EventMetadata]>),
(StringBuf, Vec<EventMetadata>),
>,
}
/// All the metadata about an event.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct EventMetadata {
/// Name of the event.
pub name: DecodeDifferentStr,
/// Arguments of the event.
pub arguments: DecodeDifferentArray<&'static str, StringBuf>,
/// Documentation of the event.
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about one storage entry.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct StorageEntryMetadata {
/// Variable name of the storage entry.
pub name: DecodeDifferentStr,
/// A storage modifier of the storage entry (is it optional? does it have a default value?).
pub modifier: StorageEntryModifier,
/// Type of the value stored in the entry.
pub ty: StorageEntryType,
/// Default value (SCALE encoded).
pub default: ByteGetter,
/// Storage entry documentation.
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about one module constant.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ModuleConstantMetadata {
/// Name of the module constant.
pub name: DecodeDifferentStr,
/// Type of the module constant.
pub ty: DecodeDifferentStr,
/// Value stored in the constant (SCALE encoded).
pub value: ByteGetter,
/// Documentation of the constant.
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about a module error.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ErrorMetadata {
/// Name of the error.
pub name: DecodeDifferentStr,
/// Error variant documentation.
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about errors in a module.
pub trait ModuleErrorMetadata {
/// Returns error metadata.
fn metadata() -> &'static [ErrorMetadata];
}
impl ModuleErrorMetadata for &'static str {
fn metadata() -> &'static [ErrorMetadata] {
&[]
}
}
/// A technical trait to store lazy initiated vec value as static dyn pointer.
pub trait DefaultByte: Send + Sync {
/// A default value (SCALE encoded).
fn default_byte(&self) -> Vec<u8>;
}
/// Wrapper over dyn pointer for accessing a cached once byte value.
#[derive(Clone)]
pub struct DefaultByteGetter(pub &'static dyn DefaultByte);
/// Decode different for static lazy initiated byte value.
pub type ByteGetter = DecodeDifferent<DefaultByteGetter, Vec<u8>>;
impl Encode for DefaultByteGetter {
fn encode_to<W: Output + ?Sized>(&self, dest: &mut W) {
self.0.default_byte().encode_to(dest)
}
}
impl codec::EncodeLike for DefaultByteGetter {}
impl PartialEq<DefaultByteGetter> for DefaultByteGetter {
fn eq(&self, other: &DefaultByteGetter) -> bool {
let left = self.0.default_byte();
let right = other.0.default_byte();
left.eq(&right)
}
}
impl Eq for DefaultByteGetter {}
#[cfg(feature = "std")]
impl serde::Serialize for DefaultByteGetter {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.0.default_byte().serialize(serializer)
}
}
impl core::fmt::Debug for DefaultByteGetter {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
self.0.default_byte().fmt(f)
}
}
/// Hasher used by storage maps
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub enum StorageHasher {
/// 128-bit Blake2 hash.
Blake2_128,
/// 256-bit Blake2 hash.
Blake2_256,
/// 128-bit XX hash.
Twox128,
/// 256-bit XX hash.
Twox256,
/// 64-bit XX hashes concatentation.
Twox64Concat,
}
/// A storage entry type.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub enum StorageEntryType {
/// Plain storage entry (just the value).
Plain(DecodeDifferentStr),
/// A storage map.
Map {
/// Hasher type for the keys.
hasher: StorageHasher,
/// Key type.
key: DecodeDifferentStr,
/// Value type.
value: DecodeDifferentStr,
is_linked: bool,
},
/// Storage Double Map.
DoubleMap {
/// Hasher type for the keys.
hasher: StorageHasher,
/// First key type.
key1: DecodeDifferentStr,
/// Second key type.
key2: DecodeDifferentStr,
/// Value type.
value: DecodeDifferentStr,
/// Hasher for the second key.
key2_hasher: StorageHasher,
},
}
/// 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 = "std", derive(Decode, 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,
}
/// All metadata of the storage.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct StorageMetadata {
/// The common prefix used by all storage entries.
pub prefix: DecodeDifferent<&'static str, StringBuf>,
pub entries: DecodeDifferent<&'static [StorageEntryMetadata], Vec<StorageEntryMetadata>>,
}
/// The metadata of a runtime.
#[derive(Eq, Encode, PartialEq, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct RuntimeMetadataV8 {
pub modules: DecodeDifferentArray<ModuleMetadata>,
}
/// The latest version of the metadata.
pub type RuntimeMetadataLastVersion = RuntimeMetadataV8;
/// All metadata about a runtime module.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ModuleMetadata {
/// Module name.
pub name: DecodeDifferentStr,
pub storage: Option<DecodeDifferent<FnEncode<StorageMetadata>, StorageMetadata>>,
pub calls: ODFnA<FunctionMetadata>,
pub event: ODFnA<EventMetadata>,
pub constants: DFnA<ModuleConstantMetadata>,
pub errors: DFnA<ErrorMetadata>,
}
type ODFnA<T> = Option<DFnA<T>>;
type DFnA<T> = DecodeDifferent<FnEncode<&'static [T]>, Vec<T>>;
@@ -0,0 +1,239 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Metadata Version 9. Networks like/as old as Kusama start here.
//! Chains old enough to contain this metadata need a way to decode it.
#![allow(missing_docs)]
use crate::decode_different::*;
use codec::{Encode, Output};
cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
use codec::Decode;
use serde::Serialize;
type StringBuf = String;
} else {
extern crate alloc;
use alloc::vec::Vec;
/// On `no_std` we do not support `Decode` and thus `StringBuf` is just `&'static str`.
/// So, if someone tries to decode this stuff on `no_std`, they will get a compilation error.
type StringBuf = &'static str;
}
}
/// Curent prefix of metadata
pub const META_RESERVED: u32 = 0x6174656d; // 'meta' warn endianness
/// All the metadata about a function.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct FunctionMetadata {
pub name: DecodeDifferentStr,
pub arguments: DecodeDifferentArray<FunctionArgumentMetadata>,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about a function argument.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct FunctionArgumentMetadata {
pub name: DecodeDifferentStr,
pub ty: DecodeDifferentStr,
}
/// All the metadata about an outer event.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct OuterEventMetadata {
pub name: DecodeDifferentStr,
pub events: DecodeDifferentArray<
(&'static str, FnEncode<&'static [EventMetadata]>),
(StringBuf, Vec<EventMetadata>),
>,
}
/// All the metadata about an event.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct EventMetadata {
pub name: DecodeDifferentStr,
pub arguments: DecodeDifferentArray<&'static str, StringBuf>,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about one storage entry.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct StorageEntryMetadata {
pub name: DecodeDifferentStr,
pub modifier: StorageEntryModifier,
pub ty: StorageEntryType,
pub default: ByteGetter,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about one module constant.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ModuleConstantMetadata {
pub name: DecodeDifferentStr,
pub ty: DecodeDifferentStr,
pub value: ByteGetter,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about a module error.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ErrorMetadata {
pub name: DecodeDifferentStr,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about errors in a module.
pub trait ModuleErrorMetadata {
fn metadata() -> &'static [ErrorMetadata];
}
impl ModuleErrorMetadata for &'static str {
fn metadata() -> &'static [ErrorMetadata] {
&[]
}
}
/// A technical trait to store lazy initiated vec value as static dyn pointer.
pub trait DefaultByte: Send + Sync {
fn default_byte(&self) -> Vec<u8>;
}
/// Wrapper over dyn pointer for accessing a cached once byte value.
#[derive(Clone)]
pub struct DefaultByteGetter(pub &'static dyn DefaultByte);
/// Decode different for static lazy initiated byte value.
pub type ByteGetter = DecodeDifferent<DefaultByteGetter, Vec<u8>>;
impl Encode for DefaultByteGetter {
fn encode_to<W: Output + ?Sized>(&self, dest: &mut W) {
self.0.default_byte().encode_to(dest)
}
}
impl codec::EncodeLike for DefaultByteGetter {}
impl PartialEq<DefaultByteGetter> for DefaultByteGetter {
fn eq(&self, other: &DefaultByteGetter) -> bool {
let left = self.0.default_byte();
let right = other.0.default_byte();
left.eq(&right)
}
}
impl Eq for DefaultByteGetter {}
#[cfg(feature = "std")]
impl serde::Serialize for DefaultByteGetter {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.0.default_byte().serialize(serializer)
}
}
impl core::fmt::Debug for DefaultByteGetter {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
self.0.default_byte().fmt(f)
}
}
/// Hasher used by storage maps
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub enum StorageHasher {
Blake2_128,
Blake2_256,
Blake2_128Concat,
Twox128,
Twox256,
Twox64Concat,
}
/// A storage entry type.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub enum StorageEntryType {
Plain(DecodeDifferentStr),
Map {
hasher: StorageHasher,
key: DecodeDifferentStr,
value: DecodeDifferentStr,
is_linked: bool,
},
DoubleMap {
hasher: StorageHasher,
key1: DecodeDifferentStr,
key2: DecodeDifferentStr,
value: DecodeDifferentStr,
key2_hasher: StorageHasher,
},
}
/// 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 = "std", derive(Decode, Serialize))]
pub enum StorageEntryModifier {
Optional,
Default,
}
/// All metadata of the storage.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct StorageMetadata {
/// The common prefix used by all storage entries.
pub prefix: DecodeDifferent<&'static str, StringBuf>,
pub entries: DecodeDifferent<&'static [StorageEntryMetadata], Vec<StorageEntryMetadata>>,
}
/// The metadata of a runtime.
#[derive(Eq, Encode, PartialEq, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct RuntimeMetadataV9 {
pub modules: DecodeDifferentArray<ModuleMetadata>,
}
/// All metadata about an runtime module.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
pub struct ModuleMetadata {
pub name: DecodeDifferentStr,
pub storage: Option<DecodeDifferent<FnEncode<StorageMetadata>, StorageMetadata>>,
pub calls: ODFnA<FunctionMetadata>,
pub event: ODFnA<EventMetadata>,
pub constants: DFnA<ModuleConstantMetadata>,
pub errors: DFnA<ErrorMetadata>,
}
type ODFnA<T> = Option<DFnA<T>>;
type DFnA<T> = DecodeDifferent<FnEncode<&'static [T]>, Vec<T>>;