/
reservedFunctions.go
59 lines (46 loc) · 1.44 KB
/
reservedFunctions.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
package contexts
import (
"github.com/ElrondNetwork/wasm-vm/arwen"
"github.com/ElrondNetwork/elrond-vm-common"
)
// reservedFunctions holds the reserved function names
type reservedFunctions struct {
functionNames vmcommon.FunctionNames
}
// NewReservedFunctions creates a new reservedFunctions
func NewReservedFunctions(scAPINames vmcommon.FunctionNames, builtInFuncContainer vmcommon.BuiltInFunctionContainer) *reservedFunctions {
result := &reservedFunctions{
functionNames: make(vmcommon.FunctionNames),
}
protocolFuncNames := builtInFuncContainer.Keys()
for name := range protocolFuncNames {
function, err := builtInFuncContainer.Get(name)
if err != nil || !function.IsActive() {
continue
}
result.functionNames[name] = struct{}{}
}
for name, value := range scAPINames {
result.functionNames[name] = value
}
var empty struct{}
result.functionNames[arwen.UpgradeFunctionName] = empty
return result
}
// IsReserved returns whether a function is reserved
func (reservedFunctions *reservedFunctions) IsReserved(functionName string) bool {
if _, ok := reservedFunctions.functionNames[functionName]; ok {
return true
}
return false
}
// GetReserved gets the reserved functions as a slice of strings
func (reservedFunctions *reservedFunctions) GetReserved() []string {
keys := make([]string, len(reservedFunctions.functionNames))
i := 0
for key := range reservedFunctions.functionNames {
keys[i] = key
i++
}
return keys
}