Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aperture as a library - nice to have's #44

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions challenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type InvoiceClient interface {
// LndChallenger is a challenger that uses an lnd backend to create new LSAT
// payment challenges.
type LndChallenger struct {
client InvoiceClient
genInvoiceReq InvoiceRequestGenerator
Client InvoiceClient
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: exported fields should have godoc comments. This also removes the need for the large indentation as the fields will be separated a bit.

GenInvoiceReq InvoiceRequestGenerator

invoiceStates map[lntypes.Hash]lnrpc.Invoice_InvoiceState
invoicesMtx *sync.Mutex
Expand Down Expand Up @@ -85,8 +85,8 @@ func NewLndChallenger(cfg *authConfig, genInvoiceReq InvoiceRequestGenerator,

invoicesMtx := &sync.Mutex{}
return &LndChallenger{
client: client,
genInvoiceReq: genInvoiceReq,
Client: client,
GenInvoiceReq: genInvoiceReq,
invoiceStates: make(map[lntypes.Hash]lnrpc.Invoice_InvoiceState),
invoicesMtx: invoicesMtx,
invoicesCond: sync.NewCond(invoicesMtx),
Expand All @@ -111,7 +111,7 @@ func (l *LndChallenger) Start() error {
// cache. We need to keep track of all invoices, even quite old ones to
// make sure tokens are valid. But to save space we only keep track of
// an invoice's state.
invoiceResp, err := l.client.ListInvoices(
invoiceResp, err := l.Client.ListInvoices(
context.Background(), &lnrpc.ListInvoiceRequest{
NumMaxInvoices: math.MaxUint64,
},
Expand Down Expand Up @@ -148,7 +148,7 @@ func (l *LndChallenger) Start() error {
ctxc, cancel := context.WithCancel(context.Background())
l.invoicesCancel = cancel

subscriptionResp, err := l.client.SubscribeInvoices(
subscriptionResp, err := l.Client.SubscribeInvoices(
ctxc, &lnrpc.InvoiceSubscription{
AddIndex: addIndex,
SettleIndex: settleIndex,
Expand Down Expand Up @@ -264,13 +264,13 @@ func (l *LndChallenger) Stop() {
func (l *LndChallenger) NewChallenge(price int64) (string, lntypes.Hash, error) {
// Obtain a new invoice from lnd first. We need to know the payment hash
// so we can add it as a caveat to the macaroon.
invoice, err := l.genInvoiceReq(price)
invoice, err := l.GenInvoiceReq(price)
if err != nil {
log.Errorf("Error generating invoice request: %v", err)
return "", lntypes.ZeroHash, err
}
ctx := context.Background()
response, err := l.client.AddInvoice(ctx, invoice)
response, err := l.Client.AddInvoice(ctx, invoice)
if err != nil {
log.Errorf("Error adding invoice: %v", err)
return "", lntypes.ZeroHash, err
Expand Down
4 changes: 2 additions & 2 deletions challenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func newChallenger() (*LndChallenger, *mockInvoiceClient, chan error) {
invoicesMtx := &sync.Mutex{}
mainErrChan := make(chan error)
return &LndChallenger{
client: mockClient,
genInvoiceReq: genInvoiceReq,
Client: mockClient,
GenInvoiceReq: genInvoiceReq,
invoiceStates: make(map[lntypes.Hash]lnrpc.Invoice_InvoiceState),
quit: make(chan struct{}),
invoicesMtx: invoicesMtx,
Expand Down