Sudo wrapper for paras (#1517)

* Sudo wrapper for paras

* Move to separate module

* Add some docs
This commit is contained in:
Fedor Sakharov
2020-08-03 22:32:57 +03:00
committed by GitHub
parent 2afa2b035f
commit a9e3a1b11d
6 changed files with 75 additions and 5 deletions
@@ -0,0 +1,63 @@
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! A simple wrapper allowing `Sudo` to call into `paras` routines.
use frame_support::{
decl_error, decl_module,
dispatch::DispatchResult,
weights::DispatchClass,
};
use system::ensure_root;
use runtime_parachains::paras::{
self,
ParaGenesisArgs,
};
use primitives::v1::Id as ParaId;
/// The module's configuration trait.
pub trait Trait: paras::Trait { }
decl_error! {
pub enum Error for Module<T: Trait> { }
}
decl_module! {
/// A sudo wrapper to call into v1 paras module.
pub struct Module<T: Trait> for enum Call where origin: <T as system::Trait>::Origin, system = system {
type Error = Error<T>;
/// Schedule a para to be initialized at the start of the next session.
#[weight = (1_000, DispatchClass::Operational)]
pub fn sudo_schedule_para_initialize(
origin,
id: ParaId,
genesis: ParaGenesisArgs,
) -> DispatchResult {
ensure_root(origin)?;
paras::Module::<T>::schedule_para_initialize(id, genesis);
Ok(())
}
/// Schedule a para to be cleaned up at the start of the next session.
#[weight = (1_000, DispatchClass::Operational)]
pub fn sudo_schedule_para_cleanup(origin, id: ParaId) -> DispatchResult {
ensure_root(origin)?;
paras::Module::<T>::schedule_para_cleanup(id);
Ok(())
}
}
}