diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ae9bac0a4..92e9156574 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog ## [Unreleased] +* [\#9205](https://github.com/cosmos/cosmos-sdk/pull/9205) Improve readability in `abci` handleQueryP2P ## Features * [\#8965](https://github.com/cosmos/cosmos-sdk/pull/8965) cosmos reflection now provides more information on the application such as: deliverable msgs, sdk.Config info etc (still in alpha stage). diff --git a/baseapp/abci.go b/baseapp/abci.go index f7ecb16e6f..399fc42efe 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -799,28 +799,32 @@ func handleQueryStore(app *BaseApp, path []string, req abci.RequestQuery) abci.R func handleQueryP2P(app *BaseApp, path []string) abci.ResponseQuery { // "/p2p" prefix for p2p queries - if len(path) >= 4 { - cmd, typ, arg := path[1], path[2], path[3] - switch cmd { - case "filter": - switch typ { - case "addr": - return app.FilterPeerByAddrPort(arg) - - case "id": - return app.FilterPeerByID(arg) - } - - default: - return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "expected second parameter to be 'filter'")) - } + if len(path) < 4 { + return sdkerrors.QueryResult( + sdkerrors.Wrap( + sdkerrors.ErrUnknownRequest, "path should be p2p filter ", + ), + ) } - return sdkerrors.QueryResult( - sdkerrors.Wrap( - sdkerrors.ErrUnknownRequest, "expected path is p2p filter ", - ), - ) + var resp abci.ResponseQuery + + cmd, typ, arg := path[1], path[2], path[3] + switch cmd { + case "filter": + switch typ { + case "addr": + resp = app.FilterPeerByAddrPort(arg) + + case "id": + resp = app.FilterPeerByID(arg) + } + + default: + resp = sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "expected second parameter to be 'filter'")) + } + + return resp } func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) abci.ResponseQuery {