Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client/utils/ reorganization
Browse files Browse the repository at this point in the history
Move REST-related types and functions out of client/utils
into a new client/rest package.
Alessio Treglia committed Feb 4, 2019
1 parent 1ae7cee commit ee9ea20
Showing 24 changed files with 404 additions and 377 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ BREAKING CHANGES
* Gaia

* SDK
* [\#3487](https://github.com/cosmos/cosmos-sdk/pull/3487) Move HTTP/REST utilities out of client/utils into a new dedicated client/rest package.

* Tendermint

12 changes: 6 additions & 6 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
@@ -14,13 +14,13 @@ import (

ctypes "github.com/tendermint/tendermint/rpc/core/types"

client "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"

"github.com/cosmos/cosmos-sdk/crypto/keys/mintkey"
tests "github.com/cosmos/cosmos-sdk/tests"
"github.com/cosmos/cosmos-sdk/tests"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
@@ -212,7 +212,7 @@ func TestCoinSend(t *testing.T) {
res, body, _ = doTransferWithGas(t, port, seed, name1, memo, pw, addr, "10000", 1.0, true, false, fees)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var gasEstResp utils.GasEstimateResponse
var gasEstResp rest.GasEstimateResponse
require.Nil(t, cdc.UnmarshalJSON([]byte(body), &gasEstResp))
require.NotZero(t, gasEstResp.GasEstimate)

@@ -288,7 +288,7 @@ func TestCoinSendGenerateSignAndBroadcast(t *testing.T) {
res, body, _ := doTransferWithGas(t, port, seed, name1, memo, "", addr, client.GasFlagAuto, 1, true, false, fees)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var gasEstResp utils.GasEstimateResponse
var gasEstResp rest.GasEstimateResponse
require.Nil(t, cdc.UnmarshalJSON([]byte(body), &gasEstResp))
require.NotZero(t, gasEstResp.GasEstimate)

@@ -315,7 +315,7 @@ func TestCoinSendGenerateSignAndBroadcast(t *testing.T) {

payload := authrest.SignBody{
Tx: msg,
BaseReq: utils.NewBaseReq(
BaseReq: rest.NewBaseReq(
name1, pw, "", viper.GetString(client.FlagChainID), "", "",
accnum, sequence, nil, nil, false, false,
),
40 changes: 20 additions & 20 deletions client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
@@ -26,9 +26,9 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/client/utils"
gapp "github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/codec"
crkeys "github.com/cosmos/cosmos-sdk/crypto/keys"
@@ -646,7 +646,7 @@ func doSign(t *testing.T, port, name, password, chainID string, accnum, sequence
var signedMsg auth.StdTx
payload := authrest.SignBody{
Tx: msg,
BaseReq: utils.NewBaseReq(
BaseReq: rest.NewBaseReq(
name, password, "", chainID, "", "", accnum, sequence, nil, nil, false, false,
),
}
@@ -712,7 +712,7 @@ func doTransferWithGas(
from = addr.String()
}

baseReq := utils.NewBaseReq(
baseReq := rest.NewBaseReq(
from, password, memo, chainID, gas,
fmt.Sprintf("%f", gasAdjustment), accnum, sequence, fees, nil,
generateOnly, simulate,
@@ -746,7 +746,7 @@ func doTransferWithGasAccAuto(
receiveAddr = sdk.AccAddress(receiveInfo.GetPubKey().Address())
chainID := viper.GetString(client.FlagChainID)

baseReq := utils.NewBaseReq(
baseReq := rest.NewBaseReq(
from, password, memo, chainID, gas,
fmt.Sprintf("%f", gasAdjustment), 0, 0, fees, nil, generateOnly, simulate,
)
@@ -764,8 +764,8 @@ func doTransferWithGasAccAuto(
}

type sendReq struct {
Amount sdk.Coins `json:"amount"`
BaseReq utils.BaseReq `json:"base_req"`
Amount sdk.Coins `json:"amount"`
BaseReq rest.BaseReq `json:"base_req"`
}

// ----------------------------------------------------------------------
@@ -779,7 +779,7 @@ func doDelegate(t *testing.T, port, name, password string,
accnum := acc.GetAccountNumber()
sequence := acc.GetSequence()
chainID := viper.GetString(client.FlagChainID)
baseReq := utils.NewBaseReq(name, password, "", chainID, "", "", accnum, sequence, fees, nil, false, false)
baseReq := rest.NewBaseReq(name, password, "", chainID, "", "", accnum, sequence, fees, nil, false, false)
msg := msgDelegationsInput{
BaseReq: baseReq,
DelegatorAddr: delAddr,
@@ -799,7 +799,7 @@ func doDelegate(t *testing.T, port, name, password string,
}

type msgDelegationsInput struct {
BaseReq utils.BaseReq `json:"base_req"`
BaseReq rest.BaseReq `json:"base_req"`
DelegatorAddr sdk.AccAddress `json:"delegator_addr"` // in bech32
ValidatorAddr sdk.ValAddress `json:"validator_addr"` // in bech32
Delegation sdk.Coin `json:"delegation"`
@@ -813,7 +813,7 @@ func doUndelegate(t *testing.T, port, name, password string,
accnum := acc.GetAccountNumber()
sequence := acc.GetSequence()
chainID := viper.GetString(client.FlagChainID)
baseReq := utils.NewBaseReq(name, password, "", chainID, "", "", accnum, sequence, fees, nil, false, false)
baseReq := rest.NewBaseReq(name, password, "", chainID, "", "", accnum, sequence, fees, nil, false, false)
msg := msgUndelegateInput{
BaseReq: baseReq,
DelegatorAddr: delAddr,
@@ -834,7 +834,7 @@ func doUndelegate(t *testing.T, port, name, password string,
}

type msgUndelegateInput struct {
BaseReq utils.BaseReq `json:"base_req"`
BaseReq rest.BaseReq `json:"base_req"`
DelegatorAddr sdk.AccAddress `json:"delegator_addr"` // in bech32
ValidatorAddr sdk.ValAddress `json:"validator_addr"` // in bech32
SharesAmount sdk.Dec `json:"shares"`
@@ -849,7 +849,7 @@ func doBeginRedelegation(t *testing.T, port, name, password string,
sequence := acc.GetSequence()

chainID := viper.GetString(client.FlagChainID)
baseReq := utils.NewBaseReq(name, password, "", chainID, "", "", accnum, sequence, fees, nil, false, false)
baseReq := rest.NewBaseReq(name, password, "", chainID, "", "", accnum, sequence, fees, nil, false, false)

msg := msgBeginRedelegateInput{
BaseReq: baseReq,
@@ -872,7 +872,7 @@ func doBeginRedelegation(t *testing.T, port, name, password string,
}

type msgBeginRedelegateInput struct {
BaseReq utils.BaseReq `json:"base_req"`
BaseReq rest.BaseReq `json:"base_req"`
DelegatorAddr sdk.AccAddress `json:"delegator_addr"` // in bech32
ValidatorSrcAddr sdk.ValAddress `json:"validator_src_addr"` // in bech32
ValidatorDstAddr sdk.ValAddress `json:"validator_dst_addr"` // in bech32
@@ -1080,7 +1080,7 @@ func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerA
accnum := acc.GetAccountNumber()
sequence := acc.GetSequence()
chainID := viper.GetString(client.FlagChainID)
baseReq := utils.NewBaseReq(name, password, "", chainID, "", "", accnum, sequence, fees, nil, false, false)
baseReq := rest.NewBaseReq(name, password, "", chainID, "", "", accnum, sequence, fees, nil, false, false)

pr := postProposalReq{
Title: "Test",
@@ -1106,7 +1106,7 @@ func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerA
}

type postProposalReq struct {
BaseReq utils.BaseReq `json:"base_req"`
BaseReq rest.BaseReq `json:"base_req"`
Title string `json:"title"` // Title of the proposal
Description string `json:"description"` // Description of the proposal
ProposalType string `json:"proposal_type"` // Type of proposal. Initial set {PlainTextProposal, SoftwareUpgradeProposal}
@@ -1176,7 +1176,7 @@ func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk
accnum := acc.GetAccountNumber()
sequence := acc.GetSequence()
chainID := viper.GetString(client.FlagChainID)
baseReq := utils.NewBaseReq(name, password, "", chainID, "", "", accnum, sequence, fees, nil, false, false)
baseReq := rest.NewBaseReq(name, password, "", chainID, "", "", accnum, sequence, fees, nil, false, false)

dr := depositReq{
Depositor: proposerAddr,
@@ -1198,7 +1198,7 @@ func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk
}

type depositReq struct {
BaseReq utils.BaseReq `json:"base_req"`
BaseReq rest.BaseReq `json:"base_req"`
Depositor sdk.AccAddress `json:"depositor"` // Address of the depositor
Amount sdk.Coins `json:"amount"` // Coins to add to the proposal's deposit
}
@@ -1230,7 +1230,7 @@ func doVote(t *testing.T, port, seed, name, password string, proposerAddr sdk.Ac
accnum := acc.GetAccountNumber()
sequence := acc.GetSequence()
chainID := viper.GetString(client.FlagChainID)
baseReq := utils.NewBaseReq(name, password, "", chainID, "", "", accnum, sequence, fees, nil, false, false)
baseReq := rest.NewBaseReq(name, password, "", chainID, "", "", accnum, sequence, fees, nil, false, false)

vr := voteReq{
Voter: proposerAddr,
@@ -1252,7 +1252,7 @@ func doVote(t *testing.T, port, seed, name, password string, proposerAddr sdk.Ac
}

type voteReq struct {
BaseReq utils.BaseReq `json:"base_req"`
BaseReq rest.BaseReq `json:"base_req"`
Voter sdk.AccAddress `json:"voter"` // address of the voter
Option string `json:"option"` // option from OptionSet chosen by the voter
}
@@ -1362,7 +1362,7 @@ func getSigningInfo(t *testing.T, port string, validatorPubKey string) slashing.
func doUnjail(t *testing.T, port, seed, name, password string,
valAddr sdk.ValAddress, fees sdk.Coins) (resultTx ctypes.ResultBroadcastTxCommit) {
chainID := viper.GetString(client.FlagChainID)
baseReq := utils.NewBaseReq(name, password, "", chainID, "", "", 1, 1, fees, nil, false, false)
baseReq := rest.NewBaseReq(name, password, "", chainID, "", "", 1, 1, fees, nil, false, false)

ur := unjailReq{
BaseReq: baseReq,
@@ -1380,5 +1380,5 @@ func doUnjail(t *testing.T, port, seed, name, password string,
}

type unjailReq struct {
BaseReq utils.BaseReq `json:"base_req"`
BaseReq rest.BaseReq `json:"base_req"`
}
130 changes: 7 additions & 123 deletions client/utils/rest.go → client/rest/rest.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package utils
package rest

import (
"fmt"
"io/ioutil"
"net/http"
"strconv"
"strings"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/keyerror"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
)

// GasEstimateResponse defines a response definition for tx gas estimation.
type GasEstimateResponse struct {
GasEstimate uint64 `json:"gas_estimate"`
}

//-----------------------------------------------------------------------------
// Basic HTTP utilities

@@ -105,116 +99,6 @@ func ParseFloat64OrReturnBadRequest(w http.ResponseWriter, s string, defaultIfEm
//-----------------------------------------------------------------------------
// Building / Sending utilities

// BaseReq defines a structure that can be embedded in other request structures
// that all share common "base" fields.
type BaseReq struct {
From string `json:"from"`
Password string `json:"password"`
Memo string `json:"memo"`
ChainID string `json:"chain_id"`
AccountNumber uint64 `json:"account_number"`
Sequence uint64 `json:"sequence"`
Fees sdk.Coins `json:"fees"`
GasPrices sdk.DecCoins `json:"gas_prices"`
Gas string `json:"gas"`
GasAdjustment string `json:"gas_adjustment"`
GenerateOnly bool `json:"generate_only"`
Simulate bool `json:"simulate"`
}

// NewBaseReq creates a new basic request instance and sanitizes its values
func NewBaseReq(
from, password, memo, chainID string, gas, gasAdjustment string,
accNumber, seq uint64, fees sdk.Coins, gasPrices sdk.DecCoins, genOnly, simulate bool,
) BaseReq {

return BaseReq{
From: strings.TrimSpace(from),
Password: password,
Memo: strings.TrimSpace(memo),
ChainID: strings.TrimSpace(chainID),
Fees: fees,
GasPrices: gasPrices,
Gas: strings.TrimSpace(gas),
GasAdjustment: strings.TrimSpace(gasAdjustment),
AccountNumber: accNumber,
Sequence: seq,
GenerateOnly: genOnly,
Simulate: simulate,
}
}

// Sanitize performs basic sanitization on a BaseReq object.
func (br BaseReq) Sanitize() BaseReq {
return NewBaseReq(
br.From, br.Password, br.Memo, br.ChainID, br.Gas, br.GasAdjustment,
br.AccountNumber, br.Sequence, br.Fees, br.GasPrices, br.GenerateOnly, br.Simulate,
)
}

// ValidateBasic performs basic validation of a BaseReq. If custom validation
// logic is needed, the implementing request handler should perform those
// checks manually.
func (br BaseReq) ValidateBasic(w http.ResponseWriter) bool {
if !br.GenerateOnly && !br.Simulate {
switch {
case len(br.Password) == 0:
WriteErrorResponse(w, http.StatusUnauthorized, "password required but not specified")
return false

case len(br.ChainID) == 0:
WriteErrorResponse(w, http.StatusUnauthorized, "chain-id required but not specified")
return false

case !br.Fees.IsZero() && !br.GasPrices.IsZero():
// both fees and gas prices were provided
WriteErrorResponse(w, http.StatusBadRequest, "cannot provide both fees and gas prices")
return false

case !br.Fees.IsValid() && !br.GasPrices.IsValid():
// neither fees or gas prices were provided
WriteErrorResponse(w, http.StatusPaymentRequired, "invalid fees or gas prices provided")
return false
}
}

if len(br.From) == 0 {
WriteErrorResponse(w, http.StatusUnauthorized, "name or address required but not specified")
return false
}

return true
}

/*
ReadRESTReq is a simple convenience wrapper that reads the body and
unmarshals to the req interface.
Usage:
type SomeReq struct {
BaseReq `json:"base_req"`
CustomField string `json:"custom_field"`
}
req := new(SomeReq)
err := ReadRESTReq(w, r, cdc, req)
*/
func ReadRESTReq(w http.ResponseWriter, r *http.Request, cdc *codec.Codec, req interface{}) error {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return err
}

err = cdc.UnmarshalJSON(body, req)
if err != nil {
WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to decode JSON payload: %s", err))
return err
}

return nil
}

// CompleteAndBroadcastTxREST implements a utility function that facilitates
// sending a series of messages in a signed tx. In addition, it will handle
// tx gas simulation and estimation.
@@ -245,12 +129,12 @@ func CompleteAndBroadcastTxREST(

cliCtx = cliCtx.WithFromName(fromName).WithFromAddress(fromAddress)
txBldr := authtxb.NewTxBuilder(
GetTxEncoder(cdc), baseReq.AccountNumber,
utils.GetTxEncoder(cdc), baseReq.AccountNumber,
baseReq.Sequence, gas, gasAdj, baseReq.Simulate,
baseReq.ChainID, baseReq.Memo, baseReq.Fees, baseReq.GasPrices,
)

txBldr, err = prepareTxBuilder(txBldr, cliCtx)
txBldr, err = utils.PrepareTxBuilder(txBldr, cliCtx)
if err != nil {
WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
@@ -262,7 +146,7 @@ func CompleteAndBroadcastTxREST(
return
}

txBldr, err = EnrichWithGas(txBldr, cliCtx, msgs)
txBldr, err = utils.EnrichWithGas(txBldr, cliCtx, msgs)
if err != nil {
WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
@@ -336,7 +220,7 @@ func WriteGenerateStdTxResponse(
}

txBldr := authtxb.NewTxBuilder(
GetTxEncoder(cdc), br.AccountNumber, br.Sequence, gas, gasAdj,
utils.GetTxEncoder(cdc), br.AccountNumber, br.Sequence, gas, gasAdj,
br.Simulate, br.ChainID, br.Memo, br.Fees, br.GasPrices,
)

@@ -346,7 +230,7 @@ func WriteGenerateStdTxResponse(
return
}

txBldr, err = EnrichWithGas(txBldr, cliCtx, msgs)
txBldr, err = utils.EnrichWithGas(txBldr, cliCtx, msgs)
if err != nil {
WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
126 changes: 126 additions & 0 deletions client/rest/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package rest

import (
"fmt"
"io/ioutil"
"net/http"
"strings"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// GasEstimateResponse defines a response definition for tx gas estimation.
type GasEstimateResponse struct {
GasEstimate uint64 `json:"gas_estimate"`
}

// BaseReq defines a structure that can be embedded in other request structures
// that all share common "base" fields.
type BaseReq struct {
From string `json:"from"`
Password string `json:"password"`
Memo string `json:"memo"`
ChainID string `json:"chain_id"`
AccountNumber uint64 `json:"account_number"`
Sequence uint64 `json:"sequence"`
Fees sdk.Coins `json:"fees"`
GasPrices sdk.DecCoins `json:"gas_prices"`
Gas string `json:"gas"`
GasAdjustment string `json:"gas_adjustment"`
GenerateOnly bool `json:"generate_only"`
Simulate bool `json:"simulate"`
}

// NewBaseReq creates a new basic request instance and sanitizes its values
func NewBaseReq(
from, password, memo, chainID string, gas, gasAdjustment string,
accNumber, seq uint64, fees sdk.Coins, gasPrices sdk.DecCoins, genOnly, simulate bool,
) BaseReq {

return BaseReq{
From: strings.TrimSpace(from),
Password: password,
Memo: strings.TrimSpace(memo),
ChainID: strings.TrimSpace(chainID),
Fees: fees,
GasPrices: gasPrices,
Gas: strings.TrimSpace(gas),
GasAdjustment: strings.TrimSpace(gasAdjustment),
AccountNumber: accNumber,
Sequence: seq,
GenerateOnly: genOnly,
Simulate: simulate,
}
}

// Sanitize performs basic sanitization on a BaseReq object.
func (br BaseReq) Sanitize() BaseReq {
return NewBaseReq(
br.From, br.Password, br.Memo, br.ChainID, br.Gas, br.GasAdjustment,
br.AccountNumber, br.Sequence, br.Fees, br.GasPrices, br.GenerateOnly, br.Simulate,
)
}

// ValidateBasic performs basic validation of a BaseReq. If custom validation
// logic is needed, the implementing request handler should perform those
// checks manually.
func (br BaseReq) ValidateBasic(w http.ResponseWriter) bool {
if !br.GenerateOnly && !br.Simulate {
switch {
case len(br.Password) == 0:
WriteErrorResponse(w, http.StatusUnauthorized, "password required but not specified")
return false

case len(br.ChainID) == 0:
WriteErrorResponse(w, http.StatusUnauthorized, "chain-id required but not specified")
return false

case !br.Fees.IsZero() && !br.GasPrices.IsZero():
// both fees and gas prices were provided
WriteErrorResponse(w, http.StatusBadRequest, "cannot provide both fees and gas prices")
return false

case !br.Fees.IsValid() && !br.GasPrices.IsValid():
// neither fees or gas prices were provided
WriteErrorResponse(w, http.StatusPaymentRequired, "invalid fees or gas prices provided")
return false
}
}

if len(br.From) == 0 {
WriteErrorResponse(w, http.StatusUnauthorized, "name or address required but not specified")
return false
}

return true
}

/*
ReadRESTReq is a simple convenience wrapper that reads the body and
unmarshals to the req interface.
Usage:
type SomeReq struct {
BaseReq `json:"base_req"`
CustomField string `json:"custom_field"`
}
req := new(SomeReq)
err := ReadRESTReq(w, r, cdc, req)
*/
func ReadRESTReq(w http.ResponseWriter, r *http.Request, cdc *codec.Codec, req interface{}) error {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return err
}

err = cdc.UnmarshalJSON(body, req)
if err != nil {
WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to decode JSON payload: %s", err))
return err
}

return nil
}
8 changes: 4 additions & 4 deletions client/rpc/block.go
Original file line number Diff line number Diff line change
@@ -5,15 +5,15 @@ import (
"net/http"
"strconv"

"github.com/cosmos/cosmos-sdk/client/rest"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"

"github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/spf13/viper"
tmliteProxy "github.com/tendermint/tendermint/lite/proxy"

"github.com/cosmos/cosmos-sdk/client/utils"
)

//BlockCommand returns the verified block data for a given heights
@@ -131,7 +131,7 @@ func BlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
w.Write([]byte(err.Error()))
return
}
utils.PostProcessResponse(w, cdc, output, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, output, cliCtx.Indent)
}
}

@@ -150,6 +150,6 @@ func LatestBlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
w.Write([]byte(err.Error()))
return
}
utils.PostProcessResponse(w, cdc, output, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, output, cliCtx.Indent)
}
}
5 changes: 3 additions & 2 deletions client/rpc/root.go
Original file line number Diff line number Diff line change
@@ -4,10 +4,11 @@ import (
"fmt"
"net/http"

"github.com/cosmos/cosmos-sdk/client/rest"

"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/version"
)

@@ -34,7 +35,7 @@ func NodeVersionRequestHandler(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
version, err := cliCtx.Query("/app/version", nil)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

5 changes: 3 additions & 2 deletions client/rpc/status.go
Original file line number Diff line number Diff line change
@@ -5,14 +5,15 @@ import (
"net/http"
"strconv"

"github.com/cosmos/cosmos-sdk/client/rest"

"github.com/spf13/cobra"

"github.com/spf13/viper"
ctypes "github.com/tendermint/tendermint/rpc/core/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
)

// StatusCommand returns the status of the network
@@ -77,7 +78,7 @@ func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}

nodeInfo := status.NodeInfo
utils.PostProcessResponse(w, cdc, nodeInfo, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, nodeInfo, cliCtx.Indent)
}
}

7 changes: 4 additions & 3 deletions client/rpc/validators.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@ import (
"net/http"
"strconv"

"github.com/cosmos/cosmos-sdk/client/rest"

"github.com/gorilla/mux"
"github.com/spf13/cobra"

@@ -14,7 +16,6 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
sdk "github.com/cosmos/cosmos-sdk/types"
)

@@ -157,7 +158,7 @@ func ValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
w.Write([]byte(err.Error()))
return
}
utils.PostProcessResponse(w, cdc, output, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, output, cliCtx.Indent)
}
}

@@ -177,6 +178,6 @@ func LatestValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerF
w.Write([]byte(err.Error()))
return
}
utils.PostProcessResponse(w, cdc, output, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, output, cliCtx.Indent)
}
}
13 changes: 7 additions & 6 deletions client/tx/broadcast.go
Original file line number Diff line number Diff line change
@@ -3,10 +3,11 @@ package tx
import (
"net/http"

"github.com/cosmos/cosmos-sdk/client/rest"

"io/ioutil"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
)

@@ -32,12 +33,12 @@ func BroadcastTxRequest(cliCtx context.CLIContext, cdc *codec.Codec) http.Handle
var m BroadcastBody
body, err := ioutil.ReadAll(r.Body)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
err = cdc.UnmarshalJSON(body, &m)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
var res interface{}
@@ -49,13 +50,13 @@ func BroadcastTxRequest(cliCtx context.CLIContext, cdc *codec.Codec) http.Handle
case flagAsync:
res, err = cliCtx.BroadcastTxAsync(m.TxBytes)
default:
utils.WriteErrorResponse(w, http.StatusInternalServerError, "unsupported return type. supported types: block, sync, async")
rest.WriteErrorResponse(w, http.StatusInternalServerError, "unsupported return type. supported types: block, sync, async")
return
}
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
utils.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
}
}
7 changes: 4 additions & 3 deletions client/tx/query.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@ import (
"fmt"
"net/http"

"github.com/cosmos/cosmos-sdk/client/rest"

"github.com/tendermint/tendermint/libs/common"

"github.com/gorilla/mux"
@@ -16,7 +18,6 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"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/x/auth"
@@ -142,9 +143,9 @@ func QueryTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.H

output, err := queryTx(cdc, cliCtx, hashHexStr)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
utils.PostProcessResponse(w, cdc, output, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, output, cliCtx.Indent)
}
}
13 changes: 7 additions & 6 deletions client/tx/search.go
Original file line number Diff line number Diff line change
@@ -8,9 +8,10 @@ import (
"strconv"
"strings"

"github.com/cosmos/cosmos-sdk/client/rest"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

@@ -175,28 +176,28 @@ func SearchTxRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.
var txs []Info
err := r.ParseForm()
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, sdk.AppendMsgToErr("could not parse query parameters", err.Error()))
rest.WriteErrorResponse(w, http.StatusBadRequest, sdk.AppendMsgToErr("could not parse query parameters", err.Error()))
return
}
if len(r.Form) == 0 {
utils.PostProcessResponse(w, cdc, txs, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, txs, cliCtx.Indent)
return
}

tags, page, limit, err = parseHTTPArgs(r)

if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

txs, err = SearchTxs(cliCtx, cdc, tags, page, limit)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

utils.PostProcessResponse(w, cdc, txs, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, txs, cliCtx.Indent)
}
}

7 changes: 4 additions & 3 deletions client/utils/utils.go
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ import (
//
// NOTE: Also see CompleteAndBroadcastTxREST.
func CompleteAndBroadcastTxCLI(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) error {
txBldr, err := prepareTxBuilder(txBldr, cliCtx)
txBldr, err := PrepareTxBuilder(txBldr, cliCtx)
if err != nil {
return err
}
@@ -227,7 +227,8 @@ func parseQueryResponse(cdc *amino.Codec, rawRes []byte) (uint64, error) {
return simulationResult.GasUsed, nil
}

func prepareTxBuilder(txBldr authtxb.TxBuilder, cliCtx context.CLIContext) (authtxb.TxBuilder, error) {
// PrepareTxBuilder populates a TxBuilder in preparation for the build of a Tx.
func PrepareTxBuilder(txBldr authtxb.TxBuilder, cliCtx context.CLIContext) (authtxb.TxBuilder, error) {
if err := cliCtx.EnsureAccountExists(); err != nil {
return txBldr, err
}
@@ -259,7 +260,7 @@ func prepareTxBuilder(txBldr authtxb.TxBuilder, cliCtx context.CLIContext) (auth
// buildUnsignedStdTx builds a StdTx as per the parameters passed in the
// contexts. Gas is automatically estimated if gas wanted is set to 0.
func buildUnsignedStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (stdTx auth.StdTx, err error) {
txBldr, err = prepareTxBuilder(txBldr, cliCtx)
txBldr, err = PrepareTxBuilder(txBldr, cliCtx)
if err != nil {
return
}
18 changes: 9 additions & 9 deletions x/auth/client/rest/query.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import (
"net/http"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"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/x/auth"
@@ -39,13 +39,13 @@ func QueryAccountRequestHandlerFn(

addr, err := sdk.AccAddressFromBech32(bech32addr)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

res, err := cliCtx.QueryStore(auth.AddressStoreKey(addr), storeName)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

@@ -58,11 +58,11 @@ func QueryAccountRequestHandlerFn(
// decode the value
account, err := decoder(res)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

utils.PostProcessResponse(w, cdc, account, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, account, cliCtx.Indent)
}
}

@@ -78,13 +78,13 @@ func QueryBalancesRequestHandlerFn(

addr, err := sdk.AccAddressFromBech32(bech32addr)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

res, err := cliCtx.QueryStore(auth.AddressStoreKey(addr), storeName)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

@@ -97,10 +97,10 @@ func QueryBalancesRequestHandlerFn(
// decode the value
account, err := decoder(res)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

utils.PostProcessResponse(w, cdc, account.GetCoins(), cliCtx.Indent)
rest.PostProcessResponse(w, cdc, account.GetCoins(), cliCtx.Indent)
}
}
23 changes: 12 additions & 11 deletions x/auth/client/rest/sign.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import (
"net/http"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/keyerror"
@@ -14,9 +15,9 @@ import (

// SignBody defines the properties of a sign request's body.
type SignBody struct {
Tx auth.StdTx `json:"tx"`
AppendSig bool `json:"append_sig"`
BaseReq utils.BaseReq `json:"base_req"`
Tx auth.StdTx `json:"tx"`
AppendSig bool `json:"append_sig"`
BaseReq rest.BaseReq `json:"base_req"`
}

// nolint: unparam
@@ -25,8 +26,8 @@ func SignTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Ha
return func(w http.ResponseWriter, r *http.Request) {
var m SignBody

if err := utils.ReadRESTReq(w, r, cdc, &m); err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
if err := rest.ReadRESTReq(w, r, cdc, &m); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

@@ -37,14 +38,14 @@ func SignTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Ha
// validate tx
// discard error if it's CodeNoSignatures as the tx comes with no signatures
if err := m.Tx.ValidateBasic(); err != nil && err.Code() != sdk.CodeNoSignatures {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

// derive the from account address and name from the Keybase
fromAddress, fromName, err := context.GetFromFields(m.BaseReq.From)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

@@ -65,16 +66,16 @@ func SignTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Ha

signedTx, err := txBldr.SignStdTx(cliCtx.GetFromName(), m.BaseReq.Password, m.Tx, m.AppendSig)
if keyerror.IsErrKeyNotFound(err) {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
} else if keyerror.IsErrWrongPassword(err) {
utils.WriteErrorResponse(w, http.StatusUnauthorized, err.Error())
rest.WriteErrorResponse(w, http.StatusUnauthorized, err.Error())
return
} else if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

utils.PostProcessResponse(w, cdc, signedTx, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, signedTx, cliCtx.Indent)
}
}
12 changes: 6 additions & 6 deletions x/bank/client/rest/broadcast.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import (
"net/http"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/auth"
)
@@ -24,29 +24,29 @@ func BroadcastTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) ht

txBytes, err := cliCtx.Codec.MarshalBinaryLengthPrefixed(m.Tx)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

res, err := cliCtx.BroadcastTx(txBytes)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

utils.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
}
}

func unmarshalBodyOrReturnBadRequest(cliCtx context.CLIContext, w http.ResponseWriter, r *http.Request, m *broadcastBody) bool {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return false
}
err = cliCtx.Codec.UnmarshalJSON(body, m)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return false
}
return true
19 changes: 10 additions & 9 deletions x/bank/client/rest/sendtx.go
Original file line number Diff line number Diff line change
@@ -3,8 +3,9 @@ package rest
import (
"net/http"

"github.com/cosmos/cosmos-sdk/client/rest"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -21,8 +22,8 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec,
}

type sendReq struct {
BaseReq utils.BaseReq `json:"base_req"`
Amount sdk.Coins `json:"amount"`
BaseReq rest.BaseReq `json:"base_req"`
Amount sdk.Coins `json:"amount"`
}

var msgCdc = codec.New()
@@ -39,12 +40,12 @@ func SendRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIC

toAddr, err := sdk.AccAddressFromBech32(bech32Addr)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

var req sendReq
err = utils.ReadRESTReq(w, r, cdc, &req)
err = rest.ReadRESTReq(w, r, cdc, &req)
if err != nil {
return
}
@@ -59,25 +60,25 @@ func SendRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIC
// address.
fromAddr, err := sdk.AccAddressFromBech32(req.BaseReq.From)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

msg := bankclient.CreateMsg(fromAddr, toAddr, req.Amount)
utils.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
rest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
return
}

// derive the from account address and name from the Keybase
fromAddress, fromName, err := context.GetFromFields(req.BaseReq.From)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

cliCtx = cliCtx.WithFromName(fromName).WithFromAddress(fromAddress)
msg := bankclient.CreateMsg(cliCtx.GetFromAddress(), toAddr, req.Amount)

utils.CompleteAndBroadcastTxREST(w, r, cliCtx, req.BaseReq, []sdk.Msg{msg}, cdc)
rest.CompleteAndBroadcastTxREST(w, r, cliCtx, req.BaseReq, []sdk.Msg{msg}, cdc)
}
}
157 changes: 79 additions & 78 deletions x/gov/client/rest/rest.go

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions x/ibc/client/rest/transfer.go
Original file line number Diff line number Diff line change
@@ -3,8 +3,9 @@ package rest
import (
"net/http"

"github.com/cosmos/cosmos-sdk/client/rest"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -19,8 +20,8 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec,
}

type transferReq struct {
BaseReq utils.BaseReq `json:"base_req"`
Amount sdk.Coins `json:"amount"`
BaseReq rest.BaseReq `json:"base_req"`
Amount sdk.Coins `json:"amount"`
}

// TransferRequestHandler - http request handler to transfer coins to a address
@@ -33,12 +34,12 @@ func TransferRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.

to, err := sdk.AccAddressFromBech32(bech32Addr)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

var req transferReq
err = utils.ReadRESTReq(w, r, cdc, &req)
err = rest.ReadRESTReq(w, r, cdc, &req)
if err != nil {
return
}
@@ -55,7 +56,7 @@ func TransferRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.
// address.
addr, err := sdk.AccAddressFromBech32(req.BaseReq.From)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

@@ -66,10 +67,10 @@ func TransferRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.
msg := ibc.IBCTransferMsg{IBCPacket: packet}

if req.BaseReq.GenerateOnly {
utils.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
rest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
return
}

utils.CompleteAndBroadcastTxREST(w, r, cliCtx, req.BaseReq, []sdk.Msg{msg}, cdc)
rest.CompleteAndBroadcastTxREST(w, r, cliCtx, req.BaseReq, []sdk.Msg{msg}, cdc)
}
}
15 changes: 8 additions & 7 deletions x/slashing/client/rest/query.go
Original file line number Diff line number Diff line change
@@ -4,10 +4,11 @@ import (
"fmt"
"net/http"

"github.com/cosmos/cosmos-sdk/client/rest"

"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client/context"
"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/x/slashing"
@@ -33,15 +34,15 @@ func signingInfoHandlerFn(cliCtx context.CLIContext, storeName string, cdc *code

pk, err := sdk.GetConsPubKeyBech32(vars["validatorPubKey"])
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

key := slashing.GetValidatorSigningInfoKey(sdk.ConsAddress(pk.Address()))

res, err := cliCtx.QueryStore(key, storeName)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

@@ -54,11 +55,11 @@ func signingInfoHandlerFn(cliCtx context.CLIContext, storeName string, cdc *code

err = cdc.UnmarshalBinaryLengthPrefixed(res, &signingInfo)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

utils.PostProcessResponse(w, cdc, signingInfo, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, signingInfo, cliCtx.Indent)
}
}

@@ -68,10 +69,10 @@ func queryParamsHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Hand

res, err := cliCtx.QueryWithData(route, nil)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

utils.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
}
}
19 changes: 10 additions & 9 deletions x/slashing/client/rest/tx.go
Original file line number Diff line number Diff line change
@@ -4,8 +4,9 @@ import (
"bytes"
"net/http"

"github.com/cosmos/cosmos-sdk/client/rest"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -23,7 +24,7 @@ func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec

// Unjail TX body
type UnjailReq struct {
BaseReq utils.BaseReq `json:"base_req"`
BaseReq rest.BaseReq `json:"base_req"`
}

func unjailRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
@@ -33,7 +34,7 @@ func unjailRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CL
bech32validator := vars["validatorAddr"]

var req UnjailReq
err := utils.ReadRESTReq(w, r, cdc, &req)
err := rest.ReadRESTReq(w, r, cdc, &req)
if err != nil {
return
}
@@ -45,36 +46,36 @@ func unjailRequestHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CL

valAddr, err := sdk.ValAddressFromBech32(bech32validator)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

msg := slashing.NewMsgUnjail(valAddr)
err = msg.ValidateBasic()
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

if req.BaseReq.GenerateOnly {
utils.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
rest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
return
}

// derive the from account address and name from the Keybase
fromAddress, fromName, err := context.GetFromFields(req.BaseReq.From)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

cliCtx = cliCtx.WithFromName(fromName).WithFromAddress(fromAddress)

if !bytes.Equal(cliCtx.GetFromAddress(), valAddr) {
utils.WriteErrorResponse(w, http.StatusUnauthorized, "must use own validator address")
rest.WriteErrorResponse(w, http.StatusUnauthorized, "must use own validator address")
return
}

utils.CompleteAndBroadcastTxREST(w, r, cliCtx, req.BaseReq, []sdk.Msg{msg}, cdc)
rest.CompleteAndBroadcastTxREST(w, r, cliCtx, req.BaseReq, []sdk.Msg{msg}, cdc)
}
}
37 changes: 19 additions & 18 deletions x/staking/client/rest/query.go
Original file line number Diff line number Diff line change
@@ -4,9 +4,10 @@ import (
"net/http"
"strings"

"github.com/cosmos/cosmos-sdk/client/rest"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/tx"
"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/x/staking"
@@ -122,13 +123,13 @@ func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Han

_, err := sdk.AccAddressFromBech32(delegatorAddr)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

node, err := cliCtx.GetNode()
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

@@ -170,17 +171,17 @@ func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Han
for _, action := range actions {
foundTxs, errQuery := queryTxs(node, cliCtx, cdc, action, delegatorAddr)
if errQuery != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
}
txs = append(txs, foundTxs...)
}

res, err := cdc.MarshalJSON(txs)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
utils.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
}
}

@@ -201,7 +202,7 @@ func redelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Ha
if len(bechDelegatorAddr) != 0 {
delegatorAddr, err := sdk.AccAddressFromBech32(bechDelegatorAddr)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
params.DelegatorAddr = delegatorAddr
@@ -210,7 +211,7 @@ func redelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Ha
if len(bechSrcValidatorAddr) != 0 {
srcValidatorAddr, err := sdk.ValAddressFromBech32(bechSrcValidatorAddr)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
params.SrcValidatorAddr = srcValidatorAddr
@@ -219,24 +220,24 @@ func redelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Ha
if len(bechDstValidatorAddr) != 0 {
dstValidatorAddr, err := sdk.ValAddressFromBech32(bechDstValidatorAddr)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
params.DstValidatorAddr = dstValidatorAddr
}

bz, err := cdc.MarshalJSON(params)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

res, err := cliCtx.QueryWithData("custom/staking/redelegations", bz)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
utils.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
}
}

@@ -260,10 +261,10 @@ func validatorsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Handl
return func(w http.ResponseWriter, r *http.Request) {
res, err := cliCtx.QueryWithData("custom/staking/validators", nil)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
utils.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
}
}

@@ -287,10 +288,10 @@ func poolHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
res, err := cliCtx.QueryWithData("custom/staking/pool", nil)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
utils.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
}
}

@@ -299,9 +300,9 @@ func paramsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFu
return func(w http.ResponseWriter, r *http.Request) {
res, err := cliCtx.QueryWithData("custom/staking/parameters", nil)
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
utils.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
}
}
51 changes: 26 additions & 25 deletions x/staking/client/rest/tx.go
Original file line number Diff line number Diff line change
@@ -4,8 +4,9 @@ import (
"bytes"
"net/http"

"github.com/cosmos/cosmos-sdk/client/rest"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -31,22 +32,22 @@ func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec

type (
msgDelegationsInput struct {
BaseReq utils.BaseReq `json:"base_req"`
BaseReq rest.BaseReq `json:"base_req"`
DelegatorAddr sdk.AccAddress `json:"delegator_addr"` // in bech32
ValidatorAddr sdk.ValAddress `json:"validator_addr"` // in bech32
Delegation sdk.Coin `json:"delegation"`
}

msgBeginRedelegateInput struct {
BaseReq utils.BaseReq `json:"base_req"`
BaseReq rest.BaseReq `json:"base_req"`
DelegatorAddr sdk.AccAddress `json:"delegator_addr"` // in bech32
ValidatorSrcAddr sdk.ValAddress `json:"validator_src_addr"` // in bech32
ValidatorDstAddr sdk.ValAddress `json:"validator_dst_addr"` // in bech32
SharesAmount sdk.Dec `json:"shares"`
}

msgUndelegateInput struct {
BaseReq utils.BaseReq `json:"base_req"`
BaseReq rest.BaseReq `json:"base_req"`
DelegatorAddr sdk.AccAddress `json:"delegator_addr"` // in bech32
ValidatorAddr sdk.ValAddress `json:"validator_addr"` // in bech32
SharesAmount sdk.Dec `json:"shares"`
@@ -57,9 +58,9 @@ func postDelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.
return func(w http.ResponseWriter, r *http.Request) {
var req msgDelegationsInput

err := utils.ReadRESTReq(w, r, cdc, &req)
err := rest.ReadRESTReq(w, r, cdc, &req)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

@@ -71,40 +72,40 @@ func postDelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.
msg := staking.NewMsgDelegate(req.DelegatorAddr, req.ValidatorAddr, req.Delegation)
err = msg.ValidateBasic()
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

if req.BaseReq.GenerateOnly {
utils.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
rest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
return
}

// derive the from account address and name from the Keybase
fromAddress, fromName, err := context.GetFromFields(req.BaseReq.From)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

cliCtx = cliCtx.WithFromName(fromName).WithFromAddress(fromAddress)

if !bytes.Equal(cliCtx.GetFromAddress(), req.DelegatorAddr) {
utils.WriteErrorResponse(w, http.StatusUnauthorized, "must use own delegator address")
rest.WriteErrorResponse(w, http.StatusUnauthorized, "must use own delegator address")
return
}

utils.CompleteAndBroadcastTxREST(w, r, cliCtx, req.BaseReq, []sdk.Msg{msg}, cdc)
rest.CompleteAndBroadcastTxREST(w, r, cliCtx, req.BaseReq, []sdk.Msg{msg}, cdc)
}
}

func postRedelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req msgBeginRedelegateInput

err := utils.ReadRESTReq(w, r, cdc, &req)
err := rest.ReadRESTReq(w, r, cdc, &req)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

@@ -116,40 +117,40 @@ func postRedelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx contex
msg := staking.NewMsgBeginRedelegate(req.DelegatorAddr, req.ValidatorSrcAddr, req.ValidatorDstAddr, req.SharesAmount)
err = msg.ValidateBasic()
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

if req.BaseReq.GenerateOnly {
utils.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
rest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
return
}

// derive the from account address and name from the Keybase
fromAddress, fromName, err := context.GetFromFields(req.BaseReq.From)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

cliCtx = cliCtx.WithFromName(fromName).WithFromAddress(fromAddress)

if !bytes.Equal(cliCtx.GetFromAddress(), req.DelegatorAddr) {
utils.WriteErrorResponse(w, http.StatusUnauthorized, "must use own delegator address")
rest.WriteErrorResponse(w, http.StatusUnauthorized, "must use own delegator address")
return
}

utils.CompleteAndBroadcastTxREST(w, r, cliCtx, req.BaseReq, []sdk.Msg{msg}, cdc)
rest.CompleteAndBroadcastTxREST(w, r, cliCtx, req.BaseReq, []sdk.Msg{msg}, cdc)
}
}

func postUnbondingDelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req msgUndelegateInput

err := utils.ReadRESTReq(w, r, cdc, &req)
err := rest.ReadRESTReq(w, r, cdc, &req)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

@@ -161,29 +162,29 @@ func postUnbondingDelegationsHandlerFn(cdc *codec.Codec, kb keys.Keybase, cliCtx
msg := staking.NewMsgUndelegate(req.DelegatorAddr, req.ValidatorAddr, req.SharesAmount)
err = msg.ValidateBasic()
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

if req.BaseReq.GenerateOnly {
utils.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
rest.WriteGenerateStdTxResponse(w, cdc, cliCtx, req.BaseReq, []sdk.Msg{msg})
return
}

// derive the from account address and name from the Keybase
fromAddress, fromName, err := context.GetFromFields(req.BaseReq.From)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

cliCtx = cliCtx.WithFromName(fromName).WithFromAddress(fromAddress)

if !bytes.Equal(cliCtx.GetFromAddress(), req.DelegatorAddr) {
utils.WriteErrorResponse(w, http.StatusUnauthorized, "must use own delegator address")
rest.WriteErrorResponse(w, http.StatusUnauthorized, "must use own delegator address")
return
}

utils.CompleteAndBroadcastTxREST(w, r, cliCtx, req.BaseReq, []sdk.Msg{msg}, cdc)
rest.CompleteAndBroadcastTxREST(w, r, cliCtx, req.BaseReq, []sdk.Msg{msg}, cdc)
}
}
39 changes: 20 additions & 19 deletions x/staking/client/rest/utils.go
Original file line number Diff line number Diff line change
@@ -4,11 +4,12 @@ import (
"fmt"
"net/http"

"github.com/cosmos/cosmos-sdk/client/rest"

"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/tx"
"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/x/staking"
@@ -59,17 +60,17 @@ func queryRedelegations(cliCtx context.CLIContext, cdc *codec.Codec, endpoint st

delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
srcValidatorAddr, err := sdk.ValAddressFromBech32(bech32srcValidator)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
dstValidatorAddr, err := sdk.ValAddressFromBech32(bech32dstValidator)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

@@ -81,16 +82,16 @@ func queryRedelegations(cliCtx context.CLIContext, cdc *codec.Codec, endpoint st

bz, err := cdc.MarshalJSON(params)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

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

@@ -103,24 +104,24 @@ func queryBonds(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string) ht
delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator)
validatorAddr, err := sdk.ValAddressFromBech32(bech32validator)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

params := staking.NewQueryBondsParams(delegatorAddr, validatorAddr)

bz, err := cdc.MarshalJSON(params)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

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

@@ -131,24 +132,24 @@ func queryDelegator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string

delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

params := staking.NewQueryDelegatorParams(delegatorAddr)

bz, err := cdc.MarshalJSON(params)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

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

@@ -159,23 +160,23 @@ func queryValidator(cliCtx context.CLIContext, cdc *codec.Codec, endpoint string

validatorAddr, err := sdk.ValAddressFromBech32(bech32validatorAddr)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

params := staking.NewQueryValidatorParams(validatorAddr)

bz, err := cdc.MarshalJSON(params)
if err != nil {
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

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

0 comments on commit ee9ea20

Please sign in to comment.