channeldb+lnd: rpc server filters payments by date

This commit is contained in:
yyforyongyu
2022-11-16 02:15:24 +08:00
parent b7c829f792
commit e9269c2093
3 changed files with 100 additions and 1 deletions

View File

@ -6359,6 +6359,16 @@ func (r *rpcServer) ListPayments(ctx context.Context,
rpcsLog.Debugf("[ListPayments]")
// If both dates are set, we check that the start date is less than the
// end date, otherwise we'll get an empty result.
if req.CreationDateStart != 0 && req.CreationDateEnd != 0 {
if req.CreationDateStart >= req.CreationDateEnd {
return nil, fmt.Errorf("start date(%v) must be before "+
"end date(%v)", req.CreationDateStart,
req.CreationDateEnd)
}
}
query := channeldb.PaymentsQuery{
IndexOffset: req.IndexOffset,
MaxPayments: req.MaxPayments,
@ -6367,6 +6377,20 @@ func (r *rpcServer) ListPayments(ctx context.Context,
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,
)
}
// If the maximum number of payments wasn't specified, then we'll
// default to return the maximal number of payments representable.
if req.MaxPayments == 0 {