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]: add swagger-ui for gov, stake and slashing #2462

Merged
merged 28 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
126dc8a
Add swagger-ui for gov, stake and slashing
Oct 9, 2018
d8852d7
Add json consume
Oct 9, 2018
eadaf43
Add json to response header
Oct 10, 2018
1774658
Fix some bugs in stake APIs
Oct 10, 2018
da7dc49
Refactor swagger.ymal, remove definitions which are only referenced once
Oct 10, 2018
e529488
Remove duplicated json header
Oct 10, 2018
66eb6f9
Merge branch 'develop' of https://github.com/cosmos/cosmos-sdk into i…
Oct 10, 2018
4ba59c7
refactor query validator set response
Oct 10, 2018
6e1a4d1
Refactor swagger.yaml according code reviewer feedback
Oct 10, 2018
ba4eadd
Add response model
Oct 11, 2018
cde3db1
Merge with develop
Oct 18, 2018
4c08aed
Merge branch 'develop' of https://github.com/cosmos/cosmos-sdk into i…
Oct 19, 2018
e050d89
Fix lcd test failure: TestUnjail
Oct 19, 2018
9db8dc2
Add response mode and add error code for all query endpoints
Oct 19, 2018
5270da6
fix ci test failure
Oct 19, 2018
6ec2d88
Resolve some spell error, add missing gov endpoint and modify swagger…
Oct 19, 2018
9136254
Fix wrong response body
Oct 19, 2018
131e0ca
Resolve inconsistence between swagger.yaml and code implementation
Oct 19, 2018
2f09cd7
Merge with develop
Oct 20, 2018
eb7d3df
Update swagger.yaml to accommodate handler implementation changes
Oct 20, 2018
2b267fc
Fix bug in normalize gov parameters
Oct 20, 2018
8363685
Add example value to proposal type and vote option
Oct 20, 2018
88b4c66
Improve error handler in delete and update key
Oct 20, 2018
4631c0b
Merge branch 'develop' of https://github.com/cosmos/cosmos-sdk into i…
Oct 22, 2018
8045d49
Implement error type in key base
Oct 23, 2018
d88a213
Add /stake/validators/{validatorAddr}/unbonding_delegations and /stak…
Oct 23, 2018
6d6b58a
Merge branch 'develop' of https://github.com/cosmos/cosmos-sdk into i…
Oct 24, 2018
fb04cfb
Add change to about split issue 2258 to swagger.yaml
Oct 24, 2018
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
2 changes: 1 addition & 1 deletion PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ FEATURES
* [gaia-lite] [\#966](https://github.com/cosmos/cosmos-sdk/issues/966) Add support for `generate_only=true` query argument to generate offline unsigned transactions
* [gaia-lite] [\#1953](https://github.com/cosmos/cosmos-sdk/issues/1953) Add /sign endpoint to sign transactions generated with `generate_only=true`.
* [gaia-lite] [\#1954](https://github.com/cosmos/cosmos-sdk/issues/1954) Add /broadcast endpoint to broadcast transactions signed by the /sign endpoint.
* [gaia-lite] [\#2113](https://github.com/cosmos/cosmos-sdk/issues/2113) Rename `/accounts/{address}/send` to `/bank/accounts/{address}/transfers`, rename `/accounts/{address}` to `/auth/accounts/{address}`
* [gaia-lite] [\#2113](https://github.com/cosmos/cosmos-sdk/issues/2113) Rename `/accounts/{address}/send` to `/bank/accounts/{address}/transfers`, rename `/accounts/{address}` to `/auth/accounts/{address}`, replace `proposal-id` with `proposalId` in all gov endpoints
* [gaia-lite] [\#2478](https://github.com/cosmos/cosmos-sdk/issues/2478) Add query gov proposal's deposits endpoint

* Gaia CLI (`gaiacli`)
Expand Down
8 changes: 5 additions & 3 deletions client/keys/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ func GetKeyRequestHandler(indent bool) http.HandlerFunc {
}

info, err := GetKeyInfo(name)
// TODO: check for the error if key actually does not exist, instead of
// assuming this as the reason
if err != nil {
if IsKeyNotFoundErr(err, name) {
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(err.Error()))
return
} else if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}

keyOutput, err := bechKeyOut(info)
Expand Down
17 changes: 17 additions & 0 deletions client/keys/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"net/http"
"strings"
)

// KeyDBName is the directory under root where we store the keys
Expand Down Expand Up @@ -256,3 +257,19 @@ func PostProcessResponse(w http.ResponseWriter, cdc *codec.Codec, response inter
w.Header().Set("Content-Type", "application/json")
w.Write(output)
}

// IsKeyNotFoundErr - check if the error means that the specified key doesn't exist
func IsKeyNotFoundErr(err error, name string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we export references to the exact error types instead of this sort of logic? It introduces technical debt.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have thought about this idea. But this will change key base implementaion. To avoid too much impact to the code, I chosen this implementation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HaoyangLiu How so? Ideally the client documentation shows the exact return types.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can check by the code or abci code I guess

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key base should export the error types directly - if it doesn't, let's fix it - all the relevant code should be in this repo I think.

Copy link
Author

@HaoyangLiu HaoyangLiu Oct 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry for misleading you. All code about key base implementation are in this repo too. My point is to minimize the change and limit the change to client code. If this is not a problem, I will change to code according to your suggestions.
@fedekunze
Currently the error has no error code or abci code. I will add error code in it.

if err != nil && strings.Contains(err.Error(), fmt.Sprintf("Key %s not found", name)) {
return true
}
return false
}

// IsWrongKeyPasswordErr - check if the error means that the specified key password is wrong
func IsWrongKeyPasswordErr(err error) bool {
if err != nil && strings.Contains(err.Error(), "Ciphertext decryption failed") {
return true
}
return false
}
2 changes: 1 addition & 1 deletion client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ func doIBCTransfer(t *testing.T, port, seed, name, password string, addr sdk.Acc
}

func getSigningInfo(t *testing.T, port string, validatorPubKey string) slashing.ValidatorSigningInfo {
res, body := Request(t, port, "GET", fmt.Sprintf("/slashing/signing_info/%s", validatorPubKey), nil)
res, body := Request(t, port, "GET", fmt.Sprintf("/slashing/validators/%s/signing_info", validatorPubKey), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var signingInfo slashing.ValidatorSigningInfo
Expand Down
Loading