diff --git a/channeldb/payments.go b/channeldb/payments.go index c2d32ee8a..15bcd8342 100644 --- a/channeldb/payments.go +++ b/channeldb/payments.go @@ -471,13 +471,13 @@ type PaymentsQuery struct { // payment index (complete and incomplete) should be counted. CountTotal bool - // CreationDateStart, if set, filters out all payments with a creation - // date greater than or euqal to it. - CreationDateStart time.Time + // CreationDateStart, expressed in Unix seconds, if set, filters out + // all payments with a creation date greater than or equal to it. + CreationDateStart int64 - // CreationDateEnd, if set, filters out all payments with a creation - // date less than or euqal to it. - CreationDateEnd time.Time + // CreationDateEnd, expressed in Unix seconds, if set, filters out all + // payments with a creation date less than or equal to it. + CreationDateEnd int64 } // PaymentsResponse contains the result of a query to the payments database. @@ -512,11 +512,7 @@ type PaymentsResponse struct { // to a subset of payments by the payments query, containing an offset // index and a maximum number of returned payments. func (d *DB) QueryPayments(query PaymentsQuery) (PaymentsResponse, error) { - var ( - resp PaymentsResponse - startDateSet = !query.CreationDateStart.IsZero() - endDateSet = !query.CreationDateEnd.IsZero() - ) + var resp PaymentsResponse if err := kvdb.View(d, func(tx kvdb.RTx) error { // Get the root payments bucket. @@ -561,20 +557,20 @@ func (d *DB) QueryPayments(query PaymentsQuery) (PaymentsResponse, error) { return false, err } + // Get the creation time in Unix seconds, this always + // rounds down the nanoseconds to full seconds. + createTime := payment.Info.CreationTime.Unix() + // Skip any payments that were created before the // specified time. - if startDateSet && payment.Info.CreationTime.Before( - query.CreationDateStart, - ) { - + if createTime < query.CreationDateStart { return false, nil } // Skip any payments that were created after the // specified time. - if endDateSet && payment.Info.CreationTime.After( - query.CreationDateEnd, - ) { + if query.CreationDateEnd != 0 && + createTime > query.CreationDateEnd { return false, nil } diff --git a/channeldb/payments_test.go b/channeldb/payments_test.go index 37a7e30e7..769f4cc77 100644 --- a/channeldb/payments_test.go +++ b/channeldb/payments_test.go @@ -438,7 +438,7 @@ func TestQueryPayments(t *testing.T) { MaxPayments: 2, Reversed: false, IncludeIncomplete: true, - CreationDateStart: time.Unix(0, 5), + CreationDateStart: 5, }, firstIndex: 5, lastIndex: 6, @@ -452,7 +452,7 @@ func TestQueryPayments(t *testing.T) { MaxPayments: 2, Reversed: false, IncludeIncomplete: true, - CreationDateStart: time.Unix(0, 7), + CreationDateStart: 7, }, firstIndex: 7, lastIndex: 7, @@ -465,8 +465,8 @@ func TestQueryPayments(t *testing.T) { MaxPayments: math.MaxUint64, Reversed: true, IncludeIncomplete: true, - CreationDateStart: time.Unix(0, 3), - CreationDateEnd: time.Unix(0, 5), + CreationDateStart: 3, + CreationDateEnd: 5, }, firstIndex: 3, lastIndex: 5, @@ -509,7 +509,7 @@ func TestQueryPayments(t *testing.T) { } // Override creation time to allow for testing // of CreationDateStart and CreationDateEnd. - info.CreationTime = time.Unix(0, int64(i+1)) + info.CreationTime = time.Unix(int64(i+1), 0) // Create a new payment entry in the database. err = pControl.InitPayment(info.PaymentIdentifier, info) diff --git a/rpcserver.go b/rpcserver.go index eb79e7c7e..e415606b7 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -6637,20 +6637,8 @@ func (r *rpcServer) ListPayments(ctx context.Context, Reversed: req.Reversed, IncludeIncomplete: req.IncludeIncomplete, CountTotal: req.CountTotalPayments, - } - - // Attach the start date if set. - if req.CreationDateStart != 0 { - query.CreationDateStart = time.Unix( - int64(req.CreationDateStart), 0, - ) - } - - // Attach the end date if set. - if req.CreationDateEnd != 0 { - query.CreationDateEnd = time.Unix( - int64(req.CreationDateEnd), 0, - ) + CreationDateStart: int64(req.CreationDateStart), + CreationDateEnd: int64(req.CreationDateEnd), } // If the maximum number of payments wasn't specified, then we'll