2018-03-04 13:56:49 +00:00
|
|
|
package transaction
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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.
|
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.
|
|
|
|
func NewInvocationTX(script []byte) *Transaction {
|
|
|
|
return &Transaction{
|
|
|
|
Type: InvocationType,
|
|
|
|
Version: 1,
|
|
|
|
Data: &InvocationTX{
|
|
|
|
Script: script,
|
|
|
|
},
|
|
|
|
Attributes: []*Attribute{},
|
|
|
|
Inputs: []*Input{},
|
|
|
|
Outputs: []*Output{},
|
|
|
|
Scripts: []*Witness{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeBinary implements the Payload interface.
|
|
|
|
func (tx *InvocationTX) DecodeBinary(r io.Reader) error {
|
2019-08-28 16:27:06 +00:00
|
|
|
br := util.BinReader{R: r}
|
|
|
|
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)
|
|
|
|
}
|
2019-08-28 16:27:06 +00:00
|
|
|
return br.Err
|
2018-03-04 13:56:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements the Payload interface.
|
|
|
|
func (tx *InvocationTX) EncodeBinary(w io.Writer) error {
|
2019-08-28 16:27:06 +00:00
|
|
|
bw := util.BinWriter{W: w}
|
|
|
|
bw.WriteBytes(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)
|
|
|
|
}
|
2019-08-28 16:27:06 +00:00
|
|
|
return bw.Err
|
2018-03-04 13:56:49 +00:00
|
|
|
}
|
2019-08-30 08:28:30 +00:00
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// Size returns serialized binary size for this transaction.
|
2019-08-30 08:28:30 +00:00
|
|
|
func (tx *InvocationTX) Size() int {
|
|
|
|
sz := util.GetVarSize(tx.Script)
|
2019-09-09 08:23:27 +00:00
|
|
|
if tx.Version >= 1 {
|
2019-08-30 08:28:30 +00:00
|
|
|
sz += tx.Gas.Size()
|
|
|
|
}
|
|
|
|
return sz
|
|
|
|
}
|