Introduce module structure over comments.

This commit is contained in:
Gav
2018-01-28 14:36:40 +01:00
parent bc6eb7d70a
commit 59469995b2
10 changed files with 460 additions and 426 deletions
@@ -23,14 +23,15 @@ use runtime::{staking, session, timestamp, governance};
/// Public functions that can be dispatched to.
#[derive(Clone, Copy)]
#[cfg_attr(feature = "with-std", derive(PartialEq, Debug))]
#[repr(u8)]
pub enum Function {
StakingStake,
StakingUnstake,
StakingTransfer,
SessionSetKey,
TimestampSet,
GovernancePropose,
GovernanceApprove,
StakingStake = 0,
StakingUnstake = 1,
StakingTransfer = 2,
SessionSetKey = 3,
TimestampSet = 4,
GovernancePropose = 5,
GovernanceApprove = 6,
}
impl Function {
@@ -55,31 +56,31 @@ impl Function {
let mut params = StreamReader::new(data);
match *self {
Function::StakingStake => {
staking::stake(transactor);
staking::public::stake(transactor);
}
Function::StakingUnstake => {
staking::unstake(transactor);
staking::public::unstake(transactor);
}
Function::StakingTransfer => {
let dest = params.read().unwrap();
let value = params.read().unwrap();
staking::transfer(transactor, &dest, value);
staking::public::transfer(transactor, &dest, value);
}
Function::SessionSetKey => {
let session = params.read().unwrap();
session::set_key(transactor, &session);
session::public::set_key(transactor, &session);
}
Function::TimestampSet => {
let t = params.read().unwrap();
timestamp::set(t);
timestamp::public::set(t);
}
Function::GovernancePropose => {
let proposal = params.read().unwrap();
governance::propose(transactor, &proposal);
governance::public::propose(transactor, &proposal);
}
Function::GovernanceApprove => {
let era_index = params.read().unwrap();
governance::approve(transactor, era_index);
governance::public::approve(transactor, era_index);
}
}
}
@@ -25,13 +25,14 @@ use runtime::{system, governance, staking, session};
/// Internal functions that can be dispatched to.
#[derive(Clone, Copy)]
#[cfg_attr(feature = "with-std", derive(PartialEq, Debug))]
#[repr(u8)]
pub enum InternalFunction {
SystemSetCode,
StakingSetSessionsPerEra,
StakingSetBondingDuration,
StakingSetValidatorCount,
GovernanceSetApprovalPpmRequired,
SessionSetLength,
SystemSetCode = 0,
StakingSetSessionsPerEra = 1,
StakingSetBondingDuration = 2,
StakingSetValidatorCount = 3,
GovernanceSetApprovalPpmRequired = 4,
SessionSetLength = 5,
}
impl InternalFunction {
@@ -85,27 +86,27 @@ impl Proposal {
match self.function {
InternalFunction::SystemSetCode => {
let code: Vec<u8> = params.read().unwrap();
system::set_code(&code);
system::privileged::set_code(&code);
}
InternalFunction::StakingSetSessionsPerEra => {
let value = params.read().unwrap();
staking::set_sessions_per_era(value);
staking::privileged::set_sessions_per_era(value);
}
InternalFunction::StakingSetBondingDuration => {
let value = params.read().unwrap();
staking::set_bonding_duration(value);
staking::privileged::set_bonding_duration(value);
}
InternalFunction::StakingSetValidatorCount => {
let value = params.read().unwrap();
staking::set_validator_count(value);
staking::privileged::set_validator_count(value);
}
InternalFunction::GovernanceSetApprovalPpmRequired => {
let value = params.read().unwrap();
governance::set_approval_ppm_required(value);
governance::privileged::set_approval_ppm_required(value);
}
InternalFunction::SessionSetLength => {
let value = params.read().unwrap();
session::set_length(value);
session::privileged::set_length(value);
}
}
}
@@ -114,7 +115,7 @@ impl Proposal {
#[cfg(test)]
mod test {
use super::*;
use statichex::StaticHexInto;
use support::StaticHexInto;
#[test]
fn slicing_should_work() {