From 68058b4890a6ade3cb0d3aee26f23609e5b658fb Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Tue, 12 Jul 2022 16:51:57 +0000 Subject: [PATCH] doc(pallet-evm-migration): document public api --- --- /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 --- 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 . +#![allow(missing_docs)] + use super::{Call, Config, Pallet}; use frame_benchmarking::benchmarks; use frame_system::RawOrigin; --- a/pallets/evm-migration/src/lib.rs +++ b/pallets/evm-migration/src/lib.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Unique Network. If not, see . +#![doc = include_str!("../README.md")] #![cfg_attr(not(feature = "std"), no_std)] +#![deny(missing_docs)] pub use pallet::*; #[cfg(feature = "runtime-benchmarks")] @@ -32,6 +34,7 @@ #[pallet::config] pub trait Config: frame_system::Config + pallet_evm::Config { + /// Weights type WeightInfo: WeightInfo; } @@ -43,7 +46,9 @@ #[pallet::error] pub enum Error { + /// Can only migrate to empty address. AccountNotEmpty, + /// Migration of this account is not yet started, or already finished. AccountIsNotMigrating, } @@ -53,6 +58,8 @@ #[pallet::call] impl Pallet { + /// Start contract migration, inserts contract stub at target address, + /// and marks account as pending, allowing to insert storage #[pallet::weight(>::begin())] pub fn begin(origin: OriginFor, address: H160) -> DispatchResult { ensure_root(origin)?; @@ -65,6 +72,8 @@ Ok(()) } + /// Insert items into contract storage, this method can be called + /// multiple times #[pallet::weight(>::set_data(data.len() as u32))] pub fn set_data( origin: OriginFor, @@ -83,6 +92,9 @@ Ok(()) } + /// Finish contract migration, allows it to be called. + /// It is not possible to alter contract storage via [`Self::set_data`] + /// after this call. #[pallet::weight(>::finish(code.len() as u32))] pub fn finish(origin: OriginFor, address: H160, code: Vec) -> DispatchResult { ensure_root(origin)?; @@ -97,6 +109,7 @@ } } + /// Implements [`pallet_evm::OnMethodCall`], which reserves accounts with pending migration pub struct OnMethodCall(PhantomData); impl pallet_evm::OnMethodCall for OnMethodCall { fn is_reserved(contract: &H160) -> bool { --- 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}}; -- gitstuff