core: properly update validator votes for Account descriptor

ValidatorsCount is not implemented yet, but we need to update validators
properly, adding account's vote to their votes count.
This commit is contained in:
Roman Khimov 2020-02-12 18:16:57 +03:00
parent 8310b76d28
commit 2ff7ceb8cf

View file

@ -714,17 +714,16 @@ func processAccountStateDescriptor(descriptor *transaction.StateDescriptor, dao
return err
}
account.Votes = votes
if votes.Len() != len(account.Votes) {
for _, vote := range votes {
validator, err := dao.GetValidatorStateOrNew(vote)
for _, vote := range account.Votes {
validatorState, err := dao.GetValidatorStateOrNew(vote)
if err != nil {
return err
}
if err := dao.PutValidatorState(validator); err != nil {
validatorState.Votes += balance
if err = dao.PutValidatorState(validatorState); err != nil {
return err
}
}
}
return dao.PutAccountState(account)
}
return nil