mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 07:17:56 +00:00
Sudo module (#1315)
* Sudo module * Fix comment * Fix errors * Fix test * Update hashes * Final test fixes and build * Final hex change
This commit is contained in:
Generated
+19
@@ -1886,6 +1886,7 @@ dependencies = [
|
||||
"srml-grandpa 0.1.0",
|
||||
"srml-session 0.1.0",
|
||||
"srml-staking 0.1.0",
|
||||
"srml-sudo 0.1.0",
|
||||
"srml-support 0.1.0",
|
||||
"srml-system 0.1.0",
|
||||
"srml-timestamp 0.1.0",
|
||||
@@ -3024,6 +3025,24 @@ dependencies = [
|
||||
"substrate-primitives 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "srml-sudo"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-io 0.1.0",
|
||||
"sr-primitives 0.1.0",
|
||||
"sr-std 0.1.0",
|
||||
"srml-consensus 0.1.0",
|
||||
"srml-support 0.1.0",
|
||||
"srml-support-procedural 0.1.0",
|
||||
"srml-system 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "srml-support"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -57,6 +57,7 @@ members = [
|
||||
"core/sr-primitives",
|
||||
"srml/session",
|
||||
"srml/staking",
|
||||
"srml/sudo",
|
||||
"srml/system",
|
||||
"srml/timestamp",
|
||||
"srml/treasury",
|
||||
|
||||
@@ -20,7 +20,7 @@ use primitives::{AuthorityId, ed25519};
|
||||
use node_primitives::AccountId;
|
||||
use node_runtime::{ConsensusConfig, CouncilSeatsConfig, CouncilVotingConfig, DemocracyConfig,
|
||||
SessionConfig, StakingConfig, TimestampConfig, BalancesConfig, TreasuryConfig,
|
||||
UpgradeKeyConfig, ContractConfig, GrandpaConfig, Permill, Perbill};
|
||||
UpgradeKeyConfig, SudoConfig, ContractConfig, GrandpaConfig, Permill, Perbill};
|
||||
pub use node_runtime::GenesisConfig;
|
||||
use substrate_service;
|
||||
|
||||
@@ -132,6 +132,9 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
upgrade_key: Some(UpgradeKeyConfig {
|
||||
key: endowed_accounts[0].clone(),
|
||||
}),
|
||||
sudo: Some(SudoConfig {
|
||||
key: endowed_accounts[0].clone(),
|
||||
}),
|
||||
grandpa: Some(GrandpaConfig {
|
||||
authorities: initial_authorities.clone().into_iter().map(|k| (k, 1)).collect(),
|
||||
})
|
||||
@@ -256,6 +259,9 @@ pub fn testnet_genesis(
|
||||
upgrade_key: Some(UpgradeKeyConfig {
|
||||
key: upgrade_key,
|
||||
}),
|
||||
sudo: Some(SudoConfig {
|
||||
key: upgrade_key,
|
||||
}),
|
||||
grandpa: Some(GrandpaConfig {
|
||||
authorities: initial_authorities.clone().into_iter().map(|k| (k, 1)).collect(),
|
||||
})
|
||||
|
||||
@@ -260,6 +260,7 @@ mod tests {
|
||||
treasury: Some(Default::default()),
|
||||
contract: Some(Default::default()),
|
||||
upgrade_key: Some(Default::default()),
|
||||
sudo: Some(Default::default()),
|
||||
grandpa: Some(GrandpaConfig {
|
||||
authorities: vec![ // set these so no GRANDPA events fire when session changes
|
||||
(Alice.to_raw_public().into(), 1),
|
||||
@@ -311,9 +312,9 @@ mod tests {
|
||||
1,
|
||||
GENESIS_HASH.into(),
|
||||
if support_changes_trie {
|
||||
hex!("1a7758d96d7353732f3054a3dacb18f04f42fc48f6706378d6f7be744c6022f1").into()
|
||||
hex!("bc4bdc45ba03402f9b4c7ec09834065c57205b1742bf2469ab9fc54544d8d002").into()
|
||||
} else {
|
||||
hex!("1cf270c8a484df4931af562f7afdc9f44d99ae1bd35fe30fbd2cf3c1be2e933b").into()
|
||||
hex!("6bfbf71fa08d99f2488e295807059269cbc43ea21af3316a92406974593a1fc2").into()
|
||||
},
|
||||
if support_changes_trie {
|
||||
vec![changes_trie_log(
|
||||
@@ -339,7 +340,7 @@ mod tests {
|
||||
construct_block(
|
||||
2,
|
||||
block1(false).1,
|
||||
hex!("a208e27269f8a17e7f7cf9513396d3579066df10a853e030345847ec96593c2e").into(),
|
||||
hex!("24f8ac99a6d98e9b53f4f6ef6ffdd12ba53ea3f247200a8126fa69c4b5047fbc").into(),
|
||||
vec![ // session changes here, so we add a grandpa change signal log.
|
||||
Log::from(::grandpa::RawLog::AuthoritiesChangeSignal(0, vec![
|
||||
(Keyring::One.to_raw_public().into(), 1),
|
||||
@@ -368,7 +369,7 @@ mod tests {
|
||||
construct_block(
|
||||
1,
|
||||
GENESIS_HASH.into(),
|
||||
hex!("a506a69fefa4dc1be6838b68dc6e5799bd5fec545ef890cadac20edc0254d37a").into(),
|
||||
hex!("7b7d3b509a444cdf214825d3354507823a4c91eafa493f0956448881a81ab797").into(),
|
||||
vec![],
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
@@ -658,7 +659,7 @@ mod tests {
|
||||
let b = construct_block(
|
||||
1,
|
||||
GENESIS_HASH.into(),
|
||||
hex!("3af4e1ba0769122b1e92b138fecf7ce8bb2fe4f2a65fba3b423f87942f1ba8c8").into(),
|
||||
hex!("bfc8051f91071149cca8b8dca6290fdb82eda6868d48cfed25f8ca38ed3a1049").into(),
|
||||
vec![],
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
|
||||
@@ -25,6 +25,7 @@ srml-staking = { path = "../../srml/staking", default-features = false }
|
||||
srml-system = { path = "../../srml/system", default-features = false }
|
||||
srml-timestamp = { path = "../../srml/timestamp", default-features = false }
|
||||
srml-treasury = { path = "../../srml/treasury", default-features = false }
|
||||
srml-sudo = { path = "../../srml/sudo", default-features = false }
|
||||
srml-upgrade-key = { path = "../../srml/upgrade-key", default-features = false }
|
||||
srml-grandpa = { path = "../../srml/grandpa", default-features = false }
|
||||
sr-version = { path = "../../core/sr-version", default-features = false }
|
||||
@@ -55,6 +56,7 @@ std = [
|
||||
"srml-system/std",
|
||||
"srml-timestamp/std",
|
||||
"srml-treasury/std",
|
||||
"srml-sudo/std",
|
||||
"srml-upgrade-key/std",
|
||||
"sr-version/std",
|
||||
"node-primitives/std",
|
||||
|
||||
@@ -47,6 +47,7 @@ extern crate srml_executive as executive;
|
||||
extern crate srml_grandpa as grandpa;
|
||||
extern crate srml_session as session;
|
||||
extern crate srml_staking as staking;
|
||||
extern crate srml_sudo as sudo;
|
||||
extern crate srml_system as system;
|
||||
extern crate srml_timestamp as timestamp;
|
||||
extern crate srml_treasury as treasury;
|
||||
@@ -96,8 +97,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("node"),
|
||||
impl_name: create_runtime_str!("substrate-node"),
|
||||
authoring_version: 10,
|
||||
spec_version: 10,
|
||||
impl_version: 0,
|
||||
spec_version: 11,
|
||||
impl_version: 11,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
|
||||
@@ -205,6 +206,11 @@ impl upgrade_key::Trait for Runtime {
|
||||
type Event = Event;
|
||||
}
|
||||
|
||||
impl sudo::Trait for Runtime {
|
||||
type Event = Event;
|
||||
type Proposal = Call;
|
||||
}
|
||||
|
||||
impl grandpa::Trait for Runtime {
|
||||
type SessionKey = SessionKey;
|
||||
type Log = Log;
|
||||
@@ -233,6 +239,7 @@ construct_runtime!(
|
||||
Treasury: treasury,
|
||||
Contract: contract::{Module, Call, Config<T>, Event<T>},
|
||||
UpgradeKey: upgrade_key,
|
||||
Sudo: sudo,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Generated
+19
@@ -520,6 +520,7 @@ dependencies = [
|
||||
"srml-grandpa 0.1.0",
|
||||
"srml-session 0.1.0",
|
||||
"srml-staking 0.1.0",
|
||||
"srml-sudo 0.1.0",
|
||||
"srml-support 0.1.0",
|
||||
"srml-system 0.1.0",
|
||||
"srml-timestamp 0.1.0",
|
||||
@@ -1282,6 +1283,24 @@ dependencies = [
|
||||
"substrate-primitives 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "srml-sudo"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-io 0.1.0",
|
||||
"sr-primitives 0.1.0",
|
||||
"sr-std 0.1.0",
|
||||
"srml-consensus 0.1.0",
|
||||
"srml-support 0.1.0",
|
||||
"srml-support-procedural 0.1.0",
|
||||
"srml-system 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "srml-support"
|
||||
version = "0.1.0"
|
||||
|
||||
BIN
Binary file not shown.
@@ -0,0 +1,33 @@
|
||||
[package]
|
||||
name = "srml-sudo"
|
||||
version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
hex-literal = "0.1.0"
|
||||
serde = { version = "1.0", default-features = false }
|
||||
parity-codec = { version = "2.1", default-features = false }
|
||||
parity-codec-derive = { version = "2.1", default-features = false }
|
||||
substrate-primitives = { path = "../../core/primitives", default-features = false }
|
||||
sr-std = { path = "../../core/sr-std", default-features = false }
|
||||
sr-io = { path = "../../core/sr-io", default-features = false }
|
||||
sr-primitives = { path = "../../core/sr-primitives", default-features = false }
|
||||
srml-support = { path = "../support", default-features = false }
|
||||
srml-support-procedural = { path = "../support/procedural" }
|
||||
srml-system = { path = "../system", default-features = false }
|
||||
srml-consensus = { path = "../consensus", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"serde/std",
|
||||
"parity-codec/std",
|
||||
"parity-codec-derive/std",
|
||||
"sr-std/std",
|
||||
"sr-io/std",
|
||||
"sr-primitives/std",
|
||||
"substrate-primitives/std",
|
||||
"srml-support/std",
|
||||
"srml-system/std",
|
||||
"srml-consensus/std",
|
||||
]
|
||||
@@ -0,0 +1,88 @@
|
||||
// Copyright 2017-2018 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/>.
|
||||
|
||||
//! The Example: A simple example of a runtime module demonstrating
|
||||
//! concepts, APIs and structures common to most runtime modules.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
extern crate sr_std;
|
||||
#[cfg(test)]
|
||||
extern crate sr_io;
|
||||
#[cfg(test)]
|
||||
extern crate substrate_primitives;
|
||||
extern crate sr_primitives;
|
||||
#[macro_use]
|
||||
extern crate parity_codec_derive;
|
||||
extern crate parity_codec as codec;
|
||||
#[macro_use]
|
||||
extern crate srml_support as support;
|
||||
|
||||
extern crate srml_system as system;
|
||||
extern crate srml_consensus as consensus;
|
||||
|
||||
use sr_std::prelude::*;
|
||||
use support::{StorageValue, Parameter, Dispatchable};
|
||||
use system::ensure_signed;
|
||||
|
||||
pub trait Trait: consensus::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>;
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
// Simple declaration of the `Module` type. Lets the macro know what its working on.
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
fn deposit_event() = default;
|
||||
|
||||
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 ok = proposal.dispatch(system::RawOrigin::Root.into()).is_ok();
|
||||
Self::deposit_event(RawEvent::Sudid(ok));
|
||||
}
|
||||
|
||||
fn set_key(origin, new: T::AccountId) {
|
||||
// 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");
|
||||
|
||||
Self::deposit_event(RawEvent::KeyChanged(Self::key()));
|
||||
<Key<T>>::put(new);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An event in this module.
|
||||
decl_event!(
|
||||
pub enum Event<T> where AccountId = <T as system::Trait>::AccountId {
|
||||
/// A sudo just took place.
|
||||
Sudid(bool),
|
||||
/// The sudoer just switched identity; the old key is supplied.
|
||||
KeyChanged(AccountId),
|
||||
}
|
||||
);
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as Sudo {
|
||||
Key get(key) config(): T::AccountId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user