mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 01:27:56 +00:00
Make sudo use decl_error! (#4369)
* Make sudo use `decl_error` * copy pasta error * Update to use `as_str` * Add doc * Add back `decl_error`
This commit is contained in:
@@ -88,10 +88,11 @@
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use sp_runtime::{
|
||||
traits::{StaticLookup, Dispatchable}, DispatchError,
|
||||
traits::{StaticLookup, Dispatchable, ModuleDispatchError}, DispatchError,
|
||||
};
|
||||
|
||||
use frame_support::{
|
||||
Parameter, decl_module, decl_event, decl_storage, ensure,
|
||||
Parameter, decl_module, decl_event, decl_storage, decl_error, ensure,
|
||||
weights::SimpleDispatchInfo,
|
||||
};
|
||||
use frame_system::{self as system, ensure_signed};
|
||||
@@ -107,6 +108,8 @@ pub trait Trait: frame_system::Trait {
|
||||
decl_module! {
|
||||
// Simple declaration of the `Module` type. Lets the macro know what it's working on.
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
type Error = Error;
|
||||
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Authenticates the sudo key and dispatches a function call with `Root` origin.
|
||||
@@ -122,8 +125,8 @@ decl_module! {
|
||||
#[weight = SimpleDispatchInfo::FreeOperational]
|
||||
fn sudo(origin, proposal: Box<T::Proposal>) {
|
||||
// This is a public call, so we ensure that the origin is some signed account.
|
||||
let sender = ensure_signed(origin)?;
|
||||
ensure!(sender == Self::key(), "only the current sudo key can sudo");
|
||||
let sender = ensure_signed(origin).map_err(|e| e.as_str())?;
|
||||
ensure!(sender == Self::key(), Error::RequireSudo);
|
||||
|
||||
let res = match proposal.dispatch(frame_system::RawOrigin::Root.into()) {
|
||||
Ok(_) => true,
|
||||
@@ -148,8 +151,8 @@ decl_module! {
|
||||
/// # </weight>
|
||||
fn set_key(origin, new: <T::Lookup as StaticLookup>::Source) {
|
||||
// This is a public call, so we ensure that the origin is some signed account.
|
||||
let sender = ensure_signed(origin)?;
|
||||
ensure!(sender == Self::key(), "only the current sudo key can change the sudo key");
|
||||
let sender = ensure_signed(origin).map_err(|e| e.as_str())?;
|
||||
ensure!(sender == Self::key(), Error::RequireSudo);
|
||||
let new = T::Lookup::lookup(new)?;
|
||||
|
||||
Self::deposit_event(RawEvent::KeyChanged(Self::key()));
|
||||
@@ -170,8 +173,8 @@ decl_module! {
|
||||
#[weight = SimpleDispatchInfo::FixedOperational(0)]
|
||||
fn sudo_as(origin, who: <T::Lookup as StaticLookup>::Source, proposal: Box<T::Proposal>) {
|
||||
// This is a public call, so we ensure that the origin is some signed account.
|
||||
let sender = ensure_signed(origin)?;
|
||||
ensure!(sender == Self::key(), "only the current sudo key can sudo");
|
||||
let sender = ensure_signed(origin).map_err(|e| e.as_str())?;
|
||||
ensure!(sender == Self::key(), Error::RequireSudo);
|
||||
|
||||
let who = T::Lookup::lookup(who)?;
|
||||
|
||||
@@ -206,3 +209,11 @@ decl_storage! {
|
||||
Key get(fn key) config(): T::AccountId;
|
||||
}
|
||||
}
|
||||
|
||||
decl_error! {
|
||||
/// Error for the Sudo module
|
||||
pub enum Error {
|
||||
/// Sender must be the Sudo account
|
||||
RequireSudo,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user