mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-03 10:46:42 +01:00
Remove AppConfig.initialize() in favor of AppConfig.start() (#1907)
* Remove AppConfig.initialize() in favor of AppConfig.start() * Fix docs
This commit is contained in:
parent
23685f124e
commit
3ab280a12b
15 changed files with 23 additions and 41 deletions
|
@ -32,9 +32,7 @@ case class BitcoinSAppConfig(
|
|||
|
||||
/** Initializes the wallet, node and chain projects */
|
||||
override def start(): Future[Unit] = {
|
||||
val futures = List(walletConf.initialize(),
|
||||
nodeConf.initialize(),
|
||||
chainConf.initialize())
|
||||
val futures = List(walletConf.start(), nodeConf.start(), chainConf.start())
|
||||
|
||||
Future.sequence(futures).map(_ => ())
|
||||
}
|
||||
|
|
|
@ -27,13 +27,13 @@ class ChainAppConfigTest extends ChainUnitTest {
|
|||
withChainFixture(test)
|
||||
|
||||
it must "initialize our chain project" in { _ =>
|
||||
val isInitF = chainAppConfig.isInitialized()
|
||||
val isInitF = chainAppConfig.isStarted()
|
||||
|
||||
for {
|
||||
isInit <- isInitF
|
||||
_ = assert(!isInit)
|
||||
_ <- chainAppConfig.initialize()
|
||||
isInitAgain <- chainAppConfig.isInitialized()
|
||||
_ <- chainAppConfig.start()
|
||||
isInitAgain <- chainAppConfig.isStarted()
|
||||
} yield assert(isInitAgain)
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ case class ChainAppConfig(
|
|||
* trying to read the genesis block header from our block
|
||||
* header table
|
||||
*/
|
||||
def isInitialized()(implicit ec: ExecutionContext): Future[Boolean] = {
|
||||
def isStarted(): Future[Boolean] = {
|
||||
val bhDAO = BlockHeaderDAO()(ec, appConfig)
|
||||
val isDefinedOptF = {
|
||||
bhDAO.read(chain.genesisBlock.blockHeader.hashBE).map(_.isDefined)
|
||||
|
@ -58,12 +58,12 @@ case class ChainAppConfig(
|
|||
* This creates the necessary tables for the chain project
|
||||
* and inserts preliminary data like the genesis block header
|
||||
*/
|
||||
override def initialize()(implicit ec: ExecutionContext): Future[Unit] = {
|
||||
override def start(): Future[Unit] = {
|
||||
val numMigrations = migrate()
|
||||
|
||||
logger.info(s"Applied ${numMigrations} to chain project")
|
||||
|
||||
val isInitF = isInitialized()
|
||||
val isInitF = isStarted()
|
||||
isInitF.flatMap { isInit =>
|
||||
if (isInit) {
|
||||
FutureUtil.unit
|
||||
|
@ -101,9 +101,6 @@ case class ChainAppConfig(
|
|||
lazy val forceRecalcChainWork: Boolean =
|
||||
config.getBooleanOrElse(s"$moduleName.force-recalc-chainwork",
|
||||
default = false)
|
||||
|
||||
/** Starts the associated application */
|
||||
override def start(): Future[Unit] = FutureUtil.unit
|
||||
}
|
||||
|
||||
object ChainAppConfig extends AppConfigFactory[ChainAppConfig] {
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.bitcoins.core.util.{BitcoinSLogger, StartStopAsync}
|
|||
import slick.basic.DatabaseConfig
|
||||
import slick.jdbc.JdbcProfile
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.concurrent.{Future}
|
||||
import scala.util.matching.Regex
|
||||
import scala.util.{Failure, Properties, Success, Try}
|
||||
|
||||
|
@ -26,17 +26,14 @@ abstract class AppConfig extends LoggerConfig with StartStopAsync[Unit] {
|
|||
private val logger = BitcoinSLogger.logger
|
||||
|
||||
/**
|
||||
* Initializes this project.
|
||||
* Starts this project.
|
||||
* After this future resolves, all operations should be
|
||||
* able to be performed correctly.
|
||||
*
|
||||
* Initializing may include creating database tables,
|
||||
* making directories or files needed latern or
|
||||
* Starting may include creating database tables,
|
||||
* making directories or files needed later or
|
||||
* something else entirely.
|
||||
*/
|
||||
def initialize()(implicit ec: ExecutionContext): Future[Unit]
|
||||
|
||||
/** Starts the associated application */
|
||||
override def start(): Future[Unit]
|
||||
|
||||
/** Releases the thread pool associated with this AppConfig's DB */
|
||||
|
|
|
@ -63,7 +63,7 @@ val config = ConfigFactory.parseString {
|
|||
implicit val chainConfig = ChainAppConfig(datadir, config)
|
||||
|
||||
// Initialize the needed database tables if they don't exist:
|
||||
val chainProjectInitF = chainConfig.initialize()
|
||||
val chainProjectInitF = chainConfig.start()
|
||||
val blockHeaderDAO = BlockHeaderDAO()
|
||||
val compactFilterHeaderDAO = CompactFilterHeaderDAO()
|
||||
val compactFilterDAO = CompactFilterDAO()
|
||||
|
|
|
@ -91,7 +91,7 @@ implicit val appConfig = BitcoinSAppConfig(datadir, config)
|
|||
implicit val chainConfig = appConfig.chainConf
|
||||
implicit val nodeConfig = appConfig.nodeConf
|
||||
|
||||
val initNodeF = nodeConfig.initialize()
|
||||
val initNodeF = nodeConfig.start()
|
||||
|
||||
//the node requires a chainHandler to store block information
|
||||
//use a helper method in our testkit to create the chain project
|
||||
|
|
|
@ -97,8 +97,8 @@ implicit val chainConfig = ChainAppConfig(datadir, config)
|
|||
// databases for managing both chain state
|
||||
// and wallet state
|
||||
val configF: Future[Unit] = for {
|
||||
_ <- walletConfig.initialize()
|
||||
_ <- chainConfig.initialize()
|
||||
_ <- walletConfig.start()
|
||||
_ <- chainConfig.start()
|
||||
} yield ()
|
||||
|
||||
val bitcoindInstance = BitcoindInstance.fromDatadir()
|
||||
|
|
|
@ -114,7 +114,6 @@ trait Node extends NodeApi with ChainQueryApi with P2PLogger {
|
|||
val start = System.currentTimeMillis()
|
||||
|
||||
for {
|
||||
_ <- nodeAppConfig.initialize()
|
||||
_ <- nodeAppConfig.start()
|
||||
// get chainApi so we don't need to call chainApiFromDb on every call
|
||||
chainApi <- chainApiFromDb
|
||||
|
|
|
@ -47,7 +47,7 @@ case class NodeAppConfig(
|
|||
* Ensures correct tables and other required information is in
|
||||
* place for our node.
|
||||
*/
|
||||
override def initialize()(implicit ec: ExecutionContext): Future[Unit] = {
|
||||
override def start(): Future[Unit] = {
|
||||
logger.debug(s"Initializing node setup")
|
||||
val numMigrations = migrate()
|
||||
|
||||
|
@ -70,9 +70,6 @@ case class NodeAppConfig(
|
|||
strs.map(_.replace("localhost", "127.0.0.1"))
|
||||
}
|
||||
|
||||
/** Starts the associated application */
|
||||
override def start(): Future[Unit] = FutureUtil.unit
|
||||
|
||||
/** Creates either a neutrino node or a spv node based on the [[NodeAppConfig]] given */
|
||||
def createNode(peer: Peer)(
|
||||
chainConf: ChainAppConfig,
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.nio.file.{Files, Path}
|
|||
|
||||
import akka.actor.ActorSystem
|
||||
import com.typesafe.config.Config
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.db._
|
||||
import scodec.bits.ByteVector
|
||||
import slick.lifted.ProvenShape
|
||||
|
@ -59,7 +58,7 @@ case class TestAppConfig(
|
|||
|
||||
override def appConfig: TestAppConfig = this
|
||||
|
||||
override def initialize()(implicit ec: ExecutionContext): Future[Unit] = {
|
||||
override def start(): Future[Unit] = {
|
||||
logger.debug(s"Initializing test setup")
|
||||
|
||||
if (Files.notExists(datadir)) {
|
||||
|
@ -68,9 +67,6 @@ case class TestAppConfig(
|
|||
|
||||
createTable(TestDAO()(ec, this).table)
|
||||
}
|
||||
|
||||
/** Starts the associated application */
|
||||
override def start(): Future[Unit] = FutureUtil.unit
|
||||
}
|
||||
|
||||
case class TestDb(pk: String, data: ByteVector)
|
||||
|
|
|
@ -35,7 +35,7 @@ sealed trait TestDAOFixture
|
|||
|
||||
def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
makeFixture(
|
||||
build = () => testConfig.initialize().map(_ => TestDAO()),
|
||||
build = () => testConfig.start().map(_ => TestDAO()),
|
||||
destroy = () => dropAll()
|
||||
)(test)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ trait NodeDAOFixture extends NodeUnitTest {
|
|||
def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||
makeFixture(build = () => {
|
||||
nodeConfig
|
||||
.initialize()
|
||||
.start()
|
||||
.map(_ => daos)
|
||||
},
|
||||
destroy = () => destroyAppConfig(nodeConfig))(test)
|
||||
|
|
|
@ -296,7 +296,7 @@ trait BitcoinSWalletTest
|
|||
def withWalletConfig(test: OneArgAsyncTest): FutureOutcome = {
|
||||
val builder: () => Future[WalletAppConfig] = () => {
|
||||
val walletConf = config.walletConf
|
||||
walletConf.initialize().map(_ => walletConf)
|
||||
walletConf.start().map(_ => walletConf)
|
||||
}
|
||||
|
||||
val destroy: WalletAppConfig => Future[Unit] = walletAppConfig => {
|
||||
|
@ -411,7 +411,7 @@ object BitcoinSWalletTest extends WalletLogger {
|
|||
// any user data
|
||||
AppConfig.throwIfDefaultDatadir(walletConfig)
|
||||
|
||||
walletConfig.initialize().flatMap { _ =>
|
||||
walletConfig.start().flatMap { _ =>
|
||||
val wallet =
|
||||
Wallet(keyManager,
|
||||
nodeApi,
|
||||
|
|
|
@ -655,7 +655,7 @@ object Wallet extends WalletLogger {
|
|||
// and still have their wallet work
|
||||
def createAccountFutures =
|
||||
for {
|
||||
_ <- walletAppConfig.initialize()
|
||||
_ <- walletAppConfig.start()
|
||||
accounts = HDPurposes.all.map { purpose =>
|
||||
//we need to create key manager params for each purpose
|
||||
//and then initialize a key manager to derive the correct xpub
|
||||
|
|
|
@ -94,7 +94,7 @@ case class WalletAppConfig(
|
|||
requiredConfirmations >= 1,
|
||||
s"requiredConfirmations cannot be less than 1, got: $requiredConfirmations")
|
||||
|
||||
override def initialize()(implicit ec: ExecutionContext): Future[Unit] = {
|
||||
override def start(): Future[Unit] = {
|
||||
logger.debug(s"Initializing wallet setup")
|
||||
|
||||
if (Files.notExists(datadir)) {
|
||||
|
@ -181,8 +181,6 @@ case class WalletAppConfig(
|
|||
bip39PasswordOpt = bip39PasswordOpt)(this, ec)
|
||||
}
|
||||
|
||||
/** Starts the associated application */
|
||||
override def start(): Future[Unit] = FutureUtil.unit
|
||||
}
|
||||
|
||||
object WalletAppConfig
|
||||
|
|
Loading…
Add table
Reference in a new issue