Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

fix: ldk list transactions limit #88

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions handle_list_transactions_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ func (svc *Service) HandleListTransactionsEvent(ctx context.Context, request *Ni
}).Info("Fetching transactions")

limit := listParams.Limit
if limit == 0 {
maxLimit := uint64(50)
if limit == 0 || limit > maxLimit {
// make sure a sensible limit is passed
limit = 50
limit = maxLimit
}
transactions, err := svc.lnClient.ListTransactions(ctx, listParams.From, listParams.Until, limit, listParams.Offset, listParams.Unpaid, listParams.Type)
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions ldk.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"path/filepath"
"sort"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -317,6 +318,7 @@ func (gs *LDKService) LookupInvoice(ctx context.Context, paymentHash string) (tr
func (gs *LDKService) ListTransactions(ctx context.Context, from, until, limit, offset uint64, unpaid bool, invoiceType string) (transactions []Nip47Transaction, err error) {
transactions = []Nip47Transaction{}

// TODO: support pagination
payments := gs.node.ListPayments()

for _, payment := range payments {
Expand All @@ -326,9 +328,12 @@ func (gs *LDKService) ListTransactions(ctx context.Context, from, until, limit,
}

// sort by created date descending
/*sort.SliceStable(transactions, func(i, j int) bool {
sort.SliceStable(transactions, func(i, j int) bool {
return transactions[i].CreatedAt > transactions[j].CreatedAt
})*/
})

// locally limit for now
transactions = transactions[:limit]

return transactions, nil
}
Expand Down
Loading