mukan-ibc/e2e/testsuite/sanitize/messages.go
Mukan Erkin Törük 88dd97a9f8
Some checks failed
CodeQL / Analyze (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Has been cancelled
refactor: replace all github.com upstream refs with git.cw.tr/mukan-network
2026-05-11 03:36:22 +03:00

82 lines
2.5 KiB
Go

package sanitize
import (
sdk "git.cw.tr/mukan-network/mukan-sdk/types"
govtypesv1 "git.cw.tr/mukan-network/mukan-sdk/x/gov/types/v1"
grouptypes "git.cw.tr/mukan-network/mukan-sdk/x/group"
"github.com/cosmos/ibc-go/e2e/semverutil"
icacontrollertypes "git.cw.tr/mukan-network/mukan-ibc/modules/apps/27-interchain-accounts/controller/types"
channeltypes "git.cw.tr/mukan-network/mukan-ibc/modules/core/04-channel/types"
)
var (
// groupsv1ProposalTitleAndSummary represents the releases that support the new title and summary fields.
groupsv1ProposalTitleAndSummary = semverutil.FeatureReleases{
MajorVersion: "v7",
}
// govv1ProposalTitleAndSummary represents the releases that support the new title and summary fields.
govv1ProposalTitleAndSummary = semverutil.FeatureReleases{
MajorVersion: "v7",
}
// icaUnorderedChannelFeatureReleases represents the releasees that support the new ordering field.
icaUnorderedChannelFeatureReleases = semverutil.FeatureReleases{
MajorVersion: "v9",
MinorVersions: []string{
"v7.5",
"v8.1",
},
}
)
// Messages removes any fields that are not supported by the chain version.
// For example, any fields that have been added in later sdk releases.
func Messages(tag string, msgs ...sdk.Msg) []sdk.Msg {
sanitizedMsgs := make([]sdk.Msg, len(msgs))
for i := range msgs {
sanitizedMsgs[i] = removeUnknownFields(tag, msgs[i])
}
return sanitizedMsgs
}
// removeUnknownFields removes any fields that are not supported by the chain version.
// The input message is returned if no changes are made.
func removeUnknownFields(tag string, msg sdk.Msg) sdk.Msg {
switch msg := msg.(type) {
case *govtypesv1.MsgSubmitProposal:
if !govv1ProposalTitleAndSummary.IsSupported(tag) {
msg.Title = ""
msg.Summary = ""
}
// sanitize messages contained in the x/gov proposal
msgs, err := msg.GetMsgs()
if err != nil {
panic(err)
}
sanitizedMsgs := Messages(tag, msgs...)
if err := msg.SetMsgs(sanitizedMsgs); err != nil {
panic(err)
}
return msg
case *grouptypes.MsgSubmitProposal:
if !groupsv1ProposalTitleAndSummary.IsSupported(tag) {
msg.Title = ""
msg.Summary = ""
}
// sanitize messages contained in the x/group proposal
msgs, err := msg.GetMsgs()
if err != nil {
panic(err)
}
sanitizedMsgs := Messages(tag, msgs...)
if err := msg.SetMsgs(sanitizedMsgs); err != nil {
panic(err)
}
return msg
case *icacontrollertypes.MsgRegisterInterchainAccount:
if !icaUnorderedChannelFeatureReleases.IsSupported(tag) {
msg.Ordering = channeltypes.NONE
}
}
return msg
}