1234567891011121314151617#![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::pallet_prelude::*;29 use frame_system::pallet_prelude::*;30 use sp_core::{H160, H256};31 use sp_std::vec::Vec;32 use super::weights::WeightInfo;33 use pallet_evm::{PrecompileHandle, Pallet as PalletEvm};3435 #[pallet::config]36 pub trait Config: frame_system::Config + pallet_evm::Config {37 38 type WeightInfo: WeightInfo;39 }4041 type SelfWeightOf<T> = <T as Config>::WeightInfo;4243 #[pallet::pallet]44 #[pallet::generate_store(pub(super) trait Store)]45 pub struct Pallet<T>(_);4647 #[pallet::error]48 pub enum Error<T> {49 50 AccountNotEmpty,51 52 AccountIsNotMigrating,53 }5455 #[pallet::storage]56 pub(super) type MigrationPending<T: Config> =57 StorageMap<Hasher = Twox64Concat, Key = H160, Value = bool, QueryKind = ValueQuery>;5859 #[pallet::call]60 impl<T: Config> Pallet<T> {61 62 63 #[pallet::weight(<SelfWeightOf<T>>::begin())]64 pub fn begin(origin: OriginFor<T>, address: H160) -> DispatchResult {65 ensure_root(origin)?;66 ensure!(67 <PalletEvm<T>>::is_account_empty(&address) && !<MigrationPending<T>>::get(&address),68 <Error<T>>::AccountNotEmpty,69 );7071 <MigrationPending<T>>::insert(address, true);72 Ok(())73 }7475 76 77 #[pallet::weight(<SelfWeightOf<T>>::set_data(data.len() as u32))]78 pub fn set_data(79 origin: OriginFor<T>,80 address: H160,81 data: Vec<(H256, H256)>,82 ) -> DispatchResult {83 ensure_root(origin)?;84 ensure!(85 <MigrationPending<T>>::get(&address),86 <Error<T>>::AccountIsNotMigrating,87 );8889 for (k, v) in data {90 <pallet_evm::AccountStorages<T>>::insert(&address, k, v);91 }92 Ok(())93 }9495 96 97 98 #[pallet::weight(<SelfWeightOf<T>>::finish(code.len() as u32))]99 pub fn finish(origin: OriginFor<T>, address: H160, code: Vec<u8>) -> DispatchResult {100 ensure_root(origin)?;101 ensure!(102 <MigrationPending<T>>::get(&address),103 <Error<T>>::AccountIsNotMigrating,104 );105106 <pallet_evm::AccountCodes<T>>::insert(&address, code);107 <MigrationPending<T>>::remove(address);108 Ok(())109 }110 }111112 113 pub struct OnMethodCall<T>(PhantomData<T>);114 impl<T: Config> pallet_evm::OnMethodCall<T> for OnMethodCall<T> {115 fn is_reserved(contract: &H160) -> bool {116 <MigrationPending<T>>::get(&contract)117 }118119 fn is_used(_contract: &H160) -> bool {120 false121 }122123 fn call(_handle: &mut impl PrecompileHandle) -> Option<pallet_evm::PrecompileResult> {124 None125 }126127 fn get_code(_contract: &H160) -> Option<Vec<u8>> {128 None129 }130 }131}