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

Commit

Permalink
Merge pull request #88 from getAlby/fix/list-transactions-limit
Browse files Browse the repository at this point in the history
fix: ldk list transactions limit
  • Loading branch information
rolznz authored Mar 5, 2024
2 parents fbcf536 + f4640b5 commit 4ee7041
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
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

0 comments on commit 4ee7041

Please sign in to comment.