/
selectors.go
169 lines (161 loc) · 4.09 KB
/
selectors.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package ride
import "github.com/wavesplatform/gowaves/pkg/ride/ast"
func selectFunctionsByName(v ast.LibraryVersion, enableInvocation bool) (func(string) (rideFunction, bool), error) {
switch v {
case ast.LibV1, ast.LibV2:
return functionsV2, nil
case ast.LibV3:
return functionsV3, nil
case ast.LibV4:
return functionsV4, nil
case ast.LibV5:
if enableInvocation {
return functionsV5, nil
}
return expressionFunctionsV5, nil
case ast.LibV6:
if enableInvocation {
return functionsV6, nil
}
return expressionFunctionsV6, nil
case ast.LibV7:
if enableInvocation {
return functionsV7, nil
}
return expressionFunctionsV7, nil
default:
return nil, EvaluationFailure.Errorf("unsupported library version '%d'", v)
}
}
func selectFunctions(v ast.LibraryVersion) (func(id int) rideFunction, error) {
switch v {
case ast.LibV1, ast.LibV2:
return functionV2, nil
case ast.LibV3:
return functionV3, nil
case ast.LibV4:
return functionV4, nil
case ast.LibV5:
return functionV5, nil
case ast.LibV6:
return functionV6, nil
case ast.LibV7:
return functionV7, nil
default:
return nil, EvaluationFailure.Errorf("unsupported library version '%d'", v)
}
}
func selectFunctionChecker(v ast.LibraryVersion) (func(name string) (uint16, bool), error) {
switch v {
case ast.LibV1, ast.LibV2:
return checkFunctionV2, nil
case ast.LibV3:
return checkFunctionV3, nil
case ast.LibV4:
return checkFunctionV4, nil
case ast.LibV5:
return checkFunctionV5, nil
case ast.LibV6:
return checkFunctionV6, nil
case ast.LibV7:
return checkFunctionV7, nil
default:
return nil, EvaluationFailure.Errorf("unsupported library version '%d'", v)
}
}
func selectEvaluationCostsProvider(v ast.LibraryVersion, ev int) (map[string]int, error) {
switch v {
case ast.LibV1, ast.LibV2:
switch ev {
case 1:
return EvaluationCatalogueV2EvaluatorV1, nil
default:
return EvaluationCatalogueV2EvaluatorV2, nil
}
case ast.LibV3:
switch ev {
case 1:
return EvaluationCatalogueV3EvaluatorV1, nil
default:
return EvaluationCatalogueV3EvaluatorV2, nil
}
case ast.LibV4:
switch ev {
case 1:
return EvaluationCatalogueV4EvaluatorV1, nil
default:
return EvaluationCatalogueV4EvaluatorV2, nil
}
case ast.LibV5:
switch ev {
case 1:
return EvaluationCatalogueV5EvaluatorV1, nil
default:
return EvaluationCatalogueV5EvaluatorV2, nil
}
case ast.LibV6: // Only new version of evaluator works after activation of RideV6
return EvaluationCatalogueV6EvaluatorV2, nil
case ast.LibV7:
return EvaluationCatalogueV7EvaluatorV2, nil
default:
return nil, EvaluationFailure.Errorf("unsupported library version '%d'", v)
}
}
func selectFunctionNameProvider(v ast.LibraryVersion) (func(int) string, error) {
switch v {
case ast.LibV1, ast.LibV2:
return functionNameV2, nil
case ast.LibV3:
return functionNameV3, nil
case ast.LibV4:
return functionNameV4, nil
case ast.LibV5:
return functionNameV5, nil
case ast.LibV6:
return functionNameV6, nil
case ast.LibV7:
return functionNameV7, nil
default:
return nil, EvaluationFailure.Errorf("unsupported library version '%d'", v)
}
}
func selectConstants(v ast.LibraryVersion) (func(int) rideConstructor, error) {
switch v {
case ast.LibV1:
return constantV1, nil
case ast.LibV2:
return constantV2, nil
case ast.LibV3:
return constantV3, nil
case ast.LibV4:
return constantV4, nil
case ast.LibV5:
return constantV5, nil
case ast.LibV6:
return constantV6, nil
case ast.LibV7:
return constantV7, nil
default:
return nil, EvaluationFailure.Errorf("unsupported library version '%d'", v)
}
}
func selectConstantsChecker(v ast.LibraryVersion) (func(name string) (uint16, bool), error) {
switch v {
case ast.LibV1:
return checkConstantV1, nil
case ast.LibV2:
return checkConstantV2, nil
case ast.LibV3:
return checkConstantV3, nil
case ast.LibV4:
return checkConstantV4, nil
case ast.LibV5:
return checkConstantV5, nil
case ast.LibV6:
return checkConstantV6, nil
case ast.LibV7:
return checkConstantV7, nil
default:
return nil, EvaluationFailure.Errorf("unsupported library version '%d'", v)
}
}