native: fill votes when registering unregistered candidate

If a candidate was registered, then unregistered and then again
registered, it's votes must not be lost.
This commit is contained in:
Evgenii Stratonikov 2020-08-06 14:49:30 +03:00
parent 27169d140f
commit 38a92323c9

View file

@ -227,10 +227,13 @@ func (n *NEO) RegisterCandidateInternal(ic *interop.Context, pub *keys.PublicKey
key := makeValidatorKey(pub)
si := ic.DAO.GetStorageItem(n.ContractID, key)
if si == nil {
si = new(state.StorageItem)
c := &candidate{Registered: true}
si = &state.StorageItem{Value: c.Bytes()}
} else {
c := new(candidate).FromBytes(si.Value)
c.Registered = true
si.Value = c.Bytes()
}
c := &candidate{Registered: true}
si.Value = c.Bytes()
return ic.DAO.PutStorageItem(n.ContractID, key, si)
}