Merge PR #4924: Return Height on Query Errors + Update Account Endpoint
This commit is contained in:
parent
a697be15fe
commit
89b1220398
|
@ -67,6 +67,10 @@ longer panics if the store to load contains substores that we didn't explicitly
|
||||||
* (simulation) [\#4893](https://github.com/cosmos/cosmos-sdk/issues/4893) Change SimApp keepers to be public and add getter functions for keys and codec
|
* (simulation) [\#4893](https://github.com/cosmos/cosmos-sdk/issues/4893) Change SimApp keepers to be public and add getter functions for keys and codec
|
||||||
* (simulation) [\#4906](https://github.com/cosmos/cosmos-sdk/issues/4906) Add simulation `Config` struct that wraps simulation flags
|
* (simulation) [\#4906](https://github.com/cosmos/cosmos-sdk/issues/4906) Add simulation `Config` struct that wraps simulation flags
|
||||||
* (store) [\#4792](https://github.com/cosmos/cosmos-sdk/issues/4792) panic on non-registered store
|
* (store) [\#4792](https://github.com/cosmos/cosmos-sdk/issues/4792) panic on non-registered store
|
||||||
|
* (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.
|
||||||
* (types) [\#4821](https://github.com/cosmos/cosmos-sdk/issues/4821) types/errors package added with support for stacktraces. It is meant as a more feature-rich replacement for sdk.Errors in the mid-term.
|
* (types) [\#4821](https://github.com/cosmos/cosmos-sdk/issues/4821) types/errors package added with support for stacktraces. It is meant as a more feature-rich replacement for sdk.Errors in the mid-term.
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
|
@ -95,7 +95,7 @@ func (ctx CLIContext) query(path string, key cmn.HexBytes) (res []byte, height i
|
||||||
|
|
||||||
resp := result.Response
|
resp := result.Response
|
||||||
if !resp.IsOK() {
|
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
|
// 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)
|
err = ctx.verifyProof(path, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, height, err
|
return res, resp.Height, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp.Value, resp.Height, nil
|
return resp.Value, resp.Height, nil
|
||||||
|
|
|
@ -34,14 +34,17 @@ func QueryAccountRequestHandlerFn(storeName string, cliCtx context.CLIContext) h
|
||||||
}
|
}
|
||||||
|
|
||||||
accGetter := types.NewAccountRetriever(cliCtx)
|
accGetter := types.NewAccountRetriever(cliCtx)
|
||||||
// the query will return empty account if there is no data
|
|
||||||
|
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 {
|
if err := accGetter.EnsureExists(addr); err != nil {
|
||||||
|
cliCtx = cliCtx.WithHeight(height)
|
||||||
rest.PostProcessResponse(w, cliCtx, types.BaseAccount{})
|
rest.PostProcessResponse(w, cliCtx, types.BaseAccount{})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
account, height, err := accGetter.GetAccountWithHeight(addr)
|
|
||||||
if err != nil {
|
|
||||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
res, height, err := ar.querier.QueryWithData(fmt.Sprintf("custom/%s/%s", QuerierRoute, QueryAccount), bs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, height, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var account exported.Account
|
var account exported.Account
|
||||||
if err := ModuleCdc.UnmarshalJSON(res, &account); err != nil {
|
if err := ModuleCdc.UnmarshalJSON(res, &account); err != nil {
|
||||||
return nil, 0, err
|
return nil, height, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return account, height, nil
|
return account, height, nil
|
||||||
|
|
Loading…
Reference in New Issue