From 38a92323c9813a404182ecd5d94c2327cbd9cdde Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 6 Aug 2020 14:49:30 +0300 Subject: [PATCH] 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. --- pkg/core/native/native_neo.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/core/native/native_neo.go b/pkg/core/native/native_neo.go index 99579165f..2a3a2faa1 100644 --- a/pkg/core/native/native_neo.go +++ b/pkg/core/native/native_neo.go @@ -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) }