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" proxy "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/lightninglabs/loop" "github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/lndclient"
"github.com/lightninglabs/loop/looprpc" "github.com/lightninglabs/loop/looprpc"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
@ -25,12 +26,15 @@ type listenerCfg struct {
// restListener returns a listener to use for the REST proxy. // restListener returns a listener to use for the REST proxy.
restListener func() (net.Listener, error) 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, // daemon runs loopd in daemon mode. It will listen for grpc connections,
// execute commands and pass back swap status information. // execute commands and pass back swap status information.
func daemon(config *config, lisCfg *listenerCfg) error { 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 { if err != nil {
return err return err
} }

@ -10,6 +10,7 @@ import (
"github.com/jessevdk/go-flags" "github.com/jessevdk/go-flags"
"github.com/lightninglabs/loop" "github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/lndclient"
"github.com/lightningnetwork/lnd/build" "github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
) )
@ -58,6 +59,13 @@ func newListenerCfg(config *config, rpcCfg RPCConfig) *listenerCfg {
return net.Listen("tcp", config.RESTListen) 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" { if parser.Active.Name == "view" {
return view(&config) return view(&config, lisCfg)
} }
return fmt.Errorf("unimplemented command %v", parser.Active.Name) return fmt.Errorf("unimplemented command %v", parser.Active.Name)

@ -8,13 +8,6 @@ import (
"github.com/lightninglabs/loop/lndclient" "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. // getClient returns an instance of the swap client.
func getClient(network, swapServer string, insecure bool, tlsPathServer string, func getClient(network, swapServer string, insecure bool, tlsPathServer string,
lnd *lndclient.LndServices) (*loop.Client, func(), error) { lnd *lndclient.LndServices) (*loop.Client, func(), error) {

@ -11,13 +11,13 @@ import (
) )
// view prints all swaps currently in the database. // 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) chainParams, err := swap.ChainParamsFromNetwork(config.Network)
if err != nil { if err != nil {
return err return err
} }
lnd, err := getLnd(config.Network, config.Lnd) lnd, err := lisCfg.getLnd(config.Network, config.Lnd)
if err != nil { if err != nil {
return err return err
} }

Loading…
Cancel
Save