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 ensure_root(origin)?;59 ensure!(60 <MigrationPending<T>>::get(&address),61 <Error<T>>::AccountIsNotMigrating,62 );6364 for (k, v) in data {65 <pallet_evm::AccountStorages<T>>::insert(&address, k, v);66 }67 Ok(())68 }6970 #[pallet::weight(<SelfWeightOf<T>>::finish(code.len() as u32))]71 #[transactional]72 pub fn finish(origin: OriginFor<T>, address: H160, code: Vec<u8>) -> DispatchResult {73 ensure_root(origin)?;74 ensure!(75 <MigrationPending<T>>::get(&address),76 <Error<T>>::AccountIsNotMigrating,77 );7879 <pallet_evm::AccountCodes<T>>::insert(&address, code);80 <MigrationPending<T>>::remove(address);81 Ok(())82 }83 }8485 pub struct OnMethodCall<T>(PhantomData<T>);86 impl<T: Config> pallet_evm::OnMethodCall<T> for OnMethodCall<T> {87 fn is_reserved(contract: &H160) -> bool {88 <MigrationPending<T>>::get(&contract)89 }9091 fn is_used(_contract: &H160) -> bool {92 false93 }9495 fn call(96 _source: &H160,97 _arget: &H160,98 _gas_left: u64,99 _input: &[u8],100 _value: sp_core::U256,101 ) -> Option<pallet_evm::PrecompileOutput> {102 None103 }104105 fn get_code(_contract: &H160) -> Option<Vec<u8>> {106 None107 }108 }109}