Skip to content

Commit 34c2e71

Browse files
committed
loopd: move lnd services init to config
This allows us to supply custom lnd connections to the daemon.
1 parent c7e8c9f commit 34c2e71

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

loopd/daemon.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
proxy "github.com/grpc-ecosystem/grpc-gateway/runtime"
1616
"github.com/lightninglabs/loop"
17+
"github.com/lightninglabs/loop/lndclient"
1718
"github.com/lightninglabs/loop/looprpc"
1819
"google.golang.org/grpc"
1920
)
@@ -25,12 +26,15 @@ type listenerCfg struct {
2526

2627
// restListener returns a listener to use for the REST proxy.
2728
restListener func() (net.Listener, error)
29+
30+
// getLnd returns a grpc connection to an lnd instance.
31+
getLnd func(string, *lndConfig) (*lndclient.GrpcLndServices, error)
2832
}
2933

3034
// daemon runs loopd in daemon mode. It will listen for grpc connections,
3135
// execute commands and pass back swap status information.
3236
func daemon(config *config, lisCfg *listenerCfg) error {
33-
lnd, err := getLnd(config.Network, config.Lnd)
37+
lnd, err := lisCfg.getLnd(config.Network, config.Lnd)
3438
if err != nil {
3539
return err
3640
}

loopd/start.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/jessevdk/go-flags"
1212
"github.com/lightninglabs/loop"
13+
"github.com/lightninglabs/loop/lndclient"
1314
"github.com/lightningnetwork/lnd/build"
1415
"github.com/lightningnetwork/lnd/lntypes"
1516
)
@@ -58,6 +59,13 @@ func newListenerCfg(config *config, rpcCfg RPCConfig) *listenerCfg {
5859

5960
return net.Listen("tcp", config.RESTListen)
6061
},
62+
getLnd: func(network string, cfg *lndConfig) (
63+
*lndclient.GrpcLndServices, error) {
64+
65+
return lndclient.NewLndServices(
66+
cfg.Host, network, cfg.MacaroonDir, cfg.TLSPath,
67+
)
68+
},
6169
}
6270
}
6371

@@ -142,7 +150,7 @@ func Start(rpcCfg RPCConfig) error {
142150
}
143151

144152
if parser.Active.Name == "view" {
145-
return view(&config)
153+
return view(&config, lisCfg)
146154
}
147155

148156
return fmt.Errorf("unimplemented command %v", parser.Active.Name)

loopd/utils.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ import (
88
"github.com/lightninglabs/loop/lndclient"
99
)
1010

11-
// getLnd returns an instance of the lnd services proxy.
12-
func getLnd(network string, cfg *lndConfig) (*lndclient.GrpcLndServices, error) {
13-
return lndclient.NewLndServices(
14-
cfg.Host, network, cfg.MacaroonDir, cfg.TLSPath,
15-
)
16-
}
17-
1811
// getClient returns an instance of the swap client.
1912
func getClient(network, swapServer string, insecure bool, tlsPathServer string,
2013
lnd *lndclient.LndServices) (*loop.Client, func(), error) {

loopd/view.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import (
1111
)
1212

1313
// view prints all swaps currently in the database.
14-
func view(config *config) error {
14+
func view(config *config, lisCfg *listenerCfg) error {
1515
chainParams, err := swap.ChainParamsFromNetwork(config.Network)
1616
if err != nil {
1717
return err
1818
}
1919

20-
lnd, err := getLnd(config.Network, config.Lnd)
20+
lnd, err := lisCfg.getLnd(config.Network, config.Lnd)
2121
if err != nil {
2222
return err
2323
}

0 commit comments

Comments
 (0)