Cleanup implementation

This commit is contained in:
Christopher Goes 2018-04-09 12:17:45 +02:00
parent 91e850b568
commit 7fa634e772
No known key found for this signature in database
GPG Key ID: E828D98232D328D3
1 changed files with 10 additions and 0 deletions

View File

@ -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,6 +90,13 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) {
}
store.Set(GetCandidateKey(candidate.Address), bz)
// marshal the new validator record
validator := candidate.validator()
bz, err = k.cdc.MarshalBinary(validator)
if err != nil {
panic(err)
}
// if the voting power is the same no need to update any of the other indexes
if oldFound && oldCandidate.Assets.Equal(candidate.Assets) {
return