Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions go/shared/cosmossdk/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ func (a *API) Root(w http.ResponseWriter, r *http.Request) {
func (a *API) ValidatePagingParams(w http.ResponseWriter, r *http.Request, defaultPageSize int, maxPageSize *int) (string, int, error) {
cursor := r.URL.Query().Get("cursor")

if cursor != "" {
c := &Cursor{}
if err := c.Decode(cursor); err != nil {
api.HandleError(w, http.StatusBadRequest, "invalid cursor")
return cursor, 0, fmt.Errorf("invalid cursor: %w", err)
}

// reject nil state entries to avoid a downstream nil pointer dereference
for source, state := range c.State {
if state == nil {
api.HandleError(w, http.StatusBadRequest, "invalid cursor")
return cursor, 0, fmt.Errorf("invalid cursor: nil state for source %q", source)
}
}
}

pageSizeQ := r.URL.Query().Get("pageSize")
if pageSizeQ == "" {
pageSizeQ = strconv.Itoa(defaultPageSize)
Expand Down
Loading