mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-19 18:02:54 +01:00
Fix NPE and log location on server start up (#2163)
This commit is contained in:
parent
de99dfe984
commit
3f066d47e7
@ -1,45 +1,56 @@
|
||||
package org.bitcoins.oracle.server
|
||||
|
||||
import org.bitcoins.crypto.AesPassword
|
||||
import org.bitcoins.dlc.oracle.DLCOracleAppConfig
|
||||
import org.bitcoins.keymanager.bip39.BIP39KeyManager
|
||||
import org.bitcoins.server.{BitcoinSRunner, Server}
|
||||
|
||||
object OracleServerMain extends App with BitcoinSRunner {
|
||||
import scala.concurrent.Future
|
||||
|
||||
class OracleServerMain(override val args: Array[String])
|
||||
extends BitcoinSRunner {
|
||||
|
||||
override val actorSystemName = "bitcoin-s-oracle"
|
||||
|
||||
implicit val conf: DLCOracleAppConfig =
|
||||
DLCOracleAppConfig(datadirPath, baseConfig)
|
||||
override def startup: Future[Unit] = {
|
||||
|
||||
// TODO need to prompt user for these
|
||||
val bip39PasswordOpt: Option[String] = None
|
||||
val aesPassword = BIP39KeyManager.badPassphrase
|
||||
implicit val conf: DLCOracleAppConfig =
|
||||
DLCOracleAppConfig(datadirPath, baseConfig)
|
||||
|
||||
for {
|
||||
_ <- conf.start()
|
||||
oracle <- conf.initialize(aesPassword, bip39PasswordOpt)
|
||||
// TODO need to prompt user for these
|
||||
val bip39PasswordOpt: Option[String] = None
|
||||
val aesPassword: AesPassword = BIP39KeyManager.badPassphrase
|
||||
for {
|
||||
_ <- conf.start()
|
||||
oracle <- conf.initialize(aesPassword, bip39PasswordOpt)
|
||||
|
||||
routes = Seq(OracleRoutes(oracle))
|
||||
server = rpcPortOpt match {
|
||||
case Some(rpcport) =>
|
||||
Server(conf, routes, rpcport = rpcport)
|
||||
case None =>
|
||||
conf.rpcPortOpt match {
|
||||
case Some(rpcport) =>
|
||||
Server(conf, routes, rpcport)
|
||||
case None =>
|
||||
Server(conf, routes)
|
||||
}
|
||||
}
|
||||
routes = Seq(OracleRoutes(oracle))
|
||||
server = rpcPortOpt match {
|
||||
case Some(rpcport) =>
|
||||
Server(conf, routes, rpcport = rpcport)
|
||||
case None =>
|
||||
conf.rpcPortOpt match {
|
||||
case Some(rpcport) =>
|
||||
Server(conf, routes, rpcport)
|
||||
case None =>
|
||||
Server(conf, routes)
|
||||
}
|
||||
}
|
||||
|
||||
_ <- server.start()
|
||||
} yield {
|
||||
logger.info(s"Done starting oracle!")
|
||||
sys.addShutdownHook {
|
||||
logger.error(s"Exiting process")
|
||||
_ <- server.start()
|
||||
} yield {
|
||||
logger.info(s"Done starting oracle!")
|
||||
sys.addShutdownHook {
|
||||
logger.error(s"Exiting process")
|
||||
|
||||
conf.stop().foreach(_ => logger.info(s"Stopped DLC Oracle"))
|
||||
system.terminate().foreach(_ => logger.info(s"Actor system terminated"))
|
||||
conf.stop().foreach(_ => logger.info(s"Stopped DLC Oracle"))
|
||||
system.terminate().foreach(_ => logger.info(s"Actor system terminated"))
|
||||
}
|
||||
()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object OracleServerMain extends App {
|
||||
new OracleServerMain(args).run()
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class ServerRunTest extends BitcoinSAsyncTest {
|
||||
|
||||
// Use Exception because different errors can occur
|
||||
recoverToSucceededIf[Exception] {
|
||||
val runMainF = new BitcoinSServerMain(args).runMain
|
||||
val runMainF = new BitcoinSServerMain(args).startup
|
||||
val deleteDirF = Future {
|
||||
Thread.sleep(2000)
|
||||
directory.deleteRecursively()
|
||||
|
@ -8,7 +8,7 @@ import org.bitcoins.core.config._
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.bitcoins.db.{AppConfig, ConfigOps}
|
||||
|
||||
import scala.concurrent.ExecutionContext
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.util.Properties
|
||||
|
||||
trait BitcoinSRunner extends BitcoinSLogger {
|
||||
@ -87,9 +87,20 @@ trait BitcoinSRunner extends BitcoinSLogger {
|
||||
case RegTest => "regtest"
|
||||
case SigNet => "signet"
|
||||
}
|
||||
val dir = datadirPath.resolve(lastDirname)
|
||||
datadirPath.resolve(lastDirname)
|
||||
}
|
||||
|
||||
System.setProperty("bitcoins.log.location", dir.toAbsolutePath.toString)
|
||||
dir
|
||||
def startup: Future[Unit]
|
||||
|
||||
// start everything!
|
||||
final def run(): Unit = {
|
||||
// Properly set log location
|
||||
System.setProperty("bitcoins.log.location", datadir.toAbsolutePath.toString)
|
||||
|
||||
val runner = startup
|
||||
runner.failed.foreach { err =>
|
||||
logger.error(s"Failed to startup server!", err)
|
||||
sys.exit(1)
|
||||
}(scala.concurrent.ExecutionContext.Implicits.global)
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class BitcoinSServerMain(override val args: Array[String])
|
||||
implicit lazy val conf: BitcoinSAppConfig =
|
||||
BitcoinSAppConfig(datadirPath, baseConfig)
|
||||
|
||||
def runMain: Future[Unit] = {
|
||||
def startup: Future[Unit] = {
|
||||
|
||||
val bip39PasswordOpt = None // todo need to prompt user for this
|
||||
|
||||
@ -177,15 +177,6 @@ class BitcoinSServerMain(override val args: Array[String])
|
||||
startFut
|
||||
}
|
||||
|
||||
//start everything!
|
||||
lazy val run: Unit = {
|
||||
val runner = runMain
|
||||
runner.failed.foreach { err =>
|
||||
logger.error(s"Failed to startup server!", err)
|
||||
sys.exit(1)
|
||||
}(scala.concurrent.ExecutionContext.Implicits.global)
|
||||
}
|
||||
|
||||
private def createCallbacks(wallet: Wallet)(implicit
|
||||
nodeConf: NodeAppConfig,
|
||||
ec: ExecutionContext): Future[NodeCallbacks] = {
|
||||
@ -300,7 +291,7 @@ class BitcoinSServerMain(override val args: Array[String])
|
||||
}
|
||||
|
||||
object BitcoinSServerMain extends App {
|
||||
new BitcoinSServerMain(args).run
|
||||
new BitcoinSServerMain(args).run()
|
||||
}
|
||||
|
||||
object BitcoinSServer {
|
||||
|
Loading…
Reference in New Issue
Block a user