diff --git a/loopd/daemon.go b/loopd/daemon.go index 26954821..a72219ee 100644 --- a/loopd/daemon.go +++ b/loopd/daemon.go @@ -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 } diff --git a/loopd/start.go b/loopd/start.go index 6cd5db60..ab03fea7 100644 --- a/loopd/start.go +++ b/loopd/start.go @@ -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) diff --git a/loopd/utils.go b/loopd/utils.go index 10bb449e..9b666851 100644 --- a/loopd/utils.go +++ b/loopd/utils.go @@ -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) { diff --git a/loopd/view.go b/loopd/view.go index dabe82c2..b9a6b302 100644 --- a/loopd/view.go +++ b/loopd/view.go @@ -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 }