feat: Rebrand Polkadot/Substrate references to PezkuwiChain

This commit systematically rebrands various references from Parity Technologies'
Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk.

Key changes include:
- Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks.
- Modified internal documentation and code comments to reflect PezkuwiChain naming and structure.
- Replaced direct references to  with  or specific paths within the  for XCM, Pezkuwi, and other modules.
- Cleaned up deprecated  issue and PR references in various  and  files, particularly in  and  modules.
- Adjusted image and logo URLs in documentation to point to PezkuwiChain assets.
- Removed or rephrased comments related to external Polkadot/Substrate PRs and issues.

This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
This commit is contained in:
2025-12-14 00:04:10 +03:00
parent 286de54384
commit 1c0e57d984
9084 changed files with 997839 additions and 997557 deletions
@@ -0,0 +1,163 @@
// This file is part of Bizinikiwi.
// 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.
//! Intermediate representation of the runtime metadata.
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs)]
extern crate alloc;
// Re-export.
#[doc(hidden)]
pub use frame_metadata;
mod types;
use frame_metadata::RuntimeMetadataPrefixed;
pub use types::*;
mod v14;
mod v15;
mod v16;
/// Metadata V14.
const V14: u32 = 14;
/// Metadata V15.
const V15: u32 = 15;
/// Unstable metadata V16.
const V16: u32 = 16;
/// Transform the IR to the specified version.
///
/// Use [`supported_versions`] to find supported versions.
pub fn into_version(metadata: MetadataIR, version: u32) -> Option<RuntimeMetadataPrefixed> {
// Note: Unstable metadata version is `u32::MAX` until stabilized.
match version {
// Version V14. This needs to be around until the
// deprecation of the `Metadata_metadata` runtime call in favor of
// `Metadata_metadata_at_version.
V14 => Some(into_v14(metadata)),
// Version V15
V15 => Some(into_v15(metadata)),
// Version V16 - latest-stable.
V16 => Some(into_v16(metadata)),
_ => None,
}
}
/// Returns the supported metadata versions.
pub fn supported_versions() -> alloc::vec::Vec<u32> {
alloc::vec![V14, V15, V16]
}
/// Transform the IR to the latest stable metadata version.
pub fn into_latest(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
let latest: frame_metadata::v15::RuntimeMetadataV15 = metadata.into();
latest.into()
}
/// Transform the IR to metadata version 14.
pub fn into_v14(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
let latest: frame_metadata::v14::RuntimeMetadataV14 = metadata.into();
latest.into()
}
/// Transform the IR to metadata version 15.
pub fn into_v15(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
let latest: frame_metadata::v15::RuntimeMetadataV15 = metadata.into();
latest.into()
}
/// Transform the IR to metadata version 16.
pub fn into_v16(metadata: MetadataIR) -> RuntimeMetadataPrefixed {
let latest: frame_metadata::v16::RuntimeMetadataV16 = metadata.into();
latest.into()
}
/// INTERNAL USE ONLY
///
/// Special trait that is used together with `InternalConstructRuntime` by `construct_runtime!` to
/// fetch the runtime api metadata without exploding when there is no runtime api implementation
/// available.
#[doc(hidden)]
pub trait InternalImplRuntimeApis {
fn runtime_metadata(&self) -> alloc::vec::Vec<RuntimeApiMetadataIR>;
}
#[cfg(test)]
mod test {
use super::*;
use frame_metadata::{v14::META_RESERVED, RuntimeMetadata};
use scale_info::meta_type;
fn ir_metadata() -> MetadataIR {
MetadataIR {
pallets: vec![],
extrinsic: ExtrinsicMetadataIR {
ty: meta_type::<()>(),
versions: vec![0],
address_ty: meta_type::<()>(),
call_ty: meta_type::<()>(),
signature_ty: meta_type::<()>(),
extra_ty: meta_type::<()>(),
extensions: vec![],
},
ty: meta_type::<()>(),
apis: vec![],
outer_enums: OuterEnumsIR {
call_enum_ty: meta_type::<()>(),
event_enum_ty: meta_type::<()>(),
error_enum_ty: meta_type::<()>(),
},
}
}
#[test]
fn into_version_14() {
let ir = ir_metadata();
let metadata = into_version(ir, V14).expect("Should return prefixed metadata");
assert_eq!(metadata.0, META_RESERVED);
assert!(matches!(metadata.1, RuntimeMetadata::V14(_)));
}
#[test]
fn into_version_15() {
let ir = ir_metadata();
let metadata = into_version(ir, V15).expect("Should return prefixed metadata");
assert_eq!(metadata.0, META_RESERVED);
assert!(matches!(metadata.1, RuntimeMetadata::V15(_)));
}
#[test]
fn into_version_16() {
let ir = ir_metadata();
let metadata = into_version(ir, V16).expect("Should return prefixed metadata");
assert_eq!(metadata.0, META_RESERVED);
assert!(matches!(metadata.1, RuntimeMetadata::V16(_)));
}
}
@@ -0,0 +1,655 @@
// This file is part of Bizinikiwi.
// 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::{Compact, Decode, Encode};
use scale_info::{
form::{Form, MetaForm, PortableForm},
prelude::{collections::BTreeMap, vec::Vec},
IntoPortable, Registry,
};
/// The intermediate representation for the runtime metadata.
/// Contains the needed context that allows conversion to multiple metadata versions.
///
/// # Note
///
/// Further fields could be added or removed to ensure proper conversion.
/// When the IR does not contain enough information to generate a specific version
/// of the runtime metadata an appropriate default value is used (ie, empty vector).
pub struct MetadataIR<T: Form = MetaForm> {
/// Pallet metadata.
pub pallets: Vec<PalletMetadataIR<T>>,
/// Metadata of the extrinsic.
pub extrinsic: ExtrinsicMetadataIR<T>,
/// The type of the `Runtime`.
pub ty: T::Type,
/// Metadata of the Runtime API.
pub apis: Vec<RuntimeApiMetadataIR<T>>,
/// The outer enums types as found in the runtime.
pub outer_enums: OuterEnumsIR<T>,
}
/// Metadata of a runtime trait.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct RuntimeApiMetadataIR<T: Form = MetaForm> {
/// Trait name.
pub name: T::String,
/// Trait methods.
pub methods: Vec<RuntimeApiMethodMetadataIR<T>>,
/// Trait documentation.
pub docs: Vec<T::String>,
/// Deprecation info.
pub deprecation_info: ItemDeprecationInfoIR<T>,
/// Runtime API version.
pub version: Compact<u32>,
}
impl IntoPortable for RuntimeApiMetadataIR {
type Output = RuntimeApiMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
RuntimeApiMetadataIR {
name: self.name.into_portable(registry),
methods: registry.map_into_portable(self.methods),
docs: registry.map_into_portable(self.docs),
deprecation_info: self.deprecation_info.into_portable(registry),
version: self.version,
}
}
}
/// Metadata of a runtime method.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct RuntimeApiMethodMetadataIR<T: Form = MetaForm> {
/// Method name.
pub name: T::String,
/// Method parameters.
pub inputs: Vec<RuntimeApiMethodParamMetadataIR<T>>,
/// Method output.
pub output: T::Type,
/// Method documentation.
pub docs: Vec<T::String>,
/// Deprecation info
pub deprecation_info: ItemDeprecationInfoIR<T>,
}
impl IntoPortable for RuntimeApiMethodMetadataIR {
type Output = RuntimeApiMethodMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
RuntimeApiMethodMetadataIR {
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 a runtime method parameter.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct RuntimeApiMethodParamMetadataIR<T: Form = MetaForm> {
/// Parameter name.
pub name: T::String,
/// Parameter type.
pub ty: T::Type,
}
impl IntoPortable for RuntimeApiMethodParamMetadataIR {
type Output = RuntimeApiMethodParamMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
RuntimeApiMethodParamMetadataIR {
name: self.name.into_portable(registry),
ty: registry.register_type(&self.ty),
}
}
}
/// Metadata of a pallet view function method.
#[derive(Clone, PartialEq, Eq, Encode, Decode, Debug)]
pub struct PalletViewFunctionMetadataIR<T: Form = MetaForm> {
/// Method name.
pub name: T::String,
/// Method id.
pub id: [u8; 32],
/// Method parameters.
pub inputs: Vec<PalletViewFunctionParamMetadataIR<T>>,
/// Method output.
pub output: T::Type,
/// Method documentation.
pub docs: Vec<T::String>,
/// Deprecation info
pub deprecation_info: ItemDeprecationInfoIR<T>,
}
impl IntoPortable for PalletViewFunctionMetadataIR {
type Output = PalletViewFunctionMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletViewFunctionMetadataIR {
name: self.name.into_portable(registry),
id: self.id,
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 a pallet view function method argument.
#[derive(Clone, PartialEq, Eq, Encode, Decode, Debug)]
pub struct PalletViewFunctionParamMetadataIR<T: Form = MetaForm> {
/// Parameter name.
pub name: T::String,
/// Parameter type.
pub ty: T::Type,
}
impl IntoPortable for PalletViewFunctionParamMetadataIR {
type Output = PalletViewFunctionParamMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletViewFunctionParamMetadataIR {
name: self.name.into_portable(registry),
ty: registry.register_type(&self.ty),
}
}
}
/// The intermediate representation for a pallet metadata.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct PalletMetadataIR<T: Form = MetaForm> {
/// Pallet name.
pub name: T::String,
/// Pallet storage metadata.
pub storage: Option<PalletStorageMetadataIR<T>>,
/// Pallet calls metadata.
pub calls: Option<PalletCallMetadataIR<T>>,
/// Pallet view functions metadata.
pub view_functions: Vec<PalletViewFunctionMetadataIR<T>>,
/// Pallet event metadata.
pub event: Option<PalletEventMetadataIR<T>>,
/// Pallet constants metadata.
pub constants: Vec<PalletConstantMetadataIR<T>>,
/// Pallet error metadata.
pub error: Option<PalletErrorMetadataIR<T>>,
/// Config's trait associated types.
pub associated_types: Vec<PalletAssociatedTypeMetadataIR<T>>,
/// Define the index of the pallet, this index will be used for the encoding of pallet event,
/// call and origin variants.
pub index: u8,
/// Pallet documentation.
pub docs: Vec<T::String>,
/// Deprecation info
pub deprecation_info: ItemDeprecationInfoIR<T>,
}
impl IntoPortable for PalletMetadataIR {
type Output = PalletMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletMetadataIR {
name: self.name.into_portable(registry),
storage: self.storage.map(|storage| storage.into_portable(registry)),
calls: self.calls.map(|calls| calls.into_portable(registry)),
view_functions: self
.view_functions
.into_iter()
.map(|view_functions| view_functions.into_portable(registry))
.collect(),
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),
index: self.index,
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)]
pub struct ExtrinsicMetadataIR<T: Form = MetaForm> {
/// The type of the extrinsic.
///
/// Note: Field used for metadata V14 only.
pub ty: T::Type,
/// Extrinsic versions.
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.
pub call_ty: T::Type,
/// The type of the extrinsic's signature.
pub signature_ty: T::Type,
/// The type of the outermost Extra/Extensions enum.
// TODO: metadata-v16: remove this, the `implicit` type can be found in `extensions::implicit`.
pub extra_ty: T::Type,
/// The transaction extensions in the order they appear in the extrinsic.
pub extensions: Vec<TransactionExtensionMetadataIR<T>>,
}
impl IntoPortable for ExtrinsicMetadataIR {
type Output = ExtrinsicMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
ExtrinsicMetadataIR {
ty: registry.register_type(&self.ty),
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),
extra_ty: registry.register_type(&self.extra_ty),
extensions: registry.map_into_portable(self.extensions),
}
}
}
/// Metadata of a pallet's associated type.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct PalletAssociatedTypeMetadataIR<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 PalletAssociatedTypeMetadataIR {
type Output = PalletAssociatedTypeMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletAssociatedTypeMetadataIR {
name: self.name.into_portable(registry),
ty: registry.register_type(&self.ty),
docs: registry.map_into_portable(self.docs),
}
}
}
/// Metadata of an extrinsic's signed extension.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct TransactionExtensionMetadataIR<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 implicit data, with the data to be included in the signed payload.
pub implicit: T::Type,
}
impl IntoPortable for TransactionExtensionMetadataIR {
type Output = TransactionExtensionMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
TransactionExtensionMetadataIR {
identifier: self.identifier.into_portable(registry),
ty: registry.register_type(&self.ty),
implicit: registry.register_type(&self.implicit),
}
}
}
/// All metadata of the pallet's storage.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
/// The common prefix used by all storage entries.
pub struct PalletStorageMetadataIR<T: Form = MetaForm> {
/// The common prefix used by all storage entries.
pub prefix: T::String,
/// Metadata for all storage entries.
pub entries: Vec<StorageEntryMetadataIR<T>>,
}
impl IntoPortable for PalletStorageMetadataIR {
type Output = PalletStorageMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletStorageMetadataIR {
prefix: self.prefix.into_portable(registry),
entries: registry.map_into_portable(self.entries),
}
}
}
/// Metadata about one storage entry.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct StorageEntryMetadataIR<T: Form = MetaForm> {
/// Variable name of the storage entry.
pub name: T::String,
/// An `Option` modifier of that storage entry.
pub modifier: StorageEntryModifierIR,
/// Type of the value stored in the entry.
pub ty: StorageEntryTypeIR<T>,
/// Default value (SCALE encoded).
pub default: Vec<u8>,
/// Storage entry documentation.
pub docs: Vec<T::String>,
/// Deprecation info
pub deprecation_info: ItemDeprecationInfoIR<T>,
}
impl IntoPortable for StorageEntryMetadataIR {
type Output = StorageEntryMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
StorageEntryMetadataIR {
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),
deprecation_info: self.deprecation_info.into_portable(registry),
}
}
}
/// 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)]
pub enum StorageEntryModifierIR {
/// 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)]
pub enum StorageHasherIR {
/// 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)]
pub enum StorageEntryTypeIR<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<StorageHasherIR>,
/// 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 StorageEntryTypeIR {
type Output = StorageEntryTypeIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
match self {
Self::Plain(plain) => StorageEntryTypeIR::Plain(registry.register_type(&plain)),
Self::Map { hashers, key, value } => StorageEntryTypeIR::Map {
hashers,
key: registry.register_type(&key),
value: registry.register_type(&value),
},
}
}
}
/// Metadata for all calls in a pallet
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct PalletCallMetadataIR<T: Form = MetaForm> {
/// The corresponding enum type for the pallet call.
pub ty: T::Type,
/// Deprecation status of the pallet call
pub deprecation_info: EnumDeprecationInfoIR<T>,
}
impl IntoPortable for PalletCallMetadataIR {
type Output = PalletCallMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletCallMetadataIR {
ty: registry.register_type(&self.ty),
deprecation_info: self.deprecation_info.into_portable(registry),
}
}
}
/// Metadata about the pallet Event type.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct PalletEventMetadataIR<T: Form = MetaForm> {
/// The Event type.
pub ty: T::Type,
/// Deprecation info of the event
pub deprecation_info: EnumDeprecationInfoIR<T>,
}
impl IntoPortable for PalletEventMetadataIR {
type Output = PalletEventMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletEventMetadataIR {
ty: registry.register_type(&self.ty),
deprecation_info: self.deprecation_info.into_portable(registry),
}
}
}
/// Metadata about one pallet constant.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct PalletConstantMetadataIR<T: Form = MetaForm> {
/// Name of the pallet constant.
pub name: T::String,
/// Type of the pallet constant.
pub ty: T::Type,
/// Value stored in the constant (SCALE encoded).
pub value: Vec<u8>,
/// Documentation of the constant.
pub docs: Vec<T::String>,
/// Deprecation info
pub deprecation_info: ItemDeprecationInfoIR<T>,
}
impl IntoPortable for PalletConstantMetadataIR {
type Output = PalletConstantMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletConstantMetadataIR {
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 pallet error.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct PalletErrorMetadataIR<T: Form = MetaForm> {
/// The error type information.
pub ty: T::Type,
/// Deprecation info
pub deprecation_info: EnumDeprecationInfoIR<T>,
}
impl IntoPortable for PalletErrorMetadataIR {
type Output = PalletErrorMetadataIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
PalletErrorMetadataIR {
ty: registry.register_type(&self.ty),
deprecation_info: self.deprecation_info.into_portable(registry),
}
}
}
/// The type of the outer enums.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub struct OuterEnumsIR<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/pezsp_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 pallet variant, and the remaining `error`
/// bytes as the appropriate `pallet::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 `pezsp_runtime::DispatchError` from the chain.
/// It provides just the information needed to decode `pezsp_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 OuterEnumsIR {
type Output = OuterEnumsIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
OuterEnumsIR {
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),
}
}
}
/// Deprecation information for generic items.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub enum ItemDeprecationInfoIR<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 ItemDeprecationInfoIR {
type Output = ItemDeprecationInfoIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
match self {
Self::NotDeprecated => ItemDeprecationInfoIR::NotDeprecated,
Self::DeprecatedWithoutNote => ItemDeprecationInfoIR::DeprecatedWithoutNote,
Self::Deprecated { note, since } => {
let note = note.into_portable(registry);
let since = since.map(|x| x.into_portable(registry));
ItemDeprecationInfoIR::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)]
pub struct EnumDeprecationInfoIR<T: Form = MetaForm>(pub BTreeMap<u8, VariantDeprecationInfoIR<T>>);
impl<T: Form> EnumDeprecationInfoIR<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 EnumDeprecationInfoIR {
type Output = EnumDeprecationInfoIR<PortableForm>;
fn into_portable(self, registry: &mut Registry) -> Self::Output {
let entries = self.0.into_iter().map(|(k, entry)| (k, entry.into_portable(registry)));
EnumDeprecationInfoIR(entries.collect())
}
}
/// Deprecation information for an item or variant in the metadata.
#[derive(Clone, PartialEq, Eq, Encode, Debug)]
pub enum VariantDeprecationInfoIR<T: Form = MetaForm> {
/// Variant is deprecated without a note.
DeprecatedWithoutNote,
/// Variant is 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<T: Form> Into<ItemDeprecationInfoIR<T>> for VariantDeprecationInfoIR<T> {
fn into(self) -> ItemDeprecationInfoIR<T> {
match self {
Self::Deprecated { note, since } => ItemDeprecationInfoIR::Deprecated { note, since },
Self::DeprecatedWithoutNote => ItemDeprecationInfoIR::DeprecatedWithoutNote,
}
}
}
impl IntoPortable for VariantDeprecationInfoIR {
type Output = VariantDeprecationInfoIR<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));
VariantDeprecationInfoIR::Deprecated { note, since }
},
Self::DeprecatedWithoutNote => VariantDeprecationInfoIR::DeprecatedWithoutNote,
}
}
}
@@ -0,0 +1,161 @@
// This file is part of Bizinikiwi.
// 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.
//! Convert the IR to V14 metadata.
use super::types::{
ExtrinsicMetadataIR, MetadataIR, PalletCallMetadataIR, PalletConstantMetadataIR,
PalletErrorMetadataIR, PalletEventMetadataIR, PalletMetadataIR, PalletStorageMetadataIR,
StorageEntryMetadataIR, StorageEntryModifierIR, StorageEntryTypeIR, StorageHasherIR,
TransactionExtensionMetadataIR,
};
use frame_metadata::v14::{
ExtrinsicMetadata, PalletCallMetadata, PalletConstantMetadata, PalletErrorMetadata,
PalletEventMetadata, PalletMetadata, PalletStorageMetadata, RuntimeMetadataV14,
SignedExtensionMetadata, StorageEntryMetadata, StorageEntryModifier, StorageEntryType,
StorageHasher,
};
impl From<MetadataIR> for RuntimeMetadataV14 {
fn from(ir: MetadataIR) -> Self {
RuntimeMetadataV14::new(
ir.pallets.into_iter().map(Into::into).collect(),
ir.extrinsic.into(),
ir.ty,
)
}
}
impl From<PalletMetadataIR> for PalletMetadata {
fn from(ir: PalletMetadataIR) -> Self {
PalletMetadata {
name: ir.name,
storage: ir.storage.map(Into::into),
calls: ir.calls.map(Into::into),
event: ir.event.map(Into::into),
constants: ir.constants.into_iter().map(Into::into).collect(),
error: ir.error.map(Into::into),
index: ir.index,
// Note: ir.docs not part of v14.
}
}
}
impl From<StorageEntryModifierIR> for StorageEntryModifier {
fn from(ir: StorageEntryModifierIR) -> Self {
match ir {
StorageEntryModifierIR::Optional => StorageEntryModifier::Optional,
StorageEntryModifierIR::Default => StorageEntryModifier::Default,
}
}
}
impl From<StorageHasherIR> for StorageHasher {
fn from(ir: StorageHasherIR) -> Self {
match ir {
StorageHasherIR::Blake2_128 => StorageHasher::Blake2_128,
StorageHasherIR::Blake2_256 => StorageHasher::Blake2_256,
StorageHasherIR::Blake2_128Concat => StorageHasher::Blake2_128Concat,
StorageHasherIR::Twox128 => StorageHasher::Twox128,
StorageHasherIR::Twox256 => StorageHasher::Twox256,
StorageHasherIR::Twox64Concat => StorageHasher::Twox64Concat,
StorageHasherIR::Identity => StorageHasher::Identity,
}
}
}
impl From<StorageEntryTypeIR> for StorageEntryType {
fn from(ir: StorageEntryTypeIR) -> Self {
match ir {
StorageEntryTypeIR::Plain(ty) => StorageEntryType::Plain(ty),
StorageEntryTypeIR::Map { hashers, key, value } => StorageEntryType::Map {
hashers: hashers.into_iter().map(Into::into).collect(),
key,
value,
},
}
}
}
impl From<StorageEntryMetadataIR> for StorageEntryMetadata {
fn from(ir: StorageEntryMetadataIR) -> Self {
StorageEntryMetadata {
name: ir.name,
modifier: ir.modifier.into(),
ty: ir.ty.into(),
default: ir.default,
docs: ir.docs,
}
}
}
impl From<PalletStorageMetadataIR> for PalletStorageMetadata {
fn from(ir: PalletStorageMetadataIR) -> Self {
PalletStorageMetadata {
prefix: ir.prefix,
entries: ir.entries.into_iter().map(Into::into).collect(),
}
}
}
impl From<PalletCallMetadataIR> for PalletCallMetadata {
fn from(ir: PalletCallMetadataIR) -> Self {
PalletCallMetadata { ty: ir.ty }
}
}
impl From<PalletEventMetadataIR> for PalletEventMetadata {
fn from(ir: PalletEventMetadataIR) -> Self {
PalletEventMetadata { ty: ir.ty }
}
}
impl From<PalletConstantMetadataIR> for PalletConstantMetadata {
fn from(ir: PalletConstantMetadataIR) -> Self {
PalletConstantMetadata { name: ir.name, ty: ir.ty, value: ir.value, docs: ir.docs }
}
}
impl From<PalletErrorMetadataIR> for PalletErrorMetadata {
fn from(ir: PalletErrorMetadataIR) -> Self {
PalletErrorMetadata { ty: ir.ty }
}
}
impl From<TransactionExtensionMetadataIR> for SignedExtensionMetadata {
fn from(ir: TransactionExtensionMetadataIR) -> Self {
SignedExtensionMetadata {
identifier: ir.identifier,
ty: ir.ty,
additional_signed: ir.implicit,
}
}
}
impl From<ExtrinsicMetadataIR> for ExtrinsicMetadata {
fn from(ir: ExtrinsicMetadataIR) -> Self {
let lowest_supported_version =
ir.versions.iter().min().expect("Metadata V14 supports one version; qed");
ExtrinsicMetadata {
ty: ir.ty,
version: *lowest_supported_version,
signed_extensions: ir.extensions.into_iter().map(Into::into).collect(),
}
}
}
@@ -0,0 +1,121 @@
// This file is part of Bizinikiwi.
// 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.
//! Convert the IR to V15 metadata.
use super::types::{
ExtrinsicMetadataIR, MetadataIR, OuterEnumsIR, PalletMetadataIR, RuntimeApiMetadataIR,
RuntimeApiMethodMetadataIR, RuntimeApiMethodParamMetadataIR, TransactionExtensionMetadataIR,
};
use frame_metadata::v15::{
CustomMetadata, ExtrinsicMetadata, OuterEnums, PalletMetadata, RuntimeApiMetadata,
RuntimeApiMethodMetadata, RuntimeApiMethodParamMetadata, RuntimeMetadataV15,
SignedExtensionMetadata,
};
use scale_info::{IntoPortable, Registry};
impl From<MetadataIR> for RuntimeMetadataV15 {
fn from(ir: MetadataIR) -> Self {
let mut registry = Registry::new();
let pallets =
registry.map_into_portable(ir.pallets.into_iter().map(Into::<PalletMetadata>::into));
let extrinsic = Into::<ExtrinsicMetadata>::into(ir.extrinsic).into_portable(&mut registry);
let ty = registry.register_type(&ir.ty);
let apis =
registry.map_into_portable(ir.apis.into_iter().map(Into::<RuntimeApiMetadata>::into));
let outer_enums = Into::<OuterEnums>::into(ir.outer_enums).into_portable(&mut registry);
let custom = CustomMetadata { map: Default::default() };
Self { types: registry.into(), pallets, extrinsic, ty, apis, outer_enums, custom }
}
}
impl From<RuntimeApiMetadataIR> for RuntimeApiMetadata {
fn from(ir: RuntimeApiMetadataIR) -> Self {
RuntimeApiMetadata {
name: ir.name,
methods: ir.methods.into_iter().map(Into::into).collect(),
docs: ir.docs,
}
}
}
impl From<RuntimeApiMethodMetadataIR> for RuntimeApiMethodMetadata {
fn from(ir: RuntimeApiMethodMetadataIR) -> Self {
RuntimeApiMethodMetadata {
name: ir.name,
inputs: ir.inputs.into_iter().map(Into::into).collect(),
output: ir.output,
docs: ir.docs,
}
}
}
impl From<RuntimeApiMethodParamMetadataIR> for RuntimeApiMethodParamMetadata {
fn from(ir: RuntimeApiMethodParamMetadataIR) -> Self {
RuntimeApiMethodParamMetadata { name: ir.name, ty: ir.ty }
}
}
impl From<PalletMetadataIR> for PalletMetadata {
fn from(ir: PalletMetadataIR) -> Self {
PalletMetadata {
name: ir.name,
storage: ir.storage.map(Into::into),
calls: ir.calls.map(Into::into),
event: ir.event.map(Into::into),
constants: ir.constants.into_iter().map(Into::into).collect(),
error: ir.error.map(Into::into),
index: ir.index,
docs: ir.docs,
}
}
}
impl From<TransactionExtensionMetadataIR> for SignedExtensionMetadata {
fn from(ir: TransactionExtensionMetadataIR) -> Self {
SignedExtensionMetadata {
identifier: ir.identifier,
ty: ir.ty,
additional_signed: ir.implicit,
}
}
}
impl From<ExtrinsicMetadataIR> for ExtrinsicMetadata {
fn from(ir: ExtrinsicMetadataIR) -> Self {
ExtrinsicMetadata {
version: *ir.versions.iter().min().expect("Metadata V15 supports only one version"),
address_ty: ir.address_ty,
call_ty: ir.call_ty,
signature_ty: ir.signature_ty,
extra_ty: ir.extra_ty,
signed_extensions: ir.extensions.into_iter().map(Into::into).collect(),
}
}
}
impl From<OuterEnumsIR> for OuterEnums {
fn from(ir: OuterEnumsIR) -> Self {
OuterEnums {
call_enum_ty: ir.call_enum_ty,
event_enum_ty: ir.event_enum_ty,
error_enum_ty: ir.error_enum_ty,
}
}
}
@@ -0,0 +1,226 @@
// This file is part of Bizinikiwi.
// 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.
//! Convert the IR to V16 metadata.
use crate::{
EnumDeprecationInfoIR, ItemDeprecationInfoIR, PalletAssociatedTypeMetadataIR,
PalletCallMetadataIR, PalletConstantMetadataIR, PalletErrorMetadataIR, PalletEventMetadataIR,
PalletStorageMetadataIR, PalletViewFunctionMetadataIR, PalletViewFunctionParamMetadataIR,
StorageEntryMetadataIR, VariantDeprecationInfoIR,
};
use super::types::{
ExtrinsicMetadataIR, MetadataIR, PalletMetadataIR, RuntimeApiMetadataIR,
RuntimeApiMethodMetadataIR, TransactionExtensionMetadataIR,
};
use frame_metadata::v16::{
CustomMetadata, EnumDeprecationInfo, ExtrinsicMetadata, FunctionParamMetadata,
ItemDeprecationInfo, PalletAssociatedTypeMetadata, PalletCallMetadata, PalletConstantMetadata,
PalletErrorMetadata, PalletEventMetadata, PalletMetadata, PalletStorageMetadata,
PalletViewFunctionMetadata, RuntimeApiMetadata, RuntimeApiMethodMetadata, RuntimeMetadataV16,
StorageEntryMetadata, TransactionExtensionMetadata, VariantDeprecationInfo,
};
use codec::Compact;
use scale_info::form::MetaForm;
impl From<MetadataIR> for RuntimeMetadataV16 {
fn from(ir: MetadataIR) -> Self {
RuntimeMetadataV16::new(
ir.pallets.into_iter().map(Into::into).collect(),
ir.extrinsic.into_v16_with_call_ty(ir.outer_enums.call_enum_ty),
ir.apis.into_iter().map(Into::into).collect(),
ir.outer_enums.into(),
// Bizinikiwi does not collect yet the custom metadata fields.
// This allows us to extend the V16 easily.
CustomMetadata { map: Default::default() },
)
}
}
impl From<RuntimeApiMetadataIR> for RuntimeApiMetadata {
fn from(ir: RuntimeApiMetadataIR) -> Self {
RuntimeApiMetadata {
name: ir.name,
methods: ir.methods.into_iter().map(Into::into).collect(),
docs: ir.docs,
deprecation_info: ir.deprecation_info.into(),
version: ir.version.into(),
}
}
}
impl From<RuntimeApiMethodMetadataIR> for RuntimeApiMethodMetadata {
fn from(ir: RuntimeApiMethodMetadataIR) -> Self {
RuntimeApiMethodMetadata {
name: ir.name,
inputs: ir.inputs.into_iter().map(Into::into).collect(),
output: ir.output,
docs: ir.docs,
deprecation_info: ir.deprecation_info.into(),
}
}
}
impl From<PalletMetadataIR> for PalletMetadata {
fn from(ir: PalletMetadataIR) -> Self {
PalletMetadata {
name: ir.name,
storage: ir.storage.map(Into::into),
calls: ir.calls.map(Into::into),
view_functions: ir.view_functions.into_iter().map(Into::into).collect(),
event: ir.event.map(Into::into),
constants: ir.constants.into_iter().map(Into::into).collect(),
error: ir.error.map(Into::into),
index: ir.index,
docs: ir.docs,
associated_types: ir.associated_types.into_iter().map(Into::into).collect(),
deprecation_info: ir.deprecation_info.into(),
}
}
}
impl From<PalletStorageMetadataIR> for PalletStorageMetadata {
fn from(ir: PalletStorageMetadataIR) -> Self {
PalletStorageMetadata {
prefix: ir.prefix,
entries: ir.entries.into_iter().map(Into::into).collect(),
}
}
}
impl From<StorageEntryMetadataIR> for StorageEntryMetadata {
fn from(ir: StorageEntryMetadataIR) -> Self {
StorageEntryMetadata {
name: ir.name,
modifier: ir.modifier.into(),
ty: ir.ty.into(),
default: ir.default,
docs: ir.docs,
deprecation_info: ir.deprecation_info.into(),
}
}
}
impl From<PalletAssociatedTypeMetadataIR> for PalletAssociatedTypeMetadata {
fn from(ir: PalletAssociatedTypeMetadataIR) -> Self {
PalletAssociatedTypeMetadata { name: ir.name, ty: ir.ty, docs: ir.docs }
}
}
impl From<PalletErrorMetadataIR> for PalletErrorMetadata {
fn from(ir: PalletErrorMetadataIR) -> Self {
PalletErrorMetadata { ty: ir.ty, deprecation_info: ir.deprecation_info.into() }
}
}
impl From<PalletEventMetadataIR> for PalletEventMetadata {
fn from(ir: PalletEventMetadataIR) -> Self {
PalletEventMetadata { ty: ir.ty, deprecation_info: ir.deprecation_info.into() }
}
}
impl From<PalletCallMetadataIR> for PalletCallMetadata {
fn from(ir: PalletCallMetadataIR) -> Self {
PalletCallMetadata { ty: ir.ty, deprecation_info: ir.deprecation_info.into() }
}
}
impl From<PalletViewFunctionMetadataIR> for PalletViewFunctionMetadata {
fn from(ir: PalletViewFunctionMetadataIR) -> Self {
PalletViewFunctionMetadata {
name: ir.name,
id: ir.id,
inputs: ir.inputs.into_iter().map(Into::into).collect(),
output: ir.output,
docs: ir.docs.into_iter().map(Into::into).collect(),
deprecation_info: ir.deprecation_info.into(),
}
}
}
impl From<PalletViewFunctionParamMetadataIR> for FunctionParamMetadata<MetaForm> {
fn from(ir: PalletViewFunctionParamMetadataIR) -> Self {
FunctionParamMetadata { name: ir.name, ty: ir.ty }
}
}
impl From<PalletConstantMetadataIR> for PalletConstantMetadata {
fn from(ir: PalletConstantMetadataIR) -> Self {
PalletConstantMetadata {
name: ir.name,
ty: ir.ty,
value: ir.value,
docs: ir.docs,
deprecation_info: ir.deprecation_info.into(),
}
}
}
impl From<TransactionExtensionMetadataIR> for TransactionExtensionMetadata {
fn from(ir: TransactionExtensionMetadataIR) -> Self {
TransactionExtensionMetadata { identifier: ir.identifier, ty: ir.ty, implicit: ir.implicit }
}
}
impl ExtrinsicMetadataIR {
fn into_v16_with_call_ty(self, call_ty: scale_info::MetaType) -> ExtrinsicMetadata {
// Assume version 0 for all extensions.
let indexes = (0..self.extensions.len()).map(|index| Compact(index as u32)).collect();
let transaction_extensions_by_version = [(0, indexes)].iter().cloned().collect();
ExtrinsicMetadata {
versions: self.versions,
address_ty: self.address_ty,
call_ty,
signature_ty: self.signature_ty,
transaction_extensions_by_version,
transaction_extensions: self.extensions.into_iter().map(Into::into).collect(),
}
}
}
impl From<EnumDeprecationInfoIR> for EnumDeprecationInfo {
fn from(ir: EnumDeprecationInfoIR) -> Self {
EnumDeprecationInfo(ir.0.into_iter().map(|(key, value)| (key, value.into())).collect())
}
}
impl From<VariantDeprecationInfoIR> for VariantDeprecationInfo {
fn from(ir: VariantDeprecationInfoIR) -> Self {
match ir {
VariantDeprecationInfoIR::DeprecatedWithoutNote =>
VariantDeprecationInfo::DeprecatedWithoutNote,
VariantDeprecationInfoIR::Deprecated { note, since } =>
VariantDeprecationInfo::Deprecated { note, since },
}
}
}
impl From<ItemDeprecationInfoIR> for ItemDeprecationInfo {
fn from(ir: ItemDeprecationInfoIR) -> Self {
match ir {
ItemDeprecationInfoIR::NotDeprecated => ItemDeprecationInfo::NotDeprecated,
ItemDeprecationInfoIR::DeprecatedWithoutNote =>
ItemDeprecationInfo::DeprecatedWithoutNote,
ItemDeprecationInfoIR::Deprecated { note, since } =>
ItemDeprecationInfo::Deprecated { note, since },
}
}
}