[][src]Crate srml_sudo

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.

Interface

Dispatchable Functions

Only the sudo key can call the dispatchable functions from the Sudo module.

Usage

Executing Privileged Functions

The Sudo module itself is not intended to be used within other modules. Instead, you can build "privileged functions" (i.e. functions that require Root origin) in other modules. 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:

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(())
        }
    }
}

Genesis Config

The Sudo module depends on the GenesisConfig. You need to set an initial superuser account as the sudo key.

Structs

GenesisConfig
Module

Enums

Call
RawEvent

Events for this module.

Traits

Trait

Type Definitions

Event

RawEvent specialized for the configuration Trait