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

Commit

Permalink
feat: add ldk pagination and filtering, support unpaid parameter (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz authored May 5, 2024
1 parent 3c7915f commit 27df9ae
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions ldk.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,22 @@ func (gs *LDKService) ListTransactions(ctx context.Context, from, until, limit,
payments := gs.node.ListPayments()

for _, payment := range payments {
if payment.Status == ldk_node.PaymentStatusSucceeded {
if payment.Status == ldk_node.PaymentStatusSucceeded || unpaid {
transaction, err := gs.ldkPaymentToTransaction(&payment)

if err != nil {
gs.svc.Logger.Errorf("Failed to map transaction: %v", err)
continue
}

// locally filter
if from != 0 && uint64(transaction.CreatedAt) < from {
continue
}
if until != 0 && uint64(transaction.CreatedAt) > until {
continue
}

transactions = append(transactions, *transaction)
}
}
Expand All @@ -534,7 +542,14 @@ func (gs *LDKService) ListTransactions(ctx context.Context, from, until, limit,
return transactions[i].CreatedAt > transactions[j].CreatedAt
})

// locally limit for now
if offset > 0 {
if offset < uint64(len(transactions)) {
transactions = transactions[offset:]
} else {
transactions = []Nip47Transaction{}
}
}

if len(transactions) > int(limit) {
transactions = transactions[:limit]
}
Expand Down

0 comments on commit 27df9ae

Please sign in to comment.