2018-03-21 16:11:04 +00:00
|
|
|
package transaction
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
// StateTX represents a state transaction.
|
|
|
|
type StateTX struct {
|
|
|
|
Descriptors []*StateDescriptor
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeBinary implements the Payload interface.
|
|
|
|
func (tx *StateTX) DecodeBinary(r io.Reader) error {
|
2019-08-28 16:27:06 +00:00
|
|
|
br := util.BinReader{R: r}
|
|
|
|
lenDesc := br.ReadVarUint()
|
|
|
|
if br.Err != nil {
|
|
|
|
return br.Err
|
|
|
|
}
|
2019-08-30 16:34:26 +00:00
|
|
|
tx.Descriptors = make([]*StateDescriptor, lenDesc)
|
2018-03-21 16:11:04 +00:00
|
|
|
for i := 0; i < int(lenDesc); i++ {
|
|
|
|
tx.Descriptors[i] = &StateDescriptor{}
|
|
|
|
if err := tx.Descriptors[i].DecodeBinary(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements the Payload interface.
|
|
|
|
func (tx *StateTX) EncodeBinary(w io.Writer) error {
|
2019-08-30 16:13:19 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2018-03-21 16:11:04 +00:00
|
|
|
return nil
|
|
|
|
}
|
2019-08-30 08:28:30 +00:00
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// Size returns serialized binary size for this transaction.
|
2019-08-30 08:28:30 +00:00
|
|
|
func (tx *StateTX) Size() int {
|
|
|
|
sz := util.GetVarSize(uint64(len(tx.Descriptors)))
|
|
|
|
for _, desc := range tx.Descriptors {
|
|
|
|
sz += desc.Size()
|
|
|
|
}
|
|
|
|
return sz
|
|
|
|
}
|