fix: Convert vendor/pezkuwi-subxt from submodule to regular directory

This commit is contained in:
2025-12-19 16:45:24 +03:00
parent 9a52edf0df
commit fdd023c499
393 changed files with 154124 additions and 1 deletions
@@ -0,0 +1,95 @@
// Copyright 2019-2025 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use scale_info::{
Path, Type, TypeInfo,
build::{Fields, Variants},
};
/// See the `ModuleErrorType` in `pezkuwi_subxt_codegen` for more info on the different DispatchError
/// types that we've encountered. We need the path to match `sp_runtime::DispatchError`, otherwise
/// we could just implement roughly the correct types and derive TypeInfo on them.
///
/// This type has TypeInfo compatible with the `NamedField` version of the DispatchError.
/// This is the oldest version that subxt supports:
/// `DispatchError::Module { index: u8, error: u8 }`
pub enum NamedFieldDispatchError {}
impl TypeInfo for NamedFieldDispatchError {
type Identity = Self;
fn type_info() -> Type {
Type::builder()
.path(Path::new("DispatchError", "sp_runtime"))
.variant(Variants::new().variant("Module", |builder| {
builder
.fields(
Fields::named()
.field(|b| b.name("error").ty::<u8>())
.field(|b| b.name("index").ty::<u8>()),
)
.index(0)
}))
}
}
/// This type has TypeInfo compatible with the `LegacyError` version of the DispatchError.
/// This is the version wasn't around for long:
/// `DispatchError::Module ( sp_runtime::ModuleError { index: u8, error: u8 } )`
pub enum LegacyDispatchError {}
impl TypeInfo for LegacyDispatchError {
type Identity = Self;
fn type_info() -> Type {
struct ModuleError;
impl TypeInfo for ModuleError {
type Identity = Self;
fn type_info() -> Type {
Type::builder()
.path(Path::new("ModuleError", "sp_runtime"))
.composite(
Fields::named()
.field(|b| b.name("index").ty::<u8>())
.field(|b| b.name("error").ty::<u8>()),
)
}
}
Type::builder()
.path(Path::new("DispatchError", "sp_runtime"))
.variant(Variants::new().variant("Module", |builder| {
builder
.fields(Fields::unnamed().field(|b| b.ty::<ModuleError>()))
.index(0)
}))
}
}
/// This type has TypeInfo compatible with the `ArrayError` version of the DispatchError.
/// This is the current version:
/// `DispatchError::Module ( sp_runtime::ModuleError { index: u8, error: [u8; 4] } )`
pub enum ArrayDispatchError {}
impl TypeInfo for ArrayDispatchError {
type Identity = Self;
fn type_info() -> Type {
struct ModuleError;
impl TypeInfo for ModuleError {
type Identity = Self;
fn type_info() -> Type {
Type::builder()
.path(Path::new("ModuleError", "sp_runtime"))
.composite(
Fields::named()
.field(|b| b.name("index").ty::<u8>())
.field(|b| b.name("error").ty::<[u8; 4]>()),
)
}
}
Type::builder()
.path(Path::new("DispatchError", "sp_runtime"))
.variant(Variants::new().variant("Module", |builder| {
builder
.fields(Fields::unnamed().field(|b| b.ty::<ModuleError>()))
.index(0)
}))
}
}
@@ -0,0 +1,90 @@
// Copyright 2019-2025 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use codec::Encode;
use frame_metadata::RuntimeMetadataPrefixed;
use frame_metadata::v15::{CustomMetadata, ExtrinsicMetadata, OuterEnums, RuntimeMetadataV15};
use scale_info::TypeInfo;
use scale_info::form::PortableForm;
use scale_info::{IntoPortable, meta_type};
use std::collections::BTreeMap;
pub mod dispatch_error;
/// Generate metadata which contains a `Foo { a: u8, b: &str }` custom value.
pub fn metadata_custom_values_foo() -> RuntimeMetadataPrefixed {
let mut registry = scale_info::Registry::new();
// create foo value and type:
#[derive(TypeInfo, Encode)]
struct Foo {
a: u8,
b: &'static str,
}
let foo_value_metadata: frame_metadata::v15::CustomValueMetadata<PortableForm> = {
let value = Foo {
a: 42,
b: "Have a great day!",
};
let foo_ty = scale_info::MetaType::new::<Foo>();
let foo_ty_id = registry.register_type(&foo_ty);
frame_metadata::v15::CustomValueMetadata {
ty: foo_ty_id,
value: value.encode(),
}
};
let invalid_type_id_metadata: frame_metadata::v15::CustomValueMetadata<PortableForm> = {
frame_metadata::v15::CustomValueMetadata {
ty: u32::MAX.into(),
value: vec![0, 1, 2, 3],
}
};
// We don't care about the extrinsic type.
let extrinsic = ExtrinsicMetadata {
version: 0,
signed_extensions: vec![],
address_ty: meta_type::<()>(),
call_ty: meta_type::<()>(),
signature_ty: meta_type::<()>(),
extra_ty: meta_type::<()>(),
};
let pallets = vec![];
let extrinsic = extrinsic.into_portable(&mut registry);
let unit_ty = registry.register_type(&meta_type::<()>());
// Metadata needs to contain this DispatchError, since codegen looks for it.
registry.register_type(&meta_type::<dispatch_error::ArrayDispatchError>());
let metadata = RuntimeMetadataV15 {
types: registry.into(),
pallets,
extrinsic,
ty: unit_ty,
apis: vec![],
outer_enums: OuterEnums {
call_enum_ty: unit_ty,
event_enum_ty: unit_ty,
error_enum_ty: unit_ty,
},
custom: CustomMetadata {
// provide foo twice, to make sure nothing breaks in these cases:
map: BTreeMap::from_iter([
("Foo".into(), foo_value_metadata.clone()),
("foo".into(), foo_value_metadata.clone()),
("12".into(), foo_value_metadata.clone()),
("&Hello".into(), foo_value_metadata),
("InvalidTypeId".into(), invalid_type_id_metadata),
]),
},
};
RuntimeMetadataPrefixed::from(metadata)
}
@@ -0,0 +1,17 @@
// Copyright 2019-2025 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use codec::Encode;
use std::io::{self, Write};
/// Creates some scale encoded metadata with custom values and writes it out to stdout (as raw bytes)
///
/// Can be called from the root of the project with: `cargo run --bin generate-custom-metadata > output.scale`.
fn main() -> io::Result<()> {
let metadata_prefixed = generate_custom_metadata::metadata_custom_values_foo();
let stdout = io::stdout();
let mut handle = stdout.lock();
handle.write_all(&metadata_prefixed.encode())?;
Ok(())
}