Skip to content

Commit

Permalink
feat(x/gov): add MsgSubmitProposal SetMsgs method (backport cosmos#17387
Browse files Browse the repository at this point in the history
) (cosmos#17388)

Co-authored-by: Julien Robert <julien@rbrt.fr>
  • Loading branch information
2 people authored and JeancarloBarrios committed Sep 28, 2024
1 parent f613d15 commit 100531d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (x/gov) [#17387](https://github.com/cosmos/cosmos-sdk/pull/17387) Add `MsgSubmitProposal` `SetMsgs` method.
* (x/gov) [#17354](https://github.com/cosmos/cosmos-sdk/issues/17354) Emit `VoterAddr` in `proposal_vote` event.
* (x/genutil) [#17296](https://github.com/cosmos/cosmos-sdk/pull/17296) Add `MigrateHandler` to allow reuse migrate genesis related function.
* In v0.46, v0.47 this function is additive to the `genesis migrate` command. However in v0.50+, adding custom migrations to the `genesis migrate` command is directly possible.
Expand Down
35 changes: 35 additions & 0 deletions x/gov/types/v1/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,41 @@ func (m *MsgSubmitProposal) SetMsgs(msgs []sdk.Msg) error {
return nil
}

// Route implements Msg
func (m MsgSubmitProposal) Route() string { return types.RouterKey }

// Type implements Msg
func (m MsgSubmitProposal) Type() string { return sdk.MsgTypeURL(&m) }

// ValidateBasic implements Msg
func (m MsgSubmitProposal) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.Proposer); err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid proposer address: %s", err)
}

deposit := sdk.NewCoins(m.InitialDeposit...)
if !deposit.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, deposit.String())
}

if deposit.IsAnyNegative() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, deposit.String())
}

// Check that either metadata or Msgs length is non nil.
if len(m.Messages) == 0 && len(m.Metadata) == 0 {
return sdkerrors.Wrap(types.ErrNoProposalMsgs, "either metadata or Msgs length must be non-nil")
}

msgs, err := m.GetMsgs()
if err != nil {
return err
}

m.Messages = anys
return nil
}

// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (m MsgSubmitProposal) UnpackInterfaces(unpacker gogoprotoany.AnyUnpacker) error {
return sdktx.UnpackInterfaces(unpacker, m.Messages)
Expand Down

0 comments on commit 100531d

Please sign in to comment.