godprotocol 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Datatypes/arr.js +11 -0
- package/Datatypes/bool.js +11 -0
- package/Datatypes/callable.js +11 -0
- package/Datatypes/functions/storage.js +5 -0
- package/Datatypes/num.js +11 -0
- package/Datatypes/str.js +11 -0
- package/Datatypes/twa.js +11 -0
- package/Datatypes/voi.js +11 -0
- package/Index.js +36 -2
- package/Objects/Account.js +35 -322
- package/Objects/Block.js +7 -80
- package/Objects/Blockweb.js +19 -26
- package/Objects/Callable.js +40 -0
- package/Objects/Chain.js +20 -244
- package/Objects/GDS/Arena_classic/.config +1 -0
- package/Objects/GDS/Arena_classic/Accounts/lola/.config +1 -0
- package/Objects/Manager.js +28 -294
- package/Objects/Oracle.js +67 -84
- package/Objects/Repository.js +67 -0
- package/Objects/Trinity.js +24 -0
- package/Objects/Virtual_machine.js +16 -206
- package/callables/functions/assign.js +6 -0
- package/callables/functions/display.js +3 -0
- package/callables/register.js +22 -0
- package/package.json +24 -43
- package/utils/create_server.js +35 -88
- package/utils/functions.js +0 -70
- package/utils/server.cert +23 -0
- package/utils/server.key +28 -0
- package/utils/services.js +61 -21
- package/utils/vm_utils.js +53 -275
- package/Executables/callables.js +0 -131
- package/Executables/executables.js +0 -230
- package/Executables/functions/adminstrator/adm_register.js +0 -29
- package/Executables/functions/adminstrator/native_components.js +0 -10
- package/Executables/functions/adminstrator/query_selectors.js +0 -10
- package/Executables/functions/adminstrator/render.js +0 -24
- package/Executables/functions/array_register.js +0 -161
- package/Executables/functions/assign.js +0 -19
- package/Executables/functions/display.js +0 -55
- package/Executables/functions/folder.js +0 -95
- package/Executables/functions/folder_register.js +0 -87
- package/Executables/functions/importcheck.js +0 -13
- package/Executables/functions/indices.js +0 -56
- package/Executables/functions/len.js +0 -22
- package/Executables/functions/methods/array.js +0 -272
- package/Executables/functions/methods/string.js +0 -197
- package/Executables/functions/methods/twain.js +0 -148
- package/Executables/functions/op.js +0 -15
- package/Executables/functions/price_register.js +0 -30
- package/Executables/functions/pricing.js +0 -26
- package/Executables/functions/servers/account.js +0 -81
- package/Executables/functions/servers/account_register.js +0 -56
- package/Executables/functions/servers/block.js +0 -21
- package/Executables/functions/servers/block_register.js +0 -18
- package/Executables/functions/servers/chain.js +0 -42
- package/Executables/functions/servers/chain_register.js +0 -28
- package/Executables/functions/set_error_catch.js +0 -34
- package/Executables/functions/string_register.js +0 -130
- package/Executables/functions/twain_register.js +0 -56
- package/Executables/functions/typecast.js +0 -43
- package/Executables/functions/utils.js +0 -9
- package/Executables/stack.js +0 -53
- package/Loader_sequence/main.js +0 -805
- package/Loader_sequence/repository.js +0 -33
- package/Objects/Explorer.js +0 -40
- package/Objects/Fee.js +0 -33
- package/Objects/Filesystem.js +0 -216
- package/Objects/Frame.js +0 -54
- package/Objects/Opcodes.js +0 -87
- package/Objects/Protocol.js +0 -5
- package/Trinity.js +0 -20
- package/callables.js +0 -172
- package/framer.js +0 -124
- package/opcodes/add.js +0 -15
- package/opcodes/indices.js +0 -82
- package/opcodes/jmp.js +0 -16
- package/opcodes/std.js +0 -12
- package/opcodes.js +0 -96
- package/readme.md +0 -133
- package/starter_scripts/constants.seq +0 -11
- package/tsconfig.json +0 -8
- package/types/Account.d.ts +0 -73
- package/types/Block.d.ts +0 -22
- package/types/Blockweb.d.ts +0 -14
- package/types/Chain.d.ts +0 -35
- package/types/Explorer.d.ts +0 -9
- package/types/Filesystem.d.ts +0 -23
- package/types/Frame.d.ts +0 -14
- package/types/Manager.d.ts +0 -21
- package/types/Opcodes.d.ts +0 -11
- package/types/Oracle.d.ts +0 -17
- package/types/Virtual_machine.d.ts +0 -20
- package/types/index.d.ts +0 -4
- package/utils/hash.js +0 -13
- package/utils/logger.js +0 -79
- package/utils/privacy.js +0 -22
- package/utils/type_coersion.js +0 -3
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import typecast from "../typecast";
|
|
2
|
-
|
|
3
|
-
const insert = (args, vm, options) => {
|
|
4
|
-
let { arr, index, value } = args;
|
|
5
|
-
|
|
6
|
-
if (
|
|
7
|
-
!index ||
|
|
8
|
-
(index && index.__classifier__ !== vm.get_type_address("number"))
|
|
9
|
-
)
|
|
10
|
-
index = { static_value: undefined };
|
|
11
|
-
else index = vm.static_value(index);
|
|
12
|
-
|
|
13
|
-
vm.exec({
|
|
14
|
-
executable: arr.__print__,
|
|
15
|
-
location: (result) => {
|
|
16
|
-
if (index.static_value != undefined) {
|
|
17
|
-
result.static_value.splice(index.static_value, 0, value.__address__);
|
|
18
|
-
} else result.static_value = [...result.static_value, value.__address__];
|
|
19
|
-
|
|
20
|
-
vm.write_chain(result, result.__address__);
|
|
21
|
-
|
|
22
|
-
vm.air_object(result.static_value.length, options);
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const pop = (args, vm, options) => {
|
|
28
|
-
let { arr, index } = args;
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
!index ||
|
|
32
|
-
(index && index.__classifier__ !== vm.get_type_address("number"))
|
|
33
|
-
)
|
|
34
|
-
index = { static_value: undefined };
|
|
35
|
-
else index = vm.static_value(index);
|
|
36
|
-
|
|
37
|
-
vm.exec({
|
|
38
|
-
executable: arr.__print__,
|
|
39
|
-
location: (result) => {
|
|
40
|
-
let item;
|
|
41
|
-
if (
|
|
42
|
-
index.static_value != undefined ||
|
|
43
|
-
index.static_value >= result.static_value.length
|
|
44
|
-
) {
|
|
45
|
-
item = result.static_value.splice(index.static_value, 1);
|
|
46
|
-
item = item[0];
|
|
47
|
-
} else item = result.static_value.pop();
|
|
48
|
-
|
|
49
|
-
vm.write_chain(result, result.__address__);
|
|
50
|
-
|
|
51
|
-
vm.write_chain(vm.read_chain(item), options.location);
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const repeat = (args, vm, options) => {
|
|
57
|
-
let {arr, n} = args;
|
|
58
|
-
|
|
59
|
-
if (
|
|
60
|
-
!n ||
|
|
61
|
-
(n && n.__classifier__ !== vm.get_type_address("number"))
|
|
62
|
-
)
|
|
63
|
-
n = { static_value: 0 };
|
|
64
|
-
else n = vm.static_value(n);
|
|
65
|
-
|
|
66
|
-
vm.exec({executable: arr.__print__, location: result=>{
|
|
67
|
-
let og = result.static_value;
|
|
68
|
-
let sv = [...result.static_value];
|
|
69
|
-
|
|
70
|
-
for (let i=0; i< n.static_value; i++){
|
|
71
|
-
sv.push(...og)
|
|
72
|
-
}
|
|
73
|
-
vm.write_chain({...result, static_value: sv}, result.__address__)
|
|
74
|
-
vm.write_chain(arr, options.location)
|
|
75
|
-
}})
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const concat_ = (arr, other, index) => {
|
|
79
|
-
if (index === undefined || index > arr.length) {
|
|
80
|
-
index = arr.length;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
let start = arr.slice(0, index);
|
|
84
|
-
let end = arr.slice(index);
|
|
85
|
-
|
|
86
|
-
arr = [...start, ...other, ...end];
|
|
87
|
-
|
|
88
|
-
return arr;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const concat = (args, vm, options) => {
|
|
92
|
-
let { spread } = options;
|
|
93
|
-
let { arr, other, index } = args;
|
|
94
|
-
|
|
95
|
-
if (other.__classifier__ !== vm.get_type_address("array")) {
|
|
96
|
-
other = typecast({
|
|
97
|
-
obj: vm.static_value(other),
|
|
98
|
-
typ: { static_value: "array" },
|
|
99
|
-
});
|
|
100
|
-
} else other = vm.static_value(other);
|
|
101
|
-
if (
|
|
102
|
-
!index ||
|
|
103
|
-
(index && index.__classifier__ !== vm.get_type_address("number"))
|
|
104
|
-
)
|
|
105
|
-
index = { static_value: undefined };
|
|
106
|
-
else index = vm.static_value(index);
|
|
107
|
-
|
|
108
|
-
vm.exec({
|
|
109
|
-
executable: arr.__print__,
|
|
110
|
-
location: (result) => {
|
|
111
|
-
let res = concat_(
|
|
112
|
-
result.static_value,
|
|
113
|
-
spread ? other.static_value : [other.static_value],
|
|
114
|
-
index.static_value
|
|
115
|
-
);
|
|
116
|
-
vm.write_chain({ ...result, static_value: res }, result.__address__);
|
|
117
|
-
|
|
118
|
-
vm.write_chain(arr, options.location);
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const index = (args, vm, options) => {
|
|
124
|
-
let { arr, n } = args;
|
|
125
|
-
|
|
126
|
-
if (!n || (n && n.__classifier__ !== vm.get_type_address("number")))
|
|
127
|
-
return vm.air_object(null, options);
|
|
128
|
-
else n = vm.static_value(n);
|
|
129
|
-
|
|
130
|
-
vm.exec({
|
|
131
|
-
executable: arr.__print__,
|
|
132
|
-
location: (result) => {
|
|
133
|
-
if (n.static_value < 0 ||( n.static_value >= result.static_value.length))
|
|
134
|
-
return vm.air_object(null, options);
|
|
135
|
-
|
|
136
|
-
vm.write_chain(vm.read_chain(result.static_value[n.static_value]), options.location);
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const slice = (args, vm, options) => {
|
|
142
|
-
let { arr, start, end } = args;
|
|
143
|
-
|
|
144
|
-
if (start.__classifier__ !== vm.get_type_address("number")) {
|
|
145
|
-
return { result: arr };
|
|
146
|
-
} else start = vm.static_value(start);
|
|
147
|
-
|
|
148
|
-
if (!end || (end && end.__classifier__ !== vm.get_type_address("number"))) {
|
|
149
|
-
end = { static_value: undefined };
|
|
150
|
-
} else end = vm.static_value(end);
|
|
151
|
-
|
|
152
|
-
vm.exec({
|
|
153
|
-
executable: arr.__print__,
|
|
154
|
-
location: (result) => {
|
|
155
|
-
let new_val = result.static_value.slice(
|
|
156
|
-
start.static_value,
|
|
157
|
-
end.static_value
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
vm.air_object(new_val, options);
|
|
161
|
-
},
|
|
162
|
-
});
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const clear = (args, vm) => {
|
|
166
|
-
let { arr } = args;
|
|
167
|
-
|
|
168
|
-
vm.exec({
|
|
169
|
-
executable: arr.__print__,
|
|
170
|
-
location: (result) => {
|
|
171
|
-
result.static_value = [];
|
|
172
|
-
vm.write_chain(result, result.__address__);
|
|
173
|
-
|
|
174
|
-
vm.write_chain(arr, options.location);
|
|
175
|
-
},
|
|
176
|
-
});
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
const replace = (args, vm) => {
|
|
180
|
-
let { arr, index, value } = args;
|
|
181
|
-
|
|
182
|
-
if (
|
|
183
|
-
!index ||
|
|
184
|
-
(index && index.__classifier__ !== vm.get_type_address("number"))
|
|
185
|
-
)
|
|
186
|
-
return { result: arr };
|
|
187
|
-
else index = vm.static_value(index);
|
|
188
|
-
|
|
189
|
-
vm.exec({
|
|
190
|
-
executable: arr.__print__,
|
|
191
|
-
location: (result) => {
|
|
192
|
-
result.static_value.splice(index.static_value, 1, value.__address__);
|
|
193
|
-
|
|
194
|
-
vm.write_chain(result, result.__address__);
|
|
195
|
-
|
|
196
|
-
vm.write_chain(arr, options.location);
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
const find = (args, vm, options)=>{
|
|
202
|
-
let {index} = options;
|
|
203
|
-
let {arr, executable} = args;
|
|
204
|
-
|
|
205
|
-
// console.log(args, 'find.args')
|
|
206
|
-
|
|
207
|
-
vm.exec({executable: arr.__print__, location: result=>{
|
|
208
|
-
let stv = result.static_value;
|
|
209
|
-
|
|
210
|
-
vm.exec({executable, metadata: {loop:{index:0, array: stv, conditioner: res=>{
|
|
211
|
-
res = vm.static_value(res)
|
|
212
|
-
return (res && res.static_value === true)
|
|
213
|
-
}}}, arguments:{argv:[{address: stv[0], position: 0}], argc:1}, location: (result, metadata)=>{
|
|
214
|
-
result = vm.static_value(result)
|
|
215
|
-
if(result.static_value=== true){
|
|
216
|
-
if (index){
|
|
217
|
-
vm.air_object(metadata.loop.index, options)
|
|
218
|
-
}else vm.write_chain(this.read_chain(stv[metadata.loop.index]), options.location)
|
|
219
|
-
}else {
|
|
220
|
-
vm.air_object(index? -1: null, options)
|
|
221
|
-
}
|
|
222
|
-
}})
|
|
223
|
-
}})
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const filter = (args, vm, options)=>{
|
|
227
|
-
let {arr, executable} = args;
|
|
228
|
-
|
|
229
|
-
// console.log(args, 'filter.args')
|
|
230
|
-
|
|
231
|
-
vm.exec({executable: arr.__print__, location: result=>{
|
|
232
|
-
let stv = result.static_value;
|
|
233
|
-
let filts = []
|
|
234
|
-
|
|
235
|
-
vm.exec({executable, metadata: {loop:{index:0, array: stv, conditioner: reslt=>{
|
|
236
|
-
let res = vm.static_value(reslt)
|
|
237
|
-
if (res && res.static_value === true){
|
|
238
|
-
filts.push(reslt)
|
|
239
|
-
}
|
|
240
|
-
return true
|
|
241
|
-
}}}, arguments:{argv:[{address: stv[0], position: 0}], argc:1}, location: (result, metadata)=>{
|
|
242
|
-
vm.air_object(filts, {...options, item_type:'static_object'})
|
|
243
|
-
}})
|
|
244
|
-
}})
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const map = (args, vm, options)=>{
|
|
248
|
-
let {arr, executable} = args;
|
|
249
|
-
|
|
250
|
-
// console.log(args, 'map.args')
|
|
251
|
-
|
|
252
|
-
vm.exec({executable: arr.__print__, location: result=>{
|
|
253
|
-
let stv = result.static_value;
|
|
254
|
-
let mapped_values = []
|
|
255
|
-
|
|
256
|
-
vm.exec({executable, metadata: {loop:{index:0, array: stv, conditioner: (res, metadata)=>{
|
|
257
|
-
mapped_values.push(res)
|
|
258
|
-
return metadata.loop.index+1 === stv.length
|
|
259
|
-
}}}, arguments:{argv:[{address: stv[0], position: 0}], argc:1}, location: (result)=>{
|
|
260
|
-
|
|
261
|
-
vm.air_object(mapped_values, {...options, item_type:'static_object'})
|
|
262
|
-
|
|
263
|
-
}})
|
|
264
|
-
|
|
265
|
-
}})
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const copy = (args, vm, options)=>{
|
|
269
|
-
let {arr, depth} = args;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export { pop, insert, repeat, map, concat, index, find, clear, slice, replace , filter, copy};
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import typecast from "../typecast";
|
|
2
|
-
|
|
3
|
-
const slice = (args, vm, options)=>{
|
|
4
|
-
let {str, start, end} = args;
|
|
5
|
-
|
|
6
|
-
if(start.__classifier__ !== vm.get_type_address('number')){
|
|
7
|
-
return {result:str}
|
|
8
|
-
}else start = vm.static_value(start)
|
|
9
|
-
|
|
10
|
-
if(!end || (end && end.__classifier__ !== vm.get_type_address('number'))){
|
|
11
|
-
end = {static_value: undefined}
|
|
12
|
-
}else end = vm.static_value(end)
|
|
13
|
-
|
|
14
|
-
vm.exec({executable:str.__print__, location:(result)=>{
|
|
15
|
-
let new_val = result.static_value.slice(start.static_value, end.static_value)
|
|
16
|
-
|
|
17
|
-
vm.air_object(new_val, options)
|
|
18
|
-
}})
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const case_ = (args, vm, options)=>{
|
|
22
|
-
let {str, type} = args;
|
|
23
|
-
|
|
24
|
-
if(str.__classifier__ !== vm.get_type_address('string')){
|
|
25
|
-
return {result:null}
|
|
26
|
-
}
|
|
27
|
-
if (type.__classifier__ !== vm.get_type_address('number')){
|
|
28
|
-
return {result: str}
|
|
29
|
-
}else type = vm.static_value(type)
|
|
30
|
-
|
|
31
|
-
vm.exec({executable: str.__print__, location:(result)=>{
|
|
32
|
-
let new_val = result.static_value;
|
|
33
|
-
|
|
34
|
-
switch(type.static_value){
|
|
35
|
-
case 1:
|
|
36
|
-
new_val = new_val.toUpperCase()
|
|
37
|
-
break;
|
|
38
|
-
case 2:
|
|
39
|
-
new_val = new_val.toLowerCase()
|
|
40
|
-
break;
|
|
41
|
-
case 3:
|
|
42
|
-
let nv = new_val.split(' ')
|
|
43
|
-
new_val = ''
|
|
44
|
-
nv.map(n=>{
|
|
45
|
-
new_val = `${new_val} ${n[0].toUpperCase()}${n.slice(1).toLowerCase()}`
|
|
46
|
-
})
|
|
47
|
-
new_val = new_val.trim()
|
|
48
|
-
break;
|
|
49
|
-
default:;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
vm.air_object(new_val, options)
|
|
53
|
-
}})
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const concat_ = (str, other, index)=> {
|
|
58
|
-
if (index === undefined || index > str.length) {
|
|
59
|
-
index = str.length;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let start = str.slice(0, index);
|
|
63
|
-
let end = str.slice(index);
|
|
64
|
-
|
|
65
|
-
str = `${start}${other}${end}`;
|
|
66
|
-
return str;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const concat = (args, vm, options)=>{
|
|
70
|
-
let {str, other, index} = args;
|
|
71
|
-
|
|
72
|
-
if (other.__classifier__ !== vm.get_type_address('string')){
|
|
73
|
-
other = typecast({obj: vm.static_value(other), type: {static_value:'string'}})
|
|
74
|
-
}
|
|
75
|
-
if (!index || (index && index.__classifier__ !== vm.get_type_address('number')))
|
|
76
|
-
index = {static_value:undefined}
|
|
77
|
-
else index = vm.static_value(index)
|
|
78
|
-
|
|
79
|
-
vm.exec({executable: str.__print__, location: result=>{
|
|
80
|
-
let res = concat_(result.static_value, other.static_value, index.static_value)
|
|
81
|
-
vm.air_object(res, options)
|
|
82
|
-
}})
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const index = (args, vm, options)=>{
|
|
87
|
-
let {str, n} = args;
|
|
88
|
-
|
|
89
|
-
if (n.__classifier__ !== vm.get_type_address('number')){
|
|
90
|
-
return vm.air_object(null, options)
|
|
91
|
-
}else n = vm.static_value(n)
|
|
92
|
-
|
|
93
|
-
vm.exec({executable: str.__print__, location:result=>{
|
|
94
|
-
vm.air_object(result.static_value[n.static_value] || null, options)
|
|
95
|
-
}})
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const indexof = (args, vm, options)=>{
|
|
100
|
-
let {str, char} = args;
|
|
101
|
-
|
|
102
|
-
if (char.__classifier__ !== vm.get_type_address('string')){
|
|
103
|
-
return vm.air_object(-1, options)
|
|
104
|
-
}else char = vm.static_value(char)
|
|
105
|
-
|
|
106
|
-
vm.exec({executable: str.__print__, location: result=>{
|
|
107
|
-
vm.air_object(result.static_value.indexOf(char.static_value), options)
|
|
108
|
-
}})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const includes = (args, vm, options)=>{
|
|
113
|
-
let {str, chars} = args;
|
|
114
|
-
|
|
115
|
-
if (chars.__classifier__ !== vm.get_type_address('string')){
|
|
116
|
-
return vm.air_object(false, options)
|
|
117
|
-
}else chars = vm.static_value(chars)
|
|
118
|
-
|
|
119
|
-
vm.exec({executable: str.__print__, location: result=>{
|
|
120
|
-
vm.air_object(result.static_value.includes(chars.static_value), options)
|
|
121
|
-
}})
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const split = (args, vm, options)=>{
|
|
125
|
-
let {str, char} = args;
|
|
126
|
-
|
|
127
|
-
if (!char){
|
|
128
|
-
if (char.__classifier__ !== vm.get_type_address('string')){
|
|
129
|
-
return vm.air_object([str], {...options, flat:true})
|
|
130
|
-
}else char = vm.static_value(char)
|
|
131
|
-
}else char = {static_value: ' '}
|
|
132
|
-
|
|
133
|
-
vm.exec({executable: str.__print__, location: result=>{
|
|
134
|
-
vm.air_object(result.static_value.split(char.static_value), options)
|
|
135
|
-
}})
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const trim_start=(str, chars)=> {
|
|
140
|
-
let regex = new RegExp(`^[${chars}]+`, 'g');
|
|
141
|
-
return str.replace(regex, '');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const trim_end=(str, chars)=> {
|
|
145
|
-
let regex = new RegExp(`[${chars}]+$`, 'g');
|
|
146
|
-
return str.replace(regex, '');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const trimmer=(str, chars)=> {
|
|
150
|
-
return trim_start(trim_end(str, chars), chars);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const trim = (args, vm, options) =>{
|
|
154
|
-
let {str, char, type} = args;
|
|
155
|
-
|
|
156
|
-
if (!char || (char.__classifier__ !== vm.get_type_address('string'))){
|
|
157
|
-
char = {static_value: ' '}
|
|
158
|
-
}else char = vm.static_value(char)
|
|
159
|
-
|
|
160
|
-
if ( !type || (type.__classifier__ !== vm.get_type_address('number'))) type = {static_value: 0}
|
|
161
|
-
else type = vm.static_value(type)
|
|
162
|
-
|
|
163
|
-
vm.exec({executable: str.__print__, location: result=>{
|
|
164
|
-
let val = result.static_value
|
|
165
|
-
switch(type.static_value){
|
|
166
|
-
case 0:
|
|
167
|
-
val = trimmer(val, char.static_value)
|
|
168
|
-
break;
|
|
169
|
-
case 1:
|
|
170
|
-
val = trim_start(val, char.static_value)
|
|
171
|
-
break;
|
|
172
|
-
case 2:
|
|
173
|
-
val = trim_end(val, char.static_value)
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
vm.air_object(val, options)
|
|
177
|
-
}})
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const repeat = (args, vm, options)=>{
|
|
181
|
-
let {str,n } = args
|
|
182
|
-
|
|
183
|
-
if (!n){
|
|
184
|
-
return {result:str}
|
|
185
|
-
}
|
|
186
|
-
if (n.__classifier__ !== vm.get_type_address('number')){
|
|
187
|
-
return vm.air_object(null, options)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
n = vm.static_value(n)
|
|
191
|
-
|
|
192
|
-
vm.exec({executable: str.__print__, location: result => {
|
|
193
|
-
vm.air_object(result.static_value.repeat(n.static_value), options)
|
|
194
|
-
}})
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export {slice, index, indexof, concat, case_, split, trim, repeat, includes}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
let hash_for_twain = (str, vm) => {
|
|
2
|
-
let hash = vm.account.manager.oracle.hash;
|
|
3
|
-
let val = hash(str, "sha-1");
|
|
4
|
-
|
|
5
|
-
if (!isNaN(parseInt(val[0]))) val = `_${val.slice(0, -1)}`;
|
|
6
|
-
|
|
7
|
-
return val;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const get = (args, vm, options) => {
|
|
11
|
-
let { twain, prop } = args;
|
|
12
|
-
|
|
13
|
-
if (twain.__classifier__ !== vm.get_type_address("twain")) {
|
|
14
|
-
return vm.stderr({
|
|
15
|
-
name: "Type_error",
|
|
16
|
-
message: "Must be of type `twain`",
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
let static_twain = vm.static_value(twain);
|
|
21
|
-
|
|
22
|
-
vm.exec({
|
|
23
|
-
executable: prop.__print__,
|
|
24
|
-
location: (prop_result) => {
|
|
25
|
-
prop_result = vm.static_value(prop_result);
|
|
26
|
-
|
|
27
|
-
let val = hash_for_twain(prop_result.static_value, vm);
|
|
28
|
-
|
|
29
|
-
let pair = static_twain.static_value[val];
|
|
30
|
-
if (!pair) vm.air_object(null, options);
|
|
31
|
-
else {
|
|
32
|
-
let value = vm.read_chain(pair[1], { tell_callable: true });
|
|
33
|
-
vm.write_chain(value.output, options.location, {
|
|
34
|
-
is_callable: value.callable,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const set = (args, vm, options) => {
|
|
42
|
-
let { twain, prop, value } = args;
|
|
43
|
-
|
|
44
|
-
if (twain.__classifier__ !== vm.get_type_address("twain")) {
|
|
45
|
-
return vm.stderr({
|
|
46
|
-
name: "Type_error",
|
|
47
|
-
message: "Must be of type `twain`",
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let static_twain = vm.static_value(twain);
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
![
|
|
55
|
-
vm.get_type_address("number"),
|
|
56
|
-
vm.get_type_address("string"),
|
|
57
|
-
vm.get_type_address("boolean"),
|
|
58
|
-
vm.get_type_address("void"),
|
|
59
|
-
].includes(prop.__classifier__)
|
|
60
|
-
) {
|
|
61
|
-
return vm.stderr({
|
|
62
|
-
name: "Key_error",
|
|
63
|
-
message: "Key type is not hashable",
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
let prop_static = vm.static_value(prop);
|
|
68
|
-
let val = hash_for_twain(prop_static.static_value, vm);
|
|
69
|
-
|
|
70
|
-
static_twain.static_value[val] = [prop.__address__, value.__address__];
|
|
71
|
-
|
|
72
|
-
vm.write_chain(static_twain, static_twain.__address__);
|
|
73
|
-
|
|
74
|
-
vm.air_object(Object.keys(static_twain.static_value).length, options);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const entries = (args, vm, options) => {
|
|
78
|
-
let { twain } = args;
|
|
79
|
-
|
|
80
|
-
if (twain.__classifier__ !== vm.get_type_address("twain")) {
|
|
81
|
-
return vm.stderr({
|
|
82
|
-
name: "Type_error",
|
|
83
|
-
message: "Must be of type `twain`",
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let static_twain = vm.static_value(twain);
|
|
88
|
-
let statics = [], rrays = [];
|
|
89
|
-
|
|
90
|
-
for (let s in static_twain.static_value) {
|
|
91
|
-
let addr = `${twain.__address__}/${s}`;
|
|
92
|
-
rrays.push(static_twain.static_value[s])
|
|
93
|
-
statics.push(addr);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
let local_addresses = statics.map((s) => `${s}_object`);
|
|
97
|
-
|
|
98
|
-
local_addresses.map((l, i)=>{
|
|
99
|
-
vm.air_object(rrays[i], {...options, location:l})
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
vm.air_object(local_addresses, options)
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const keys = (args, vm, options) => {
|
|
106
|
-
let { twain } = args;
|
|
107
|
-
|
|
108
|
-
if (twain.__classifier__ !== vm.get_type_address("twain")) {
|
|
109
|
-
return vm.stderr({
|
|
110
|
-
name: "Type_error",
|
|
111
|
-
message: "Must be of type `twain`",
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
let static_twain = vm.static_value(twain);
|
|
116
|
-
let statics = [];
|
|
117
|
-
|
|
118
|
-
for (let s in static_twain.static_value) {
|
|
119
|
-
statics.push(static_twain.static_value[s][0]);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
vm.air_object(statics, options)
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const unset = (args, vm, options) => {
|
|
126
|
-
let {twain, prop} = args;
|
|
127
|
-
|
|
128
|
-
let prop_static = vm.static_value(prop)
|
|
129
|
-
let twain_static = vm.static_value(twain)
|
|
130
|
-
|
|
131
|
-
let hash = hash_for_twain(prop_static.static_value)
|
|
132
|
-
let has = twain_static.static_value.hasOwnProperty(hash)
|
|
133
|
-
if (!has){
|
|
134
|
-
return vm.air_object(null, options)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
let value = twain_static.static_value[hash]
|
|
138
|
-
|
|
139
|
-
let value_obj = vm.read_chain(value[1], {tell_callable:true})
|
|
140
|
-
|
|
141
|
-
delete twain_static.static_value[hash]
|
|
142
|
-
|
|
143
|
-
vm.write_chain(twain_static, twain_static.__address__)
|
|
144
|
-
|
|
145
|
-
vm.write_chain(value_obj.output, options.location, {is_callable: value_obj.callable})
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
export { get, set, entries, keys, unset };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const operation = (args, vm, options)=>{
|
|
2
|
-
let {op} = options
|
|
3
|
-
let {left, right }= args;
|
|
4
|
-
|
|
5
|
-
vm.exec({executable: left.__print__, location: (result1)=>{
|
|
6
|
-
if(right){
|
|
7
|
-
vm.exec({executable: right.__print__, location: (result2)=>{
|
|
8
|
-
vm.air_object(vm.run_opcode([result1, result2], op), options)
|
|
9
|
-
}})
|
|
10
|
-
}else vm.air_object(vm.run_opcode([result1], op), options)
|
|
11
|
-
}})
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default operation
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { price } from "./pricing"
|
|
2
|
-
|
|
3
|
-
const price_register = (account)=>{
|
|
4
|
-
let add_callable = account.vm.add_callable
|
|
5
|
-
|
|
6
|
-
add_callable('price_', {
|
|
7
|
-
callable: price,
|
|
8
|
-
config: {
|
|
9
|
-
parameters: [
|
|
10
|
-
{name: 'commodity', position:0},
|
|
11
|
-
{name: 'purpose', position:1},
|
|
12
|
-
{name: 'fee', position:2},
|
|
13
|
-
]
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
add_callable('pay_', {
|
|
18
|
-
callable: price,
|
|
19
|
-
config: {
|
|
20
|
-
parameters: [
|
|
21
|
-
{name: 'payer', position:0},
|
|
22
|
-
{name: 'purpose', position:1},
|
|
23
|
-
{name: 'fee', position:2},
|
|
24
|
-
{name: 'payee', position:3},
|
|
25
|
-
]
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default price_register
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const price = (args, vm, options)=>{
|
|
2
|
-
let {commodity, purpose, validator, fee} = args;
|
|
3
|
-
|
|
4
|
-
let addr = commodity.__address__
|
|
5
|
-
let chain = vm.handle_chain(addr)
|
|
6
|
-
chain.set_fee({purpose, validator, fee})
|
|
7
|
-
|
|
8
|
-
return {result: commodity}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const pay = (args, vm, options) =>{
|
|
12
|
-
let {payer, purpose, fee, payee, callback} = args;
|
|
13
|
-
|
|
14
|
-
let chain = vm.handle_chain(payee.__address__)
|
|
15
|
-
let pass = chain.pay(purpose, fee, payer, (pass)=>{
|
|
16
|
-
pass = vm.display(pass)
|
|
17
|
-
if(pass.static_value !== true) return vm.air_object(null, options)
|
|
18
|
-
|
|
19
|
-
vm.exec({executable: callback, location: options.location, arguments: {argc:1, argv:[{position:0, static_value: pass.payload}]}})
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
return {result: pass}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export {price, pay}
|