mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 23:30:36 +00:00
28908aa3cf
Signed-off-by: Elizaveta Chichindaeva <elizaveta@nspcc.ru>
45 lines
979 B
Go
45 lines
979 B
Go
package native
|
|
|
|
import (
|
|
"math/big"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
)
|
|
|
|
type candidate struct {
|
|
Registered bool
|
|
Votes big.Int
|
|
}
|
|
|
|
// FromBytes unmarshals a candidate from the byte array.
|
|
func (c *candidate) FromBytes(data []byte) *candidate {
|
|
err := stackitem.DeserializeConvertible(data, c)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return c
|
|
}
|
|
|
|
// ToStackItem implements stackitem.Convertible. It never returns an error.
|
|
func (c *candidate) ToStackItem() (stackitem.Item, error) {
|
|
return stackitem.NewStruct([]stackitem.Item{
|
|
stackitem.NewBool(c.Registered),
|
|
stackitem.NewBigInteger(&c.Votes),
|
|
}), nil
|
|
}
|
|
|
|
// FromStackItem implements stackitem.Convertible.
|
|
func (c *candidate) FromStackItem(item stackitem.Item) error {
|
|
arr := item.(*stackitem.Struct).Value().([]stackitem.Item)
|
|
vs, err := arr[1].TryInteger()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
reg, err := arr[0].TryBool()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.Registered = reg
|
|
c.Votes = *vs
|
|
return nil
|
|
}
|