neoneo-go/pkg/core/transaction/invocation.go
Anthony De Meulemeester 1a1a19da7d
Smartcontract (#39)
* deleted transfer_output added asset type and transaction result to core

* removed writing 0x00 when buffer length is 0

* Refactored emit into VM package + moved tx to own package.

* implemented transaction along with claimTransaction.

* refactored naming of transaction + added decode address for uint160 types

* removed unnecessary folder and files.

* transaction/smartcontract logic

* bumped version 0.24.0
2018-03-04 14:56:49 +01:00

54 lines
1.3 KiB
Go

package transaction
import (
"encoding/binary"
"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
}
// 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 {
lenScript := util.ReadVarUint(r)
tx.Script = make([]byte, lenScript)
if err := binary.Read(r, binary.LittleEndian, tx.Script); err != nil {
return err
}
return binary.Read(r, binary.LittleEndian, &tx.Gas)
}
// EncodeBinary implements the Payload interface.
func (tx *InvocationTX) EncodeBinary(w io.Writer) error {
if err := util.WriteVarUint(w, uint64(len(tx.Script))); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, tx.Script); err != nil {
return err
}
return binary.Write(w, binary.LittleEndian, tx.Gas)
}