This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete proposal execution workflow
- Loading branch information
Showing
8 changed files
with
571 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package group | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
// ensureMsgAuthZ checks that if a message requires signers that all of them are equal to the given group account. | ||
func ensureMsgAuthZ(msgs []sdk.Msg, groupAccount sdk.AccAddress) error { | ||
for i := range msgs { | ||
for _, acct := range msgs[i].GetSigners() { | ||
if !groupAccount.Equals(acct) { | ||
return errors.Wrap(errors.ErrUnauthorized, "msg does not have group account authorization") | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// doExecuteMsgs routes the messages to the registered handlers. Messages are limited to those that require no authZ or | ||
// by the group account only. Otherwise this gives access to other peoples accounts as the sdk ant handler is bypassed | ||
func doExecuteMsgs(ctx sdk.Context, router sdk.Router, groupAccount sdk.AccAddress, msgs []sdk.Msg) ([]sdk.Result, error) { | ||
results := make([]sdk.Result, len(msgs)) | ||
if err := ensureMsgAuthZ(msgs, groupAccount); err != nil { | ||
return nil, err | ||
} | ||
for i, msg := range msgs { | ||
handler := router.Route(ctx, msg.Route()) | ||
if handler == nil { | ||
return nil, errors.Wrapf(ErrInvalid, "no message handler found for %q", msg.Route()) | ||
} | ||
r, err := handler(ctx, msg) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "message %q at position %d", msg.Type(), i) | ||
} | ||
if r != nil { | ||
results[i] = *r | ||
} | ||
} | ||
return results, nil | ||
} |
Oops, something went wrong.