Skip to content

Commit 046ec27

Browse files
ellemoutonpositiveblue
authored andcommitted
subserver: add faraday
1 parent d02749a commit 046ec27

File tree

2 files changed

+97
-2
lines changed

2 files changed

+97
-2
lines changed

subservers/faraday.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package subservers
2+
3+
import (
4+
"github.com/lightninglabs/faraday"
5+
"github.com/lightninglabs/faraday/frdrpc"
6+
"github.com/lightninglabs/faraday/frdrpcserver"
7+
"github.com/lightninglabs/lndclient"
8+
"github.com/lightningnetwork/lnd/lnrpc"
9+
"google.golang.org/grpc"
10+
)
11+
12+
// faradaySubServer implements the SubServer interface.
13+
type faradaySubServer struct {
14+
*frdrpcserver.RPCServer
15+
16+
remote bool
17+
cfg *faraday.Config
18+
remoteCfg *RemoteDaemonConfig
19+
}
20+
21+
// A compile-time check to ensure that faradaySubServer implements SubServer.
22+
var _ SubServer = (*faradaySubServer)(nil)
23+
24+
// NewFaradaySubServer returns a new faraday implementation of the SubServer
25+
// interface.
26+
func NewFaradaySubServer(cfg *faraday.Config, rpcCfg *frdrpcserver.Config,
27+
remoteCfg *RemoteDaemonConfig, remote bool) SubServer {
28+
29+
return &faradaySubServer{
30+
RPCServer: frdrpcserver.NewRPCServer(rpcCfg),
31+
cfg: cfg,
32+
remoteCfg: remoteCfg,
33+
remote: remote,
34+
}
35+
}
36+
37+
// Name returns the name of the sub-server.
38+
//
39+
// NOTE: this is part of the SubServer interface.
40+
func (f *faradaySubServer) Name() string {
41+
return FARADAY
42+
}
43+
44+
// Remote returns true if the sub-server is running remotely and so
45+
// should be connected to instead of spinning up an integrated server.
46+
//
47+
// NOTE: this is part of the SubServer interface.
48+
func (f *faradaySubServer) Remote() bool {
49+
return f.remote
50+
}
51+
52+
// RemoteConfig returns the config required to connect to the sub-server
53+
// if it is running in remote mode.
54+
//
55+
// NOTE: this is part of the SubServer interface.
56+
func (f *faradaySubServer) RemoteConfig() *RemoteDaemonConfig {
57+
return f.remoteCfg
58+
}
59+
60+
// Start starts the sub-server in integrated mode.
61+
//
62+
// NOTE: this is part of the SubServer interface.
63+
func (f *faradaySubServer) Start(_ lnrpc.LightningClient,
64+
lndGrpc *lndclient.GrpcLndServices, withMacaroonService bool) error {
65+
66+
return f.StartAsSubserver(
67+
lndGrpc.LndServices, withMacaroonService,
68+
)
69+
}
70+
71+
// RegisterGrpcService must register the sub-server's GRPC server with the given
72+
// registrar.
73+
//
74+
// NOTE: this is part of the SubServer interface.
75+
func (f *faradaySubServer) RegisterGrpcService(service grpc.ServiceRegistrar) {
76+
frdrpc.RegisterFaradayServerServer(service, f)
77+
}
78+
79+
// ServerErrChan returns an error channel that should be listened on after
80+
// starting the sub-server to listen for any runtime errors. It is optional and
81+
// may be set to nil. This only applies in integrated mode.
82+
//
83+
// NOTE: this is part of the SubServer interface.
84+
func (f *faradaySubServer) ServerErrChan() chan error {
85+
return nil
86+
}
87+
88+
// MacPath returns the path to the sub-server's macaroon if it is not running in
89+
// remote mode.
90+
//
91+
// NOTE: this is part of the SubServer interface.
92+
func (f *faradaySubServer) MacPath() string {
93+
return f.cfg.MacaroonPath
94+
}

subservers/subserver.go

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

1313
const (
14-
LND string = "lnd"
15-
LIT string = "lit"
14+
LND string = "lnd"
15+
LIT string = "lit"
16+
FARADAY string = "faraday"
1617
)
1718

1819
// subServerWrapper is a wrapper around the SubServer interface and is used by

0 commit comments

Comments
 (0)