1#![cfg_attr(not(feature = "std"), no_std)]23pub use pallet::*;4#[cfg(feature = "runtime-benchmarks")]5pub mod benchmarking;6pub mod weights;78#[frame_support::pallet]9pub mod pallet {10 use frame_support::{pallet_prelude::*, transactional};11 use frame_system::pallet_prelude::*;12 use sp_core::{H160, H256};13 use sp_std::vec::Vec;14 use super::weights::WeightInfo;1516 #[pallet::config]17 pub trait Config: frame_system::Config + pallet_evm::Config {18 type WeightInfo: WeightInfo;19 }2021 type SelfWeightOf<T> = <T as Config>::WeightInfo;2223 #[pallet::pallet]24 #[pallet::generate_store(pub(super) trait Store)]25 pub struct Pallet<T>(_);2627 #[pallet::error]28 pub enum Error<T> {29 AccountNotEmpty,30 AccountIsNotMigrating,31 }3233 #[pallet::storage]34 pub(super) type MigrationPending<T: Config> =35 StorageMap<Hasher = Twox64Concat, Key = H160, Value = bool, QueryKind = ValueQuery>;3637 #[pallet::call]38 impl<T: Config> Pallet<T> {39 #[pallet::weight(<SelfWeightOf<T>>::begin())]40 pub fn begin(origin: OriginFor<T>, address: H160) -> DispatchResult {41 ensure_root(origin)?;42 ensure!(43 <pallet_evm::Pallet<T>>::is_account_empty(&address)44 && !<MigrationPending<T>>::get(&address),45 <Error<T>>::AccountNotEmpty,46 );4748 <MigrationPending<T>>::insert(address, true);49 Ok(())50 }5152 #[pallet::weight(<SelfWeightOf<T>>::set_data(data.len() as u32))]53 pub fn set_data(54 origin: OriginFor<T>,55 address: H160,56 data: Vec<(H256, H256)>,57 ) -> DispatchResult {58 use frame_support::StorageDoubleMap;59 ensure_root(origin)?;60 ensure!(61 <MigrationPending<T>>::get(&address),62 <Error<T>>::AccountIsNotMigrating,63 );6465 for (k, v) in data {66 pallet_evm::AccountStorages::insert(&address, k, v);67 }68 Ok(())69 }7071 #[pallet::weight(<SelfWeightOf<T>>::finish(code.len() as u32))]72 #[transactional]73 pub fn finish(origin: OriginFor<T>, address: H160, code: Vec<u8>) -> DispatchResult {74 use frame_support::StorageMap;75 ensure_root(origin)?;76 ensure!(77 <MigrationPending<T>>::get(&address),78 <Error<T>>::AccountIsNotMigrating,79 );8081 pallet_evm::AccountCodes::insert(&address, code);82 <MigrationPending<T>>::remove(address);83 Ok(())84 }85 }8687 pub struct OnMethodCall<T>(PhantomData<T>);88 impl<T: Config> pallet_evm::OnMethodCall<T> for OnMethodCall<T> {89 fn is_reserved(contract: &H160) -> bool {90 <MigrationPending<T>>::get(&contract)91 }9293 fn is_used(_contract: &H160) -> bool {94 false95 }9697 fn call(98 _source: &H160,99 _arget: &H160,100 _gas_left: u64,101 _input: &[u8],102 _value: sp_core::U256,103 ) -> Option<pallet_evm::PrecompileOutput> {104 None105 }106107 fn get_code(_contract: &H160) -> Option<Vec<u8>> {108 None109 }110 }111}