From b9c40ea2b6c6113f940993d1c3251baa5dc14b16 Mon Sep 17 00:00:00 2001
From: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Date: Tue, 3 Dec 2019 12:14:18 +0100
Subject: [PATCH] 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
---
 CHANGELOG.md                    |  1 +
 x/staking/legacy/v0_36/types.go |  3 +-
 x/staking/legacy/v0_38/types.go |  2 +-
 x/staking/types/msg.go          | 84 +++++++++++++++++++++------------
 4 files changed, 58 insertions(+), 32 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7783efc23de..7148e122122b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
 * (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 `description` instead of `Description` as a JSON key.
 
 ### Features
 
diff --git a/x/staking/legacy/v0_36/types.go b/x/staking/legacy/v0_36/types.go
index b5edcc04864c..1e0ff71bd8f8 100644
--- a/x/staking/legacy/v0_36/types.go
+++ b/x/staking/legacy/v0_36/types.go
@@ -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 (
diff --git a/x/staking/legacy/v0_38/types.go b/x/staking/legacy/v0_38/types.go
index 3b21d8f9cc0b..88bce2c5c505 100644
--- a/x/staking/legacy/v0_38/types.go
+++ b/x/staking/legacy/v0_38/types.go
@@ -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"
diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go
index 6be3587865da..1efe19530de9 100644
--- a/x/staking/types/msg.go
+++ b/x/staking/types/msg.go
@@ -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.
 func NewMsgCreateValidator(
 	valAddr sdk.ValAddress, pubKey crypto.PubKey, selfDelegation sdk.Coin,
 	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) 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 {
 	// 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
@@ -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.
 func (msg MsgCreateValidator) MarshalYAML() (interface{}, error) {
 	bs, err := yaml.Marshal(struct {
 		Description       Description
@@ -146,7 +150,7 @@ func (msg MsgCreateValidator) GetSignBytes() []byte {
 	return sdk.MustSortJSON(bz)
 }
 
-// quick validity check
+// ValidateBasic implements the sdk.Msg interface.
 func (msg MsgCreateValidator) ValidateBasic() sdk.Error {
 	// note that unmarshaling from bech32 ensures either empty or valid
 	if msg.DelegatorAddress.Empty() {
@@ -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
@@ -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,
@@ -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) 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 {
 	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 {
 	bz := ModuleCdc.MustMarshalJSON(msg)
 	return sdk.MustSortJSON(bz)
 }
 
-// quick validity check
+// ValidateBasic implements the sdk.Msg interface.
 func (msg MsgEditValidator) ValidateBasic() sdk.Error {
 	if msg.ValidatorAddress.Empty() {
 		return sdk.NewError(DefaultCodespace, CodeInvalidInput, "nil validator address")
@@ -246,6 +255,7 @@ type MsgDelegate struct {
 	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 {
 	return MsgDelegate{
 		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) 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 {
 	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 {
 	bz := ModuleCdc.MustMarshalJSON(msg)
 	return sdk.MustSortJSON(bz)
 }
 
-// quick validity check
+// ValidateBasic implements the sdk.Msg interface.
 func (msg MsgDelegate) ValidateBasic() sdk.Error {
 	if msg.DelegatorAddress.Empty() {
 		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 {
 	DelegatorAddress    sdk.AccAddress `json:"delegator_address" yaml:"delegator_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"`
 }
 
-func NewMsgBeginRedelegate(delAddr sdk.AccAddress, valSrcAddr,
-	valDstAddr sdk.ValAddress, amount sdk.Coin) MsgBeginRedelegate {
-
+// NewMsgBeginRedelegate creates a new MsgBeginRedelegate instance.
+func NewMsgBeginRedelegate(
+	delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, amount sdk.Coin,
+) MsgBeginRedelegate {
 	return MsgBeginRedelegate{
 		DelegatorAddress:    delAddr,
 		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) 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 {
 	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 {
 	bz := ModuleCdc.MustMarshalJSON(msg)
 	return sdk.MustSortJSON(bz)
 }
 
-// quick validity check
+// ValidateBasic implements the sdk.Msg interface.
 func (msg MsgBeginRedelegate) ValidateBasic() sdk.Error {
 	if msg.DelegatorAddress.Empty() {
 		return ErrNilDelegatorAddr(DefaultCodespace)
@@ -339,6 +358,7 @@ type MsgUndelegate struct {
 	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 {
 	return MsgUndelegate{
 		DelegatorAddress: delAddr,
@@ -347,18 +367,22 @@ func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk
 	}
 }
 
-//nolint
-func (msg MsgUndelegate) Route() string                { return RouterKey }
-func (msg MsgUndelegate) Type() string                 { return "begin_unbonding" }
+// Route implements the sdk.Msg interface.
+func (msg MsgUndelegate) Route() string { return RouterKey }
+
+// 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} }
 
-// get the bytes for the message signer to sign on
+// GetSignBytes implements the sdk.Msg interface.
 func (msg MsgUndelegate) GetSignBytes() []byte {
 	bz := ModuleCdc.MustMarshalJSON(msg)
 	return sdk.MustSortJSON(bz)
 }
 
-// quick validity check
+// ValidateBasic implements the sdk.Msg interface.
 func (msg MsgUndelegate) ValidateBasic() sdk.Error {
 	if msg.DelegatorAddress.Empty() {
 		return ErrNilDelegatorAddr(DefaultCodespace)