channeldb+lnd: rpc server filters invoices by date

This commit is contained in:
yyforyongyu
2022-11-16 02:03:16 +08:00
parent cfa2cb01d0
commit 234b9a3d97
3 changed files with 165 additions and 1 deletions

View File

@@ -1279,6 +1279,14 @@ type InvoiceQuery struct {
// Reversed, if set, indicates that the invoices returned should start
// from the IndexOffset and go backwards.
Reversed bool
// CreationDateStart, if set, filters out all invoices with a creation
// date greater than or euqal to it.
CreationDateStart time.Time
// CreationDateEnd, if set, filters out all invoices with a creation
// date less than or euqal to it.
CreationDateEnd time.Time
}
// InvoiceSlice is the response to a invoice query. It includes the original
@@ -1309,7 +1317,11 @@ type InvoiceSlice struct {
// QueryInvoices allows a caller to query the invoice database for invoices
// within the specified add index range.
func (d *DB) QueryInvoices(q InvoiceQuery) (InvoiceSlice, error) {
var resp InvoiceSlice
var (
resp InvoiceSlice
startDateSet = !q.CreationDateStart.IsZero()
endDateSet = !q.CreationDateEnd.IsZero()
)
err := kvdb.View(d, func(tx kvdb.RTx) error {
// If the bucket wasn't found, then there aren't any invoices
@@ -1349,6 +1361,24 @@ func (d *DB) QueryInvoices(q InvoiceQuery) (InvoiceSlice, error) {
return false, nil
}
// Skip any invoices that were created before the
// specified time.
if startDateSet && invoice.CreationDate.Before(
q.CreationDateStart,
) {
return false, nil
}
// Skip any invoices that were created after the
// specified time.
if endDateSet && invoice.CreationDate.After(
q.CreationDateEnd,
) {
return false, nil
}
// At this point, we've exhausted the offset, so we'll
// begin collecting invoices found within the range.
resp.Invoices = append(resp.Invoices, invoice)