├── runtime
├── wasm
│ ├── src
│ ├── build.sh
│ ├── Cargo.toml
│ └── Cargo.lock
├── parking_space_struct.json
├── src
│ ├── parking_space.rs
│ └── lib.rs
└── Cargo.toml
├── extrinsic.png
├── settings.png
├── chain-state.png
├── .gitignore
├── .editorconfig
├── src
├── error.rs
├── main.rs
├── chain_spec.rs
├── service.rs
└── cli.rs
├── init.sh
├── README.md
├── LICENSE
└── Cargo.toml
/runtime/wasm/src:
--------------------------------------------------------------------------------
1 | ../src
--------------------------------------------------------------------------------
/extrinsic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nasa8x/ParkingSpaceSubstrate/master/extrinsic.png
--------------------------------------------------------------------------------
/settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nasa8x/ParkingSpaceSubstrate/master/settings.png
--------------------------------------------------------------------------------
/chain-state.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nasa8x/ParkingSpaceSubstrate/master/chain-state.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Generated by Cargo
2 | # will have compiled files and executables
3 | **/target/
4 |
5 | # These are backup files generated by rustfmt
6 | **/*.rs.bk
7 |
--------------------------------------------------------------------------------
/runtime/parking_space_struct.json:
--------------------------------------------------------------------------------
1 | {
2 | "Space": {
3 | "index": "u32",
4 | "renter": "AccountId",
5 | "space_balance": "Balance"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 | [*]
3 | indent_style=tab
4 | indent_size=tab
5 | tab_width=4
6 | end_of_line=lf
7 | charset=utf-8
8 | trim_trailing_whitespace=true
9 | max_line_length=120
10 | insert_final_newline=true
11 |
12 | [*.yml]
13 | indent_style=space
14 | indent_size=2
15 | tab_width=8
16 | end_of_line=lf
17 |
--------------------------------------------------------------------------------
/src/error.rs:
--------------------------------------------------------------------------------
1 | //! Initialization errors.
2 |
3 | use client;
4 |
5 | error_chain! {
6 | foreign_links {
7 | Io(::std::io::Error) #[doc="IO error"];
8 | Cli(::clap::Error) #[doc="CLI error"];
9 | }
10 | links {
11 | Client(client::error::Error, client::error::ErrorKind) #[doc="Client error"];
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/runtime/wasm/build.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | if cargo --version | grep -q "nightly"; then
5 | CARGO_CMD="cargo"
6 | else
7 | CARGO_CMD="cargo +nightly"
8 | fi
9 | $CARGO_CMD build --target=wasm32-unknown-unknown --release
10 | for i in parking_space_substrate_runtime
11 | do
12 | wasm-gc target/wasm32-unknown-unknown/release/$i.wasm target/wasm32-unknown-unknown/release/$i.compact.wasm
13 | done
14 |
--------------------------------------------------------------------------------
/init.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -e
4 |
5 | echo "*** Initialising WASM build environment"
6 |
7 | if [ -z $CI_PROJECT_NAME ] ; then
8 | rustup update nightly
9 | rustup update stable
10 | fi
11 |
12 | rustup target add wasm32-unknown-unknown --toolchain nightly
13 |
14 | # Install wasm-gc. It's useful for stripping slimming down wasm binaries.
15 | command -v wasm-gc || \
16 | cargo +nightly install --git https://github.com/alexcrichton/wasm-gc --force
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # parking-space-substrate
2 |
3 | Parking Space Registry, silly example of using Substrate Node Template to launch a chain.
4 |
5 | You rent a space by adding a balance to it, you can't rent spaces with a balance remaining on it.
6 |
7 | ## Build and Start parking-space chain
8 | ```
9 | $ curl https://getsubstrate.io -sSf | bash
10 | $ git clone https://github.com/yjkimjunior/ParkingSpaceSubstrate
11 | $ ./init.sh
12 | $ ./build.sh
13 | $ cargo build --release
14 | $ ./target/release/parking-space-substrate --dev
15 | ```
16 |
17 | ## Actually do stuff with the parking-space-chain runtime
18 | The Polkadot/Substrate GUI makes it easier to interact with the runtime:
19 |
20 |
21 | Because we use a custom Struct to represent a Parking Space, we need to let the UI know about it so it can decode it appropriately. That's done with the `runtime/parking_space_struct.json` file, uploaded under the `Settings` tab in the UI.
22 |
23 | 
24 |
25 | Here you rent a space by paying some of your token balance onto it.
26 |
27 | 
28 |
29 | Here you query the chain to confirm it actually happened.
30 | 
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | This is free and unencumbered software released into the public domain.
2 |
3 | Anyone is free to copy, modify, publish, use, compile, sell, or
4 | distribute this software, either in source code form or as a compiled
5 | binary, for any purpose, commercial or non-commercial, and by any
6 | means.
7 |
8 | In jurisdictions that recognize copyright laws, the author or authors
9 | of this software dedicate any and all copyright interest in the
10 | software to the public domain. We make this dedication for the benefit
11 | of the public at large and to the detriment of our heirs and
12 | successors. We intend this dedication to be an overt act of
13 | relinquishment in perpetuity of all present and future rights to this
14 | software under copyright law.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | For more information, please refer to
25 |
--------------------------------------------------------------------------------
/src/main.rs:
--------------------------------------------------------------------------------
1 | //! Substrate Node Template CLI library.
2 |
3 | #![warn(missing_docs)]
4 | #![warn(unused_extern_crates)]
5 |
6 | extern crate futures;
7 | #[macro_use]
8 | extern crate error_chain;
9 | extern crate tokio;
10 | #[macro_use]
11 | extern crate log;
12 | extern crate substrate_cli;
13 | extern crate substrate_primitives as primitives;
14 | extern crate substrate_consensus_aura as consensus;
15 | extern crate substrate_client as client;
16 | #[macro_use]
17 | extern crate substrate_network as network;
18 | #[macro_use]
19 | extern crate substrate_executor;
20 | extern crate substrate_transaction_pool as transaction_pool;
21 | extern crate substrate_basic_authorship as basic_authorship;
22 | #[macro_use]
23 | extern crate substrate_service;
24 | extern crate parking_space_substrate_runtime;
25 | #[macro_use]
26 | extern crate structopt;
27 | extern crate node_executor;
28 | extern crate sr_primitives as runtime_primitives;
29 |
30 | mod chain_spec;
31 | mod service;
32 | mod cli;
33 |
34 | pub use substrate_cli::{VersionInfo, IntoExit, error};
35 |
36 | fn run() -> cli::error::Result<()> {
37 | let version = VersionInfo {
38 | commit: env!("VERGEN_SHA_SHORT"),
39 | version: env!("CARGO_PKG_VERSION"),
40 | executable_name: "parking-space-substrate",
41 | author: "yj",
42 | description: "parking-space-substrate",
43 | };
44 | cli::run(::std::env::args(), cli::Exit, version)
45 | }
46 |
47 | quick_main!(run);
48 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "parking-space-substrate"
3 | version = "0.9.0"
4 | authors = ["Parity Technologies "]
5 | build = "build.rs"
6 |
7 | [[bin]]
8 | name = "parking-space-substrate"
9 | path = "src/main.rs"
10 |
11 | [dependencies]
12 | error-chain = "0.12"
13 | futures = "0.1"
14 | ctrlc = { version = "3.0", features = ["termination"] }
15 | log = "0.4"
16 | tokio = "0.1.7"
17 | exit-future = "0.1"
18 | parking_lot = "0.4"
19 | hex-literal = "0.1"
20 | slog = "^2"
21 | parity-codec = { version = "2.1" }
22 | trie-root = { git = "https://github.com/paritytech/trie" }
23 | sr-io = { git = "https://github.com/paritytech/substrate" }
24 | sr-primitives = { git = "https://github.com/paritytech/substrate" }
25 | substrate-cli = { git = "https://github.com/paritytech/substrate" }
26 | substrate-primitives = { git = "https://github.com/paritytech/substrate" }
27 | substrate-executor = { git = "https://github.com/paritytech/substrate" }
28 | substrate-service = { git = "https://github.com/paritytech/substrate" }
29 | substrate-transaction-pool = { git = "https://github.com/paritytech/substrate" }
30 | substrate-network = { git = "https://github.com/paritytech/substrate" }
31 | substrate-consensus-aura = { git = "https://github.com/paritytech/substrate" }
32 | substrate-client = { git = "https://github.com/paritytech/substrate", default-features = false }
33 | substrate-finality-grandpa = { git = "https://github.com/paritytech/substrate" }
34 | substrate-basic-authorship = { git = "https://github.com/paritytech/substrate" }
35 | parking-space-substrate-runtime = { path = "runtime" }
36 | node-executor = { git = "https://github.com/paritytech/substrate" }
37 | structopt = "0.2.13"
38 |
39 | [build-dependencies]
40 | vergen = "2"
41 |
42 | [workspace]
43 | members = [ "runtime" ]
44 | exclude = [ "runtime/wasm" ]
45 |
46 | [profile.release]
47 | # Substrate runtime requires unwinding.
48 | panic = "unwind"
49 |
--------------------------------------------------------------------------------
/runtime/src/parking_space.rs:
--------------------------------------------------------------------------------
1 | use srml_support::{StorageValue, StorageMap, dispatch::Result};
2 | use {balances, system::ensure_signed};
3 |
4 | extern crate sr_primitives as primitives;
5 | extern crate substrate_primitives;
6 |
7 | pub trait Trait: balances::Trait {}
8 |
9 | #[derive(Encode, Eq, PartialEq, Clone, Copy, Decode, Default)]
10 | pub struct Space {
11 | index: u32,
12 | renter: AccountId,
13 | space_balance: Balance,
14 | }
15 |
16 | decl_module! {
17 | pub struct Module for enum Call where origin: T::Origin {
18 | fn rent_space(_origin, payment: T::Balance, space_index: u32) -> Result {
19 | let renter = ensure_signed(_origin)?;
20 |
21 | // check if balance is zero (then it's empty)
22 | ensure!(Self::spaceAt(space_index).space_balance < payment, "Sorry, someone's already paid more for this space.");
23 |
24 | // decrease the renter's balance by 1
25 | >::decrease_free_balance(&renter, payment)?;
26 |
27 | // construct the space struct
28 | let my_space = Space {
29 | index: space_index.clone(),
30 | renter: renter.clone(),
31 | space_balance: payment.clone()
32 | };
33 |
34 | // add that balance to rent the space
35 | >::insert(space_index, my_space.clone());
36 |
37 | // insert the mapping of renter accound id to the space index and its current balance
38 | >::insert(&renter, my_space.clone());
39 |
40 | Ok(())
41 | }
42 | }
43 | }
44 |
45 | decl_storage! {
46 | trait Store for Module as ParkingSpaceStorage {
47 | pub SpaceAt get(spaceAt): map u32 => Space;
48 | pub SpaceOf get(spaceOf): map T::AccountId => Space;
49 | pub OwnerOf get(ownerOf): map u32 => T::AccountId;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/runtime/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "parking-space-substrate-runtime"
3 | version = "0.9.0"
4 | authors = ["Parity Technologies "]
5 |
6 | [dependencies]
7 | rustc-hex = "1.0"
8 | hex-literal = "0.1.0"
9 | serde = { version = "1.0", default-features = false }
10 | serde_derive = { version = "1.0", optional = true }
11 | safe-mix = { version = "1.0", default-features = false }
12 | parity-codec = "2.0"
13 | parity-codec-derive = "2.0"
14 | sr-std = { git = "https://github.com/paritytech/substrate" }
15 | sr-io = { git = "https://github.com/paritytech/substrate" }
16 | srml-support = { git = "https://github.com/paritytech/substrate" }
17 | substrate-primitives = { git = "https://github.com/paritytech/substrate" }
18 | substrate-keyring = { git = "https://github.com/paritytech/substrate" }
19 | srml-balances = { git = "https://github.com/paritytech/substrate" }
20 | srml-consensus = { git = "https://github.com/paritytech/substrate" }
21 | srml-aura = { git = "https://github.com/paritytech/substrate" }
22 | srml-executive = { git = "https://github.com/paritytech/substrate" }
23 | sr-primitives = { git = "https://github.com/paritytech/substrate" }
24 | srml-system = { git = "https://github.com/paritytech/substrate" }
25 | srml-timestamp = { git = "https://github.com/paritytech/substrate" }
26 | srml-sudo = { git = "https://github.com/paritytech/substrate" }
27 | substrate-client = { git = "https://github.com/paritytech/substrate", optional = true }
28 | sr-version = { git = "https://github.com/paritytech/substrate" }
29 | substrate-consensus-aura-primitives = { git = "https://github.com/paritytech/substrate" }
30 |
31 | [features]
32 | default = ["std"]
33 | std = [
34 | "parity-codec/std",
35 | "substrate-primitives/std",
36 | "substrate-client/std",
37 | "sr-std/std",
38 | "sr-io/std",
39 | "srml-support/std",
40 | "srml-balances/std",
41 | "srml-executive/std",
42 | "srml-aura/std",
43 | "sr-primitives/std",
44 | "srml-system/std",
45 | "srml-timestamp/std",
46 | "srml-sudo/std",
47 | "sr-version/std",
48 | "serde_derive",
49 | "serde/std",
50 | "safe-mix/std",
51 | "substrate-client",
52 | "substrate-consensus-aura-primitives/std",
53 | ]
54 |
--------------------------------------------------------------------------------
/runtime/wasm/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "parking-space-substrate-runtime"
3 | version = "0.9.0"
4 | authors = ["Parity Technologies "]
5 |
6 | [lib]
7 | crate-type = ["cdylib"]
8 |
9 | [dependencies]
10 | integer-sqrt = { git = "https://github.com/paritytech/integer-sqrt-rs.git" }
11 | safe-mix = { version = "1.0", default-features = false}
12 | parity-codec-derive = { version = "^2.1" }
13 | parity-codec = { version = "^2.1", default-features = false }
14 | substrate-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
15 | substrate-client = { git = "https://github.com/paritytech/substrate", default-features = false }
16 | sr-std = { git = "https://github.com/paritytech/substrate", default-features = false }
17 | sr-io = { git = "https://github.com/paritytech/substrate", default-features = false }
18 | srml-support = { git = "https://github.com/paritytech/substrate", default-features = false }
19 | srml-balances = { git = "https://github.com/paritytech/substrate", default-features = false }
20 | srml-consensus = { git = "https://github.com/paritytech/substrate", default-features = false }
21 | srml-executive = { git = "https://github.com/paritytech/substrate", default-features = false }
22 | srml-aura = { git = "https://github.com/paritytech/substrate", default-features = false }
23 | sr-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
24 | srml-system = { git = "https://github.com/paritytech/substrate", default-features = false }
25 | srml-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false }
26 | srml-sudo = { git = "https://github.com/paritytech/substrate", default-features = false }
27 | sr-version = { git = "https://github.com/paritytech/substrate", default-features = false }
28 | substrate-consensus-aura-primitives = { git = "https://github.com/paritytech/substrate", default-features = false }
29 |
30 | [features]
31 | default = []
32 | std = [
33 | "safe-mix/std",
34 | "parity-codec/std",
35 | "substrate-primitives/std",
36 | "substrate-client/std",
37 | "sr-std/std",
38 | "sr-io/std",
39 | "srml-support/std",
40 | "srml-balances/std",
41 | "srml-consensus/std",
42 | "srml-executive/std",
43 | "srml-aura/std",
44 | "sr-primitives/std",
45 | "srml-system/std",
46 | "srml-timestamp/std",
47 | "srml-sudo/std",
48 | "sr-version/std",
49 | ]
50 |
51 | [profile.release]
52 | panic = "abort"
53 | lto = true
54 |
55 | [workspace]
56 | members = []
57 |
--------------------------------------------------------------------------------
/src/chain_spec.rs:
--------------------------------------------------------------------------------
1 | use primitives::{Ed25519AuthorityId, ed25519};
2 | use parking_space_substrate_runtime::{
3 | AccountId, GenesisConfig, ConsensusConfig, TimestampConfig, BalancesConfig, SudoConfig,
4 | };
5 | use substrate_service;
6 |
7 | // Note this is the URL for the telemetry server
8 | //const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
9 |
10 | /// Specialised `ChainSpec`. This is a specialisation of the general Substrate ChainSpec type.
11 | pub type ChainSpec = substrate_service::ChainSpec;
12 |
13 | /// The chain specification option. This is expected to come in from the CLI and
14 | /// is little more than one of a number of alternatives which can easily be converted
15 | /// from a string (`--chain=...`) into a `ChainSpec`.
16 | #[derive(Clone, Debug)]
17 | pub enum Alternative {
18 | /// Whatever the current runtime is, with just Alice as an auth.
19 | Development,
20 | /// Whatever the current runtime is, with simple Alice/Bob auths.
21 | LocalTestnet,
22 | }
23 |
24 | impl Alternative {
25 | /// Get an actual chain config from one of the alternatives.
26 | pub(crate) fn load(self) -> Result {
27 | Ok(match self {
28 | Alternative::Development => ChainSpec::from_genesis(
29 | "Development",
30 | "dev",
31 | || testnet_genesis(vec![
32 | ed25519::Pair::from_seed(b"Alice ").public().into(),
33 | ], vec![
34 | ed25519::Pair::from_seed(b"Alice ").public().0.into(),
35 | ],
36 | ed25519::Pair::from_seed(b"Alice ").public().0.into()
37 | ),
38 | vec![],
39 | None,
40 | None,
41 | None,
42 | None
43 | ),
44 | Alternative::LocalTestnet => ChainSpec::from_genesis(
45 | "Local Testnet",
46 | "local_testnet",
47 | || testnet_genesis(vec![
48 | ed25519::Pair::from_seed(b"Alice ").public().into(),
49 | ed25519::Pair::from_seed(b"Bob ").public().into(),
50 | ], vec![
51 | ed25519::Pair::from_seed(b"Alice ").public().0.into(),
52 | ed25519::Pair::from_seed(b"Bob ").public().0.into(),
53 | ed25519::Pair::from_seed(b"Charlie ").public().0.into(),
54 | ed25519::Pair::from_seed(b"Dave ").public().0.into(),
55 | ed25519::Pair::from_seed(b"Eve ").public().0.into(),
56 | ed25519::Pair::from_seed(b"Ferdie ").public().0.into(),
57 | ],
58 | ed25519::Pair::from_seed(b"Alice ").public().0.into()
59 | ),
60 | vec![],
61 | None,
62 | None,
63 | None,
64 | None
65 | ),
66 | })
67 | }
68 |
69 | pub(crate) fn from(s: &str) -> Option {
70 | match s {
71 | "dev" => Some(Alternative::Development),
72 | "local" => Some(Alternative::LocalTestnet),
73 | _ => None,
74 | }
75 | }
76 | }
77 |
78 | fn testnet_genesis(initial_authorities: Vec, endowed_accounts: Vec, root_key: AccountId) -> GenesisConfig {
79 | GenesisConfig {
80 | consensus: Some(ConsensusConfig {
81 | code: include_bytes!("../runtime/wasm/target/wasm32-unknown-unknown/release/parking_space_substrate_runtime.compact.wasm").to_vec(),
82 | authorities: initial_authorities.clone(),
83 | }),
84 | system: None,
85 | timestamp: Some(TimestampConfig {
86 | period: 5, // 5 second block time.
87 | }),
88 | balances: Some(BalancesConfig {
89 | transaction_base_fee: 1,
90 | transaction_byte_fee: 0,
91 | existential_deposit: 500,
92 | transfer_fee: 0,
93 | creation_fee: 0,
94 | reclaim_rebate: 0,
95 | balances: endowed_accounts.iter().map(|&k|(k, (1 << 60))).collect(),
96 | }),
97 | sudo: Some(SudoConfig {
98 | key: root_key,
99 | }),
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/service.rs:
--------------------------------------------------------------------------------
1 | //! Service and ServiceFactory implementation. Specialized wrapper over Substrate service.
2 |
3 | #![warn(unused_extern_crates)]
4 |
5 | use std::sync::Arc;
6 | use transaction_pool::{self, txpool::{Pool as TransactionPool}};
7 | use parking_space_substrate_runtime::{self, GenesisConfig, opaque::Block, RuntimeApi};
8 | use substrate_service::{
9 | FactoryFullConfiguration, LightComponents, FullComponents, FullBackend,
10 | FullClient, LightClient, LightBackend, FullExecutor, LightExecutor,
11 | TaskExecutor,
12 | };
13 | use basic_authorship::ProposerFactory;
14 | use node_executor;
15 | use consensus::{import_queue, start_aura, AuraImportQueue, SlotDuration, NothingExtra};
16 | use client;
17 | use primitives::ed25519::Pair;
18 | use runtime_primitives::BasicInherentData as InherentData;
19 |
20 | pub use substrate_executor::NativeExecutor;
21 | // Our native executor instance.
22 | native_executor_instance!(
23 | pub Executor,
24 | parking_space_substrate_runtime::api::dispatch,
25 | parking_space_substrate_runtime::native_version,
26 | include_bytes!("../runtime/wasm/target/wasm32-unknown-unknown/release/parking_space_substrate_runtime.compact.wasm")
27 | );
28 |
29 | construct_simple_protocol! {
30 | /// Demo protocol attachment for substrate.
31 | pub struct NodeProtocol where Block = Block { }
32 | }
33 |
34 | construct_service_factory! {
35 | struct Factory {
36 | Block = Block,
37 | RuntimeApi = RuntimeApi,
38 | NetworkProtocol = NodeProtocol { |config| Ok(NodeProtocol::new()) },
39 | RuntimeDispatch = node_executor::Executor,
40 | FullTransactionPoolApi = transaction_pool::ChainApi, FullExecutor, Block, RuntimeApi>, Block>
41 | { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) },
42 | LightTransactionPoolApi = transaction_pool::ChainApi, LightExecutor, Block, RuntimeApi>, Block>
43 | { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) },
44 | Genesis = GenesisConfig,
45 | Configuration = (),
46 | FullService = FullComponents
47 | { |config: FactoryFullConfiguration, executor: TaskExecutor|
48 | FullComponents::::new(config, executor)
49 | },
50 | AuthoritySetup = {
51 | |service: Self::FullService, executor: TaskExecutor, key: Option>| {
52 | if let Some(key) = key {
53 | info!("Using authority key {}", key.public());
54 | let proposer = Arc::new(ProposerFactory {
55 | client: service.client(),
56 | transaction_pool: service.transaction_pool(),
57 | });
58 | let client = service.client();
59 | executor.spawn(start_aura(
60 | SlotDuration::get_or_compute(&*client)?,
61 | key.clone(),
62 | client.clone(),
63 | client,
64 | proposer,
65 | service.network(),
66 | service.on_exit(),
67 | ));
68 | }
69 |
70 | Ok(service)
71 | }
72 | },
73 | LightService = LightComponents
74 | { |config, executor| >::new(config, executor) },
75 | FullImportQueue = AuraImportQueue<
76 | Self::Block,
77 | FullClient,
78 | NothingExtra,
79 | ::consensus::InherentProducingFn,
80 | >
81 | { |config: &mut FactoryFullConfiguration , client: Arc>|
82 | Ok(import_queue(
83 | SlotDuration::get_or_compute(&*client)?,
84 | client,
85 | NothingExtra,
86 | ::consensus::make_basic_inherent as _,
87 | ))
88 | },
89 | LightImportQueue = AuraImportQueue<
90 | Self::Block,
91 | LightClient,
92 | NothingExtra,
93 | ::consensus::InherentProducingFn,
94 | >
95 | { |ref mut config, client: Arc>|
96 | Ok(import_queue(
97 | SlotDuration::get_or_compute(&*client)?,
98 | client,
99 | NothingExtra,
100 | ::consensus::make_basic_inherent as _,
101 | ))
102 | },
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/cli.rs:
--------------------------------------------------------------------------------
1 | use service;
2 | use futures::{future, Future, sync::oneshot};
3 | use std::cell::RefCell;
4 | use tokio::runtime::Runtime;
5 | pub use substrate_cli::{VersionInfo, IntoExit, error};
6 | use substrate_cli::{Action, informant, parse_matches, execute_default, CoreParams};
7 | use substrate_service::{ServiceFactory, Roles as ServiceRoles};
8 | use chain_spec;
9 | use std::ops::Deref;
10 | use structopt::StructOpt;
11 |
12 | /// Extend params for Node
13 | #[derive(Debug, StructOpt)]
14 | pub struct NodeParams {
15 | /// Should run as a GRANDPA authority node
16 | #[structopt(long = "grandpa-authority", help = "Run Node as a GRANDPA authority, implies --validator")]
17 | grandpa_authority: bool,
18 |
19 | /// Should run as a GRANDPA authority node only
20 | #[structopt(long = "grandpa-authority-only", help = "Run Node as a GRANDPA authority only, don't as a usual validator, implies --grandpa-authority")]
21 | grandpa_authority_only: bool,
22 |
23 | #[structopt(flatten)]
24 | core: CoreParams
25 | }
26 |
27 | /// Parse command line arguments into service configuration.
28 | pub fn run(args: I, exit: E, version: VersionInfo) -> error::Result<()> where
29 | I: IntoIterator- ,
30 | T: Into + Clone,
31 | E: IntoExit,
32 | {
33 | let full_version = substrate_service::config::full_version_from_strs(
34 | version.version,
35 | version.commit
36 | );
37 |
38 | let matches = match NodeParams::clap()
39 | .name(version.executable_name)
40 | .author(version.author)
41 | .about(version.description)
42 | .version(&(full_version + "\n")[..])
43 | .get_matches_from_safe(args) {
44 | Ok(m) => m,
45 | Err(e) => e.exit(),
46 | };
47 |
48 | let (spec, config) = parse_matches::(
49 | load_spec, version, "substrate-node", &matches
50 | )?;
51 |
52 | match execute_default::(spec, exit, &matches, &config)? {
53 | Action::ExecutedInternally => (),
54 | Action::RunService(exit) => {
55 | info!("Substrate Node");
56 | info!(" version {}", config.full_version());
57 | info!(" by Parity Technologies, 2017, 2018");
58 | info!("Chain specification: {}", config.chain_spec.name());
59 | info!("Node name: {}", config.name);
60 | info!("Roles: {:?}", config.roles);
61 | let mut runtime = Runtime::new()?;
62 | let executor = runtime.executor();
63 | match config.roles == ServiceRoles::LIGHT {
64 | true => run_until_exit(&mut runtime, service::Factory::new_light(config, executor)?, exit)?,
65 | false => run_until_exit(&mut runtime, service::Factory::new_full(config, executor)?, exit)?,
66 | }
67 | }
68 | }
69 |
70 | Ok(())
71 | }
72 |
73 | fn load_spec(id: &str) -> Result