Skip to content

Commit

Permalink
refactor(x/staking): use default staking msgs but override create-val…
Browse files Browse the repository at this point in the history
…idator
  • Loading branch information
hacheigriega committed Dec 6, 2024
1 parent 8ea1819 commit 4b39fe9
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 355 deletions.
34 changes: 0 additions & 34 deletions proto/sedachain/staking/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,10 @@ import "sedachain/pubkey/v1/pubkey.proto";

option go_package = "github.com/sedaprotocol/seda-chain/x/staking/types";

// Msg defines the staking Msg service.
service Msg {
// CreateSEDAValidator defines a method for creating a new validator.
rpc CreateSEDAValidator(MsgCreateSEDAValidator)
returns (MsgCreateSEDAValidatorResponse);

// EditValidator defines a method for editing an existing validator.
rpc EditValidator(cosmos.staking.v1beta1.MsgEditValidator)
returns (cosmos.staking.v1beta1.MsgEditValidatorResponse);

// Delegate defines a method for performing a delegation of coins
// from a delegator to a validator.
rpc Delegate(cosmos.staking.v1beta1.MsgDelegate)
returns (cosmos.staking.v1beta1.MsgDelegateResponse);

// BeginRedelegate defines a method for performing a redelegation
// of coins from a delegator and source validator to a destination validator.
rpc BeginRedelegate(cosmos.staking.v1beta1.MsgBeginRedelegate)
returns (cosmos.staking.v1beta1.MsgBeginRedelegateResponse);

// Undelegate defines a method for performing an undelegation from a
// delegate and a validator.
rpc Undelegate(cosmos.staking.v1beta1.MsgUndelegate)
returns (cosmos.staking.v1beta1.MsgUndelegateResponse);

// CancelUnbondingDelegation defines a method for performing canceling the
// unbonding delegation and delegate back to previous validator.
//
// Since: cosmos-sdk 0.46
rpc CancelUnbondingDelegation(
cosmos.staking.v1beta1.MsgCancelUnbondingDelegation)
returns (cosmos.staking.v1beta1.MsgCancelUnbondingDelegationResponse);

// UpdateParams defines an operation for updating the x/staking module
// parameters.
// Since: cosmos-sdk 0.47
rpc UpdateParams(cosmos.staking.v1beta1.MsgUpdateParams)
returns (cosmos.staking.v1beta1.MsgUpdateParamsResponse);
}

// MsgCreateSEDAValidator defines a message for creating a new SEDA
Expand Down
2 changes: 2 additions & 0 deletions x/pubkey/keeper/endblock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ func initFixture(tb testing.TB) *fixture {
})

types.RegisterMsgServer(integrationApp.MsgServiceRouter(), keeper.NewMsgServerImpl(pubKeyKeeper))

sdkStakingMsgServer := sdkstakingkeeper.NewMsgServerImpl(sdkStakingKeeper)
stakingMsgServer := stakingkeeper.NewMsgServerImpl(sdkStakingMsgServer, stakingKeeper)
sdkstakingtypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), stakingMsgServer)
stakingtypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), stakingMsgServer)

return &fixture{
Expand Down
2 changes: 1 addition & 1 deletion x/staking/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewTxCmd(valAddrCodec, ac address.Codec) *cobra.Command {
func NewCreateValidatorCmd(ac address.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "create-validator [path/to/validator.json]",
Short: "create new validator initialized with a self-delegation to it",
Short: "Create new validator initialized with a self-delegation to it",
Args: cobra.ExactArgs(1),
Long: `Create a new validator initialized with a self-delegation by submitting a JSON file with the new validator details.`,
Example: strings.TrimSpace(
Expand Down
35 changes: 10 additions & 25 deletions x/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package keeper
import (
"context"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand All @@ -18,14 +20,21 @@ type msgServer struct {
*Keeper
}

func NewMsgServerImpl(sdkMsgServer stakingtypes.MsgServer, keeper *Keeper) types.MsgServer {
func NewMsgServerImpl(sdkMsgServer stakingtypes.MsgServer, keeper *Keeper) types.CombinedMsgServer {

Check failure on line 23 in x/staking/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / golangci

undefined: types.CombinedMsgServer (typecheck)

Check failure on line 23 in x/staking/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / golangci

undefined: types.CombinedMsgServer) (typecheck)

Check failure on line 23 in x/staking/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / golangci

undefined: types.CombinedMsgServer) (typecheck)

Check failure on line 23 in x/staking/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / golangci

undefined: types.CombinedMsgServer) (typecheck)

Check failure on line 23 in x/staking/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / linux-amd64

undefined: types.CombinedMsgServer

Check failure on line 23 in x/staking/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / darwin-arm64

undefined: types.CombinedMsgServer

Check failure on line 23 in x/staking/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / linux-arm64

undefined: types.CombinedMsgServer

Check failure on line 23 in x/staking/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / darwin-amd64

undefined: types.CombinedMsgServer

Check failure on line 23 in x/staking/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / unit-tests

undefined: types.CombinedMsgServer
ms := &msgServer{
MsgServer: sdkMsgServer,
Keeper: keeper,
}
return ms
}

// CreateValidator overrides the default CreateValidator method.
func (m msgServer) CreateValidator(ctx context.Context, msg *stakingtypes.MsgCreateValidator) (*stakingtypes.MsgCreateValidatorResponse, error) {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "not implemented")
}

// CreateSEDAValidator stores given SEDA public keys, if provided, and
// creates a validator.
func (m msgServer) CreateSEDAValidator(ctx context.Context, msg *types.MsgCreateSEDAValidator) (*types.MsgCreateSEDAValidatorResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

Expand Down Expand Up @@ -71,27 +80,3 @@ func (m msgServer) CreateSEDAValidator(ctx context.Context, msg *types.MsgCreate
}
return &types.MsgCreateSEDAValidatorResponse{}, nil
}

func (m msgServer) EditValidator(ctx context.Context, msg *stakingtypes.MsgEditValidator) (*stakingtypes.MsgEditValidatorResponse, error) {
return m.MsgServer.EditValidator(ctx, msg)
}

func (m msgServer) Delegate(ctx context.Context, msg *stakingtypes.MsgDelegate) (*stakingtypes.MsgDelegateResponse, error) {
return m.MsgServer.Delegate(ctx, msg)
}

func (m msgServer) BeginRedelegate(ctx context.Context, msg *stakingtypes.MsgBeginRedelegate) (*stakingtypes.MsgBeginRedelegateResponse, error) {
return m.MsgServer.BeginRedelegate(ctx, msg)
}

func (m msgServer) Undelegate(ctx context.Context, msg *stakingtypes.MsgUndelegate) (*stakingtypes.MsgUndelegateResponse, error) {
return m.MsgServer.Undelegate(ctx, msg)
}

func (m msgServer) CancelUnbondingDelegation(ctx context.Context, msg *stakingtypes.MsgCancelUnbondingDelegation) (*stakingtypes.MsgCancelUnbondingDelegationResponse, error) {
return m.MsgServer.CancelUnbondingDelegation(ctx, msg)
}

func (m msgServer) UpdateParams(ctx context.Context, msg *stakingtypes.MsgUpdateParams) (*stakingtypes.MsgUpdateParamsResponse, error) {
return m.MsgServer.UpdateParams(ctx, msg)
}
2 changes: 2 additions & 0 deletions x/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ func NewAppModule(
func (am AppModule) RegisterServices(cfg module.Configurator) {
sdkMsgServer := sdkkeeper.NewMsgServerImpl(am.keeper.Keeper)
msgServer := keeper.NewMsgServerImpl(sdkMsgServer, am.keeper)

sdktypes.RegisterMsgServer(cfg.MsgServer(), msgServer)
types.RegisterMsgServer(cfg.MsgServer(), msgServer)

querier := sdkkeeper.Querier{Keeper: am.keeper.Keeper}
Expand Down
1 change: 1 addition & 0 deletions x/staking/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgCreateSEDAValidator{},
&types.MsgCreateValidator{},
&types.MsgEditValidator{},
&types.MsgDelegate{},
&types.MsgUndelegate{},
Expand Down
Loading

0 comments on commit 4b39fe9

Please sign in to comment.