diff --git a/subservers/faraday.go b/subservers/faraday.go new file mode 100644 index 00000000..c55c7e18 --- /dev/null +++ b/subservers/faraday.go @@ -0,0 +1,94 @@ +package subservers + +import ( + "github.com/lightninglabs/faraday" + "github.com/lightninglabs/faraday/frdrpc" + "github.com/lightninglabs/faraday/frdrpcserver" + "github.com/lightninglabs/lndclient" + "github.com/lightningnetwork/lnd/lnrpc" + "google.golang.org/grpc" +) + +// faradaySubServer implements the SubServer interface. +type faradaySubServer struct { + *frdrpcserver.RPCServer + + remote bool + cfg *faraday.Config + remoteCfg *RemoteDaemonConfig +} + +// A compile-time check to ensure that faradaySubServer implements SubServer. +var _ SubServer = (*faradaySubServer)(nil) + +// NewFaradaySubServer returns a new faraday implementation of the SubServer +// interface. +func NewFaradaySubServer(cfg *faraday.Config, rpcCfg *frdrpcserver.Config, + remoteCfg *RemoteDaemonConfig, remote bool) SubServer { + + return &faradaySubServer{ + RPCServer: frdrpcserver.NewRPCServer(rpcCfg), + cfg: cfg, + remoteCfg: remoteCfg, + remote: remote, + } +} + +// Name returns the name of the sub-server. +// +// NOTE: this is part of the SubServer interface. +func (f *faradaySubServer) Name() string { + return FARADAY +} + +// Remote returns true if the sub-server is running remotely and so +// should be connected to instead of spinning up an integrated server. +// +// NOTE: this is part of the SubServer interface. +func (f *faradaySubServer) Remote() bool { + return f.remote +} + +// RemoteConfig returns the config required to connect to the sub-server +// if it is running in remote mode. +// +// NOTE: this is part of the SubServer interface. +func (f *faradaySubServer) RemoteConfig() *RemoteDaemonConfig { + return f.remoteCfg +} + +// Start starts the sub-server in integrated mode. +// +// NOTE: this is part of the SubServer interface. +func (f *faradaySubServer) Start(_ lnrpc.LightningClient, + lndGrpc *lndclient.GrpcLndServices, withMacaroonService bool) error { + + return f.StartAsSubserver( + lndGrpc.LndServices, withMacaroonService, + ) +} + +// RegisterGrpcService must register the sub-server's GRPC server with the given +// registrar. +// +// NOTE: this is part of the SubServer interface. +func (f *faradaySubServer) RegisterGrpcService(service grpc.ServiceRegistrar) { + frdrpc.RegisterFaradayServerServer(service, f) +} + +// ServerErrChan returns an error channel that should be listened on after +// starting the sub-server to listen for any runtime errors. It is optional and +// may be set to nil. This only applies in integrated mode. +// +// NOTE: this is part of the SubServer interface. +func (f *faradaySubServer) ServerErrChan() chan error { + return nil +} + +// MacPath returns the path to the sub-server's macaroon if it is not running in +// remote mode. +// +// NOTE: this is part of the SubServer interface. +func (f *faradaySubServer) MacPath() string { + return f.cfg.MacaroonPath +} diff --git a/subservers/subserver.go b/subservers/subserver.go index 3e61165f..afd00378 100644 --- a/subservers/subserver.go +++ b/subservers/subserver.go @@ -11,8 +11,9 @@ import ( ) const ( - LND string = "lnd" - LIT string = "lit" + LND string = "lnd" + LIT string = "lit" + FARADAY string = "faraday" ) // subServerWrapper is a wrapper around the SubServer interface and is used by