Merge PR #2215: Add swagger-ui for gaiacli lite-server

This commit is contained in:
HaoyangLiu
2018-10-04 13:00:24 +02:00
committed by Christopher Goes
parent b4e8fe5e94
commit 9f67e8af20
46 changed files with 81580 additions and 1050 deletions
+6 -8
View File
@@ -8,6 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -62,13 +63,10 @@ func getBlock(cliCtx context.CLIContext, height *int64) ([]byte, error) {
}
}
// TODO move maarshalling into cmd/rest functions
// output, err := tmcodec.MarshalJSON(res)
output, err := cdc.MarshalJSON(res)
if err != nil {
return nil, err
if cliCtx.Indent {
return cdc.MarshalJSONIndent(res, "", " ")
}
return output, nil
return cdc.MarshalJSON(res)
}
// get the current blockchain height
@@ -133,7 +131,7 @@ func BlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
w.Write([]byte(err.Error()))
return
}
w.Write(output)
utils.PostProcessResponse(w, cdc, output, cliCtx.Indent)
}
}
@@ -152,6 +150,6 @@ func LatestBlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
w.Write([]byte(err.Error()))
return
}
w.Write(output)
utils.PostProcessResponse(w, cdc, output, cliCtx.Indent)
}
}
+13 -11
View File
@@ -9,6 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/spf13/viper"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
)
@@ -22,6 +23,7 @@ func statusCommand() *cobra.Command {
cmd.Flags().StringP(client.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
viper.BindPFlag(client.FlagNode, cmd.Flags().Lookup(client.FlagNode))
cmd.Flags().Bool(client.FlagIndentResponse, false, "Add indent to JSON response")
return cmd
}
@@ -38,13 +40,20 @@ func getNodeStatus(cliCtx context.CLIContext) (*ctypes.ResultStatus, error) {
// CMD
func printNodeStatus(cmd *cobra.Command, args []string) error {
status, err := getNodeStatus(context.NewCLIContext())
// No need to verify proof in getting node status
viper.Set(client.FlagTrustNode, true)
cliCtx := context.NewCLIContext()
status, err := getNodeStatus(cliCtx)
if err != nil {
return err
}
output, err := cdc.MarshalJSON(status)
// output, err := cdc.MarshalJSONIndent(res, " ", "")
var output []byte
if cliCtx.Indent {
output, err = cdc.MarshalJSONIndent(status, "", " ")
} else {
output, err = cdc.MarshalJSON(status)
}
if err != nil {
return err
}
@@ -66,14 +75,7 @@ func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}
nodeInfo := status.NodeInfo
output, err := cdc.MarshalJSON(nodeInfo)
if err != nil {
w.WriteHeader(500)
w.Write([]byte(err.Error()))
return
}
w.Write(output)
utils.PostProcessResponse(w, cdc, nodeInfo, cliCtx.Indent)
}
}
+6 -8
View File
@@ -14,6 +14,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/viper"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/client/utils"
)
// TODO these next two functions feel kinda hacky based on their placement
@@ -98,12 +99,11 @@ func getValidators(cliCtx context.CLIContext, height *int64) ([]byte, error) {
}
}
output, err := cdc.MarshalJSON(outputValidatorsRes)
if err != nil {
return nil, err
if cliCtx.Indent {
return cdc.MarshalJSONIndent(outputValidatorsRes, "", " ")
}
return cdc.MarshalJSON(outputValidatorsRes)
return output, nil
}
// CMD
@@ -158,8 +158,7 @@ func ValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
w.Write([]byte(err.Error()))
return
}
w.Write(output)
utils.PostProcessResponse(w, cdc, output, cliCtx.Indent)
}
}
@@ -179,7 +178,6 @@ func LatestValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerF
w.Write([]byte(err.Error()))
return
}
w.Write(output)
utils.PostProcessResponse(w, cdc, output, cliCtx.Indent)
}
}