difftreelog
feat remove rmrk leftovers migration
in: master
3 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6272,6 +6272,7 @@
"parity-scale-codec",
"scale-info",
"sp-core",
+ "sp-io",
"sp-std",
]
pallets/evm-migration/Cargo.tomldiffbeforeafterboth--- a/pallets/evm-migration/Cargo.toml
+++ b/pallets/evm-migration/Cargo.toml
@@ -16,9 +16,10 @@
scale-info = { workspace = true }
sp-core = { workspace = true }
sp-std = { workspace = true }
+sp-io = { workspace = true }
[features]
default = ["runtime-benchmarks", "std"]
runtime-benchmarks = ["frame-benchmarking"]
-std = ["frame-benchmarking/std", "frame-support/std", "frame-system/std", "pallet-evm/std", "sp-core/std", "sp-std/std"]
+std = ["frame-benchmarking/std", "frame-support/std", "frame-system/std", "pallet-evm/std", "sp-core/std", "sp-std/std", "sp-io/std"]
try-runtime = ["frame-support/try-runtime"]
pallets/evm-migration/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![doc = include_str!("../README.md")]18#![cfg_attr(not(feature = "std"), no_std)]19#![deny(missing_docs)]2021pub use pallet::*;22#[cfg(feature = "runtime-benchmarks")]23pub mod benchmarking;24pub mod weights;2526#[frame_support::pallet]27pub mod pallet {28 use frame_support::{29 pallet_prelude::{*, DispatchResult},30 traits::IsType,31 };32 use frame_system::pallet_prelude::{*, OriginFor};33 use sp_core::{H160, H256};34 use sp_std::vec::Vec;35 use super::weights::WeightInfo;36 use pallet_evm::{PrecompileHandle, Pallet as PalletEvm};3738 #[pallet::config]39 pub trait Config: frame_system::Config + pallet_evm::Config {40 /// Weights41 type WeightInfo: WeightInfo;42 /// The overarching event type.43 type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;44 }4546 type SelfWeightOf<T> = <T as Config>::WeightInfo;4748 #[pallet::pallet]49 #[pallet::generate_store(pub(super) trait Store)]50 pub struct Pallet<T>(_);5152 #[pallet::event]53 pub enum Event<T: Config> {54 /// This event is used in benchmarking and can be used for tests55 TestEvent,56 }5758 #[pallet::error]59 pub enum Error<T> {60 /// Can only migrate to empty address.61 AccountNotEmpty,62 /// Migration of this account is not yet started, or already finished.63 AccountIsNotMigrating,64 /// Failed to decode event bytes65 BadEvent,66 }6768 #[pallet::storage]69 pub(super) type MigrationPending<T: Config> =70 StorageMap<Hasher = Twox64Concat, Key = H160, Value = bool, QueryKind = ValueQuery>;7172 #[pallet::call]73 impl<T: Config> Pallet<T> {74 /// Start contract migration, inserts contract stub at target address,75 /// and marks account as pending, allowing to insert storage76 #[pallet::call_index(0)]77 #[pallet::weight(<SelfWeightOf<T>>::begin())]78 pub fn begin(origin: OriginFor<T>, address: H160) -> DispatchResult {79 ensure_root(origin)?;80 ensure!(81 <PalletEvm<T>>::is_account_empty(&address) && !<MigrationPending<T>>::get(&address),82 <Error<T>>::AccountNotEmpty,83 );8485 <MigrationPending<T>>::insert(address, true);86 Ok(())87 }8889 /// Insert items into contract storage, this method can be called90 /// multiple times91 #[pallet::call_index(1)]92 #[pallet::weight(<SelfWeightOf<T>>::set_data(data.len() as u32))]93 pub fn set_data(94 origin: OriginFor<T>,95 address: H160,96 data: Vec<(H256, H256)>,97 ) -> DispatchResult {98 ensure_root(origin)?;99 ensure!(100 <MigrationPending<T>>::get(&address),101 <Error<T>>::AccountIsNotMigrating,102 );103104 for (k, v) in data {105 <pallet_evm::AccountStorages<T>>::insert(&address, k, v);106 }107 Ok(())108 }109110 /// Finish contract migration, allows it to be called.111 /// It is not possible to alter contract storage via [`Self::set_data`]112 /// after this call.113 #[pallet::call_index(2)]114 #[pallet::weight(<SelfWeightOf<T>>::finish(code.len() as u32))]115 pub fn finish(origin: OriginFor<T>, address: H160, code: Vec<u8>) -> DispatchResult {116 ensure_root(origin)?;117 ensure!(118 <MigrationPending<T>>::get(&address),119 <Error<T>>::AccountIsNotMigrating,120 );121122 <pallet_evm::AccountCodes<T>>::insert(&address, code);123 <MigrationPending<T>>::remove(address);124 Ok(())125 }126127 /// Create ethereum events attached to the fake transaction128 #[pallet::call_index(3)]129 #[pallet::weight(<SelfWeightOf<T>>::insert_eth_logs(logs.len() as u32))]130 pub fn insert_eth_logs(origin: OriginFor<T>, logs: Vec<ethereum::Log>) -> DispatchResult {131 ensure_root(origin)?;132 for log in logs {133 <pallet_evm::Pallet<T>>::deposit_log(log);134 }135 // Transactions is created by FakeTransactionFinalizer136 Ok(())137 }138139 /// Create substrate events140 #[pallet::call_index(4)]141 #[pallet::weight(<SelfWeightOf<T>>::insert_events(events.len() as u32))]142 pub fn insert_events(origin: OriginFor<T>, events: Vec<Vec<u8>>) -> DispatchResult {143 ensure_root(origin)?;144 for event in events {145 <frame_system::Pallet<T>>::deposit_event(146 <T as frame_system::Config>::RuntimeEvent::decode(&mut event.as_slice())147 .map_err(|_| <Error<T>>::BadEvent)?,148 );149 }150 Ok(())151 }152 }153154 /// Implements [`pallet_evm::OnMethodCall`], which reserves accounts with pending migration155 pub struct OnMethodCall<T>(PhantomData<T>);156 impl<T: Config> pallet_evm::OnMethodCall<T> for OnMethodCall<T> {157 fn is_reserved(contract: &H160) -> bool {158 <MigrationPending<T>>::get(&contract)159 }160161 fn is_used(_contract: &H160) -> bool {162 false163 }164165 fn call(_handle: &mut impl PrecompileHandle) -> Option<pallet_evm::PrecompileResult> {166 None167 }168169 fn get_code(_contract: &H160) -> Option<Vec<u8>> {170 None171 }172 }173}