From c999a9a911bad3395a182ef897018713064d0ebc Mon Sep 17 00:00:00 2001 From: Shogo Hyodo Date: Tue, 6 Feb 2024 12:50:22 +0900 Subject: [PATCH] Remove global codec --- x/stakingplus/authz.go | 4 ---- x/stakingplus/keeper/msg_server.go | 10 +++++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x/stakingplus/authz.go b/x/stakingplus/authz.go index e585fc4f25..2e4d7231a4 100644 --- a/x/stakingplus/authz.go +++ b/x/stakingplus/authz.go @@ -28,9 +28,5 @@ func (a CreateValidatorAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (foun } func (a CreateValidatorAuthorization) ValidateBasic() error { - if _, err := sdk.ValAddressFromBech32(a.ValidatorAddress); err != nil { - return err - } - return nil } diff --git a/x/stakingplus/keeper/msg_server.go b/x/stakingplus/keeper/msg_server.go index 3b1bd03452..69bd3628cd 100644 --- a/x/stakingplus/keeper/msg_server.go +++ b/x/stakingplus/keeper/msg_server.go @@ -3,6 +3,8 @@ package keeper import ( "context" + addresscodec "cosmossdk.io/core/address" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/errors" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" @@ -13,15 +15,17 @@ import ( type msgServer struct { stakingtypes.MsgServer - - fk stakingplus.FoundationKeeper + fk stakingplus.FoundationKeeper + valCodec addresscodec.Codec } // NewMsgServerImpl returns an implementation of the staking MsgServer interface // for the provided Keeper. func NewMsgServerImpl(keeper *stakingkeeper.Keeper, fk stakingplus.FoundationKeeper) stakingtypes.MsgServer { + keeper.ValidatorAddressCodec() return &msgServer{ MsgServer: stakingkeeper.NewMsgServerImpl(keeper), + valCodec: keeper.ValidatorAddressCodec(), fk: fk, } } @@ -31,7 +35,7 @@ var _ stakingtypes.MsgServer = msgServer{} func (k msgServer) CreateValidator(goCtx context.Context, msg *stakingtypes.MsgCreateValidator) (*stakingtypes.MsgCreateValidatorResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) + valAddr, err := k.valCodec.StringToBytes(msg.ValidatorAddress) if err != nil { return nil, errors.ErrInvalidAddress.Wrapf("invalid validator address: %s", msg.ValidatorAddress) }