mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-10-16 23:46:26 +00:00
5bf00db2c9
The logic here is that we'll have all binary encoding/decoding done via our io package, which simplifies error handling. This functionality doesn't belong to util, so it's moved. This also expands BufBinWriter with Reset() method to fit the needs of core package.
48 lines
1 KiB
Go
48 lines
1 KiB
Go
package transaction
|
|
|
|
import (
|
|
"github.com/CityOfZion/neo-go/pkg/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.BinReader) error {
|
|
r.ReadLE(&s.Type)
|
|
|
|
s.Key = r.ReadBytes()
|
|
s.Value = r.ReadBytes()
|
|
s.Field = r.ReadString()
|
|
|
|
return r.Err
|
|
}
|
|
|
|
// EncodeBinary implements the Payload interface.
|
|
func (s *StateDescriptor) EncodeBinary(w *io.BinWriter) error {
|
|
w.WriteLE(s.Type)
|
|
w.WriteBytes(s.Key)
|
|
w.WriteBytes(s.Value)
|
|
w.WriteString(s.Field)
|
|
return w.Err
|
|
}
|
|
|
|
// Size returns serialized binary size for state descriptor.
|
|
func (s *StateDescriptor) Size() int {
|
|
return 1 + util.GetVarSize(s.Key) + util.GetVarSize(s.Value) + util.GetVarSize(s.Field)
|
|
}
|