fix MsgEditValidator JSON tag (#5342)
* add json tag to MsgEditValidator; closes #5336 * changelog * Apply suggestions from code review Co-Authored-By: Alessio Treglia <alessio@tendermint.com> * format * changelog minor fix
This commit is contained in:
parent
b862e271a1
commit
b9c40ea2b6
|
@ -83,6 +83,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
|
* (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
|
* (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.
|
increased significantly due to modular `AnteHandler` support. Increase GasLimit accordingly.
|
||||||
|
* (rest) [\#5336](https://github.com/cosmos/cosmos-sdk/issues/5336) `MsgEditValidator` uses `description` instead of `Description` as a JSON key.
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,11 @@ package v0_36
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
|
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -5,9 +5,9 @@ package v0_38
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
|
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
|
||||||
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_36"
|
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_36"
|
||||||
|
|
|
@ -42,7 +42,8 @@ type msgCreateValidatorJSON struct {
|
||||||
Value sdk.Coin `json:"value" yaml:"value"`
|
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.
|
||||||
func NewMsgCreateValidator(
|
func NewMsgCreateValidator(
|
||||||
valAddr sdk.ValAddress, pubKey crypto.PubKey, selfDelegation sdk.Coin,
|
valAddr sdk.ValAddress, pubKey crypto.PubKey, selfDelegation sdk.Coin,
|
||||||
description Description, commission CommissionRates, minSelfDelegation sdk.Int,
|
description Description, commission CommissionRates, minSelfDelegation sdk.Int,
|
||||||
|
@ -59,18 +60,21 @@ func NewMsgCreateValidator(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint
|
// Route implements the sdk.Msg interface.
|
||||||
func (msg MsgCreateValidator) Route() string { return RouterKey }
|
func (msg MsgCreateValidator) Route() string { return RouterKey }
|
||||||
func (msg MsgCreateValidator) Type() string { return "create_validator" }
|
|
||||||
|
|
||||||
// Return address(es) that must sign over msg.GetSignBytes()
|
// Type implements the sdk.Msg interface.
|
||||||
|
func (msg MsgCreateValidator) Type() string { return "create_validator" }
|
||||||
|
|
||||||
|
// GetSigners implements the sdk.Msg interface. It returns the address(es) that
|
||||||
|
// must sign over msg.GetSignBytes().
|
||||||
|
// 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 {
|
func (msg MsgCreateValidator) GetSigners() []sdk.AccAddress {
|
||||||
// delegator is first signer so delegator pays fees
|
// delegator is first signer so delegator pays fees
|
||||||
addrs := []sdk.AccAddress{msg.DelegatorAddress}
|
addrs := []sdk.AccAddress{msg.DelegatorAddress}
|
||||||
|
|
||||||
if !bytes.Equal(msg.DelegatorAddress.Bytes(), msg.ValidatorAddress.Bytes()) {
|
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))
|
addrs = append(addrs, sdk.AccAddress(msg.ValidatorAddress))
|
||||||
}
|
}
|
||||||
return addrs
|
return addrs
|
||||||
|
@ -113,7 +117,7 @@ func (msg *MsgCreateValidator) UnmarshalJSON(bz []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom marshal yaml function due to consensus pubkey
|
// MarshalYAML implements a custom marshal yaml function due to consensus pubkey.
|
||||||
func (msg MsgCreateValidator) MarshalYAML() (interface{}, error) {
|
func (msg MsgCreateValidator) MarshalYAML() (interface{}, error) {
|
||||||
bs, err := yaml.Marshal(struct {
|
bs, err := yaml.Marshal(struct {
|
||||||
Description Description
|
Description Description
|
||||||
|
@ -146,7 +150,7 @@ func (msg MsgCreateValidator) GetSignBytes() []byte {
|
||||||
return sdk.MustSortJSON(bz)
|
return sdk.MustSortJSON(bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
// quick validity check
|
// ValidateBasic implements the sdk.Msg interface.
|
||||||
func (msg MsgCreateValidator) ValidateBasic() sdk.Error {
|
func (msg MsgCreateValidator) ValidateBasic() sdk.Error {
|
||||||
// note that unmarshaling from bech32 ensures either empty or valid
|
// note that unmarshaling from bech32 ensures either empty or valid
|
||||||
if msg.DelegatorAddress.Empty() {
|
if msg.DelegatorAddress.Empty() {
|
||||||
|
@ -182,7 +186,7 @@ func (msg MsgCreateValidator) ValidateBasic() sdk.Error {
|
||||||
|
|
||||||
// MsgEditValidator - struct for editing a validator
|
// MsgEditValidator - struct for editing a validator
|
||||||
type MsgEditValidator struct {
|
type MsgEditValidator struct {
|
||||||
Description
|
Description Description `json:"description" yaml:"description"`
|
||||||
ValidatorAddress sdk.ValAddress `json:"address" yaml:"address"`
|
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
|
// We pass a reference to the new commission rate and min self delegation as it's not mandatory to
|
||||||
|
@ -194,6 +198,7 @@ type MsgEditValidator struct {
|
||||||
MinSelfDelegation *sdk.Int `json:"min_self_delegation" yaml:"min_self_delegation"`
|
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 {
|
func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRate *sdk.Dec, newMinSelfDelegation *sdk.Int) MsgEditValidator {
|
||||||
return MsgEditValidator{
|
return MsgEditValidator{
|
||||||
Description: description,
|
Description: description,
|
||||||
|
@ -203,20 +208,24 @@ func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint
|
// Route implements the sdk.Msg interface.
|
||||||
func (msg MsgEditValidator) Route() string { return RouterKey }
|
func (msg MsgEditValidator) Route() string { return RouterKey }
|
||||||
func (msg MsgEditValidator) Type() string { return "edit_validator" }
|
|
||||||
|
// Type implements the sdk.Msg interface.
|
||||||
|
func (msg MsgEditValidator) Type() string { return "edit_validator" }
|
||||||
|
|
||||||
|
// GetSigners implements the sdk.Msg interface.
|
||||||
func (msg MsgEditValidator) GetSigners() []sdk.AccAddress {
|
func (msg MsgEditValidator) GetSigners() []sdk.AccAddress {
|
||||||
return []sdk.AccAddress{sdk.AccAddress(msg.ValidatorAddress)}
|
return []sdk.AccAddress{sdk.AccAddress(msg.ValidatorAddress)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the bytes for the message signer to sign on
|
// GetSignBytes implements the sdk.Msg interface.
|
||||||
func (msg MsgEditValidator) GetSignBytes() []byte {
|
func (msg MsgEditValidator) GetSignBytes() []byte {
|
||||||
bz := ModuleCdc.MustMarshalJSON(msg)
|
bz := ModuleCdc.MustMarshalJSON(msg)
|
||||||
return sdk.MustSortJSON(bz)
|
return sdk.MustSortJSON(bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
// quick validity check
|
// ValidateBasic implements the sdk.Msg interface.
|
||||||
func (msg MsgEditValidator) ValidateBasic() sdk.Error {
|
func (msg MsgEditValidator) ValidateBasic() sdk.Error {
|
||||||
if msg.ValidatorAddress.Empty() {
|
if msg.ValidatorAddress.Empty() {
|
||||||
return sdk.NewError(DefaultCodespace, CodeInvalidInput, "nil validator address")
|
return sdk.NewError(DefaultCodespace, CodeInvalidInput, "nil validator address")
|
||||||
|
@ -246,6 +255,7 @@ type MsgDelegate struct {
|
||||||
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewMsgDelegate creates a new MsgDelegate instance.
|
||||||
func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) MsgDelegate {
|
func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) MsgDelegate {
|
||||||
return MsgDelegate{
|
return MsgDelegate{
|
||||||
DelegatorAddress: delAddr,
|
DelegatorAddress: delAddr,
|
||||||
|
@ -254,20 +264,24 @@ func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint
|
// Route implements the sdk.Msg interface.
|
||||||
func (msg MsgDelegate) Route() string { return RouterKey }
|
func (msg MsgDelegate) Route() string { return RouterKey }
|
||||||
func (msg MsgDelegate) Type() string { return "delegate" }
|
|
||||||
|
// Type implements the sdk.Msg interface.
|
||||||
|
func (msg MsgDelegate) Type() string { return "delegate" }
|
||||||
|
|
||||||
|
// GetSigners implements the sdk.Msg interface.
|
||||||
func (msg MsgDelegate) GetSigners() []sdk.AccAddress {
|
func (msg MsgDelegate) GetSigners() []sdk.AccAddress {
|
||||||
return []sdk.AccAddress{msg.DelegatorAddress}
|
return []sdk.AccAddress{msg.DelegatorAddress}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the bytes for the message signer to sign on
|
// GetSignBytes implements the sdk.Msg interface.
|
||||||
func (msg MsgDelegate) GetSignBytes() []byte {
|
func (msg MsgDelegate) GetSignBytes() []byte {
|
||||||
bz := ModuleCdc.MustMarshalJSON(msg)
|
bz := ModuleCdc.MustMarshalJSON(msg)
|
||||||
return sdk.MustSortJSON(bz)
|
return sdk.MustSortJSON(bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
// quick validity check
|
// ValidateBasic implements the sdk.Msg interface.
|
||||||
func (msg MsgDelegate) ValidateBasic() sdk.Error {
|
func (msg MsgDelegate) ValidateBasic() sdk.Error {
|
||||||
if msg.DelegatorAddress.Empty() {
|
if msg.DelegatorAddress.Empty() {
|
||||||
return ErrNilDelegatorAddr(DefaultCodespace)
|
return ErrNilDelegatorAddr(DefaultCodespace)
|
||||||
|
@ -283,7 +297,7 @@ func (msg MsgDelegate) ValidateBasic() sdk.Error {
|
||||||
|
|
||||||
//______________________________________________________________________
|
//______________________________________________________________________
|
||||||
|
|
||||||
// MsgDelegate - struct for bonding transactions
|
// MsgBeginRedelegate defines the attributes of a bonding transaction.
|
||||||
type MsgBeginRedelegate struct {
|
type MsgBeginRedelegate struct {
|
||||||
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
|
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
|
||||||
ValidatorSrcAddress sdk.ValAddress `json:"validator_src_address" yaml:"validator_src_address"`
|
ValidatorSrcAddress sdk.ValAddress `json:"validator_src_address" yaml:"validator_src_address"`
|
||||||
|
@ -291,9 +305,10 @@ type MsgBeginRedelegate struct {
|
||||||
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMsgBeginRedelegate(delAddr sdk.AccAddress, valSrcAddr,
|
// NewMsgBeginRedelegate creates a new MsgBeginRedelegate instance.
|
||||||
valDstAddr sdk.ValAddress, amount sdk.Coin) MsgBeginRedelegate {
|
func NewMsgBeginRedelegate(
|
||||||
|
delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, amount sdk.Coin,
|
||||||
|
) MsgBeginRedelegate {
|
||||||
return MsgBeginRedelegate{
|
return MsgBeginRedelegate{
|
||||||
DelegatorAddress: delAddr,
|
DelegatorAddress: delAddr,
|
||||||
ValidatorSrcAddress: valSrcAddr,
|
ValidatorSrcAddress: valSrcAddr,
|
||||||
|
@ -302,20 +317,24 @@ func NewMsgBeginRedelegate(delAddr sdk.AccAddress, valSrcAddr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint
|
// Route implements the sdk.Msg interface.
|
||||||
func (msg MsgBeginRedelegate) Route() string { return RouterKey }
|
func (msg MsgBeginRedelegate) Route() string { return RouterKey }
|
||||||
func (msg MsgBeginRedelegate) Type() string { return "begin_redelegate" }
|
|
||||||
|
// 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 {
|
func (msg MsgBeginRedelegate) GetSigners() []sdk.AccAddress {
|
||||||
return []sdk.AccAddress{msg.DelegatorAddress}
|
return []sdk.AccAddress{msg.DelegatorAddress}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the bytes for the message signer to sign on
|
// GetSignBytes implements the sdk.Msg interface.
|
||||||
func (msg MsgBeginRedelegate) GetSignBytes() []byte {
|
func (msg MsgBeginRedelegate) GetSignBytes() []byte {
|
||||||
bz := ModuleCdc.MustMarshalJSON(msg)
|
bz := ModuleCdc.MustMarshalJSON(msg)
|
||||||
return sdk.MustSortJSON(bz)
|
return sdk.MustSortJSON(bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
// quick validity check
|
// ValidateBasic implements the sdk.Msg interface.
|
||||||
func (msg MsgBeginRedelegate) ValidateBasic() sdk.Error {
|
func (msg MsgBeginRedelegate) ValidateBasic() sdk.Error {
|
||||||
if msg.DelegatorAddress.Empty() {
|
if msg.DelegatorAddress.Empty() {
|
||||||
return ErrNilDelegatorAddr(DefaultCodespace)
|
return ErrNilDelegatorAddr(DefaultCodespace)
|
||||||
|
@ -339,6 +358,7 @@ type MsgUndelegate struct {
|
||||||
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewMsgUndelegate creates a new MsgUndelegate instance.
|
||||||
func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) MsgUndelegate {
|
func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) MsgUndelegate {
|
||||||
return MsgUndelegate{
|
return MsgUndelegate{
|
||||||
DelegatorAddress: delAddr,
|
DelegatorAddress: delAddr,
|
||||||
|
@ -347,18 +367,22 @@ func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint
|
// Route implements the sdk.Msg interface.
|
||||||
func (msg MsgUndelegate) Route() string { return RouterKey }
|
func (msg MsgUndelegate) Route() string { return RouterKey }
|
||||||
func (msg MsgUndelegate) Type() string { return "begin_unbonding" }
|
|
||||||
|
// Type implements the sdk.Msg interface.
|
||||||
|
func (msg MsgUndelegate) Type() string { return "begin_unbonding" }
|
||||||
|
|
||||||
|
// GetSigners implements the sdk.Msg interface.
|
||||||
func (msg MsgUndelegate) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{msg.DelegatorAddress} }
|
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.
|
||||||
func (msg MsgUndelegate) GetSignBytes() []byte {
|
func (msg MsgUndelegate) GetSignBytes() []byte {
|
||||||
bz := ModuleCdc.MustMarshalJSON(msg)
|
bz := ModuleCdc.MustMarshalJSON(msg)
|
||||||
return sdk.MustSortJSON(bz)
|
return sdk.MustSortJSON(bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
// quick validity check
|
// ValidateBasic implements the sdk.Msg interface.
|
||||||
func (msg MsgUndelegate) ValidateBasic() sdk.Error {
|
func (msg MsgUndelegate) ValidateBasic() sdk.Error {
|
||||||
if msg.DelegatorAddress.Empty() {
|
if msg.DelegatorAddress.Empty() {
|
||||||
return ErrNilDelegatorAddr(DefaultCodespace)
|
return ErrNilDelegatorAddr(DefaultCodespace)
|
||||||
|
|
Loading…
Reference in New Issue