Merge PR #3580: Code cleanup of client types
This commit is contained in:
committed by
Jack Zampolin
parent
f72a7c3829
commit
1aa6c197ff
+3
-2
@@ -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"
|
||||
|
||||
@@ -399,7 +400,7 @@ func AddNewKeyRequestHandler(indent bool) http.HandlerFunc {
|
||||
|
||||
keyOutput.Mnemonic = mnemonic
|
||||
|
||||
PostProcessResponse(w, cdc, keyOutput, indent)
|
||||
rest.PostProcessResponse(w, cdc, keyOutput, indent)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,6 +489,6 @@ func RecoverRequestHandler(indent bool) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
PostProcessResponse(w, cdc, keyOutput, indent)
|
||||
rest.PostProcessResponse(w, cdc, keyOutput, indent)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -3,6 +3,7 @@ package keys
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -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"
|
||||
|
||||
@@ -188,6 +189,6 @@ func GetKeyRequestHandler(indent bool) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
PostProcessResponse(w, cdc, keyOutput, indent)
|
||||
rest.PostProcessResponse(w, cdc, keyOutput, indent)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user