Skip to content

Commit

Permalink
fix: add alby offset workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Jun 30, 2024
1 parent 98fa127 commit e3c5d84
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ You can also contribute to our [bounty program](https://github.com/getAlby/light
- ⚠️ fees_paid in response not supported

`list_transactions`
- ⚠️ offset and unpaid in request not supported
- ⚠️ offset only works with multiples of limit e.g. (0, limit, limit * 2)
- ⚠️ unpaid in request not supported
- ⚠️ fees_paid in response not supported
- ⚠️ unsettled and failed transactions will not be returned

Expand Down
12 changes: 10 additions & 2 deletions alby.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,7 @@ func (svc *AlbyOAuthService) ListTransactions(ctx context.Context, senderPubkey
client := svc.oauthConf.Client(ctx, tok)

urlParams := url.Values{}
//urlParams.Add("page", "1")

// TODO: clarify gt/lt vs from to in NWC spec
if from != 0 {
urlParams.Add("q[created_at_gt]", strconv.FormatUint(from, 10))
}
Expand All @@ -393,6 +391,16 @@ func (svc *AlbyOAuthService) ListTransactions(ctx context.Context, senderPubkey
if limit != 0 {
urlParams.Add("items", strconv.FormatUint(limit, 10))
}

// hack to allow offset but only via pagination
if offset != 0 {
if limit == 0 || offset%limit != 0 {
return nil, fmt.Errorf("offset must be a multiple of the limit provided (e.g. 0, %d, %d)", limit, limit*2)
}

urlParams.Add("page", strconv.FormatUint((offset/limit)+1, 10))
}

// TODO: Add Offset and Unpaid

endpoint := "/invoices"
Expand Down

0 comments on commit e3c5d84

Please sign in to comment.