native: update voting information when changing Neo balance
This commit is contained in:
parent
36c6c6690b
commit
66c80d429e
1 changed files with 21 additions and 0 deletions
|
@ -167,6 +167,27 @@ func (n *NEO) increaseBalance(ic *interop.Context, h util.Uint160, si *state.Sto
|
||||||
if amount.Sign() == 0 {
|
if amount.Sign() == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
oldAcc, err := ic.DAO.GetAccountState(h)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := n.ModifyAccountVotes(oldAcc, ic.DAO, new(big.Int).Neg(&acc.Balance)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
siVC := ic.DAO.GetStorageItem(n.Hash, validatorsCountKey)
|
||||||
|
if siVC == nil {
|
||||||
|
return errors.New("validators count uninitialized")
|
||||||
|
}
|
||||||
|
vc, err := ValidatorsCountFromBytes(siVC.Value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
vc[len(oldAcc.Votes)-1].Add(&vc[len(oldAcc.Votes)-1], amount)
|
||||||
|
siVC.Value = vc.Bytes()
|
||||||
|
if err := ic.DAO.PutStorageItem(n.Hash, validatorsCountKey, siVC); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
acc.Balance.Add(&acc.Balance, amount)
|
acc.Balance.Add(&acc.Balance, amount)
|
||||||
si.Value = acc.Bytes()
|
si.Value = acc.Bytes()
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue