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