-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathFunctionCode.go
More file actions
95 lines (81 loc) · 1.87 KB
/
FunctionCode.go
File metadata and controls
95 lines (81 loc) · 1.87 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package code
import (
"DNA/common/log"
. "DNA/common"
. "DNA/core/contract"
"DNA/common/serialization"
"fmt"
"io"
)
type FunctionCode struct {
// Contract Code
Code []byte
// Contract parameter type list
ParameterTypes []ContractParameterType
// Contract return type list
ReturnType ContractParameterType
codeHash Uint160
}
// method of SerializableData
func (fc *FunctionCode) Serialize(w io.Writer) error {
err := serialization.WriteByte(w, byte(fc.ReturnType))
if err != nil {
return err
}
err = serialization.WriteVarBytes(w, ContractParameterTypeToByte(fc.ParameterTypes))
if err != nil {
return err
}
err = serialization.WriteVarBytes(w,fc.Code)
if err != nil {
return err
}
return nil
}
// method of SerializableData
func (fc *FunctionCode) Deserialize(r io.Reader) error {
returnType, err := serialization.ReadByte(r)
if err != nil {
return err
}
fc.ReturnType = ContractParameterType(returnType)
parameterTypes, err := serialization.ReadVarBytes(r)
if err != nil {
return err
}
fc.ParameterTypes = ByteToContractParameterType(parameterTypes)
fc.Code,err = serialization.ReadVarBytes(r)
if err != nil {
return err
}
return nil
}
// method of ICode
// Get code
func (fc *FunctionCode) GetCode() []byte {
return fc.Code
}
// method of ICode
// Get the list of parameter value
func (fc *FunctionCode) GetParameterTypes() []ContractParameterType {
return fc.ParameterTypes
}
// method of ICode
// Get the list of return value
func (fc *FunctionCode) GetReturnType() ContractParameterType {
return fc.ReturnType
}
// method of ICode
// Get the hash of the smart contract
func (fc *FunctionCode) CodeHash() Uint160 {
u160 := Uint160{}
if fc.codeHash == u160 {
u160, err := ToCodeHash(fc.Code)
if err != nil {
log.Debug( fmt.Sprintf("[FunctionCode] ToCodeHash err=%s",err) )
return u160
}
fc.codeHash = u160
}
return fc.codeHash
}