-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#31 Initial commit for new cli structure
- Loading branch information
1 parent
dd01f8b
commit 1f4180c
Showing
10 changed files
with
737 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[package] | ||
authors = ['Polkadex Team https://github.com/Polkadex-Substrate/Polkadex'] | ||
build = 'build.rs' | ||
description = 'Polkadex: Orderbook based Decentralized Chain' | ||
edition = '2018' | ||
homepage = 'https://github.com/Polkadex-Substrate/Polkadex' | ||
license = 'Apache 2.0' | ||
name = 'polkadex-cli' | ||
repository = 'https://github.com/Polkadex-Substrate/Polkadex' | ||
version = "2.0.0" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ['x86_64-unknown-linux-gnu'] | ||
|
||
[[bin]] | ||
name = 'polkadex-mainnet' | ||
|
||
[dependencies] | ||
jsonrpc-core = '15.0.0' | ||
structopt = '0.3.8' | ||
engine-rpc = { path = "../../pallets/polkadex-engine/rpc" } | ||
engine-runtime-api = { default-features = false, path = "../../pallets/polkadex-engine/runtime-api" } | ||
polkadex-mainnet-runtime = { path = "../../runtime/mainnet", version = "2.0.0" } | ||
pallet-transaction-payment-rpc = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sc-basic-authorship = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sc-client-api = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sc-consensus = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sc-consensus-slots = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sc-consensus-babe = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sc-executor = { git = 'https://github.com/paritytech/substrate.git', branch = "master", features = ['wasmtime'] } | ||
sc-finality-grandpa = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sc-rpc = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sc-rpc-api = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sc-service = { git = 'https://github.com/paritytech/substrate.git', branch = "master", features = ['wasmtime'] } | ||
sc-transaction-pool = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sp-api = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sp-block-builder = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sp-blockchain = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sp-consensus = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sp-consensus-babe = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sp-core = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sp-finality-grandpa = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sp-inherents = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sp-runtime = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sp-transaction-pool = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
substrate-frame-rpc-system = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
frame-benchmarking-cli = { git = 'https://github.com/paritytech/substrate.git', branch = "master" } | ||
sc-cli = { git = 'https://github.com/paritytech/substrate.git', features = ['wasmtime'], branch = "master" } | ||
|
||
[build-dependencies] | ||
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "master" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; | ||
|
||
fn main() { | ||
generate_cargo_keys(); | ||
rerun_if_git_head_changed(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
use sp_core::{Pair, Public, sr25519}; | ||
use polkadex_mainnet_runtime::{ | ||
AccountId, BabeConfig,BalancesConfig, GenesisConfig, GrandpaConfig, | ||
SudoConfig, SystemConfig, WASM_BINARY, Signature, SessionConfig, StakingConfig, StakerStatus, | ||
opaque::SessionKeys, Balance, CustomAssetConfig | ||
}; | ||
// use sp_consensus_aura::sr25519::AuthorityId as AuraId; | ||
use sp_consensus_babe::{AuthorityId as BabeId}; | ||
use sp_finality_grandpa::AuthorityId as GrandpaId; | ||
use sp_runtime::traits::{Verify, IdentifyAccount}; | ||
use sc_service::ChainType; | ||
use sp_runtime::{Perbill}; | ||
use sp_runtime::FixedU128; | ||
use sp_runtime::testing::H256; | ||
|
||
// The URL for the telemetry server. | ||
// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; | ||
|
||
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. | ||
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>; | ||
|
||
/// Generate a crypto pair from seed. | ||
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public { | ||
TPublic::Pair::from_string(&format!("//{}", seed), None) | ||
.expect("static values are valid; qed") | ||
.public() | ||
} | ||
|
||
type AccountPublic = <Signature as Verify>::Signer; | ||
|
||
/// Generate an account ID from seed. | ||
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId where | ||
AccountPublic: From<<TPublic::Pair as Pair>::Public> | ||
{ | ||
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account() | ||
} | ||
|
||
/// Generate an Babe authority key. | ||
pub fn authority_keys_from_seed(s: &str) -> (BabeId, GrandpaId, AccountId, AccountId) { | ||
( | ||
get_from_seed::<BabeId>(s), | ||
get_from_seed::<GrandpaId>(s), | ||
get_account_id_from_seed::<sr25519::Public>(&format!("{}//stash", s)), | ||
get_account_id_from_seed::<sr25519::Public>(s) | ||
) | ||
} | ||
|
||
pub fn development_config() -> Result<ChainSpec, String> { | ||
let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?; | ||
|
||
Ok(ChainSpec::from_genesis( | ||
// Name | ||
"Development", | ||
// ID | ||
"dev", | ||
ChainType::Development, | ||
move || testnet_genesis( | ||
wasm_binary, | ||
// Initial Babe authorities | ||
vec![ | ||
authority_keys_from_seed("Alice"), | ||
], | ||
// Sudo account | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
// Pre-funded accounts | ||
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, | ||
), | ||
// Bootnodes | ||
vec![], | ||
// Telemetry | ||
None, | ||
// Protocol ID | ||
None, | ||
// Properties | ||
None, | ||
// Extensions | ||
None, | ||
)) | ||
} | ||
|
||
pub fn local_testnet_config() -> Result<ChainSpec, String> { | ||
let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?; | ||
|
||
Ok(ChainSpec::from_genesis( | ||
// Name | ||
"Local Testnet", | ||
// ID | ||
"local_testnet", | ||
ChainType::Local, | ||
move || testnet_genesis( | ||
wasm_binary, | ||
// Initial Babe authorities | ||
vec![ | ||
authority_keys_from_seed("Alice"), | ||
authority_keys_from_seed("Bob"), | ||
], | ||
// Sudo account | ||
get_account_id_from_seed::<sr25519::Public>("Alice"), | ||
// Pre-funded accounts | ||
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, | ||
), | ||
// Bootnodes | ||
vec![], | ||
// Telemetry | ||
None, | ||
// Protocol ID | ||
None, | ||
// Properties | ||
None, | ||
// Extensions | ||
None, | ||
)) | ||
} | ||
|
||
/// Configure initial storage state for FRAME modules. | ||
fn testnet_genesis( | ||
wasm_binary: &[u8], | ||
initial_authorities: Vec<(BabeId, GrandpaId, AccountId,AccountId)>, | ||
root_key: AccountId, | ||
endowed_accounts: Vec<AccountId>, | ||
_enable_println: bool, | ||
) -> GenesisConfig { | ||
const STASH: Balance = 100; | ||
const UNIT: u128 = 1_000_000_000_000; | ||
GenesisConfig { | ||
frame_system: Some(SystemConfig { | ||
// Add Wasm runtime to storage. | ||
code: wasm_binary.to_vec(), | ||
changes_trie_config: Default::default(), | ||
}), | ||
pallet_balances: Some(BalancesConfig { | ||
// Configure endowed accounts with initial balance of 1 << 60. | ||
balances: vec![], | ||
}), | ||
pallet_babe: Some(BabeConfig { | ||
// authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(), | ||
authorities: vec![], | ||
}), | ||
pallet_grandpa: Some(GrandpaConfig { | ||
// authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(), | ||
authorities: vec![], | ||
}), | ||
pallet_sudo: Some(SudoConfig { | ||
// Assign network admin rights. | ||
key: root_key, | ||
}), | ||
pallet_session: Some(SessionConfig { | ||
keys: initial_authorities.iter().map(|x| { | ||
(x.2.clone(), x.2.clone(), session_keys( | ||
x.1.clone(), | ||
x.0.clone() | ||
)) | ||
}).collect::<Vec<_>>(), | ||
}), | ||
pallet_staking: Some(StakingConfig { | ||
validator_count: initial_authorities.len() as u32 * 2, | ||
minimum_validator_count: initial_authorities.len() as u32, | ||
stakers: initial_authorities.iter().map(|x| { | ||
(x.2.clone(), x.3.clone(), STASH, StakerStatus::Validator) | ||
}).collect(), | ||
invulnerables: initial_authorities.iter().map(|x| x.2.clone()).collect(), | ||
slash_reward_fraction: Perbill::from_percent(10), | ||
.. Default::default() | ||
}), | ||
polkadex_custom_assets: Some(CustomAssetConfig{ | ||
assets: vec![H256::random()], | ||
initial_balance: FixedU128::from(UNIT*UNIT), // TODO Change values accordingly | ||
endowed_accounts: endowed_accounts | ||
.clone().into_iter().map(Into::into).collect(), | ||
native_asset: H256::random() | ||
}) | ||
} | ||
} | ||
|
||
fn session_keys( | ||
grandpa: GrandpaId, | ||
babe: BabeId, | ||
) -> SessionKeys { | ||
SessionKeys { grandpa, babe } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use structopt::StructOpt; | ||
use sc_cli::RunCmd; | ||
|
||
#[derive(Debug, StructOpt)] | ||
pub struct Cli { | ||
#[structopt(subcommand)] | ||
pub subcommand: Option<Subcommand>, | ||
|
||
#[structopt(flatten)] | ||
pub run: RunCmd, | ||
} | ||
|
||
#[derive(Debug, StructOpt)] | ||
pub enum Subcommand { | ||
/// Key management cli utilities | ||
Key(sc_cli::KeySubcommand), | ||
/// Build a chain specification. | ||
BuildSpec(sc_cli::BuildSpecCmd), | ||
|
||
/// Validate blocks. | ||
CheckBlock(sc_cli::CheckBlockCmd), | ||
|
||
/// Export blocks. | ||
ExportBlocks(sc_cli::ExportBlocksCmd), | ||
|
||
/// Export the state of a given block into a chain spec. | ||
ExportState(sc_cli::ExportStateCmd), | ||
|
||
/// Import blocks. | ||
ImportBlocks(sc_cli::ImportBlocksCmd), | ||
|
||
/// Remove the whole chain. | ||
PurgeChain(sc_cli::PurgeChainCmd), | ||
|
||
/// Revert the chain to a previous state. | ||
Revert(sc_cli::RevertCmd), | ||
|
||
/// The custom benchmark subcommmand benchmarking runtime pallets. | ||
#[structopt(name = "benchmark", about = "Benchmark runtime pallets.")] | ||
Benchmark(frame_benchmarking_cli::BenchmarkCmd), | ||
} |
Oops, something went wrong.