From 1a2bd70630e0ff07ca9fc2fcee4e2a7f95f89622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Aasted=20S=C3=B8rensen?= Date: Mon, 19 Aug 2019 15:22:07 +0200 Subject: [PATCH 1/3] Merge PR #4919: Fix GetConfirmation User Input Bug --- CHANGELOG.md | 2 ++ client/input/input.go | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b789545afe25..acb4b37930bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Update `handleQueryStore` to resemble `handleQueryCustom` * (simulation) [\#4912](https://github.com/cosmos/cosmos-sdk/issues/4912) Fix SimApp ModuleAccountAddrs to properly return black listed addresses for bank keeper initialization. +* (cli) [\#4919](https://github.com/cosmos/cosmos-sdk/pull/4919) Don't crash CLI +if user doesn't answer y/n confirmation request. ## [v0.36.0] - 2019-08-13 diff --git a/client/input/input.go b/client/input/input.go index 0ccf8c1b12aa..95f32281edd5 100644 --- a/client/input/input.go +++ b/client/input/input.go @@ -74,7 +74,12 @@ func GetConfirmation(prompt string, buf *bufio.Reader) (bool, error) { return false, err } - response = strings.ToLower(strings.TrimSpace(response)) + response = strings.TrimSpace(response) + if len(response) == 0 { + return false, nil + } + + response = strings.ToLower(response) if response[0] == 'y' { return true, nil } From 6b8655ed7b649cc5e394e97ab90c10239ae4557e Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Mon, 19 Aug 2019 10:58:11 -0400 Subject: [PATCH 2/3] Merge PR #4924: Return Height on Query Errors + Update Account Endpoint --- CHANGELOG.md | 9 ++++++++- client/context/query.go | 4 ++-- x/auth/client/rest/query.go | 13 ++++++++----- x/auth/types/account_retriever.go | 4 ++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index acb4b37930bb..73e490ea733f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] -## [v0.37.0] - 2019-08-16 +## [v0.37.0] - TBD ### Bug Fixes @@ -48,6 +48,13 @@ to properly return black listed addresses for bank keeper initialization. * (cli) [\#4919](https://github.com/cosmos/cosmos-sdk/pull/4919) Don't crash CLI if user doesn't answer y/n confirmation request. +### Improvements + +* (rest) [\#4924](https://github.com/cosmos/cosmos-sdk/pull/4924) Return response +height even upon error as it may be useful for the downstream caller and have +`/auth/accounts/{address}` return a 200 with an empty account upon error when +that error is that the account doesn't exist. + ## [v0.36.0] - 2019-08-13 ### Breaking Changes diff --git a/client/context/query.go b/client/context/query.go index 49ec0c59f7ab..2a553d663367 100644 --- a/client/context/query.go +++ b/client/context/query.go @@ -95,7 +95,7 @@ func (ctx CLIContext) query(path string, key cmn.HexBytes) (res []byte, height i resp := result.Response if !resp.IsOK() { - return res, height, errors.New(resp.Log) + return res, resp.Height, errors.New(resp.Log) } // data from trusted node or subspace query doesn't need verification @@ -105,7 +105,7 @@ func (ctx CLIContext) query(path string, key cmn.HexBytes) (res []byte, height i err = ctx.verifyProof(path, resp) if err != nil { - return res, height, err + return res, resp.Height, err } return resp.Value, resp.Height, nil diff --git a/x/auth/client/rest/query.go b/x/auth/client/rest/query.go index d4a1a32f8d30..be094b6c69a4 100644 --- a/x/auth/client/rest/query.go +++ b/x/auth/client/rest/query.go @@ -34,14 +34,17 @@ func QueryAccountRequestHandlerFn(storeName string, cliCtx context.CLIContext) h } accGetter := types.NewAccountRetriever(cliCtx) - // the query will return empty account if there is no data - if err := accGetter.EnsureExists(addr); err != nil { - rest.PostProcessResponse(w, cliCtx, types.BaseAccount{}) - return - } account, height, err := accGetter.GetAccountWithHeight(addr) if err != nil { + // TODO: Handle more appropriately based on the error type. + // Ref: https://github.com/cosmos/cosmos-sdk/issues/4923 + if err := accGetter.EnsureExists(addr); err != nil { + cliCtx = cliCtx.WithHeight(height) + rest.PostProcessResponse(w, cliCtx, types.BaseAccount{}) + return + } + rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return } diff --git a/x/auth/types/account_retriever.go b/x/auth/types/account_retriever.go index 90af84ec6057..ab87e3259b95 100644 --- a/x/auth/types/account_retriever.go +++ b/x/auth/types/account_retriever.go @@ -44,12 +44,12 @@ func (ar AccountRetriever) GetAccountWithHeight(addr sdk.AccAddress) (exported.A res, height, err := ar.querier.QueryWithData(fmt.Sprintf("custom/%s/%s", QuerierRoute, QueryAccount), bs) if err != nil { - return nil, 0, err + return nil, height, err } var account exported.Account if err := ModuleCdc.UnmarshalJSON(res, &account); err != nil { - return nil, 0, err + return nil, height, err } return account, height, nil From 8d1f9bb378bef74c87c4b5bcae16410215cc80fb Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Tue, 20 Aug 2019 12:57:27 -0400 Subject: [PATCH 3/3] Merge PR #4932: Fix gov query vote cmd --- CHANGELOG.md | 2 ++ x/gov/client/cli/query.go | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73e490ea733f..6a79102044f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ to properly return black listed addresses for bank keeper initialization. * (cli) [\#4919](https://github.com/cosmos/cosmos-sdk/pull/4919) Don't crash CLI if user doesn't answer y/n confirmation request. +* (cli) [\#4927](https://github.com/cosmos/cosmos-sdk/issues/4927) Fix the `q gov vote` +command to handle empty (pruned) votes correctly. ### Improvements diff --git a/x/gov/client/cli/query.go b/x/gov/client/cli/query.go index 28b957e41bbc..8dc4642e36b4 100644 --- a/x/gov/client/cli/query.go +++ b/x/gov/client/cli/query.go @@ -215,21 +215,24 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk } var vote types.Vote - if err := cdc.UnmarshalJSON(res, &vote); err != nil { - return err - } + + // XXX: Allow the decoding to potentially fail as the vote may have been + // pruned from state. If so, decoding will fail and so we need to check the + // Empty() case. Consider updating Vote JSON decoding to not fail when empty. + _ = cdc.UnmarshalJSON(res, &vote) if vote.Empty() { res, err = gcutils.QueryVoteByTxQuery(cliCtx, params) if err != nil { return err } + if err := cdc.UnmarshalJSON(res, &vote); err != nil { return err } } - return cliCtx.PrintOutput(vote) //nolint:errcheck + return cliCtx.PrintOutput(vote) }, } }