mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 11:41:48 +00:00
stackitem: introduce Convertible interface
We have a lot of native contract types that are converted to stack items before serialization, then deserialized as stack items and converted back to regular structures. stackitem.Convertible allows to remove a lot of repetitive io.Serializable code. This also introduces to/from converter in testserdes which unfortunately required to change util tests to avoid circular references.
This commit is contained in:
parent
2d993d0da5
commit
aab18c3083
23 changed files with 223 additions and 339 deletions
|
@ -697,7 +697,7 @@ func (n *NEO) RegisterCandidateInternal(ic *interop.Context, pub *keys.PublicKey
|
|||
c = new(candidate).FromBytes(si)
|
||||
c.Registered = true
|
||||
}
|
||||
return ic.DAO.PutStorageItem(n.ID, key, c.Bytes())
|
||||
return putConvertibleToDAO(n.ID, ic.DAO, key, c)
|
||||
}
|
||||
|
||||
func (n *NEO) unregisterCandidate(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
||||
|
@ -726,7 +726,7 @@ func (n *NEO) UnregisterCandidateInternal(ic *interop.Context, pub *keys.PublicK
|
|||
if ok {
|
||||
return err
|
||||
}
|
||||
return ic.DAO.PutStorageItem(n.ID, key, c.Bytes())
|
||||
return putConvertibleToDAO(n.ID, ic.DAO, key, c)
|
||||
}
|
||||
|
||||
func (n *NEO) vote(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
||||
|
@ -819,7 +819,7 @@ func (n *NEO) ModifyAccountVotes(acc *state.NEOBalanceState, d dao.DAO, value *b
|
|||
}
|
||||
}
|
||||
n.validators.Store(keys.PublicKeys(nil))
|
||||
return d.PutStorageItem(n.ID, key, cd.Bytes())
|
||||
return putConvertibleToDAO(n.ID, d, key, cd)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue