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

no changes

modifiedpallets/evm-migration/src/benchmarking.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/>.
16
17#![allow(missing_docs)]
1618
17use super::{Call, Config, Pallet};19use super::{Call, Config, Pallet};
18use frame_benchmarking::benchmarks;20use frame_benchmarking::benchmarks;
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
26#![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)]
3031
31use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};32use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};