difftreelog
doc(pallet-evm-migration): document public api
in: master
4 files changed
pallets/evm-migration/README.mddiffbeforeafterboth--- /dev/null
+++ b/pallets/evm-migration/README.md
@@ -0,0 +1,18 @@
+# EVM contract migration pallet
+
+This pallet is only callable by root, it has functionality to migrate contract
+from other ethereum chain to pallet-evm
+
+Contract data includes contract code, and contract storage,
+where contract storage is a mapping from evm word to evm word (evm word = 32 byte)
+
+To import contract data into pallet-evm admin should call this pallet multiple times:
+1. Start migration via `begin`
+2. Insert all contract data using single or
+ multiple (If data can't be fit into single extrinsic) calls
+ to `set_data`
+3. Finish migration using `finish`, providing contract code
+
+During migration no one can insert code at address of this contract,
+as [`pallet::OnMethodCall`] prevents this, and no one can call this contract,
+as code is only supplied at final stage of contract deployment
\ No newline at end of file
pallets/evm-migration/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/evm-migration/src/benchmarking.rs
+++ b/pallets/evm-migration/src/benchmarking.rs
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+#![allow(missing_docs)]
+
use super::{Call, Config, Pallet};
use frame_benchmarking::benchmarks;
use frame_system::RawOrigin;
pallets/evm-migration/src/lib.rsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617#![doc = include_str!("../README.md")]17#![cfg_attr(not(feature = "std"), no_std)]18#![cfg_attr(not(feature = "std"), no_std)]19#![deny(missing_docs)]182019pub use pallet::*;21pub use pallet::*;20#[cfg(feature = "runtime-benchmarks")]22#[cfg(feature = "runtime-benchmarks")]323433 #[pallet::config]35 #[pallet::config]34 pub trait Config: frame_system::Config + pallet_evm::Config {36 pub trait Config: frame_system::Config + pallet_evm::Config {37 /// Weights35 type WeightInfo: WeightInfo;38 type WeightInfo: WeightInfo;36 }39 }3740434644 #[pallet::error]47 #[pallet::error]45 pub enum Error<T> {48 pub enum Error<T> {49 /// Can only migrate to empty address.46 AccountNotEmpty,50 AccountNotEmpty,51 /// Migration of this account is not yet started, or already finished.47 AccountIsNotMigrating,52 AccountIsNotMigrating,48 }53 }4954535854 #[pallet::call]59 #[pallet::call]55 impl<T: Config> Pallet<T> {60 impl<T: Config> Pallet<T> {61 /// Start contract migration, inserts contract stub at target address,62 /// and marks account as pending, allowing to insert storage56 #[pallet::weight(<SelfWeightOf<T>>::begin())]63 #[pallet::weight(<SelfWeightOf<T>>::begin())]57 pub fn begin(origin: OriginFor<T>, address: H160) -> DispatchResult {64 pub fn begin(origin: OriginFor<T>, address: H160) -> DispatchResult {58 ensure_root(origin)?;65 ensure_root(origin)?;65 Ok(())72 Ok(())66 }73 }677475 /// Insert items into contract storage, this method can be called76 /// multiple times68 #[pallet::weight(<SelfWeightOf<T>>::set_data(data.len() as u32))]77 #[pallet::weight(<SelfWeightOf<T>>::set_data(data.len() as u32))]69 pub fn set_data(78 pub fn set_data(70 origin: OriginFor<T>,79 origin: OriginFor<T>,83 Ok(())92 Ok(())84 }93 }859495 /// Finish contract migration, allows it to be called.96 /// It is not possible to alter contract storage via [`Self::set_data`]97 /// after this call.86 #[pallet::weight(<SelfWeightOf<T>>::finish(code.len() as u32))]98 #[pallet::weight(<SelfWeightOf<T>>::finish(code.len() as u32))]87 pub fn finish(origin: OriginFor<T>, address: H160, code: Vec<u8>) -> DispatchResult {99 pub fn finish(origin: OriginFor<T>, address: H160, code: Vec<u8>) -> DispatchResult {88 ensure_root(origin)?;100 ensure_root(origin)?;97 }109 }98 }110 }99111112 /// Implements [`pallet_evm::OnMethodCall`], which reserves accounts with pending migration100 pub struct OnMethodCall<T>(PhantomData<T>);113 pub struct OnMethodCall<T>(PhantomData<T>);101 impl<T: Config> pallet_evm::OnMethodCall<T> for OnMethodCall<T> {114 impl<T: Config> pallet_evm::OnMethodCall<T> for OnMethodCall<T> {102 fn is_reserved(contract: &H160) -> bool {115 fn is_reserved(contract: &H160) -> bool {pallets/evm-migration/src/weights.rsdiffbeforeafterboth--- a/pallets/evm-migration/src/weights.rs
+++ b/pallets/evm-migration/src/weights.rs
@@ -26,6 +26,7 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
+#![allow(missing_docs)]
#![allow(clippy::unnecessary_cast)]
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};