Assign unique storage names to pallets. (#5010)

* Assign unique storage names to pallets.

* Bump spec

* Upgrade logic for finality tracker (untested)

* Logic for migrating Identity (untested)

* Logic for migrating transaction-payment

* Fix tests

* Fix `decl_storage` build

* Contract -> Contracts

* Update Cargo.lock

* bump spec

* update migration

* Fix merge error

* Migration for contracts

* Remove serde

* Remove some illegal spaces and Options

* Fix types in identity.

* Minor variable rename

Co-authored-by: Gavin Wood <gavin@parity.io>
This commit is contained in:
Shawn Tabrizi
2020-03-14 13:44:48 +02:00
committed by GitHub
parent 7285cbc801
commit 74f8db5def
16 changed files with 246 additions and 11 deletions
+6 -1
View File
@@ -80,6 +80,7 @@ use frame_system::{self as system, ensure_signed, ensure_root};
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
mod migration;
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
type NegativeImbalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
@@ -382,7 +383,7 @@ pub struct RegistrarInfo<
}
decl_storage! {
trait Store for Module<T: Trait> as Sudo {
trait Store for Module<T: Trait> as Identity {
/// Information that is pertinent to identify the entity behind an account.
pub IdentityOf get(fn identity):
map hasher(blake2_256) T::AccountId => Option<Registration<BalanceOf<T>>>;
@@ -873,6 +874,10 @@ decl_module! {
Self::deposit_event(RawEvent::IdentityKilled(target, deposit));
}
fn on_runtime_upgrade() {
migration::on_runtime_upgrade::<T>()
}
}
}
+52
View File
@@ -0,0 +1,52 @@
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! Migration code to update storage.
use super::*;
use frame_support::storage::migration::{put_storage_value, take_storage_value, StorageIterator};
pub fn on_runtime_upgrade<T: Trait>() {
change_name_sudo_to_identity::<T>()
}
// Change the storage name used by this pallet from `Sudo` to `Identity`.
//
// Since the format of the storage items themselves have not changed, we do not
// need to keep track of a storage version. If the runtime does not need to be
// upgraded, nothing here will happen anyway.
fn change_name_sudo_to_identity<T: Trait>() {
sp_runtime::print("Migrating Identity.");
for (hash, identity_of) in StorageIterator::<Registration<BalanceOf<T>>>::new(b"Sudo", b"IdentityOf").drain() {
put_storage_value(b"Identity", b"IdentityOf", &hash, identity_of);
}
for (hash, super_of) in StorageIterator::<(T::AccountId, Data)>::new(b"Sudo", b"SuperOf").drain() {
put_storage_value(b"Identity", b"SuperOf", &hash, super_of);
}
for (hash, subs_of) in StorageIterator::<(BalanceOf<T>, Vec<T::AccountId>)>::new(b"Sudo", b"SubsOf").drain() {
put_storage_value(b"Identity", b"SubsOf", &hash, subs_of);
}
if let Some(registrars) = take_storage_value::<Vec<Option<RegistrarInfo<BalanceOf<T>, T::AccountId>>>>(b"Sudo", b"Registrars", &[]) {
put_storage_value(b"Identity", b"Registrars", &[], registrars);
}
sp_runtime::print("Done Identity.");
}