- 迁移multisig数据
fn on_runtime_upgrade() -> Weight {
// Utility.Multisigs -> Multisig.Multisigs
use frame_support::migration::{StorageIterator, put_storage_value};
for (key, value) in StorageIterator::<
Multisig<T::BlockNumber, BalanceOf<T>, T::AccountId>
>::new(b"Utility", b"Multisigs").drain() {
put_storage_value(b"Multisig", b"Multisigs", &key, value);
}
1_000_000_000
}
分析: 这个是更改模块名字时候进行的数据迁移
- democracy模块迁移
fn on_runtime_upgrade() -> Weight {
if let None = StorageVersion::get() {
StorageVersion::put(Releases::V1);
DepositOf::<T>::translate::<
(BalanceOf<T>, Vec<T::AccountId>), _
>(|_, (balance, accounts)| {
Some((accounts, balance))
});
T::MaximumBlockWeight::get()
} else {
T::DbWeight::get().reads(1)
}
}
分析: 这个应该是value值交换
- indices模块
fn on_runtime_upgrade() -> Weight {
use frame_support::migration::{StorageIterator, put_storage_value};
for (key, value) in StorageIterator::<
(T::AccountId, BalanceOf<T>)
>::new(b"Indices", b"Accounts").drain() {
put_storage_value(b"Indices", b"Accounts", &key, (value.0, value.1, false));
}
1_000_000_000
}
- staking模块
fn on_runtime_upgrade() -> Weight {
#[allow(dead_code)]
mod inner {
pub struct Module<T>(sp_std::marker::PhantomData<T>);
frame_support::decl_storage! {
trait Store for Module<T: super::Trait> as Staking {
pub MigrateEra: Option<super::EraIndex>;
}
}
}
if let Releases::V3_0_0 = StorageVersion::get() {
StorageVersion::put(Releases::V4_0_0);
inner::MigrateEra::kill();
T::DbWeight::get().reads_writes(1, 1)
} else {
T::DbWeight::get().reads(1)
}
}