Merge PR #4499: Remove Client Codec Redundancy

This commit is contained in:
Alexander Bezobchuk 2019-06-06 11:43:15 -04:00 committed by GitHub
parent 5b78a7bc19
commit 3180e68c7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 390 additions and 456 deletions

View File

@ -0,0 +1,2 @@
#4479 Remove codec argument redundency in client usage where
the CLIContext's codec should be used instead.

View File

@ -29,7 +29,6 @@ type RestServer struct {
Mux *mux.Router
CliCtx context.CLIContext
KeyBase keybase.Keybase
Cdc *codec.Codec
log log.Logger
listener net.Listener
@ -45,7 +44,6 @@ func NewRestServer(cdc *codec.Codec) *RestServer {
return &RestServer{
Mux: r,
CliCtx: cliCtx,
Cdc: cdc,
log: logger,
}
}

View File

@ -7,19 +7,16 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/auth"
)
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Building / Sending utilities
// WriteGenerateStdTxResponse writes response for the generate only mode.
func WriteGenerateStdTxResponse(w http.ResponseWriter, cdc *codec.Codec,
cliCtx context.CLIContext, br rest.BaseReq, msgs []sdk.Msg) {
func WriteGenerateStdTxResponse(w http.ResponseWriter, cliCtx context.CLIContext, br rest.BaseReq, msgs []sdk.Msg) {
gasAdj, ok := rest.ParseFloat64OrReturnBadRequest(w, br.GasAdjustment, flags.DefaultGasAdjustment)
if !ok {
return
@ -32,7 +29,7 @@ func WriteGenerateStdTxResponse(w http.ResponseWriter, cdc *codec.Codec,
}
txBldr := auth.NewTxBuilder(
utils.GetTxEncoder(cdc), br.AccountNumber, br.Sequence, gas, gasAdj,
utils.GetTxEncoder(cliCtx.Codec), br.AccountNumber, br.Sequence, gas, gasAdj,
br.Simulate, br.ChainID, br.Memo, br.Fees, br.GasPrices,
)
@ -49,7 +46,7 @@ func WriteGenerateStdTxResponse(w http.ResponseWriter, cdc *codec.Codec,
}
if br.Simulate {
rest.WriteSimulationResponse(w, cdc, txBldr.Gas())
rest.WriteSimulationResponse(w, cliCtx.Codec, txBldr.Gas())
return
}
}
@ -60,7 +57,7 @@ func WriteGenerateStdTxResponse(w http.ResponseWriter, cdc *codec.Codec,
return
}
output, err := cdc.MarshalJSON(auth.NewStdTx(stdMsg.Msgs, stdMsg.Fee, nil, stdMsg.Memo))
output, err := cliCtx.Codec.MarshalJSON(auth.NewStdTx(stdMsg.Msgs, stdMsg.Fee, nil, stdMsg.Memo))
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
@ -70,5 +67,6 @@ func WriteGenerateStdTxResponse(w http.ResponseWriter, cdc *codec.Codec,
if _, err := w.Write(output); err != nil {
log.Printf("could not write response: %v", err)
}
return
}

View File

@ -4,11 +4,10 @@ import (
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
)
// Register routes
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
RegisterRPCRoutes(cliCtx, r)
RegisterTxRoutes(cliCtx, r, cdc)
RegisterTxRoutes(cliCtx, r)
}

View File

@ -131,7 +131,7 @@ func BlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, codec.Cdc, output, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, output)
}
}
@ -144,6 +144,6 @@ func LatestBlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}
rest.PostProcessResponse(w, codec.Cdc, output, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, output)
}
}

View File

@ -78,7 +78,7 @@ func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}
nodeInfo := status.NodeInfo
rest.PostProcessResponse(w, codec.Cdc, nodeInfo, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, nodeInfo)
}
}

View File

@ -176,7 +176,7 @@ func ValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, codec.Cdc, output, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, output)
}
}
@ -189,6 +189,6 @@ func LatestValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerF
return
}
rest.PostProcessResponse(w, codec.Cdc, output, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, output)
}
}

View File

@ -26,7 +26,7 @@ type BroadcastReq struct {
// BroadcastTxRequest implements a tx broadcasting handler that is responsible
// for broadcasting a valid and signed tx to a full node. The tx can be
// broadcasted via a sync|async|block mechanism.
func BroadcastTxRequest(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
func BroadcastTxRequest(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req BroadcastReq
@ -36,13 +36,13 @@ func BroadcastTxRequest(cliCtx context.CLIContext, cdc *codec.Codec) http.Handle
return
}
err = cdc.UnmarshalJSON(body, &req)
err = cliCtx.Codec.UnmarshalJSON(body, &req)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
txBytes, err := cdc.MarshalBinaryLengthPrefixed(req.Tx)
txBytes, err := cliCtx.Codec.MarshalBinaryLengthPrefixed(req.Tx)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
@ -56,7 +56,7 @@ func BroadcastTxRequest(cliCtx context.CLIContext, cdc *codec.Codec) http.Handle
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}

View File

@ -28,7 +28,7 @@ type (
// EncodeTxRequestHandlerFn returns the encode tx REST handler. In particular,
// it takes a json-formatted transaction, encodes it to the Amino wire protocol,
// and responds with base64-encoded bytes.
func EncodeTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func EncodeTxRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req auth.StdTx
@ -38,7 +38,7 @@ func EncodeTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.
return
}
err = cdc.UnmarshalJSON(body, &req)
err = cliCtx.Codec.UnmarshalJSON(body, &req)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -55,7 +55,7 @@ func EncodeTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.
txBytesBase64 := base64.StdEncoding.EncodeToString(txBytes)
response := EncodeResp{Tx: txBytesBase64}
rest.PostProcessResponse(w, cdc, response, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, response)
}
}

View File

@ -71,7 +71,7 @@ $ <appcli> query txs --tags '<tag1>:<value1>&<tag2>:<value2>' --page 1 --limit 3
limit := viper.GetInt(flagLimit)
cliCtx := context.NewCLIContext().WithCodec(cdc)
txs, err := SearchTxs(cliCtx, cdc, tmTags, page, limit)
txs, err := SearchTxs(cliCtx, tmTags, page, limit)
if err != nil {
return err
}
@ -114,7 +114,7 @@ func QueryTxCmd(cdc *codec.Codec) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
output, err := queryTx(cdc, cliCtx, args[0])
output, err := queryTx(cliCtx, args[0])
if err != nil {
return err
}
@ -141,7 +141,7 @@ func QueryTxCmd(cdc *codec.Codec) *cobra.Command {
// QueryTxsByTagsRequestHandlerFn implements a REST handler that searches for
// transactions by tags.
func QueryTxsByTagsRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
func QueryTxsByTagsRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var (
tags []string
@ -157,7 +157,7 @@ func QueryTxsByTagsRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec)
}
if len(r.Form) == 0 {
rest.PostProcessResponse(w, cdc, txs, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, txs)
return
}
@ -167,24 +167,24 @@ func QueryTxsByTagsRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec)
return
}
searchResult, err := SearchTxs(cliCtx, cdc, tags, page, limit)
searchResult, err := SearchTxs(cliCtx, tags, page, limit)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, searchResult, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, searchResult)
}
}
// QueryTxRequestHandlerFn implements a REST handler that queries a transaction
// by hash in a committed block.
func QueryTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func QueryTxRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
hashHexStr := vars["hash"]
output, err := queryTx(cdc, cliCtx, hashHexStr)
output, err := queryTx(cliCtx, hashHexStr)
if err != nil {
if strings.Contains(err.Error(), hashHexStr) {
rest.WriteErrorResponse(w, http.StatusNotFound, err.Error())
@ -198,6 +198,6 @@ func QueryTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.H
rest.WriteErrorResponse(w, http.StatusNotFound, fmt.Sprintf("no transaction found with hash %s", hashHexStr))
}
rest.PostProcessResponse(w, cdc, output, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, output)
}
}

View File

@ -4,13 +4,12 @@ import (
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
)
// register REST routes
func RegisterTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(cdc, cliCtx)).Methods("GET")
r.HandleFunc("/txs", QueryTxsByTagsRequestHandlerFn(cliCtx, cdc)).Methods("GET")
r.HandleFunc("/txs", BroadcastTxRequest(cliCtx, cdc)).Methods("POST")
r.HandleFunc("/txs/encode", EncodeTxRequestHandlerFn(cdc, cliCtx)).Methods("POST")
func RegisterTxRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/txs", QueryTxsByTagsRequestHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/txs", BroadcastTxRequest(cliCtx)).Methods("POST")
r.HandleFunc("/txs/encode", EncodeTxRequestHandlerFn(cliCtx)).Methods("POST")
}

View File

@ -17,7 +17,7 @@ import (
// SearchTxs performs a search for transactions for a given set of tags via
// Tendermint RPC. It returns a slice of Info object containing txs and metadata.
// An error is returned if the query fails.
func SearchTxs(cliCtx context.CLIContext, cdc *codec.Codec, tags []string, page, limit int) (*sdk.SearchTxsResult, error) {
func SearchTxs(cliCtx context.CLIContext, tags []string, page, limit int) (*sdk.SearchTxsResult, error) {
if len(tags) == 0 {
return nil, errors.New("must declare at least one tag to search")
}
@ -59,7 +59,7 @@ func SearchTxs(cliCtx context.CLIContext, cdc *codec.Codec, tags []string, page,
return nil, err
}
txs, err := formatTxResults(cdc, resTxs.Txs, resBlocks)
txs, err := formatTxResults(cliCtx.Codec, resTxs.Txs, resBlocks)
if err != nil {
return nil, err
}
@ -140,7 +140,7 @@ func parseTx(cdc *codec.Codec, txBytes []byte) (sdk.Tx, error) {
return tx, nil
}
func queryTx(cdc *codec.Codec, cliCtx context.CLIContext, hashHexStr string) (sdk.TxResponse, error) {
func queryTx(cliCtx context.CLIContext, hashHexStr string) (sdk.TxResponse, error) {
hash, err := hex.DecodeString(hashHexStr)
if err != nil {
return sdk.TxResponse{}, err
@ -167,7 +167,7 @@ func queryTx(cdc *codec.Codec, cliCtx context.CLIContext, hashHexStr string) (sd
return sdk.TxResponse{}, err
}
out, err := formatTxResult(cdc, resTx, resBlocks[resTx.Height])
out, err := formatTxResult(cliCtx.Codec, resTx, resBlocks[resTx.Height])
if err != nil {
return out, err
}

View File

@ -51,7 +51,7 @@ type AppModuleBasic interface {
ValidateGenesis(json.RawMessage) error
// client functionality
RegisterRESTRoutes(context.CLIContext, *mux.Router, *codec.Codec)
RegisterRESTRoutes(context.CLIContext, *mux.Router)
GetTxCmd(*codec.Codec) *cobra.Command
GetQueryCmd(*codec.Codec) *cobra.Command
}
@ -94,11 +94,9 @@ func (bm BasicManager) ValidateGenesis(genesis map[string]json.RawMessage) error
}
// RegisterRestRoutes registers all module rest routes
func (bm BasicManager) RegisterRESTRoutes(
ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
func (bm BasicManager) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
for _, b := range bm {
b.RegisterRESTRoutes(ctx, rtr, cdc)
b.RegisterRESTRoutes(ctx, rtr)
}
}

View File

@ -13,6 +13,7 @@ import (
"github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -197,7 +198,7 @@ func ParseFloat64OrReturnBadRequest(w http.ResponseWriter, s string, defaultIfEm
}
// PostProcessResponse performs post processing for a REST response.
func PostProcessResponse(w http.ResponseWriter, cdc *codec.Codec, response interface{}, indent bool) {
func PostProcessResponse(w http.ResponseWriter, cliCtx context.CLIContext, response interface{}) {
var output []byte
switch response.(type) {
@ -206,10 +207,10 @@ func PostProcessResponse(w http.ResponseWriter, cdc *codec.Codec, response inter
default:
var err error
if indent {
output, err = cdc.MarshalJSONIndent(response, "", " ")
if cliCtx.Indent {
output, err = cliCtx.Codec.MarshalJSONIndent(response, "", " ")
} else {
output, err = cdc.MarshalJSON(response)
output, err = cliCtx.Codec.MarshalJSON(response)
}
if err != nil {
WriteErrorResponse(w, http.StatusInternalServerError, err.Error())

View File

@ -6,7 +6,6 @@ import (
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
@ -14,23 +13,23 @@ import (
)
// register REST routes
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, storeName string) {
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, storeName string) {
r.HandleFunc(
"/auth/accounts/{address}",
QueryAccountRequestHandlerFn(storeName, cdc, context.GetAccountDecoder(cdc), cliCtx),
QueryAccountRequestHandlerFn(storeName, context.GetAccountDecoder(cliCtx.Codec), cliCtx),
).Methods("GET")
r.HandleFunc(
"/bank/balances/{address}",
QueryBalancesRequestHandlerFn(storeName, cdc, context.GetAccountDecoder(cdc), cliCtx),
QueryBalancesRequestHandlerFn(storeName, context.GetAccountDecoder(cliCtx.Codec), cliCtx),
).Methods("GET")
}
// query accountREST Handler
func QueryAccountRequestHandlerFn(
storeName string, cdc *codec.Codec,
decoder types.AccountDecoder, cliCtx context.CLIContext,
storeName string, decoder types.AccountDecoder, cliCtx context.CLIContext,
) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
bech32addr := vars["address"]
@ -49,7 +48,7 @@ func QueryAccountRequestHandlerFn(
// the query will return empty account if there is no data
if len(res) == 0 {
rest.PostProcessResponse(w, cdc, types.BaseAccount{}, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, types.BaseAccount{})
return
}
@ -60,15 +59,15 @@ func QueryAccountRequestHandlerFn(
return
}
rest.PostProcessResponse(w, cdc, account, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, account)
}
}
// query accountREST Handler
func QueryBalancesRequestHandlerFn(
storeName string, cdc *codec.Codec,
decoder types.AccountDecoder, cliCtx context.CLIContext,
storeName string, decoder types.AccountDecoder, cliCtx context.CLIContext,
) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
vars := mux.Vars(r)
@ -88,7 +87,7 @@ func QueryBalancesRequestHandlerFn(
// the query will return empty if there is no data for this account
if len(res) == 0 {
rest.PostProcessResponse(w, cdc, sdk.Coins{}, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, sdk.Coins{})
return
}
@ -99,6 +98,6 @@ func QueryBalancesRequestHandlerFn(
return
}
rest.PostProcessResponse(w, cdc, account.GetCoins(), cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, account.GetCoins())
}
}

View File

@ -50,7 +50,7 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
}
// register rest routes
func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router, _ *codec.Codec) {}
func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router) {}
// get the root tx command of this module
func (AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command { return nil }

View File

@ -50,8 +50,8 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
}
// register rest routes
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
rest.RegisterRoutes(ctx, rtr, cdc, types.StoreKey)
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
rest.RegisterRoutes(ctx, rtr, types.StoreKey)
}
// get the root tx command of this module

View File

@ -15,8 +15,8 @@ import (
)
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
r.HandleFunc("/bank/accounts/{address}/transfers", SendRequestHandlerFn(cdc, cliCtx)).Methods("POST")
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc("/bank/accounts/{address}/transfers", SendRequestHandlerFn(cliCtx)).Methods("POST")
}
// SendReq defines the properties of a send request's body.
@ -32,7 +32,7 @@ func init() {
}
// SendRequestHandlerFn - http request handler to send coins to a address.
func SendRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func SendRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
bech32Addr := vars["address"]
@ -44,7 +44,7 @@ func SendRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Hand
}
var req SendReq
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -60,6 +60,6 @@ func SendRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Hand
}
msg := types.NewMsgSend(fromAddr, toAddr, req.Amount)
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}

View File

@ -54,8 +54,8 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
}
// register rest routes
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
rest.RegisterRoutes(ctx, rtr, cdc)
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
rest.RegisterRoutes(ctx, rtr)
}
// get the root tx command of this module

View File

@ -48,8 +48,7 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
}
// register rest routes
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
}
func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router) {}
// get the root tx command of this module
func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {

View File

@ -127,7 +127,7 @@ $ %s query distr commission cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
return err
}
res, err := common.QueryValidatorCommission(cliCtx, cdc, queryRoute, validatorAddr)
res, err := common.QueryValidatorCommission(cliCtx, queryRoute, validatorAddr)
if err != nil {
return err
}
@ -211,7 +211,7 @@ $ %s query distr rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosval
if len(args) == 2 {
// query for rewards from a particular delegation
resp, err := common.QueryDelegationRewards(cliCtx, cdc, queryRoute, args[0], args[1])
resp, err := common.QueryDelegationRewards(cliCtx, queryRoute, args[0], args[1])
if err != nil {
return err
}
@ -222,7 +222,7 @@ $ %s query distr rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosmosval
}
// query for delegator total rewards
resp, err := common.QueryDelegatorTotalRewards(cliCtx, cdc, queryRoute, args[0])
resp, err := common.QueryDelegatorTotalRewards(cliCtx, queryRoute, args[0])
if err != nil {
return err
}

View File

@ -147,7 +147,7 @@ $ %s tx distr withdraw-all-rewards --from mykey
WithAccountDecoder(cdc)
delAddr := cliCtx.GetFromAddress()
msgs, err := common.WithdrawAllDelegatorRewards(cliCtx, cdc, queryRoute, delAddr)
msgs, err := common.WithdrawAllDelegatorRewards(cliCtx, queryRoute, delAddr)
if err != nil {
return err
}

View File

@ -4,7 +4,6 @@ import (
"fmt"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)
@ -36,14 +35,13 @@ func QueryParams(cliCtx context.CLIContext, queryRoute string) (PrettyParams, er
return PrettyParams{}, err
}
return NewPrettyParams(retCommunityTax, retBaseProposerReward,
retBonusProposerReward, retWithdrawAddrEnabled), nil
return NewPrettyParams(
retCommunityTax, retBaseProposerReward, retBonusProposerReward, retWithdrawAddrEnabled,
), nil
}
// QueryDelegatorTotalRewards queries delegator total rewards.
func QueryDelegatorTotalRewards(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute, delAddr string) ([]byte, error) {
func QueryDelegatorTotalRewards(cliCtx context.CLIContext, queryRoute, delAddr string) ([]byte, error) {
delegatorAddr, err := sdk.AccAddressFromBech32(delAddr)
if err != nil {
return nil, err
@ -51,18 +49,17 @@ func QueryDelegatorTotalRewards(cliCtx context.CLIContext, cdc *codec.Codec,
return cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegatorTotalRewards),
cdc.MustMarshalJSON(types.NewQueryDelegatorParams(delegatorAddr)),
cliCtx.Codec.MustMarshalJSON(types.NewQueryDelegatorParams(delegatorAddr)),
)
}
// QueryDelegationRewards queries a delegation rewards.
func QueryDelegationRewards(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute, delAddr, valAddr string) ([]byte, error) {
func QueryDelegationRewards(cliCtx context.CLIContext, queryRoute, delAddr, valAddr string) ([]byte, error) {
delegatorAddr, err := sdk.AccAddressFromBech32(delAddr)
if err != nil {
return nil, err
}
validatorAddr, err := sdk.ValAddressFromBech32(valAddr)
if err != nil {
return nil, err
@ -70,45 +67,39 @@ func QueryDelegationRewards(cliCtx context.CLIContext, cdc *codec.Codec,
return cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegationRewards),
cdc.MustMarshalJSON(types.NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr)),
cliCtx.Codec.MustMarshalJSON(types.NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr)),
)
}
// QueryDelegatorValidators returns delegator's list of validators
// it submitted delegations to.
func QueryDelegatorValidators(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute string, delegatorAddr sdk.AccAddress) ([]byte, error) {
func QueryDelegatorValidators(cliCtx context.CLIContext, queryRoute string, delegatorAddr sdk.AccAddress) ([]byte, error) {
return cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegatorValidators),
cdc.MustMarshalJSON(types.NewQueryDelegatorParams(delegatorAddr)),
cliCtx.Codec.MustMarshalJSON(types.NewQueryDelegatorParams(delegatorAddr)),
)
}
// QueryValidatorCommission returns a validator's commission.
func QueryValidatorCommission(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute string, validatorAddr sdk.ValAddress) ([]byte, error) {
func QueryValidatorCommission(cliCtx context.CLIContext, queryRoute string, validatorAddr sdk.ValAddress) ([]byte, error) {
return cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryValidatorCommission),
cdc.MustMarshalJSON(types.NewQueryValidatorCommissionParams(validatorAddr)),
cliCtx.Codec.MustMarshalJSON(types.NewQueryValidatorCommissionParams(validatorAddr)),
)
}
// WithdrawAllDelegatorRewards builds a multi-message slice to be used
// to withdraw all delegations rewards for the given delegator.
func WithdrawAllDelegatorRewards(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute string, delegatorAddr sdk.AccAddress) ([]sdk.Msg, error) {
func WithdrawAllDelegatorRewards(cliCtx context.CLIContext, queryRoute string, delegatorAddr sdk.AccAddress) ([]sdk.Msg, error) {
// retrieve the comprehensive list of all validators which the
// delegator had submitted delegations to
bz, err := QueryDelegatorValidators(cliCtx, cdc, queryRoute, delegatorAddr)
bz, err := QueryDelegatorValidators(cliCtx, queryRoute, delegatorAddr)
if err != nil {
return nil, err
}
var validators []sdk.ValAddress
if err := cdc.UnmarshalJSON(bz, &validators); err != nil {
if err := cliCtx.Codec.UnmarshalJSON(bz, &validators); err != nil {
return nil, err
}
@ -128,15 +119,13 @@ func WithdrawAllDelegatorRewards(cliCtx context.CLIContext, cdc *codec.Codec,
// WithdrawValidatorRewardsAndCommission builds a two-message message slice to be
// used to withdraw both validation's commission and self-delegation reward.
func WithdrawValidatorRewardsAndCommission(validatorAddr sdk.ValAddress) ([]sdk.Msg, error) {
commissionMsg := types.NewMsgWithdrawValidatorCommission(validatorAddr)
if err := commissionMsg.ValidateBasic(); err != nil {
return nil, err
}
// build and validate MsgWithdrawDelegatorReward
rewardMsg := types.NewMsgWithdrawDelegatorReward(
sdk.AccAddress(validatorAddr.Bytes()), validatorAddr)
rewardMsg := types.NewMsgWithdrawDelegatorReward(sdk.AccAddress(validatorAddr.Bytes()), validatorAddr)
if err := rewardMsg.ValidateBasic(); err != nil {
return nil, err
}

View File

@ -29,7 +29,7 @@ func TestQueryDelegationRewardsAddrValidation(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := QueryDelegationRewards(ctx, cdc, "", tt.args.delAddr, tt.args.valAddr)
_, err := QueryDelegationRewards(ctx, "", tt.args.delAddr, tt.args.valAddr)
require.True(t, err != nil, tt.wantErr)
})
}

View File

@ -10,114 +10,103 @@ import (
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
)
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router,
cdc *codec.Codec, queryRoute string) {
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, queryRoute string) {
// Get the total rewards balance from all delegations
r.HandleFunc(
"/distribution/delegators/{delegatorAddr}/rewards",
delegatorRewardsHandlerFn(cliCtx, cdc, queryRoute),
delegatorRewardsHandlerFn(cliCtx, queryRoute),
).Methods("GET")
// Query a delegation reward
r.HandleFunc(
"/distribution/delegators/{delegatorAddr}/rewards/{validatorAddr}",
delegationRewardsHandlerFn(cliCtx, cdc, queryRoute),
delegationRewardsHandlerFn(cliCtx, queryRoute),
).Methods("GET")
// Get the rewards withdrawal address
r.HandleFunc(
"/distribution/delegators/{delegatorAddr}/withdraw_address",
delegatorWithdrawalAddrHandlerFn(cliCtx, cdc, queryRoute),
delegatorWithdrawalAddrHandlerFn(cliCtx, queryRoute),
).Methods("GET")
// Validator distribution information
r.HandleFunc(
"/distribution/validators/{validatorAddr}",
validatorInfoHandlerFn(cliCtx, cdc, queryRoute),
validatorInfoHandlerFn(cliCtx, queryRoute),
).Methods("GET")
// Commission and self-delegation rewards of a single a validator
r.HandleFunc(
"/distribution/validators/{validatorAddr}/rewards",
validatorRewardsHandlerFn(cliCtx, cdc, queryRoute),
validatorRewardsHandlerFn(cliCtx, queryRoute),
).Methods("GET")
// Outstanding rewards of a single validator
r.HandleFunc(
"/distribution/validators/{validatorAddr}/outstanding_rewards",
outstandingRewardsHandlerFn(cliCtx, cdc, queryRoute),
outstandingRewardsHandlerFn(cliCtx, queryRoute),
).Methods("GET")
// Get the current distribution parameter values
r.HandleFunc(
"/distribution/parameters",
paramsHandlerFn(cliCtx, cdc, queryRoute),
paramsHandlerFn(cliCtx, queryRoute),
).Methods("GET")
// Get the amount held in the community pool
r.HandleFunc(
"/distribution/community_pool",
communityPoolHandler(cliCtx, cdc, queryRoute),
communityPoolHandler(cliCtx, queryRoute),
).Methods("GET")
}
// HTTP request handler to query the total rewards balance from all delegations
func delegatorRewardsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute string) http.HandlerFunc {
func delegatorRewardsHandlerFn(cliCtx context.CLIContext, queryRoute string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// query for rewards from a particular delegator
res, ok := checkResponseQueryDelegatorTotalRewards(w, cliCtx, cdc, queryRoute,
mux.Vars(r)["delegatorAddr"])
res, ok := checkResponseQueryDelegatorTotalRewards(w, cliCtx, queryRoute, mux.Vars(r)["delegatorAddr"])
if !ok {
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
// HTTP request handler to query a delegation rewards
func delegationRewardsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute string) http.HandlerFunc {
func delegationRewardsHandlerFn(cliCtx context.CLIContext, queryRoute string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// query for rewards from a particular delegation
res, ok := checkResponseQueryDelegationRewards(w, cliCtx, cdc, queryRoute,
mux.Vars(r)["delegatorAddr"], mux.Vars(r)["validatorAddr"])
res, ok := checkResponseQueryDelegationRewards(w, cliCtx, queryRoute, mux.Vars(r)["delegatorAddr"], mux.Vars(r)["validatorAddr"])
if !ok {
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
// HTTP request handler to query a delegation rewards
func delegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute string) http.HandlerFunc {
func delegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext, queryRoute string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
delegatorAddr, ok := checkDelegatorAddressVar(w, r)
if !ok {
return
}
bz := cdc.MustMarshalJSON(types.NewQueryDelegatorWithdrawAddrParams(delegatorAddr))
bz := cliCtx.Codec.MustMarshalJSON(types.NewQueryDelegatorWithdrawAddrParams(delegatorAddr))
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/withdraw_addr", queryRoute), bz)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
@ -140,9 +129,7 @@ func NewValidatorDistInfo(operatorAddr sdk.AccAddress, rewards sdk.DecCoins,
}
// HTTP request handler to query validator's distribution information
func validatorInfoHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute string) http.HandlerFunc {
func validatorInfoHandlerFn(cliCtx context.CLIContext, queryRoute string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
valAddr := mux.Vars(r)["validatorAddr"]
validatorAddr, ok := checkValidatorAddressVar(w, r)
@ -151,36 +138,33 @@ func validatorInfoHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec,
}
// query commission
commissionRes, err := common.QueryValidatorCommission(cliCtx, cdc, queryRoute, validatorAddr)
commissionRes, err := common.QueryValidatorCommission(cliCtx, queryRoute, validatorAddr)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
var valCom types.ValidatorAccumulatedCommission
cdc.MustUnmarshalJSON(commissionRes, &valCom)
cliCtx.Codec.MustUnmarshalJSON(commissionRes, &valCom)
// self bond rewards
delAddr := sdk.AccAddress(validatorAddr)
rewardsRes, ok := checkResponseQueryDelegationRewards(w, cliCtx, cdc, queryRoute,
delAddr.String(), valAddr)
rewardsRes, ok := checkResponseQueryDelegationRewards(w, cliCtx, queryRoute, delAddr.String(), valAddr)
if !ok {
return
}
var rewards sdk.DecCoins
cdc.MustUnmarshalJSON(rewardsRes, &rewards)
cliCtx.Codec.MustUnmarshalJSON(rewardsRes, &rewards)
// Prepare response
res := cdc.MustMarshalJSON(NewValidatorDistInfo(delAddr, rewards, valCom))
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
res := cliCtx.Codec.MustMarshalJSON(NewValidatorDistInfo(delAddr, rewards, valCom))
rest.PostProcessResponse(w, cliCtx, res)
}
}
// HTTP request handler to query validator's commission and self-delegation rewards
func validatorRewardsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute string) http.HandlerFunc {
func validatorRewardsHandlerFn(cliCtx context.CLIContext, queryRoute string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
valAddr := mux.Vars(r)["validatorAddr"]
validatorAddr, ok := checkValidatorAddressVar(w, r)
@ -189,32 +173,29 @@ func validatorRewardsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec,
}
delAddr := sdk.AccAddress(validatorAddr).String()
res, ok := checkResponseQueryDelegationRewards(w, cliCtx, cdc, queryRoute, delAddr, valAddr)
res, ok := checkResponseQueryDelegationRewards(w, cliCtx, queryRoute, delAddr, valAddr)
if !ok {
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
// HTTP request handler to query the distribution params values
func paramsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute string) http.HandlerFunc {
func paramsHandlerFn(cliCtx context.CLIContext, queryRoute string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
params, err := common.QueryParams(cliCtx, queryRoute)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, params, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, params)
}
}
func communityPoolHandler(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute string) http.HandlerFunc {
func communityPoolHandler(cliCtx context.CLIContext, queryRoute string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/community_pool", queryRoute), nil)
if err != nil {
@ -223,39 +204,39 @@ func communityPoolHandler(cliCtx context.CLIContext, cdc *codec.Codec,
}
var result sdk.DecCoins
if err := cdc.UnmarshalJSON(res, &result); err != nil {
if err := cliCtx.Codec.UnmarshalJSON(res, &result); err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, result, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, result)
}
}
// HTTP request handler to query the outstanding rewards
func outstandingRewardsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute string) http.HandlerFunc {
func outstandingRewardsHandlerFn(cliCtx context.CLIContext, queryRoute string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
validatorAddr, ok := checkValidatorAddressVar(w, r)
if !ok {
return
}
bin := cdc.MustMarshalJSON(types.NewQueryValidatorOutstandingRewardsParams(validatorAddr))
bin := cliCtx.Codec.MustMarshalJSON(types.NewQueryValidatorOutstandingRewardsParams(validatorAddr))
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/validator_outstanding_rewards", queryRoute), bin)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
func checkResponseQueryDelegatorTotalRewards(w http.ResponseWriter, cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute, delAddr string) (res []byte, ok bool) {
func checkResponseQueryDelegatorTotalRewards(
w http.ResponseWriter, cliCtx context.CLIContext, queryRoute, delAddr string,
) (res []byte, ok bool) {
res, err := common.QueryDelegatorTotalRewards(cliCtx, cdc, queryRoute, delAddr)
res, err := common.QueryDelegatorTotalRewards(cliCtx, queryRoute, delAddr)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return nil, false
@ -264,10 +245,11 @@ func checkResponseQueryDelegatorTotalRewards(w http.ResponseWriter, cliCtx conte
return res, true
}
func checkResponseQueryDelegationRewards(w http.ResponseWriter, cliCtx context.CLIContext, cdc *codec.Codec,
queryRoute, delAddr, valAddr string) (res []byte, ok bool) {
func checkResponseQueryDelegationRewards(
w http.ResponseWriter, cliCtx context.CLIContext, queryRoute, delAddr, valAddr string,
) (res []byte, ok bool) {
res, err := common.QueryDelegationRewards(cliCtx, cdc, queryRoute, delAddr, valAddr)
res, err := common.QueryDelegationRewards(cliCtx, queryRoute, delAddr, valAddr)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return nil, false

View File

@ -7,7 +7,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
@ -16,23 +15,23 @@ import (
)
// RegisterRoutes register distribution REST routes.
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, queryRoute string) {
registerQueryRoutes(cliCtx, r, cdc, queryRoute)
registerTxRoutes(cliCtx, r, cdc, queryRoute)
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, queryRoute string) {
registerQueryRoutes(cliCtx, r, queryRoute)
registerTxRoutes(cliCtx, r, queryRoute)
}
// ProposalRESTHandler returns a ProposalRESTHandler that exposes the community pool spend REST handler with a given sub-route.
func ProposalRESTHandler(cliCtx context.CLIContext, cdc *codec.Codec) govrest.ProposalRESTHandler {
func ProposalRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler {
return govrest.ProposalRESTHandler{
SubRoute: "community_pool_spend",
Handler: postProposalHandlerFn(cdc, cliCtx),
Handler: postProposalHandlerFn(cliCtx),
}
}
func postProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req CommunityPoolSpendProposalReq
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -49,6 +48,6 @@ func postProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Han
return
}
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}

View File

@ -7,7 +7,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/distribution/client/common"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
@ -15,31 +14,29 @@ import (
"github.com/cosmos/cosmos-sdk/types/rest"
)
func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router,
cdc *codec.Codec, queryRoute string) {
func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, queryRoute string) {
// Withdraw all delegator rewards
r.HandleFunc(
"/distribution/delegators/{delegatorAddr}/rewards",
withdrawDelegatorRewardsHandlerFn(cdc, cliCtx, queryRoute),
withdrawDelegatorRewardsHandlerFn(cliCtx, queryRoute),
).Methods("POST")
// Withdraw delegation rewards
r.HandleFunc(
"/distribution/delegators/{delegatorAddr}/rewards/{validatorAddr}",
withdrawDelegationRewardsHandlerFn(cdc, cliCtx),
withdrawDelegationRewardsHandlerFn(cliCtx),
).Methods("POST")
// Replace the rewards withdrawal address
r.HandleFunc(
"/distribution/delegators/{delegatorAddr}/withdraw_address",
setDelegatorWithdrawalAddrHandlerFn(cdc, cliCtx),
setDelegatorWithdrawalAddrHandlerFn(cliCtx),
).Methods("POST")
// Withdraw validator rewards and commission
r.HandleFunc(
"/distribution/validators/{validatorAddr}/rewards",
withdrawValidatorRewardsHandlerFn(cdc, cliCtx),
withdrawValidatorRewardsHandlerFn(cliCtx),
).Methods("POST")
}
@ -56,13 +53,10 @@ type (
)
// Withdraw delegator rewards
func withdrawDelegatorRewardsHandlerFn(
cdc *codec.Codec, cliCtx context.CLIContext, queryRoute string,
) http.HandlerFunc {
func withdrawDelegatorRewardsHandlerFn(cliCtx context.CLIContext, queryRoute string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req withdrawRewardsReq
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -77,22 +71,22 @@ func withdrawDelegatorRewardsHandlerFn(
return
}
msgs, err := common.WithdrawAllDelegatorRewards(cliCtx, cdc, queryRoute, delAddr)
msgs, err := common.WithdrawAllDelegatorRewards(cliCtx, queryRoute, delAddr)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, msgs)
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, msgs)
}
}
// Withdraw delegation rewards
func withdrawDelegationRewardsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func withdrawDelegationRewardsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req withdrawRewardsReq
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -118,16 +112,16 @@ func withdrawDelegationRewardsHandlerFn(cdc *codec.Codec, cliCtx context.CLICont
return
}
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}
// Replace the rewards withdrawal address
func setDelegatorWithdrawalAddrHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func setDelegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req setWithdrawalAddrReq
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -148,16 +142,16 @@ func setDelegatorWithdrawalAddrHandlerFn(cdc *codec.Codec, cliCtx context.CLICon
return
}
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}
// Withdraw validator rewards and commission
func withdrawValidatorRewardsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func withdrawValidatorRewardsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req withdrawRewardsReq
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -179,7 +173,7 @@ func withdrawValidatorRewardsHandlerFn(cdc *codec.Codec, cliCtx context.CLIConte
return
}
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, msgs)
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, msgs)
}
}
@ -191,6 +185,7 @@ func checkDelegatorAddressVar(w http.ResponseWriter, r *http.Request) (sdk.AccAd
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return nil, false
}
return addr, true
}
@ -200,5 +195,6 @@ func checkValidatorAddressVar(w http.ResponseWriter, r *http.Request) (sdk.ValAd
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return nil, false
}
return addr, true
}

View File

@ -50,8 +50,8 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
}
// register rest routes
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
rest.RegisterRoutes(ctx, rtr, cdc, StoreKey)
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
rest.RegisterRoutes(ctx, rtr, StoreKey)
}
// get the root tx command of this module

View File

@ -49,8 +49,7 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
}
// register rest routes
func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router, _ *codec.Codec) {
}
func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router) {}
// get the root tx command of this module
func (AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command { return nil }

View File

@ -70,7 +70,7 @@ $ %s query gov proposal 1
}
// Query the proposal
res, err := gcutils.QueryProposalByID(proposalID, cliCtx, cdc, queryRoute)
res, err := gcutils.QueryProposalByID(proposalID, cliCtx, queryRoute)
if err != nil {
return err
}
@ -194,7 +194,7 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk
}
// check to see if the proposal is in the store
_, err = gcutils.QueryProposalByID(proposalID, cliCtx, cdc, queryRoute)
_, err = gcutils.QueryProposalByID(proposalID, cliCtx, queryRoute)
if err != nil {
return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err)
}
@ -221,7 +221,7 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk
}
if vote.Empty() {
res, err = gcutils.QueryVoteByTxQuery(cdc, cliCtx, params)
res, err = gcutils.QueryVoteByTxQuery(cliCtx, params)
if err != nil {
return err
}
@ -266,7 +266,7 @@ $ %s query gov votes 1
}
// check to see if the proposal is in the store
res, err := gcutils.QueryProposalByID(proposalID, cliCtx, cdc, queryRoute)
res, err := gcutils.QueryProposalByID(proposalID, cliCtx, queryRoute)
if err != nil {
return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err)
}
@ -276,7 +276,7 @@ $ %s query gov votes 1
propStatus := proposal.Status
if !(propStatus == types.StatusVotingPeriod || propStatus == types.StatusDepositPeriod) {
res, err = gcutils.QueryVotesByTxQuery(cdc, cliCtx, params)
res, err = gcutils.QueryVotesByTxQuery(cliCtx, params)
} else {
res, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/votes", queryRoute), bz)
}
@ -318,7 +318,7 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk
}
// check to see if the proposal is in the store
_, err = gcutils.QueryProposalByID(proposalID, cliCtx, cdc, queryRoute)
_, err = gcutils.QueryProposalByID(proposalID, cliCtx, queryRoute)
if err != nil {
return fmt.Errorf("Failed to fetch proposal-id %d: %s", proposalID, err)
}
@ -343,7 +343,7 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk
cdc.MustUnmarshalJSON(res, &deposit)
if deposit.Empty() {
res, err = gcutils.QueryDepositByTxQuery(cdc, cliCtx, params)
res, err = gcutils.QueryDepositByTxQuery(cliCtx, params)
if err != nil {
return err
}
@ -387,7 +387,7 @@ $ %s query gov deposits 1
}
// check to see if the proposal is in the store
res, err := gcutils.QueryProposalByID(proposalID, cliCtx, cdc, queryRoute)
res, err := gcutils.QueryProposalByID(proposalID, cliCtx, queryRoute)
if err != nil {
return fmt.Errorf("failed to fetch proposal with id %d: %s", proposalID, err)
}
@ -397,7 +397,7 @@ $ %s query gov deposits 1
propStatus := proposal.Status
if !(propStatus == types.StatusVotingPeriod || propStatus == types.StatusDepositPeriod) {
res, err = gcutils.QueryDepositsByTxQuery(cdc, cliCtx, params)
res, err = gcutils.QueryDepositsByTxQuery(cliCtx, params)
} else {
res, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/deposits", queryRoute), bz)
}
@ -439,7 +439,7 @@ $ %s query gov tally 1
}
// check to see if the proposal is in the store
_, err = gcutils.QueryProposalByID(proposalID, cliCtx, cdc, queryRoute)
_, err = gcutils.QueryProposalByID(proposalID, cliCtx, queryRoute)
if err != nil {
return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err)
}
@ -578,7 +578,7 @@ $ %s query gov proposer 1
return fmt.Errorf("proposal-id %s is not a valid uint", args[0])
}
prop, err := gcutils.QueryProposerByTxQuery(cdc, cliCtx, proposalID)
prop, err := gcutils.QueryProposerByTxQuery(cliCtx, proposalID)
if err != nil {
return err
}

View File

@ -9,7 +9,7 @@ import (
)
// function to create the rest handler
type RESTHandlerFn func(context.CLIContext, *codec.Codec) rest.ProposalRESTHandler
type RESTHandlerFn func(context.CLIContext) rest.ProposalRESTHandler
// function to create the cli handler
type CLIHandlerFn func(*codec.Codec) *cobra.Command

View File

@ -9,7 +9,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
@ -35,32 +34,32 @@ type ProposalRESTHandler struct {
}
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, phs []ProposalRESTHandler) {
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, phs []ProposalRESTHandler) {
propSubRtr := r.PathPrefix("/gov/proposals").Subrouter()
for _, ph := range phs {
propSubRtr.HandleFunc(fmt.Sprintf("/%s", ph.SubRoute), ph.Handler).Methods("POST")
}
r.HandleFunc("/gov/proposals", postProposalHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), depositHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), voteHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc("/gov/proposals", postProposalHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), depositHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), voteHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(
fmt.Sprintf("/gov/parameters/{%s}", RestParamsType),
queryParamsHandlerFn(cdc, cliCtx),
queryParamsHandlerFn(cliCtx),
).Methods("GET")
r.HandleFunc("/gov/proposals", queryProposalsWithParameterFn(cdc, cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}", RestProposalID), queryProposalHandlerFn(cdc, cliCtx)).Methods("GET")
r.HandleFunc("/gov/proposals", queryProposalsWithParameterFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}", RestProposalID), queryProposalHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(
fmt.Sprintf("/gov/proposals/{%s}/proposer", RestProposalID),
queryProposerHandlerFn(cdc, cliCtx),
queryProposerHandlerFn(cliCtx),
).Methods("GET")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), queryDepositsHandlerFn(cdc, cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits/{%s}", RestProposalID, RestDepositor), queryDepositHandlerFn(cdc, cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/tally", RestProposalID), queryTallyOnProposalHandlerFn(cdc, cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), queryVotesOnProposalHandlerFn(cdc, cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes/{%s}", RestProposalID, RestVoter), queryVoteHandlerFn(cdc, cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), queryDepositsHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits/{%s}", RestProposalID, RestDepositor), queryDepositHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/tally", RestProposalID), queryTallyOnProposalHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), queryVotesOnProposalHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes/{%s}", RestProposalID, RestVoter), queryVoteHandlerFn(cliCtx)).Methods("GET")
}
// PostProposalReq defines the properties of a proposal request's body.
@ -87,10 +86,10 @@ type VoteReq struct {
Option string `json:"option"` // option from OptionSet chosen by the voter
}
func postProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req PostProposalReq
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -108,11 +107,11 @@ func postProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Han
return
}
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}
func depositHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func depositHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
strProposalID := vars[RestProposalID]
@ -129,7 +128,7 @@ func depositHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerF
}
var req DepositReq
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -145,11 +144,11 @@ func depositHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerF
return
}
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}
func voteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func voteHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
strProposalID := vars[RestProposalID]
@ -166,7 +165,7 @@ func voteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc
}
var req VoteReq
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -188,11 +187,11 @@ func voteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc
return
}
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}
func queryParamsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
paramType := vars[RestParamsType]
@ -203,11 +202,11 @@ func queryParamsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Hand
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
func queryProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func queryProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
strProposalID := vars[RestProposalID]
@ -225,7 +224,7 @@ func queryProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Ha
params := types.NewQueryProposalParams(proposalID)
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -237,11 +236,11 @@ func queryProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Ha
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
func queryDepositsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func queryDepositsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
strProposalID := vars[RestProposalID]
@ -253,7 +252,7 @@ func queryDepositsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Ha
params := types.NewQueryProposalParams(proposalID)
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -266,7 +265,7 @@ func queryDepositsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Ha
}
var proposal types.Proposal
if err := cdc.UnmarshalJSON(res, &proposal); err != nil {
if err := cliCtx.Codec.UnmarshalJSON(res, &proposal); err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
@ -275,7 +274,7 @@ func queryDepositsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Ha
// as they're no longer in state.
propStatus := proposal.Status
if !(propStatus == types.StatusVotingPeriod || propStatus == types.StatusDepositPeriod) {
res, err = gcutils.QueryDepositsByTxQuery(cdc, cliCtx, params)
res, err = gcutils.QueryDepositsByTxQuery(cliCtx, params)
} else {
res, err = cliCtx.QueryWithData("custom/gov/deposits", bz)
}
@ -285,11 +284,11 @@ func queryDepositsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Ha
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
func queryProposerHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func queryProposerHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
strProposalID := vars[RestProposalID]
@ -299,17 +298,17 @@ func queryProposerHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Ha
return
}
res, err := gcutils.QueryProposerByTxQuery(cdc, cliCtx, proposalID)
res, err := gcutils.QueryProposerByTxQuery(cliCtx, proposalID)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
func queryDepositHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func queryDepositHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
strProposalID := vars[RestProposalID]
@ -340,7 +339,7 @@ func queryDepositHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Han
params := types.NewQueryDepositParams(proposalID, depositorAddr)
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -353,7 +352,7 @@ func queryDepositHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Han
}
var deposit types.Deposit
if err := cdc.UnmarshalJSON(res, &deposit); err != nil {
if err := cliCtx.Codec.UnmarshalJSON(res, &deposit); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
@ -362,7 +361,7 @@ func queryDepositHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Han
// which case the deposit would be removed from state and should be queried
// for directly via a txs query.
if deposit.Empty() {
bz, err := cdc.MarshalJSON(types.NewQueryProposalParams(proposalID))
bz, err := cliCtx.Codec.MarshalJSON(types.NewQueryProposalParams(proposalID))
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -375,18 +374,18 @@ func queryDepositHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Han
return
}
res, err = gcutils.QueryDepositByTxQuery(cdc, cliCtx, params)
res, err = gcutils.QueryDepositByTxQuery(cliCtx, params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
func queryVoteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func queryVoteHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
strProposalID := vars[RestProposalID]
@ -417,7 +416,7 @@ func queryVoteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Handle
params := types.NewQueryVoteParams(proposalID, voterAddr)
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -430,7 +429,7 @@ func queryVoteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Handle
}
var vote types.Vote
if err := cdc.UnmarshalJSON(res, &vote); err != nil {
if err := cliCtx.Codec.UnmarshalJSON(res, &vote); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
@ -439,7 +438,7 @@ func queryVoteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Handle
// which case the vote would be removed from state and should be queried for
// directly via a txs query.
if vote.Empty() {
bz, err := cdc.MarshalJSON(types.NewQueryProposalParams(proposalID))
bz, err := cliCtx.Codec.MarshalJSON(types.NewQueryProposalParams(proposalID))
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -452,19 +451,19 @@ func queryVoteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Handle
return
}
res, err = gcutils.QueryVoteByTxQuery(cdc, cliCtx, params)
res, err = gcutils.QueryVoteByTxQuery(cliCtx, params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
// todo: Split this functionality into helper functions to remove the above
func queryVotesOnProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func queryVotesOnProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
strProposalID := vars[RestProposalID]
@ -482,7 +481,7 @@ func queryVotesOnProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext)
params := types.NewQueryProposalParams(proposalID)
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -495,7 +494,7 @@ func queryVotesOnProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext)
}
var proposal types.Proposal
if err := cdc.UnmarshalJSON(res, &proposal); err != nil {
if err := cliCtx.Codec.UnmarshalJSON(res, &proposal); err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
@ -504,7 +503,7 @@ func queryVotesOnProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext)
// as they're no longer in state.
propStatus := proposal.Status
if !(propStatus == types.StatusVotingPeriod || propStatus == types.StatusDepositPeriod) {
res, err = gcutils.QueryVotesByTxQuery(cdc, cliCtx, params)
res, err = gcutils.QueryVotesByTxQuery(cliCtx, params)
} else {
res, err = cliCtx.QueryWithData("custom/gov/votes", bz)
}
@ -514,12 +513,12 @@ func queryVotesOnProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext)
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
// todo: Split this functionality into helper functions to remove the above
func queryProposalsWithParameterFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func queryProposalsWithParameterFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
bechVoterAddr := r.URL.Query().Get(RestVoter)
bechDepositorAddr := r.URL.Query().Get(RestDepositor)
@ -562,7 +561,7 @@ func queryProposalsWithParameterFn(cdc *codec.Codec, cliCtx context.CLIContext)
params.Limit = numLimit
}
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -574,12 +573,12 @@ func queryProposalsWithParameterFn(cdc *codec.Codec, cliCtx context.CLIContext)
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
// todo: Split this functionality into helper functions to remove the above
func queryTallyOnProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func queryTallyOnProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
strProposalID := vars[RestProposalID]
@ -597,7 +596,7 @@ func queryTallyOnProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext)
params := types.NewQueryProposalParams(proposalID)
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -609,6 +608,6 @@ func queryTallyOnProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext)
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}

View File

@ -5,7 +5,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/gov/tags"
"github.com/cosmos/cosmos-sdk/x/gov/types"
)
@ -37,10 +36,7 @@ func (p Proposer) String() string {
//
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
// support configurable pagination.
func QueryDepositsByTxQuery(
cdc *codec.Codec, cliCtx context.CLIContext, params types.QueryProposalParams,
) ([]byte, error) {
func QueryDepositsByTxQuery(cliCtx context.CLIContext, params types.QueryProposalParams) ([]byte, error) {
tags := []string{
fmt.Sprintf("%s='%s'", tags.Action, types.MsgDeposit{}.Type()),
fmt.Sprintf("%s='%s'", tags.ProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
@ -48,7 +44,7 @@ func QueryDepositsByTxQuery(
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
// support configurable pagination.
searchResult, err := tx.SearchTxs(cliCtx, cdc, tags, defaultPage, defaultLimit)
searchResult, err := tx.SearchTxs(cliCtx, tags, defaultPage, defaultLimit)
if err != nil {
return nil, err
}
@ -70,10 +66,10 @@ func QueryDepositsByTxQuery(
}
if cliCtx.Indent {
return cdc.MarshalJSONIndent(deposits, "", " ")
return cliCtx.Codec.MarshalJSONIndent(deposits, "", " ")
}
return cdc.MarshalJSON(deposits)
return cliCtx.Codec.MarshalJSON(deposits)
}
// QueryVotesByTxQuery will query for votes via a direct txs tags query. It
@ -82,10 +78,7 @@ func QueryDepositsByTxQuery(
//
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
// support configurable pagination.
func QueryVotesByTxQuery(
cdc *codec.Codec, cliCtx context.CLIContext, params types.QueryProposalParams,
) ([]byte, error) {
func QueryVotesByTxQuery(cliCtx context.CLIContext, params types.QueryProposalParams) ([]byte, error) {
tags := []string{
fmt.Sprintf("%s='%s'", tags.Action, types.MsgVote{}.Type()),
fmt.Sprintf("%s='%s'", tags.ProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
@ -93,7 +86,7 @@ func QueryVotesByTxQuery(
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
// support configurable pagination.
searchResult, err := tx.SearchTxs(cliCtx, cdc, tags, defaultPage, defaultLimit)
searchResult, err := tx.SearchTxs(cliCtx, tags, defaultPage, defaultLimit)
if err != nil {
return nil, err
}
@ -115,17 +108,14 @@ func QueryVotesByTxQuery(
}
if cliCtx.Indent {
return cdc.MarshalJSONIndent(votes, "", " ")
return cliCtx.Codec.MarshalJSONIndent(votes, "", " ")
}
return cdc.MarshalJSON(votes)
return cliCtx.Codec.MarshalJSON(votes)
}
// QueryVoteByTxQuery will query for a single vote via a direct txs tags query.
func QueryVoteByTxQuery(
cdc *codec.Codec, cliCtx context.CLIContext, params types.QueryVoteParams,
) ([]byte, error) {
func QueryVoteByTxQuery(cliCtx context.CLIContext, params types.QueryVoteParams) ([]byte, error) {
tags := []string{
fmt.Sprintf("%s='%s'", tags.Action, types.MsgVote{}.Type()),
fmt.Sprintf("%s='%s'", tags.ProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
@ -134,7 +124,7 @@ func QueryVoteByTxQuery(
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
// support configurable pagination.
searchResult, err := tx.SearchTxs(cliCtx, cdc, tags, defaultPage, defaultLimit)
searchResult, err := tx.SearchTxs(cliCtx, tags, defaultPage, defaultLimit)
if err != nil {
return nil, err
}
@ -152,10 +142,10 @@ func QueryVoteByTxQuery(
}
if cliCtx.Indent {
return cdc.MarshalJSONIndent(vote, "", " ")
return cliCtx.Codec.MarshalJSONIndent(vote, "", " ")
}
return cdc.MarshalJSON(vote)
return cliCtx.Codec.MarshalJSON(vote)
}
}
}
@ -165,10 +155,7 @@ func QueryVoteByTxQuery(
// QueryDepositByTxQuery will query for a single deposit via a direct txs tags
// query.
func QueryDepositByTxQuery(
cdc *codec.Codec, cliCtx context.CLIContext, params types.QueryDepositParams,
) ([]byte, error) {
func QueryDepositByTxQuery(cliCtx context.CLIContext, params types.QueryDepositParams) ([]byte, error) {
tags := []string{
fmt.Sprintf("%s='%s'", tags.Action, types.MsgDeposit{}.Type()),
fmt.Sprintf("%s='%s'", tags.ProposalID, []byte(fmt.Sprintf("%d", params.ProposalID))),
@ -177,7 +164,7 @@ func QueryDepositByTxQuery(
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
// support configurable pagination.
searchResult, err := tx.SearchTxs(cliCtx, cdc, tags, defaultPage, defaultLimit)
searchResult, err := tx.SearchTxs(cliCtx, tags, defaultPage, defaultLimit)
if err != nil {
return nil, err
}
@ -195,10 +182,10 @@ func QueryDepositByTxQuery(
}
if cliCtx.Indent {
return cdc.MarshalJSONIndent(deposit, "", " ")
return cliCtx.Codec.MarshalJSONIndent(deposit, "", " ")
}
return cdc.MarshalJSON(deposit)
return cliCtx.Codec.MarshalJSON(deposit)
}
}
}
@ -208,10 +195,7 @@ func QueryDepositByTxQuery(
// QueryProposerByTxQuery will query for a proposer of a governance proposal by
// ID.
func QueryProposerByTxQuery(
cdc *codec.Codec, cliCtx context.CLIContext, proposalID uint64,
) (Proposer, error) {
func QueryProposerByTxQuery(cliCtx context.CLIContext, proposalID uint64) (Proposer, error) {
tags := []string{
fmt.Sprintf("%s='%s'", tags.Action, types.MsgSubmitProposal{}.Type()),
fmt.Sprintf("%s='%s'", tags.ProposalID, []byte(fmt.Sprintf("%d", proposalID))),
@ -219,7 +203,7 @@ func QueryProposerByTxQuery(
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
// support configurable pagination.
searchResult, err := tx.SearchTxs(cliCtx, cdc, tags, defaultPage, defaultLimit)
searchResult, err := tx.SearchTxs(cliCtx, tags, defaultPage, defaultLimit)
if err != nil {
return Proposer{}, err
}
@ -233,13 +217,14 @@ func QueryProposerByTxQuery(
}
}
}
return Proposer{}, fmt.Errorf("failed to find the proposer for proposalID %d", proposalID)
}
// QueryProposalByID takes a proposalID and returns a proposal
func QueryProposalByID(proposalID uint64, cliCtx context.CLIContext, cdc *codec.Codec, queryRoute string) ([]byte, error) {
func QueryProposalByID(proposalID uint64, cliCtx context.CLIContext, queryRoute string) ([]byte, error) {
params := types.NewQueryProposalParams(proposalID)
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
return nil, err
}
@ -248,5 +233,6 @@ func QueryProposalByID(proposalID uint64, cliCtx context.CLIContext, cdc *codec.
if err != nil {
return nil, err
}
return res, err
}

View File

@ -63,14 +63,13 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
}
// register rest routes
func (a AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
func (a AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
var proposalRESTHandlers []rest.ProposalRESTHandler
for _, proposalHandler := range a.proposalHandlers {
proposalRESTHandlers = append(proposalRESTHandlers, proposalHandler.RESTHandler(ctx, cdc))
proposalRESTHandlers = append(proposalRESTHandlers, proposalHandler.RESTHandler(ctx))
}
rest.RegisterRoutes(ctx, rtr, cdc, proposalRESTHandlers)
rest.RegisterRoutes(ctx, rtr, proposalRESTHandlers)
}
// get the root tx command of this module

View File

@ -5,8 +5,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/ibc"
@ -15,8 +13,8 @@ import (
)
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, kb keys.Keybase) {
r.HandleFunc("/ibc/{destchain}/{address}/send", TransferRequestHandlerFn(cdc, kb, cliCtx)).Methods("POST")
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc("/ibc/{destchain}/{address}/send", TransferRequestHandlerFn(cliCtx)).Methods("POST")
}
type transferReq struct {
@ -26,7 +24,7 @@ type transferReq struct {
// TransferRequestHandler - http request handler to transfer coins to a address
// on a different chain via IBC.
func TransferRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
func TransferRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
destChainID := vars["destchain"]
@ -39,7 +37,7 @@ func TransferRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.
}
var req transferReq
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -57,6 +55,6 @@ func TransferRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.
packet := ibc.NewIBCPacket(from, to, req.Amount, req.BaseReq.ChainID, destChainID)
msg := ibc.MsgIBCTransfer{IBCPacket: packet}
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}

View File

@ -7,29 +7,28 @@ import (
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/mint/types"
)
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc(
"/minting/parameters",
queryParamsHandlerFn(cdc, cliCtx),
queryParamsHandlerFn(cliCtx),
).Methods("GET")
r.HandleFunc(
"/minting/inflation",
queryInflationHandlerFn(cdc, cliCtx),
queryInflationHandlerFn(cliCtx),
).Methods("GET")
r.HandleFunc(
"/minting/annual-provisions",
queryAnnualProvisionsHandlerFn(cdc, cliCtx),
queryAnnualProvisionsHandlerFn(cliCtx),
).Methods("GET")
}
func queryParamsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParameters)
@ -39,11 +38,11 @@ func queryParamsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Hand
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
func queryInflationHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func queryInflationHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryInflation)
@ -53,11 +52,11 @@ func queryInflationHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.H
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
func queryAnnualProvisionsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func queryAnnualProvisionsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAnnualProvisions)
@ -67,6 +66,6 @@ func queryAnnualProvisionsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext)
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}

View File

@ -4,10 +4,9 @@ import (
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
)
// RegisterRoutes registers minting module REST handlers on the provided router.
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
registerQueryRoutes(cliCtx, r, cdc)
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
registerQueryRoutes(cliCtx, r)
}

View File

@ -50,8 +50,8 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
}
// register rest routes
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
rest.RegisterRoutes(ctx, rtr, cdc)
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
rest.RegisterRoutes(ctx, rtr)
}
// get the root tx command of this module

View File

@ -5,7 +5,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/gov"
@ -16,17 +15,17 @@ import (
// ProposalRESTHandler returns a ProposalRESTHandler that exposes the param
// change REST handler with a given sub-route.
func ProposalRESTHandler(cliCtx context.CLIContext, cdc *codec.Codec) govrest.ProposalRESTHandler {
func ProposalRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler {
return govrest.ProposalRESTHandler{
SubRoute: "param_change",
Handler: postProposalHandlerFn(cdc, cliCtx),
Handler: postProposalHandlerFn(cliCtx),
}
}
func postProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req paramscutils.ParamChangeProposalReq
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -43,6 +42,6 @@ func postProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Han
return
}
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}

View File

@ -38,7 +38,7 @@ func (AppModuleBasic) DefaultGenesis() json.RawMessage { return nil }
func (AppModuleBasic) ValidateGenesis(_ json.RawMessage) error { return nil }
// register rest routes
func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router, _ *codec.Codec) {}
func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router) {}
// get the root tx command of this module
func (AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command { return nil }

View File

@ -7,31 +7,30 @@ import (
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/slashing/types"
)
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc(
"/slashing/validators/{validatorPubKey}/signing_info",
signingInfoHandlerFn(cliCtx, cdc),
signingInfoHandlerFn(cliCtx),
).Methods("GET")
r.HandleFunc(
"/slashing/signing_infos",
signingInfoHandlerListFn(cliCtx, cdc),
signingInfoHandlerListFn(cliCtx),
).Methods("GET")
r.HandleFunc(
"/slashing/parameters",
queryParamsHandlerFn(cdc, cliCtx),
queryParamsHandlerFn(cliCtx),
).Methods("GET")
}
// http request handler to query signing info
func signingInfoHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
func signingInfoHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
pk, err := sdk.GetConsPubKeyBech32(vars["validatorPubKey"])
@ -42,7 +41,7 @@ func signingInfoHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Hand
params := types.NewQuerySigningInfoParams(sdk.ConsAddress(pk.Address()))
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -55,12 +54,12 @@ func signingInfoHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Hand
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
// http request handler to query signing info
func signingInfoHandlerListFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
func signingInfoHandlerListFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
if err != nil {
@ -69,7 +68,7 @@ func signingInfoHandlerListFn(cliCtx context.CLIContext, cdc *codec.Codec) http.
}
params := types.NewQuerySigningInfosParams(page, limit)
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
@ -82,11 +81,11 @@ func signingInfoHandlerListFn(cliCtx context.CLIContext, cdc *codec.Codec) http.
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
func queryParamsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
route := fmt.Sprintf("custom/%s/parameters", types.QuerierRoute)
@ -96,6 +95,6 @@ func queryParamsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Hand
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}

View File

@ -4,11 +4,10 @@ import (
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
)
// RegisterRoutes registers staking-related REST handlers to a router
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
registerQueryRoutes(cliCtx, r, cdc)
registerTxRoutes(cliCtx, r, cdc)
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
registerQueryRoutes(cliCtx, r)
registerTxRoutes(cliCtx, r)
}

View File

@ -8,16 +8,15 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/slashing/types"
)
func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc(
"/slashing/validators/{validatorAddr}/unjail",
unjailRequestHandlerFn(cdc, cliCtx),
unjailRequestHandlerFn(cliCtx),
).Methods("POST")
}
@ -26,14 +25,14 @@ type UnjailReq struct {
BaseReq rest.BaseReq `json:"base_req"`
}
func unjailRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func unjailRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
bech32validator := vars["validatorAddr"]
var req UnjailReq
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -66,6 +65,6 @@ func unjailRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Ha
return
}
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}

View File

@ -53,8 +53,8 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
}
// register rest routes
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
rest.RegisterRoutes(ctx, rtr, cdc)
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
rest.RegisterRoutes(ctx, rtr)
}
// get the root tx command of this module

View File

@ -8,111 +8,110 @@ import (
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
// Get all delegations from a delegator
r.HandleFunc(
"/staking/delegators/{delegatorAddr}/delegations",
delegatorDelegationsHandlerFn(cliCtx, cdc),
delegatorDelegationsHandlerFn(cliCtx),
).Methods("GET")
// Get all unbonding delegations from a delegator
r.HandleFunc(
"/staking/delegators/{delegatorAddr}/unbonding_delegations",
delegatorUnbondingDelegationsHandlerFn(cliCtx, cdc),
delegatorUnbondingDelegationsHandlerFn(cliCtx),
).Methods("GET")
// Get all staking txs (i.e msgs) from a delegator
r.HandleFunc(
"/staking/delegators/{delegatorAddr}/txs",
delegatorTxsHandlerFn(cliCtx, cdc),
delegatorTxsHandlerFn(cliCtx),
).Methods("GET")
// Query all validators that a delegator is bonded to
r.HandleFunc(
"/staking/delegators/{delegatorAddr}/validators",
delegatorValidatorsHandlerFn(cliCtx, cdc),
delegatorValidatorsHandlerFn(cliCtx),
).Methods("GET")
// Query a validator that a delegator is bonded to
r.HandleFunc(
"/staking/delegators/{delegatorAddr}/validators/{validatorAddr}",
delegatorValidatorHandlerFn(cliCtx, cdc),
delegatorValidatorHandlerFn(cliCtx),
).Methods("GET")
// Query a delegation between a delegator and a validator
r.HandleFunc(
"/staking/delegators/{delegatorAddr}/delegations/{validatorAddr}",
delegationHandlerFn(cliCtx, cdc),
delegationHandlerFn(cliCtx),
).Methods("GET")
// Query all unbonding delegations between a delegator and a validator
r.HandleFunc(
"/staking/delegators/{delegatorAddr}/unbonding_delegations/{validatorAddr}",
unbondingDelegationHandlerFn(cliCtx, cdc),
unbondingDelegationHandlerFn(cliCtx),
).Methods("GET")
// Query redelegations (filters in query params)
r.HandleFunc(
"/staking/redelegations",
redelegationsHandlerFn(cliCtx, cdc),
redelegationsHandlerFn(cliCtx),
).Methods("GET")
// Get all validators
r.HandleFunc(
"/staking/validators",
validatorsHandlerFn(cliCtx, cdc),
validatorsHandlerFn(cliCtx),
).Methods("GET")
// Get a single validator info
r.HandleFunc(
"/staking/validators/{validatorAddr}",
validatorHandlerFn(cliCtx, cdc),
validatorHandlerFn(cliCtx),
).Methods("GET")
// Get all delegations to a validator
r.HandleFunc(
"/staking/validators/{validatorAddr}/delegations",
validatorDelegationsHandlerFn(cliCtx, cdc),
validatorDelegationsHandlerFn(cliCtx),
).Methods("GET")
// Get all unbonding delegations from a validator
r.HandleFunc(
"/staking/validators/{validatorAddr}/unbonding_delegations",
validatorUnbondingDelegationsHandlerFn(cliCtx, cdc),
validatorUnbondingDelegationsHandlerFn(cliCtx),
).Methods("GET")
// Get the current state of the staking pool
r.HandleFunc(
"/staking/pool",
poolHandlerFn(cliCtx, cdc),
poolHandlerFn(cliCtx),
).Methods("GET")
// Get the current staking parameter values
r.HandleFunc(
"/staking/parameters",
paramsHandlerFn(cliCtx, cdc),
paramsHandlerFn(cliCtx),
).Methods("GET")
}
// HTTP request handler to query a delegator delegations
func delegatorDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
return queryDelegator(cliCtx, cdc, fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryDelegatorDelegations))
func delegatorDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryDelegator(cliCtx, fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryDelegatorDelegations))
}
// HTTP request handler to query a delegator unbonding delegations
func delegatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
return queryDelegator(cliCtx, cdc, "custom/staking/delegatorUnbondingDelegations")
func delegatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryDelegator(cliCtx, "custom/staking/delegatorUnbondingDelegations")
}
// HTTP request handler to query all staking txs (msgs) from a delegator
func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
func delegatorTxsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var typesQuerySlice []string
vars := mux.Vars(r)
@ -154,29 +153,30 @@ func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Han
}
for _, action := range actions {
foundTxs, errQuery := queryTxs(cliCtx, cdc, action, delegatorAddr)
foundTxs, errQuery := queryTxs(cliCtx, action, delegatorAddr)
if errQuery != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, errQuery.Error())
}
txs = append(txs, foundTxs)
}
res, err := cdc.MarshalJSON(txs)
res, err := cliCtx.Codec.MarshalJSON(txs)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
// HTTP request handler to query an unbonding-delegation
func unbondingDelegationHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
return queryBonds(cliCtx, cdc, "custom/staking/unbondingDelegation")
func unbondingDelegationHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryBonds(cliCtx, "custom/staking/unbondingDelegation")
}
// HTTP request handler to query redelegations
func redelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
func redelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var params types.QueryRedelegationParams
@ -211,7 +211,7 @@ func redelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Ha
params.DstValidatorAddr = dstValidatorAddr
}
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -222,27 +222,28 @@ func redelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Ha
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
// HTTP request handler to query a delegation
func delegationHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
return queryBonds(cliCtx, cdc, fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryDelegation))
func delegationHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryBonds(cliCtx, fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryDelegation))
}
// HTTP request handler to query all delegator bonded validators
func delegatorValidatorsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
return queryDelegator(cliCtx, cdc, "custom/staking/delegatorValidators")
func delegatorValidatorsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryDelegator(cliCtx, "custom/staking/delegatorValidators")
}
// HTTP request handler to get information from a currently bonded validator
func delegatorValidatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
return queryBonds(cliCtx, cdc, "custom/staking/delegatorValidator")
func delegatorValidatorHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryBonds(cliCtx, "custom/staking/delegatorValidator")
}
// HTTP request handler to query list of validators
func validatorsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
func validatorsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
if err != nil {
@ -256,7 +257,7 @@ func validatorsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Handl
}
params := types.NewQueryValidatorsParams(page, limit, status)
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -268,45 +269,47 @@ func validatorsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Handl
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
// HTTP request handler to query the validator information from a given validator address
func validatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
return queryValidator(cliCtx, cdc, "custom/staking/validator")
func validatorHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryValidator(cliCtx, "custom/staking/validator")
}
// HTTP request handler to query all unbonding delegations from a validator
func validatorDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
return queryValidator(cliCtx, cdc, fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryValidatorDelegations))
func validatorDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryValidator(cliCtx, fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryValidatorDelegations))
}
// HTTP request handler to query all unbonding delegations from a validator
func validatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
return queryValidator(cliCtx, cdc, "custom/staking/validatorUnbondingDelegations")
func validatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryValidator(cliCtx, "custom/staking/validatorUnbondingDelegations")
}
// HTTP request handler to query the pool information
func poolHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
func poolHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
res, err := cliCtx.QueryWithData("custom/staking/pool", nil)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
// HTTP request handler to query the staking params values
func paramsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc {
func paramsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
res, err := cliCtx.QueryWithData("custom/staking/parameters", nil)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}

View File

@ -4,11 +4,10 @@ import (
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
)
// RegisterRoutes registers staking-related REST handlers to a router
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
registerQueryRoutes(cliCtx, r, cdc)
registerTxRoutes(cliCtx, r, cdc)
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
registerQueryRoutes(cliCtx, r)
registerTxRoutes(cliCtx, r)
}

View File

@ -8,24 +8,23 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc(
"/staking/delegators/{delegatorAddr}/delegations",
postDelegationsHandlerFn(cdc, cliCtx),
postDelegationsHandlerFn(cliCtx),
).Methods("POST")
r.HandleFunc(
"/staking/delegators/{delegatorAddr}/unbonding_delegations",
postUnbondingDelegationsHandlerFn(cdc, cliCtx),
postUnbondingDelegationsHandlerFn(cliCtx),
).Methods("POST")
r.HandleFunc(
"/staking/delegators/{delegatorAddr}/redelegations",
postRedelegationsHandlerFn(cdc, cliCtx),
postRedelegationsHandlerFn(cliCtx),
).Methods("POST")
}
@ -56,11 +55,11 @@ type (
}
)
func postDelegationsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func postDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req DelegateRequest
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -86,15 +85,15 @@ func postDelegationsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.
return
}
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}
func postRedelegationsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func postRedelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req RedelegateRequest
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -120,15 +119,15 @@ func postRedelegationsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) htt
return
}
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}
func postUnbondingDelegationsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
func postUnbondingDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req UndelegateRequest
if !rest.ReadRESTReq(w, r, cdc, &req) {
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
@ -154,6 +153,6 @@ func postUnbondingDelegationsHandlerFn(cdc *codec.Codec, cliCtx context.CLIConte
return
}
clientrest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
clientrest.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}

View File

@ -8,7 +8,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/staking/tags"
@ -26,7 +25,7 @@ func contains(stringSlice []string, txType string) bool {
}
// queries staking txs
func queryTxs(cliCtx context.CLIContext, cdc *codec.Codec, tag string, delegatorAddr string) (*sdk.SearchTxsResult, error) {
func queryTxs(cliCtx context.CLIContext, tag string, delegatorAddr string) (*sdk.SearchTxsResult, error) {
page := 1
limit := 100
tags := []string{
@ -34,10 +33,10 @@ func queryTxs(cliCtx context.CLIContext, cdc *codec.Codec, tag string, delegator
fmt.Sprintf("%s='%s'", tags.Sender, delegatorAddr),
}
return tx.SearchTxs(cliCtx, cdc, tags, page, limit)
return tx.SearchTxs(cliCtx, tags, page, limit)
}
func queryBonds(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string) http.HandlerFunc {
func queryBonds(cliCtx context.CLIContext, endpoint string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
bech32delegator := vars["delegatorAddr"]
@ -52,7 +51,7 @@ func queryBonds(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string) ht
params := types.NewQueryBondsParams(delegatorAddr, validatorAddr)
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -63,11 +62,11 @@ func queryBonds(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string) ht
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
func queryDelegator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string) http.HandlerFunc {
func queryDelegator(cliCtx context.CLIContext, endpoint string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
bech32delegator := vars["delegatorAddr"]
@ -80,7 +79,7 @@ func queryDelegator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string
params := types.NewQueryDelegatorParams(delegatorAddr)
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -91,11 +90,11 @@ func queryDelegator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
func queryValidator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string) http.HandlerFunc {
func queryValidator(cliCtx context.CLIContext, endpoint string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
bech32validatorAddr := vars["validatorAddr"]
@ -108,7 +107,7 @@ func queryValidator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string
params := types.NewQueryValidatorParams(validatorAddr)
bz, err := cdc.MarshalJSON(params)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@ -119,6 +118,6 @@ func queryValidator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}

View File

@ -57,8 +57,8 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
}
// register rest routes
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router, cdc *codec.Codec) {
rest.RegisterRoutes(ctx, rtr, cdc)
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
rest.RegisterRoutes(ctx, rtr)
}
// get the root tx command of this module