@@ -22,6 +22,7 @@ import (
2222 "github.com/lightninglabs/aperture/aperturedb"
2323 "github.com/lightninglabs/aperture/auth"
2424 "github.com/lightninglabs/aperture/challenger"
25+ "github.com/lightninglabs/aperture/lnc"
2526 "github.com/lightninglabs/aperture/mint"
2627 "github.com/lightninglabs/aperture/proxy"
2728 "github.com/lightninglabs/lightning-node-connect/hashmailrpc"
@@ -219,6 +220,7 @@ func (a *Aperture) Start(errChan chan error) error {
219220 var (
220221 secretStore mint.SecretStore
221222 onionStore tor.OnionStore
223+ lncStore lnc.Store
222224 )
223225
224226 // Connect to the chosen database backend.
@@ -260,6 +262,13 @@ func (a *Aperture) Start(errChan chan error) error {
260262 )
261263 onionStore = aperturedb .NewOnionStore (dbOnionTxer )
262264
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+
263272 case "sqlite" :
264273 db , err := aperturedb .NewSqliteStore (a .cfg .Sqlite )
265274 if err != nil {
@@ -282,6 +291,13 @@ func (a *Aperture) Start(errChan chan error) error {
282291 )
283292 onionStore = aperturedb .NewOnionStore (dbOnionTxer )
284293
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+
285301 default :
286302 return fmt .Errorf ("unknown database backend: %s" ,
287303 a .cfg .DatabaseBackend )
@@ -290,30 +306,63 @@ func (a *Aperture) Start(errChan chan error) error {
290306 log .Infof ("Using %v as database backend" , a .cfg .DatabaseBackend )
291307
292308 if ! a .cfg .Authenticator .Disable {
309+ authCfg := a .cfg .Authenticator
293310 genInvoiceReq := func (price int64 ) (* lnrpc.Invoice , error ) {
294311 return & lnrpc.Invoice {
295312 Memo : "LSAT" ,
296313 Value : price ,
297314 }, nil
298315 }
299316
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+ }
317366 }
318367 }
319368
0 commit comments