Skip to content

Commit

Permalink
Migrate cli to 2018 edition (paritytech#420)
Browse files Browse the repository at this point in the history
* Migrate cli to 2018 edition

Signed-off-by: koushiro <[email protected]>

* Remove useless dep

Signed-off-by: koushiro <[email protected]>

* Update wasm

Signed-off-by: koushiro <[email protected]>
  • Loading branch information
koushiro authored and gguoss committed Mar 16, 2019
1 parent f514dbd commit d5c51ec
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 138 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

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

52 changes: 24 additions & 28 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,56 @@
name = "chainx-cli"
version = "0.1.0"
description = "ChainX node implementation in Rust."
edition = "2018"

[dependencies]
log = "0.4"
structopt = "0.2.13"
tokio = "0.1.7"
exit-future = "0.1"
hex-literal = "0.1"
parity-codec = { version = "3.1" }
rustc-hex = "2.0.1"
slog = "^2"
csv = "1"
structopt = "0.2.13"
serde = "1.0"
serde_derive = "1.0"
csv = "1.0"

# substrate
substrate-cli = { git = "https://github.com/chainpool/substrate" }
substrate-client = { git = "https://github.com/chainpool/substrate" }
substrate-primitives = { git = "https://github.com/chainpool/substrate" }
substrate-basic-authorship = { git = "https://github.com/chainpool/substrate" }
cli = { package = "substrate-cli", git = "https://github.com/chainpool/substrate" }
client = { package = "substrate-client", git = "https://github.com/chainpool/substrate" }
basic-authorship = { package = "substrate-basic-authorship", git = "https://github.com/chainpool/substrate" }
transaction-pool = { package = "substrate-transaction-pool", git = "https://github.com/chainpool/substrate" }
network = { package = "substrate-network", git = "https://github.com/chainpool/substrate" }
consensus = { package = "substrate-consensus-aura", git = "https://github.com/chainpool/substrate" }
grandpa = { package = "substrate-finality-grandpa", git = "https://github.com/chainpool/substrate" }
inherents = { package = "substrate-inherents", git = "https://github.com/chainpool/substrate" }
telemetry = { package = "substrate-telemetry", git = "https://github.com/chainpool/substrate" }
substrate-service = { git = "https://github.com/chainpool/substrate" }
substrate-transaction-pool = { git = "https://github.com/chainpool/substrate" }
substrate-network = { git = "https://github.com/chainpool/substrate" }
substrate-consensus-aura = { git = "https://github.com/chainpool/substrate" }
substrate-finality-grandpa = { git = "https://github.com/chainpool/substrate" }
substrate-inherents = { git = "https://github.com/chainpool/substrate" }
substrate-telemetry = { git = "https://github.com/chainpool/substrate" }
sr-io = { git = "https://github.com/chainpool/substrate" }
sr-primitives = { git = "https://github.com/chainpool/substrate" }
substrate-primitives = { git = "https://github.com/chainpool/substrate" }
sr-primitives = { package = "sr-primitives", git = "https://github.com/chainpool/substrate" }

chainx-runtime = { path = "../runtime" }
# chainx
rpc-servers = { package = "substrate-rpc-servers", path = "../rpc-servers" }
chainx-primitives = { path = "../primitives" }

chainx-executor = { path = "../executor" }

xrml-xsystem = { path = "../xrml/xsystem" }

chainx-runtime = { path = "../runtime" }
runtime-api = { path = "../runtime-api" }
xsystem = { package = "xrml-xsystem", path = "../xrml/xsystem" }

# bitcoin
primitives = { git = "https://github.com/chainx-org/bitcoin-rust" }
chain = { git = "https://github.com/chainx-org/bitcoin-rust" }
substrate-rpc-servers = { path = "../rpc-servers" }
btc-primitives = { package = "primitives", git = "https://github.com/chainx-org/bitcoin-rust" }
btc-chain = { package = "chain", git = "https://github.com/chainx-org/bitcoin-rust" }

[dev-dependencies]
substrate-service-test = { git = "https://github.com/chainpool/substrate" }
service-test = { package = "substrate-service-test", git = "https://github.com/chainpool/substrate" }

[features]
msgbus-redis = [
"substrate-cli/msgbus-redis"
"cli/msgbus-redis"
]
msgbus-redis-keyhash = [
"msgbus-redis",
"substrate-cli/msgbus-redis-keyhash",
"cli/msgbus-redis-keyhash",
]
cache-lru = [
"substrate-cli/cache-lru"
"cli/cache-lru"
]
7 changes: 4 additions & 3 deletions cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright 2019 Chainpool

use telemetry::TelemetryEndpoints;

use chainx_runtime::GenesisConfig;
use genesis_config::{testnet_genesis, GenesisSpec};
use substrate_service;
use substrate_telemetry::TelemetryEndpoints;

use super::genesis_config::{testnet_genesis, GenesisSpec};

const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
const CHAINX_TELEMETRY_URL: &str = "wss://stats.chainx.org/submit/";
Expand Down
Binary file modified cli/src/chainx_runtime_wasm.compact.wasm
Binary file not shown.
29 changes: 0 additions & 29 deletions cli/src/error.rs

This file was deleted.

7 changes: 3 additions & 4 deletions cli/src/genesis_config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright 2018 chainpool

use std::error::Error;

use hex_literal::{hex, hex_impl};
use rustc_hex::FromHex;
use serde_derive::Deserialize;

use primitives::{ed25519, Ed25519AuthorityId};
use substrate_primitives::{ed25519, Ed25519AuthorityId};

use chainx_runtime::{
xassets::{self, Asset, Chain, ChainT},
Expand Down Expand Up @@ -317,7 +316,7 @@ pub struct RecordOfSDOT {
quantity: f64,
}

fn load_sdot_info() -> Result<Vec<([u8; 20], u64)>, Box<dyn Error>> {
fn load_sdot_info() -> Result<Vec<([u8; 20], u64)>, Box<dyn std::error::Error>> {
let mut reader = csv::Reader::from_reader(&include_bytes!("dot_tx.csv")[..]);
let mut res = Vec::with_capacity(3053);
for result in reader.deserialize() {
Expand Down
45 changes: 7 additions & 38 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,22 @@
#![feature(custom_attribute)]

extern crate tokio;

extern crate chainx_runtime;
extern crate exit_future;
extern crate hex_literal;
extern crate substrate_cli as cli;
extern crate substrate_primitives as primitives;
#[cfg(test)]
extern crate substrate_service_test as service_test;
extern crate substrate_transaction_pool as transaction_pool;
#[macro_use]
extern crate substrate_network as network;
extern crate chainx_primitives;
extern crate substrate_client as client;
extern crate substrate_consensus_aura as consensus;
extern crate substrate_finality_grandpa as grandpa;
#[macro_use]
extern crate substrate_service;
extern crate chainx_executor;
extern crate substrate_inherents as inherents;
extern crate substrate_rpc_servers as rpc;
extern crate substrate_telemetry;

#[macro_use]
extern crate log;
extern crate rustc_hex;
extern crate structopt;
#[macro_use]
extern crate serde_derive;

extern crate chain as btc_chain;
extern crate primitives as btc_primitives;

mod chain_spec;
mod genesis_config;
mod native_rpc;
mod params;
mod service;

pub use cli::{error, IntoExit, NoCustom, VersionInfo};
//use primitives::ed25519;
use std::ops::Deref;
use substrate_service::{Roles as ServiceRoles, ServiceFactory};

use log::info;
use tokio::runtime::Runtime;

use params::ChainXParams;
use service::set_validator_name;
pub use cli::{error, IntoExit, NoCustom, VersionInfo};
use substrate_service::{Roles as ServiceRoles, ServiceFactory};

use self::params::ChainXParams;
use self::service::set_validator_name;

/// The chain specification option.
#[derive(Clone, Debug)]
Expand Down
8 changes: 6 additions & 2 deletions cli/src/native_rpc.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Copyright 2018 Chainpool

use rpc;
use service;
use std::io;
use std::net::SocketAddr;

use log::warn;

use rpc_servers as rpc;
use substrate_service::{ComponentBlock, ComponentExHash, TaskExecutor};

use super::service;

fn maybe_start_server<T, F>(address: Option<SocketAddr>, start: F) -> Result<Option<T>, io::Error>
where
F: Fn(&SocketAddr) -> Result<T, io::Error>,
Expand Down
3 changes: 1 addition & 2 deletions cli/src/params.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use cli::AugmentClap;
use structopt::{clap::App, StructOpt};

#[derive(Clone, StructOpt, Debug)]
Expand All @@ -11,7 +10,7 @@ pub struct ChainXParams {
pub only_grandpa: bool,
}

impl AugmentClap for ChainXParams {
impl cli::AugmentClap for ChainXParams {
fn augment_clap<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
ChainXParams::augment_clap(app)
}
Expand Down
36 changes: 16 additions & 20 deletions cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,28 @@

//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
extern crate runtime_api;
extern crate sr_primitives;
extern crate xrml_xsystem;
use std::sync::Arc;
use std::time::Duration;

use log::{info, warn};

use chainx_executor;
use chainx_primitives::{AccountId, Block};
use chainx_runtime::{GenesisConfig, RuntimeApi};
use client;
use consensus::{import_queue, start_aura, AuraImportQueue, NothingExtra, SlotDuration};
use grandpa;
use inherents::InherentDataProviders;
use primitives::ed25519::Pair;
use std::sync::Arc;
use std::time::Duration;
use network::construct_simple_protocol;
use sr_primitives::generic::BlockId;
use sr_primitives::traits::ProvideRuntimeApi;
use substrate_primitives::ed25519::Pair;
use substrate_service::{
FactoryFullConfiguration, FullBackend, FullClient, FullComponents, FullExecutor, LightBackend,
LightClient, LightComponents, LightExecutor, TaskExecutor,
construct_service_factory, FactoryFullConfiguration, FullBackend, FullClient, FullComponents,
FullExecutor, LightBackend, LightClient, LightComponents, LightExecutor, TaskExecutor,
};
use transaction_pool::{self, txpool::Pool as TransactionPool};
use transaction_pool::txpool::Pool as TransactionPool;

use self::runtime_api::xsession_api::XSessionApi;
use self::sr_primitives::generic::BlockId;
use self::sr_primitives::traits::ProvideRuntimeApi;
use self::xrml_xsystem::InherentDataProvider;
use chainx_primitives::{AccountId, Block};
use chainx_runtime::{GenesisConfig, RuntimeApi};
use runtime_api::xsession_api::XSessionApi;

type XSystemInherentDataProvider = InherentDataProvider;
type XSystemInherentDataProvider = xsystem::InherentDataProvider;

static mut VALIDATOR_NAME: Option<String> = None;

Expand Down Expand Up @@ -110,7 +106,7 @@ construct_service_factory! {

if !service.config.custom.only_grandpa {
if let Some(ref key) = local_key {
let proposer = Arc::new(substrate_basic_authorship::ProposerFactory {
let proposer = Arc::new(basic_authorship::ProposerFactory {
client: service.client(),
transaction_pool: service.transaction_pool(),
});
Expand Down
4 changes: 3 additions & 1 deletion rpc-servers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Substrate RPC servers.
#[warn(missing_docs)]
#![warn(missing_docs)]

pub use substrate_rpc as apis;

Expand All @@ -35,7 +35,9 @@ const MAX_PAYLOAD: usize = 15 * 1024 * 1024;

type Metadata = apis::metadata::Metadata;
type RpcHandler = pubsub::PubSubHandler<Metadata>;
/// HTTP RPC Server.
pub type HttpServer = http::Server;
/// WebSocket RPC Server.
pub type WsServer = ws::Server;

/// Construct rpc `IoHandler`
Expand Down
16 changes: 8 additions & 8 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ parity-codec = { version = "3.1", default_features = false }

client = { package = "substrate-client", git = "https://github.com/chainpool/substrate", default-features = false }
substrate-primitives = { git = "https://github.com/chainpool/substrate", default-features = false }
consensus_aura = { package = "substrate-consensus-aura-primitives", git = "https://github.com/chainpool/substrate", default-features = false }
consensus-aura = { package = "substrate-consensus-aura-primitives", git = "https://github.com/chainpool/substrate", default-features = false }

runtime_primitives = { package = "sr-primitives", git = "https://github.com/chainpool/substrate", default-features = false }
runtime_io = { package = "sr-io", git = "https://github.com/chainpool/substrate", default-features = false }
runtime-primitives = { package = "sr-primitives", git = "https://github.com/chainpool/substrate", default-features = false }
runtime-io = { package = "sr-io", git = "https://github.com/chainpool/substrate", default-features = false }
version = { package = "sr-version", git = "https://github.com/chainpool/substrate", default-features = false }
rstd = { package = "sr-std", git = "https://github.com/chainpool/substrate", default-features = false }

Expand Down Expand Up @@ -46,7 +46,7 @@ xsession = { package = "xrml-session", path = "../xrml/xsession", default-featur
xaura = { package = "xrml-aura", path = "../xrml/xaura", default-features = false }
xgrandpa = { package = "xrml-grandpa", path = "../xrml/xgrandpa", default-features = false }
# fee
xfee_manager = { package = "xrml-fee-manager", path = "../xrml/xfee/manager", default-features = false }
xfee-manager = { package = "xrml-fee-manager", path = "../xrml/xfee/manager", default-features = false }
# assets
xassets = { package = "xrml-xassets-assets", path = "../xrml/xassets/assets", default-features = false }
xrecords = { package = "xrml-xassets-records", path = "../xrml/xassets/records", default-features = false }
Expand All @@ -72,11 +72,11 @@ std = [

"client/std",
"substrate-primitives/std",
"runtime_io/std",
"consensus_aura/std",
"runtime-io/std",
"consensus-aura/std",

# substrate runtime module
"runtime_primitives/std",
"runtime-primitives/std",
"version/std",
"rstd/std",

Expand Down Expand Up @@ -106,7 +106,7 @@ std = [
"xsystem/std",
"xaccounts/std",
# fee
"xfee_manager/std",
"xfee-manager/std",
# asset
"xassets/std",
"xrecords/std",
Expand Down
Binary file not shown.

0 comments on commit d5c51ec

Please sign in to comment.