Skip to content

Commit 0a51bf4

Browse files
committed
loopd: make lnd conn configurable
1 parent 34c2e71 commit 0a51bf4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

loopd/start.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package loopd
22

33
import (
4+
"context"
45
"fmt"
56
"net"
67
"os"
@@ -36,6 +37,10 @@ type RPCConfig struct {
3637
// listener.
3738
// Note that setting this will also disable REST.
3839
RPCListener net.Listener
40+
41+
// LndConn is an optional connection to an lnd instance. If set it will
42+
// override the TCP connection created from daemon's config.
43+
LndConn net.Conn
3944
}
4045

4146
// newListenerCfg creates and returns a new listenerCfg from the passed config
@@ -62,6 +67,21 @@ func newListenerCfg(config *config, rpcCfg RPCConfig) *listenerCfg {
6267
getLnd: func(network string, cfg *lndConfig) (
6368
*lndclient.GrpcLndServices, error) {
6469

70+
// If a custom lnd connection is specified we use that
71+
// directly.
72+
if rpcCfg.LndConn != nil {
73+
dialer := func(context.Context, string) (
74+
net.Conn, error) {
75+
return rpcCfg.LndConn, nil
76+
}
77+
78+
return lndclient.NewLndServicesWithDialer(
79+
dialer,
80+
rpcCfg.LndConn.RemoteAddr().String(),
81+
network, cfg.MacaroonDir, cfg.TLSPath,
82+
)
83+
}
84+
6585
return lndclient.NewLndServices(
6686
cfg.Host, network, cfg.MacaroonDir, cfg.TLSPath,
6787
)

0 commit comments

Comments
 (0)