Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: generalize query response with height #4573

Merged
merged 19 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .pending/improvements/sdk/4573-adds-height-in-
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4573 adds height in response for validator endpoints
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions types/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ type GasEstimateResponse struct {
GasEstimate uint64 `json:"gas_estimate"`
}

// ResponseWithHeight wraps the embedded interface with the height it was queried
// at.
type ResponseWithHeight struct {
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
RespValue interface{} `json:"response"`
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
Height int64 `json:"height"`
}

// BaseReq defines a structure that can be embedded in other request structures
// that all share common "base" fields.
type BaseReq struct {
Expand Down
9 changes: 1 addition & 8 deletions x/auth/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/types"
)

// AccountWithHeight wraps the embedded Account with the height it was queried
// at.
type AccountWithHeight struct {
types.Account `json:"account"`
Height int64 `json:"height"`
}

// query accountREST Handler
func QueryAccountRequestHandlerFn(
storeName string, decoder types.AccountDecoder, cliCtx context.CLIContext,
Expand Down Expand Up @@ -60,7 +53,7 @@ func QueryAccountRequestHandlerFn(
return
}

rest.PostProcessResponse(w, cliCtx, AccountWithHeight{account, height})
rest.PostProcessResponse(w, cliCtx, rest.ResponseWithHeight{account, height})
}
}

Expand Down
4 changes: 2 additions & 2 deletions x/staking/client/rest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ func queryValidator(cliCtx context.CLIContext, endpoint string) http.HandlerFunc
return
}

res, _, err := cliCtx.QueryWithData(endpoint, bz)
res, height, err := cliCtx.QueryWithData(endpoint, bz)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cliCtx, res)
rest.PostProcessResponse(w, cliCtx, rest.ResponseWithHeight{res, height})
}
}