forked from paritytech/substrate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/block producer (paritytech#99)
* cx system init * provide a new inherent tx for block_producer
- Loading branch information
Showing
12 changed files
with
207 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[package] | ||
name = "cxrml-system" | ||
version = "0.1.0" | ||
authors = ["Chainpool <http://chainx.org>"] | ||
|
||
|
||
[dependencies] | ||
hex-literal = "0.1.0" | ||
serde = { version = "1.0", default_features = false } | ||
serde_derive = { version = "1.0", optional = true } | ||
parity-codec = { version = "2.0", default-features = false } | ||
parity-codec-derive = { version = "2.0", default-features = false } | ||
substrate-primitives = { git = "https://github.com/paritytech/substrate", default_features = false } | ||
sr-std = { git = "https://github.com/paritytech/substrate", default_features = false } | ||
sr-io = { git = "https://github.com/paritytech/substrate", default_features = false } | ||
sr-primitives = { git = "https://github.com/paritytech/substrate", default_features = false } | ||
srml-support = { git = "https://github.com/paritytech/substrate", default_features = false } | ||
srml-system = { git = "https://github.com/paritytech/substrate", default_features = false } | ||
|
||
|
||
[features] | ||
default = ["std"] | ||
std=[ | ||
"serde/std", | ||
"serde_derive", | ||
"parity-codec/std", | ||
"parity-codec-derive/std", | ||
"substrate-primitives/std", | ||
"sr-std/std", | ||
"sr-io/std", | ||
"sr-primitives/std", | ||
"srml-support/std", | ||
"srml-system/std", | ||
] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//! this module is for bch-bridge | ||
|
||
#![cfg_attr(not(feature = "std"), no_std)] | ||
// for encode/decode | ||
// Needed for deriving `Serialize` and `Deserialize` for various types. | ||
// We only implement the serde traits for std builds - they're unneeded | ||
// in the wasm runtime. | ||
#[cfg(feature = "std")] | ||
#[macro_use] | ||
extern crate serde_derive; | ||
|
||
// Needed for deriving `Encode` and `Decode` for `RawEvent`. | ||
//#[macro_use] | ||
//extern crate parity_codec_derive; | ||
extern crate parity_codec as codec; | ||
|
||
// for substrate | ||
// Needed for the set of mock primitives used in our tests. | ||
#[cfg(feature = "std")] | ||
extern crate substrate_primitives; | ||
|
||
// for substrate runtime | ||
// map!, vec! marco. | ||
extern crate sr_std as rstd; | ||
// Needed for tests (`with_externalities`). | ||
#[cfg(feature = "std")] | ||
extern crate sr_io as runtime_io; | ||
extern crate sr_primitives as runtime_primitives; | ||
// for substrate runtime module lib | ||
// Needed for type-safe access to storage DB. | ||
#[macro_use] | ||
extern crate srml_support as runtime_support; | ||
extern crate srml_system as system; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
//use codec::{Codec, Decode, Encode}; | ||
use rstd::prelude::*; | ||
//use rstd::marker::PhantomData; | ||
//use rstd::result::Result as StdResult; | ||
use runtime_support::dispatch::Result; | ||
use runtime_support::StorageValue; | ||
use runtime_primitives::traits::OnFinalise; | ||
|
||
use system::ensure_inherent; | ||
|
||
|
||
pub trait Trait: system::Trait {} | ||
|
||
|
||
decl_module! { | ||
pub struct Module<T: Trait> for enum Call where origin: T::Origin { | ||
fn set_block_producer(origin, producer: T::AccountId) -> Result; | ||
} | ||
} | ||
|
||
impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> { | ||
fn on_finalise(_: T::BlockNumber) { | ||
BlockProdocer::<T>::kill(); | ||
} | ||
} | ||
|
||
decl_storage! { | ||
trait Store for Module<T: Trait> as CXSystem { | ||
pub BlockProdocer get(block_producer) config(): Option<T::AccountId>; | ||
} | ||
} | ||
|
||
impl<T: Trait> Module<T> { | ||
fn set_block_producer(origin: T::Origin, producer: T::AccountId) -> Result { | ||
ensure_inherent(origin)?; | ||
BlockProdocer::<T>::put(producer); | ||
Ok(()) | ||
} | ||
} | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#[test] | ||
fn it_works() { | ||
assert_eq!(2 + 2, 4); | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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