@@ -22,6 +22,7 @@ import (
22
22
"github.com/lightninglabs/aperture/aperturedb"
23
23
"github.com/lightninglabs/aperture/auth"
24
24
"github.com/lightninglabs/aperture/challenger"
25
+ "github.com/lightninglabs/aperture/lnc"
25
26
"github.com/lightninglabs/aperture/mint"
26
27
"github.com/lightninglabs/aperture/proxy"
27
28
"github.com/lightninglabs/lightning-node-connect/hashmailrpc"
@@ -219,6 +220,7 @@ func (a *Aperture) Start(errChan chan error) error {
219
220
var (
220
221
secretStore mint.SecretStore
221
222
onionStore tor.OnionStore
223
+ lncStore lnc.Store
222
224
)
223
225
224
226
// Connect to the chosen database backend.
@@ -260,6 +262,13 @@ func (a *Aperture) Start(errChan chan error) error {
260
262
)
261
263
onionStore = aperturedb .NewOnionStore (dbOnionTxer )
262
264
265
+ dbLNCTxer := aperturedb .NewTransactionExecutor (db ,
266
+ func (tx * sql.Tx ) aperturedb.LNCSessionsDB {
267
+ return db .WithTx (tx )
268
+ },
269
+ )
270
+ lncStore = aperturedb .NewLNCSessionsStore (dbLNCTxer )
271
+
263
272
case "sqlite" :
264
273
db , err := aperturedb .NewSqliteStore (a .cfg .Sqlite )
265
274
if err != nil {
@@ -282,6 +291,13 @@ func (a *Aperture) Start(errChan chan error) error {
282
291
)
283
292
onionStore = aperturedb .NewOnionStore (dbOnionTxer )
284
293
294
+ dbLNCTxer := aperturedb .NewTransactionExecutor (db ,
295
+ func (tx * sql.Tx ) aperturedb.LNCSessionsDB {
296
+ return db .WithTx (tx )
297
+ },
298
+ )
299
+ lncStore = aperturedb .NewLNCSessionsStore (dbLNCTxer )
300
+
285
301
default :
286
302
return fmt .Errorf ("unknown database backend: %s" ,
287
303
a .cfg .DatabaseBackend )
@@ -290,30 +306,63 @@ func (a *Aperture) Start(errChan chan error) error {
290
306
log .Infof ("Using %v as database backend" , a .cfg .DatabaseBackend )
291
307
292
308
if ! a .cfg .Authenticator .Disable {
309
+ authCfg := a .cfg .Authenticator
293
310
genInvoiceReq := func (price int64 ) (* lnrpc.Invoice , error ) {
294
311
return & lnrpc.Invoice {
295
312
Memo : "LSAT" ,
296
313
Value : price ,
297
314
}, nil
298
315
}
299
316
300
- authCfg := a .cfg .Authenticator
301
- client , err := lndclient .NewBasicClient (
302
- authCfg .LndHost , authCfg .TLSPath ,
303
- authCfg .MacDir , authCfg .Network ,
304
- lndclient .MacFilename (
305
- invoiceMacaroonName ,
306
- ),
307
- )
308
- if err != nil {
309
- return err
310
- }
311
- a .challenger , err = challenger .NewLndChallenger (
312
- client , genInvoiceReq , context .Background ,
313
- errChan ,
314
- )
315
- if err != nil {
316
- return err
317
+ switch {
318
+ case authCfg .Passphrase != "" :
319
+ log .Infof ("Using lnc's authenticator config" )
320
+
321
+ if a .cfg .DatabaseBackend == "etcd" {
322
+ return fmt .Errorf ("etcd is not supported as " +
323
+ "a database backend for lnc " +
324
+ "connections" )
325
+ }
326
+
327
+ session , err := lnc .NewSession (
328
+ authCfg .Passphrase , authCfg .MailboxAddress ,
329
+ authCfg .DevServer ,
330
+ )
331
+ if err != nil {
332
+ return fmt .Errorf ("unable to create lnc " +
333
+ "session: %w" , err )
334
+ }
335
+
336
+ a .challenger , err = challenger .NewLNCChallenger (
337
+ session , lncStore , genInvoiceReq , errChan ,
338
+ )
339
+ if err != nil {
340
+ return fmt .Errorf ("unable to start lnc " +
341
+ "challenger: %w" , err )
342
+ }
343
+
344
+ case authCfg .LndHost != "" :
345
+ log .Infof ("Using lnd's authenticator config" )
346
+
347
+ authCfg := a .cfg .Authenticator
348
+ client , err := lndclient .NewBasicClient (
349
+ authCfg .LndHost , authCfg .TLSPath ,
350
+ authCfg .MacDir , authCfg .Network ,
351
+ lndclient .MacFilename (
352
+ invoiceMacaroonName ,
353
+ ),
354
+ )
355
+ if err != nil {
356
+ return err
357
+ }
358
+
359
+ a .challenger , err = challenger .NewLndChallenger (
360
+ client , genInvoiceReq , context .Background ,
361
+ errChan ,
362
+ )
363
+ if err != nil {
364
+ return err
365
+ }
317
366
}
318
367
}
319
368
0 commit comments