Skip to content

Commit

Permalink
fix: collect all responses from authz/MsgExec (#9538)
Browse files Browse the repository at this point in the history
## Description

Closes: #9536

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
robert-zaremba authored Jun 18, 2021
1 parent 105ad99 commit 6a5a2de
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 73 deletions.
2 changes: 1 addition & 1 deletion docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ MsgExecResponse defines the Msg/MsgExecResponse response type.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `result` | [cosmos.base.abci.v1beta1.Result](#cosmos.base.abci.v1beta1.Result) | | |
| `results` | [bytes](#bytes) | repeated | |



Expand Down
2 changes: 1 addition & 1 deletion proto/cosmos/authz/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ message MsgGrant {

// MsgExecResponse defines the Msg/MsgExecResponse response type.
message MsgExecResponse {
cosmos.base.abci.v1beta1.Result result = 1;
repeated bytes results = 1;
}

// MsgExec attempts to execute the provided messages using
Expand Down
14 changes: 7 additions & 7 deletions x/authz/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ func (k Keeper) update(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccA

// DispatchActions attempts to execute the provided messages via authorization
// grants from the message signer to the grantee.
func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs []sdk.Msg) (*sdk.Result, error) {
var msgResult *sdk.Result
var err error
for _, msg := range msgs {
func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs []sdk.Msg) ([][]byte, error) {
var results = make([][]byte, len(msgs))
for i, msg := range msgs {
signers := msg.GetSigners()
if len(signers) != 1 {
return nil, sdkerrors.ErrInvalidRequest.Wrap("authorization can be given to msg with only one signer")
Expand Down Expand Up @@ -103,19 +102,20 @@ func (k Keeper) DispatchActions(ctx sdk.Context, grantee sdk.AccAddress, msgs []
return nil, sdkerrors.ErrUnauthorized
}
}
handler := k.router.Handler(msg)

handler := k.router.Handler(msg)
if handler == nil {
return nil, sdkerrors.ErrUnknownRequest.Wrapf("unrecognized message route: %s", sdk.MsgTypeURL(msg))
}

msgResult, err = handler(ctx, msg)
msgResp, err := handler(ctx, msg)
if err != nil {
return nil, sdkerrors.Wrapf(err, "failed to execute message; message %v", msg)
}
results[i] = msgResp.Data
}

return msgResult, nil
return results, nil
}

// SaveGrant method grants the provided authorization to the grantee on the granter's account
Expand Down
4 changes: 2 additions & 2 deletions x/authz/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func (k Keeper) Exec(goCtx context.Context, msg *authz.MsgExec) (*authz.MsgExecR
if err != nil {
return nil, err
}
result, err := k.DispatchActions(ctx, grantee, msgs)
results, err := k.DispatchActions(ctx, grantee, msgs)
if err != nil {
return nil, err
}
return &authz.MsgExecResponse{Result: result}, nil
return &authz.MsgExecResponse{Results: results}, nil
}
118 changes: 56 additions & 62 deletions x/authz/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6a5a2de

Please sign in to comment.