2018-03-04 13:56:49 +00:00
|
|
|
package transaction
|
|
|
|
|
|
|
|
import (
|
2019-09-16 09:18:13 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
2018-03-04 13:56:49 +00:00
|
|
|
"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.
|
2019-09-09 08:23:27 +00:00
|
|
|
Gas util.Fixed8
|
2019-08-30 07:44:59 +00:00
|
|
|
Version uint8
|
2018-03-04 13:56:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewInvocationTX returns a new invocation transaction.
|
2019-11-19 17:23:14 +00:00
|
|
|
func NewInvocationTX(script []byte, gas util.Fixed8) *Transaction {
|
2018-03-04 13:56:49 +00:00
|
|
|
return &Transaction{
|
|
|
|
Type: InvocationType,
|
|
|
|
Version: 1,
|
|
|
|
Data: &InvocationTX{
|
2019-10-23 08:49:43 +00:00
|
|
|
Script: script,
|
2019-11-19 17:23:14 +00:00
|
|
|
Gas: gas,
|
2019-10-23 08:49:43 +00:00
|
|
|
Version: 1,
|
2018-03-04 13:56:49 +00:00
|
|
|
},
|
|
|
|
Attributes: []*Attribute{},
|
|
|
|
Inputs: []*Input{},
|
|
|
|
Outputs: []*Output{},
|
|
|
|
Scripts: []*Witness{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// DecodeBinary implements Serializable interface.
|
|
|
|
func (tx *InvocationTX) DecodeBinary(br *io.BinReader) {
|
2019-08-28 16:27:06 +00:00
|
|
|
tx.Script = br.ReadBytes()
|
2019-09-09 08:23:27 +00:00
|
|
|
if tx.Version >= 1 {
|
2019-08-30 07:44:59 +00:00
|
|
|
br.ReadLE(&tx.Gas)
|
|
|
|
} else {
|
|
|
|
tx.Gas = util.Fixed8FromInt64(0)
|
|
|
|
}
|
2018-03-04 13:56:49 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// EncodeBinary implements Serializable interface.
|
|
|
|
func (tx *InvocationTX) EncodeBinary(bw *io.BinWriter) {
|
2019-11-22 10:34:06 +00:00
|
|
|
bw.WriteVarBytes(tx.Script)
|
2019-09-09 08:23:27 +00:00
|
|
|
if tx.Version >= 1 {
|
2019-08-30 07:44:59 +00:00
|
|
|
bw.WriteLE(tx.Gas)
|
|
|
|
}
|
2018-03-04 13:56:49 +00:00
|
|
|
}
|