Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: various: code clean up, refactoring #3580

Merged
merged 23 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ BREAKING CHANGES
* Gaia

* SDK
* \#3580 Migrate HTTP request/response types and utilities to types/rest.
* \#3592 Drop deprecated keybase implementation's New() constructor in
favor of a new crypto/keys.New(string, string) implementation that
returns a lazy keybase instance. Remove client.MockKeyBase,
superseded by crypto/keys.NewInMemory()

* Tendermint

Expand Down
5 changes: 3 additions & 2 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"

"errors"

Expand Down Expand Up @@ -399,7 +400,7 @@ func AddNewKeyRequestHandler(indent bool) http.HandlerFunc {

keyOutput.Mnemonic = mnemonic

PostProcessResponse(w, cdc, keyOutput, indent)
rest.PostProcessResponse(w, cdc, keyOutput, indent)
}
}

Expand Down Expand Up @@ -488,6 +489,6 @@ func RecoverRequestHandler(indent bool) http.HandlerFunc {
return
}

PostProcessResponse(w, cdc, keyOutput, indent)
rest.PostProcessResponse(w, cdc, keyOutput, indent)
}
}
5 changes: 3 additions & 2 deletions client/keys/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keys
import (
"net/http"

"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -49,7 +50,7 @@ func QueryKeysRequestHandler(indent bool) http.HandlerFunc {
}
// an empty list will be JSONized as null, but we want to keep the empty list
if len(infos) == 0 {
PostProcessResponse(w, cdc, []string{}, indent)
rest.PostProcessResponse(w, cdc, []string{}, indent)
return
}
keysOutput, err := Bech32KeysOutput(infos)
Expand All @@ -58,6 +59,6 @@ func QueryKeysRequestHandler(indent bool) http.HandlerFunc {
_, _ = w.Write([]byte(err.Error()))
return
}
PostProcessResponse(w, cdc, keysOutput, indent)
rest.PostProcessResponse(w, cdc, keysOutput, indent)
}
}
3 changes: 2 additions & 1 deletion client/keys/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/tendermint/tendermint/crypto"

"github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/cosmos/cosmos-sdk/types/rest"

"errors"

Expand Down Expand Up @@ -188,6 +189,6 @@ func GetKeyRequestHandler(indent bool) http.HandlerFunc {
return
}

PostProcessResponse(w, cdc, keyOutput, indent)
rest.PostProcessResponse(w, cdc, keyOutput, indent)
}
}
25 changes: 0 additions & 25 deletions client/keys/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package keys

import (
"fmt"
"net/http"
"path/filepath"

"github.com/spf13/viper"
"github.com/tendermint/tendermint/libs/cli"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -217,26 +215,3 @@ func printPubKey(info keys.Info, bechKeyOut bechKeyOutFn) {

fmt.Println(ko.PubKey)
}

// PostProcessResponse performs post process for rest response
func PostProcessResponse(w http.ResponseWriter, cdc *codec.Codec, response interface{}, indent bool) {
var output []byte
switch response.(type) {
default:
var err error
if indent {
output, err = cdc.MarshalJSONIndent(response, "", " ")
} else {
output, err = cdc.MarshalJSON(response)
}
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error()))
return
}
case []byte:
output = response.([]byte)
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write(output)
}
2 changes: 1 addition & 1 deletion client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ 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/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/crypto/keys/mintkey"
"github.com/cosmos/cosmos-sdk/tests"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
Expand Down
5 changes: 3 additions & 2 deletions client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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"
gapp "github.com/cosmos/cosmos-sdk/cmd/gaia/app"
Expand All @@ -29,6 +29,7 @@ import (
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/tests"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/auth"
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
txbuilder "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
Expand Down Expand Up @@ -653,7 +654,7 @@ func doSign(t *testing.T, port, name, password, chainID string, accnum, sequence

// POST /tx/broadcast Send a signed Tx
func doBroadcast(t *testing.T, port string, msg auth.StdTx) sdk.TxResponse {
tx := rest.BroadcastReq{Tx: msg, Return: "block"}
tx := authrest.BroadcastReq{Tx: msg, Return: "block"}
req, err := cdc.MarshalJSON(tx)
require.Nil(t, err)
res, body := Request(t, port, "POST", "/tx/broadcast", req)
Expand Down
Loading