mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
lnd: update invoiceRegistry to match new switch requirements
This commit is contained in:
parent
2196d9375e
commit
c19c872cff
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
"github.com/lightningnetwork/lnd/zpay32"
|
||||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||||
"github.com/roasbeef/btcutil"
|
"github.com/roasbeef/btcutil"
|
||||||
)
|
)
|
||||||
@ -95,10 +96,14 @@ func (i *invoiceRegistry) AddInvoice(invoice *channeldb.Invoice) error {
|
|||||||
//go i.notifyClients(invoice, false)
|
//go i.notifyClients(invoice, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// lookupInvoice looks up an invoice by its payment hash (R-Hash), if found
|
// LookupInvoice looks up an invoice by its payment hash (R-Hash), if found
|
||||||
// then we're able to pull the funds pending within an HTLC.
|
// then we're able to pull the funds pending within an HTLC. We'll also return
|
||||||
|
// what the expected min final CLTV delta is, pre-parsed from the payment
|
||||||
|
// request. This may be used by callers to determine if an HTLC is well formed
|
||||||
|
// according to the cltv delta.
|
||||||
|
//
|
||||||
// TODO(roasbeef): ignore if settled?
|
// TODO(roasbeef): ignore if settled?
|
||||||
func (i *invoiceRegistry) LookupInvoice(rHash chainhash.Hash) (channeldb.Invoice, error) {
|
func (i *invoiceRegistry) LookupInvoice(rHash chainhash.Hash) (channeldb.Invoice, uint32, error) {
|
||||||
// First check the in-memory debug invoice index to see if this is an
|
// First check the in-memory debug invoice index to see if this is an
|
||||||
// existing invoice added for debugging.
|
// existing invoice added for debugging.
|
||||||
i.RLock()
|
i.RLock()
|
||||||
@ -107,17 +112,24 @@ func (i *invoiceRegistry) LookupInvoice(rHash chainhash.Hash) (channeldb.Invoice
|
|||||||
|
|
||||||
// If found, then simply return the invoice directly.
|
// If found, then simply return the invoice directly.
|
||||||
if ok {
|
if ok {
|
||||||
return *invoice, nil
|
return *invoice, 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we'll check the database to see if there's an existing
|
// Otherwise, we'll check the database to see if there's an existing
|
||||||
// matching invoice.
|
// matching invoice.
|
||||||
invoice, err := i.cdb.LookupInvoice(rHash)
|
invoice, err := i.cdb.LookupInvoice(rHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return channeldb.Invoice{}, err
|
return channeldb.Invoice{}, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return *invoice, nil
|
payReq, err := zpay32.Decode(
|
||||||
|
string(invoice.PaymentRequest), activeNetParams.Params,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return channeldb.Invoice{}, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return *invoice, uint32(payReq.MinFinalCLTVExpiry()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SettleInvoice attempts to mark an invoice as settled. If the invoice is a
|
// SettleInvoice attempts to mark an invoice as settled. If the invoice is a
|
||||||
|
@ -2799,7 +2799,7 @@ func (r *rpcServer) LookupInvoice(ctx context.Context,
|
|||||||
|
|
||||||
rpcsLog.Tracef("[lookupinvoice] searching for invoice %x", payHash[:])
|
rpcsLog.Tracef("[lookupinvoice] searching for invoice %x", payHash[:])
|
||||||
|
|
||||||
invoice, err := r.server.invoices.LookupInvoice(payHash)
|
invoice, _, err := r.server.invoices.LookupInvoice(payHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ func (p *preimageBeacon) LookupPreimage(payHash []byte) ([]byte, bool) {
|
|||||||
// the preimage as it's on that we created ourselves.
|
// the preimage as it's on that we created ourselves.
|
||||||
var invoiceKey chainhash.Hash
|
var invoiceKey chainhash.Hash
|
||||||
copy(invoiceKey[:], payHash)
|
copy(invoiceKey[:], payHash)
|
||||||
invoice, err := p.invoices.LookupInvoice(invoiceKey)
|
invoice, _, err := p.invoices.LookupInvoice(invoiceKey)
|
||||||
switch {
|
switch {
|
||||||
case err == channeldb.ErrInvoiceNotFound:
|
case err == channeldb.ErrInvoiceNotFound:
|
||||||
// If we get this error, then it simply means that this invoice
|
// If we get this error, then it simply means that this invoice
|
||||||
|
Loading…
Reference in New Issue
Block a user