Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make path into an option
  • Loading branch information
gnunicorn committed Nov 1, 2019
commit 0113741827eb3cb30ec20ee15fdb19f1c76ec0ba
19 changes: 11 additions & 8 deletions core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,11 @@ impl<'a> ParseAndPrepareBuildSpec<'a> {

if spec.boot_nodes().is_empty() && !self.params.disable_default_bootnode {
let base_path = base_path(&self.params.shared_params, self.version);
let config = service::Configuration::<C,_,_>::default_with_spec_and_base_path(spec.clone(), base_path);
let node_key = node_key_config(self.params.node_key_params, &Some(config.network_path()))?;
let cfg = service::Configuration::<C,_,_>::default_with_spec_and_base_path(spec.clone(), Some(base_path));
let node_key = node_key_config(
self.params.node_key_params,
&Some(cfg.network_path().expect("We provided a base_path"))
)?;
let keys = node_key.into_keypair()?;
let peer_id = keys.public().into_peer_id();
let addr = build_multiaddr![
Expand Down Expand Up @@ -655,7 +658,7 @@ where
{
let spec = load_spec(&cli.shared_params, spec_factory)?;
let base_path = base_path(&cli.shared_params, &version);
let mut config = service::Configuration::default_with_spec_and_base_path(spec.clone(), base_path);
let mut config = service::Configuration::default_with_spec_and_base_path(spec.clone(), Some(base_path));

fill_config_keystore_password(&mut config, &cli)?;

Expand All @@ -679,10 +682,10 @@ where
)?
}

config.keystore_path = cli.keystore_path.unwrap_or_else(|| config.in_chain_config_dir("keystore"));
config.keystore_path = cli.keystore_path.or_else(|| config.in_chain_config_dir("keystore"));

config.database = DatabaseConfig::Path {
path: config.database_path(),
path: config.database_path().expect("We provided a base_path."),
cache_size: cli.database_cache_size,
};
config.state_cache_size = cli.state_cache_size;
Expand Down Expand Up @@ -749,7 +752,7 @@ where
let client_id = config.client_id();
fill_network_configuration(
cli.network_config,
config.network_path(),
config.network_path().expect("We provided a basepath"),
&mut config.network,
client_id,
is_dev,
Expand Down Expand Up @@ -813,9 +816,9 @@ where
let spec = load_spec(cli, spec_factory)?;
let base_path = base_path(cli, version);

let mut config = service::Configuration::default_with_spec_and_base_path(spec.clone(), base_path);
let mut config = service::Configuration::default_with_spec_and_base_path(spec.clone(), Some(base_path));
config.database = DatabaseConfig::Path {
path: config.database_path(),
path: config.database_path().expect("We provided a base_path."),
cache_size: None,
};

Expand Down
10 changes: 8 additions & 2 deletions core/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ where TGen: RuntimeGenesis, TCSExt: Extension {
(),
TFullBackend<TBl>,
>, Error> {
let keystore = Keystore::open(config.keystore_path.clone(), config.keystore_password.clone())?;
let keystore = Keystore::open(
config.keystore_path.clone().ok_or("No basepath configured")?,
config.keystore_password.clone()
)?;

let executor = NativeExecutor::<TExecDisp>::new(
config.wasm_method,
Expand Down Expand Up @@ -236,7 +239,10 @@ where TGen: RuntimeGenesis, TCSExt: Extension {
(),
TLightBackend<TBl>,
>, Error> {
let keystore = Keystore::open(config.keystore_path.clone(), config.keystore_password.clone())?;
let keystore = Keystore::open(
config.keystore_path.clone().ok_or("No basepath configured")?,
config.keystore_password.clone()
)?;

let executor = NativeExecutor::<TExecDisp>::new(
config.wasm_method,
Expand Down
28 changes: 15 additions & 13 deletions core/service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ pub struct Configuration<C, G, E = NoExtension> {
/// Network configuration.
pub network: NetworkConfiguration,
/// Path to the base configuration directory.
pub config_dir: PathBuf,
pub config_dir: Option<PathBuf>,
/// Path to key files.
pub keystore_path: PathBuf,
pub keystore_path: Option<PathBuf>,
/// Configuration for the database.
pub database: DatabaseConfig,
/// Size of internal state cache in Bytes
Expand Down Expand Up @@ -121,18 +121,18 @@ impl<C, G, E> Configuration<C, G, E> where
E: Extension,
{
/// Create a default config for given chain spec and path to configuration dir
pub fn default_with_spec_and_base_path(chain_spec: ChainSpec<G, E>, config_dir: PathBuf) -> Self {
pub fn default_with_spec_and_base_path(chain_spec: ChainSpec<G, E>, config_dir: Option<PathBuf>) -> Self {
let mut configuration = Configuration {
impl_name: "parity-substrate",
impl_version: "0.0.0",
impl_commit: "",
chain_spec,
config_dir,
config_dir: config_dir.clone(),
name: Default::default(),
roles: Roles::FULL,
transaction_pool: Default::default(),
network: Default::default(),
keystore_path: Default::default(),
keystore_path: config_dir.map(|c| c.join("keystore")),
database: DatabaseConfig::Path {
path: Default::default(),
cache_size: Default::default(),
Expand Down Expand Up @@ -178,21 +178,23 @@ impl<C, G, E> Configuration<C, G, E> {
}

/// Generate a PathBuf to sub in the chain configuration directory
pub fn in_chain_config_dir(&self, sub: &str) -> PathBuf {
let mut path = self.config_dir.clone();
path.push("chains");
path.push(self.chain_spec.id());
path.push(sub);
path
/// if given
pub fn in_chain_config_dir(&self, sub: &str) -> Option<PathBuf> {
self.config_dir.clone().map(|mut path| {
path.push("chains");
path.push(self.chain_spec.id());
path.push(sub);
path
})
}

/// The basepath for the db directory
pub fn database_path(&self) -> PathBuf {
pub fn database_path(&self) -> Option<PathBuf> {
self.in_chain_config_dir("db")
}

/// The basepath for the network file
pub fn network_path(&self) -> PathBuf {
pub fn network_path(&self) -> Option<PathBuf> {
self.in_chain_config_dir("network")
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/service/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ fn node_config<G, E: Clone> (
roles: role,
transaction_pool: Default::default(),
network: network_config,
keystore_path: root.join("key"),
keystore_path: Some(root.join("key")),
keystore_password: None,
config_dir: root.clone(),
config_dir: Some(root.clone()),
database: DatabaseConfig::Path {
path: root.join("db"),
cache_size: None
Expand Down
2 changes: 1 addition & 1 deletion node/cli/src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn start_inner(wasm_ext: wasm_ext::ffi::Transport) -> Result<Client, Box<dyn std
let config = {
let wasm_ext = wasm_ext::ExtTransport::new(wasm_ext);
let chain_spec = ChainSpec::FlamingFir.load().map_err(|e| format!("{:?}", e))?;
let mut config = Configuration::<(), _, _>::default_with_spec(chain_spec);
let mut config = Configuration::<(), _, _>::default_with_spec_and_base_path(chain_spec, None);
config.network.transport = network::config::TransportConfig::Normal {
wasm_external_transport: Some(wasm_ext.clone()),
enable_mdns: false,
Expand Down