Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Council motions for approving treasury proposals #694

Merged
merged 10 commits into from
Sep 10, 2018
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion demo/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use std::sync::Arc;
use demo_primitives::{AccountId, Hash};
use demo_runtime::{Block, BlockId, GenesisConfig,
BalancesConfig, ConsensusConfig, CouncilConfig, DemocracyConfig, SessionConfig,
StakingConfig, TimestampConfig};
StakingConfig, TimestampConfig, TreasuryConfig, Permill};
use futures::{Future, Sink, Stream};
use tokio::runtime::Runtime;
use demo_executor::NativeExecutor;
Expand Down Expand Up @@ -211,6 +211,12 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
timestamp: Some(TimestampConfig {
period: 5, // 5 second block time.
}),
treasury: Some(TreasuryConfig {
proposal_bond: Permill::from_percent(5),
proposal_bond_minimum: 1_000_000,
spend_period: 12 * 60 * 24,
Copy link
Contributor

@pepyakin pepyakin Sep 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, this looks like a timestamp or something, but it's actually should be a BlockNumber

Copy link
Member Author

@gavofyork gavofyork Sep 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should not be a block number per se but rather a number of blocks for which the type is BlockNumber. in this case, we assume 12 blocks per minute (1 every 5 seconds), multiply by 60 and 24 to get approximately one day.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha, that's clear now!

burn: Permill::from_percent(50),
}),
};

let client = Arc::new(client::new_in_mem::<NativeExecutor<demo_executor::Executor>, Block, _>(executor, genesis_config)?);
Expand Down
1 change: 1 addition & 0 deletions demo/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ substrate-runtime-session = { path = "../../substrate/runtime/session" }
substrate-runtime-staking = { path = "../../substrate/runtime/staking" }
substrate-runtime-system = { path = "../../substrate/runtime/system" }
substrate-runtime-consensus = { path = "../../substrate/runtime/consensus" }
substrate-runtime-treasury = { path = "../../substrate/runtime/treasury" }
34 changes: 30 additions & 4 deletions demo/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern crate triehash;
#[cfg(test)] extern crate substrate_runtime_staking as staking;
#[cfg(test)] extern crate substrate_runtime_system as system;
#[cfg(test)] extern crate substrate_runtime_consensus as consensus;
#[cfg(test)] extern crate substrate_runtime_treasury as treasury;
#[cfg(test)] #[macro_use] extern crate hex_literal;

pub use substrate_executor::NativeExecutor;
Expand All @@ -53,7 +54,7 @@ mod tests {
use demo_primitives::{Hash, BlockNumber, AccountId};
use runtime_primitives::traits::Header as HeaderT;
use runtime_primitives::{ApplyOutcome, ApplyError, ApplyResult};
use {balances, staking, session, system, consensus};
use {balances, staking, session, system, consensus, treasury};
use system::{EventRecord, Phase};
use demo_runtime::{Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances,
BuildStorage, GenesisConfig, BalancesConfig, SessionConfig, StakingConfig, System, Event};
Expand Down Expand Up @@ -234,6 +235,7 @@ mod tests {
democracy: Some(Default::default()),
council: Some(Default::default()),
timestamp: Some(Default::default()),
treasury: Some(Default::default()),
}.build_storage().unwrap().into()
}

Expand All @@ -260,7 +262,7 @@ mod tests {
construct_block(
1,
[69u8; 32].into(),
hex!("ddfc4d60889b25215f4fe6ead4e38b7522fa20809a793476eae3ad5ab2d9c399").into(),
hex!("1e930ccf2a39029931fcb9173637ab99a7de9d0364e7bf57cfbcb3eb4619e0d4").into(),
vec![CheckedExtrinsic {
signed: Some(alice()),
index: 0,
Expand All @@ -273,7 +275,7 @@ mod tests {
construct_block(
2,
block1().1,
hex!("2b4464c7e0d51325505663ae2ebd2246fcefc5cb998e9c29d8030c559cbbf27f").into(),
hex!("80e45869c9a9f513695b94baf479913ddf0bc9653f1be63baa383be8553a9e13").into(),
vec![
CheckedExtrinsic {
signed: Some(bob()),
Expand All @@ -293,7 +295,7 @@ mod tests {
construct_block(
1,
[69u8; 32].into(),
hex!("e45221804da3a3609454d4e09debe6364cc6af63c2ff067d802d1af62fea32ae").into(),
hex!("58bf7cd5a908de7296bfc0524d89086384df3e8010ab83c8599be036445d6c79").into(),
vec![CheckedExtrinsic {
signed: Some(alice()),
index: 0,
Expand Down Expand Up @@ -328,6 +330,18 @@ mod tests {
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::system(system::Event::ExtrinsicSuccess)
},
EventRecord {
phase: Phase::Finalization,
event: Event::treasury(treasury::RawEvent::Spending(0))
},
EventRecord {
phase: Phase::Finalization,
event: Event::treasury(treasury::RawEvent::Burnt(0))
},
EventRecord {
phase: Phase::Finalization,
event: Event::treasury(treasury::RawEvent::Rollover(0))
}
]);
});
Expand Down Expand Up @@ -368,6 +382,18 @@ mod tests {
phase: Phase::ApplyExtrinsic(1),
event: Event::system(system::Event::ExtrinsicSuccess)
},
EventRecord {
phase: Phase::Finalization,
event: Event::treasury(treasury::RawEvent::Spending(0))
},
EventRecord {
phase: Phase::Finalization,
event: Event::treasury(treasury::RawEvent::Burnt(0))
},
EventRecord {
phase: Phase::Finalization,
event: Event::treasury(treasury::RawEvent::Rollover(0))
},
EventRecord {
phase: Phase::Finalization,
event: Event::session(session::RawEvent::NewSession(1))
Expand Down
2 changes: 2 additions & 0 deletions demo/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ substrate-runtime-session = { path = "../../substrate/runtime/session" }
substrate-runtime-staking = { path = "../../substrate/runtime/staking" }
substrate-runtime-system = { path = "../../substrate/runtime/system" }
substrate-runtime-timestamp = { path = "../../substrate/runtime/timestamp" }
substrate-runtime-treasury = { path = "../../substrate/runtime/treasury" }
substrate-runtime-version = { path = "../../substrate/runtime/version" }
demo-primitives = { path = "../primitives" }

Expand All @@ -48,6 +49,7 @@ std = [
"substrate-runtime-staking/std",
"substrate-runtime-system/std",
"substrate-runtime-timestamp/std",
"substrate-runtime-treasury/std",
"substrate-runtime-version/std",
"demo-primitives/std",
"serde_derive",
Expand Down
32 changes: 29 additions & 3 deletions demo/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern crate serde_derive;
extern crate serde;

extern crate substrate_codec as codec;
extern crate substrate_primitives;

#[macro_use]
extern crate substrate_codec_derive;
Expand All @@ -49,6 +50,7 @@ extern crate substrate_runtime_session as session;
extern crate substrate_runtime_staking as staking;
extern crate substrate_runtime_system as system;
extern crate substrate_runtime_timestamp as timestamp;
extern crate substrate_runtime_treasury as treasury;
#[macro_use]
extern crate substrate_runtime_version as version;
extern crate demo_primitives;
Expand All @@ -57,9 +59,11 @@ use demo_primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index
use runtime_primitives::generic;
use runtime_primitives::traits::{Convert, BlakeTwo256, DigestItem};
use version::RuntimeVersion;
use council::motions as council_motions;
use substrate_primitives::u32_trait::{_2, _4};

#[cfg(any(feature = "std", test))]
pub use runtime_primitives::BuildStorage;
pub use runtime_primitives::{BuildStorage, Permill};

// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -161,9 +165,27 @@ pub type Council = council::Module<Runtime>;
/// Council voting module for this concrete runtime.
pub type CouncilVoting = council::voting::Module<Runtime>;

impl council::motions::Trait for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
}

/// Council motions module for this concrete runtime.
pub type CouncilMotions = council_motions::Module<Runtime>;

impl treasury::Trait for Runtime {
type ApproveOrigin = council_motions::EnsureMembers<_4>;
type RejectOrigin = council_motions::EnsureMembers<_2>;
type Event = Event;
}

/// Treasury module for this concrete runtime.
pub type Treasury = treasury::Module<Runtime>;

impl_outer_event! {
pub enum Event for Runtime {
balances, session, staking, democracy
balances, session, staking, democracy, treasury, council_motions
}
}

Expand All @@ -175,6 +197,7 @@ impl_outer_log! {

impl_outer_origin! {
pub enum Origin for Runtime {
council_motions
}
}

Expand All @@ -188,6 +211,8 @@ impl_outer_dispatch! {
Democracy,
Council,
CouncilVoting,
CouncilMotions,
Treasury,
}
}

Expand All @@ -201,6 +226,7 @@ impl_outer_config! {
DemocracyConfig => democracy,
CouncilConfig => council,
TimestampConfig => timestamp,
TreasuryConfig => treasury,
}
}

Expand Down Expand Up @@ -228,7 +254,7 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Index, Call,
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Index, Call>;
/// Executive: handles dispatch to the various modules.
pub type Executive = executive::Executive<Runtime, Block, Balances, Balances,
(((((), Council), Democracy), Staking), Session)>;
((((((), Treasury), Council), Democracy), Staking), Session)>;

pub mod api {
impl_stubs!(
Expand Down
20 changes: 20 additions & 0 deletions demo/runtime/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions demo/runtime/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ substrate-runtime-session = { path = "../../../substrate/runtime/session", defau
substrate-runtime-staking = { path = "../../../substrate/runtime/staking", default-features = false }
substrate-runtime-system = { path = "../../../substrate/runtime/system", default-features = false }
substrate-runtime-timestamp = { path = "../../../substrate/runtime/timestamp", default-features = false }
substrate-runtime-treasury = { path = "../../../substrate/runtime/treasury", default-features = false }
substrate-runtime-version = { path = "../../../substrate/runtime/version", default-features = false }
demo-primitives = { path = "../../primitives", default-features = false }

Expand All @@ -47,6 +48,7 @@ std = [
"substrate-runtime-staking/std",
"substrate-runtime-system/std",
"substrate-runtime-timestamp/std",
"substrate-runtime-treasury/std",
"substrate-runtime-version/std",
"demo-primitives/std",
]
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions substrate/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ pub use hashing::{blake2_256, twox_128, twox_256};
#[cfg(feature = "std")]
pub mod hexdisplay;

pub mod u32_trait;

pub mod hash;
mod hasher;
pub mod sandbox;
Expand Down
Loading