Extend PalletInfoAccess with module_name and crate_version method (#9690)

* Record pallet indices in CallMetadata

* Resurrect PalletVersion infrastructure and rename as CrateVersion

* cargo fmt

* Add missing runtime generics to pallet struct

* Fix path to instance

* Fix test

* Fix UI test expectations

* Fix UI test expectations

* Move crate_version function to PalletInfoAccess

* Update UI test expectations

* Add crate_name method to PalletInfo

* Convert path to module name instead of exposing crate name

* cargo fmt

* Keep the double colons when constructing the module name

* Remove unused import

* Update UI test expectations

* Update frame/support/src/traits/metadata.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Update UI test expectations

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Keith Yeung
2021-09-28 02:35:33 -07:00
committed by GitHub
parent 951a033e8d
commit 7b65b049cb
13 changed files with 299 additions and 16 deletions
+19 -1
View File
@@ -21,6 +21,7 @@
mod clone_no_bound;
mod construct_runtime;
mod crate_version;
mod debug_no_bound;
mod default_no_bound;
mod dummy_part_checker;
@@ -31,7 +32,7 @@ mod storage;
mod transactional;
use proc_macro::TokenStream;
use std::cell::RefCell;
use std::{cell::RefCell, str::FromStr};
pub(crate) use storage::INHERENT_INSTANCE_NAME;
thread_local! {
@@ -52,6 +53,16 @@ impl Counter {
}
}
/// Get the value from the given environment variable set by cargo.
///
/// The value is parsed into the requested destination type.
fn get_cargo_env_var<T: FromStr>(version_env: &str) -> std::result::Result<T, ()> {
let version = std::env::var(version_env)
.unwrap_or_else(|_| panic!("`{}` is always set by cargo; qed", version_env));
T::from_str(&version).map_err(drop)
}
/// Declares strongly-typed wrappers around codec-compatible types in storage.
///
/// ## Example
@@ -462,6 +473,13 @@ pub fn require_transactional(attr: TokenStream, input: TokenStream) -> TokenStre
.unwrap_or_else(|e| e.to_compile_error().into())
}
#[proc_macro]
pub fn crate_to_crate_version(input: TokenStream) -> TokenStream {
crate_version::crate_to_crate_version(input)
.unwrap_or_else(|e| e.to_compile_error())
.into()
}
/// The number of module instances supported by the runtime, starting at index 1,
/// and up to `NUMBER_OF_INSTANCE`.
pub(crate) const NUMBER_OF_INSTANCE: u8 = 16;