mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 18:31:05 +00:00
XXX: Adjust repo to use V15 metadata
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
@@ -10,7 +10,7 @@ use color_eyre::eyre::{
|
||||
use frame_metadata::{
|
||||
RuntimeMetadata,
|
||||
RuntimeMetadataPrefixed,
|
||||
RuntimeMetadataV14,
|
||||
RuntimeMetadataV15,
|
||||
META_RESERVED,
|
||||
};
|
||||
use jsonrpsee::client_transport::ws::Uri;
|
||||
@@ -110,7 +110,7 @@ async fn handle_full_metadata(nodes: &[Uri]) -> color_eyre::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn fetch_runtime_metadata(url: &Uri) -> color_eyre::Result<RuntimeMetadataV14> {
|
||||
async fn fetch_runtime_metadata(url: &Uri) -> color_eyre::Result<RuntimeMetadataV15> {
|
||||
let bytes = subxt_codegen::utils::fetch_metadata_bytes(url).await?;
|
||||
|
||||
let metadata = <RuntimeMetadataPrefixed as Decode>::decode(&mut &bytes[..])?;
|
||||
@@ -124,7 +124,7 @@ async fn fetch_runtime_metadata(url: &Uri) -> color_eyre::Result<RuntimeMetadata
|
||||
}
|
||||
|
||||
match metadata.1 {
|
||||
RuntimeMetadata::V14(v14) => Ok(v14),
|
||||
RuntimeMetadata::V15(v15) => Ok(v15),
|
||||
_ => {
|
||||
Err(eyre::eyre!(
|
||||
"Node {:?} with unsupported metadata version: {:?}",
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
CratePath,
|
||||
};
|
||||
use frame_metadata::{
|
||||
v14::RuntimeMetadataV14,
|
||||
v15::RuntimeMetadataV15,
|
||||
PalletMetadata,
|
||||
};
|
||||
use heck::{
|
||||
@@ -35,7 +35,7 @@ use scale_info::form::PortableForm;
|
||||
/// - `pallet` - Pallet metadata from which the calls are generated.
|
||||
/// - `types_mod_ident` - The ident of the base module that we can use to access the generated types from.
|
||||
pub fn generate_calls(
|
||||
metadata: &RuntimeMetadataV14,
|
||||
metadata: &RuntimeMetadataV15,
|
||||
type_gen: &TypeGenerator,
|
||||
pallet: &PalletMetadata<PortableForm>,
|
||||
types_mod_ident: &syn::Ident,
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
CratePath,
|
||||
};
|
||||
use frame_metadata::{
|
||||
v14::RuntimeMetadataV14,
|
||||
v15::RuntimeMetadataV15,
|
||||
PalletMetadata,
|
||||
};
|
||||
use heck::ToSnakeCase as _;
|
||||
@@ -43,7 +43,7 @@ use scale_info::form::PortableForm;
|
||||
/// - `pallet` - Pallet metadata from which the calls are generated.
|
||||
/// - `types_mod_ident` - The ident of the base module that we can use to access the generated types from.
|
||||
pub fn generate_constants(
|
||||
metadata: &RuntimeMetadataV14,
|
||||
metadata: &RuntimeMetadataV15,
|
||||
type_gen: &TypeGenerator,
|
||||
pallet: &PalletMetadata<PortableForm>,
|
||||
types_mod_ident: &syn::Ident,
|
||||
|
||||
@@ -28,7 +28,7 @@ use crate::{
|
||||
};
|
||||
use codec::Decode;
|
||||
use frame_metadata::{
|
||||
v14::RuntimeMetadataV14,
|
||||
v15::RuntimeMetadataV15,
|
||||
RuntimeMetadata,
|
||||
RuntimeMetadataPrefixed,
|
||||
};
|
||||
@@ -144,7 +144,7 @@ pub fn generate_runtime_api_from_bytes(
|
||||
|
||||
/// Create the API for interacting with a Substrate runtime.
|
||||
pub struct RuntimeGenerator {
|
||||
metadata: RuntimeMetadataV14,
|
||||
metadata: RuntimeMetadataV15,
|
||||
}
|
||||
|
||||
impl RuntimeGenerator {
|
||||
@@ -155,7 +155,7 @@ impl RuntimeGenerator {
|
||||
/// from that.
|
||||
pub fn new(metadata: RuntimeMetadataPrefixed) -> Self {
|
||||
match metadata.1 {
|
||||
RuntimeMetadata::V14(v14) => Self { metadata: v14 },
|
||||
RuntimeMetadata::V15(v15) => Self { metadata: v15 },
|
||||
_ => panic!("Unsupported metadata version {:?}", metadata.1),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
CratePath,
|
||||
};
|
||||
use frame_metadata::{
|
||||
v14::RuntimeMetadataV14,
|
||||
v15::RuntimeMetadataV15,
|
||||
PalletMetadata,
|
||||
StorageEntryMetadata,
|
||||
StorageEntryModifier,
|
||||
@@ -36,7 +36,7 @@ use scale_info::{
|
||||
/// - `pallet` - Pallet metadata from which the storages are generated.
|
||||
/// - `types_mod_ident` - The ident of the base module that we can use to access the generated types from.
|
||||
pub fn generate_storage(
|
||||
metadata: &RuntimeMetadataV14,
|
||||
metadata: &RuntimeMetadataV15,
|
||||
type_gen: &TypeGenerator,
|
||||
pallet: &PalletMetadata<PortableForm>,
|
||||
types_mod_ident: &syn::Ident,
|
||||
@@ -70,7 +70,7 @@ pub fn generate_storage(
|
||||
}
|
||||
|
||||
fn generate_storage_entry_fns(
|
||||
metadata: &RuntimeMetadataV14,
|
||||
metadata: &RuntimeMetadataV15,
|
||||
type_gen: &TypeGenerator,
|
||||
pallet: &PalletMetadata<PortableForm>,
|
||||
storage_entry: &StorageEntryMetadata<PortableForm>,
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
use codec::Decode;
|
||||
use criterion::*;
|
||||
use frame_metadata::{
|
||||
RuntimeMetadata::V14,
|
||||
RuntimeMetadata::V15,
|
||||
RuntimeMetadataPrefixed,
|
||||
RuntimeMetadataV14,
|
||||
RuntimeMetadataV15,
|
||||
};
|
||||
use scale_info::{
|
||||
form::PortableForm,
|
||||
@@ -26,14 +26,14 @@ use subxt_metadata::{
|
||||
get_storage_hash,
|
||||
};
|
||||
|
||||
fn load_metadata() -> RuntimeMetadataV14 {
|
||||
fn load_metadata() -> RuntimeMetadataV15 {
|
||||
let bytes = fs::read(Path::new("../artifacts/polkadot_metadata.scale"))
|
||||
.expect("Cannot read metadata blob");
|
||||
let meta: RuntimeMetadataPrefixed =
|
||||
Decode::decode(&mut &*bytes).expect("Cannot decode scale metadata");
|
||||
|
||||
match meta.1 {
|
||||
V14(v14) => v14,
|
||||
V15(v15) => v15,
|
||||
_ => panic!("Unsupported metadata version {:?}", meta.1),
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -4,7 +4,7 @@
|
||||
|
||||
use frame_metadata::{
|
||||
ExtrinsicMetadata,
|
||||
RuntimeMetadataV14,
|
||||
RuntimeMetadataV15,
|
||||
StorageEntryMetadata,
|
||||
StorageEntryType,
|
||||
};
|
||||
@@ -247,7 +247,7 @@ fn get_storage_entry_hash(
|
||||
|
||||
/// Obtain the hash for a specific storage item, or an error if it's not found.
|
||||
pub fn get_storage_hash(
|
||||
metadata: &RuntimeMetadataV14,
|
||||
metadata: &RuntimeMetadataV15,
|
||||
pallet_name: &str,
|
||||
storage_name: &str,
|
||||
) -> Result<[u8; 32], NotFound> {
|
||||
@@ -271,7 +271,7 @@ pub fn get_storage_hash(
|
||||
|
||||
/// Obtain the hash for a specific constant, or an error if it's not found.
|
||||
pub fn get_constant_hash(
|
||||
metadata: &RuntimeMetadataV14,
|
||||
metadata: &RuntimeMetadataV15,
|
||||
pallet_name: &str,
|
||||
constant_name: &str,
|
||||
) -> Result<[u8; 32], NotFound> {
|
||||
@@ -294,7 +294,7 @@ pub fn get_constant_hash(
|
||||
|
||||
/// Obtain the hash for a specific call, or an error if it's not found.
|
||||
pub fn get_call_hash(
|
||||
metadata: &RuntimeMetadataV14,
|
||||
metadata: &RuntimeMetadataV15,
|
||||
pallet_name: &str,
|
||||
call_name: &str,
|
||||
) -> Result<[u8; 32], NotFound> {
|
||||
@@ -370,8 +370,8 @@ pub fn get_pallet_hash(
|
||||
bytes
|
||||
}
|
||||
|
||||
/// Obtain the hash representation of a `frame_metadata::RuntimeMetadataV14`.
|
||||
pub fn get_metadata_hash(metadata: &RuntimeMetadataV14) -> [u8; 32] {
|
||||
/// Obtain the hash representation of a `frame_metadata::RuntimeMetadataV15`.
|
||||
pub fn get_metadata_hash(metadata: &RuntimeMetadataV15) -> [u8; 32] {
|
||||
// Collect all pairs of (pallet name, pallet hash).
|
||||
let mut pallets: Vec<(&str, [u8; 32])> = metadata
|
||||
.pallets
|
||||
@@ -405,7 +405,7 @@ pub fn get_metadata_hash(metadata: &RuntimeMetadataV14) -> [u8; 32] {
|
||||
hash(&bytes)
|
||||
}
|
||||
|
||||
/// Obtain the hash representation of a `frame_metadata::RuntimeMetadataV14`
|
||||
/// Obtain the hash representation of a `frame_metadata::RuntimeMetadataV15`
|
||||
/// hashing only the provided pallets.
|
||||
///
|
||||
/// **Note:** This is similar to `get_metadata_hash`, but performs hashing only of the provided
|
||||
@@ -413,7 +413,7 @@ pub fn get_metadata_hash(metadata: &RuntimeMetadataV14) -> [u8; 32] {
|
||||
/// the pallets from the static metadata. In those cases, the static API can communicate
|
||||
/// properly with the subset of pallets from the runtime node.
|
||||
pub fn get_metadata_per_pallet_hash<T: AsRef<str>>(
|
||||
metadata: &RuntimeMetadataV14,
|
||||
metadata: &RuntimeMetadataV15,
|
||||
pallets: &[T],
|
||||
) -> [u8; 32] {
|
||||
// Collect all pairs of (pallet name, pallet hash).
|
||||
@@ -471,7 +471,7 @@ mod tests {
|
||||
PalletEventMetadata,
|
||||
PalletMetadata,
|
||||
PalletStorageMetadata,
|
||||
RuntimeMetadataV14,
|
||||
RuntimeMetadataV15,
|
||||
StorageEntryMetadata,
|
||||
StorageEntryModifier,
|
||||
};
|
||||
@@ -570,8 +570,8 @@ mod tests {
|
||||
]
|
||||
}
|
||||
|
||||
fn pallets_to_metadata(pallets: Vec<PalletMetadata>) -> RuntimeMetadataV14 {
|
||||
RuntimeMetadataV14::new(pallets, build_default_extrinsic(), meta_type::<()>())
|
||||
fn pallets_to_metadata(pallets: Vec<PalletMetadata>) -> RuntimeMetadataV15 {
|
||||
RuntimeMetadataV15::new(pallets, build_default_extrinsic(), meta_type::<()>())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -404,11 +404,11 @@ pub(crate) mod test_utils {
|
||||
};
|
||||
use codec::Encode;
|
||||
use frame_metadata::{
|
||||
v14::{
|
||||
v15::{
|
||||
ExtrinsicMetadata,
|
||||
PalletEventMetadata,
|
||||
PalletMetadata,
|
||||
RuntimeMetadataV14,
|
||||
RuntimeMetadataV15,
|
||||
},
|
||||
RuntimeMetadataPrefixed,
|
||||
};
|
||||
@@ -464,8 +464,8 @@ pub(crate) mod test_utils {
|
||||
signed_extensions: vec![],
|
||||
};
|
||||
|
||||
let v14 = RuntimeMetadataV14::new(pallets, extrinsic, meta_type::<()>());
|
||||
let runtime_metadata: RuntimeMetadataPrefixed = v14.into();
|
||||
let v15 = RuntimeMetadataV15::new(pallets, extrinsic, meta_type::<()>(), vec![]);
|
||||
let runtime_metadata: RuntimeMetadataPrefixed = v15.into();
|
||||
|
||||
Metadata::try_from(runtime_metadata).unwrap()
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use frame_metadata::{
|
||||
PalletConstantMetadata,
|
||||
RuntimeMetadata,
|
||||
RuntimeMetadataPrefixed,
|
||||
RuntimeMetadataV14,
|
||||
RuntimeMetadataV15,
|
||||
StorageEntryMetadata,
|
||||
META_RESERVED,
|
||||
};
|
||||
@@ -77,7 +77,7 @@ pub enum MetadataError {
|
||||
// We hide the innards behind an Arc so that it's easy to clone and share.
|
||||
#[derive(Debug)]
|
||||
struct MetadataInner {
|
||||
metadata: RuntimeMetadataV14,
|
||||
metadata: RuntimeMetadataV15,
|
||||
pallets: HashMap<String, PalletMetadata>,
|
||||
events: HashMap<(u8, u8), EventMetadata>,
|
||||
// Errors are hashed by pallet index.
|
||||
@@ -153,7 +153,7 @@ impl Metadata {
|
||||
}
|
||||
|
||||
/// Return the runtime metadata.
|
||||
pub fn runtime_metadata(&self) -> &RuntimeMetadataV14 {
|
||||
pub fn runtime_metadata(&self) -> &RuntimeMetadataV15 {
|
||||
&self.inner.metadata
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ impl TryFrom<RuntimeMetadataPrefixed> for Metadata {
|
||||
return Err(InvalidMetadataError::InvalidPrefix)
|
||||
}
|
||||
let metadata = match metadata.1 {
|
||||
RuntimeMetadata::V14(meta) => meta,
|
||||
RuntimeMetadata::V15(meta) => meta,
|
||||
_ => return Err(InvalidMetadataError::InvalidVersion),
|
||||
};
|
||||
|
||||
@@ -596,7 +596,7 @@ mod tests {
|
||||
error: None,
|
||||
};
|
||||
|
||||
let metadata = RuntimeMetadataV14::new(
|
||||
let metadata = RuntimeMetadataV15::new(
|
||||
vec![pallet],
|
||||
ExtrinsicMetadata {
|
||||
ty: meta_type::<()>(),
|
||||
|
||||
@@ -109,7 +109,7 @@ async fn runtime_api_call() -> Result<(), subxt::Error> {
|
||||
let _ = <Compact<u32>>::decode(cursor)?;
|
||||
let meta: RuntimeMetadataPrefixed = Decode::decode(cursor)?;
|
||||
let metadata_call = match meta.1 {
|
||||
frame_metadata::RuntimeMetadata::V14(metadata) => metadata,
|
||||
frame_metadata::RuntimeMetadata::V15(metadata) => metadata,
|
||||
_ => panic!("Metadata V14 unavailable"),
|
||||
};
|
||||
|
||||
|
||||
@@ -309,7 +309,7 @@ async fn rpc_state_call() {
|
||||
let _ = <Compact<u32>>::decode(cursor).unwrap();
|
||||
let meta: RuntimeMetadataPrefixed = Decode::decode(cursor).unwrap();
|
||||
let metadata_call = match meta.1 {
|
||||
frame_metadata::RuntimeMetadata::V14(metadata) => metadata,
|
||||
frame_metadata::RuntimeMetadata::V15(metadata) => metadata,
|
||||
_ => panic!("Metadata V14 unavailable"),
|
||||
};
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ fn metadata_docs() -> Vec<String> {
|
||||
// Load the runtime metadata downloaded from a node via `test-runtime`.
|
||||
let meta = load_test_metadata();
|
||||
let metadata = match meta.1 {
|
||||
frame_metadata::RuntimeMetadata::V14(v14) => v14,
|
||||
frame_metadata::RuntimeMetadata::V15(v15) => v15,
|
||||
_ => panic!("Unsupported metadata version {:?}", meta.1),
|
||||
};
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ use frame_metadata::{
|
||||
PalletMetadata,
|
||||
PalletStorageMetadata,
|
||||
RuntimeMetadataPrefixed,
|
||||
RuntimeMetadataV14,
|
||||
RuntimeMetadataV15,
|
||||
StorageEntryMetadata,
|
||||
StorageEntryModifier,
|
||||
StorageEntryType,
|
||||
@@ -35,7 +35,7 @@ use subxt::{
|
||||
};
|
||||
|
||||
async fn metadata_to_api(
|
||||
metadata: RuntimeMetadataV14,
|
||||
metadata: RuntimeMetadataV15,
|
||||
ctx: &TestContext,
|
||||
) -> OfflineClient<SubstrateConfig> {
|
||||
let prefixed = RuntimeMetadataPrefixed::from(metadata);
|
||||
@@ -57,7 +57,7 @@ async fn full_metadata_check() {
|
||||
assert!(node_runtime::validate_codegen(&api).is_ok());
|
||||
|
||||
// Modify the metadata.
|
||||
let mut metadata: RuntimeMetadataV14 = api.metadata().runtime_metadata().clone();
|
||||
let mut metadata: RuntimeMetadataV15 = api.metadata().runtime_metadata().clone();
|
||||
metadata.pallets[0].name = "NewPallet".to_string();
|
||||
|
||||
let api = metadata_to_api(metadata, &ctx).await;
|
||||
@@ -79,7 +79,7 @@ async fn constant_values_are_not_validated() {
|
||||
assert!(api.constants().at(&deposit_addr).is_ok());
|
||||
|
||||
// Modify the metadata.
|
||||
let mut metadata: RuntimeMetadataV14 = api.metadata().runtime_metadata().clone();
|
||||
let mut metadata: RuntimeMetadataV15 = api.metadata().runtime_metadata().clone();
|
||||
|
||||
let mut existential = metadata
|
||||
.pallets
|
||||
@@ -112,8 +112,8 @@ fn default_pallet() -> PalletMetadata {
|
||||
}
|
||||
}
|
||||
|
||||
fn pallets_to_metadata(pallets: Vec<PalletMetadata>) -> RuntimeMetadataV14 {
|
||||
RuntimeMetadataV14::new(
|
||||
fn pallets_to_metadata(pallets: Vec<PalletMetadata>) -> RuntimeMetadataV15 {
|
||||
RuntimeMetadataV15::new(
|
||||
pallets,
|
||||
ExtrinsicMetadata {
|
||||
ty: meta_type::<()>(),
|
||||
|
||||
@@ -6,7 +6,7 @@ pub mod dispatch_error;
|
||||
mod metadata_test_runner;
|
||||
|
||||
use frame_metadata::{
|
||||
v14::RuntimeMetadataV14,
|
||||
v15::RuntimeMetadataV15,
|
||||
ExtrinsicMetadata,
|
||||
PalletMetadata,
|
||||
PalletStorageMetadata,
|
||||
@@ -36,7 +36,7 @@ pub fn generate_metadata_from_pallets_custom_dispatch_error<
|
||||
signed_extensions: vec![],
|
||||
};
|
||||
|
||||
// Construct metadata manually from our types (See `RuntimeMetadataV14::new()`).
|
||||
// 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);
|
||||
@@ -46,7 +46,7 @@ pub fn generate_metadata_from_pallets_custom_dispatch_error<
|
||||
// Metadata needs to contain this DispatchError, since codegen looks for it.
|
||||
registry.register_type(&meta_type::<DispatchError>());
|
||||
|
||||
let metadata = RuntimeMetadataV14 {
|
||||
let metadata = RuntimeMetadataV15 {
|
||||
types: registry.into(),
|
||||
pallets,
|
||||
extrinsic,
|
||||
|
||||
Reference in New Issue
Block a user