From 6f486fd40cf22c7f66c5b704860d03f8f5d3ca25 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 15 Aug 2023 09:02:41 +0000 Subject: [PATCH] feat(x/gov): add MsgSubmitProposal SetMsgs method (backport #17387) (#17388) Co-authored-by: Julien Robert --- CHANGELOG.md | 1 + x/gov/types/v1/msgs.go | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d0448dcdba..6a3e8640161 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,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. diff --git a/x/gov/types/v1/msgs.go b/x/gov/types/v1/msgs.go index dd83bf5dfa4..e78121b0ab1 100644 --- a/x/gov/types/v1/msgs.go +++ b/x/gov/types/v1/msgs.go @@ -40,6 +40,18 @@ func (m *MsgSubmitProposal) GetMsgs() ([]sdk.Msg, error) { return sdktx.GetMsgs(m.Messages, "sdk.MsgProposal") } +// SetMsgs packs sdk.Msg's into m.Messages Any's +// NOTE: this will overwrite any existing messages +func (m *MsgSubmitProposal) SetMsgs(msgs []sdk.Msg) error { + anys, err := sdktx.SetMsgs(msgs) + if err != nil { + return err + } + + m.Messages = anys + return nil +} + // Route implements Msg func (m MsgSubmitProposal) Route() string { return types.RouterKey }