From 065a2a45d67f7b098dd024c6b99dc50207a04a8c Mon Sep 17 00:00:00 2001 From: Torkel Rogstad Date: Mon, 4 Feb 2019 17:05:40 +0100 Subject: [PATCH] Get Eclair data dir from config in EclairAuthCredentials (#326) * Get Eclair data dir from config in EclairAuthCredentials * Removes faulty datadir opt * Include datadir in EclairInstance.fromDatadir --- .../rpc/config/EclairAuthCredentials.scala | 28 +++++++++++--- .../eclair/rpc/config/EclairInstance.scala | 37 ++++++++++++------- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/config/EclairAuthCredentials.scala b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/config/EclairAuthCredentials.scala index 717c957b95..0f4b402338 100644 --- a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/config/EclairAuthCredentials.scala +++ b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/config/EclairAuthCredentials.scala @@ -42,6 +42,13 @@ sealed trait EclairAuthCredentials { } } +/** + * @define fromConfigDoc + * Parses a [[com.typesafe.config.Config Config]] in the format of this + * [[https://github.com/ACINQ/eclair/blob/master/eclair-core/src/main/resources/reference.conf sample reference.conf]] + * file to a + * [[org.bitcoins.eclair.rpc.config.EclairAuthCredentials EclairAuthCredentials]] + */ object EclairAuthCredentials { private case class AuthCredentialsImpl( password: String, @@ -73,12 +80,20 @@ object EclairAuthCredentials { } /** - * Parses a [[com.typesafe.config.Config Config]] in the format of this - * [[https://github.com/ACINQ/eclair/blob/master/eclair-core/src/main/resources/reference.conf sample reference.conf]] - * file to a - * [[org.bitcoins.eclair.rpc.config.EclairAuthCredentials EclairAuthCredentials]] + * $fromConfigDoc */ - def fromConfig(config: Config): EclairAuthCredentials = { + def fromConfig(config: Config, datadir: File): EclairAuthCredentials = + fromConfig(config, Some(datadir)) + + /** + * $fromConfigDoc + */ + def fromConfig(config: Config): EclairAuthCredentials = + fromConfig(config, None) + + private[config] def fromConfig( + config: Config, + datadir: Option[File]): EclairAuthCredentials = { val bitcoindUsername = config.getString("eclair.bitcoind.rpcuser") val bitcoindPassword = config.getString("eclair.bitcoind.rpcpassword") @@ -101,7 +116,8 @@ object EclairAuthCredentials { EclairAuthCredentials(password = password, bitcoinAuthOpt = Some(bitcoindAuth), - port = eclairRpcPort) + port = eclairRpcPort, + datadir = datadir) } private def getDefaultBitcoindRpcPort(config: Config): Int = { diff --git a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/config/EclairInstance.scala b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/config/EclairInstance.scala index e63b0e368e..1cb5f6c812 100644 --- a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/config/EclairInstance.scala +++ b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/config/EclairInstance.scala @@ -17,6 +17,13 @@ sealed trait EclairInstance { def authCredentials: EclairAuthCredentials } +/** + * @define fromConfigDoc + * Parses a [[com.typesafe.config.Config Config]] in the format of this + * [[https://github.com/ACINQ/eclair/blob/master/eclair-core/src/main/resources/reference.conf sample reference.conf]] + * file to a + * [[org.bitcoins.eclair.rpc.config.EclairInstance EclairInstance]] + */ object EclairInstance { private case class EclairInstanceImpl( network: NetworkParameters, @@ -53,24 +60,26 @@ object EclairInstance { val config = ConfigFactory.parseFile(file) - val configWithDatadir = - if (config.hasPath("eclair.datadir")) { - config - } else { - config.withValue("eclair.datadir", - ConfigValueFactory.fromAnyRef(file.getParent)) - } - - fromConfig(configWithDatadir) + fromConfig(config, file.getParentFile) } /** - * Parses a [[com.typesafe.config.Config Config]] in the format of this - * [[https://github.com/ACINQ/eclair/blob/master/eclair-core/src/main/resources/reference.conf sample reference.conf]] - * file to a - * [[org.bitcoins.eclair.rpc.config.EclairInstance EclairInstance]] + * $fromConfigDoc + */ + def fromConfig(config: Config, datadir: File): EclairInstance = { + fromConfig(config, Some(datadir)) + } + + /** + * $fromConfigDoc */ def fromConfig(config: Config): EclairInstance = { + fromConfig(config, None) + } + + private def fromConfig( + config: Config, + datadir: Option[File]): EclairInstance = { val chain = ConfigUtil.getStringOrElse(config, "eclair.chain", "testnet") // default conf: https://github.com/ACINQ/eclair/blob/master/eclair-core/src/main/resources/reference.conf @@ -102,7 +111,7 @@ object EclairInstance { val rpcUri: URI = new URI(s"http://$rpcHost:$rpcPort") - val eclairAuth = EclairAuthCredentials.fromConfig(config) + val eclairAuth = EclairAuthCredentials.fromConfig(config, datadir) val instance = EclairInstance(network = np, uri = uri,