mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-22 23:08:00 +00:00
78a106f059
* Update frame-metadata to the latest branch Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Add outer enum types Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Extend the extrinsic with address,call,sign,extra types Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Codegen test Event, Error and Call for outer enums Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Revert "Codegen test Event, Error and Call for outer enums" This reverts commit db542dca0369eedd257a7ec031d5b5549bc46a88. * Update frame-metadata from the latest release Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Update scale-info Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * codegen/error: Support v15 message Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Convert v14 to v15 Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata/retain: Adjust to extrinsic type for V15 Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata/validation: Adjust hashing for extrinsic types V15 Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * scripts: Fetch V15 and output codegen for full_client only Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * subxt/blocks: Use extrinsic types directly Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * testing: Fetch V15 for build script Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * artifacts: Generate from latest polkadot version Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * codegen: Fetch legacy with old API for v14 only Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * rpc: Fetch metadata versions Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * client: Fetch latest unstable then V15 then V14 Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * testing: Adjust testing API to latest interface Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Adjust clippy Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Generate the `RuntimeError` type for V14 Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Remove testing files Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * testing/staking: Remove controller account from bond Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata/validation: Use specific variants for hashing RuntimeCall Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * XXX: Custom Substrate binary: must revert with next release Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * XXX: To revert: CI use hardcoded substrate Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * codegen: Use v15 outer enum types Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Retain outer enum types Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * codegen: Use outer enum types instead of generating them Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Update artifacts Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Revert "XXX: Custom Substrate binary: must revert with next release" This reverts commit e9705298661919f5769720b35030759fb8a7b01d. Revert "XXX: To revert: CI use hardcoded substrate" This reverts commit b18a5a0985a56ee4ad99bc9a1c0f9cd733cf4271. * testing: Include env for dummy wat contracts Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Adjsut clippy Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * ci: Use new link for fetching latest substrate binary Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * tests: Include dummy RuntimeEvent into test metadata Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * ci: Bump light-client timeout tests to 25min Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata/validation: Use specific pallets as provided Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * testing: Rename metadata constant Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Use call_ty instead of signature_ty Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Rename retaining variant function Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Use Option<&[&str]> Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * online_client: Fetch V15 metadata explicitely Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata/validation: Include the hash of the outer enum types Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Fix sign typo Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * artifacts: Update the artifacts Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * subxt: Remove RootError RootEvent and RootExtrinsic traits Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Update polkadot.rs Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata/tests: Ensure outer enum variants are retained Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * scripts: Include multiple pallets for our decoding purposes Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * subxt: Apply clippy Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * artifacts: Update small metadata Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * error: Keep raw bytes for the ModuleError representation Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * error: Modify docs to not include links Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * subxt/tests: Propagate `RuntimeCall` to outer enums Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * subxt: Provide proper byte slice for decoding Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Update artifacts Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * cli/tests: Adjust expected pallets message Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Test conversion from v14 to v15 Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Fix typo Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Update subxt/src/blocks/extrinsic_types.rs Co-authored-by: James Wilson <james@jsdw.me> * metadata: Simplify type path for RuntimeError Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata/validation: Use visited ids per outer enum Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * error: Remove RawModuleError Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Fix new clippy error from updated rust version Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> Co-authored-by: James Wilson <james@jsdw.me>
110 lines
3.7 KiB
Rust
110 lines
3.7 KiB
Rust
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
|
|
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
|
// see LICENSE for license details.
|
|
|
|
pub mod dispatch_error;
|
|
mod metadata_test_runner;
|
|
|
|
use frame_metadata::{
|
|
v15::{
|
|
CustomMetadata, ExtrinsicMetadata, OuterEnums, PalletMetadata, PalletStorageMetadata,
|
|
RuntimeMetadataV15, StorageEntryMetadata,
|
|
},
|
|
RuntimeMetadataPrefixed,
|
|
};
|
|
use scale_info::{meta_type, IntoPortable, TypeInfo};
|
|
|
|
pub use metadata_test_runner::MetadataTestRunner;
|
|
|
|
/// Given some pallet metadata, generate a [`RuntimeMetadataPrefixed`] struct.
|
|
/// We default to a useless extrinsic type, and register a fake `DispatchError`
|
|
/// type matching the generic type param provided.
|
|
pub fn generate_metadata_from_pallets_custom_dispatch_error<DispatchError: TypeInfo + 'static>(
|
|
pallets: Vec<PalletMetadata>,
|
|
) -> RuntimeMetadataPrefixed {
|
|
// 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::<()>(),
|
|
};
|
|
|
|
// Construct metadata manually from our types (See `RuntimeMetadataV15::new()`).
|
|
// Add any extra types we need to the registry.
|
|
let mut registry = scale_info::Registry::new();
|
|
let pallets = registry.map_into_portable(pallets);
|
|
let extrinsic = extrinsic.into_portable(&mut registry);
|
|
|
|
#[derive(TypeInfo)]
|
|
struct Runtime;
|
|
#[derive(TypeInfo)]
|
|
enum RuntimeCall {}
|
|
#[derive(TypeInfo)]
|
|
enum RuntimeEvent {}
|
|
#[derive(TypeInfo)]
|
|
enum RuntimeError {}
|
|
|
|
let ty = registry.register_type(&meta_type::<Runtime>());
|
|
let runtime_call = registry.register_type(&meta_type::<RuntimeCall>());
|
|
let runtime_event = registry.register_type(&meta_type::<RuntimeEvent>());
|
|
let runtime_error = registry.register_type(&meta_type::<RuntimeError>());
|
|
|
|
// Metadata needs to contain this DispatchError, since codegen looks for it.
|
|
registry.register_type(&meta_type::<DispatchError>());
|
|
|
|
let metadata = RuntimeMetadataV15 {
|
|
types: registry.into(),
|
|
pallets,
|
|
extrinsic,
|
|
ty,
|
|
apis: vec![],
|
|
outer_enums: OuterEnums {
|
|
call_enum_ty: runtime_call,
|
|
event_enum_ty: runtime_event,
|
|
error_enum_ty: runtime_error,
|
|
},
|
|
custom: CustomMetadata {
|
|
map: Default::default(),
|
|
},
|
|
};
|
|
|
|
RuntimeMetadataPrefixed::from(metadata)
|
|
}
|
|
|
|
/// Given some pallet metadata, generate a [`RuntimeMetadataPrefixed`] struct.
|
|
/// We default to a useless extrinsic type, and register a fake `DispatchError`
|
|
/// type so that codegen is happy with the metadata generated.
|
|
pub fn generate_metadata_from_pallets(pallets: Vec<PalletMetadata>) -> RuntimeMetadataPrefixed {
|
|
generate_metadata_from_pallets_custom_dispatch_error::<dispatch_error::ArrayDispatchError>(
|
|
pallets,
|
|
)
|
|
}
|
|
|
|
/// Given some storage entries, generate a [`RuntimeMetadataPrefixed`] struct.
|
|
/// We default to a useless extrinsic type, mock a pallet out, and register a
|
|
/// fake `DispatchError` type so that codegen is happy with the metadata generated.
|
|
pub fn generate_metadata_from_storage_entries(
|
|
storage_entries: Vec<StorageEntryMetadata>,
|
|
) -> RuntimeMetadataPrefixed {
|
|
let storage = PalletStorageMetadata {
|
|
prefix: "System",
|
|
entries: storage_entries,
|
|
};
|
|
|
|
let pallet = PalletMetadata {
|
|
index: 0,
|
|
name: "System",
|
|
storage: Some(storage),
|
|
constants: vec![],
|
|
calls: None,
|
|
event: None,
|
|
error: None,
|
|
docs: vec![],
|
|
};
|
|
|
|
generate_metadata_from_pallets(vec![pallet])
|
|
}
|