Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix MsgEditValidator json tag #5342

Merged
merged 7 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ if the provided arguments are invalid.
* (rest) [\#4783](https://github.com/cosmos/cosmos-sdk/issues/4783) The balance field in the DelegationResponse type is now sdk.Coin instead of sdk.Int
* (x/auth) [\#5006](https://github.com/cosmos/cosmos-sdk/pull/5006) The gas required to pass the `AnteHandler` has
increased significantly due to modular `AnteHandler` support. Increase GasLimit accordingly.
* (rest) [\#5336](https://github.com/cosmos/cosmos-sdk/issues/5336) `MsgEditValidator` uses `delegator` instead of `Delegator` as a JSON key.

### Features

Expand Down
3 changes: 2 additions & 1 deletion x/staking/legacy/v0_36/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ package v0_36
import (
"time"

"github.com/tendermint/tendermint/crypto"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
"github.com/tendermint/tendermint/crypto"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion x/staking/legacy/v0_38/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ package v0_38
import (
"time"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/tendermint/tendermint/crypto"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_36"
Expand Down
72 changes: 48 additions & 24 deletions x/staking/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type msgCreateValidatorJSON struct {
Value sdk.Coin `json:"value" yaml:"value"`
}

// Default way to create validator. Delegator address and validator address are the same
// NewMsgCreateValidator creates a new MsgCreateValidator instance.
// Delegator address and validator address are the same
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func NewMsgCreateValidator(
valAddr sdk.ValAddress, pubKey crypto.PubKey, selfDelegation sdk.Coin,
description Description, commission CommissionRates, minSelfDelegation sdk.Int,
Expand All @@ -59,18 +60,21 @@ func NewMsgCreateValidator(
}
}

//nolint
// Route implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgCreateValidator) Route() string { return RouterKey }

// Type implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgCreateValidator) Type() string { return "create_validator" }

// Return address(es) that must sign over msg.GetSignBytes()
// GetSigners implements the sdk.Msg interface. It returns the address(es) that
// must sign over msg.GetSignBytes().
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
// If the validator address is not same as delegator's, then the validator must
// sign the msg as well.
func (msg MsgCreateValidator) GetSigners() []sdk.AccAddress {
// delegator is first signer so delegator pays fees
addrs := []sdk.AccAddress{msg.DelegatorAddress}

if !bytes.Equal(msg.DelegatorAddress.Bytes(), msg.ValidatorAddress.Bytes()) {
// if validator addr is not same as delegator addr, validator must sign
// msg as well
addrs = append(addrs, sdk.AccAddress(msg.ValidatorAddress))
}
return addrs
Expand Down Expand Up @@ -113,7 +117,7 @@ func (msg *MsgCreateValidator) UnmarshalJSON(bz []byte) error {
return nil
}

// custom marshal yaml function due to consensus pubkey
// MarshalYAML implements a custom marshal yaml function due to consensus pubkey
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgCreateValidator) MarshalYAML() (interface{}, error) {
bs, err := yaml.Marshal(struct {
Description Description
Expand Down Expand Up @@ -146,7 +150,7 @@ func (msg MsgCreateValidator) GetSignBytes() []byte {
return sdk.MustSortJSON(bz)
}

// quick validity check
// ValidateBasic implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgCreateValidator) ValidateBasic() sdk.Error {
// note that unmarshaling from bech32 ensures either empty or valid
if msg.DelegatorAddress.Empty() {
Expand Down Expand Up @@ -182,7 +186,7 @@ func (msg MsgCreateValidator) ValidateBasic() sdk.Error {

// MsgEditValidator - struct for editing a validator
type MsgEditValidator struct {
Description
Description Description `json:"description" yaml:"description"`
ValidatorAddress sdk.ValAddress `json:"address" yaml:"address"`

// We pass a reference to the new commission rate and min self delegation as it's not mandatory to
Expand All @@ -194,6 +198,7 @@ type MsgEditValidator struct {
MinSelfDelegation *sdk.Int `json:"min_self_delegation" yaml:"min_self_delegation"`
}

// NewMsgEditValidator creates a new MsgEditValidator instance
func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRate *sdk.Dec, newMinSelfDelegation *sdk.Int) MsgEditValidator {
return MsgEditValidator{
Description: description,
Expand All @@ -203,20 +208,24 @@ func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRat
}
}

//nolint
// Route implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgEditValidator) Route() string { return RouterKey }

// Type implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgEditValidator) Type() string { return "edit_validator" }

// GetSigners implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgEditValidator) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sdk.AccAddress(msg.ValidatorAddress)}
}

// get the bytes for the message signer to sign on
// GetSignBytes implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgEditValidator) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

// quick validity check
// ValidateBasic implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgEditValidator) ValidateBasic() sdk.Error {
if msg.ValidatorAddress.Empty() {
return sdk.NewError(DefaultCodespace, CodeInvalidInput, "nil validator address")
Expand Down Expand Up @@ -246,6 +255,7 @@ type MsgDelegate struct {
Amount sdk.Coin `json:"amount" yaml:"amount"`
}

// NewMsgDelegate creates a new MsgDelegate instance
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) MsgDelegate {
return MsgDelegate{
DelegatorAddress: delAddr,
Expand All @@ -254,20 +264,24 @@ func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.C
}
}

//nolint
// Route implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgDelegate) Route() string { return RouterKey }

// Type implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgDelegate) Type() string { return "delegate" }

// GetSigners implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgDelegate) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.DelegatorAddress}
}

// get the bytes for the message signer to sign on
// GetSignBytes implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgDelegate) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

// quick validity check
// ValidateBasic implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgDelegate) ValidateBasic() sdk.Error {
if msg.DelegatorAddress.Empty() {
return ErrNilDelegatorAddr(DefaultCodespace)
Expand All @@ -283,17 +297,18 @@ func (msg MsgDelegate) ValidateBasic() sdk.Error {

//______________________________________________________________________

// MsgDelegate - struct for bonding transactions
// MsgBeginRedelegate - struct for bonding transactions
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
type MsgBeginRedelegate struct {
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
ValidatorSrcAddress sdk.ValAddress `json:"validator_src_address" yaml:"validator_src_address"`
ValidatorDstAddress sdk.ValAddress `json:"validator_dst_address" yaml:"validator_dst_address"`
Amount sdk.Coin `json:"amount" yaml:"amount"`
}

func NewMsgBeginRedelegate(delAddr sdk.AccAddress, valSrcAddr,
valDstAddr sdk.ValAddress, amount sdk.Coin) MsgBeginRedelegate {

// NewMsgBeginRedelegate creates a new MsgBeginRedelegate instance
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func NewMsgBeginRedelegate(
delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, amount sdk.Coin,
) MsgBeginRedelegate {
return MsgBeginRedelegate{
DelegatorAddress: delAddr,
ValidatorSrcAddress: valSrcAddr,
Expand All @@ -302,20 +317,24 @@ func NewMsgBeginRedelegate(delAddr sdk.AccAddress, valSrcAddr,
}
}

//nolint
// Route implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgBeginRedelegate) Route() string { return RouterKey }

// Type implements the sdk.Msg interface
func (msg MsgBeginRedelegate) Type() string { return "begin_redelegate" }

// GetSigners implements the sdk.Msg interface
func (msg MsgBeginRedelegate) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.DelegatorAddress}
}

// get the bytes for the message signer to sign on
// GetSignBytes implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgBeginRedelegate) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

// quick validity check
// ValidateBasic implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgBeginRedelegate) ValidateBasic() sdk.Error {
if msg.DelegatorAddress.Empty() {
return ErrNilDelegatorAddr(DefaultCodespace)
Expand All @@ -339,6 +358,7 @@ type MsgUndelegate struct {
Amount sdk.Coin `json:"amount" yaml:"amount"`
}

// NewMsgUndelegate creates a new MsgUndelegate instance
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) MsgUndelegate {
return MsgUndelegate{
DelegatorAddress: delAddr,
Expand All @@ -347,18 +367,22 @@ func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk
}
}

//nolint
// Route implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgUndelegate) Route() string { return RouterKey }

// Type implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgUndelegate) Type() string { return "begin_unbonding" }

// GetSigners implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgUndelegate) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.DelegatorAddress} }

// get the bytes for the message signer to sign on
// GetSignBytes implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgUndelegate) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

// quick validity check
// ValidateBasic implements the sdk.Msg interface
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (msg MsgUndelegate) ValidateBasic() sdk.Error {
if msg.DelegatorAddress.Empty() {
return ErrNilDelegatorAddr(DefaultCodespace)
Expand Down