mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-08 14:31:53 +02:00
config: allow independent rpccookie config
The bitcoind .cookie contains an autogenerated user (__cookie__) and password (random string), which can be used instead of the rpc user name and password. This commit allows for running against bitcoind without having to access bitcoin.conf like in the case for pure user/password/zmq configuration.
This commit is contained in:
61
config.go
61
config.go
@ -1794,6 +1794,47 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{},
|
||||
}
|
||||
}
|
||||
|
||||
// Get the daemon name for displaying proper errors.
|
||||
switch net {
|
||||
case chainreg.BitcoinChain:
|
||||
daemonName = "bitcoind"
|
||||
confDir = conf.Dir
|
||||
confFile = conf.ConfigPath
|
||||
confFileBase = "bitcoin"
|
||||
case chainreg.LitecoinChain:
|
||||
daemonName = "litecoind"
|
||||
confDir = conf.Dir
|
||||
confFile = conf.ConfigPath
|
||||
confFileBase = "litecoin"
|
||||
}
|
||||
|
||||
// Check that cookie and credentials don't contradict each
|
||||
// other.
|
||||
if (conf.RPCUser != "" || conf.RPCPass != "") &&
|
||||
conf.RPCCookie != "" {
|
||||
|
||||
return fmt.Errorf("please only provide either "+
|
||||
"%[1]v.rpccookie or %[1]v.rpcuser and "+
|
||||
"%[1]v.rpcpass", daemonName)
|
||||
}
|
||||
|
||||
// We convert the cookie into a user name and password.
|
||||
if conf.RPCCookie != "" {
|
||||
cookie, err := ioutil.ReadFile(conf.RPCCookie)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot read cookie file: %w",
|
||||
err)
|
||||
}
|
||||
|
||||
splitCookie := strings.Split(string(cookie), ":")
|
||||
if len(splitCookie) != 2 {
|
||||
return fmt.Errorf("cookie file has a wrong " +
|
||||
"format")
|
||||
}
|
||||
conf.RPCUser = splitCookie[0]
|
||||
conf.RPCPass = splitCookie[1]
|
||||
}
|
||||
|
||||
if conf.RPCUser != "" && conf.RPCPass != "" {
|
||||
// If all of RPCUser, RPCPass, ZMQBlockHost, and
|
||||
// ZMQTxHost are set, we assume those parameters are
|
||||
@ -1809,28 +1850,14 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{},
|
||||
}
|
||||
}
|
||||
|
||||
// Get the daemon name for displaying proper errors.
|
||||
switch net {
|
||||
case chainreg.BitcoinChain:
|
||||
daemonName = "bitcoind"
|
||||
confDir = conf.Dir
|
||||
confFile = conf.ConfigPath
|
||||
confFileBase = "bitcoin"
|
||||
case chainreg.LitecoinChain:
|
||||
daemonName = "litecoind"
|
||||
confDir = conf.Dir
|
||||
confFile = conf.ConfigPath
|
||||
confFileBase = "litecoin"
|
||||
}
|
||||
|
||||
// If not all of the parameters are set, we'll assume the user
|
||||
// did this unintentionally.
|
||||
if conf.RPCUser != "" || conf.RPCPass != "" ||
|
||||
conf.ZMQPubRawBlock != "" || conf.ZMQPubRawTx != "" {
|
||||
|
||||
return fmt.Errorf("please set all or none of "+
|
||||
"%[1]v.rpcuser, %[1]v.rpcpass, "+
|
||||
"%[1]v.zmqpubrawblock, %[1]v.zmqpubrawtx",
|
||||
return fmt.Errorf("please set %[1]v.rpcuser and "+
|
||||
"%[1]v.rpcpass (or %[1]v.rpccookie) together "+
|
||||
"with %[1]v.zmqpubrawblock, %[1]v.zmqpubrawtx",
|
||||
daemonName)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user