-
Notifications
You must be signed in to change notification settings - Fork 78
/
invocation.go
62 lines (55 loc) · 1.36 KB
/
invocation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package transaction
import (
"errors"
"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,
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)
}
}