@@ -100,7 +100,8 @@ func New(config *Config, lisCfg *listenerCfg) *Daemon {
100
100
// execute commands and pass back swap status information.
101
101
func (d * Daemon ) Start () error {
102
102
// There should be no reason to start the daemon twice. Therefore return
103
- // an error if that's tried.
103
+ // an error if that's tried. This is mostly to guard against Start and
104
+ // StartAsSubserver both being called.
104
105
if atomic .AddInt32 (& d .started , 1 ) != 1 {
105
106
return errOnlyStartOnce
106
107
}
@@ -136,6 +137,29 @@ func (d *Daemon) Start() error {
136
137
return nil
137
138
}
138
139
140
+ // StartAsSubserver is an alternative to Start where the RPC server does not
141
+ // create its own gRPC server but registers to an existing one. The same goes
142
+ // for REST (if enabled), instead of creating an own mux and HTTP server, we
143
+ // register to an existing one.
144
+ func (d * Daemon ) StartAsSubserver (lndGrpc * lndclient.GrpcLndServices ) error {
145
+ // There should be no reason to start the daemon twice. Therefore return
146
+ // an error if that's tried. This is mostly to guard against Start and
147
+ // StartAsSubserver both being called.
148
+ if atomic .AddInt32 (& d .started , 1 ) != 1 {
149
+ return errOnlyStartOnce
150
+ }
151
+
152
+ // When starting as a subserver, we get passed in an already established
153
+ // connection to lnd that might be shared among other subservers.
154
+ d .lnd = lndGrpc
155
+
156
+ // With lnd already pre-connected, initialize everything else, such as
157
+ // the swap server client, the RPC server instance and our main swap
158
+ // handlers. If this fails, then nothing has been started yet and we can
159
+ // just return the error.
160
+ return d .initialize ()
161
+ }
162
+
139
163
// startWebServers starts the gRPC and REST servers in goroutines.
140
164
func (d * Daemon ) startWebServers () error {
141
165
var err error
0 commit comments