channeldb/invoice: add InvoiceRefByAddr
This commit is contained in:
parent
438b03afa4
commit
be6698447e
@ -1225,6 +1225,13 @@ func TestInvoiceRef(t *testing.T) {
|
||||
require.Equal(t, lntypes.Hash{}, refBySetID.PayHash())
|
||||
require.Equal(t, (*[32]byte)(nil), refBySetID.PayAddr())
|
||||
require.Equal(t, &setID, refBySetID.SetID())
|
||||
|
||||
// An InvoiceRef by pay addr should only return a pay addr, but nil for
|
||||
// pay hash and set id.
|
||||
refByAddr := InvoiceRefByAddr(payAddr)
|
||||
require.Equal(t, (*lntypes.Hash)(nil), refByAddr.PayHash())
|
||||
require.Equal(t, &payAddr, refByAddr.PayAddr())
|
||||
require.Equal(t, (*[32]byte)(nil), refByAddr.SetID())
|
||||
}
|
||||
|
||||
// TestHTLCSet asserts that HTLCSet returns the proper set of accepted HTLCs
|
||||
|
@ -236,6 +236,14 @@ func InvoiceRefByHashAndAddr(payHash lntypes.Hash,
|
||||
}
|
||||
}
|
||||
|
||||
// InvoiceRefByAddr creates an InvoiceRef that queries the payment addr index
|
||||
// for an invoice with the provided payment address.
|
||||
func InvoiceRefByAddr(addr [32]byte) InvoiceRef {
|
||||
return InvoiceRef{
|
||||
payAddr: &addr,
|
||||
}
|
||||
}
|
||||
|
||||
// InvoiceRefBySetID creates an InvoiceRef that queries the set id index for an
|
||||
// invoice with the provided setID. If the invoice is not found, the query will
|
||||
// not fallback to payHash or payAddr.
|
||||
@ -903,6 +911,10 @@ func fetchInvoiceNumByRef(invoiceIndex, payAddrIndex, setIDIndex kvdb.RBucket,
|
||||
|
||||
return invoiceNumByAddr, nil
|
||||
|
||||
// Return invoices by payment addr only.
|
||||
case invoiceNumByAddr != nil:
|
||||
return invoiceNumByAddr, nil
|
||||
|
||||
// If we were only able to reference the invoice by hash, return the
|
||||
// corresponding invoice number. This can happen when no payment address
|
||||
// was provided, or if it didn't match anything in our records.
|
||||
|
Loading…
Reference in New Issue
Block a user