mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-01 03:49:13 +00:00
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
|
package transaction
|
||
|
|
||
|
import (
|
||
|
"encoding/binary"
|
||
|
"io"
|
||
|
|
||
|
"github.com/CityOfZion/neo-go/pkg/util"
|
||
|
)
|
||
|
|
||
|
// DescStateType represents the type of StateDescriptor.
|
||
|
type DescStateType uint8
|
||
|
|
||
|
// Valid DescStateType constants.
|
||
|
const (
|
||
|
Account DescStateType = 0x40
|
||
|
Validator DescStateType = 0x48
|
||
|
)
|
||
|
|
||
|
// StateDescriptor ..
|
||
|
type StateDescriptor struct {
|
||
|
Type DescStateType
|
||
|
Key []byte
|
||
|
Value []byte
|
||
|
Field string
|
||
|
}
|
||
|
|
||
|
// DecodeBinary implements the Payload interface.
|
||
|
func (s *StateDescriptor) DecodeBinary(r io.Reader) error {
|
||
|
if err := binary.Read(r, binary.LittleEndian, &s.Type); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
keyLen := util.ReadVarUint(r)
|
||
|
s.Key = make([]byte, keyLen)
|
||
|
if err := binary.Read(r, binary.LittleEndian, s.Key); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
valLen := util.ReadVarUint(r)
|
||
|
s.Value = make([]byte, valLen)
|
||
|
if err := binary.Read(r, binary.LittleEndian, s.Value); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
fieldLen := util.ReadVarUint(r)
|
||
|
field := make([]byte, fieldLen)
|
||
|
if err := binary.Read(r, binary.LittleEndian, field); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
s.Field = string(field)
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// EncodeBinary implements the Payload interface.
|
||
|
func (s *StateDescriptor) EncodeBinary(w io.Writer) error {
|
||
|
return nil
|
||
|
}
|