mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-09 13:13:13 +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
|
@ -35,25 +35,6 @@ type NativeContract struct {
|
|||
UpdateHistory []uint32 `json:"updatehistory"`
|
||||
}
|
||||
|
||||
// DecodeBinary implements Serializable interface.
|
||||
func (c *Contract) DecodeBinary(r *io.BinReader) {
|
||||
si := stackitem.DecodeBinary(r)
|
||||
if r.Err != nil {
|
||||
return
|
||||
}
|
||||
r.Err = c.FromStackItem(si)
|
||||
}
|
||||
|
||||
// EncodeBinary implements Serializable interface.
|
||||
func (c *Contract) EncodeBinary(w *io.BinWriter) {
|
||||
si, err := c.ToStackItem()
|
||||
if err != nil {
|
||||
w.Err = err
|
||||
return
|
||||
}
|
||||
stackitem.EncodeBinary(si, w)
|
||||
}
|
||||
|
||||
// ToStackItem converts state.Contract to stackitem.Item.
|
||||
func (c *Contract) ToStackItem() (stackitem.Item, error) {
|
||||
rawNef, err := c.NEF.Bytes()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue