cursors for nft/assets (#400)

This commit is contained in:
Dominic Wong
2022-03-09 16:55:31 +00:00
committed by GitHub
parent 163c24dc17
commit b8e712b97a
4 changed files with 103 additions and 59 deletions

View File

@@ -49,7 +49,6 @@ func (o *OpenSea) Assets(ctx context.Context, req *pb.AssetsRequest, rsp *pb.Ass
params := "?"
limit := int32(20)
offset := int32(0)
order := "desc"
orderBy := ""
@@ -57,10 +56,6 @@ func (o *OpenSea) Assets(ctx context.Context, req *pb.AssetsRequest, rsp *pb.Ass
limit = req.Limit
}
if req.Offset > 0 {
offset = req.Offset
}
if req.Order == "asc" {
order = "asc"
}
@@ -70,8 +65,11 @@ func (o *OpenSea) Assets(ctx context.Context, req *pb.AssetsRequest, rsp *pb.Ass
orderBy = req.OrderBy
}
params += fmt.Sprintf("limit=%d&offset=%d&order_direction=%s",
limit, offset, order)
params += fmt.Sprintf("limit=%d&order_direction=%s", limit, order)
if len(req.Cursor) > 0 {
params += fmt.Sprintf("&cursor=%s", req.Cursor)
}
if len(orderBy) > 0 {
params += "&order_by=" + orderBy
@@ -90,6 +88,8 @@ func (o *OpenSea) Assets(ctx context.Context, req *pb.AssetsRequest, rsp *pb.Ass
for _, asset := range resp.Assets {
rsp.Assets = append(rsp.Assets, assetToPb(asset))
}
rsp.Next = resp.Next
rsp.Previous = resp.Previous
return nil
}