Skip to content

Commit 3c95ab6

Browse files
ellemoutonpositiveblue
authored andcommitted
subserver: add loop
1 parent 5b1aa97 commit 3c95ab6

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

subservers/loop.go

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

subservers/subserver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
const (
1414
LND string = "lnd"
1515
LIT string = "lit"
16+
LOOP string = "loop"
1617
POOL string = "pool"
1718
FARADAY string = "faraday"
1819
)

0 commit comments

Comments
 (0)