Merge PR #5584: Staking additions for IBC
This commit is contained in:
parent
deea89e52c
commit
ec35cf2d91
|
@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||
### Improvements
|
||||
|
||||
* (types) [\#5581](https://github.com/cosmos/cosmos-sdk/pull/5581) Add convenience functions {,Must}Bech32ifyAddressBytes.
|
||||
* (staking) [\#5584](https://github.com/cosmos/cosmos-sdk/pull/5584) Add util function `ToTmValidator` that converts a `staking.Validator` type to `*tmtypes.Validator`.
|
||||
|
||||
## [v0.38.0] - 2020-01-23
|
||||
|
||||
|
|
|
@ -12,13 +12,13 @@ import (
|
|||
// HistoricalInfo contains the historical information that gets stored at each height
|
||||
type HistoricalInfo struct {
|
||||
Header abci.Header `json:"header" yaml:"header"`
|
||||
ValSet []Validator `json:"valset" yaml:"valset"`
|
||||
ValSet Validators `json:"valset" yaml:"valset"`
|
||||
}
|
||||
|
||||
// NewHistoricalInfo will create a historical information struct from header and valset
|
||||
// it will first sort valset before inclusion into historical info
|
||||
func NewHistoricalInfo(header abci.Header, valSet []Validator) HistoricalInfo {
|
||||
sort.Sort(Validators(valSet))
|
||||
func NewHistoricalInfo(header abci.Header, valSet Validators) HistoricalInfo {
|
||||
sort.Sort(valSet)
|
||||
return HistoricalInfo{
|
||||
Header: header,
|
||||
ValSet: valSet,
|
||||
|
|
|
@ -104,6 +104,15 @@ func (v Validators) ToSDKValidators() (validators []exported.ValidatorI) {
|
|||
return validators
|
||||
}
|
||||
|
||||
// ToTmValidators casts all validators to the corresponding tendermint type.
|
||||
func (v Validators) ToTmValidators() []*tmtypes.Validator {
|
||||
validators := make([]*tmtypes.Validator, len(v))
|
||||
for i, val := range v {
|
||||
validators[i] = val.ToTmValidator()
|
||||
}
|
||||
return validators
|
||||
}
|
||||
|
||||
// Sort Validators sorts validator array in ascending operator address order
|
||||
func (v Validators) Sort() {
|
||||
sort.Sort(v)
|
||||
|
@ -370,6 +379,11 @@ func (v Validator) ABCIValidatorUpdateZero() abci.ValidatorUpdate {
|
|||
}
|
||||
}
|
||||
|
||||
// ToTmValidator casts an SDK validator to a tendermint type Validator.
|
||||
func (v Validator) ToTmValidator() *tmtypes.Validator {
|
||||
return tmtypes.NewValidator(v.ConsPubKey, v.ConsensusPower())
|
||||
}
|
||||
|
||||
// SetInitialCommission attempts to set a validator's initial commission. An
|
||||
// error is returned if the commission is invalid.
|
||||
func (v Validator) SetInitialCommission(commission Commission) (Validator, error) {
|
||||
|
|
|
@ -335,3 +335,19 @@ func TestValidatorsSortDeterminism(t *testing.T) {
|
|||
require.True(t, reflect.DeepEqual(sortedVals, vals), "Validator sort returned different slices")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatorToTm(t *testing.T) {
|
||||
vals := make(Validators, 10)
|
||||
expected := make([]*tmtypes.Validator, 10)
|
||||
|
||||
for i := range vals {
|
||||
pk := ed25519.GenPrivKey().PubKey()
|
||||
val := NewValidator(sdk.ValAddress(pk.Address()), pk, Description{})
|
||||
val.Status = sdk.Bonded
|
||||
val.Tokens = sdk.NewInt(rand.Int63())
|
||||
vals[i] = val
|
||||
expected[i] = tmtypes.NewValidator(pk, val.ConsensusPower())
|
||||
}
|
||||
|
||||
require.Equal(t, expected, vals.ToTmValidators())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue