neoneo-go/pkg/core/transaction/state_descriptor.go
Anthony De Meulemeester 52fa41a12a
Persist transactions (#51)
* added account_state + changed ECPoint to PublicKey

* account state persist

* in depth test for existing accounts.

* implemented GetTransaction.

* added enrollment TX

* added persist of accounts and unspent coins

* bumped version -> 0.32.0
2018-03-21 17:11:04 +01:00

58 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
}