mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-30 09:33:36 +00:00
8d0ed9259c
NewInvocationTX() returned a version number one transaction that actually failed to pass that version down to the invocation data which lead to serialization/deserialization inconsistency.
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package transaction
|
|
|
|
import (
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
|
"github.com/CityOfZion/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) *Transaction {
|
|
return &Transaction{
|
|
Type: InvocationType,
|
|
Version: 1,
|
|
Data: &InvocationTX{
|
|
Script: script,
|
|
Version: 1,
|
|
},
|
|
Attributes: []*Attribute{},
|
|
Inputs: []*Input{},
|
|
Outputs: []*Output{},
|
|
Scripts: []*Witness{},
|
|
}
|
|
}
|
|
|
|
// DecodeBinary implements Serializable interface.
|
|
func (tx *InvocationTX) DecodeBinary(br *io.BinReader) {
|
|
tx.Script = br.ReadBytes()
|
|
if tx.Version >= 1 {
|
|
br.ReadLE(&tx.Gas)
|
|
} else {
|
|
tx.Gas = util.Fixed8FromInt64(0)
|
|
}
|
|
}
|
|
|
|
// EncodeBinary implements Serializable interface.
|
|
func (tx *InvocationTX) EncodeBinary(bw *io.BinWriter) {
|
|
bw.WriteBytes(tx.Script)
|
|
if tx.Version >= 1 {
|
|
bw.WriteLE(tx.Gas)
|
|
}
|
|
}
|