From ec17e1e6eda170d27676f0cf8ca183614efe6b5a Mon Sep 17 00:00:00 2001 From: "james.zhang" <68689915+zenzenless@users.noreply.github.com> Date: Wed, 14 Aug 2024 18:06:39 +0800 Subject: [PATCH] chore: remove todo: "abstract out staking message back to staking" (#21266) Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- x/genutil/collect.go | 15 ++++++++++----- x/staking/types/msg.go | 5 +++++ 2 files changed, 15 insertions(+), 5 deletions(-) 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