mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-29 23:21:12 +02:00
channeldb+lnd: rpc server filters invoices by date
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user