multi: extend InvoiceDB methods with a context argument (#8066)
* multi: extend InvoiceDB methods with a context argument This commit adds a context to InvoiceDB's methods. Along this refactor we also extend InvoiceRegistry methods with contexts where it makes sense. This change is essential to be able to provide kvdb and sqldb implementations for InvoiceDB. * channeldb: restrict invoice tests to only use an InvoiceDB instance * docs: update release notes for 0.18.0
This commit is contained in:
1 parent
9478b85e59
commit
ad5cd9c8bb
18 files changed
+458
-328
No files matched your search
@@ -47,8 +47,8 @@ const (
|
||||
// AddInvoiceConfig contains dependencies for invoice creation.
|
||||
type AddInvoiceConfig struct {
|
||||
// AddInvoice is called to add the invoice to the registry.
|
||||
AddInvoice func(invoice *invoices.Invoice, paymentHash lntypes.Hash) (
|
||||
uint64, error)
|
||||
AddInvoice func(ctx context.Context, invoice *invoices.Invoice,
|
||||
paymentHash lntypes.Hash) (uint64, error)
|
||||
|
||||
// IsChannelActive is used to generate valid hop hints.
|
||||
IsChannelActive func(chanID lnwire.ChannelID) bool
|
||||
@@ -478,7 +478,7 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
|
||||
)
|
||||
|
||||
// With all sanity checks passed, write the invoice to the database.
|
||||
_, err = cfg.AddInvoice(newInvoice, paymentHash)
|
||||
_, err = cfg.AddInvoice(ctx, newInvoice, paymentHash)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -238,7 +238,9 @@ func (s *Server) SubscribeSingleInvoice(req *SubscribeSingleInvoiceRequest,
|
||||
return err
|
||||
}
|
||||
|
||||
invoiceClient, err := s.cfg.InvoiceRegistry.SubscribeSingleInvoice(hash)
|
||||
invoiceClient, err := s.cfg.InvoiceRegistry.SubscribeSingleInvoice(
|
||||
updateStream.Context(), hash,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -287,7 +289,7 @@ func (s *Server) SettleInvoice(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = s.cfg.InvoiceRegistry.SettleHodlInvoice(preimage)
|
||||
err = s.cfg.InvoiceRegistry.SettleHodlInvoice(ctx, preimage)
|
||||
if err != nil && !errors.Is(err, invoices.ErrInvoiceAlreadySettled) {
|
||||
return nil, err
|
||||
}
|
||||
@@ -306,7 +308,7 @@ func (s *Server) CancelInvoice(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = s.cfg.InvoiceRegistry.CancelInvoice(paymentHash)
|
||||
err = s.cfg.InvoiceRegistry.CancelInvoice(ctx, paymentHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -433,7 +435,9 @@ func (s *Server) LookupInvoiceV2(ctx context.Context,
|
||||
|
||||
// Attempt to locate the invoice, returning a nice "not found" error if
|
||||
// we can't find it in the database.
|
||||
invoice, err := s.cfg.InvoiceRegistry.LookupInvoiceByRef(invoiceRef)
|
||||
invoice, err := s.cfg.InvoiceRegistry.LookupInvoiceByRef(
|
||||
ctx, invoiceRef,
|
||||
)
|
||||
switch {
|
||||
case errors.Is(err, invoices.ErrInvoiceNotFound):
|
||||
return nil, status.Error(codes.NotFound, err.Error())
|
||||
|
||||
Reference in new issue
Block a user