Metadata difference command (#1015)

* diffing pallets and runtime apis

* print diff

* clippy fix and format

* change formatting

* fmt

* diff working with storage details

* fix diff

* cargo fmt

* remove printing of node

* change strings

* handle parsing differently

* clippy fix

* cargo fmt

* more abstraction

* clippy fix and fmt

* add unit test and ordering

* fix small issue
This commit is contained in:
Tadeo Hepperle
2023-06-21 14:33:21 +02:00
committed by GitHub
parent b4eb406ee5
commit 2a990edaca
9 changed files with 541 additions and 23 deletions
+20 -5
View File
@@ -20,7 +20,7 @@ mod from_into;
mod utils;
use scale_info::{form::PortableForm, PortableRegistry, Variant};
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use utils::ordered_map::OrderedMap;
use utils::variant_index::VariantIndex;
@@ -138,6 +138,16 @@ impl Metadata {
{
utils::retain::retain_metadata(self, pallet_filter, api_filter);
}
/// Get type hash for a type in the registry
pub fn type_hash(&self, id: u32) -> Option<[u8; 32]> {
self.types.resolve(id)?;
Some(crate::utils::validation::get_type_hash(
&self.types,
id,
&mut HashSet::<u32>::new(),
))
}
}
/// Metadata for a specific pallet.
@@ -303,8 +313,8 @@ impl StorageMetadata {
}
/// An iterator over the storage entries.
pub fn entries(&self) -> impl ExactSizeIterator<Item = &StorageEntryMetadata> {
self.entries.values().iter()
pub fn entries(&self) -> &[StorageEntryMetadata] {
self.entries.values()
}
/// Return a specific storage entry given its name.
@@ -387,7 +397,7 @@ pub enum StorageHasher {
}
/// Is the storage entry optional, or does it have a default value.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum StorageEntryModifier {
/// The storage entry returns an `Option<T>`, with `None` if the key is not present.
Optional,
@@ -490,7 +500,7 @@ pub struct RuntimeApiMetadata<'a> {
impl<'a> RuntimeApiMetadata<'a> {
/// Trait name.
pub fn name(&self) -> &str {
pub fn name(&self) -> &'a str {
&self.inner.name
}
/// Trait documentation.
@@ -509,6 +519,11 @@ impl<'a> RuntimeApiMetadata<'a> {
pub fn method_hash(&self, method_name: &str) -> Option<[u8; 32]> {
crate::utils::validation::get_runtime_api_hash(self, method_name)
}
/// Return a hash for the runtime API trait.
pub fn hash(&self) -> [u8; 32] {
crate::utils::validation::get_runtime_trait_hash(*self)
}
}
#[derive(Debug, Clone)]