diff --git a/.pending/improvements/sdk/4536-cli-context-que b/.pending/improvements/sdk/4536-cli-context-que new file mode 100644 index 0000000000..f69dc70d3c --- /dev/null +++ b/.pending/improvements/sdk/4536-cli-context-que @@ -0,0 +1 @@ +#4536 cli context queries return query height and accounts are returned with query height \ No newline at end of file diff --git a/client/context/query.go b/client/context/query.go index fa1cceb5bb..6153baca44 100644 --- a/client/context/query.go +++ b/client/context/query.go @@ -29,28 +29,34 @@ func (ctx CLIContext) GetNode() (rpcclient.Client, error) { return ctx.Client, nil } -// Query performs a query for information about the connected node. -func (ctx CLIContext) Query(path string, data cmn.HexBytes) (res []byte, err error) { +// Query performs a query to a Tendermint node with the provided path. +// It returns the result and height of the query upon success +// or an error if the query fails. +func (ctx CLIContext) Query(path string, data cmn.HexBytes) ([]byte, int64, error) { return ctx.query(path, data) } -// Query information about the connected node with a data payload -func (ctx CLIContext) QueryWithData(path string, data []byte) (res []byte, err error) { +// QueryWithData performs a query to a Tendermint node with the provided path +// and a data payload. It returns the result and height of the query upon success +// or an error if the query fails. +func (ctx CLIContext) QueryWithData(path string, data []byte) ([]byte, int64, error) { return ctx.query(path, data) } -// QueryStore performs a query from a Tendermint node with the provided key and -// store name. -func (ctx CLIContext) QueryStore(key cmn.HexBytes, storeName string) (res []byte, err error) { +// QueryStore performs a query to a Tendermint node with the provided key and +// store name. It returns the result and height of the query upon success +// or an error if the query fails. +func (ctx CLIContext) QueryStore(key cmn.HexBytes, storeName string) ([]byte, int64, error) { return ctx.queryStore(key, storeName, "key") } -// QuerySubspace performs a query from a Tendermint node with the provided -// store name and subspace. -func (ctx CLIContext) QuerySubspace(subspace []byte, storeName string) (res []sdk.KVPair, err error) { - resRaw, err := ctx.queryStore(subspace, storeName, "subspace") +// QuerySubspace performs a query to a Tendermint node with the provided +// store name and subspace. It returns key value pair and height of the query +// upon success or an error if the query fails. +func (ctx CLIContext) QuerySubspace(subspace []byte, storeName string) (res []sdk.KVPair, height int64, err error) { + resRaw, height, err := ctx.queryStore(subspace, storeName, "subspace") if err != nil { - return res, err + return res, height, err } ctx.Codec.MustUnmarshalBinaryLengthPrefixed(resRaw, &res) @@ -134,7 +140,7 @@ func (ctx CLIContext) queryAccount(addr sdk.AccAddress) ([]byte, error) { route := fmt.Sprintf("custom/%s/%s", ctx.AccountStore, authtypes.QueryAccount) - res, err := ctx.QueryWithData(route, bz) + res, _, err := ctx.query(route, bz) if err != nil { return nil, err } @@ -142,12 +148,13 @@ func (ctx CLIContext) queryAccount(addr sdk.AccAddress) ([]byte, error) { return res, nil } -// query performs a query from a Tendermint node with the provided store name -// and path. -func (ctx CLIContext) query(path string, key cmn.HexBytes) (res []byte, err error) { +// query performs a query to a Tendermint node with the provided store name +// and path. It returns the result and height of the query upon success +// or an error if the query fails. +func (ctx CLIContext) query(path string, key cmn.HexBytes) (res []byte, height int64, err error) { node, err := ctx.GetNode() if err != nil { - return res, err + return res, height, err } opts := rpcclient.ABCIQueryOptions{ @@ -157,25 +164,25 @@ func (ctx CLIContext) query(path string, key cmn.HexBytes) (res []byte, err erro result, err := node.ABCIQueryWithOptions(path, key, opts) if err != nil { - return res, err + return res, height, err } resp := result.Response if !resp.IsOK() { - return res, errors.New(resp.Log) + return res, height, errors.New(resp.Log) } // data from trusted node or subspace query doesn't need verification if ctx.TrustNode || !isQueryStoreWithProof(path) { - return resp.Value, nil + return resp.Value, resp.Height, nil } err = ctx.verifyProof(path, resp) if err != nil { - return nil, err + return res, height, err } - return resp.Value, nil + return resp.Value, resp.Height, nil } // Verify verifies the consensus proof at given height. @@ -231,9 +238,10 @@ func (ctx CLIContext) verifyProof(queryPath string, resp abci.ResponseQuery) err return nil } -// queryStore performs a query from a Tendermint node with the provided a store -// name and path. -func (ctx CLIContext) queryStore(key cmn.HexBytes, storeName, endPath string) ([]byte, error) { +// queryStore performs a query to a Tendermint node with the provided a store +// name and path. It returns the result and height of the query upon success +// or an error if the query fails. +func (ctx CLIContext) queryStore(key cmn.HexBytes, storeName, endPath string) ([]byte, int64, error) { path := fmt.Sprintf("/store/%s/%s", storeName, endPath) return ctx.query(path, key) } diff --git a/client/rpc/root.go b/client/rpc/root.go index 889fbc3a4d..eb4b36820d 100644 --- a/client/rpc/root.go +++ b/client/rpc/root.go @@ -35,7 +35,7 @@ func CLIVersionRequestHandler(w http.ResponseWriter, r *http.Request) { // connected node version REST handler endpoint func NodeVersionRequestHandler(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - version, err := cliCtx.Query("/app/version", nil) + version, _, err := cliCtx.Query("/app/version", nil) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/client/utils/utils.go b/client/utils/utils.go index 12e6a5bc46..da9170f9db 100644 --- a/client/utils/utils.go +++ b/client/utils/utils.go @@ -127,12 +127,12 @@ func EnrichWithGas(txBldr authtypes.TxBuilder, cliCtx context.CLIContext, msgs [ // CalculateGas simulates the execution of a transaction and returns // both the estimate obtained by the query and the adjusted amount. -func CalculateGas(queryFunc func(string, common.HexBytes) ([]byte, error), +func CalculateGas(queryFunc func(string, common.HexBytes) ([]byte, int64, error), cdc *codec.Codec, txBytes []byte, adjustment float64) (estimate, adjusted uint64, err error) { // run a simulation (via /app/simulate query) to // estimate gas and update TxBuilder accordingly - rawRes, err := queryFunc("/app/simulate", txBytes) + rawRes, _, err := queryFunc("/app/simulate", txBytes) if err != nil { return } diff --git a/client/utils/utils_test.go b/client/utils/utils_test.go index 94df3e797d..ef666c9edb 100644 --- a/client/utils/utils_test.go +++ b/client/utils/utils_test.go @@ -36,12 +36,12 @@ func TestParseQueryResponse(t *testing.T) { func TestCalculateGas(t *testing.T) { cdc := makeCodec() - makeQueryFunc := func(gasUsed uint64, wantErr bool) func(string, common.HexBytes) ([]byte, error) { - return func(string, common.HexBytes) ([]byte, error) { + makeQueryFunc := func(gasUsed uint64, wantErr bool) func(string, common.HexBytes) ([]byte, int64, error) { + return func(string, common.HexBytes) ([]byte, int64, error) { if wantErr { - return nil, errors.New("") + return nil, 0, errors.New("") } - return cdc.MustMarshalBinaryLengthPrefixed(sdk.Result{GasUsed: gasUsed}), nil + return cdc.MustMarshalBinaryLengthPrefixed(sdk.Result{GasUsed: gasUsed}), 0, nil } } type args struct { diff --git a/x/auth/client/rest/query.go b/x/auth/client/rest/query.go index 68f58aecba..81bffe65ac 100644 --- a/x/auth/client/rest/query.go +++ b/x/auth/client/rest/query.go @@ -12,6 +12,13 @@ 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 + Height int64 `json:"height"` +} + // register REST routes func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, storeName string) { r.HandleFunc( @@ -45,7 +52,7 @@ func QueryAccountRequestHandlerFn( return } - res, err := cliCtx.QueryStore(types.AddressStoreKey(addr), storeName) + res, height, err := cliCtx.QueryStore(types.AddressStoreKey(addr), storeName) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -64,7 +71,7 @@ func QueryAccountRequestHandlerFn( return } - rest.PostProcessResponse(w, cliCtx, account) + rest.PostProcessResponse(w, cliCtx, AccountWithHeight{account, height}) } } @@ -89,7 +96,7 @@ func QueryBalancesRequestHandlerFn( return } - res, err := cliCtx.QueryStore(types.AddressStoreKey(addr), storeName) + res, _, err := cliCtx.QueryStore(types.AddressStoreKey(addr), storeName) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/x/distribution/client/cli/query.go b/x/distribution/client/cli/query.go index 815feb8285..f227e1159c 100644 --- a/x/distribution/client/cli/query.go +++ b/x/distribution/client/cli/query.go @@ -86,7 +86,7 @@ $ %s query distr validator-outstanding-rewards cosmosvaloper1lwjmdnks33xwnmfayc6 return err } - resp, err := cliCtx.QueryWithData( + resp, _, err := cliCtx.QueryWithData( fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryValidatorOutstandingRewards), bz, ) @@ -178,7 +178,7 @@ $ %s query distr slashes cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 0 return err } - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/validator_slashes", queryRoute), bz) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/validator_slashes", queryRoute), bz) if err != nil { return err } @@ -252,7 +252,7 @@ $ %s query distr community-pool RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/community_pool", queryRoute), nil) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/community_pool", queryRoute), nil) if err != nil { return err } diff --git a/x/distribution/client/common/common.go b/x/distribution/client/common/common.go index eb4e3b0598..077933f037 100644 --- a/x/distribution/client/common/common.go +++ b/x/distribution/client/common/common.go @@ -12,25 +12,25 @@ import ( func QueryParams(cliCtx context.CLIContext, queryRoute string) (PrettyParams, error) { route := fmt.Sprintf("custom/%s/params/%s", queryRoute, types.ParamCommunityTax) - retCommunityTax, err := cliCtx.QueryWithData(route, []byte{}) + retCommunityTax, _, err := cliCtx.QueryWithData(route, []byte{}) if err != nil { return PrettyParams{}, err } route = fmt.Sprintf("custom/%s/params/%s", queryRoute, types.ParamBaseProposerReward) - retBaseProposerReward, err := cliCtx.QueryWithData(route, []byte{}) + retBaseProposerReward, _, err := cliCtx.QueryWithData(route, []byte{}) if err != nil { return PrettyParams{}, err } route = fmt.Sprintf("custom/%s/params/%s", queryRoute, types.ParamBonusProposerReward) - retBonusProposerReward, err := cliCtx.QueryWithData(route, []byte{}) + retBonusProposerReward, _, err := cliCtx.QueryWithData(route, []byte{}) if err != nil { return PrettyParams{}, err } route = fmt.Sprintf("custom/%s/params/%s", queryRoute, types.ParamWithdrawAddrEnabled) - retWithdrawAddrEnabled, err := cliCtx.QueryWithData(route, []byte{}) + retWithdrawAddrEnabled, _, err := cliCtx.QueryWithData(route, []byte{}) if err != nil { return PrettyParams{}, err } @@ -47,10 +47,11 @@ func QueryDelegatorTotalRewards(cliCtx context.CLIContext, queryRoute, delAddr s return nil, err } - return cliCtx.QueryWithData( + res, _, err := cliCtx.QueryWithData( fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegatorTotalRewards), cliCtx.Codec.MustMarshalJSON(types.NewQueryDelegatorParams(delegatorAddr)), ) + return res, err } // QueryDelegationRewards queries a delegation rewards. @@ -65,27 +66,30 @@ func QueryDelegationRewards(cliCtx context.CLIContext, queryRoute, delAddr, valA return nil, err } - return cliCtx.QueryWithData( + res, _, err := cliCtx.QueryWithData( fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegationRewards), cliCtx.Codec.MustMarshalJSON(types.NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr)), ) + return res, err } // QueryDelegatorValidators returns delegator's list of validators // it submitted delegations to. func QueryDelegatorValidators(cliCtx context.CLIContext, queryRoute string, delegatorAddr sdk.AccAddress) ([]byte, error) { - return cliCtx.QueryWithData( + res, _, err := cliCtx.QueryWithData( fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegatorValidators), cliCtx.Codec.MustMarshalJSON(types.NewQueryDelegatorParams(delegatorAddr)), ) + return res, err } // QueryValidatorCommission returns a validator's commission. func QueryValidatorCommission(cliCtx context.CLIContext, queryRoute string, validatorAddr sdk.ValAddress) ([]byte, error) { - return cliCtx.QueryWithData( + res, _, err := cliCtx.QueryWithData( fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryValidatorCommission), cliCtx.Codec.MustMarshalJSON(types.NewQueryValidatorCommissionParams(validatorAddr)), ) + return res, err } // WithdrawAllDelegatorRewards builds a multi-message slice to be used diff --git a/x/distribution/client/rest/query.go b/x/distribution/client/rest/query.go index 86ae87f87f..c669135de2 100644 --- a/x/distribution/client/rest/query.go +++ b/x/distribution/client/rest/query.go @@ -115,7 +115,7 @@ func delegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext, queryRoute stri } bz := cliCtx.Codec.MustMarshalJSON(types.NewQueryDelegatorWithdrawAddrParams(delegatorAddr)) - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/withdraw_addr", queryRoute), bz) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/withdraw_addr", queryRoute), bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -232,7 +232,7 @@ func communityPoolHandler(cliCtx context.CLIContext, queryRoute string) http.Han return } - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/community_pool", queryRoute), nil) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/community_pool", queryRoute), nil) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -262,7 +262,7 @@ func outstandingRewardsHandlerFn(cliCtx context.CLIContext, queryRoute string) h } bin := cliCtx.Codec.MustMarshalJSON(types.NewQueryValidatorOutstandingRewardsParams(validatorAddr)) - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/validator_outstanding_rewards", queryRoute), bin) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/validator_outstanding_rewards", queryRoute), bin) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/x/gov/client/cli/query.go b/x/gov/client/cli/query.go index a3d09f509f..e6b3b74897 100644 --- a/x/gov/client/cli/query.go +++ b/x/gov/client/cli/query.go @@ -141,7 +141,7 @@ $ %s query gov proposals --status (DepositPeriod|VotingPeriod|Passed|Rejected) cliCtx := context.NewCLIContext().WithCodec(cdc) - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/proposals", queryRoute), bz) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/proposals", queryRoute), bz) if err != nil { return err } @@ -210,7 +210,7 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk return err } - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/vote", queryRoute), bz) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/vote", queryRoute), bz) if err != nil { return err } @@ -278,7 +278,7 @@ $ %s query gov votes 1 if !(propStatus == types.StatusVotingPeriod || propStatus == types.StatusDepositPeriod) { res, err = gcutils.QueryVotesByTxQuery(cliCtx, params) } else { - res, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/votes", queryRoute), bz) + res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/votes", queryRoute), bz) } if err != nil { @@ -334,7 +334,7 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk return err } - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/deposit", queryRoute), bz) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/deposit", queryRoute), bz) if err != nil { return err } @@ -399,7 +399,7 @@ $ %s query gov deposits 1 if !(propStatus == types.StatusVotingPeriod || propStatus == types.StatusDepositPeriod) { res, err = gcutils.QueryDepositsByTxQuery(cliCtx, params) } else { - res, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/deposits", queryRoute), bz) + res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/deposits", queryRoute), bz) } if err != nil { @@ -452,7 +452,7 @@ $ %s query gov tally 1 } // Query store - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/tally", queryRoute), bz) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/tally", queryRoute), bz) if err != nil { return err } @@ -481,15 +481,15 @@ $ %s query gov params Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) - tp, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/params/tallying", queryRoute), nil) + tp, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/params/tallying", queryRoute), nil) if err != nil { return err } - dp, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/params/deposit", queryRoute), nil) + dp, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/params/deposit", queryRoute), nil) if err != nil { return err } - vp, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/params/voting", queryRoute), nil) + vp, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/params/voting", queryRoute), nil) if err != nil { return err } @@ -527,7 +527,7 @@ $ %s query gov param deposit cliCtx := context.NewCLIContext().WithCodec(cdc) // Query store - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/params/%s", queryRoute, args[0]), nil) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/params/%s", queryRoute, args[0]), nil) if err != nil { return err } diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index 7c89731313..297b21de9f 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -201,7 +201,7 @@ func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/gov/%s/%s", types.QueryParams, paramType), nil) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/gov/%s/%s", types.QueryParams, paramType), nil) if err != nil { rest.WriteErrorResponse(w, http.StatusNotFound, err.Error()) return @@ -240,7 +240,7 @@ func queryProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err := cliCtx.QueryWithData("custom/gov/proposal", bz) + res, _, err := cliCtx.QueryWithData("custom/gov/proposal", bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -273,7 +273,7 @@ func queryDepositsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err := cliCtx.QueryWithData("custom/gov/proposal", bz) + res, _, err := cliCtx.QueryWithData("custom/gov/proposal", bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -291,7 +291,7 @@ func queryDepositsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { if !(propStatus == types.StatusVotingPeriod || propStatus == types.StatusDepositPeriod) { res, err = gcutils.QueryDepositsByTxQuery(cliCtx, params) } else { - res, err = cliCtx.QueryWithData("custom/gov/deposits", bz) + res, _, err = cliCtx.QueryWithData("custom/gov/deposits", bz) } if err != nil { @@ -370,7 +370,7 @@ func queryDepositHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err := cliCtx.QueryWithData("custom/gov/deposit", bz) + res, _, err := cliCtx.QueryWithData("custom/gov/deposit", bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -392,7 +392,7 @@ func queryDepositHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err = cliCtx.QueryWithData("custom/gov/proposal", bz) + res, _, err = cliCtx.QueryWithData("custom/gov/proposal", bz) if err != nil || len(res) == 0 { err := fmt.Errorf("proposalID %d does not exist", proposalID) rest.WriteErrorResponse(w, http.StatusNotFound, err.Error()) @@ -452,7 +452,7 @@ func queryVoteHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err := cliCtx.QueryWithData("custom/gov/vote", bz) + res, _, err := cliCtx.QueryWithData("custom/gov/vote", bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -474,7 +474,7 @@ func queryVoteHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err = cliCtx.QueryWithData("custom/gov/proposal", bz) + res, _, err = cliCtx.QueryWithData("custom/gov/proposal", bz) if err != nil || len(res) == 0 { err := fmt.Errorf("proposalID %d does not exist", proposalID) rest.WriteErrorResponse(w, http.StatusNotFound, err.Error()) @@ -522,7 +522,7 @@ func queryVotesOnProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err := cliCtx.QueryWithData("custom/gov/proposal", bz) + res, _, err := cliCtx.QueryWithData("custom/gov/proposal", bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -540,7 +540,7 @@ func queryVotesOnProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { if !(propStatus == types.StatusVotingPeriod || propStatus == types.StatusDepositPeriod) { res, err = gcutils.QueryVotesByTxQuery(cliCtx, params) } else { - res, err = cliCtx.QueryWithData("custom/gov/votes", bz) + res, _, err = cliCtx.QueryWithData("custom/gov/votes", bz) } if err != nil { @@ -607,7 +607,7 @@ func queryProposalsWithParameterFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err := cliCtx.QueryWithData("custom/gov/proposals", bz) + res, _, err := cliCtx.QueryWithData("custom/gov/proposals", bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -647,7 +647,7 @@ func queryTallyOnProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err := cliCtx.QueryWithData("custom/gov/tally", bz) + res, _, err := cliCtx.QueryWithData("custom/gov/tally", bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/x/gov/client/utils/query.go b/x/gov/client/utils/query.go index 9d94c20cc2..8675b97055 100644 --- a/x/gov/client/utils/query.go +++ b/x/gov/client/utils/query.go @@ -229,7 +229,7 @@ func QueryProposalByID(proposalID uint64, cliCtx context.CLIContext, queryRoute return nil, err } - res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/proposal", queryRoute), bz) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/proposal", queryRoute), bz) if err != nil { return nil, err } diff --git a/x/ibc/client/cli/relay.go b/x/ibc/client/cli/relay.go index 577dcc0d18..071a91109c 100644 --- a/x/ibc/client/cli/relay.go +++ b/x/ibc/client/cli/relay.go @@ -157,7 +157,8 @@ OUTER: } func query(node string, key []byte, storeName string) (res []byte, err error) { - return context.NewCLIContext().WithNodeURI(node).QueryStore(key, storeName) + res, _, err = context.NewCLIContext().WithNodeURI(node).QueryStore(key, storeName) + return res, err } // nolint: unparam diff --git a/x/mint/client/cli/query.go b/x/mint/client/cli/query.go index ce57342a9b..b50e370964 100644 --- a/x/mint/client/cli/query.go +++ b/x/mint/client/cli/query.go @@ -45,7 +45,7 @@ func GetCmdQueryParams(cdc *codec.Codec) *cobra.Command { cliCtx := context.NewCLIContext().WithCodec(cdc) route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParameters) - res, err := cliCtx.QueryWithData(route, nil) + res, _, err := cliCtx.QueryWithData(route, nil) if err != nil { return err } @@ -71,7 +71,7 @@ func GetCmdQueryInflation(cdc *codec.Codec) *cobra.Command { cliCtx := context.NewCLIContext().WithCodec(cdc) route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryInflation) - res, err := cliCtx.QueryWithData(route, nil) + res, _, err := cliCtx.QueryWithData(route, nil) if err != nil { return err } @@ -97,7 +97,7 @@ func GetCmdQueryAnnualProvisions(cdc *codec.Codec) *cobra.Command { cliCtx := context.NewCLIContext().WithCodec(cdc) route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAnnualProvisions) - res, err := cliCtx.QueryWithData(route, nil) + res, _, err := cliCtx.QueryWithData(route, nil) if err != nil { return err } diff --git a/x/mint/client/rest/query.go b/x/mint/client/rest/query.go index 0ee44b37e4..f8083d06a0 100644 --- a/x/mint/client/rest/query.go +++ b/x/mint/client/rest/query.go @@ -37,7 +37,7 @@ func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err := cliCtx.QueryWithData(route, nil) + res, _, err := cliCtx.QueryWithData(route, nil) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -56,7 +56,7 @@ func queryInflationHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err := cliCtx.QueryWithData(route, nil) + res, _, err := cliCtx.QueryWithData(route, nil) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -75,7 +75,7 @@ func queryAnnualProvisionsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc return } - res, err := cliCtx.QueryWithData(route, nil) + res, _, err := cliCtx.QueryWithData(route, nil) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/x/slashing/client/cli/query.go b/x/slashing/client/cli/query.go index de149a79dc..5ca6004af6 100644 --- a/x/slashing/client/cli/query.go +++ b/x/slashing/client/cli/query.go @@ -58,7 +58,7 @@ $ query slashing signing-info cosmosvalconspub1zcjduepqfhvwcmt7p06fvdge consAddr := sdk.ConsAddress(pk.Address()) key := types.GetValidatorSigningInfoKey(consAddr) - res, err := cliCtx.QueryStore(key, storeName) + res, _, err := cliCtx.QueryStore(key, storeName) if err != nil { return err } @@ -88,7 +88,7 @@ $ query slashing params cliCtx := context.NewCLIContext().WithCodec(cdc) route := fmt.Sprintf("custom/%s/parameters", types.QuerierRoute) - res, err := cliCtx.QueryWithData(route, nil) + res, _, err := cliCtx.QueryWithData(route, nil) if err != nil { return err } diff --git a/x/slashing/client/rest/query.go b/x/slashing/client/rest/query.go index cb67893416..e5cdd7966b 100644 --- a/x/slashing/client/rest/query.go +++ b/x/slashing/client/rest/query.go @@ -53,7 +53,7 @@ func signingInfoHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { } route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QuerySigningInfo) - res, err := cliCtx.QueryWithData(route, bz) + res, _, err := cliCtx.QueryWithData(route, bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -85,7 +85,7 @@ func signingInfoHandlerListFn(cliCtx context.CLIContext) http.HandlerFunc { } route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QuerySigningInfos) - res, err := cliCtx.QueryWithData(route, bz) + res, _, err := cliCtx.QueryWithData(route, bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -104,7 +104,7 @@ func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { route := fmt.Sprintf("custom/%s/parameters", types.QuerierRoute) - res, err := cliCtx.QueryWithData(route, nil) + res, _, err := cliCtx.QueryWithData(route, nil) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/x/staking/client/cli/query.go b/x/staking/client/cli/query.go index f9ea5314ec..8f4258b75f 100644 --- a/x/staking/client/cli/query.go +++ b/x/staking/client/cli/query.go @@ -66,7 +66,7 @@ $ %s query staking validator cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhff return err } - res, err := cliCtx.QueryStore(types.GetValidatorKey(addr), storeName) + res, _, err := cliCtx.QueryStore(types.GetValidatorKey(addr), storeName) if err != nil { return err } @@ -98,7 +98,7 @@ $ %s query staking validators RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) - resKVs, err := cliCtx.QuerySubspace(types.ValidatorsKey, storeName) + resKVs, _, err := cliCtx.QuerySubspace(types.ValidatorsKey, storeName) if err != nil { return err } @@ -142,7 +142,7 @@ $ %s query staking unbonding-delegations-from cosmosvaloper1gghjut3ccd8ay0zduzj6 } route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryValidatorUnbondingDelegations) - res, err := cliCtx.QueryWithData(route, bz) + res, _, err := cliCtx.QueryWithData(route, bz) if err != nil { return err } @@ -184,7 +184,7 @@ $ %s query staking redelegations-from cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fx } route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryRedelegations) - res, err := cliCtx.QueryWithData(route, bz) + res, _, err := cliCtx.QueryWithData(route, bz) if err != nil { return err } @@ -233,7 +233,7 @@ $ %s query staking delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosm } route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegation) - res, err := cliCtx.QueryWithData(route, bz) + res, _, err := cliCtx.QueryWithData(route, bz) if err != nil { return err } @@ -278,7 +278,7 @@ $ %s query staking delegations cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p } route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegatorDelegations) - res, err := cliCtx.QueryWithData(route, bz) + res, _, err := cliCtx.QueryWithData(route, bz) if err != nil { return err } @@ -323,7 +323,7 @@ $ %s query staking delegations-to cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ld } route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryValidatorDelegations) - res, err := cliCtx.QueryWithData(route, bz) + res, _, err := cliCtx.QueryWithData(route, bz) if err != nil { return err } @@ -373,7 +373,7 @@ $ %s query staking unbonding-delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld7 } route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryUnbondingDelegation) - res, err := cliCtx.QueryWithData(route, bz) + res, _, err := cliCtx.QueryWithData(route, bz) if err != nil { return err } @@ -413,7 +413,7 @@ $ %s query staking unbonding-delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld7 } route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegatorUnbondingDelegations) - res, err := cliCtx.QueryWithData(route, bz) + res, _, err := cliCtx.QueryWithData(route, bz) if err != nil { return err } @@ -468,7 +468,7 @@ $ %s query staking redelegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p co } route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryRedelegations) - res, err := cliCtx.QueryWithData(route, bz) + res, _, err := cliCtx.QueryWithData(route, bz) if err != nil { return err } @@ -513,7 +513,7 @@ $ %s query staking redelegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p } route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryRedelegations) - res, err := cliCtx.QueryWithData(route, bz) + res, _, err := cliCtx.QueryWithData(route, bz) if err != nil { return err } @@ -546,7 +546,7 @@ $ %s query staking pool RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) - res, err := cliCtx.QueryStore(types.PoolKey, storeName) + res, _, err := cliCtx.QueryStore(types.PoolKey, storeName) if err != nil { return err } @@ -575,7 +575,7 @@ $ %s query staking params cliCtx := context.NewCLIContext().WithCodec(cdc) route := fmt.Sprintf("custom/%s/%s", storeName, types.QueryParameters) - bz, err := cliCtx.QueryWithData(route, nil) + bz, _, err := cliCtx.QueryWithData(route, nil) if err != nil { return err } diff --git a/x/staking/client/rest/query.go b/x/staking/client/rest/query.go index 2d1e66da4a..3a10eb42d3 100644 --- a/x/staking/client/rest/query.go +++ b/x/staking/client/rest/query.go @@ -227,7 +227,7 @@ func redelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err := cliCtx.QueryWithData("custom/staking/redelegations", bz) + res, _, err := cliCtx.QueryWithData("custom/staking/redelegations", bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -279,7 +279,7 @@ func validatorsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { } route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryValidators) - res, err := cliCtx.QueryWithData(route, bz) + res, _, err := cliCtx.QueryWithData(route, bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -311,7 +311,7 @@ func poolHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err := cliCtx.QueryWithData("custom/staking/pool", nil) + res, _, err := cliCtx.QueryWithData("custom/staking/pool", nil) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -329,7 +329,7 @@ func paramsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return } - res, err := cliCtx.QueryWithData("custom/staking/parameters", nil) + res, _, err := cliCtx.QueryWithData("custom/staking/parameters", nil) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return diff --git a/x/staking/client/rest/utils.go b/x/staking/client/rest/utils.go index 488759c468..6730346c9e 100644 --- a/x/staking/client/rest/utils.go +++ b/x/staking/client/rest/utils.go @@ -62,7 +62,7 @@ func queryBonds(cliCtx context.CLIContext, endpoint string) http.HandlerFunc { return } - res, err := cliCtx.QueryWithData(endpoint, bz) + res, _, err := cliCtx.QueryWithData(endpoint, bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -95,7 +95,7 @@ func queryDelegator(cliCtx context.CLIContext, endpoint string) http.HandlerFunc return } - res, err := cliCtx.QueryWithData(endpoint, bz) + res, _, err := cliCtx.QueryWithData(endpoint, bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -128,7 +128,7 @@ func queryValidator(cliCtx context.CLIContext, endpoint string) http.HandlerFunc return } - res, err := cliCtx.QueryWithData(endpoint, bz) + res, _, err := cliCtx.QueryWithData(endpoint, bz) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return