mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 09:57:56 +00:00
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:
@@ -36,7 +36,11 @@ use sp_trie::{
|
||||
use trie_db::{Trie, TrieMut};
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use frame_support::{parameter_types, traits::KeyOwnerProofSystem, weights::RuntimeDbWeight};
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
traits::{CrateVersion, KeyOwnerProofSystem},
|
||||
weights::RuntimeDbWeight,
|
||||
};
|
||||
use frame_system::limits::{BlockLength, BlockWeights};
|
||||
use sp_api::{decl_runtime_apis, impl_runtime_apis};
|
||||
pub use sp_core::hash::H256;
|
||||
@@ -520,6 +524,35 @@ impl frame_support::traits::PalletInfo for Runtime {
|
||||
return Some("Babe")
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
fn module_name<P: 'static>() -> Option<&'static str> {
|
||||
let type_id = sp_std::any::TypeId::of::<P>();
|
||||
if type_id == sp_std::any::TypeId::of::<system::Pallet<Runtime>>() {
|
||||
return Some("system")
|
||||
}
|
||||
if type_id == sp_std::any::TypeId::of::<pallet_timestamp::Pallet<Runtime>>() {
|
||||
return Some("pallet_timestamp")
|
||||
}
|
||||
if type_id == sp_std::any::TypeId::of::<pallet_babe::Pallet<Runtime>>() {
|
||||
return Some("pallet_babe")
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
fn crate_version<P: 'static>() -> Option<CrateVersion> {
|
||||
use frame_support::traits::PalletInfoAccess as _;
|
||||
let type_id = sp_std::any::TypeId::of::<P>();
|
||||
if type_id == sp_std::any::TypeId::of::<system::Pallet<Runtime>>() {
|
||||
return Some(system::Pallet::<Runtime>::crate_version())
|
||||
}
|
||||
if type_id == sp_std::any::TypeId::of::<pallet_timestamp::Pallet<Runtime>>() {
|
||||
return Some(pallet_timestamp::Pallet::<Runtime>::crate_version())
|
||||
}
|
||||
if type_id == sp_std::any::TypeId::of::<pallet_babe::Pallet<Runtime>>() {
|
||||
return Some(pallet_babe::Pallet::<Runtime>::crate_version())
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user