channeldb/invoice: add InvoiceRefByAddr

This commit is contained in:
Conner Fromknecht
2021-03-24 19:48:23 -07:00
parent 438b03afa4
commit be6698447e
2 changed files with 19 additions and 0 deletions

View File

@@ -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.