forked from TrueCloudLab/neoneo-go
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.
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package transaction
|
|
|
|
import (
|
|
"errors"
|
|
"math/rand"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
)
|
|
|
|
// InvocationTX represents a invocation transaction and is used to
|
|
// deploy smart contract to the NEO blockchain.
|
|
type InvocationTX struct {
|
|
// Script output of the smart contract.
|
|
Script []byte
|
|
|
|
// Gas cost of the smart contract.
|
|
Gas util.Fixed8
|
|
Version uint8
|
|
}
|
|
|
|
// NewInvocationTX returns a new invocation transaction.
|
|
func NewInvocationTX(script []byte, gas util.Fixed8) *Transaction {
|
|
return &Transaction{
|
|
Type: InvocationType,
|
|
Version: 1,
|
|
Nonce: rand.Uint32(),
|
|
Data: &InvocationTX{
|
|
Script: script,
|
|
Gas: gas,
|
|
Version: 1,
|
|
},
|
|
Attributes: []Attribute{},
|
|
Inputs: []Input{},
|
|
Outputs: []Output{},
|
|
Scripts: []Witness{},
|
|
}
|
|
}
|
|
|
|
// DecodeBinary implements Serializable interface.
|
|
func (tx *InvocationTX) DecodeBinary(br *io.BinReader) {
|
|
tx.Script = br.ReadVarBytes()
|
|
if br.Err == nil && len(tx.Script) == 0 {
|
|
br.Err = errors.New("no script")
|
|
return
|
|
}
|
|
if tx.Version >= 1 {
|
|
tx.Gas.DecodeBinary(br)
|
|
if br.Err == nil && tx.Gas.LessThan(0) {
|
|
br.Err = errors.New("negative gas")
|
|
return
|
|
}
|
|
} else {
|
|
tx.Gas = util.Fixed8FromInt64(0)
|
|
}
|
|
}
|
|
|
|
// EncodeBinary implements Serializable interface.
|
|
func (tx *InvocationTX) EncodeBinary(bw *io.BinWriter) {
|
|
bw.WriteVarBytes(tx.Script)
|
|
if tx.Version >= 1 {
|
|
tx.Gas.EncodeBinary(bw)
|
|
}
|
|
}
|