From b7f27a0e1faf98c2d35306c68f3b2f8c5e08cc27 Mon Sep 17 00:00:00 2001 From: HaoyangLiu Date: Sun, 30 Sep 2018 12:35:06 +0800 Subject: [PATCH] update gopkg.lock and fix compile error --- Gopkg.lock | 9 +++++++++ client/lcd/lcd_test.go | 10 ++-------- client/lcd/root.go | 19 +++++++++++-------- client/lcd/swagger-ui/swagger.yaml | 10 +++++----- client/tx/root.go | 2 +- client/tx/search.go | 2 +- 6 files changed, 29 insertions(+), 23 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 00eafa4ade..9b753baf2c 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -312,6 +312,14 @@ pruneopts = "UT" revision = "05ee40e3a273f7245e8777337fc7b46e533a9a92" +[[projects]] + digest = "1:ea0700160aca4ef099f4e06686a665a87691f4248dddd40796925eda2e46bd64" + name = "github.com/rakyll/statik" + packages = ["fs"] + pruneopts = "UT" + revision = "aa8a7b1baecd0f31a436bf7956fcdcc609a83035" + version = "v0.1.4" + [[projects]] digest = "1:c4556a44e350b50a490544d9b06e9fba9c286c21d6c0e47f54f3a9214597298c" name = "github.com/rcrowley/go-metrics" @@ -641,6 +649,7 @@ "github.com/mitchellh/go-homedir", "github.com/pelletier/go-toml", "github.com/pkg/errors", + "github.com/rakyll/statik/fs", "github.com/spf13/cobra", "github.com/spf13/pflag", "github.com/spf13/viper", diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 1419fdb9a6..e91aaf90a3 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -45,12 +45,6 @@ func TestKeys(t *testing.T) { cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr}) defer cleanup() - // recover key - res, body := doRecoverKey(t, port, seed) - var response keys.KeyOutput - err := wire.Cdc.UnmarshalJSON([]byte(body), &response) - require.Nil(t, err, body) - reg, err := regexp.Compile(`([a-z]+ ){12}`) require.Nil(t, err) match := reg.MatchString(seed) @@ -61,7 +55,7 @@ func TestKeys(t *testing.T) { // add key jsonStr := []byte(fmt.Sprintf(`{"name":"%s", "password":"%s", "seed":"%s"}`, newName, newPassword, seed)) - res, body = Request(t, port, "POST", "/keys", jsonStr) + res, body := Request(t, port, "POST", "/keys", jsonStr) require.Equal(t, http.StatusOK, res.StatusCode, body) var resp keys.KeyOutput @@ -80,7 +74,7 @@ func TestKeys(t *testing.T) { // existing keys res, body = Request(t, port, "GET", "/keys", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) - var m [3]keys.KeyOutput + var m [2]keys.KeyOutput err = cdc.UnmarshalJSON([]byte(body), &m) require.Nil(t, err) diff --git a/client/lcd/root.go b/client/lcd/root.go index 704e61f932..663b7c1ad1 100644 --- a/client/lcd/root.go +++ b/client/lcd/root.go @@ -47,6 +47,7 @@ func ServeCommand(cdc *codec.Codec) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) (err error) { listenAddr := viper.GetString(flagListenAddr) handler := createHandler(cdc) + registerSwaggerUI(handler) logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "rest-server") maxOpen := viper.GetInt(flagMaxOpenConnections) sslHosts := viper.GetString(flagSSLHosts) @@ -129,7 +130,7 @@ func ServeCommand(cdc *codec.Codec) *cobra.Command { return cmd } -func createHandler(cdc *codec.Codec) http.Handler { +func createHandler(cdc *codec.Codec) *mux.Router { r := mux.NewRouter() kb, err := keys.GetKeyBase() //XXX @@ -137,13 +138,6 @@ func createHandler(cdc *codec.Codec) http.Handler { panic(err) } - statikFS, err := fs.New() - if err != nil { - panic(err) - } - staticServer := http.FileServer(statikFS) - r.PathPrefix("/swagger-ui/").Handler(http.StripPrefix("/swagger-ui/", staticServer)) - cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -163,6 +157,15 @@ func createHandler(cdc *codec.Codec) http.Handler { return r } +func registerSwaggerUI(r *mux.Router) { + statikFS, err := fs.New() + if err != nil { + panic(err) + } + staticServer := http.FileServer(statikFS) + r.PathPrefix("/swagger-ui/").Handler(http.StripPrefix("/swagger-ui/", staticServer)) +} + func validateCertKeyFiles(certFile, keyFile string) error { if keyFile == "" { return errors.New("a key file is required") diff --git a/client/lcd/swagger-ui/swagger.yaml b/client/lcd/swagger-ui/swagger.yaml index a9e93e36c1..2295c06257 100644 --- a/client/lcd/swagger-ui/swagger.yaml +++ b/client/lcd/swagger-ui/swagger.yaml @@ -178,16 +178,17 @@ paths: $ref: "#/definitions/TxQuery" 404: description: Tx not available for provided hash - /txs/search: + /txs: get: tags: - ICS0 - summary: Query Tx + summary: Search transactions + description: Search transactions by tag parameters: - in: query name: tag type: string - description: "transaction tag, for instance: sender=`'cosmos1g9ahr6xhht5rmqven628nklxluzyv8z9jqjcmc'`" + description: "transaction tag, for instance: sender_bech32=`'cosmos1g9ahr6xhht5rmqven628nklxluzyv8z9jqjcmc'`" required: true - in: query name: page @@ -206,12 +207,11 @@ paths: $ref: "#/definitions/TxQuery" 404: description: Pagination is out of bounds - /txs: post: tags: - ICS0 summary: broadcast Tx - description: broadcast tx + description: broadcast tx with tendermint rpc parameters: - in: body name: txBroadcast diff --git a/client/tx/root.go b/client/tx/root.go index 711c896e26..ef3523a1cc 100644 --- a/client/tx/root.go +++ b/client/tx/root.go @@ -19,7 +19,7 @@ func AddCommands(cmd *cobra.Command, cdc *codec.Codec) { // register REST routes func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) { r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(cdc, cliCtx)).Methods("GET") - r.HandleFunc("/txs/search", SearchTxRequestHandlerFn(cliCtx, cdc)).Methods("GET") + r.HandleFunc("/txs", SearchTxRequestHandlerFn(cliCtx, cdc)).Methods("GET") // r.HandleFunc("/txs/sign", SignTxRequstHandler).Methods("POST") r.HandleFunc("/txs", BroadcastTxRequest(cliCtx, cdc)).Methods("POST") } diff --git a/client/tx/search.go b/client/tx/search.go index 8d83c44b3e..57b50d6840 100644 --- a/client/tx/search.go +++ b/client/tx/search.go @@ -174,7 +174,7 @@ func SearchTxRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http. return } - output, err := cdc.MarshalJSON(txs) + output, err := cdc.MarshalJSONIndent(txs, "", " ") if err != nil { w.WriteHeader(500) w.Write([]byte(err.Error()))