|
| 1 | +// Copyright 2020 Parity Technologies (UK) Ltd. |
| 2 | +// This file is part of Substrate. |
| 3 | + |
| 4 | +// Substrate is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | + |
| 9 | +// Substrate is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | + |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Substrate. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +//! Migration code to update storage. |
| 18 | +
|
| 19 | +use super::*; |
| 20 | +use frame_support::storage::migration::{put_storage_value, take_storage_value, StorageIterator}; |
| 21 | + |
| 22 | +pub fn on_runtime_upgrade<T: Trait>() { |
| 23 | + change_name_contract_to_contracts::<T>() |
| 24 | +} |
| 25 | + |
| 26 | +// Change the storage name used by this pallet from `Contract` to `Contracts`. |
| 27 | +// |
| 28 | +// Since the format of the storage items themselves have not changed, we do not |
| 29 | +// need to keep track of a storage version. If the runtime does not need to be |
| 30 | +// upgraded, nothing here will happen anyway. |
| 31 | + |
| 32 | +fn change_name_contract_to_contracts<T: Trait>() { |
| 33 | + sp_runtime::print("Migrating Contracts."); |
| 34 | + |
| 35 | + if let Some(gas_spent) = take_storage_value::<Gas>(b"Contract", b"GasSpent", &[]) { |
| 36 | + put_storage_value(b"Contracts", b"GasSpent", &[], gas_spent); |
| 37 | + } |
| 38 | + |
| 39 | + if let Some(current_schedule) = take_storage_value::<Schedule>(b"Contract", b"CurrentSchedule", &[]) { |
| 40 | + put_storage_value(b"Contracts", b"CurrentSchedule", &[], current_schedule); |
| 41 | + } |
| 42 | + |
| 43 | + for (hash, pristine_code) in StorageIterator::<Vec<u8>>::new(b"Contract", b"PristineCode").drain() { |
| 44 | + put_storage_value(b"Contracts", b"PristineCode", &hash, pristine_code); |
| 45 | + } |
| 46 | + |
| 47 | + for (hash, code_storage) in StorageIterator::<wasm::PrefabWasmModule>::new(b"Contract", b"CodeStorage").drain() { |
| 48 | + put_storage_value(b"Contracts", b"CodeStorage", &hash, code_storage); |
| 49 | + } |
| 50 | + |
| 51 | + if let Some(current_schedule) = take_storage_value::<u64>(b"Contract", b"AccountCounter", &[]) { |
| 52 | + put_storage_value(b"Contracts", b"AccountCounter", &[], current_schedule); |
| 53 | + } |
| 54 | + |
| 55 | + for (hash, contract_info_of) in StorageIterator::<ContractInfo<T>>::new(b"Contract", b"ContractInfoOf").drain() { |
| 56 | + put_storage_value(b"Contracts", b"ContractInfoOf", &hash, contract_info_of); |
| 57 | + } |
| 58 | + |
| 59 | + if let Some(get_price) = take_storage_value::<BalanceOf<T>>(b"Contract", b"GetPrice", &[]) { |
| 60 | + put_storage_value(b"Contracts", b"GetPrice", &[], get_price); |
| 61 | + } |
| 62 | +} |
0 commit comments