2018-03-21 16:11:04 +00:00
|
|
|
package transaction
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/smartcontract"
|
2018-03-25 10:45:54 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
2018-03-21 16:11:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// PublishTX represents a publish transaction.
|
2018-03-25 10:45:54 +00:00
|
|
|
// NOTE: This is deprecated and should no longer be used.
|
2018-03-21 16:11:04 +00:00
|
|
|
type PublishTX struct {
|
|
|
|
Script []byte
|
|
|
|
ParamList []smartcontract.ParamType
|
|
|
|
ReturnType smartcontract.ParamType
|
|
|
|
NeedStorage bool
|
|
|
|
Name string
|
2018-03-25 10:45:54 +00:00
|
|
|
CodeVersion string
|
2018-03-21 16:11:04 +00:00
|
|
|
Author string
|
|
|
|
Email string
|
|
|
|
Description string
|
2019-08-27 16:58:50 +00:00
|
|
|
Version uint8 // Version of the parent struct Transaction. Used in reading NeedStorage flag.
|
2018-03-21 16:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeBinary implements the Payload interface.
|
|
|
|
func (tx *PublishTX) DecodeBinary(r io.Reader) error {
|
2019-09-15 11:58:19 +00:00
|
|
|
br := util.NewBinReaderFromIO(r)
|
2019-08-28 16:27:06 +00:00
|
|
|
tx.Script = br.ReadBytes()
|
2018-03-25 10:45:54 +00:00
|
|
|
|
2019-08-28 16:27:06 +00:00
|
|
|
lenParams := br.ReadVarUint()
|
2018-03-25 10:45:54 +00:00
|
|
|
tx.ParamList = make([]smartcontract.ParamType, lenParams)
|
|
|
|
for i := 0; i < int(lenParams); i++ {
|
|
|
|
var ptype uint8
|
2019-08-28 16:27:06 +00:00
|
|
|
br.ReadLE(&ptype)
|
2018-03-25 10:45:54 +00:00
|
|
|
tx.ParamList[i] = smartcontract.ParamType(ptype)
|
|
|
|
}
|
|
|
|
|
|
|
|
var rtype uint8
|
2019-08-28 16:27:06 +00:00
|
|
|
br.ReadLE(&rtype)
|
2018-03-25 10:45:54 +00:00
|
|
|
tx.ReturnType = smartcontract.ParamType(rtype)
|
|
|
|
|
2019-08-27 16:58:50 +00:00
|
|
|
if tx.Version >= 1 {
|
|
|
|
br.ReadLE(&tx.NeedStorage)
|
|
|
|
} else {
|
|
|
|
tx.NeedStorage = false
|
|
|
|
}
|
2018-03-25 10:45:54 +00:00
|
|
|
|
2019-08-28 16:27:06 +00:00
|
|
|
tx.Name = br.ReadString()
|
|
|
|
tx.CodeVersion = br.ReadString()
|
|
|
|
tx.Author = br.ReadString()
|
|
|
|
tx.Email = br.ReadString()
|
|
|
|
tx.Description = br.ReadString()
|
2018-03-25 10:45:54 +00:00
|
|
|
|
2019-08-28 16:27:06 +00:00
|
|
|
return br.Err
|
2018-03-21 16:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements the Payload interface.
|
|
|
|
func (tx *PublishTX) EncodeBinary(w io.Writer) error {
|
2019-09-15 11:58:19 +00:00
|
|
|
bw := util.NewBinWriterFromIO(w)
|
2019-08-30 16:19:43 +00:00
|
|
|
bw.WriteBytes(tx.Script)
|
|
|
|
bw.WriteVarUint(uint64(len(tx.ParamList)))
|
|
|
|
for _, param := range tx.ParamList {
|
|
|
|
bw.WriteLE(uint8(param))
|
|
|
|
}
|
|
|
|
bw.WriteLE(uint8(tx.ReturnType))
|
|
|
|
if tx.Version >= 1 {
|
|
|
|
bw.WriteLE(tx.NeedStorage)
|
|
|
|
}
|
|
|
|
bw.WriteString(tx.Name)
|
|
|
|
bw.WriteString(tx.CodeVersion)
|
|
|
|
bw.WriteString(tx.Author)
|
|
|
|
bw.WriteString(tx.Email)
|
|
|
|
bw.WriteString(tx.Description)
|
|
|
|
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 this transaction.
|
2019-08-30 08:28:30 +00:00
|
|
|
func (tx *PublishTX) Size() int {
|
|
|
|
sz := util.GetVarSize(tx.Script) + util.GetVarSize(uint64(len(tx.ParamList)))
|
|
|
|
sz += 1 * len(tx.ParamList)
|
2019-09-03 15:01:37 +00:00
|
|
|
sz++
|
2019-08-30 08:28:30 +00:00
|
|
|
if tx.Version >= 1 {
|
2019-09-03 15:01:37 +00:00
|
|
|
sz++
|
2019-08-30 08:28:30 +00:00
|
|
|
}
|
|
|
|
sz += util.GetVarSize(tx.Name) + util.GetVarSize(tx.CodeVersion)
|
|
|
|
sz += util.GetVarSize(tx.Author) + util.GetVarSize(tx.Email)
|
|
|
|
sz += util.GetVarSize(tx.Description)
|
|
|
|
return sz
|
|
|
|
}
|