mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-27 13:58:05 +00:00
65503aa9b4
1. Closes #840: added Nonce field to transaction.Transaction and removed Nonce field from transaction.MinerTx 2. Added following methods to different tx types: - NewMinerTx() - NewMinerTxWithNonce(...) - NewEnrollmentTx(...) - NewIssueTx() - NewPublishTx(...) - NewRegisterTx(...) - NewStateTx(...) in order to avoid code duplication when new transaction is created. 3. Commented out test cases where binary transaction/block are used. These test cases marked with `TODO NEO3.0: Update binary` and need to be updated. 4. Updated other tests 5. Added constant Nonce to GoveringTockenTx, UtilityTokenTx and genesis block to avoid data variability. Also marked with TODO.
101 lines
2.8 KiB
Go
101 lines
2.8 KiB
Go
package transaction
|
|
|
|
import (
|
|
"math/rand"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
)
|
|
|
|
// PublishTX represents a publish transaction.
|
|
// NOTE: This is deprecated and should no longer be used.
|
|
type PublishTX struct {
|
|
Script []byte
|
|
ParamList []smartcontract.ParamType
|
|
ReturnType smartcontract.ParamType
|
|
NeedStorage bool
|
|
Name string
|
|
CodeVersion string
|
|
Author string
|
|
Email string
|
|
Description string
|
|
Version uint8 // Version of the parent struct Transaction. Used in reading NeedStorage flag.
|
|
}
|
|
|
|
// 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,
|
|
}
|
|
}
|
|
|
|
// DecodeBinary implements Serializable interface.
|
|
func (tx *PublishTX) DecodeBinary(br *io.BinReader) {
|
|
tx.Script = br.ReadVarBytes()
|
|
|
|
lenParams := br.ReadVarUint()
|
|
tx.ParamList = make([]smartcontract.ParamType, lenParams)
|
|
for i := 0; i < int(lenParams); i++ {
|
|
tx.ParamList[i] = smartcontract.ParamType(br.ReadB())
|
|
}
|
|
|
|
tx.ReturnType = smartcontract.ParamType(br.ReadB())
|
|
|
|
if tx.Version >= 1 {
|
|
tx.NeedStorage = br.ReadBool()
|
|
} else {
|
|
tx.NeedStorage = false
|
|
}
|
|
|
|
tx.Name = br.ReadString()
|
|
tx.CodeVersion = br.ReadString()
|
|
tx.Author = br.ReadString()
|
|
tx.Email = br.ReadString()
|
|
tx.Description = br.ReadString()
|
|
}
|
|
|
|
// EncodeBinary implements Serializable interface.
|
|
func (tx *PublishTX) EncodeBinary(bw *io.BinWriter) {
|
|
bw.WriteVarBytes(tx.Script)
|
|
bw.WriteVarUint(uint64(len(tx.ParamList)))
|
|
for _, param := range tx.ParamList {
|
|
bw.WriteB(byte(param))
|
|
}
|
|
bw.WriteB(byte(tx.ReturnType))
|
|
if tx.Version >= 1 {
|
|
bw.WriteBool(tx.NeedStorage)
|
|
}
|
|
bw.WriteString(tx.Name)
|
|
bw.WriteString(tx.CodeVersion)
|
|
bw.WriteString(tx.Author)
|
|
bw.WriteString(tx.Email)
|
|
bw.WriteString(tx.Description)
|
|
}
|
|
|
|
// 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"`
|
|
}
|