mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 12:17:58 +00:00
Allow Sudo to do anything (#6375)
* All Sudo to do anything. * Rename old labels.
This commit is contained in:
@@ -88,12 +88,12 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use sp_runtime::{DispatchResult, traits::{StaticLookup, Dispatchable}};
|
||||
use sp_runtime::{DispatchResult, traits::StaticLookup};
|
||||
|
||||
use frame_support::{
|
||||
Parameter, decl_module, decl_event, decl_storage, decl_error, ensure,
|
||||
};
|
||||
use frame_support::weights::{Weight, GetDispatchInfo};
|
||||
use frame_support::{weights::{Weight, GetDispatchInfo}, traits::UnfilteredDispatchable};
|
||||
use frame_system::{self as system, ensure_signed};
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -106,7 +106,7 @@ pub trait Trait: frame_system::Trait {
|
||||
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
|
||||
|
||||
/// A sudo-able call.
|
||||
type Call: Parameter + Dispatchable<Origin=Self::Origin> + GetDispatchInfo;
|
||||
type Call: Parameter + UnfilteredDispatchable<Origin=Self::Origin> + GetDispatchInfo;
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
@@ -132,7 +132,7 @@ decl_module! {
|
||||
let sender = ensure_signed(origin)?;
|
||||
ensure!(sender == Self::key(), Error::<T>::RequireSudo);
|
||||
|
||||
let res = call.dispatch(frame_system::RawOrigin::Root.into());
|
||||
let res = call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into());
|
||||
Self::deposit_event(RawEvent::Sudid(res.map(|_| ()).map_err(|e| e.error)));
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ decl_module! {
|
||||
let sender = ensure_signed(origin)?;
|
||||
ensure!(sender == Self::key(), Error::<T>::RequireSudo);
|
||||
|
||||
let res = call.dispatch(frame_system::RawOrigin::Root.into());
|
||||
let res = call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into());
|
||||
Self::deposit_event(RawEvent::Sudid(res.map(|_| ()).map_err(|e| e.error)));
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ decl_module! {
|
||||
|
||||
let who = T::Lookup::lookup(who)?;
|
||||
|
||||
let res = match call.dispatch(frame_system::RawOrigin::Signed(who).into()) {
|
||||
let res = match call.dispatch_bypass_filter(frame_system::RawOrigin::Signed(who).into()) {
|
||||
Ok(_) => true,
|
||||
Err(e) => {
|
||||
sp_runtime::print(e);
|
||||
|
||||
@@ -24,10 +24,11 @@ use frame_support::{
|
||||
};
|
||||
use sp_core::H256;
|
||||
// The testing primitives are very useful for avoiding having to work with signatures
|
||||
// or public keys.
|
||||
// or public keys.
|
||||
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header};
|
||||
use sp_io;
|
||||
use crate as sudo;
|
||||
use frame_support::traits::Filter;
|
||||
|
||||
// Logger module to track execution.
|
||||
pub mod logger {
|
||||
@@ -58,7 +59,7 @@ pub mod logger {
|
||||
|
||||
#[weight = *weight]
|
||||
fn privileged_i32_log(origin, i: i32, weight: Weight){
|
||||
// Ensure that the `origin` is `Root`.
|
||||
// Ensure that the `origin` is `Root`.
|
||||
ensure_root(origin)?;
|
||||
<I32Log>::append(i);
|
||||
Self::deposit_event(RawEvent::AppendI32(i, weight));
|
||||
@@ -66,7 +67,7 @@ pub mod logger {
|
||||
|
||||
#[weight = *weight]
|
||||
fn non_privileged_log(origin, i: i32, weight: Weight){
|
||||
// Ensure that the `origin` is some signed account.
|
||||
// Ensure that the `origin` is some signed account.
|
||||
let sender = ensure_signed(origin)?;
|
||||
<I32Log>::append(i);
|
||||
<AccountLog<T>>::append(sender.clone());
|
||||
@@ -112,8 +113,15 @@ parameter_types! {
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::one();
|
||||
}
|
||||
|
||||
pub struct BlockEverything;
|
||||
impl Filter<Call> for BlockEverything {
|
||||
fn filter(_: &Call) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl frame_system::Trait for Test {
|
||||
type BaseCallFilter = ();
|
||||
type BaseCallFilter = BlockEverything;
|
||||
type Origin = Origin;
|
||||
type Call = Call;
|
||||
type Index = u64;
|
||||
@@ -121,7 +129,7 @@ impl frame_system::Trait for Test {
|
||||
type Hash = H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Header = Header;
|
||||
type Event = TestEvent;
|
||||
type BlockHashCount = BlockHashCount;
|
||||
|
||||
Reference in New Issue
Block a user