Skip to content

Commit

Permalink
refactor(x/accounts): add sender assertions to SendModuleMessageUntyp…
Browse files Browse the repository at this point in the history
…ed (cosmos#20197)
  • Loading branch information
sontrinh16 authored Apr 26, 2024
1 parent 84bae07 commit a6871c7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions x/accounts/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,17 @@ func (k Keeper) sendAnyMessages(ctx context.Context, sender []byte, anyMessages
// SendModuleMessageUntyped can be used to send a message towards a module.
// It should be used when the response type is not known by the caller.
func (k Keeper) SendModuleMessageUntyped(ctx context.Context, sender []byte, msg implementation.ProtoMsg) (implementation.ProtoMsg, error) {
// do sender assertions.
wantSenders, _, err := k.codec.GetMsgV1Signers(msg)
if err != nil {
return nil, fmt.Errorf("cannot get signers: %w", err)
}
if len(wantSenders) != 1 {
return nil, fmt.Errorf("expected only one signer, got %d", len(wantSenders))
}
if !bytes.Equal(sender, wantSenders[0]) {
return nil, fmt.Errorf("%w: sender does not match expected sender", ErrUnauthorized)
}
resp, err := k.RouterService.MessageRouterService().InvokeUntyped(ctx, msg)
if err != nil {
return nil, err
Expand Down

0 comments on commit a6871c7

Please sign in to comment.