ソースを参照

chain-spec-builder: Convert the chain-spec-builder crate.

Shamil Gadelshin 4 年 前
コミット
58d6221e77
5 ファイル変更43 行追加50 行削除
  1. 14 0
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 2 1
      node/src/chain_spec.rs
  4. 11 24
      utils/chain-spec-builder/Cargo.toml
  5. 15 24
      utils/chain-spec-builder/src/main.rs

+ 14 - 0
Cargo.lock

@@ -560,6 +560,20 @@ dependencies = [
  "zeroize",
 ]
 
+[[package]]
+name = "chain-spec-builder"
+version = "3.0.0"
+dependencies = [
+ "ansi_term 0.12.1",
+ "joystream-node",
+ "rand 0.7.3",
+ "sc-chain-spec",
+ "sc-keystore",
+ "sc-telemetry",
+ "sp-core",
+ "structopt",
+]
+
 [[package]]
 name = "chrono"
 version = "0.4.11"

+ 1 - 1
Cargo.toml

@@ -20,7 +20,7 @@ members = [
 	"runtime-modules/versioned-store-permissions",
 	"runtime-modules/working-group",
 	"node",
-#	"utils/chain-spec-builder/"
+	"utils/chain-spec-builder/"
 ]
 
 [profile.release]

+ 2 - 1
node/src/chain_spec.rs

@@ -19,7 +19,6 @@
 // Example:  voting_period: 1 * DAY
 #![allow(clippy::identity_op)]
 
-use node_runtime::{AccountId, GenesisConfig};
 use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
 use serde_json as json;
 use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
@@ -38,6 +37,8 @@ use node_runtime::{
     StorageWorkingGroupConfig, SudoConfig, SystemConfig, VersionedStoreConfig, DAYS, WASM_BINARY,
 };
 
+pub use node_runtime::{AccountId, GenesisConfig};
+
 type AccountPublic = <Signature as Verify>::Signer;
 
 /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.

+ 11 - 24
utils/chain-spec-builder/Cargo.toml

@@ -1,30 +1,17 @@
 [package]
-name = "chain-spec-builder"
-version = "2.0.0-alpha.3"
-authors = ["Parity Technologies <admin@parity.io>"]
-edition = "2018"
-build = "build.rs"
-license = "GPL-3.0"
-homepage = "https://substrate.dev"
-repository = "https://github.com/paritytech/substrate/"
+authors = ['Joystream contributors']
+build = 'build.rs'
+edition = '2018'
+name = 'chain-spec-builder'
+version = '3.0.0'
 
 [dependencies]
 ansi_term = "0.12.1"
 rand = "0.7.2"
-structopt = "0.3.5"
-joystream-node = { version = "2.1.2", path = "../../node" }
+structopt = "0.3.8"
+sc-keystore = { git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4' }
+sc-telemetry = { git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4' }
+sc-chain-spec = { git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4' }
+sp-core = { git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4' }
+joystream-node = { path = "../../node" }
 
-[dependencies.sr-keystore]
-git = 'https://github.com/paritytech/substrate.git'
-package = 'substrate-keystore'
-rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
-
-[dependencies.sr-primitives]
-git = 'https://github.com/paritytech/substrate.git'
-package = 'substrate-primitives'
-rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
-
-[dependencies.substrate-telemetry]
-git = 'https://github.com/paritytech/substrate.git'
-package = 'substrate-telemetry'
-rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'

+ 15 - 24
utils/chain-spec-builder/src/main.rs

@@ -24,14 +24,15 @@ use rand::{distributions::Alphanumeric, rngs::OsRng, Rng};
 use structopt::StructOpt;
 
 use joystream_node::chain_spec::{self, chain_spec_properties, AccountId};
-use sr_keystore::Store as Keystore;
-use sr_primitives::{
+use sc_chain_spec::ChainType;
+use sc_keystore::Store as Keystore;
+use sc_telemetry::TelemetryEndpoints;
+use sp_core::{
     crypto::{Public, Ss58Codec},
     sr25519,
     traits::BareCryptoStore,
 };
 
-use substrate_telemetry::TelemetryEndpoints;
 const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
 
 /// A utility to easily create a testnet chain spec definition with a given set
@@ -133,26 +134,22 @@ fn generate_chain_spec(
     //     "/dns4/tesnet.joystream.org/tcp/30333/p2p/QmaTTdEF6YVCtynSjsXmGPSGcEesAahoZ8pmcCmmBwSE7S",
     // )];
 
+    let telemetry_endpoints = TelemetryEndpoints::new(vec![(STAGING_TELEMETRY_URL.to_string(), 0)])
+        .map_err(|err| format!("Failed to create telemetry endpoints: {:?}", err))?;
+
     let chain_spec = chain_spec::ChainSpec::from_genesis(
         "Joystream Testnet",
         "joy_testnet",
+        ChainType::Development,
         move || genesis_constructor(&authority_seeds, &endowed_accounts, &sudo_account),
-        // below can be manually modified in chainspec file, they don't affect genesis state
-        // but we set some default values here for convenience.
         vec![],
-        Some(TelemetryEndpoints::new(vec![(
-            STAGING_TELEMETRY_URL.to_string(),
-            0,
-        )])),
-        // protocol_id
+        Some(telemetry_endpoints),
         Some(&*"/joy/testnet/0"),
-        // Properties
         Some(chain_spec_properties()),
-        // Extensions
-        None, // Default::default(),
+        None,
     );
 
-    chain_spec.to_json(false).map_err(|err| err)
+    chain_spec.as_json(false).map_err(|err| err)
 }
 
 fn generate_authority_keys_and_store(seeds: &[String], keystore_path: &Path) -> Result<(), String> {
@@ -160,7 +157,7 @@ fn generate_authority_keys_and_store(seeds: &[String], keystore_path: &Path) ->
         let keystore = Keystore::open(keystore_path.join(format!("auth-{}", n)), None)
             .map_err(|err| err.to_string())?;
 
-        let (_, _, grandpa, babe, im_online) = chain_spec::get_authority_keys_from_seed(seed);
+        let (_, _, grandpa, babe, im_online, _) = chain_spec::get_authority_keys_from_seed(seed);
 
         let insert_key = |key_type, public| {
             keystore
@@ -169,17 +166,11 @@ fn generate_authority_keys_and_store(seeds: &[String], keystore_path: &Path) ->
                 .map_err(|_| format!("Failed to insert key: {}", grandpa))
         };
 
-        insert_key(sr_primitives::crypto::key_types::BABE, babe.as_slice())?;
+        insert_key(sp_core::crypto::key_types::BABE, babe.as_slice())?;
 
-        insert_key(
-            sr_primitives::crypto::key_types::GRANDPA,
-            grandpa.as_slice(),
-        )?;
+        insert_key(sp_core::crypto::key_types::GRANDPA, grandpa.as_slice())?;
 
-        insert_key(
-            sr_primitives::crypto::key_types::IM_ONLINE,
-            im_online.as_slice(),
-        )?;
+        insert_key(sp_core::crypto::key_types::IM_ONLINE, im_online.as_slice())?;
     }
 
     Ok(())