diff --git a/x/staking/legacy/v0_34/types.go b/x/staking/legacy/v0_34/types.go index aef346183819..64e997ebcf69 100644 --- a/x/staking/legacy/v0_34/types.go +++ b/x/staking/legacy/v0_34/types.go @@ -41,14 +41,10 @@ type ( } Commission struct { - CommissionRates CommissionRates `json:"commission_rates"` - UpdateTime time.Time `json:"update_time"` - } - - CommissionRates struct { - Rate sdk.Dec `json:"rate"` - MaxRate sdk.Dec `json:"max_rate"` - MaxChangeRate sdk.Dec `json:"max_change_rate"` + Rate sdk.Dec `json:"rate"` + MaxRate sdk.Dec `json:"max_rate"` + MaxChangeRate sdk.Dec `json:"max_change_rate"` + UpdateTime time.Time `json:"update_time"` } bechValidator struct { diff --git a/x/staking/legacy/v0_36/migrate.go b/x/staking/legacy/v0_36/migrate.go index 7ccac5f54d3a..0d1b0fa2e7a9 100644 --- a/x/staking/legacy/v0_36/migrate.go +++ b/x/staking/legacy/v0_36/migrate.go @@ -14,10 +14,39 @@ func Migrate(oldGenState v034staking.GenesisState) GenesisState { oldGenState.Params, oldGenState.LastTotalPower, oldGenState.LastValidatorPowers, - oldGenState.Validators, + migrateValidators(oldGenState.Validators), oldGenState.Delegations, oldGenState.UnbondingDelegations, oldGenState.Redelegations, oldGenState.Exported, ) } + +func migrateValidators(oldValidators v034staking.Validators) Validators { + validators := make(Validators, len(oldValidators)) + + for i, val := range oldValidators { + validators[i] = Validator{ + OperatorAddress: val.OperatorAddress, + ConsPubKey: val.ConsPubKey, + Jailed: val.Jailed, + Status: val.Status, + Tokens: val.Tokens, + DelegatorShares: val.DelegatorShares, + Description: val.Description, + UnbondingHeight: val.UnbondingHeight, + UnbondingCompletionTime: val.UnbondingCompletionTime, + Commission: Commission{ + CommissionRates: CommissionRates{ + Rate: val.Commission.Rate, + MaxRate: val.Commission.MaxRate, + MaxChangeRate: val.Commission.MaxChangeRate, + }, + UpdateTime: val.Commission.UpdateTime, + }, + MinSelfDelegation: val.MinSelfDelegation, + } + } + + return validators +} diff --git a/x/staking/legacy/v0_36/types.go b/x/staking/legacy/v0_36/types.go index 5af5d8acd948..e58422804d8e 100644 --- a/x/staking/legacy/v0_36/types.go +++ b/x/staking/legacy/v0_36/types.go @@ -3,9 +3,12 @@ package v0_36 import ( - v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34" + "time" + + "github.com/tendermint/tendermint/crypto" sdk "github.com/cosmos/cosmos-sdk/types" + v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34" ) const ( @@ -13,11 +16,38 @@ const ( ) type ( + Commission struct { + CommissionRates `json:"commission_rates" yaml:"commission_rates"` + UpdateTime time.Time `json:"update_time" yaml:"update_time"` + } + + CommissionRates struct { + Rate sdk.Dec `json:"rate" yaml:"rate"` + MaxRate sdk.Dec `json:"max_rate" yaml:"max_rate"` + MaxChangeRate sdk.Dec `json:"max_change_rate" yaml:"max_change_rate"` + } + + Validator struct { + OperatorAddress sdk.ValAddress `json:"operator_address" yaml:"operator_address"` + ConsPubKey crypto.PubKey `json:"consensus_pubkey" yaml:"consensus_pubkey"` + Jailed bool `json:"jailed" yaml:"jailed"` + Status sdk.BondStatus `json:"status" yaml:"status"` + Tokens sdk.Int `json:"tokens" yaml:"tokens"` + DelegatorShares sdk.Dec `json:"delegator_shares" yaml:"delegator_shares"` + Description v034staking.Description `json:"description" yaml:"description"` + UnbondingHeight int64 `json:"unbonding_height" yaml:"unbonding_height"` + UnbondingCompletionTime time.Time `json:"unbonding_time" yaml:"unbonding_time"` + Commission Commission `json:"commission" yaml:"commission"` + MinSelfDelegation sdk.Int `json:"min_self_delegation" yaml:"min_self_delegation"` + } + + Validators []Validator + GenesisState struct { Params v034staking.Params `json:"params"` LastTotalPower sdk.Int `json:"last_total_power"` LastValidatorPowers []v034staking.LastValidatorPower `json:"last_validator_powers"` - Validators v034staking.Validators `json:"validators"` + Validators Validators `json:"validators"` Delegations v034staking.Delegations `json:"delegations"` UnbondingDelegations []v034staking.UnbondingDelegation `json:"unbonding_delegations"` Redelegations []v034staking.Redelegation `json:"redelegations"` @@ -27,7 +57,7 @@ type ( func NewGenesisState( params v034staking.Params, lastTotalPower sdk.Int, lastValPowers []v034staking.LastValidatorPower, - validators v034staking.Validators, delegations v034staking.Delegations, + validators Validators, delegations v034staking.Delegations, ubds []v034staking.UnbondingDelegation, reds []v034staking.Redelegation, exported bool, ) GenesisState { diff --git a/x/staking/types/commission.go b/x/staking/types/commission.go index db0269df8ba7..9b7b327e102f 100644 --- a/x/staking/types/commission.go +++ b/x/staking/types/commission.go @@ -10,8 +10,8 @@ import ( type ( // Commission defines a commission parameters for a given validator. Commission struct { - CommissionRates - UpdateTime time.Time `json:"update_time" yaml:"update_time"` // the last time the commission rate was changed + CommissionRates `json:"commission_rates" yaml:"commission_rates"` + UpdateTime time.Time `json:"update_time" yaml:"update_time"` // the last time the commission rate was changed } // CommissionRates defines the initial commission rates to be used for creating a diff --git a/x/staking/types/validator_test.go b/x/staking/types/validator_test.go index 02af66f59be3..73308666b65f 100644 --- a/x/staking/types/validator_test.go +++ b/x/staking/types/validator_test.go @@ -293,7 +293,7 @@ func TestValidatorMarshalYAML(t *testing.T) { unbondingheight: 0 unbondingcompletiontime: 1970-01-01T00:00:00Z commission: - commissionrates: + commission_rates: rate: "0.000000000000000000" max_rate: "0.000000000000000000" max_change_rate: "0.000000000000000000"