From d5fe9b7eef8e87eb96656e3d454bfe6b977acbee Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Fri, 14 Jun 2019 11:52:28 +0200 Subject: [PATCH] Merge PR #4550: Minor Cleanup --- client/context/query.go | 8 ++++---- client/rpc/root.go | 4 ++-- client/utils/utils.go | 6 ++---- client/utils/utils_test.go | 5 ++--- x/auth/client/rest/query.go | 4 ++-- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/client/context/query.go b/client/context/query.go index 6153baca44..de1779da02 100644 --- a/client/context/query.go +++ b/client/context/query.go @@ -30,10 +30,10 @@ func (ctx CLIContext) GetNode() (rpcclient.Client, error) { } // Query performs a query to a Tendermint node with the provided path. -// It returns the result and height of the query upon success -// or an error if the query fails. -func (ctx CLIContext) Query(path string, data cmn.HexBytes) ([]byte, int64, error) { - return ctx.query(path, data) +// It returns the result and height of the query upon success or an error if +// the query fails. +func (ctx CLIContext) Query(path string) ([]byte, int64, error) { + return ctx.query(path, nil) } // QueryWithData performs a query to a Tendermint node with the provided path diff --git a/client/rpc/root.go b/client/rpc/root.go index eb4b36820d..ed361386b4 100644 --- a/client/rpc/root.go +++ b/client/rpc/root.go @@ -35,14 +35,14 @@ func CLIVersionRequestHandler(w http.ResponseWriter, r *http.Request) { // connected node version REST handler endpoint func NodeVersionRequestHandler(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - version, _, err := cliCtx.Query("/app/version", nil) + res, _, err := cliCtx.Query("/app/version") if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return } w.Header().Set("Content-Type", "application/json") - if _, err := w.Write(version); err != nil { + if _, err := w.Write(res); err != nil { log.Printf("could not write response: %v", err) } } diff --git a/client/utils/utils.go b/client/utils/utils.go index da9170f9db..f55793e4ce 100644 --- a/client/utils/utils.go +++ b/client/utils/utils.go @@ -10,8 +10,6 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/tendermint/tendermint/libs/common" - "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/input" @@ -127,7 +125,7 @@ func EnrichWithGas(txBldr authtypes.TxBuilder, cliCtx context.CLIContext, msgs [ // CalculateGas simulates the execution of a transaction and returns // both the estimate obtained by the query and the adjusted amount. -func CalculateGas(queryFunc func(string, common.HexBytes) ([]byte, int64, error), +func CalculateGas(queryFunc func(string, []byte) ([]byte, int64, error), cdc *codec.Codec, txBytes []byte, adjustment float64) (estimate, adjusted uint64, err error) { // run a simulation (via /app/simulate query) to @@ -275,7 +273,7 @@ func simulateMsgs(txBldr authtypes.TxBuilder, cliCtx context.CLIContext, msgs [] if err != nil { return } - estimated, adjusted, err = CalculateGas(cliCtx.Query, cliCtx.Codec, txBytes, txBldr.GasAdjustment()) + estimated, adjusted, err = CalculateGas(cliCtx.QueryWithData, cliCtx.Codec, txBytes, txBldr.GasAdjustment()) return } diff --git a/client/utils/utils_test.go b/client/utils/utils_test.go index ef666c9edb..b0cc27fa3b 100644 --- a/client/utils/utils_test.go +++ b/client/utils/utils_test.go @@ -11,7 +11,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/libs/common" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -36,8 +35,8 @@ func TestParseQueryResponse(t *testing.T) { func TestCalculateGas(t *testing.T) { cdc := makeCodec() - makeQueryFunc := func(gasUsed uint64, wantErr bool) func(string, common.HexBytes) ([]byte, int64, error) { - return func(string, common.HexBytes) ([]byte, int64, error) { + makeQueryFunc := func(gasUsed uint64, wantErr bool) func(string, []byte) ([]byte, int64, error) { + return func(string, []byte) ([]byte, int64, error) { if wantErr { return nil, 0, errors.New("") } diff --git a/x/auth/client/rest/query.go b/x/auth/client/rest/query.go index 81bffe65ac..4cc23d63e2 100644 --- a/x/auth/client/rest/query.go +++ b/x/auth/client/rest/query.go @@ -12,8 +12,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" ) -// AccountWithHeight wraps the embedded Account -// with the height it was queried at +// AccountWithHeight wraps the embedded Account with the height it was queried +// at. type AccountWithHeight struct { types.Account Height int64 `json:"height"`