git.delta.rocks / unique-network / refs/commits / 68058b4890a6

difftreelog

doc(pallet-evm-migration): document public api

Yaroslav Bolyukin2022-07-12parent: #19dbab9.patch.diff
in: master

4 files changed

addedpallets/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
modifiedpallets/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;
modifiedpallets/evm-migration/src/lib.rsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// 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/>.
1616
17#![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)]
1820
19pub use pallet::*;21pub use pallet::*;
20#[cfg(feature = "runtime-benchmarks")]22#[cfg(feature = "runtime-benchmarks")]
3234
33 #[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 /// Weights
35 type WeightInfo: WeightInfo;38 type WeightInfo: WeightInfo;
36 }39 }
3740
4346
44 #[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 }
4954
5358
54 #[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 storage
56 #[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 }
6774
75 /// Insert items into contract storage, this method can be called
76 /// multiple times
68 #[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 }
8594
95 /// 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 }
99111
112 /// Implements [`pallet_evm::OnMethodCall`], which reserves accounts with pending migration
100 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 {
modifiedpallets/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}};