Skip to content

Commit 300b489

Browse files
committed
rpc: add pagination and sorting to AddrReceives endpoint
1 parent 66c30c6 commit 300b489

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

rpcserver.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,6 +2224,28 @@ func (r *rpcServer) AddrReceives(ctx context.Context,
22242224

22252225
var sqlQuery address.EventQueryParams
22262226

2227+
if req.Offset < 0 {
2228+
return nil, fmt.Errorf("offset must be non-negative")
2229+
}
2230+
if req.Limit < 0 {
2231+
return nil, fmt.Errorf("limit must be non-negative")
2232+
}
2233+
2234+
sqlQuery.Offset = req.Offset
2235+
sqlQuery.Limit = req.Limit
2236+
2237+
switch req.Direction {
2238+
case 0:
2239+
sqlQuery.SortDirection = address.SortAscending
2240+
2241+
case 1:
2242+
sqlQuery.SortDirection = address.SortDescending
2243+
2244+
default:
2245+
return nil, fmt.Errorf("invalid sort direction: %v",
2246+
req.Direction)
2247+
}
2248+
22272249
if len(req.FilterAddr) > 0 {
22282250
addr, err := address.DecodeAddress(
22292251
req.FilterAddr, &r.cfg.ChainParams,

0 commit comments

Comments
 (0)