Created
May 10, 2019 11:25
-
-
Save shawntabrizi/b4a1952dbd3af113e8a3498418e52741 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(prelude_import)] | |
#![no_std] | |
// Copyright 2017-2019 Parity Technologies (UK) Ltd. | |
// This file is part of Substrate. | |
// Substrate 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. | |
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>. | |
//! # Sudo Module | |
//! | |
//! ## Overview | |
//! | |
//! The sudo module allows for a single account (called the "sudo key") | |
//! to execute dispatchable functions that require a `Root` call | |
//! or designate a new account to replace them as the sudo key. | |
//! Only one account can be the sudo key at a time. | |
//! | |
//! You can start using the sudo module by implementing the sudo [`Trait`]. | |
//! | |
//! Supported dispatchable functions are documented in the [`Call`] enum. | |
//! | |
//! ## Interface | |
//! | |
//! ### Dispatchable Functions | |
//! | |
//! Only the sudo key can call the dispatchable functions from the sudo module. | |
//! | |
//! * `sudo` - Make a `Root` call to a dispatchable function. | |
//! * `set_key` - Assign a new account to be the sudo key. | |
//! | |
//! Please refer to the [`Call`] enum and its associated variants for documentation on each function. | |
//! | |
//! ## Usage | |
//! | |
//! ### Prerequisites | |
//! | |
//! To use the sudo module in your runtime, you must implement the following trait in your runtime: | |
//! | |
//! ```ignore | |
//! impl sudo::Trait for Runtime { | |
//! type Event = Event; | |
//! type Proposal = Call; | |
//! } | |
//! ``` | |
//! | |
//! You can then import the Sudo module in your `construct_runtime!` macro with: | |
//! | |
//! ```ignore | |
//! Sudo: sudo, | |
//! ``` | |
//! | |
//! ### Executing Privileged Functions | |
//! | |
//! The sudo module itself is not intended to be used within other modules. | |
//! Instead, you can build "privileged functions" in other modules that require `Root` origin. | |
//! You can execute these privileged functions by calling `sudo` with the sudo key account. | |
//! Privileged functions cannot be directly executed via an extrinsic. | |
//! | |
//! Learn more about privileged functions and `Root` origin in the [`Origin`] type documentation. | |
//! | |
//! ### Simple Code Snippet | |
//! | |
//! This is an example of a module that exposes a privileged function: | |
//! | |
//! ```ignore | |
//! use support::{decl_module, dispatch::Result}; | |
//! use system::ensure_root; | |
//! | |
//! pub trait Trait: system::Trait {} | |
//! | |
//! decl_module! { | |
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin { | |
//! pub fn privileged_function(origin) -> Result { | |
//! ensure_root(origin)?; | |
//! | |
//! // do something... | |
//! | |
//! Ok(()) | |
//! } | |
//! } | |
//! } | |
//! ``` | |
//! | |
//! ### Example from SRML | |
//! | |
//! The consensus module exposes a `set_code` privileged function | |
//! that allows you to set the on-chain Wasm runtime code: | |
//! | |
//! ```ignore | |
//! /// Set the new code. | |
//! pub fn set_code(new: Vec<u8>) { | |
//! storage::unhashed::put_raw(well_known_keys::CODE, &new); | |
//! } | |
//! ``` | |
//! | |
//! ## Genesis Config | |
//! | |
//! To use the sudo module, you need to set an initial superuser account as the sudo `key`. | |
//! | |
//! ```ignore | |
//! GenesisConfig { | |
//! sudo: Some(SudoConfig { | |
//! key: AccountId, | |
//! }) | |
//! } | |
//! ``` | |
//! | |
//! ## Related Modules | |
//! | |
//! * [Consensus](../srml_consensus/index.html) | |
//! * [Democracy](../srml_democracy/index.html) | |
//! | |
//! [`Call`]: ./enum.Call.html | |
//! [`Trait`]: ./trait.Trait.html | |
//! [`Origin`]: https://docs.substrate.dev/docs/substrate-types | |
#[prelude_import] | |
use ::std::prelude::v1::*; | |
#[macro_use] | |
extern crate std as std; | |
use sr_std::prelude::*; | |
use sr_primitives::traits::StaticLookup; | |
use srml_support::{StorageValue, Parameter, Dispatchable, decl_module, | |
decl_event, decl_storage, ensure}; | |
use system::ensure_signed; | |
pub trait Trait: system::Trait { | |
/// The overarching event type. | |
type | |
Event: From<Event<Self>> + | |
Into<<Self as system::Trait>::Event>; | |
/// A sudo-able call. | |
type | |
Proposal: Parameter + | |
Dispatchable<Origin | |
= | |
Self::Origin>; | |
} | |
// Simple declaration of the `Module` type. Lets the macro know what it's working on. | |
// This is a public call, so we ensure that the origin is some signed account. | |
// This is a public call, so we ensure that the origin is some signed account. | |
#[cfg(feature = "std")] | |
#[structural_match] | |
#[rustc_copy_clone_marker] | |
pub struct Module<T: Trait>(::std::marker::PhantomData<(T)>); | |
#[automatically_derived] | |
#[allow(unused_qualifications)] | |
impl <T: ::std::clone::Clone + Trait> ::std::clone::Clone for Module<T> { | |
#[inline] | |
fn clone(&self) -> Module<T> { | |
match *self { | |
Module(ref __self_0_0) => | |
Module(::std::clone::Clone::clone(&(*__self_0_0))), | |
} | |
} | |
} | |
#[automatically_derived] | |
#[allow(unused_qualifications)] | |
impl <T: ::std::marker::Copy + Trait> ::std::marker::Copy for Module<T> { } | |
#[automatically_derived] | |
#[allow(unused_qualifications)] | |
impl <T: ::std::cmp::PartialEq + Trait> ::std::cmp::PartialEq for Module<T> { | |
#[inline] | |
fn eq(&self, other: &Module<T>) -> bool { | |
match *other { | |
Module(ref __self_1_0) => | |
match *self { | |
Module(ref __self_0_0) => (*__self_0_0) == (*__self_1_0), | |
}, | |
} | |
} | |
#[inline] | |
fn ne(&self, other: &Module<T>) -> bool { | |
match *other { | |
Module(ref __self_1_0) => | |
match *self { | |
Module(ref __self_0_0) => (*__self_0_0) != (*__self_1_0), | |
}, | |
} | |
} | |
} | |
#[automatically_derived] | |
#[allow(unused_qualifications)] | |
impl <T: ::std::cmp::Eq + Trait> ::std::cmp::Eq for Module<T> { | |
#[inline] | |
#[doc(hidden)] | |
fn assert_receiver_is_total_eq(&self) -> () { | |
{ | |
let _: | |
::std::cmp::AssertParamIsEq<::std::marker::PhantomData<(T)>>; | |
} | |
} | |
} | |
#[automatically_derived] | |
#[allow(unused_qualifications)] | |
impl <T: ::std::fmt::Debug + Trait> ::std::fmt::Debug for Module<T> { | |
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { | |
match *self { | |
Module(ref __self_0_0) => { | |
let mut debug_trait_builder = f.debug_tuple("Module"); | |
let _ = debug_trait_builder.field(&&(*__self_0_0)); | |
debug_trait_builder.finish() | |
} | |
} | |
} | |
} | |
impl <T: Trait> | |
::srml_support::runtime_primitives::traits::OnInitialize<T::BlockNumber> for | |
Module<T> { | |
} | |
impl <T: Trait> | |
::srml_support::runtime_primitives::traits::OnFinalize<T::BlockNumber> for | |
Module<T> { | |
} | |
impl <T: Trait> | |
::srml_support::runtime_primitives::traits::OffchainWorker<T::BlockNumber> | |
for Module<T> { | |
} | |
impl <T: Trait> Module<T> { | |
fn deposit_event(event: Event<T>) { | |
<system::Module<T>>::deposit_event(<T as Trait>::from(event).into()); | |
} | |
} | |
/// Can also be called using [`Call`]. | |
/// | |
/// [`Call`]: enum.Call.html | |
impl <T: Trait> Module<T> { | |
#[doc = | |
r" Authenticates the sudo key and dispatches a function call with `Root` origin."] | |
#[doc = r""] | |
#[doc = r" The dispatch origin for this call must be _Signed_."] | |
fn sudo(origin: T::Origin, proposal: Box<T::Proposal>) | |
-> ::srml_support::dispatch::Result { | |
{ | |
let sender = ensure_signed(origin)?; | |
{ | |
if !(sender == Self::key()) { | |
{ return Err("only the current sudo key can sudo"); }; | |
} | |
}; | |
let ok = | |
proposal.dispatch(system::RawOrigin::Root.into()).is_ok(); | |
Self::deposit_event(RawEvent::Sudid(ok)); | |
} | |
Ok(()) | |
} | |
#[doc = | |
r" Authenticates the current sudo key and sets the given AccountId (`new`) as the new sudo key."] | |
#[doc = r""] | |
#[doc = r" The dispatch origin for this call must be _Signed_."] | |
fn set_key(origin: T::Origin, new: <T::Lookup as StaticLookup>::Source) | |
-> ::srml_support::dispatch::Result { | |
{ | |
let sender = ensure_signed(origin)?; | |
{ | |
if !(sender == Self::key()) { | |
{ | |
return Err("only the current sudo key can change the sudo key"); | |
}; | |
} | |
}; | |
let new = T::Lookup::lookup(new)?; | |
Self::deposit_event(RawEvent::KeyChanged(Self::key())); | |
<Key<T>>::put(new); | |
} | |
Ok(()) | |
} | |
} | |
#[cfg(feature = "std")] | |
pub enum Call<T: Trait> { | |
#[doc(hidden)] | |
__PhantomItem(::std::marker::PhantomData<(T)>, | |
::srml_support::dispatch::Never), | |
#[allow(non_camel_case_types)] | |
#[doc = | |
r" Authenticates the sudo key and dispatches a function call with `Root` origin."] | |
#[doc = r""] | |
#[doc = r" The dispatch origin for this call must be _Signed_."] | |
sudo(Box<T::Proposal>), | |
#[allow(non_camel_case_types)] | |
#[doc = | |
r" Authenticates the current sudo key and sets the given AccountId (`new`) as the new sudo key."] | |
#[doc = r""] | |
#[doc = r" The dispatch origin for this call must be _Signed_."] | |
set_key(<T::Lookup as StaticLookup>::Source), | |
} | |
impl <T: Trait> ::srml_support::dispatch::Clone for Call<T> { | |
fn clone(&self) -> Self { | |
match *self { | |
Call::sudo(ref proposal) => Call::sudo((*proposal).clone()), | |
Call::set_key(ref new) => Call::set_key((*new).clone()), | |
_ => { | |
{ | |
::std::rt::begin_panic("internal error: entered unreachable code", | |
&("/Users/shawntabrizi/.cargo/git/checkouts/substrate-7e08433d4c370a21/f2f2994/srml/sudo/src/lib.rs", | |
140u32, 1u32)) | |
} | |
} | |
} | |
} | |
} | |
impl <T: Trait> ::srml_support::dispatch::PartialEq for Call<T> { | |
fn eq(&self, _other: &Self) -> bool { | |
match *self { | |
Call::sudo(ref proposal) => { | |
let self_params = (proposal,); | |
if let Call::sudo(ref proposal) = *_other { | |
self_params == (proposal,) | |
} else { | |
match *_other { | |
Call::__PhantomItem(_, _) => { | |
{ | |
::std::rt::begin_panic("internal error: entered unreachable code", | |
&("/Users/shawntabrizi/.cargo/git/checkouts/substrate-7e08433d4c370a21/f2f2994/srml/sudo/src/lib.rs", | |
140u32, 1u32)) | |
} | |
} | |
_ => false, | |
} | |
} | |
} | |
Call::set_key(ref new) => { | |
let self_params = (new,); | |
if let Call::set_key(ref new) = *_other { | |
self_params == (new,) | |
} else { | |
match *_other { | |
Call::__PhantomItem(_, _) => { | |
{ | |
::std::rt::begin_panic("internal error: entered unreachable code", | |
&("/Users/shawntabrizi/.cargo/git/checkouts/substrate-7e08433d4c370a21/f2f2994/srml/sudo/src/lib.rs", | |
140u32, 1u32)) | |
} | |
} | |
_ => false, | |
} | |
} | |
} | |
_ => { | |
{ | |
::std::rt::begin_panic("internal error: entered unreachable code", | |
&("/Users/shawntabrizi/.cargo/git/checkouts/substrate-7e08433d4c370a21/f2f2994/srml/sudo/src/lib.rs", | |
140u32, 1u32)) | |
} | |
} | |
} | |
} | |
} | |
impl <T: Trait> ::srml_support::dispatch::Eq for Call<T> { } | |
#[cfg(feature = "std")] | |
impl <T: Trait> ::srml_support::dispatch::fmt::Debug for Call<T> { | |
fn fmt(&self, _f: &mut ::srml_support::dispatch::fmt::Formatter) | |
-> | |
::srml_support::dispatch::result::Result<(), | |
::srml_support::dispatch::fmt::Error> { | |
match *self { | |
Call::sudo(ref proposal) => | |
_f.write_fmt(::std::fmt::Arguments::new_v1(&["", ""], | |
&match (&"sudo", | |
&(proposal.clone(),)) | |
{ | |
(arg0, arg1) => | |
[::std::fmt::ArgumentV1::new(arg0, | |
::std::fmt::Display::fmt), | |
::std::fmt::ArgumentV1::new(arg1, | |
::std::fmt::Debug::fmt)], | |
})), | |
Call::set_key(ref new) => | |
_f.write_fmt(::std::fmt::Arguments::new_v1(&["", ""], | |
&match (&"set_key", | |
&(new.clone(),)) | |
{ | |
(arg0, arg1) => | |
[::std::fmt::ArgumentV1::new(arg0, | |
::std::fmt::Display::fmt), | |
::std::fmt::ArgumentV1::new(arg1, | |
::std::fmt::Debug::fmt)], | |
})), | |
_ => { | |
{ | |
::std::rt::begin_panic("internal error: entered unreachable code", | |
&("/Users/shawntabrizi/.cargo/git/checkouts/substrate-7e08433d4c370a21/f2f2994/srml/sudo/src/lib.rs", | |
140u32, 1u32)) | |
} | |
} | |
} | |
} | |
} | |
impl <T: Trait> ::srml_support::dispatch::Decode for Call<T> { | |
fn decode<Input: ::srml_support::dispatch::Input>(input: &mut Input) | |
-> Option<Self> { | |
let _input_id = input.read_byte()?; | |
{ | |
if _input_id == (0) { | |
let proposal = | |
::srml_support::dispatch::Decode::decode(input)?; | |
return Some(Call::sudo(proposal)); | |
} | |
{ | |
if _input_id == (0 + 1) { | |
let new = | |
::srml_support::dispatch::Decode::decode(input)?; | |
return Some(Call::set_key(new)); | |
} | |
None | |
} | |
} | |
} | |
} | |
impl <T: Trait> ::srml_support::dispatch::Encode for Call<T> { | |
fn encode_to<W: ::srml_support::dispatch::Output>(&self, _dest: &mut W) { | |
{ | |
if let Call::sudo(ref proposal) = *self { | |
_dest.push_byte((0) as u8); | |
proposal.encode_to(_dest); | |
} | |
{ | |
if let Call::set_key(ref new) = *self { | |
_dest.push_byte((0 + 1) as u8); | |
new.encode_to(_dest); | |
} | |
{ } | |
} | |
}; | |
} | |
} | |
impl <T: Trait> ::srml_support::dispatch::Dispatchable for Call<T> { | |
type | |
Trait | |
= | |
T; | |
type | |
Origin | |
= | |
T::Origin; | |
fn dispatch(self, _origin: Self::Origin) | |
-> ::srml_support::dispatch::Result { | |
match self { | |
Call::sudo(proposal) => { <Module<T>>::sudo(_origin, proposal) } | |
Call::set_key(new) => { <Module<T>>::set_key(_origin, new) } | |
Call::__PhantomItem(_, _) => { | |
{ | |
{ | |
{ | |
::std::rt::begin_panic_fmt(&::std::fmt::Arguments::new_v1(&["internal error: entered unreachable code: "], | |
&match (&"__PhantomItem should never be used.",) | |
{ | |
(arg0,) | |
=> | |
[::std::fmt::ArgumentV1::new(arg0, | |
::std::fmt::Display::fmt)], | |
}), | |
&("/Users/shawntabrizi/.cargo/git/checkouts/substrate-7e08433d4c370a21/f2f2994/srml/sudo/src/lib.rs", | |
140u32, 1u32)) | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
impl <T: Trait> ::srml_support::dispatch::Callable for Module<T> { | |
type | |
Call | |
= | |
Call<T>; | |
} | |
impl <T: Trait> Module<T> { | |
#[doc(hidden)] | |
pub fn dispatch<D: ::srml_support::dispatch::Dispatchable<Trait = | |
T>>(d: D, origin: D::Origin) | |
-> ::srml_support::dispatch::Result { | |
d.dispatch(origin) | |
} | |
} | |
impl <T: Trait> Module<T> { | |
#[doc(hidden)] | |
pub fn call_functions() | |
-> &'static [::srml_support::dispatch::FunctionMetadata] { | |
&[::srml_support::dispatch::FunctionMetadata{name: | |
::srml_support::dispatch::DecodeDifferent::Encode("sudo"), | |
arguments: | |
::srml_support::dispatch::DecodeDifferent::Encode(&[::srml_support::dispatch::FunctionArgumentMetadata{name: | |
::srml_support::dispatch::DecodeDifferent::Encode("proposal"), | |
ty: | |
::srml_support::dispatch::DecodeDifferent::Encode("Box<T::Proposal>"),}]), | |
documentation: | |
::srml_support::dispatch::DecodeDifferent::Encode(&[r" Authenticates the sudo key and dispatches a function call with `Root` origin.", | |
r"", | |
r" The dispatch origin for this call must be _Signed_."]),}, | |
::srml_support::dispatch::FunctionMetadata{name: | |
::srml_support::dispatch::DecodeDifferent::Encode("set_key"), | |
arguments: | |
::srml_support::dispatch::DecodeDifferent::Encode(&[::srml_support::dispatch::FunctionArgumentMetadata{name: | |
::srml_support::dispatch::DecodeDifferent::Encode("new"), | |
ty: | |
::srml_support::dispatch::DecodeDifferent::Encode("<T::Lookup as StaticLookup>::Source"),}]), | |
documentation: | |
::srml_support::dispatch::DecodeDifferent::Encode(&[r" Authenticates the current sudo key and sets the given AccountId (`new`) as the new sudo key.", | |
r"", | |
r" The dispatch origin for this call must be _Signed_."]),}] | |
} | |
} | |
/// [`RawEvent`] specialized for the configuration [`Trait`] | |
/// | |
/// [`RawEvent`]: enum.RawEvent.html | |
/// [`Trait`]: trait.Trait.html | |
pub type Event<T> = RawEvent<<T as system::Trait>::AccountId>; | |
/// Events for this module. | |
/// | |
#[structural_match] | |
pub enum RawEvent<AccountId> { | |
#[doc = r" A sudo just took place."] | |
Sudid(bool), | |
#[doc = r" The sudoer just switched identity; the old key is supplied."] | |
KeyChanged(AccountId), | |
} | |
#[automatically_derived] | |
#[allow(unused_qualifications)] | |
impl <AccountId: ::std::clone::Clone> ::std::clone::Clone for | |
RawEvent<AccountId> { | |
#[inline] | |
fn clone(&self) -> RawEvent<AccountId> { | |
match (&*self,) { | |
(&RawEvent::Sudid(ref __self_0),) => | |
RawEvent::Sudid(::std::clone::Clone::clone(&(*__self_0))), | |
(&RawEvent::KeyChanged(ref __self_0),) => | |
RawEvent::KeyChanged(::std::clone::Clone::clone(&(*__self_0))), | |
} | |
} | |
} | |
#[automatically_derived] | |
#[allow(unused_qualifications)] | |
impl <AccountId: ::std::cmp::PartialEq> ::std::cmp::PartialEq for | |
RawEvent<AccountId> { | |
#[inline] | |
fn eq(&self, other: &RawEvent<AccountId>) -> bool { | |
{ | |
let __self_vi = | |
unsafe { ::std::intrinsics::discriminant_value(&*self) } as | |
isize; | |
let __arg_1_vi = | |
unsafe { ::std::intrinsics::discriminant_value(&*other) } as | |
isize; | |
if true && __self_vi == __arg_1_vi { | |
match (&*self, &*other) { | |
(&RawEvent::Sudid(ref __self_0), | |
&RawEvent::Sudid(ref __arg_1_0)) => | |
(*__self_0) == (*__arg_1_0), | |
(&RawEvent::KeyChanged(ref __self_0), | |
&RawEvent::KeyChanged(ref __arg_1_0)) => | |
(*__self_0) == (*__arg_1_0), | |
_ => unsafe { ::std::intrinsics::unreachable() } | |
} | |
} else { false } | |
} | |
} | |
#[inline] | |
fn ne(&self, other: &RawEvent<AccountId>) -> bool { | |
{ | |
let __self_vi = | |
unsafe { ::std::intrinsics::discriminant_value(&*self) } as | |
isize; | |
let __arg_1_vi = | |
unsafe { ::std::intrinsics::discriminant_value(&*other) } as | |
isize; | |
if true && __self_vi == __arg_1_vi { | |
match (&*self, &*other) { | |
(&RawEvent::Sudid(ref __self_0), | |
&RawEvent::Sudid(ref __arg_1_0)) => | |
(*__self_0) != (*__arg_1_0), | |
(&RawEvent::KeyChanged(ref __self_0), | |
&RawEvent::KeyChanged(ref __arg_1_0)) => | |
(*__self_0) != (*__arg_1_0), | |
_ => unsafe { ::std::intrinsics::unreachable() } | |
} | |
} else { true } | |
} | |
} | |
} | |
#[automatically_derived] | |
#[allow(unused_qualifications)] | |
impl <AccountId: ::std::cmp::Eq> ::std::cmp::Eq for RawEvent<AccountId> { | |
#[inline] | |
#[doc(hidden)] | |
fn assert_receiver_is_total_eq(&self) -> () { | |
{ | |
let _: ::std::cmp::AssertParamIsEq<bool>; | |
let _: ::std::cmp::AssertParamIsEq<AccountId>; | |
} | |
} | |
} | |
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] | |
const _IMPL_ENCODE_FOR_RawEvent: () = | |
{ | |
#[allow(unknown_lints)] | |
#[allow(rust_2018_idioms)] | |
extern crate parity_codec as _parity_codec; | |
impl <AccountId> _parity_codec::Encode for RawEvent<AccountId> where | |
AccountId: _parity_codec::Encode, AccountId: _parity_codec::Encode { | |
fn encode_to<EncOut: _parity_codec::Output>(&self, | |
dest: &mut EncOut) { | |
match *self { | |
RawEvent::Sudid(ref aa) => { | |
dest.push_byte(0usize as u8); | |
dest.push(aa); | |
} | |
RawEvent::KeyChanged(ref aa) => { | |
dest.push_byte(1usize as u8); | |
dest.push(aa); | |
} | |
_ => (), | |
} | |
} | |
} | |
}; | |
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] | |
const _IMPL_DECODE_FOR_RawEvent: () = | |
{ | |
#[allow(unknown_lints)] | |
#[allow(rust_2018_idioms)] | |
extern crate parity_codec as _parity_codec; | |
impl <AccountId> _parity_codec::Decode for RawEvent<AccountId> where | |
AccountId: _parity_codec::Decode, AccountId: _parity_codec::Decode { | |
fn decode<DecIn: _parity_codec::Input>(input: &mut DecIn) | |
-> Option<Self> { | |
match input.read_byte()? { | |
x if x == 0usize as u8 => { | |
Some(RawEvent::Sudid(_parity_codec::Decode::decode(input)?)) | |
} | |
x if x == 1usize as u8 => { | |
Some(RawEvent::KeyChanged(_parity_codec::Decode::decode(input)?)) | |
} | |
_ => None, | |
} | |
} | |
} | |
}; | |
#[automatically_derived] | |
#[allow(unused_qualifications)] | |
impl <AccountId: ::std::fmt::Debug> ::std::fmt::Debug for RawEvent<AccountId> | |
{ | |
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { | |
match (&*self,) { | |
(&RawEvent::Sudid(ref __self_0),) => { | |
let mut debug_trait_builder = f.debug_tuple("Sudid"); | |
let _ = debug_trait_builder.field(&&(*__self_0)); | |
debug_trait_builder.finish() | |
} | |
(&RawEvent::KeyChanged(ref __self_0),) => { | |
let mut debug_trait_builder = f.debug_tuple("KeyChanged"); | |
let _ = debug_trait_builder.field(&&(*__self_0)); | |
debug_trait_builder.finish() | |
} | |
} | |
} | |
} | |
impl <AccountId> From<RawEvent<AccountId>> for () { | |
fn from(_: RawEvent<AccountId>) -> () { () } | |
} | |
impl <AccountId> RawEvent<AccountId> { | |
#[allow(dead_code)] | |
pub fn metadata() -> &'static [::srml_support::event::EventMetadata] { | |
&[::srml_support::event::EventMetadata{name: | |
::srml_support::event::DecodeDifferent::Encode("Sudid"), | |
arguments: | |
::srml_support::event::DecodeDifferent::Encode(&["bool"]), | |
documentation: | |
::srml_support::event::DecodeDifferent::Encode(&[r" A sudo just took place."]),}, | |
::srml_support::event::EventMetadata{name: | |
::srml_support::event::DecodeDifferent::Encode("KeyChanged"), | |
arguments: | |
::srml_support::event::DecodeDifferent::Encode(&["AccountId"]), | |
documentation: | |
::srml_support::event::DecodeDifferent::Encode(&[r" The sudoer just switched identity; the old key is supplied."]),}] | |
} | |
} | |
#[doc(hidden)] | |
mod sr_api_hidden_includes_decl_storage { | |
pub extern crate srml_support as hidden_include; | |
} | |
#[doc = " The `AccountId` of the sudo key."] | |
struct Key<T: Trait>(self::sr_api_hidden_includes_decl_storage::hidden_include::rstd::marker::PhantomData<(T)>); | |
impl <T: Trait> | |
self::sr_api_hidden_includes_decl_storage::hidden_include::storage::hashed::generator::StorageValue<T::AccountId> | |
for Key<T> { | |
type | |
Query | |
= | |
T::AccountId; | |
#[doc = r" Get the storage key."] | |
fn key() -> &'static [u8] { "Sudo Key".as_bytes() } | |
#[doc = r" Load the value from the provided storage instance."] | |
fn get<S: self::sr_api_hidden_includes_decl_storage::hidden_include::HashedStorage<self::sr_api_hidden_includes_decl_storage::hidden_include::Twox128>>(storage: | |
&S) | |
-> Self::Query { | |
storage.get(<Self as | |
self::sr_api_hidden_includes_decl_storage::hidden_include::storage::hashed::generator::StorageValue<T::AccountId>>::key()).unwrap_or_else(|| | |
Default::default()) | |
} | |
#[doc = r" Take a value from storage, removing it afterwards."] | |
fn take<S: self::sr_api_hidden_includes_decl_storage::hidden_include::HashedStorage<self::sr_api_hidden_includes_decl_storage::hidden_include::Twox128>>(storage: | |
&S) | |
-> Self::Query { | |
storage.take(<Self as | |
self::sr_api_hidden_includes_decl_storage::hidden_include::storage::hashed::generator::StorageValue<T::AccountId>>::key()).unwrap_or_else(|| | |
Default::default()) | |
} | |
#[doc = r" Mutate the value under a key."] | |
fn mutate<R, F: FnOnce(&mut Self::Query) -> R, | |
S: self::sr_api_hidden_includes_decl_storage::hidden_include::HashedStorage<self::sr_api_hidden_includes_decl_storage::hidden_include::Twox128>>(f: | |
F, | |
storage: | |
&S) | |
-> R { | |
let mut val = | |
<Self as | |
self::sr_api_hidden_includes_decl_storage::hidden_include::storage::hashed::generator::StorageValue<T::AccountId>>::get(storage); | |
let ret = f(&mut val); | |
<Self as | |
self::sr_api_hidden_includes_decl_storage::hidden_include::storage::hashed::generator::StorageValue<T::AccountId>>::put(&val, | |
storage); | |
ret | |
} | |
} | |
trait Store { | |
type | |
Key; | |
} | |
#[doc(hidden)] | |
pub struct __GetByteStructKey<T>(pub self::sr_api_hidden_includes_decl_storage::hidden_include::rstd::marker::PhantomData<(T)>); | |
#[cfg(feature = "std")] | |
#[allow(non_upper_case_globals)] | |
static __CACHE_GET_BYTE_STRUCT_Key: | |
self::sr_api_hidden_includes_decl_storage::hidden_include::once_cell::sync::OnceCell<self::sr_api_hidden_includes_decl_storage::hidden_include::rstd::vec::Vec<u8>> | |
= | |
self::sr_api_hidden_includes_decl_storage::hidden_include::once_cell::sync::OnceCell::INIT; | |
#[cfg(feature = "std")] | |
impl <T: Trait> | |
self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::DefaultByte | |
for __GetByteStructKey<T> { | |
fn default_byte(&self) | |
-> | |
self::sr_api_hidden_includes_decl_storage::hidden_include::rstd::vec::Vec<u8> { | |
use self::sr_api_hidden_includes_decl_storage::hidden_include::codec::Encode; | |
__CACHE_GET_BYTE_STRUCT_Key.get_or_init(|| | |
{ | |
let def_val: | |
T::AccountId = | |
Default::default(); | |
<T::AccountId as | |
Encode>::encode(&def_val) | |
}).clone() | |
} | |
} | |
impl <T: Trait> Store for Module<T> { | |
type | |
Key | |
= | |
Key<T>; | |
} | |
impl <T: 'static + Trait> Module<T> { | |
#[doc = " The `AccountId` of the sudo key."] | |
pub fn key() -> T::AccountId { | |
<Key<T> as | |
self::sr_api_hidden_includes_decl_storage::hidden_include::storage::hashed::generator::StorageValue<T::AccountId>>::get(&self::sr_api_hidden_includes_decl_storage::hidden_include::storage::RuntimeStorage) | |
} | |
#[doc(hidden)] | |
pub fn store_metadata() | |
-> | |
self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::StorageMetadata { | |
self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::StorageMetadata{functions: | |
self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::DecodeDifferent::Encode({ | |
&[self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::StorageFunctionMetadata{name: | |
self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::DecodeDifferent::Encode("Key"), | |
modifier: | |
self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::StorageFunctionModifier::Default, | |
ty: | |
self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::StorageFunctionType::Plain(self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::DecodeDifferent::Encode("T::AccountId")), | |
default: | |
self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::DecodeDifferent::Encode(self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::DefaultByteGetter(&__GetByteStructKey::<T>(self::sr_api_hidden_includes_decl_storage::hidden_include::rstd::marker::PhantomData))), | |
documentation: | |
self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::DecodeDifferent::Encode(&[" The `AccountId` of the sudo key."]),}] | |
}),} | |
} | |
#[doc(hidden)] | |
pub fn store_metadata_functions() | |
-> | |
&'static [self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::StorageFunctionMetadata] { | |
{ | |
&[self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::StorageFunctionMetadata{name: | |
self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::DecodeDifferent::Encode("Key"), | |
modifier: | |
self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::StorageFunctionModifier::Default, | |
ty: | |
self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::StorageFunctionType::Plain(self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::DecodeDifferent::Encode("T::AccountId")), | |
default: | |
self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::DecodeDifferent::Encode(self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::DefaultByteGetter(&__GetByteStructKey::<T>(self::sr_api_hidden_includes_decl_storage::hidden_include::rstd::marker::PhantomData))), | |
documentation: | |
self::sr_api_hidden_includes_decl_storage::hidden_include::metadata::DecodeDifferent::Encode(&[" The `AccountId` of the sudo key."]),}] | |
} | |
} | |
#[doc(hidden)] | |
pub fn store_metadata_name() -> &'static str { "Sudo" } | |
} | |
#[cfg(feature = "std")] | |
#[serde(rename_all = "camelCase")] | |
#[serde(deny_unknown_fields)] | |
#[serde(bound(serialize = | |
"T :: AccountId : self :: sr_api_hidden_includes_decl_storage :: hidden_include::serde::Serialize, "))] | |
#[serde(bound(deserialize = | |
"T :: AccountId : self :: sr_api_hidden_includes_decl_storage :: hidden_include::serde::de::DeserializeOwned, "))] | |
pub struct GenesisConfig<T: Trait> { | |
#[doc = " The `AccountId` of the sudo key."] | |
pub key: T::AccountId, | |
} | |
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] | |
const _IMPL_SERIALIZE_FOR_GenesisConfig: () = | |
{ | |
#[allow(unknown_lints)] | |
#[allow(rust_2018_idioms)] | |
extern crate serde as _serde; | |
#[allow(unused_macros)] | |
macro_rules! try(( $ __expr : expr ) => { | |
match $ __expr { | |
_serde :: export :: Ok ( __val ) => __val , _serde :: | |
export :: Err ( __err ) => { | |
return _serde :: export :: Err ( __err ) ; } } }); | |
#[automatically_derived] | |
impl <T: Trait> _serde::Serialize for GenesisConfig<T> where | |
T::AccountId: self::sr_api_hidden_includes_decl_storage::hidden_include::serde::Serialize | |
{ | |
fn serialize<__S>(&self, __serializer: __S) | |
-> _serde::export::Result<__S::Ok, __S::Error> where | |
__S: _serde::Serializer { | |
let mut __serde_state = | |
match _serde::Serializer::serialize_struct(__serializer, | |
"GenesisConfig", | |
false as usize | |
+ 1) { | |
_serde::export::Ok(__val) => __val, | |
_serde::export::Err(__err) => { | |
return _serde::export::Err(__err); | |
} | |
}; | |
match _serde::ser::SerializeStruct::serialize_field(&mut __serde_state, | |
"key", | |
&self.key) | |
{ | |
_serde::export::Ok(__val) => __val, | |
_serde::export::Err(__err) => { | |
return _serde::export::Err(__err); | |
} | |
}; | |
_serde::ser::SerializeStruct::end(__serde_state) | |
} | |
} | |
}; | |
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] | |
const _IMPL_DESERIALIZE_FOR_GenesisConfig: () = | |
{ | |
#[allow(unknown_lints)] | |
#[allow(rust_2018_idioms)] | |
extern crate serde as _serde; | |
#[allow(unused_macros)] | |
macro_rules! try(( $ __expr : expr ) => { | |
match $ __expr { | |
_serde :: export :: Ok ( __val ) => __val , _serde :: | |
export :: Err ( __err ) => { | |
return _serde :: export :: Err ( __err ) ; } } }); | |
#[automatically_derived] | |
impl <'de, T: Trait> _serde::Deserialize<'de> for GenesisConfig<T> | |
where | |
T::AccountId: self::sr_api_hidden_includes_decl_storage::hidden_include::serde::de::DeserializeOwned | |
{ | |
fn deserialize<__D>(__deserializer: __D) | |
-> _serde::export::Result<Self, __D::Error> where | |
__D: _serde::Deserializer<'de> { | |
#[allow(non_camel_case_types)] | |
enum __Field { __field0, } | |
struct __FieldVisitor; | |
impl <'de> _serde::de::Visitor<'de> for __FieldVisitor { | |
type | |
Value | |
= | |
__Field; | |
fn expecting(&self, | |
__formatter: &mut _serde::export::Formatter) | |
-> _serde::export::fmt::Result { | |
_serde::export::Formatter::write_str(__formatter, | |
"field identifier") | |
} | |
fn visit_u64<__E>(self, __value: u64) | |
-> _serde::export::Result<Self::Value, __E> where | |
__E: _serde::de::Error { | |
match __value { | |
0u64 => _serde::export::Ok(__Field::__field0), | |
_ => | |
_serde::export::Err(_serde::de::Error::invalid_value(_serde::de::Unexpected::Unsigned(__value), | |
&"field index 0 <= i < 1")), | |
} | |
} | |
fn visit_str<__E>(self, __value: &str) | |
-> _serde::export::Result<Self::Value, __E> where | |
__E: _serde::de::Error { | |
match __value { | |
"key" => _serde::export::Ok(__Field::__field0), | |
_ => { | |
_serde::export::Err(_serde::de::Error::unknown_field(__value, | |
FIELDS)) | |
} | |
} | |
} | |
fn visit_bytes<__E>(self, __value: &[u8]) | |
-> _serde::export::Result<Self::Value, __E> where | |
__E: _serde::de::Error { | |
match __value { | |
b"key" => _serde::export::Ok(__Field::__field0), | |
_ => { | |
let __value = | |
&_serde::export::from_utf8_lossy(__value); | |
_serde::export::Err(_serde::de::Error::unknown_field(__value, | |
FIELDS)) | |
} | |
} | |
} | |
} | |
impl <'de> _serde::Deserialize<'de> for __Field { | |
#[inline] | |
fn deserialize<__D>(__deserializer: __D) | |
-> _serde::export::Result<Self, __D::Error> where | |
__D: _serde::Deserializer<'de> { | |
_serde::Deserializer::deserialize_identifier(__deserializer, | |
__FieldVisitor) | |
} | |
} | |
struct __Visitor<'de, T: Trait> where | |
T::AccountId: self::sr_api_hidden_includes_decl_storage::hidden_include::serde::de::DeserializeOwned { | |
marker: _serde::export::PhantomData<GenesisConfig<T>>, | |
lifetime: _serde::export::PhantomData<&'de ()>, | |
} | |
impl <'de, T: Trait> _serde::de::Visitor<'de> for | |
__Visitor<'de, T> where | |
T::AccountId: self::sr_api_hidden_includes_decl_storage::hidden_include::serde::de::DeserializeOwned | |
{ | |
type | |
Value | |
= | |
GenesisConfig<T>; | |
fn expecting(&self, | |
__formatter: &mut _serde::export::Formatter) | |
-> _serde::export::fmt::Result { | |
_serde::export::Formatter::write_str(__formatter, | |
"struct GenesisConfig") | |
} | |
#[inline] | |
fn visit_seq<__A>(self, mut __seq: __A) | |
-> _serde::export::Result<Self::Value, __A::Error> where | |
__A: _serde::de::SeqAccess<'de> { | |
let __field0 = | |
match match _serde::de::SeqAccess::next_element::<T::AccountId>(&mut __seq) | |
{ | |
_serde::export::Ok(__val) => __val, | |
_serde::export::Err(__err) => { | |
return _serde::export::Err(__err); | |
} | |
} { | |
_serde::export::Some(__value) => __value, | |
_serde::export::None => { | |
return _serde::export::Err(_serde::de::Error::invalid_length(0usize, | |
&"struct GenesisConfig with 1 element")); | |
} | |
}; | |
_serde::export::Ok(GenesisConfig{key: __field0,}) | |
} | |
#[inline] | |
fn visit_map<__A>(self, mut __map: __A) | |
-> _serde::export::Result<Self::Value, __A::Error> where | |
__A: _serde::de::MapAccess<'de> { | |
let mut __field0: | |
_serde::export::Option<T::AccountId> = | |
_serde::export::None; | |
while let _serde::export::Some(__key) = | |
match _serde::de::MapAccess::next_key::<__Field>(&mut __map) | |
{ | |
_serde::export::Ok(__val) => __val, | |
_serde::export::Err(__err) => { | |
return _serde::export::Err(__err); | |
} | |
} { | |
match __key { | |
__Field::__field0 => { | |
if _serde::export::Option::is_some(&__field0) | |
{ | |
return _serde::export::Err(<__A::Error | |
as | |
_serde::de::Error>::duplicate_field("key")); | |
} | |
__field0 = | |
_serde::export::Some(match _serde::de::MapAccess::next_value::<T::AccountId>(&mut __map) | |
{ | |
_serde::export::Ok(__val) | |
=> __val, | |
_serde::export::Err(__err) | |
=> { | |
return _serde::export::Err(__err); | |
} | |
}); | |
} | |
} | |
} | |
let __field0 = | |
match __field0 { | |
_serde::export::Some(__field0) => __field0, | |
_serde::export::None => | |
match _serde::private::de::missing_field("key") | |
{ | |
_serde::export::Ok(__val) => __val, | |
_serde::export::Err(__err) => { | |
return _serde::export::Err(__err); | |
} | |
}, | |
}; | |
_serde::export::Ok(GenesisConfig{key: __field0,}) | |
} | |
} | |
const FIELDS: &'static [&'static str] = &["key"]; | |
_serde::Deserializer::deserialize_struct(__deserializer, | |
"GenesisConfig", | |
FIELDS, | |
__Visitor{marker: | |
_serde::export::PhantomData::<GenesisConfig<T>>, | |
lifetime: | |
_serde::export::PhantomData,}) | |
} | |
} | |
}; | |
#[cfg(feature = "std")] | |
impl <T: Trait> Default for GenesisConfig<T> { | |
fn default() -> Self { GenesisConfig{key: Default::default(),} } | |
} | |
#[cfg(feature = "std")] | |
impl <T: Trait> | |
self::sr_api_hidden_includes_decl_storage::hidden_include::runtime_primitives::BuildStorage | |
for GenesisConfig<T> { | |
fn assimilate_storage(self, | |
r: | |
&mut self::sr_api_hidden_includes_decl_storage::hidden_include::runtime_primitives::StorageOverlay, | |
c: | |
&mut self::sr_api_hidden_includes_decl_storage::hidden_include::runtime_primitives::ChildrenStorageOverlay) | |
-> ::std::result::Result<(), String> { | |
use self::sr_api_hidden_includes_decl_storage::hidden_include::rstd::cell::RefCell; | |
let storage = RefCell::new(r); | |
{ | |
use self::sr_api_hidden_includes_decl_storage::hidden_include::rstd::{cell::RefCell, | |
marker::PhantomData}; | |
use self::sr_api_hidden_includes_decl_storage::hidden_include::codec::{Encode, | |
Decode}; | |
let v = ((|config: &GenesisConfig<T>| config.key.clone()))(&self); | |
<Key<T> as | |
self::sr_api_hidden_includes_decl_storage::hidden_include::storage::hashed::generator::StorageValue<T::AccountId>>::put(&v, | |
&storage); | |
} | |
let r = storage.into_inner(); | |
(|_, _, _| { })(r, c, &self); | |
Ok(()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment