diff --git a/x/genutil/collect.go b/x/genutil/collect.go index d070f92c62f6..11b8db747d2b 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -12,7 +12,6 @@ import ( cfg "github.com/cometbft/cometbft/config" "cosmossdk.io/core/address" - stakingtypes "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -120,11 +119,12 @@ func CollectTxs(txJSONDecoder sdk.TxDecoder, moniker, genTxsDir string, // genesis transactions must be single-message msgs := genTx.GetMsgs() - // TODO abstract out staking message validation back to staking - msg := msgs[0].(*stakingtypes.MsgCreateValidator) - + msg, ok := msgs[0].(msgWithMoniker) + if !ok { + return appGenTxs, persistentPeers, fmt.Errorf("expected msgWithMoniker, got %T", msgs[0]) + } // exclude itself from persistent peers - if msg.Description.Moniker != moniker { + if msg.GetMoniker() != moniker { addressesIPs = append(addressesIPs, nodeAddrIP) } } @@ -134,3 +134,8 @@ func CollectTxs(txJSONDecoder sdk.TxDecoder, moniker, genTxsDir string, return appGenTxs, persistentPeers, nil } + +// MsgWithMoniker must have GetMoniker() method to use CollectTx +type msgWithMoniker interface { + GetMoniker() string +} diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 782183ff0684..b68818275ddf 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -90,6 +90,11 @@ func (msg MsgCreateValidator) Validate(ac address.Codec) error { return nil } +// GetMoniker returns the moniker of the validator +func (msg MsgCreateValidator) GetMoniker() string { + return msg.Description.GetMoniker() +} + // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (msg MsgCreateValidator) UnpackInterfaces(unpacker gogoprotoany.AnyUnpacker) error { var pubKey cryptotypes.PubKey