mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-19 18:02:54 +01:00
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
This commit is contained in:
parent
77d0f98f95
commit
065a2a45d6
@ -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 = {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user