Skip to content

Commit e77362a

Browse files
authored
Merge pull request #1813 from lightninglabs/feat/addr-receives-pagination
`AddrReceives` pagination and sorting direction.
2 parents 21f385d + b4bba57 commit e77362a

33 files changed

+5610
-1853
lines changed

address/event.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,33 @@ const (
4141
StatusCompleted Status = 3
4242
)
4343

44+
// SortDirection is an enum used to specify the order of returned events.
45+
type SortDirection uint8
46+
47+
const (
48+
// UndefinedSortDirection indicates that the sort direction
49+
// is not specified.
50+
UndefinedSortDirection SortDirection = iota
51+
52+
// DescSortDirection indicates that the sort should be in
53+
// descending order.
54+
DescSortDirection
55+
56+
// AscSortDirection indicates that the sort should be in
57+
// ascending order.
58+
AscSortDirection
59+
)
60+
61+
const (
62+
// DefaultEventQueryLimit is the number of events returned
63+
// when no limit is provided.
64+
DefaultEventQueryLimit = 512
65+
66+
// MaxEventQueryLimit is the maximum number of events that can be
67+
// returned in a single query.
68+
MaxEventQueryLimit = 16384
69+
)
70+
4471
// EventQueryParams holds the set of query params for address events.
4572
type EventQueryParams struct {
4673
// AddrTaprootOutputKey is the optional 32-byte x-only serialized
@@ -65,6 +92,17 @@ type EventQueryParams struct {
6592
// (inclusive). Can be set to nil to return events of all creation
6693
// times.
6794
CreationTimeTo *time.Time
95+
96+
// Offset is the offset into the result set to start returning events.
97+
Offset int32
98+
99+
// Limit is the max number of events that should be returned. If zero,
100+
// then DefaultEventQueryLimit will be used.
101+
Limit int32
102+
103+
// SortDirection is the sort direction to use when returning the
104+
// events. The default zero value sorts the events in ascending order.
105+
SortDirection SortDirection
68106
}
69107

70108
// AssetOutput holds the information about a single asset output that was sent

cmd/commands/addrs.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ const (
158158
limitName = "limit"
159159

160160
offsetName = "offset"
161+
162+
directionName = "direction"
161163
)
162164

163165
var queryAddrsCommand = cli.Command{
@@ -293,6 +295,20 @@ var receivesAddrCommand = cli.Command{
293295
Usage: "filter transfers created before this + " +
294296
"unix timestamp (seconds)",
295297
},
298+
cli.Int64Flag{
299+
Name: limitName,
300+
Usage: "the max number of events returned",
301+
},
302+
cli.Int64Flag{
303+
Name: offsetName,
304+
Usage: "the number of events to skip",
305+
},
306+
cli.StringFlag{
307+
Name: directionName,
308+
Usage: "the sort direction for events (asc or desc). " +
309+
"Defaults to desc.",
310+
Value: "desc",
311+
},
296312
},
297313
Action: addrReceives,
298314
}
@@ -311,10 +327,18 @@ func addrReceives(ctx *cli.Context) error {
311327
addr = ctx.Args().First()
312328
}
313329

330+
direction := taprpc.SortDirection_SORT_DIRECTION_DESC
331+
if ctx.String(directionName) == "asc" {
332+
direction = taprpc.SortDirection_SORT_DIRECTION_ASC
333+
}
334+
314335
resp, err := client.AddrReceives(ctxc, &taprpc.AddrReceivesRequest{
315336
FilterAddr: addr,
316337
StartTimestamp: ctx.Uint64("start_timestamp"),
317338
EndTimestamp: ctx.Uint64("end_timestamp"),
339+
Limit: int32(ctx.Int64(limitName)),
340+
Offset: int32(ctx.Int64(offsetName)),
341+
Direction: direction,
318342
})
319343
if err != nil {
320344
return fmt.Errorf("unable to query addr receives: %w", err)

docs/asset-channel-funding.md

Lines changed: 261 additions & 83 deletions
Large diffs are not rendered by default.

docs/release-notes/release-notes-0.7.0.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
- https://github.com/lightninglabs/taproot-assets/pull/1797
7979
- https://github.com/lightninglabs/taproot-assets/pull/1823
8080
- https://github.com/lightninglabs/taproot-assets/pull/1822
81+
- https://github.com/lightninglabs/taproot-assets/pull/1820
8182

8283
- A new [address version 2 was introduced that supports grouped assets and
8384
custom (sender-defined)
@@ -173,6 +174,9 @@
173174
- The `AddrReceives` RPC now supports timestamp filtering with
174175
[new `StartTimestamp` and `EndTimestamp` fields](https://github.com/lightninglabs/taproot-assets/pull/1794).
175176

177+
- The `AddrReceives` RPC has new fields `limit`, `offset` and `direction` that
178+
allows pagination and sorting. [See PR](https://github.com/lightninglabs/taproot-assets/pull/1813).
179+
176180
## tapcli Additions
177181

178182
- [Rename](https://github.com/lightninglabs/taproot-assets/pull/1682) the mint
@@ -194,6 +198,9 @@
194198
- The `tapcli addrs receives` command now supports
195199
[new `--start_timestamp` and `--end_timestamp` flags](https://github.com/lightninglabs/taproot-assets/pull/1794).
196200

201+
- The `tapcli addrs receives` command now has new flags `--limit`, `--offset` and
202+
`--direction` that allows pagination and sorting. [See PR](https://github.com/lightninglabs/taproot-assets/pull/1813).
203+
197204
- The `fetchsupplycommit` command [now supports](https://github.com/lightninglabs/taproot-assets/pull/1823)
198205
a `--first` flag to fetch the very first supply commitment; if no flag is
199206
provided, it defaults to fetching the latest. Only one of `--first`,

0 commit comments

Comments
 (0)