From af212f496e243f3d54ffea0d16cd09fdce58e60d Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 30 Aug 2019 19:13:19 +0300 Subject: [PATCH] transaction: implement encoding for state --- pkg/core/transaction/state.go | 11 +++++++++++ pkg/core/transaction/state_descriptor.go | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/core/transaction/state.go b/pkg/core/transaction/state.go index 8a68c92e5..8c37d822a 100644 --- a/pkg/core/transaction/state.go +++ b/pkg/core/transaction/state.go @@ -29,6 +29,17 @@ func (tx *StateTX) DecodeBinary(r io.Reader) error { // EncodeBinary implements the Payload interface. func (tx *StateTX) EncodeBinary(w io.Writer) error { + bw := util.BinWriter{W: w} + bw.WriteVarUint(uint64(len(tx.Descriptors))) + if bw.Err != nil { + return bw.Err + } + for _, desc := range tx.Descriptors { + err := desc.EncodeBinary(w) + if err != nil { + return err + } + } return nil } diff --git a/pkg/core/transaction/state_descriptor.go b/pkg/core/transaction/state_descriptor.go index 770bb6c53..a9447c9db 100644 --- a/pkg/core/transaction/state_descriptor.go +++ b/pkg/core/transaction/state_descriptor.go @@ -37,7 +37,12 @@ func (s *StateDescriptor) DecodeBinary(r io.Reader) error { // EncodeBinary implements the Payload interface. func (s *StateDescriptor) EncodeBinary(w io.Writer) error { - return nil + bw := util.BinWriter{W: w} + bw.WriteLE(s.Type) + bw.WriteBytes(s.Key) + bw.WriteBytes(s.Value) + bw.WriteString(s.Field) + return bw.Err } func (s *StateDescriptor) Size() int {