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.rsdiffbeforeafterboth--- 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 <http://www.gnu.org/licenses/>.
+#![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<T> {
+ /// 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<T: Config> Pallet<T> {
+ /// Start contract migration, inserts contract stub at target address,
+ /// and marks account as pending, allowing to insert storage
#[pallet::weight(<SelfWeightOf<T>>::begin())]
pub fn begin(origin: OriginFor<T>, 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(<SelfWeightOf<T>>::set_data(data.len() as u32))]
pub fn set_data(
origin: OriginFor<T>,
@@ -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(<SelfWeightOf<T>>::finish(code.len() as u32))]
pub fn finish(origin: OriginFor<T>, address: H160, code: Vec<u8>) -> DispatchResult {
ensure_root(origin)?;
@@ -97,6 +109,7 @@
}
}
+ /// Implements [`pallet_evm::OnMethodCall`], which reserves accounts with pending migration
pub struct OnMethodCall<T>(PhantomData<T>);
impl<T: Config> pallet_evm::OnMethodCall<T> for OnMethodCall<T> {
fn is_reserved(contract: &H160) -> bool {
pallets/evm-migration/src/weights.rsdiffbeforeafterboth26#![cfg_attr(rustfmt, rustfmt_skip)]26#![cfg_attr(rustfmt, rustfmt_skip)]27#![allow(unused_parens)]27#![allow(unused_parens)]28#![allow(unused_imports)]28#![allow(unused_imports)]29#![allow(missing_docs)]29#![allow(clippy::unnecessary_cast)]30#![allow(clippy::unnecessary_cast)]303131use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};32use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};