diff --git a/Makefile b/Makefile index 983234dbc3..4015f9de68 100644 --- a/Makefile +++ b/Makefile @@ -167,7 +167,7 @@ test_cover: @bash tests/test_cover.sh test_lint: - gometalinter.v2 --config=tools/gometalinter.json ./... + gometalinter.v2 --config=tools/gometalinter.json ./... | grep -v "client/lcd/statik" !(gometalinter.v2 --disable-all --enable='errcheck' --vendor ./... | grep -v "client/") find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s dep status >> /dev/null diff --git a/PENDING.md b/PENDING.md index 7eb324a23d..f0bdaaef0b 100644 --- a/PENDING.md +++ b/PENDING.md @@ -17,6 +17,7 @@ BREAKING CHANGES * \#2040 All commands that utilize a validator's address must now use the new bech32 prefix, `cosmosval`. A validator's Tendermint signing key and address now use a new bech32 prefix, `cosmoscons`. + * [cli] \#2215 `gaiacli rest-server` was renamed to `gaiacli lite-server`. In `gaiacli lite-server`, swagger-ui is supported. * Gaia * Make the transient store key use a distinct store key. [#2013](https://github.com/cosmos/cosmos-sdk/pull/2013) diff --git a/client/keys/add.go b/client/keys/add.go index 88cd9db4bc..de6039391d 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -164,7 +164,28 @@ type NewKeyBody struct { Seed string `json:"seed"` } -// add new key REST handler +func paramCheck(m NewKeyBody, kb keys.Keybase) (int, string) { + if m.Name == "" { + return http.StatusBadRequest, fmt.Sprintf("You have to specify a name for the locally stored account.") + } + if m.Password == "" { + return http.StatusBadRequest, fmt.Sprintf("You have to specify a password for the locally stored account.") + } + + // check if already exists + infos, err := kb.List() + if err != nil { + return http.StatusInternalServerError, err.Error() + } + for _, i := range infos { + if i.GetName() == m.Name { + return http.StatusConflict, fmt.Sprintf("Account with name %s already exists.", m.Name) + } + } + return http.StatusOK, "" +} + +// AddNewKeyRequestHandler add new key REST handler func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) { var kb keys.Keybase var m NewKeyBody @@ -190,32 +211,12 @@ func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) { return } - if err != nil { - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte(err.Error())) + code, errMsg := paramCheck(m, kb) + if code != http.StatusOK { + w.WriteHeader(code) + w.Write([]byte(errMsg)) return } - if m.Name == "" { - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte("You have to specify a name for the locally stored account.")) - return - } - if m.Password == "" { - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte("You have to specify a password for the locally stored account.")) - return - } - - // check if already exists - infos, err := kb.List() - for _, i := range infos { - if i.GetName() == m.Name { - w.WriteHeader(http.StatusConflict) - w.Write([]byte(fmt.Sprintf("Account with name %s already exists.", m.Name))) - return - } - } - // create account seed := m.Seed if seed == "" { diff --git a/docs/light/readme.md b/docs/light/readme.md index a9cdb2fff4..55e0c72ac3 100644 --- a/docs/light/readme.md +++ b/docs/light/readme.md @@ -20,6 +20,7 @@ LCD will be used in the Cosmos Hub, the first Hub in the Cosmos network. 2. [**Get Started**](getting_started.md) 3. [**API**](api.md) 4. [**Specifications**](specification.md) +4. [**Update API docs To Swagger-UI**](update_API_docs.md) ## Overview diff --git a/client/lcd/README.md b/docs/light/update_API_docs.md similarity index 100% rename from client/lcd/README.md rename to docs/light/update_API_docs.md