Implement AppConfigFactory (#1462)

* Implement AppConfigFactory

* Fix docs
This commit is contained in:
Chris Stewart 2020-05-25 14:43:37 -05:00 committed by GitHub
parent 192cd49974
commit d8170f319a
4 changed files with 28 additions and 11 deletions

View File

@ -95,14 +95,14 @@ case class ChainAppConfig(
config.getInt(s"${moduleName}.neutrino.filter-batch-size")
}
object ChainAppConfig {
object ChainAppConfig extends AppConfigFactory[ChainAppConfig] {
/** Constructs a chain verification configuration from the default Bitcoin-S
* data directory and given list of configuration overrides.
*/
def fromDefaultDatadir(useLogbackConf: Boolean, confs: Config*)(
override def fromDatadir(datadir: Path, useLogbackConf: Boolean, confs: Vector[Config])(
implicit ec: ExecutionContext): ChainAppConfig =
ChainAppConfig(AppConfig.DEFAULT_BITCOIN_S_DATADIR,
ChainAppConfig(datadir,
useLogbackConf,
confs: _*)
}

View File

@ -0,0 +1,17 @@
package org.bitcoins.db
import java.nio.file.Path
import com.typesafe.config.Config
import scala.concurrent.ExecutionContext
trait AppConfigFactory[C <: AppConfig] {
def fromDefaultDatadir(useLogbackConf: Boolean, confs: Vector[Config] = Vector.empty)(
implicit ec: ExecutionContext): C = {
fromDatadir(AppConfig.DEFAULT_BITCOIN_S_DATADIR,useLogbackConf,confs)
}
def fromDatadir(datadir: Path, useLogbackConf: Boolean, confs: Vector[Config] = Vector.empty)(implicit ec: ExecutionContext): C
}

View File

@ -4,7 +4,7 @@ import java.nio.file.Path
import com.typesafe.config.Config
import org.bitcoins.core.util.FutureUtil
import org.bitcoins.db.{AppConfig, JdbcProfileComponent}
import org.bitcoins.db.{AppConfig, AppConfigFactory, JdbcProfileComponent}
import org.bitcoins.node.db.NodeDbManagement
import scala.concurrent.{ExecutionContext, Future}
@ -70,14 +70,14 @@ case class NodeAppConfig(
}
}
object NodeAppConfig {
object NodeAppConfig extends AppConfigFactory[NodeAppConfig] {
/** Constructs a node configuration from the default Bitcoin-S
* data directory and given list of configuration overrides.
*/
def fromDefaultDatadir(useLogbackConf: Boolean, confs: Config*)(
override def fromDatadir(datadir: Path, useLogbackConf: Boolean, confs: Vector[Config])(
implicit ec: ExecutionContext): NodeAppConfig =
NodeAppConfig(AppConfig.DEFAULT_BITCOIN_S_DATADIR,
NodeAppConfig(datadir,
useLogbackConf,
confs: _*)

View File

@ -6,7 +6,7 @@ import java.util.concurrent.TimeUnit
import com.typesafe.config.Config
import org.bitcoins.core.hd._
import org.bitcoins.core.util.FutureUtil
import org.bitcoins.db.{AppConfig, JdbcProfileComponent}
import org.bitcoins.db.{AppConfig, AppConfigFactory, JdbcProfileComponent}
import org.bitcoins.keymanager.{KeyManagerParams, WalletStorage}
import org.bitcoins.wallet.db.WalletDbManagement
@ -127,14 +127,14 @@ case class WalletAppConfig(
}
}
object WalletAppConfig {
object WalletAppConfig extends AppConfigFactory[WalletAppConfig] {
/** Constructs a wallet configuration from the default Bitcoin-S
* data directory and given list of configuration overrides.
*/
def fromDefaultDatadir(useLogbackConf: Boolean, confs: Config*)(
override def fromDatadir(datadir: Path, useLogbackConf: Boolean, confs: Vector[Config])(
implicit ec: ExecutionContext): WalletAppConfig =
WalletAppConfig(AppConfig.DEFAULT_BITCOIN_S_DATADIR,
WalletAppConfig(datadir,
useLogbackConf,
confs: _*)
}