2018-03-21 16:11:04 +00:00
|
|
|
package transaction
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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 {
|
2019-08-28 16:27:06 +00:00
|
|
|
br := util.BinReader{R: r}
|
|
|
|
br.ReadLE(&s.Type)
|
2018-03-21 16:11:04 +00:00
|
|
|
|
2019-08-28 16:27:06 +00:00
|
|
|
s.Key = br.ReadBytes()
|
|
|
|
s.Value = br.ReadBytes()
|
|
|
|
s.Field = br.ReadString()
|
|
|
|
|
|
|
|
return br.Err
|
2018-03-21 16:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements the Payload interface.
|
|
|
|
func (s *StateDescriptor) EncodeBinary(w io.Writer) error {
|
2019-08-30 16:13:19 +00:00
|
|
|
bw := util.BinWriter{W: w}
|
|
|
|
bw.WriteLE(s.Type)
|
|
|
|
bw.WriteBytes(s.Key)
|
|
|
|
bw.WriteBytes(s.Value)
|
|
|
|
bw.WriteString(s.Field)
|
|
|
|
return bw.Err
|
2018-03-21 16:11:04 +00:00
|
|
|
}
|
2019-08-30 08:28:30 +00:00
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// Size returns serialized binary size for state descriptor.
|
2019-08-30 08:28:30 +00:00
|
|
|
func (s *StateDescriptor) Size() int {
|
|
|
|
return 1 + util.GetVarSize(s.Key) + util.GetVarSize(s.Value) + util.GetVarSize(s.Field)
|
|
|
|
}
|