Merge PR #4840: Various Updates for Gaia
This commit is contained in:
parent
f218de8141
commit
4b354a782b
|
@ -561,31 +561,37 @@ func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) (res
|
||||||
return sdk.ErrUnknownRequest(fmt.Sprintf("no custom querier found for route %s", path[1])).QueryResult()
|
return sdk.ErrUnknownRequest(fmt.Sprintf("no custom querier found for route %s", path[1])).QueryResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
// cache wrap the commit-multistore for safety
|
// when a client did not provide a query height, manually inject the latest
|
||||||
ctx := sdk.NewContext(
|
if req.Height == 0 {
|
||||||
app.cms.CacheMultiStore(), app.checkState.ctx.BlockHeader(), true, app.logger,
|
req.Height = app.LastBlockHeight()
|
||||||
).WithMinGasPrices(app.minGasPrices)
|
}
|
||||||
|
|
||||||
if req.Height > 0 {
|
|
||||||
cacheMS, err := app.cms.CacheMultiStoreWithVersion(req.Height)
|
cacheMS, err := app.cms.CacheMultiStoreWithVersion(req.Height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sdk.ErrInternal(fmt.Sprintf("failed to load state at height %d; %s", req.Height, err)).QueryResult()
|
return sdk.ErrInternal(
|
||||||
|
fmt.Sprintf(
|
||||||
|
"failed to load state at height %d; %s (latest height: %d)",
|
||||||
|
req.Height, err, app.LastBlockHeight(),
|
||||||
|
),
|
||||||
|
).QueryResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = ctx.WithMultiStore(cacheMS)
|
// cache wrap the commit-multistore for safety
|
||||||
}
|
ctx := sdk.NewContext(
|
||||||
|
cacheMS, app.checkState.ctx.BlockHeader(), true, app.logger,
|
||||||
|
).WithMinGasPrices(app.minGasPrices)
|
||||||
|
|
||||||
// Passes the rest of the path as an argument to the querier.
|
// Passes the rest of the path as an argument to the querier.
|
||||||
//
|
//
|
||||||
// For example, in the path "custom/gov/proposal/test", the gov querier gets
|
// For example, in the path "custom/gov/proposal/test", the gov querier gets
|
||||||
// []string{"proposal", "test"} as the path.
|
// []string{"proposal", "test"} as the path.
|
||||||
resBytes, err := querier(ctx, path[2:], req)
|
resBytes, queryErr := querier(ctx, path[2:], req)
|
||||||
if err != nil {
|
if queryErr != nil {
|
||||||
return abci.ResponseQuery{
|
return abci.ResponseQuery{
|
||||||
Code: uint32(err.Code()),
|
Code: uint32(queryErr.Code()),
|
||||||
Codespace: string(err.Codespace()),
|
Codespace: string(queryErr.Codespace()),
|
||||||
Height: req.Height,
|
Height: req.Height,
|
||||||
Log: err.ABCILog(),
|
Log: queryErr.ABCILog(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,16 +81,6 @@ func (ctx CLIContext) query(path string, key cmn.HexBytes) (res []byte, height i
|
||||||
return res, height, err
|
return res, height, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// When a client did not provide a query height, manually query for it so it can
|
|
||||||
// be injected downstream into responses.
|
|
||||||
if ctx.Height == 0 {
|
|
||||||
status, err := node.Status()
|
|
||||||
if err != nil {
|
|
||||||
return res, height, err
|
|
||||||
}
|
|
||||||
ctx = ctx.WithHeight(status.SyncInfo.LatestBlockHeight)
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := rpcclient.ABCIQueryOptions{
|
opts := rpcclient.ABCIQueryOptions{
|
||||||
Height: ctx.Height,
|
Height: ctx.Height,
|
||||||
Prove: !ctx.TrustNode,
|
Prove: !ctx.TrustNode,
|
||||||
|
|
|
@ -67,6 +67,7 @@ func getBlock(cliCtx context.CLIContext, height *int64) ([]byte, error) {
|
||||||
if cliCtx.Indent {
|
if cliCtx.Indent {
|
||||||
return codec.Cdc.MarshalJSONIndent(res, "", " ")
|
return codec.Cdc.MarshalJSONIndent(res, "", " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
return codec.Cdc.MarshalJSON(res)
|
return codec.Cdc.MarshalJSON(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,10 +77,12 @@ func GetChainHeight(cliCtx context.CLIContext) (int64, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
status, err := node.Status()
|
status, err := node.Status()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
height := status.SyncInfo.LatestBlockHeight
|
height := status.SyncInfo.LatestBlockHeight
|
||||||
return height, nil
|
return height, nil
|
||||||
}
|
}
|
||||||
|
@ -104,6 +107,7 @@ func printBlock(cmd *cobra.Command, args []string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(string(output))
|
fmt.Println(string(output))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -114,27 +118,32 @@ func printBlock(cmd *cobra.Command, args []string) error {
|
||||||
func BlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
func BlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
|
|
||||||
height, err := strconv.ParseInt(vars["height"], 10, 64)
|
height, err := strconv.ParseInt(vars["height"], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rest.WriteErrorResponse(w, http.StatusBadRequest,
|
rest.WriteErrorResponse(w, http.StatusBadRequest,
|
||||||
"couldn't parse block height. Assumed format is '/block/{height}'.")
|
"couldn't parse block height. Assumed format is '/block/{height}'.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
chainHeight, err := GetChainHeight(cliCtx)
|
chainHeight, err := GetChainHeight(cliCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, "failed to parse chain height")
|
rest.WriteErrorResponse(w, http.StatusInternalServerError, "failed to parse chain height")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if height > chainHeight {
|
if height > chainHeight {
|
||||||
rest.WriteErrorResponse(w, http.StatusNotFound, "requested block height is bigger then the chain length")
|
rest.WriteErrorResponse(w, http.StatusNotFound, "requested block height is bigger then the chain length")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err := getBlock(cliCtx, &height)
|
output, err := getBlock(cliCtx, &height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rest.PostProcessResponse(w, cliCtx, output)
|
|
||||||
|
rest.PostProcessResponseBare(w, cliCtx, output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +156,6 @@ func LatestBlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rest.PostProcessResponse(w, cliCtx, output)
|
rest.PostProcessResponseBare(w, cliCtx, output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,9 @@ func printNodeStatus(_ *cobra.Command, _ []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type nodeInfoResponse struct {
|
// NodeInfoResponse defines a response type that contains node status and version
|
||||||
|
// information.
|
||||||
|
type NodeInfoResponse struct {
|
||||||
p2p.DefaultNodeInfo `json:"node_info"`
|
p2p.DefaultNodeInfo `json:"node_info"`
|
||||||
|
|
||||||
ApplicationVersion version.Info `json:"application_version"`
|
ApplicationVersion version.Info `json:"application_version"`
|
||||||
|
@ -79,7 +81,7 @@ func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := nodeInfoResponse{
|
resp := NodeInfoResponse{
|
||||||
DefaultNodeInfo: status.NodeInfo,
|
DefaultNodeInfo: status.NodeInfo,
|
||||||
ApplicationVersion: version.NewInfo(),
|
ApplicationVersion: version.NewInfo(),
|
||||||
}
|
}
|
||||||
|
@ -87,7 +89,8 @@ func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type syncingResponse struct {
|
// SyncingResponse defines a response type that contains node syncing information.
|
||||||
|
type SyncingResponse struct {
|
||||||
Syncing bool `json:"syncing"`
|
Syncing bool `json:"syncing"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +103,6 @@ func NodeSyncingRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rest.PostProcessResponseBare(w, cliCtx, syncingResponse{Syncing: status.SyncInfo.CatchingUp})
|
rest.PostProcessResponseBare(w, cliCtx, SyncingResponse{Syncing: status.SyncInfo.CatchingUp})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,10 +68,10 @@ func waitForHeightTM(height int64, url string) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if resBlock.Block != nil &&
|
if resBlock.Block != nil && resBlock.Block.Height >= height {
|
||||||
resBlock.Block.Height >= height {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * 100)
|
time.Sleep(time.Millisecond * 100)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,7 @@ func StatusOK(statusCode int) bool {
|
||||||
func waitForHeight(height int64, url string) {
|
func waitForHeight(height int64, url string) {
|
||||||
var res *http.Response
|
var res *http.Response
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// Since this is in a testing file we are accepting nolint to be passed
|
// Since this is in a testing file we are accepting nolint to be passed
|
||||||
res, err = http.Get(url) //nolint:gosec
|
res, err = http.Get(url) //nolint:gosec
|
||||||
|
@ -107,21 +108,20 @@ func waitForHeight(height int64, url string) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = res.Body.Close()
|
|
||||||
if err != nil {
|
if err = res.Body.Close(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var resultBlock ctypes.ResultBlock
|
var resultBlock ctypes.ResultBlock
|
||||||
err = cdc.UnmarshalJSON(body, &resultBlock)
|
if err = cdc.UnmarshalJSON(body, &resultBlock); err != nil {
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if resultBlock.Block != nil &&
|
if resultBlock.Block != nil && resultBlock.Block.Height >= height {
|
||||||
resultBlock.Block.Height >= height {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * 100)
|
time.Sleep(time.Millisecond * 100)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,6 +232,8 @@ func ParseQueryHeightOrReturnBadRequest(w http.ResponseWriter, cliCtx context.CL
|
||||||
if height > 0 {
|
if height > 0 {
|
||||||
cliCtx = cliCtx.WithHeight(height)
|
cliCtx = cliCtx.WithHeight(height)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
cliCtx = cliCtx.WithHeight(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
return cliCtx, true
|
return cliCtx, true
|
||||||
|
|
|
@ -48,6 +48,6 @@ func BroadcastTxRequest(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rest.PostProcessResponse(w, cliCtx, res)
|
rest.PostProcessResponseBare(w, cliCtx, res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,6 @@ func EncodeTxRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
txBytesBase64 := base64.StdEncoding.EncodeToString(txBytes)
|
txBytesBase64 := base64.StdEncoding.EncodeToString(txBytes)
|
||||||
|
|
||||||
response := EncodeResp{Tx: txBytesBase64}
|
response := EncodeResp{Tx: txBytesBase64}
|
||||||
rest.PostProcessResponse(w, cliCtx, response)
|
rest.PostProcessResponseBare(w, cliCtx, response)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
|
|
||||||
// query accountREST Handler
|
// query accountREST Handler
|
||||||
func QueryAccountRequestHandlerFn(storeName string, cliCtx context.CLIContext) http.HandlerFunc {
|
func QueryAccountRequestHandlerFn(storeName string, cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
bech32addr := vars["address"]
|
bech32addr := vars["address"]
|
||||||
|
@ -85,7 +84,7 @@ func QueryTxsRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(r.Form) == 0 {
|
if len(r.Form) == 0 {
|
||||||
rest.PostProcessResponse(w, cliCtx, txs)
|
rest.PostProcessResponseBare(w, cliCtx, txs)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +100,7 @@ func QueryTxsRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rest.PostProcessResponse(w, cliCtx, searchResult)
|
rest.PostProcessResponseBare(w, cliCtx, searchResult)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +130,6 @@ func QueryTxRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
rest.WriteErrorResponse(w, http.StatusNotFound, fmt.Sprintf("no transaction found with hash %s", hashHexStr))
|
rest.WriteErrorResponse(w, http.StatusNotFound, fmt.Sprintf("no transaction found with hash %s", hashHexStr))
|
||||||
}
|
}
|
||||||
|
|
||||||
rest.PostProcessResponse(w, cliCtx, output)
|
rest.PostProcessResponseBare(w, cliCtx, output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import (
|
||||||
|
|
||||||
// query accountREST Handler
|
// query accountREST Handler
|
||||||
func QueryBalancesRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
func QueryBalancesRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
|
|
|
@ -37,5 +37,5 @@ func QueryGenesisTxs(cliCtx context.CLIContext, w http.ResponseWriter) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rest.PostProcessResponse(w, cliCtx, genTxs)
|
rest.PostProcessResponseBare(w, cliCtx, genTxs)
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,7 +178,7 @@ func delegatorTxsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rest.PostProcessResponse(w, cliCtx, res)
|
rest.PostProcessResponseBare(w, cliCtx, res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue