Skip to content

Commit

Permalink
Refactor x/staking according to ADR 031 (cosmos#7556)
Browse files Browse the repository at this point in the history
* Refactor x/staking according to ADR 031

* lint

* review changes

* review changes

* review changes

Co-authored-by: Aaron Craelius <[email protected]>
  • Loading branch information
atheeshp and aaronc authored Oct 16, 2020
1 parent 8384a5a commit 18ef33c
Show file tree
Hide file tree
Showing 7 changed files with 1,473 additions and 452 deletions.
53 changes: 47 additions & 6 deletions proto/cosmos/staking/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,33 @@ package cosmos.staking.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "google/protobuf/timestamp.proto";
import "cosmos/staking/v1beta1/staking.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/staking/types";

// MsgCreateValidator defines an SDK message for creating a new validator.
// Msg defines the staking Msg service.
service Msg {
// CreateValidator defines a method for creating a new validator.
rpc CreateValidator(MsgCreateValidator) returns (MsgCreateValidatorResponse);

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

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

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

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

// MsgCreateValidator defines a SDK message for creating a new validator.
message MsgCreateValidator {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
Expand All @@ -25,7 +47,10 @@ message MsgCreateValidator {
cosmos.base.v1beta1.Coin value = 7 [(gogoproto.nullable) = false];
}

// MsgEditValidator defines an SDK message for editing an existing validator.
// MsgCreateValidatorResponse defines the Msg/CreateValidator response type.
message MsgCreateValidatorResponse { }

// MsgEditValidator defines a SDK message for editing an existing validator.
message MsgEditValidator {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
Expand All @@ -48,7 +73,10 @@ message MsgEditValidator {
];
}

// MsgDelegate defines an SDK message for performing a delegation of coins
// MsgEditValidatorResponse defines the Msg/EditValidator response type.
message MsgEditValidatorResponse { }

// MsgDelegate defines a SDK message for performing a delegation of coins
// from a delegator to a validator.
message MsgDelegate {
option (gogoproto.equal) = false;
Expand All @@ -59,7 +87,10 @@ message MsgDelegate {
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false];
}

// MsgBeginRedelegate defines an SDK message for performing a redelegation
// MsgDelegateResponse defines the Msg/Delegate response type.
message MsgDelegateResponse { }

// MsgBeginRedelegate defines a SDK message for performing a redelegation
// of coins from a delegator and source validator to a destination validator.
message MsgBeginRedelegate {
option (gogoproto.equal) = false;
Expand All @@ -71,7 +102,12 @@ message MsgBeginRedelegate {
cosmos.base.v1beta1.Coin amount = 4 [(gogoproto.nullable) = false];
}

// MsgUndelegate defines an SDK message for performing an undelegation from a
// MsgBeginRedelegateResponse defines the Msg/BeginRedelegate response type.
message MsgBeginRedelegateResponse {
google.protobuf.Timestamp completion_time = 1 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
}

// MsgUndelegate defines a SDK message for performing an undelegation from a
// delegate and a validator.
message MsgUndelegate {
option (gogoproto.equal) = false;
Expand All @@ -80,4 +116,9 @@ message MsgUndelegate {
string delegator_address = 1 [(gogoproto.moretags) = "yaml:\"delegator_address\""];
string validator_address = 2 [(gogoproto.moretags) = "yaml:\"validator_address\""];
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false];
}
}

// MsgUndelegateResponse defines the Msg/Undelegate response type.
message MsgUndelegateResponse {
google.protobuf.Timestamp completion_time = 1 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
}
4 changes: 2 additions & 2 deletions x/distribution/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
)

func NewHandler(k keeper.Keeper) sdk.Handler {
msgServer := keeper.NewMsgServerImpl(k)

return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())

msgServer := keeper.NewMsgServerImpl(k)

switch msg := msg.(type) {
case *types.MsgSetWithdrawAddress:
res, err := msgServer.SetWithdrawAddress(sdk.WrapSDKContext(ctx), msg)
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type msgServer struct {
Keeper
}

// NewMsgServerImpl returns an implementation of the bank MsgServer interface
// NewMsgServerImpl returns an implementation of the distribution MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{Keeper: keeper}
Expand Down
Loading

0 comments on commit 18ef33c

Please sign in to comment.