Cleanup implementation
This commit is contained in:
parent
b1c83f2edb
commit
905a9eefb9
|
@ -80,6 +80,9 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) {
|
|||
// retreive the old candidate record
|
||||
oldCandidate, oldFound := k.GetCandidate(ctx, address)
|
||||
|
||||
// update the validator block height (will only get written if stake has changed)
|
||||
candidate.ValidatorHeight = ctx.BlockHeight()
|
||||
|
||||
// marshal the candidate record and add to the state
|
||||
bz, err := k.cdc.MarshalBinary(candidate)
|
||||
if err != nil {
|
||||
|
@ -87,7 +90,7 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) {
|
|||
}
|
||||
store.Set(GetCandidateKey(candidate.Address), bz)
|
||||
|
||||
// mashal the new validator record
|
||||
// marshal the new validator record
|
||||
validator := candidate.validator()
|
||||
bz, err = k.cdc.MarshalBinary(validator)
|
||||
if err != nil {
|
||||
|
@ -121,7 +124,9 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) {
|
|||
panic(err)
|
||||
}
|
||||
store.Set(GetAccUpdateValidatorKey(validator.Address), bz)
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -32,10 +32,10 @@ func GetCandidateKey(addr sdk.Address) []byte {
|
|||
}
|
||||
|
||||
// get the key for the validator used in the power-store
|
||||
func GetValidatorKey(addr sdk.Address, power sdk.Rat, height uint64, cdc *wire.Codec) []byte {
|
||||
func GetValidatorKey(addr sdk.Address, power sdk.Rat, height int64, cdc *wire.Codec) []byte {
|
||||
powerBytes := []byte(power.ToLeftPadded(maxDigitsForAccount)) // power big-endian (more powerful validators first)
|
||||
heightBytes := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(heightBytes, height) // height little-endian (older validators first)
|
||||
binary.LittleEndian.PutUint64(heightBytes, uint64(height)) // height little-endian (older validators first)
|
||||
return append(ValidatorsKey, append(powerBytes, append(heightBytes, addr.Bytes()...)...)...)
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ type Candidate struct {
|
|||
Assets sdk.Rat `json:"assets"` // total shares of a global hold pools
|
||||
Liabilities sdk.Rat `json:"liabilities"` // total shares issued to a candidate's delegators
|
||||
Description Description `json:"description"` // Description terms for the candidate
|
||||
ValidatorHeight uint64 `json:"validator_height"` // If considered a validator, height when first considered a validator, else 0
|
||||
ValidatorHeight int64 `json:"validator_height"` // Earliest height at current voting power
|
||||
}
|
||||
|
||||
// Candidates - list of Candidates
|
||||
|
@ -80,7 +80,7 @@ func NewCandidate(address sdk.Address, pubKey crypto.PubKey, description Descrip
|
|||
Assets: sdk.ZeroRat,
|
||||
Liabilities: sdk.ZeroRat,
|
||||
Description: description,
|
||||
ValidatorHeight: uint64(0),
|
||||
ValidatorHeight: int64(0),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ type Validator struct {
|
|||
Address sdk.Address `json:"address"`
|
||||
PubKey crypto.PubKey `json:"pub_key"`
|
||||
Power sdk.Rat `json:"voting_power"`
|
||||
Height uint64 `json:"height"` // If considered a validator, height when first considered a validator, else 0
|
||||
Height int64 `json:"height"` // Earliest height at current voting power
|
||||
}
|
||||
|
||||
// abci validator from stake validator type
|
||||
|
|
Loading…
Reference in New Issue