Skip to content

Commit 7c206f5

Browse files
committed
challenger: change NewLndChallenger client parameter
- Alters NewLndChallenger so that it takes challenger.InvoiceClient in as a parameter. (This is useful in the case of using NewLndChallenger in the lnd watchtower project, to avoid having to import lndclient, which leads to an import cycle.) - Also deletes the AuthConfig parameter. Since we now pass the LND client directly into the function, the AuthConfig parameter is no longer needed.
1 parent 0deba12 commit 7c206f5

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
lines changed

aperture.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/lightninglabs/aperture/proxy"
2424
"github.com/lightninglabs/aperture/secrets"
2525
"github.com/lightninglabs/lightning-node-connect/hashmailrpc"
26+
"github.com/lightninglabs/lndclient"
2627
"github.com/lightningnetwork/lnd"
2728
"github.com/lightningnetwork/lnd/build"
2829
"github.com/lightningnetwork/lnd/cert"
@@ -223,15 +224,17 @@ func (a *Aperture) Start(errChan chan error) error {
223224
}
224225

225226
if !a.cfg.Authenticator.Disable {
226-
challengerAuth := &challenger.AuthConfig{
227-
LndHost: a.cfg.Authenticator.LndHost,
228-
TLSPath: a.cfg.Authenticator.TLSPath,
229-
MacDir: a.cfg.Authenticator.MacDir,
230-
Network: a.cfg.Authenticator.Network,
231-
Disable: a.cfg.Authenticator.Disable,
227+
client, err := lndclient.NewBasicClient(
228+
a.cfg.Authenticator.LndHost, a.cfg.Authenticator.TLSPath,
229+
a.cfg.Authenticator.MacDir, a.cfg.Authenticator.Network,
230+
lndclient.MacFilename(challenger.InvoiceMacaroonName),
231+
)
232+
if err != nil {
233+
return err
232234
}
235+
233236
a.challenger, err = challenger.NewLndChallenger(
234-
challengerAuth, genInvoiceReq, errChan,
237+
genInvoiceReq, client, errChan,
235238
)
236239
if err != nil {
237240
return err

challenger/challenger.go

Lines changed: 2 additions & 24 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"
@@ -55,19 +54,6 @@ type LndChallenger struct {
5554
wg sync.WaitGroup
5655
}
5756

58-
type AuthConfig struct {
59-
// LndHost is the hostname of the LND instance to connect to.
60-
LndHost string `long:"lndhost" description:"Hostname of the LND instance to connect to"`
61-
62-
TLSPath string `long:"tlspath" description:"Path to LND instance's tls certificate"`
63-
64-
MacDir string `long:"macdir" description:"Directory containing LND instance's macaroons"`
65-
66-
Network string `long:"network" description:"The network LND is connected to." choice:"regtest" choice:"simnet" choice:"testnet" choice:"mainnet"`
67-
68-
Disable bool `long:"disable" description:"Whether to disable LND auth."`
69-
}
70-
7157
// A compile time flag to ensure the LndChallenger satisfies the
7258
// mint.Challenger and auth.InvoiceChecker interface.
7359
var _ mint.Challenger = (*LndChallenger)(nil)
@@ -81,21 +67,13 @@ const (
8167

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

8773
if genInvoiceReq == nil {
8874
return nil, fmt.Errorf("genInvoiceReq cannot be nil")
8975
}
9076

91-
client, err := lndclient.NewBasicClient(
92-
cfg.LndHost, cfg.TLSPath, cfg.MacDir, cfg.Network,
93-
lndclient.MacFilename(InvoiceMacaroonName),
94-
)
95-
if err != nil {
96-
return nil, err
97-
}
98-
9977
invoicesMtx := &sync.Mutex{}
10078
return &LndChallenger{
10179
client: client,

0 commit comments

Comments
 (0)