mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 13:27:57 +00:00
frame-system: Add last_runtime_upgrade_spec_version (#2351)
Adds a function for querying the last runtime upgrade spec version. This can be useful for when writing runtime level migrations to ensure that they are not executed multiple times. An example would be a session key migration. --------- Co-authored-by: Liam Aharon <liam.aharon@hotmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -1094,6 +1094,25 @@ pub enum DecRefStatus {
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Returns the `spec_version` of the last runtime upgrade.
|
||||
///
|
||||
/// This function is useful for writing guarded runtime migrations in the runtime. A runtime
|
||||
/// migration can use the `spec_version` to ensure that it isn't applied twice. This works
|
||||
/// similar as the storage version for pallets.
|
||||
///
|
||||
/// This functions returns the `spec_version` of the last runtime upgrade while executing the
|
||||
/// runtime migrations
|
||||
/// [`on_runtime_upgrade`](frame_support::traits::OnRuntimeUpgrade::on_runtime_upgrade)
|
||||
/// function. After all migrations are executed, this will return the `spec_version` of the
|
||||
/// current runtime until there is another runtime upgrade.
|
||||
///
|
||||
/// Example:
|
||||
#[doc = docify::embed!("src/tests.rs", last_runtime_upgrade_spec_version_usage)]
|
||||
pub fn last_runtime_upgrade_spec_version() -> u32 {
|
||||
LastRuntimeUpgrade::<T>::get().map_or(0, |l| l.spec_version.0)
|
||||
}
|
||||
|
||||
/// Returns true if the given account exists.
|
||||
pub fn account_exists(who: &T::AccountId) -> bool {
|
||||
Account::<T>::contains_key(who)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user