Merge pull request #25 from substrate-developer-hub/joshy-alpha-3
Update node template to alpha.3main
commit
5b41f0b156
File diff suppressed because it is too large
Load Diff
135
Cargo.toml
135
Cargo.toml
|
@ -1,134 +1,9 @@
|
|||
[profile.release]
|
||||
panic = 'unwind'
|
||||
|
||||
[package]
|
||||
authors = ['Anonymous']
|
||||
build = 'build.rs'
|
||||
edition = '2018'
|
||||
name = 'node-template'
|
||||
version = '2.0.0'
|
||||
|
||||
[build-dependencies]
|
||||
vergen = '3.0.4'
|
||||
|
||||
[build-dependencies.build-script-utils]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'substrate-build-script-utils'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies]
|
||||
futures = '0.3.1'
|
||||
log = '0.4.8'
|
||||
parking_lot = '0.9.0'
|
||||
tokio = '0.1.22'
|
||||
trie-root = '0.15.2'
|
||||
|
||||
[dependencies.codec]
|
||||
package = 'parity-scale-codec'
|
||||
version = '1.0.0'
|
||||
|
||||
[dependencies.ctrlc]
|
||||
features = ['termination']
|
||||
version = '3.1.3'
|
||||
|
||||
[dependencies.futures01]
|
||||
package = 'futures'
|
||||
version = '0.1.29'
|
||||
|
||||
[dependencies.grandpa]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'sc-finality-grandpa'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.grandpa-primitives]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'sp-finality-grandpa'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.node-template-runtime]
|
||||
path = 'runtime'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sc-basic-authority]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
|
||||
[dependencies.sc-cli]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sc-client]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sc-consensus-aura]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '0.8'
|
||||
|
||||
[dependencies.sc-executor]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sc-network]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '0.8'
|
||||
|
||||
[dependencies.sc-service]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sc-transaction-pool]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sp-consensus]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '0.8'
|
||||
|
||||
[dependencies.sp-consensus-aura]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '0.8'
|
||||
|
||||
[dependencies.sp-core]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sp-inherents]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sp-io]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sp-runtime]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sp-transaction-pool]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[workspace]
|
||||
members = ['runtime']
|
||||
|
||||
[[bin]]
|
||||
name = 'node-template'
|
||||
path = 'src/main.rs'
|
||||
members = [
|
||||
'node',
|
||||
'pallets/template',
|
||||
'runtime',
|
||||
]
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
# Substrate Node Template
|
||||
|
||||
A new FRAME-based Substrate node, ready for hacking.
|
||||
A new Substrate node, ready for hacking. This node includes:
|
||||
|
||||
* A FRAME-based runtime
|
||||
* A template pallet
|
||||
* Aura block authoring
|
||||
* Grandpa finality gadget
|
||||
|
||||
## Build
|
||||
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
[build-dependencies]
|
||||
vergen = '3.0.4'
|
||||
|
||||
[build-dependencies.build-script-utils]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'substrate-build-script-utils'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[package]
|
||||
authors = ['Anonymous']
|
||||
build = 'build.rs'
|
||||
edition = '2018'
|
||||
homepage = 'https://substrate.dev'
|
||||
license = 'Unlicense'
|
||||
name = 'node-template'
|
||||
repository = 'https://github.com/paritytech/substrate/'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[[bin]]
|
||||
name = 'node-template'
|
||||
|
||||
[dependencies]
|
||||
futures = '0.3.1'
|
||||
log = '0.4.8'
|
||||
structopt = '0.3.8'
|
||||
|
||||
[dependencies.grandpa]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'sc-finality-grandpa'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '0.8.0-alpha.3'
|
||||
|
||||
[dependencies.grandpa-primitives]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'sp-finality-grandpa'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.node-template-runtime]
|
||||
path = '../runtime'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sc-basic-authorship]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '0.8.0-alpha.3'
|
||||
|
||||
[dependencies.sc-cli]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '0.8.0-alpha.3'
|
||||
|
||||
[dependencies.sc-client]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '0.8.0-alpha.3'
|
||||
|
||||
[dependencies.sc-consensus-aura]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '0.8.0-alpha.3'
|
||||
|
||||
[dependencies.sc-executor]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '0.8.0-alpha.3'
|
||||
|
||||
[dependencies.sc-network]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '0.8.0-alpha.3'
|
||||
|
||||
[dependencies.sc-service]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '0.8.0-alpha.3'
|
||||
|
||||
[dependencies.sc-transaction-pool]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sp-consensus]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '0.8.0-alpha.3'
|
||||
|
||||
[dependencies.sp-consensus-aura]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '0.8.0-alpha.3'
|
||||
|
||||
[dependencies.sp-core]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sp-inherents]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sp-runtime]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sp-transaction-pool]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
|
@ -0,0 +1,9 @@
|
|||
use vergen::{ConstantsFlags, generate_cargo_keys};
|
||||
|
||||
const ERROR_MSG: &str = "Failed to generate metadata files";
|
||||
|
||||
fn main() {
|
||||
generate_cargo_keys(ConstantsFlags::SHA_SHORT).expect(ERROR_MSG);
|
||||
|
||||
build_script_utils::rerun_if_git_head_changed();
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
use sp_core::{Pair, Public, sr25519};
|
||||
use node_template_runtime::{
|
||||
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig,
|
||||
SudoConfig, IndicesConfig, SystemConfig, WASM_BINARY, Signature
|
||||
SudoConfig, SystemConfig, WASM_BINARY, Signature
|
||||
};
|
||||
use sp_consensus_aura::sr25519::{AuthorityId as AuraId};
|
||||
use grandpa_primitives::{AuthorityId as GrandpaId};
|
||||
|
@ -56,17 +56,19 @@ impl Alternative {
|
|||
Alternative::Development => ChainSpec::from_genesis(
|
||||
"Development",
|
||||
"dev",
|
||||
|| testnet_genesis(vec![
|
||||
get_authority_keys_from_seed("Alice"),
|
||||
],
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
vec![
|
||||
|| testnet_genesis(
|
||||
vec![
|
||||
get_authority_keys_from_seed("Alice"),
|
||||
],
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
|
||||
],
|
||||
true),
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
|
||||
],
|
||||
true,
|
||||
),
|
||||
vec![],
|
||||
None,
|
||||
None,
|
||||
|
@ -76,26 +78,28 @@ impl Alternative {
|
|||
Alternative::LocalTestnet => ChainSpec::from_genesis(
|
||||
"Local Testnet",
|
||||
"local_testnet",
|
||||
|| testnet_genesis(vec![
|
||||
get_authority_keys_from_seed("Alice"),
|
||||
get_authority_keys_from_seed("Bob"),
|
||||
],
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
vec![
|
||||
|| testnet_genesis(
|
||||
vec![
|
||||
get_authority_keys_from_seed("Alice"),
|
||||
get_authority_keys_from_seed("Bob"),
|
||||
],
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Charlie"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Dave"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Eve"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
|
||||
],
|
||||
true),
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Charlie"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Dave"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Eve"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
|
||||
],
|
||||
true,
|
||||
),
|
||||
vec![],
|
||||
None,
|
||||
None,
|
||||
|
@ -123,15 +127,8 @@ fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,
|
|||
code: WASM_BINARY.to_vec(),
|
||||
changes_trie_config: Default::default(),
|
||||
}),
|
||||
indices: Some(IndicesConfig {
|
||||
ids: endowed_accounts.clone(),
|
||||
}),
|
||||
balances: Some(BalancesConfig {
|
||||
balances: endowed_accounts.iter().cloned().map(|k|(k, 1 << 60)).collect(),
|
||||
vesting: vec![],
|
||||
}),
|
||||
sudo: Some(SudoConfig {
|
||||
key: root_key,
|
||||
}),
|
||||
aura: Some(AuraConfig {
|
||||
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
|
||||
|
@ -139,5 +136,15 @@ fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,
|
|||
grandpa: Some(GrandpaConfig {
|
||||
authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),
|
||||
}),
|
||||
sudo: Some(SudoConfig {
|
||||
key: root_key,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_spec(id: &str) -> Result<Option<ChainSpec>, String> {
|
||||
Ok(match Alternative::from(id) {
|
||||
Some(spec) => Some(spec.load()?),
|
||||
None => None,
|
||||
})
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
use sc_cli::{RunCmd, Subcommand};
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct Cli {
|
||||
#[structopt(subcommand)]
|
||||
pub subcommand: Option<Subcommand>,
|
||||
|
||||
#[structopt(flatten)]
|
||||
pub run: RunCmd,
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair};
|
||||
use sc_cli::VersionInfo;
|
||||
use crate::service;
|
||||
use crate::chain_spec;
|
||||
use crate::cli::Cli;
|
||||
|
||||
/// Parse and run command line arguments
|
||||
pub fn run(version: VersionInfo) -> sc_cli::Result<()> {
|
||||
let opt = sc_cli::from_args::<Cli>(&version);
|
||||
|
||||
let mut config = sc_service::Configuration::from_version(&version);
|
||||
|
||||
match opt.subcommand {
|
||||
Some(subcommand) => {
|
||||
subcommand.init(&version)?;
|
||||
subcommand.update_config(&mut config, chain_spec::load_spec, &version)?;
|
||||
subcommand.run(
|
||||
config,
|
||||
|config: _| Ok(new_full_start!(config).0),
|
||||
)
|
||||
},
|
||||
None => {
|
||||
opt.run.init(&version)?;
|
||||
opt.run.update_config(&mut config, chain_spec::load_spec, &version)?;
|
||||
opt.run.run(
|
||||
config,
|
||||
service::new_light,
|
||||
service::new_full,
|
||||
&version,
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
|
@ -1,17 +1,14 @@
|
|||
//! Substrate Node Template CLI library.
|
||||
|
||||
#![warn(missing_docs)]
|
||||
#![warn(unused_extern_crates)]
|
||||
|
||||
mod chain_spec;
|
||||
#[macro_use]
|
||||
mod service;
|
||||
mod cli;
|
||||
mod command;
|
||||
|
||||
pub use sc_cli::{VersionInfo, IntoExit, error};
|
||||
|
||||
fn main() -> Result<(), cli::error::Error> {
|
||||
let version = VersionInfo {
|
||||
fn main() -> sc_cli::Result<()> {
|
||||
let version = sc_cli::VersionInfo {
|
||||
name: "Substrate Node",
|
||||
commit: env!("VERGEN_SHA_SHORT"),
|
||||
version: env!("CARGO_PKG_VERSION"),
|
||||
|
@ -19,7 +16,8 @@ fn main() -> Result<(), cli::error::Error> {
|
|||
author: "Anonymous",
|
||||
description: "Template Node",
|
||||
support_url: "support.anonymous.an",
|
||||
copyright_start_year: 2017,
|
||||
};
|
||||
|
||||
cli::run(std::env::args(), cli::Exit, version)
|
||||
command::run(version)
|
||||
}
|
|
@ -6,12 +6,10 @@ use sc_client::LongestChain;
|
|||
use node_template_runtime::{self, GenesisConfig, opaque::Block, RuntimeApi};
|
||||
use sc_service::{error::{Error as ServiceError}, AbstractService, Configuration, ServiceBuilder};
|
||||
use sp_inherents::InherentDataProviders;
|
||||
use sc_network::{construct_simple_protocol};
|
||||
use sc_executor::native_executor_instance;
|
||||
pub use sc_executor::NativeExecutor;
|
||||
use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair};
|
||||
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
|
||||
use sc_basic_authority;
|
||||
|
||||
// Our native executor instance.
|
||||
native_executor_instance!(
|
||||
|
@ -20,11 +18,6 @@ native_executor_instance!(
|
|||
node_template_runtime::native_version,
|
||||
);
|
||||
|
||||
construct_simple_protocol! {
|
||||
/// Demo protocol attachment for substrate.
|
||||
pub struct NodeProtocol where Block = Block { }
|
||||
}
|
||||
|
||||
/// Starts a `ServiceBuilder` for a full service.
|
||||
///
|
||||
/// Use this macro if you don't actually need the full service, but just the builder in order to
|
||||
|
@ -42,32 +35,26 @@ macro_rules! new_full_start {
|
|||
})?
|
||||
.with_transaction_pool(|config, client, _fetcher| {
|
||||
let pool_api = sc_transaction_pool::FullChainApi::new(client.clone());
|
||||
let pool = sc_transaction_pool::BasicPool::new(config, pool_api);
|
||||
let maintainer = sc_transaction_pool::FullBasicPoolMaintainer::new(pool.pool().clone(), client);
|
||||
let maintainable_pool = sp_transaction_pool::MaintainableTransactionPool::new(pool, maintainer);
|
||||
Ok(maintainable_pool)
|
||||
Ok(sc_transaction_pool::BasicPool::new(config, std::sync::Arc::new(pool_api)))
|
||||
})?
|
||||
.with_import_queue(|_config, client, mut select_chain, transaction_pool| {
|
||||
.with_import_queue(|_config, client, mut select_chain, _transaction_pool| {
|
||||
let select_chain = select_chain.take()
|
||||
.ok_or_else(|| sc_service::Error::SelectChainRequired)?;
|
||||
|
||||
let (grandpa_block_import, grandpa_link) =
|
||||
grandpa::block_import::<_, _, _, node_template_runtime::RuntimeApi, _>(
|
||||
client.clone(), &*client, select_chain
|
||||
)?;
|
||||
grandpa::block_import(client.clone(), &*client, select_chain)?;
|
||||
|
||||
let aura_block_import = sc_consensus_aura::AuraBlockImport::<_, _, _, AuraPair>::new(
|
||||
grandpa_block_import.clone(), client.clone(),
|
||||
);
|
||||
|
||||
let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _>(
|
||||
sc_consensus_aura::SlotDuration::get_or_compute(&*client)?,
|
||||
let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair>(
|
||||
sc_consensus_aura::slot_duration(&*client)?,
|
||||
aura_block_import,
|
||||
Some(Box::new(grandpa_block_import.clone())),
|
||||
None,
|
||||
client,
|
||||
inherent_data_providers.clone(),
|
||||
Some(transaction_pool),
|
||||
)?;
|
||||
|
||||
import_setup = Some((grandpa_block_import, grandpa_link));
|
||||
|
@ -80,7 +67,7 @@ macro_rules! new_full_start {
|
|||
}
|
||||
|
||||
/// Builds a new service for a full client.
|
||||
pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisConfig>)
|
||||
pub fn new_full(config: Configuration<GenesisConfig>)
|
||||
-> Result<impl AbstractService, ServiceError>
|
||||
{
|
||||
let is_authority = config.roles.is_authority();
|
||||
|
@ -99,17 +86,17 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
|
|||
import_setup.take()
|
||||
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");
|
||||
|
||||
let service = builder.with_network_protocol(|_| Ok(NodeProtocol::new()))?
|
||||
let service = builder
|
||||
.with_finality_proof_provider(|client, backend|
|
||||
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _)
|
||||
)?
|
||||
.build()?;
|
||||
|
||||
if participates_in_consensus {
|
||||
let proposer = sc_basic_authority::ProposerFactory {
|
||||
client: service.client(),
|
||||
transaction_pool: service.transaction_pool(),
|
||||
};
|
||||
let proposer = sc_basic_authorship::ProposerFactory::new(
|
||||
service.client(),
|
||||
service.transaction_pool()
|
||||
);
|
||||
|
||||
let client = service.client();
|
||||
let select_chain = service.select_chain()
|
||||
|
@ -118,8 +105,8 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
|
|||
let can_author_with =
|
||||
sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone());
|
||||
|
||||
let aura = sc_consensus_aura::start_aura::<_, _, _, _, _, AuraPair, _, _, _, _>(
|
||||
sc_consensus_aura::SlotDuration::get_or_compute(&*client)?,
|
||||
let aura = sc_consensus_aura::start_aura::<_, _, _, _, _, AuraPair, _, _, _>(
|
||||
sc_consensus_aura::slot_duration(&*client)?,
|
||||
client,
|
||||
select_chain,
|
||||
block_import,
|
||||
|
@ -133,7 +120,7 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
|
|||
|
||||
// the AURA authoring task is considered essential, i.e. if it
|
||||
// fails we take down the service with it.
|
||||
service.spawn_essential_task(aura);
|
||||
service.spawn_essential_task("aura", aura);
|
||||
}
|
||||
|
||||
// if the node isn't actively participating in consensus then it doesn't
|
||||
|
@ -149,53 +136,48 @@ pub fn new_full<C: Send + Default + 'static>(config: Configuration<C, GenesisCon
|
|||
gossip_duration: Duration::from_millis(333),
|
||||
justification_period: 512,
|
||||
name: Some(name),
|
||||
observer_enabled: true,
|
||||
observer_enabled: false,
|
||||
keystore,
|
||||
is_authority,
|
||||
};
|
||||
|
||||
match (is_authority, disable_grandpa) {
|
||||
(false, false) => {
|
||||
// start the lightweight GRANDPA observer
|
||||
service.spawn_task(grandpa::run_grandpa_observer(
|
||||
grandpa_config,
|
||||
grandpa_link,
|
||||
service.network(),
|
||||
service.on_exit(),
|
||||
service.spawn_task_handle(),
|
||||
)?);
|
||||
},
|
||||
(true, false) => {
|
||||
// start the full GRANDPA voter
|
||||
let voter_config = grandpa::GrandpaParams {
|
||||
config: grandpa_config,
|
||||
link: grandpa_link,
|
||||
network: service.network(),
|
||||
inherent_data_providers: inherent_data_providers.clone(),
|
||||
on_exit: service.on_exit(),
|
||||
telemetry_on_connect: Some(service.telemetry_on_connect_stream()),
|
||||
voting_rule: grandpa::VotingRulesBuilder::default().build(),
|
||||
executor: service.spawn_task_handle(),
|
||||
};
|
||||
let enable_grandpa = !disable_grandpa;
|
||||
if enable_grandpa {
|
||||
// start the full GRANDPA voter
|
||||
// NOTE: non-authorities could run the GRANDPA observer protocol, but at
|
||||
// this point the full voter should provide better guarantees of block
|
||||
// and vote data availability than the observer. The observer has not
|
||||
// been tested extensively yet and having most nodes in a network run it
|
||||
// could lead to finality stalls.
|
||||
let grandpa_config = grandpa::GrandpaParams {
|
||||
config: grandpa_config,
|
||||
link: grandpa_link,
|
||||
network: service.network(),
|
||||
inherent_data_providers: inherent_data_providers.clone(),
|
||||
on_exit: service.on_exit(),
|
||||
telemetry_on_connect: Some(service.telemetry_on_connect_stream()),
|
||||
voting_rule: grandpa::VotingRulesBuilder::default().build(),
|
||||
};
|
||||
|
||||
// the GRANDPA voter task is considered infallible, i.e.
|
||||
// if it fails we take down the service with it.
|
||||
service.spawn_essential_task(grandpa::run_grandpa_voter(voter_config)?);
|
||||
},
|
||||
(_, true) => {
|
||||
grandpa::setup_disabled_grandpa(
|
||||
service.client(),
|
||||
&inherent_data_providers,
|
||||
service.network(),
|
||||
)?;
|
||||
},
|
||||
// the GRANDPA voter task is considered infallible, i.e.
|
||||
// if it fails we take down the service with it.
|
||||
service.spawn_essential_task(
|
||||
"grandpa-voter",
|
||||
grandpa::run_grandpa_voter(grandpa_config)?
|
||||
);
|
||||
} else {
|
||||
grandpa::setup_disabled_grandpa(
|
||||
service.client(),
|
||||
&inherent_data_providers,
|
||||
service.network(),
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(service)
|
||||
}
|
||||
|
||||
/// Builds a new service for a light client.
|
||||
pub fn new_light<C: Send + Default + 'static>(config: Configuration<C, GenesisConfig>)
|
||||
pub fn new_light(config: Configuration<GenesisConfig>)
|
||||
-> Result<impl AbstractService, ServiceError>
|
||||
{
|
||||
let inherent_data_providers = InherentDataProviders::new();
|
||||
|
@ -207,36 +189,35 @@ pub fn new_light<C: Send + Default + 'static>(config: Configuration<C, GenesisCo
|
|||
.with_transaction_pool(|config, client, fetcher| {
|
||||
let fetcher = fetcher
|
||||
.ok_or_else(|| "Trying to start light transaction pool without active fetcher")?;
|
||||
|
||||
let pool_api = sc_transaction_pool::LightChainApi::new(client.clone(), fetcher.clone());
|
||||
let pool = sc_transaction_pool::BasicPool::new(config, pool_api);
|
||||
let maintainer = sc_transaction_pool::LightBasicPoolMaintainer::with_defaults(pool.pool().clone(), client, fetcher);
|
||||
let maintainable_pool = sp_transaction_pool::MaintainableTransactionPool::new(pool, maintainer);
|
||||
Ok(maintainable_pool)
|
||||
let pool = sc_transaction_pool::BasicPool::with_revalidation_type(
|
||||
config, Arc::new(pool_api), sc_transaction_pool::RevalidationType::Light,
|
||||
);
|
||||
Ok(pool)
|
||||
})?
|
||||
.with_import_queue_and_fprb(|_config, client, backend, fetcher, _select_chain, _tx_pool| {
|
||||
let fetch_checker = fetcher
|
||||
.map(|fetcher| fetcher.checker().clone())
|
||||
.ok_or_else(|| "Trying to start light import queue without active fetch checker")?;
|
||||
let grandpa_block_import = grandpa::light_block_import::<_, _, _, RuntimeApi>(
|
||||
let grandpa_block_import = grandpa::light_block_import(
|
||||
client.clone(), backend, &*client.clone(), Arc::new(fetch_checker),
|
||||
)?;
|
||||
let finality_proof_import = grandpa_block_import.clone();
|
||||
let finality_proof_request_builder =
|
||||
finality_proof_import.create_finality_proof_request_builder();
|
||||
|
||||
let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, ()>(
|
||||
sc_consensus_aura::SlotDuration::get_or_compute(&*client)?,
|
||||
let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair>(
|
||||
sc_consensus_aura::slot_duration(&*client)?,
|
||||
grandpa_block_import,
|
||||
None,
|
||||
Some(Box::new(finality_proof_import)),
|
||||
client,
|
||||
inherent_data_providers.clone(),
|
||||
None,
|
||||
)?;
|
||||
|
||||
Ok((import_queue, finality_proof_request_builder))
|
||||
})?
|
||||
.with_network_protocol(|_| Ok(NodeProtocol::new()))?
|
||||
.with_finality_proof_provider(|client, backend|
|
||||
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _)
|
||||
)?
|
|
@ -0,0 +1,58 @@
|
|||
[dev-dependencies.sp-core]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dev-dependencies.sp-io]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dev-dependencies.sp-runtime]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[features]
|
||||
default = ['std']
|
||||
std = [
|
||||
'codec/std',
|
||||
'frame-support/std',
|
||||
'safe-mix/std',
|
||||
'system/std',
|
||||
]
|
||||
|
||||
[package]
|
||||
authors = ['Anonymous']
|
||||
description = 'FRAME pallet template'
|
||||
edition = '2018'
|
||||
homepage = 'https://substrate.dev'
|
||||
license = 'Unlicense'
|
||||
name = 'pallet-template'
|
||||
repository = 'https://github.com/paritytech/substrate/'
|
||||
version = '2.0.0-alpha.3'
|
||||
[dependencies.codec]
|
||||
default-features = false
|
||||
features = ['derive']
|
||||
package = 'parity-scale-codec'
|
||||
version = '1.0.0'
|
||||
|
||||
[dependencies.frame-support]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.safe-mix]
|
||||
default-features = false
|
||||
version = '1.0.0'
|
||||
|
||||
[dependencies.system]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'frame-system'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
|
@ -0,0 +1,104 @@
|
|||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
/// A FRAME pallet template with necessary imports
|
||||
|
||||
/// Feel free to remove or edit this file as needed.
|
||||
/// If you change the name of this file, make sure to update its references in runtime/src/lib.rs
|
||||
/// If you remove this file, you can remove those references
|
||||
|
||||
/// For more guidance on Substrate FRAME, see the example pallet
|
||||
/// https://github.com/paritytech/substrate/blob/master/frame/example/src/lib.rs
|
||||
|
||||
use frame_support::{decl_module, decl_storage, decl_event, decl_error, dispatch};
|
||||
use system::ensure_signed;
|
||||
|
||||
#[cfg(test)]
|
||||
mod mock;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
/// The pallet's configuration trait.
|
||||
pub trait Trait: system::Trait {
|
||||
// Add other types and constants required to configure this pallet.
|
||||
|
||||
/// The overarching event type.
|
||||
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
|
||||
}
|
||||
|
||||
// This pallet's storage items.
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as TemplateModule {
|
||||
// Just a dummy storage item.
|
||||
// Here we are declaring a StorageValue, `Something` as a Option<u32>
|
||||
// `get(fn something)` is the default getter which returns either the stored `u32` or `None` if nothing stored
|
||||
Something get(fn something): Option<u32>;
|
||||
}
|
||||
}
|
||||
|
||||
// The pallet's events
|
||||
decl_event!(
|
||||
pub enum Event<T> where AccountId = <T as system::Trait>::AccountId {
|
||||
/// Just a dummy event.
|
||||
/// Event `Something` is declared with a parameter of the type `u32` and `AccountId`
|
||||
/// To emit this event, we call the deposit function, from our runtime functions
|
||||
SomethingStored(u32, AccountId),
|
||||
}
|
||||
);
|
||||
|
||||
// The pallet's errors
|
||||
decl_error! {
|
||||
pub enum Error for Module<T: Trait> {
|
||||
/// Value was None
|
||||
NoneValue,
|
||||
/// Value reached maximum and cannot be incremented further
|
||||
StorageOverflow,
|
||||
}
|
||||
}
|
||||
|
||||
// The pallet's dispatchable functions.
|
||||
decl_module! {
|
||||
/// The module declaration.
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
// Initializing errors
|
||||
// this includes information about your errors in the node's metadata.
|
||||
// it is needed only if you are using errors in your pallet
|
||||
type Error = Error<T>;
|
||||
|
||||
// Initializing events
|
||||
// this is needed only if you are using events in your pallet
|
||||
fn deposit_event() = default;
|
||||
|
||||
/// Just a dummy entry point.
|
||||
/// function that can be called by the external world as an extrinsics call
|
||||
/// takes a parameter of the type `AccountId`, stores it, and emits an event
|
||||
pub fn do_something(origin, something: u32) -> dispatch::DispatchResult {
|
||||
// Check it was signed and get the signer. See also: ensure_root and ensure_none
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
// Code to execute when something calls this.
|
||||
// For example: the following line stores the passed in u32 in the storage
|
||||
Something::put(something);
|
||||
|
||||
// Here we are raising the Something event
|
||||
Self::deposit_event(RawEvent::SomethingStored(something, who));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Another dummy entry point.
|
||||
/// takes no parameters, attempts to increment storage value, and possibly throws an error
|
||||
pub fn cause_error(origin) -> dispatch::DispatchResult {
|
||||
// Check it was signed and get the signer. See also: ensure_root and ensure_none
|
||||
let _who = ensure_signed(origin)?;
|
||||
|
||||
match Something::get() {
|
||||
None => Err(Error::<T>::NoneValue)?,
|
||||
Some(old) => {
|
||||
let new = old.checked_add(1).ok_or(Error::<T>::StorageOverflow)?;
|
||||
Something::put(new);
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
// Creating mock runtime here
|
||||
|
||||
use crate::{Module, Trait};
|
||||
use sp_core::H256;
|
||||
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
|
||||
use sp_runtime::{
|
||||
traits::{BlakeTwo256, IdentityLookup}, testing::Header, Perbill,
|
||||
};
|
||||
|
||||
impl_outer_origin! {
|
||||
pub enum Origin for Test {}
|
||||
}
|
||||
|
||||
// For testing the pallet, we construct most of a mock runtime. This means
|
||||
// first constructing a configuration type (`Test`) which `impl`s each of the
|
||||
// configuration traits of pallets we want to use.
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct Test;
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub const MaximumBlockWeight: Weight = 1024;
|
||||
pub const MaximumBlockLength: u32 = 2 * 1024;
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
|
||||
}
|
||||
impl system::Trait for Test {
|
||||
type Origin = Origin;
|
||||
type Call = ();
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Header = Header;
|
||||
type Event = ();
|
||||
type BlockHashCount = BlockHashCount;
|
||||
type MaximumBlockWeight = MaximumBlockWeight;
|
||||
type MaximumBlockLength = MaximumBlockLength;
|
||||
type AvailableBlockRatio = AvailableBlockRatio;
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
type AccountData = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
}
|
||||
impl Trait for Test {
|
||||
type Event = ();
|
||||
}
|
||||
pub type TemplateModule = Module<Test>;
|
||||
|
||||
// This function basically just builds a genesis storage key/value store according to
|
||||
// our desired mockup.
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
// Tests to be written here
|
||||
|
||||
use crate::{Error, mock::*};
|
||||
use frame_support::{assert_ok, assert_noop};
|
||||
|
||||
#[test]
|
||||
fn it_works_for_default_value() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Just a dummy test for the dummy function `do_something`
|
||||
// calling the `do_something` function with a value 42
|
||||
assert_ok!(TemplateModule::do_something(Origin::signed(1), 42));
|
||||
// asserting that the stored value is equal to what we stored
|
||||
assert_eq!(TemplateModule::something(), Some(42));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn correct_error_for_none_value() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Ensure the correct error is thrown on None value
|
||||
assert_noop!(
|
||||
TemplateModule::cause_error(Origin::signed(1)),
|
||||
Error::<Test>::NoneValue
|
||||
);
|
||||
});
|
||||
}
|
|
@ -1,162 +1,16 @@
|
|||
[dependencies.aura]
|
||||
default-features = false
|
||||
[package]
|
||||
authors = ['Anonymous']
|
||||
edition = '2018'
|
||||
homepage = 'https://substrate.dev'
|
||||
license = 'Unlicense'
|
||||
name = 'node-template-runtime'
|
||||
repository = 'https://github.com/paritytech/substrate/'
|
||||
version = '2.0.0-alpha.3'
|
||||
[build-dependencies.wasm-builder-runner]
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'pallet-aura'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.balances]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'pallet-balances'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.codec]
|
||||
default-features = false
|
||||
features = ['derive']
|
||||
package = 'parity-scale-codec'
|
||||
version = '1.0.0'
|
||||
|
||||
[dependencies.frame-executive]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.frame-support]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.grandpa]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'pallet-grandpa'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.indices]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'pallet-indices'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.randomness-collective-flip]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'pallet-randomness-collective-flip'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.safe-mix]
|
||||
default-features = false
|
||||
version = '1.0.0'
|
||||
|
||||
[dependencies.serde]
|
||||
features = ['derive']
|
||||
optional = true
|
||||
version = '1.0.101'
|
||||
|
||||
[dependencies.sp-api]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sp-block-builder]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
|
||||
[dependencies.sp-consensus-aura]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '0.8'
|
||||
|
||||
[dependencies.sp-core]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sp-inherents]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
|
||||
[dependencies.sp-io]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sp-offchain]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sp-runtime]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sp-session]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sp-std]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sp-transaction-pool]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sp-version]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.sudo]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'pallet-sudo'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.system]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'frame-system'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.timestamp]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'pallet-timestamp'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
|
||||
[dependencies.transaction-payment]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'pallet-transaction-payment'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '2.0.0'
|
||||
package = 'substrate-wasm-builder-runner'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '1.0.5'
|
||||
|
||||
[features]
|
||||
default = ['std']
|
||||
|
@ -167,9 +21,7 @@ std = [
|
|||
'frame-executive/std',
|
||||
'frame-support/std',
|
||||
'grandpa/std',
|
||||
'indices/std',
|
||||
'randomness-collective-flip/std',
|
||||
'safe-mix/std',
|
||||
'serde',
|
||||
'sp-api/std',
|
||||
'sp-block-builder/std',
|
||||
|
@ -187,15 +39,161 @@ std = [
|
|||
'system/std',
|
||||
'timestamp/std',
|
||||
'transaction-payment/std',
|
||||
'template/std',
|
||||
]
|
||||
|
||||
[package]
|
||||
authors = ['Anonymous']
|
||||
edition = '2018'
|
||||
name = 'node-template-runtime'
|
||||
version = '2.0.0'
|
||||
[build-dependencies.wasm-builder-runner]
|
||||
[dependencies.aura]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'substrate-wasm-builder-runner'
|
||||
rev = '3e651110aa06aa835790df63410a29676243fc54'
|
||||
version = '1.0.4'
|
||||
package = 'pallet-aura'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.balances]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'pallet-balances'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.codec]
|
||||
default-features = false
|
||||
features = ['derive']
|
||||
package = 'parity-scale-codec'
|
||||
version = '1.0.0'
|
||||
|
||||
[dependencies.frame-executive]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.frame-support]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.grandpa]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'pallet-grandpa'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.randomness-collective-flip]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'pallet-randomness-collective-flip'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.serde]
|
||||
features = ['derive']
|
||||
optional = true
|
||||
version = '1.0.101'
|
||||
|
||||
[dependencies.sp-api]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sp-block-builder]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sp-consensus-aura]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '0.8.0-alpha.3'
|
||||
|
||||
[dependencies.sp-core]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sp-inherents]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sp-io]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sp-offchain]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sp-runtime]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sp-session]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sp-std]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sp-transaction-pool]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sp-version]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.sudo]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'pallet-sudo'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.system]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'frame-system'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.template]
|
||||
default-features = false
|
||||
package = 'pallet-template'
|
||||
path = '../pallets/template'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.timestamp]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'pallet-timestamp'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
||||
[dependencies.transaction-payment]
|
||||
default-features = false
|
||||
git = 'https://github.com/paritytech/substrate.git'
|
||||
package = 'pallet-transaction-payment'
|
||||
rev = '013c1ee167354a08283fb69915fda56a62fee943'
|
||||
version = '2.0.0-alpha.3'
|
||||
|
|
|
@ -1,27 +1,10 @@
|
|||
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use wasm_builder_runner::{build_current_project_with_rustflags, WasmBuilderSource};
|
||||
use wasm_builder_runner::WasmBuilder;
|
||||
|
||||
fn main() {
|
||||
build_current_project_with_rustflags(
|
||||
"wasm_binary.rs",
|
||||
WasmBuilderSource::Crates("1.0.8"),
|
||||
// This instructs LLD to export __heap_base as a global variable, which is used by the
|
||||
// external memory allocator.
|
||||
"-Clink-arg=--export=__heap_base",
|
||||
);
|
||||
WasmBuilder::new()
|
||||
.with_current_project()
|
||||
.with_wasm_builder_from_crates("1.0.9")
|
||||
.export_heap_base()
|
||||
.import_memory()
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ use sp_std::prelude::*;
|
|||
use sp_core::OpaqueMetadata;
|
||||
use sp_runtime::{
|
||||
ApplyExtrinsicResult, transaction_validity::TransactionValidity, generic, create_runtime_str,
|
||||
impl_opaque_keys, MultiSignature
|
||||
impl_opaque_keys, MultiSignature,
|
||||
};
|
||||
use sp_runtime::traits::{
|
||||
NumberFor, BlakeTwo256, Block as BlockT, StaticLookup, Verify, ConvertInto, IdentifyAccount
|
||||
BlakeTwo256, Block as BlockT, IdentityLookup, Verify, ConvertInto, IdentifyAccount
|
||||
};
|
||||
use sp_api::impl_runtime_apis;
|
||||
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
||||
|
@ -37,6 +37,9 @@ pub use frame_support::{
|
|||
weights::Weight,
|
||||
};
|
||||
|
||||
/// Importing a template pallet
|
||||
pub use template;
|
||||
|
||||
/// An index to a block.
|
||||
pub type BlockNumber = u32;
|
||||
|
||||
|
@ -63,13 +66,10 @@ pub type Hash = sp_core::H256;
|
|||
/// Digest item type.
|
||||
pub type DigestItem = generic::DigestItem<Hash>;
|
||||
|
||||
/// Used for the module template in `./template.rs`
|
||||
mod template;
|
||||
|
||||
/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
|
||||
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
|
||||
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
|
||||
/// to even the core datastructures.
|
||||
/// to even the core data structures.
|
||||
pub mod opaque {
|
||||
use super::*;
|
||||
|
||||
|
@ -109,7 +109,7 @@ pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
|
|||
pub const HOURS: BlockNumber = MINUTES * 60;
|
||||
pub const DAYS: BlockNumber = HOURS * 24;
|
||||
|
||||
/// The version infromation used to identify this runtime when compiled natively.
|
||||
/// The version information used to identify this runtime when compiled natively.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn native_version() -> NativeVersion {
|
||||
NativeVersion {
|
||||
|
@ -120,7 +120,7 @@ pub fn native_version() -> NativeVersion {
|
|||
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: BlockNumber = 250;
|
||||
pub const MaximumBlockWeight: Weight = 1_000_000;
|
||||
pub const MaximumBlockWeight: Weight = 1_000_000_000;
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
|
||||
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
|
||||
pub const Version: RuntimeVersion = VERSION;
|
||||
|
@ -132,7 +132,7 @@ impl system::Trait for Runtime {
|
|||
/// The aggregated dispatch type that is available for extrinsics.
|
||||
type Call = Call;
|
||||
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
|
||||
type Lookup = Indices;
|
||||
type Lookup = IdentityLookup<AccountId>;
|
||||
/// The index type for storing how many extrinsics an account has signed.
|
||||
type Index = Index;
|
||||
/// The index type for blocks.
|
||||
|
@ -161,6 +161,12 @@ impl system::Trait for Runtime {
|
|||
///
|
||||
/// This type is being generated by `construct_runtime!`.
|
||||
type ModuleToIndex = ModuleToIndex;
|
||||
/// What to do if a new account is created.
|
||||
type OnNewAccount = ();
|
||||
/// What to do if an account is fully reaped from the system.
|
||||
type OnKilledAccount = ();
|
||||
/// The data to be stored in an account.
|
||||
type AccountData = balances::AccountData<Balance>;
|
||||
}
|
||||
|
||||
impl aura::Trait for Runtime {
|
||||
|
@ -171,18 +177,6 @@ impl grandpa::Trait for Runtime {
|
|||
type Event = Event;
|
||||
}
|
||||
|
||||
impl indices::Trait for Runtime {
|
||||
/// The type for recording indexing into the account enumeration. If this ever overflows, there
|
||||
/// will be problems!
|
||||
type AccountIndex = AccountIndex;
|
||||
/// Use the standard means of resolving an index hint from an id.
|
||||
type ResolveHint = indices::SimpleResolveHint<Self::AccountId, Self::AccountIndex>;
|
||||
/// Determine whether an account is dead.
|
||||
type IsDeadAccount = Balances;
|
||||
/// The ubiquitous event type.
|
||||
type Event = Event;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
|
||||
}
|
||||
|
@ -196,24 +190,16 @@ impl timestamp::Trait for Runtime {
|
|||
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: u128 = 500;
|
||||
pub const TransferFee: u128 = 0;
|
||||
pub const CreationFee: u128 = 0;
|
||||
}
|
||||
|
||||
impl balances::Trait for Runtime {
|
||||
/// The type for recording an account's balance.
|
||||
type Balance = Balance;
|
||||
/// What to do if an account's free balance gets zeroed.
|
||||
type OnFreeBalanceZero = ();
|
||||
/// What to do if a new account is created.
|
||||
type OnNewAccount = Indices;
|
||||
/// The ubiquitous event type.
|
||||
type Event = Event;
|
||||
type DustRemoval = ();
|
||||
type TransferPayment = ();
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type TransferFee = TransferFee;
|
||||
type CreationFee = CreationFee;
|
||||
type AccountStore = System;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
|
@ -232,7 +218,7 @@ impl transaction_payment::Trait for Runtime {
|
|||
|
||||
impl sudo::Trait for Runtime {
|
||||
type Event = Event;
|
||||
type Proposal = Call;
|
||||
type Call = Call;
|
||||
}
|
||||
|
||||
/// Used for the module template in `./template.rs`
|
||||
|
@ -246,22 +232,21 @@ construct_runtime!(
|
|||
NodeBlock = opaque::Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic
|
||||
{
|
||||
System: system::{Module, Call, Storage, Config, Event},
|
||||
System: system::{Module, Call, Config, Storage, Event<T>},
|
||||
RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},
|
||||
Timestamp: timestamp::{Module, Call, Storage, Inherent},
|
||||
Aura: aura::{Module, Config<T>, Inherent(Timestamp)},
|
||||
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
|
||||
Indices: indices,
|
||||
Balances: balances,
|
||||
Balances: balances::{Module, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: transaction_payment::{Module, Storage},
|
||||
Sudo: sudo,
|
||||
Sudo: sudo::{Module, Call, Config<T>, Storage, Event<T>},
|
||||
// Used for the module template in `./template.rs`
|
||||
TemplateModule: template::{Module, Call, Storage, Event<T>},
|
||||
RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},
|
||||
}
|
||||
);
|
||||
|
||||
/// The address format for describing accounts.
|
||||
pub type Address = <Indices as StaticLookup>::Source;
|
||||
pub type Address = AccountId;
|
||||
/// Block header type as expected by this runtime.
|
||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
/// Block type as expected by this runtime.
|
||||
|
@ -312,6 +297,10 @@ impl_runtime_apis! {
|
|||
Executive::apply_extrinsic(extrinsic)
|
||||
}
|
||||
|
||||
fn apply_trusted_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
|
||||
Executive::apply_trusted_extrinsic(extrinsic)
|
||||
}
|
||||
|
||||
fn finalize_block() -> <Block as BlockT>::Header {
|
||||
Executive::finalize_block()
|
||||
}
|
||||
|
@ -339,8 +328,8 @@ impl_runtime_apis! {
|
|||
}
|
||||
|
||||
impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
|
||||
fn offchain_worker(number: NumberFor<Block>) {
|
||||
Executive::offchain_worker(number)
|
||||
fn offchain_worker(header: &<Block as BlockT>::Header) {
|
||||
Executive::offchain_worker(header)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -358,6 +347,12 @@ impl_runtime_apis! {
|
|||
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
|
||||
opaque::SessionKeys::generate(seed)
|
||||
}
|
||||
|
||||
fn decode_session_keys(
|
||||
encoded: Vec<u8>,
|
||||
) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
|
||||
opaque::SessionKeys::decode_into_raw_public_keys(&encoded)
|
||||
}
|
||||
}
|
||||
|
||||
impl fg_primitives::GrandpaApi<Block> for Runtime {
|
||||
|
|
|
@ -1,132 +0,0 @@
|
|||
/// A runtime module template with necessary imports
|
||||
|
||||
/// Feel free to remove or edit this file as needed.
|
||||
/// If you change the name of this file, make sure to update its references in runtime/src/lib.rs
|
||||
/// If you remove this file, you can remove those references
|
||||
|
||||
|
||||
/// For more guidance on Substrate modules, see the example module
|
||||
/// https://github.com/paritytech/substrate/blob/master/frame/example/src/lib.rs
|
||||
|
||||
use frame_support::{decl_module, decl_storage, decl_event, dispatch::DispatchResult};
|
||||
use system::ensure_signed;
|
||||
|
||||
/// The module's configuration trait.
|
||||
pub trait Trait: system::Trait {
|
||||
// TODO: Add other types and constants required configure this module.
|
||||
|
||||
/// The overarching event type.
|
||||
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
|
||||
}
|
||||
|
||||
// This module's storage items.
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as TemplateModule {
|
||||
// Just a dummy storage item.
|
||||
// Here we are declaring a StorageValue, `Something` as a Option<u32>
|
||||
// `get(fn something)` is the default getter which returns either the stored `u32` or `None` if nothing stored
|
||||
Something get(fn something): Option<u32>;
|
||||
}
|
||||
}
|
||||
|
||||
// The module's dispatchable functions.
|
||||
decl_module! {
|
||||
/// The module declaration.
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
// Initializing events
|
||||
// this is needed only if you are using events in your module
|
||||
fn deposit_event() = default;
|
||||
|
||||
// Just a dummy entry point.
|
||||
// function that can be called by the external world as an extrinsics call
|
||||
// takes a parameter of the type `AccountId`, stores it and emits an event
|
||||
pub fn do_something(origin, something: u32) -> DispatchResult {
|
||||
// TODO: You only need this if you want to check it was signed.
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
// TODO: Code to execute when something calls this.
|
||||
// For example: the following line stores the passed in u32 in the storage
|
||||
Something::put(something);
|
||||
|
||||
// here we are raising the Something event
|
||||
Self::deposit_event(RawEvent::SomethingStored(something, who));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
decl_event!(
|
||||
pub enum Event<T> where AccountId = <T as system::Trait>::AccountId {
|
||||
// Just a dummy event.
|
||||
// Event `Something` is declared with a parameter of the type `u32` and `AccountId`
|
||||
// To emit this event, we call the deposit funtion, from our runtime funtions
|
||||
SomethingStored(u32, AccountId),
|
||||
}
|
||||
);
|
||||
|
||||
/// tests for this module
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use sp_core::H256;
|
||||
use frame_support::{impl_outer_origin, assert_ok, parameter_types, weights::Weight};
|
||||
use sp_runtime::{
|
||||
traits::{BlakeTwo256, IdentityLookup}, testing::Header, Perbill,
|
||||
};
|
||||
|
||||
impl_outer_origin! {
|
||||
pub enum Origin for Test {}
|
||||
}
|
||||
|
||||
// For testing the module, we construct most of a mock runtime. This means
|
||||
// first constructing a configuration type (`Test`) which `impl`s each of the
|
||||
// configuration traits of modules we want to use.
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct Test;
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub const MaximumBlockWeight: Weight = 1024;
|
||||
pub const MaximumBlockLength: u32 = 2 * 1024;
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
|
||||
}
|
||||
impl system::Trait for Test {
|
||||
type Origin = Origin;
|
||||
type Call = ();
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Header = Header;
|
||||
type Event = ();
|
||||
type BlockHashCount = BlockHashCount;
|
||||
type MaximumBlockWeight = MaximumBlockWeight;
|
||||
type MaximumBlockLength = MaximumBlockLength;
|
||||
type AvailableBlockRatio = AvailableBlockRatio;
|
||||
type Version = ();
|
||||
type ModuleToIndex = ();
|
||||
}
|
||||
impl Trait for Test {
|
||||
type Event = ();
|
||||
}
|
||||
type TemplateModule = Module<Test>;
|
||||
|
||||
// This function basically just builds a genesis storage key/value store according to
|
||||
// our desired mockup.
|
||||
fn new_test_ext() -> sp_io::TestExternalities {
|
||||
system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_works_for_default_value() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Just a dummy test for the dummy funtion `do_something`
|
||||
// calling the `do_something` function with a value 42
|
||||
assert_ok!(TemplateModule::do_something(Origin::signed(1), 42));
|
||||
// asserting that the stored value is equal to what we stored
|
||||
assert_eq!(TemplateModule::something(), Some(42));
|
||||
});
|
||||
}
|
||||
}
|
128
src/cli.rs
128
src/cli.rs
|
@ -1,128 +0,0 @@
|
|||
use crate::service;
|
||||
use futures::{future::{select, Map}, FutureExt, TryFutureExt, channel::oneshot, compat::Future01CompatExt};
|
||||
use std::cell::RefCell;
|
||||
use tokio::runtime::Runtime;
|
||||
pub use sc_cli::{VersionInfo, IntoExit, error};
|
||||
use sc_cli::{display_role, informant, parse_and_prepare, ParseAndPrepare, NoCustom};
|
||||
use sc_service::{AbstractService, Roles as ServiceRoles, Configuration};
|
||||
use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair};
|
||||
use crate::chain_spec;
|
||||
use log::info;
|
||||
|
||||
/// Parse command line arguments into service configuration.
|
||||
pub fn run<I, T, E>(args: I, exit: E, version: VersionInfo) -> error::Result<()> where
|
||||
I: IntoIterator<Item = T>,
|
||||
T: Into<std::ffi::OsString> + Clone,
|
||||
E: IntoExit,
|
||||
{
|
||||
type Config<T> = Configuration<(), T>;
|
||||
match parse_and_prepare::<NoCustom, NoCustom, _>(&version, "substrate-node", args) {
|
||||
ParseAndPrepare::Run(cmd) => cmd.run(load_spec, exit,
|
||||
|exit, _cli_args, _custom_args, config: Config<_>| {
|
||||
info!("{}", version.name);
|
||||
info!(" version {}", config.full_version());
|
||||
info!(" by {}, 2017, 2018", version.author);
|
||||
info!("Chain specification: {}", config.chain_spec.name());
|
||||
info!("Node name: {}", config.name);
|
||||
info!("Roles: {}", display_role(&config));
|
||||
let runtime = Runtime::new().map_err(|e| format!("{:?}", e))?;
|
||||
match config.roles {
|
||||
ServiceRoles::LIGHT => run_until_exit(
|
||||
runtime,
|
||||
service::new_light(config)?,
|
||||
exit
|
||||
),
|
||||
_ => run_until_exit(
|
||||
runtime,
|
||||
service::new_full(config)?,
|
||||
exit
|
||||
),
|
||||
}
|
||||
}),
|
||||
ParseAndPrepare::BuildSpec(cmd) => cmd.run::<NoCustom, _, _, _>(load_spec),
|
||||
ParseAndPrepare::ExportBlocks(cmd) => cmd.run_with_builder(|config: Config<_>|
|
||||
Ok(new_full_start!(config).0), load_spec, exit),
|
||||
ParseAndPrepare::ImportBlocks(cmd) => cmd.run_with_builder(|config: Config<_>|
|
||||
Ok(new_full_start!(config).0), load_spec, exit),
|
||||
ParseAndPrepare::CheckBlock(cmd) => cmd.run_with_builder(|config: Config<_>|
|
||||
Ok(new_full_start!(config).0), load_spec, exit),
|
||||
ParseAndPrepare::PurgeChain(cmd) => cmd.run(load_spec),
|
||||
ParseAndPrepare::RevertChain(cmd) => cmd.run_with_builder(|config: Config<_>|
|
||||
Ok(new_full_start!(config).0), load_spec),
|
||||
ParseAndPrepare::CustomCommand(_) => Ok(())
|
||||
}?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn load_spec(id: &str) -> Result<Option<chain_spec::ChainSpec>, String> {
|
||||
Ok(match chain_spec::Alternative::from(id) {
|
||||
Some(spec) => Some(spec.load()?),
|
||||
None => None,
|
||||
})
|
||||
}
|
||||
|
||||
fn run_until_exit<T, E>(
|
||||
mut runtime: Runtime,
|
||||
service: T,
|
||||
e: E,
|
||||
) -> error::Result<()>
|
||||
where
|
||||
T: AbstractService,
|
||||
E: IntoExit,
|
||||
{
|
||||
let (exit_send, exit) = oneshot::channel();
|
||||
|
||||
let informant = informant::build(&service);
|
||||
|
||||
let future = select(exit, informant)
|
||||
.map(|_| Ok(()))
|
||||
.compat();
|
||||
|
||||
runtime.executor().spawn(future);
|
||||
|
||||
// we eagerly drop the service so that the internal exit future is fired,
|
||||
// but we need to keep holding a reference to the global telemetry guard
|
||||
let _telemetry = service.telemetry();
|
||||
|
||||
let service_res = {
|
||||
let exit = e.into_exit();
|
||||
let service = service
|
||||
.map_err(|err| error::Error::Service(err))
|
||||
.compat();
|
||||
let select = select(service, exit)
|
||||
.map(|_| Ok(()))
|
||||
.compat();
|
||||
runtime.block_on(select)
|
||||
};
|
||||
|
||||
let _ = exit_send.send(());
|
||||
|
||||
// TODO [andre]: timeout this future #1318
|
||||
|
||||
use futures01::Future;
|
||||
|
||||
let _ = runtime.shutdown_on_idle().wait();
|
||||
|
||||
service_res
|
||||
}
|
||||
|
||||
// handles ctrl-c
|
||||
pub struct Exit;
|
||||
impl IntoExit for Exit {
|
||||
type Exit = Map<oneshot::Receiver<()>, fn(Result<(), oneshot::Canceled>) -> ()>;
|
||||
fn into_exit(self) -> Self::Exit {
|
||||
// can't use signal directly here because CtrlC takes only `Fn`.
|
||||
let (exit_send, exit) = oneshot::channel();
|
||||
|
||||
let exit_send_cell = RefCell::new(Some(exit_send));
|
||||
ctrlc::set_handler(move || {
|
||||
let exit_send = exit_send_cell.try_borrow_mut().expect("signal handler not reentrant; qed").take();
|
||||
if let Some(exit_send) = exit_send {
|
||||
exit_send.send(()).expect("Error sending exit notification");
|
||||
}
|
||||
}).expect("Error setting Ctrl-C handler");
|
||||
|
||||
exit.map(drop)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue