Move config path generation into the service config for reusability (#3978)

* Move config path generation into the service config for reusability

* Make NoCostum Default and fix tests

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* remove function not used anymore

* Make path into an option

* remove database_path function and call it directly

* remove helper functions, use consts
This commit is contained in:
Benjamin Kampmann
2019-11-01 18:51:06 +01:00
committed by Gavin Wood
parent 8fe64173e8
commit 2ff04d332d
8 changed files with 71 additions and 86 deletions
+8 -2
View File
@@ -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,
@@ -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,
+21 -4
View File
@@ -43,8 +43,10 @@ pub struct Configuration<C, G, E = NoExtension> {
pub transaction_pool: transaction_pool::txpool::Options,
/// Network configuration.
pub network: NetworkConfiguration,
/// Path to the base configuration directory.
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
@@ -118,18 +120,19 @@ impl<C, G, E> Configuration<C, G, E> where
G: RuntimeGenesis,
E: Extension,
{
/// Create default config for given chain spec.
pub fn default_with_spec(chain_spec: ChainSpec<G, E>) -> Self {
/// 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: Option<PathBuf>) -> Self {
let mut configuration = Configuration {
impl_name: "parity-substrate",
impl_version: "0.0.0",
impl_commit: "",
chain_spec,
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(),
@@ -161,6 +164,9 @@ impl<C, G, E> Configuration<C, G, E> where
configuration
}
}
impl<C, G, E> Configuration<C, G, E> {
/// Returns full version string of this configuration.
pub fn full_version(&self) -> String {
full_version_from_strs(self.impl_version, self.impl_commit)
@@ -170,6 +176,17 @@ impl<C, G, E> Configuration<C, G, E> where
pub fn client_id(&self) -> String {
format!("{}/v{}", self.impl_name, self.full_version())
}
/// Generate a PathBuf to sub in the chain configuration directory
/// 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
})
}
}
/// Returns platform info