loopd: move lnd services init to config

This allows us to supply custom lnd connections to the daemon.
pull/115/head
Johan T. Halseth 4 years ago
parent c7e8c9f964
commit 34c2e71f9e
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -14,6 +14,7 @@ import (
proxy "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/lndclient"
"github.com/lightninglabs/loop/looprpc"
"google.golang.org/grpc"
)
@ -25,12 +26,15 @@ type listenerCfg struct {
// restListener returns a listener to use for the REST proxy.
restListener func() (net.Listener, error)
// getLnd returns a grpc connection to an lnd instance.
getLnd func(string, *lndConfig) (*lndclient.GrpcLndServices, error)
}
// daemon runs loopd in daemon mode. It will listen for grpc connections,
// execute commands and pass back swap status information.
func daemon(config *config, lisCfg *listenerCfg) error {
lnd, err := getLnd(config.Network, config.Lnd)
lnd, err := lisCfg.getLnd(config.Network, config.Lnd)
if err != nil {
return err
}

@ -10,6 +10,7 @@ import (
"github.com/jessevdk/go-flags"
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/lndclient"
"github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/lntypes"
)
@ -58,6 +59,13 @@ func newListenerCfg(config *config, rpcCfg RPCConfig) *listenerCfg {
return net.Listen("tcp", config.RESTListen)
},
getLnd: func(network string, cfg *lndConfig) (
*lndclient.GrpcLndServices, error) {
return lndclient.NewLndServices(
cfg.Host, network, cfg.MacaroonDir, cfg.TLSPath,
)
},
}
}
@ -142,7 +150,7 @@ func Start(rpcCfg RPCConfig) error {
}
if parser.Active.Name == "view" {
return view(&config)
return view(&config, lisCfg)
}
return fmt.Errorf("unimplemented command %v", parser.Active.Name)

@ -8,13 +8,6 @@ import (
"github.com/lightninglabs/loop/lndclient"
)
// getLnd returns an instance of the lnd services proxy.
func getLnd(network string, cfg *lndConfig) (*lndclient.GrpcLndServices, error) {
return lndclient.NewLndServices(
cfg.Host, network, cfg.MacaroonDir, cfg.TLSPath,
)
}
// getClient returns an instance of the swap client.
func getClient(network, swapServer string, insecure bool, tlsPathServer string,
lnd *lndclient.LndServices) (*loop.Client, func(), error) {

@ -11,13 +11,13 @@ import (
)
// view prints all swaps currently in the database.
func view(config *config) error {
func view(config *config, lisCfg *listenerCfg) error {
chainParams, err := swap.ChainParamsFromNetwork(config.Network)
if err != nil {
return err
}
lnd, err := getLnd(config.Network, config.Lnd)
lnd, err := lisCfg.getLnd(config.Network, config.Lnd)
if err != nil {
return err
}

Loading…
Cancel
Save