Skip to content

Commit 3d53f20

Browse files
committed
multi: use InvoiceClient in NewLndChallenger
Stop creating the connection inside the `NewLndChallenger`. That will allow us reuse the function with an LNC connection.
1 parent 0e02476 commit 3d53f20

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

aperture.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/lightninglabs/aperture/mint"
2525
"github.com/lightninglabs/aperture/proxy"
2626
"github.com/lightninglabs/lightning-node-connect/hashmailrpc"
27+
"github.com/lightninglabs/lndclient"
2728
"github.com/lightningnetwork/lnd"
2829
"github.com/lightningnetwork/lnd/build"
2930
"github.com/lightningnetwork/lnd/cert"
@@ -293,8 +294,19 @@ func (a *Aperture) Start(errChan chan error) error {
293294
}
294295

295296
if !a.cfg.Authenticator.Disable {
297+
authCfg := a.cfg.Authenticator
298+
client, err := lndclient.NewBasicClient(
299+
authCfg.LndHost, authCfg.TLSPath, authCfg.MacDir,
300+
authCfg.Network, lndclient.MacFilename(
301+
invoiceMacaroonName,
302+
),
303+
)
304+
if err != nil {
305+
return err
306+
}
307+
296308
a.challenger, err = NewLndChallenger(
297-
a.cfg.Authenticator, genInvoiceReq, errChan,
309+
client, genInvoiceReq, errChan,
298310
)
299311
if err != nil {
300312
return err

challenger.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/lightninglabs/aperture/auth"
1313
"github.com/lightninglabs/aperture/mint"
14-
"github.com/lightninglabs/lndclient"
1514
"github.com/lightningnetwork/lnd/lnrpc"
1615
"github.com/lightningnetwork/lnd/lntypes"
1716
"google.golang.org/grpc"
@@ -66,23 +65,16 @@ const (
6665
invoiceMacaroonName = "invoice.macaroon"
6766
)
6867

69-
// NewLndChallenger creates a new challenger that uses the given connection
70-
// details to connect to an lnd backend to create payment challenges.
71-
func NewLndChallenger(cfg *AuthConfig, genInvoiceReq InvoiceRequestGenerator,
68+
// NewLndChallenger creates a new challenger that uses the given connection to
69+
// an lnd backend to create payment challenges.
70+
func NewLndChallenger(client InvoiceClient,
71+
genInvoiceReq InvoiceRequestGenerator,
7272
errChan chan<- error) (*LndChallenger, error) {
7373

7474
if genInvoiceReq == nil {
7575
return nil, fmt.Errorf("genInvoiceReq cannot be nil")
7676
}
7777

78-
client, err := lndclient.NewBasicClient(
79-
cfg.LndHost, cfg.TLSPath, cfg.MacDir, cfg.Network,
80-
lndclient.MacFilename(invoiceMacaroonName),
81-
)
82-
if err != nil {
83-
return nil, err
84-
}
85-
8678
invoicesMtx := &sync.Mutex{}
8779
return &LndChallenger{
8880
client: client,

0 commit comments

Comments
 (0)