config: add an option to pass in a hex-encoded rpc cert (--rawrpccert)
This commit adds an option to pass in a raw hex-encoded rpc cert via lnd’s configuration file. Such a change allows for programmatically creating lnd nodes which can connect to an existing btcd instance without requiring a file for the rpc cert to be specified. Additionally, this commit makes the creation of an integration testing harness easier.
This commit is contained in:
parent
a03126ed83
commit
0085e2a38a
@ -63,6 +63,7 @@ type config struct {
|
|||||||
RPCPass string `short:"P" long:"rpcpass" default-mask:"-" description:"Password for RPC connections"`
|
RPCPass string `short:"P" long:"rpcpass" default-mask:"-" description:"Password for RPC connections"`
|
||||||
|
|
||||||
RPCCert string `long:"rpccert" description:"File containing btcd's certificate file"`
|
RPCCert string `long:"rpccert" description:"File containing btcd's certificate file"`
|
||||||
|
RawRPCCert string `long:"rawrpccert" description:"The raw bytes of btcd's PEM-encoded certificate chain which will be used to authenticate the RPC connection."`
|
||||||
SPVHostAdr string `long:"spvhostadr" description:"Address of full bitcoin node. It is used in SPV mode."`
|
SPVHostAdr string `long:"spvhostadr" description:"Address of full bitcoin node. It is used in SPV mode."`
|
||||||
TestNet3 bool `long:"testnet" description:"Use the test network"`
|
TestNet3 bool `long:"testnet" description:"Use the test network"`
|
||||||
SimNet bool `long:"simnet" description:"Use the simulation test network"`
|
SimNet bool `long:"simnet" description:"Use the simulation test network"`
|
||||||
|
37
lnd.go
37
lnd.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
@ -64,26 +65,44 @@ func lndMain() error {
|
|||||||
}
|
}
|
||||||
defer chanDB.Close()
|
defer chanDB.Close()
|
||||||
|
|
||||||
// Read btcd's rpc cert for lnwallet's convenience.
|
// Next load btcd's TLS cert for the RPC connection. If a raw cert was
|
||||||
f, err := os.Open(loadedConfig.RPCCert)
|
// specified in the config, then we'll se that directly. Otherwise, we
|
||||||
|
// attempt to read the cert from the path specified in the config.
|
||||||
|
var rpcCert []byte
|
||||||
|
if loadedConfig.RawRPCCert != "" {
|
||||||
|
rpcCert, err = hex.DecodeString(loadedConfig.RawRPCCert)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
certFile, err := os.Open(loadedConfig.RPCCert)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rpcCert, err = ioutil.ReadAll(certFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := certFile.Close(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rpcIP, err := net.LookupHost(loadedConfig.RPCHost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Printf("unable to resolve rpc host: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cert, err := ioutil.ReadAll(f)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
// Create, and start the lnwallet, which handles the core payment channel
|
// Create, and start the lnwallet, which handles the core payment channel
|
||||||
// logic, and exposes control via proxy state machines.
|
// logic, and exposes control via proxy state machines.
|
||||||
config := &lnwallet.Config{
|
config := &lnwallet.Config{
|
||||||
PrivatePass: []byte("hello"),
|
PrivatePass: []byte("hello"),
|
||||||
DataDir: filepath.Join(loadedConfig.DataDir, "lnwallet"),
|
DataDir: filepath.Join(loadedConfig.DataDir, "lnwallet"),
|
||||||
RpcHost: fmt.Sprintf("%v:%v", loadedConfig.RPCHost, activeNetParams.rpcPort),
|
RpcHost: fmt.Sprintf("%v:%v", rpcIP[0], activeNetParams.rpcPort),
|
||||||
RpcUser: loadedConfig.RPCUser,
|
RpcUser: loadedConfig.RPCUser,
|
||||||
RpcPass: loadedConfig.RPCPass,
|
RpcPass: loadedConfig.RPCPass,
|
||||||
CACert: cert,
|
CACert: rpcCert,
|
||||||
NetParams: activeNetParams.Params,
|
NetParams: activeNetParams.Params,
|
||||||
}
|
}
|
||||||
wallet, err := lnwallet.NewLightningWallet(config, chanDB)
|
wallet, err := lnwallet.NewLightningWallet(config, chanDB)
|
||||||
|
Loading…
Reference in New Issue
Block a user