From 0a51bf4d2de8fb3fa8ba49f614295880e5445fea Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Fri, 3 Jan 2020 14:01:32 +0100 Subject: [PATCH] loopd: make lnd conn configurable --- loopd/start.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/loopd/start.go b/loopd/start.go index ab03fea..321ed5c 100644 --- a/loopd/start.go +++ b/loopd/start.go @@ -1,6 +1,7 @@ package loopd import ( + "context" "fmt" "net" "os" @@ -36,6 +37,10 @@ type RPCConfig struct { // listener. // Note that setting this will also disable REST. RPCListener net.Listener + + // LndConn is an optional connection to an lnd instance. If set it will + // override the TCP connection created from daemon's config. + LndConn net.Conn } // newListenerCfg creates and returns a new listenerCfg from the passed config @@ -62,6 +67,21 @@ func newListenerCfg(config *config, rpcCfg RPCConfig) *listenerCfg { getLnd: func(network string, cfg *lndConfig) ( *lndclient.GrpcLndServices, error) { + // If a custom lnd connection is specified we use that + // directly. + if rpcCfg.LndConn != nil { + dialer := func(context.Context, string) ( + net.Conn, error) { + return rpcCfg.LndConn, nil + } + + return lndclient.NewLndServicesWithDialer( + dialer, + rpcCfg.LndConn.RemoteAddr().String(), + network, cfg.MacaroonDir, cfg.TLSPath, + ) + } + return lndclient.NewLndServices( cfg.Host, network, cfg.MacaroonDir, cfg.TLSPath, )