2018-03-21 16:11:04 +00:00
|
|
|
package transaction
|
|
|
|
|
|
|
|
import (
|
2020-04-10 10:41:49 +00:00
|
|
|
"math/rand"
|
|
|
|
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
2020-03-23 14:31:28 +00:00
|
|
|
"github.com/nspcc-dev/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
|
|
|
}
|
|
|
|
|
2020-04-10 10:41:49 +00:00
|
|
|
// NewPublishTX creates Transaction of PublishType type.
|
|
|
|
func NewPublishTX(publish *PublishTX) *Transaction {
|
|
|
|
return &Transaction{
|
|
|
|
Type: PublishType,
|
|
|
|
Version: 0,
|
|
|
|
Nonce: rand.Uint32(),
|
|
|
|
Data: publish,
|
|
|
|
Attributes: []Attribute{},
|
|
|
|
Inputs: []Input{},
|
|
|
|
Outputs: []Output{},
|
|
|
|
Scripts: []Witness{},
|
|
|
|
Trimmed: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// DecodeBinary implements Serializable interface.
|
|
|
|
func (tx *PublishTX) DecodeBinary(br *io.BinReader) {
|
2019-12-06 15:37:37 +00:00
|
|
|
tx.Script = br.ReadVarBytes()
|
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++ {
|
2019-12-12 17:17:50 +00:00
|
|
|
tx.ParamList[i] = smartcontract.ParamType(br.ReadB())
|
2018-03-25 10:45:54 +00:00
|
|
|
}
|
|
|
|
|
2019-12-12 17:17:50 +00:00
|
|
|
tx.ReturnType = smartcontract.ParamType(br.ReadB())
|
2018-03-25 10:45:54 +00:00
|
|
|
|
2019-08-27 16:58:50 +00:00
|
|
|
if tx.Version >= 1 {
|
2019-12-12 15:52:23 +00:00
|
|
|
tx.NeedStorage = br.ReadBool()
|
2019-08-27 16:58:50 +00:00
|
|
|
} 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-21 16:11:04 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// EncodeBinary implements Serializable interface.
|
|
|
|
func (tx *PublishTX) EncodeBinary(bw *io.BinWriter) {
|
2019-11-22 10:34:06 +00:00
|
|
|
bw.WriteVarBytes(tx.Script)
|
2019-08-30 16:19:43 +00:00
|
|
|
bw.WriteVarUint(uint64(len(tx.ParamList)))
|
|
|
|
for _, param := range tx.ParamList {
|
2019-12-12 17:17:50 +00:00
|
|
|
bw.WriteB(byte(param))
|
2019-08-30 16:19:43 +00:00
|
|
|
}
|
2019-12-12 17:17:50 +00:00
|
|
|
bw.WriteB(byte(tx.ReturnType))
|
2019-08-30 16:19:43 +00:00
|
|
|
if tx.Version >= 1 {
|
2019-12-12 15:52:23 +00:00
|
|
|
bw.WriteBool(tx.NeedStorage)
|
2019-08-30 16:19:43 +00:00
|
|
|
}
|
|
|
|
bw.WriteString(tx.Name)
|
|
|
|
bw.WriteString(tx.CodeVersion)
|
|
|
|
bw.WriteString(tx.Author)
|
|
|
|
bw.WriteString(tx.Email)
|
|
|
|
bw.WriteString(tx.Description)
|
2018-03-21 16:11:04 +00:00
|
|
|
}
|
2020-03-23 14:31:28 +00:00
|
|
|
|
|
|
|
// publishedContract is a JSON wrapper for PublishTransaction
|
|
|
|
type publishedContract struct {
|
|
|
|
Code publishedCode `json:"code"`
|
|
|
|
NeedStorage bool `json:"needstorage,omitempty"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
CodeVersion string `json:"version,omitempty"`
|
|
|
|
Author string `json:"author,omitempty"`
|
|
|
|
Email string `json:"email,omitempty"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// publishedCode is a JSON wrapper for PublishTransaction Code
|
|
|
|
type publishedCode struct {
|
|
|
|
Hash util.Uint160 `json:"hash,omitempty"`
|
|
|
|
Script string `json:"script,omitempty"`
|
|
|
|
ParamList []smartcontract.ParamType `json:"parameters,omitempty"`
|
|
|
|
ReturnType smartcontract.ParamType `json:"returntype,omitempty"`
|
|
|
|
}
|