godprotocol 1.1.2 → 1.1.3
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 +276 -3
- package/Datatypes/bool.js +5 -3
- package/Datatypes/callable.js +4 -3
- package/Datatypes/cls.js +41 -0
- package/Datatypes/conf.js +117 -0
- package/Datatypes/func.js +22 -0
- package/Datatypes/functions/storage.js +20 -1
- package/Datatypes/instance.js +155 -0
- package/Datatypes/num.js +173 -3
- package/Datatypes/str.js +130 -3
- package/Datatypes/twa.js +81 -3
- package/Datatypes/voi.js +3 -3
- package/Index.js +1 -34
- package/Objects/Account.js +45 -29
- package/Objects/Blockweb.js +15 -28
- package/Objects/Callable.js +176 -16
- package/Objects/Chain.js +189 -28
- package/Objects/Datatypes.js +620 -0
- package/Objects/Manager.js +10 -2
- package/Objects/Oracle.js +229 -55
- package/Objects/Repository.js +6 -35
- package/Objects/Trinity.js +3 -3
- package/Objects/Utils.js +16 -0
- package/Objects/Virtual_machine.js +341 -11
- package/callables/functions/display.js +15 -1
- package/callables/functions/exit.js +10 -0
- package/callables/functions/net.js +27 -0
- package/callables/functions/twain.js +11 -0
- package/callables/register.js +23 -7
- package/package.json +1 -1
- package/utils/create_server.js +22 -8
- package/utils/hash.js +18 -0
- package/utils/ops.js +17 -0
- package/utils/services.js +2 -0
- package/utils/vm_utils.js +76 -43
- package/Objects/GDS/Arena_classic/.config +0 -1
- package/Objects/GDS/Arena_classic/Accounts/lola/.config +0 -1
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
class Datatypes{
|
|
2
|
+
|
|
3
|
+
string = async(op, args)=>{
|
|
4
|
+
let me = await this.literal(),
|
|
5
|
+
other = args[0], result=null;
|
|
6
|
+
|
|
7
|
+
console.log(op)
|
|
8
|
+
switch(op){
|
|
9
|
+
case 'upper':
|
|
10
|
+
result = me.toUpperCase()
|
|
11
|
+
break;
|
|
12
|
+
case 'lower':
|
|
13
|
+
result = me.toLowerCase()
|
|
14
|
+
break;
|
|
15
|
+
case 'title':
|
|
16
|
+
result = "";
|
|
17
|
+
me = me.split(' ').map(m=>{
|
|
18
|
+
result = `${result} ${m[0].toUpperCase()}${m.slice(1).toLowerCase()}`.trim()
|
|
19
|
+
})
|
|
20
|
+
break;
|
|
21
|
+
case 'slice':
|
|
22
|
+
let start = args[0], end = args[1];
|
|
23
|
+
start = start && await start.literal()
|
|
24
|
+
end = end && await end.literal()
|
|
25
|
+
|
|
26
|
+
result = me.slice(start, end)
|
|
27
|
+
break;
|
|
28
|
+
case 'concat':
|
|
29
|
+
other = await args[0].literal()
|
|
30
|
+
result = `${me}${other}`
|
|
31
|
+
break;
|
|
32
|
+
case 'find':
|
|
33
|
+
let lst = args[1] && await args[1].literal()
|
|
34
|
+
result = me[lst?'lastIndexOf': 'indexOf'](await other.literal())
|
|
35
|
+
break;
|
|
36
|
+
case 'includes':
|
|
37
|
+
result = me.includes(await other.literal())
|
|
38
|
+
break;
|
|
39
|
+
case 'index':
|
|
40
|
+
other = await other.literal()
|
|
41
|
+
if (other < 0){
|
|
42
|
+
result = me.slice(other)[0]
|
|
43
|
+
}else result = me[other]
|
|
44
|
+
break;
|
|
45
|
+
case 'trim':
|
|
46
|
+
other = args[0]
|
|
47
|
+
if (other) other = await other.literal()
|
|
48
|
+
else other = 0
|
|
49
|
+
let char = args[1]
|
|
50
|
+
if (char) char = await char.literal()
|
|
51
|
+
else char = ' '
|
|
52
|
+
|
|
53
|
+
let esc_regx_char = (char) => char.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
54
|
+
|
|
55
|
+
let char_regx = esc_regx_char(char);
|
|
56
|
+
|
|
57
|
+
switch (other) {
|
|
58
|
+
case 1:
|
|
59
|
+
result = me.replace(new RegExp(`^${char_regx}+`), '');
|
|
60
|
+
break
|
|
61
|
+
case 2:
|
|
62
|
+
result = me.replace(new RegExp(`${char_regx}+$`), '');
|
|
63
|
+
break
|
|
64
|
+
case 0:
|
|
65
|
+
default:
|
|
66
|
+
result = me.replace(new RegExp(`^${char_regx}+|${char_regx}+$`, 'g'), '');
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
case 'length':
|
|
70
|
+
result = me.length;
|
|
71
|
+
break;
|
|
72
|
+
case 'is_empty':
|
|
73
|
+
result = !!me
|
|
74
|
+
break;
|
|
75
|
+
case 'is_blank':
|
|
76
|
+
result = !!me.trim()
|
|
77
|
+
break;
|
|
78
|
+
case 'is_numeric':
|
|
79
|
+
result = !!me && !isNaN(Number(me))
|
|
80
|
+
break;
|
|
81
|
+
case "endswith":
|
|
82
|
+
result = me.endsWith(await other.literal())
|
|
83
|
+
break;
|
|
84
|
+
case "startswith":
|
|
85
|
+
result = me.startsWith(await other.literal())
|
|
86
|
+
break;
|
|
87
|
+
case 'padend':
|
|
88
|
+
result = me.padEnd(await other.literal(), await args[1].literal())
|
|
89
|
+
break;
|
|
90
|
+
case 'padstart':
|
|
91
|
+
result = me.padStart(await other.literal(), await args[1].literal())
|
|
92
|
+
break;
|
|
93
|
+
case 'count':
|
|
94
|
+
other = await args[0].literal()
|
|
95
|
+
|
|
96
|
+
let count = 0;
|
|
97
|
+
let position = 0;
|
|
98
|
+
|
|
99
|
+
while ((position = me.indexOf(other, position)) !== -1) {
|
|
100
|
+
count++;
|
|
101
|
+
position += other.length;
|
|
102
|
+
}
|
|
103
|
+
result = count;
|
|
104
|
+
break;
|
|
105
|
+
case 'reverse':
|
|
106
|
+
result = me.split('').reverse().join('');
|
|
107
|
+
break
|
|
108
|
+
case 'repeat':
|
|
109
|
+
result = me.repeat(await other.literal())
|
|
110
|
+
break
|
|
111
|
+
case 'replace':
|
|
112
|
+
let globally = args[2] && await args[2].literal(),
|
|
113
|
+
keyword = await other.literal(), replacement = await args[1].literal()
|
|
114
|
+
result = me.replace(keyword, replacement)
|
|
115
|
+
if (globally){
|
|
116
|
+
while(result.includes(keyword)) result = result.replace(keyword, replacement)
|
|
117
|
+
}
|
|
118
|
+
break
|
|
119
|
+
case 'split':
|
|
120
|
+
other = other ? await other.literal(): ' '
|
|
121
|
+
result = me.split(other)
|
|
122
|
+
break
|
|
123
|
+
case 'charcode':
|
|
124
|
+
let code = args[1] ? await args[1].literal() : 'ascii'
|
|
125
|
+
if (code === 'ascii'){
|
|
126
|
+
result = me.split("").map(char => char.charCodeAt(0))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return result
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
number = async (op, args)=>{
|
|
136
|
+
let other = args[0]
|
|
137
|
+
|
|
138
|
+
other = other && await other.literal()
|
|
139
|
+
let me = await this.literal()
|
|
140
|
+
|
|
141
|
+
let result;
|
|
142
|
+
switch(op){
|
|
143
|
+
case '__add__':
|
|
144
|
+
result = me + other;
|
|
145
|
+
break;
|
|
146
|
+
case '__sub__':
|
|
147
|
+
result = me - other;
|
|
148
|
+
break;
|
|
149
|
+
case '__mul__':
|
|
150
|
+
result = me * other;
|
|
151
|
+
break;
|
|
152
|
+
case '__div__':
|
|
153
|
+
if (!other)result = { error:true, value:{name: 'ZeroDivision'}}
|
|
154
|
+
else result = me / other;
|
|
155
|
+
break;
|
|
156
|
+
case '__exp__':
|
|
157
|
+
result = me ** other;
|
|
158
|
+
break;
|
|
159
|
+
case '__floordiv__':
|
|
160
|
+
result = Math.floor(me / other);
|
|
161
|
+
break;
|
|
162
|
+
case '__mod__':
|
|
163
|
+
result = me % other;
|
|
164
|
+
break;
|
|
165
|
+
case '__eq__':
|
|
166
|
+
result = me === other
|
|
167
|
+
break;
|
|
168
|
+
case '__ne__':
|
|
169
|
+
result = me !== other
|
|
170
|
+
break;
|
|
171
|
+
case '__lt__':
|
|
172
|
+
result = me < other
|
|
173
|
+
break;
|
|
174
|
+
case '__lte__':
|
|
175
|
+
result = me <= other
|
|
176
|
+
break;
|
|
177
|
+
case '__gt__':
|
|
178
|
+
result = me > other
|
|
179
|
+
break;
|
|
180
|
+
case '__gte__':
|
|
181
|
+
result = me >= other
|
|
182
|
+
break;
|
|
183
|
+
case 'abs':
|
|
184
|
+
result = Math.abs(me)
|
|
185
|
+
break;
|
|
186
|
+
case 'sqrt':
|
|
187
|
+
result = Math.sqrt(me)
|
|
188
|
+
break;
|
|
189
|
+
case 'to_int':
|
|
190
|
+
result = parseInt(me)
|
|
191
|
+
break;
|
|
192
|
+
case 'to_float':
|
|
193
|
+
result = Number(me).toFixed(other)
|
|
194
|
+
break;
|
|
195
|
+
case 'to_string':
|
|
196
|
+
result = me.toString()
|
|
197
|
+
break;
|
|
198
|
+
case 'tan':
|
|
199
|
+
result = Math.tan(me)
|
|
200
|
+
break;
|
|
201
|
+
case 'sin':
|
|
202
|
+
result = Math.sin(me)
|
|
203
|
+
break;
|
|
204
|
+
case 'cos':
|
|
205
|
+
result = Math.cos(me)
|
|
206
|
+
break;
|
|
207
|
+
case 'atan':
|
|
208
|
+
result = Math.atan(me)
|
|
209
|
+
break;
|
|
210
|
+
case 'atan2':
|
|
211
|
+
result = Math.atan2(me)
|
|
212
|
+
break;
|
|
213
|
+
case 'asin':
|
|
214
|
+
result = Math.asin(me)
|
|
215
|
+
break;
|
|
216
|
+
case 'acos':
|
|
217
|
+
result = Math.acos(me)
|
|
218
|
+
break;
|
|
219
|
+
case 'tanh':
|
|
220
|
+
result = Math.tanh(me)
|
|
221
|
+
break;
|
|
222
|
+
case 'sinh':
|
|
223
|
+
result = Math.sinh(me)
|
|
224
|
+
break;
|
|
225
|
+
case 'cosh':
|
|
226
|
+
result = Math.cosh(me)
|
|
227
|
+
break;
|
|
228
|
+
case 'asinh':
|
|
229
|
+
result = Math.asinh(me)
|
|
230
|
+
break;
|
|
231
|
+
case 'acosh':
|
|
232
|
+
result = Math.acosh(me)
|
|
233
|
+
break;
|
|
234
|
+
case 'atanh':
|
|
235
|
+
result = Math.atanh(me)
|
|
236
|
+
break;
|
|
237
|
+
case 'round':
|
|
238
|
+
if (other){
|
|
239
|
+
result = Number(Number(me).toFixed(other))
|
|
240
|
+
}else result = Math.round(me)
|
|
241
|
+
break;
|
|
242
|
+
case 'ceil':
|
|
243
|
+
result = Math.ceil(me)
|
|
244
|
+
break;
|
|
245
|
+
case 'floor':
|
|
246
|
+
result = Math.floor(me)
|
|
247
|
+
break;
|
|
248
|
+
case 'is_prime':
|
|
249
|
+
if (me <= 1) result = false;
|
|
250
|
+
if (me <= 3) result = true;
|
|
251
|
+
|
|
252
|
+
if (me % 2 === 0 || me % 3 === 0) result = false;
|
|
253
|
+
|
|
254
|
+
for (let i = 5; i * i <= me; i += 6) {
|
|
255
|
+
if (me % i === 0 || me % (i + 2) === 0) {
|
|
256
|
+
result = false;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
result = true;
|
|
260
|
+
break;
|
|
261
|
+
case 'is_odd':
|
|
262
|
+
result = (me % 2) === 1
|
|
263
|
+
break
|
|
264
|
+
case 'is_even':
|
|
265
|
+
result = (me % 2) === 0
|
|
266
|
+
break
|
|
267
|
+
case 'log':
|
|
268
|
+
if (!other || (other === 10))
|
|
269
|
+
result = Math.log10(me)
|
|
270
|
+
else if (other === Math.E){
|
|
271
|
+
result = Math.log(me)
|
|
272
|
+
}else result = Math.log(me) / Math.log(other)
|
|
273
|
+
break;
|
|
274
|
+
case 'factorial':
|
|
275
|
+
result = this.factorial(me)
|
|
276
|
+
break;
|
|
277
|
+
case 'is_perfect_square':
|
|
278
|
+
if (me < 0) result = false;
|
|
279
|
+
|
|
280
|
+
let sqrt = Math.sqrt(me);
|
|
281
|
+
result = sqrt === Math.floor(sqrt);
|
|
282
|
+
break
|
|
283
|
+
case 'to_degrees':
|
|
284
|
+
result = me * (180 / Math.PI)
|
|
285
|
+
break;
|
|
286
|
+
case 'to_radians':
|
|
287
|
+
result = me * (Math.PI / 180)
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return result
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
array = async(op, args, options={})=>{
|
|
295
|
+
let {config, chain } = options;
|
|
296
|
+
|
|
297
|
+
await this.literal()
|
|
298
|
+
let other = args[0], store, result = null;
|
|
299
|
+
|
|
300
|
+
switch(op){
|
|
301
|
+
case 'push':
|
|
302
|
+
result = this.lit.content_addr.push(other.value.path)
|
|
303
|
+
store = true;
|
|
304
|
+
break;
|
|
305
|
+
case 'length':
|
|
306
|
+
result = this.lit.content.length;
|
|
307
|
+
break;
|
|
308
|
+
case 'pop':
|
|
309
|
+
if (other){
|
|
310
|
+
result = this.lit.content_addr.splice(await other.literal(), 1)[0]
|
|
311
|
+
}else result = this.lit.content_addr.pop()
|
|
312
|
+
|
|
313
|
+
store= true
|
|
314
|
+
|
|
315
|
+
if(result){
|
|
316
|
+
result = {type:'address',value: result}
|
|
317
|
+
}
|
|
318
|
+
break;
|
|
319
|
+
case 'extend':
|
|
320
|
+
await other.literal()
|
|
321
|
+
result = this.lit.content_addr.push(...other.lit.content_addr)
|
|
322
|
+
store = true
|
|
323
|
+
|
|
324
|
+
break;
|
|
325
|
+
case 'slice':
|
|
326
|
+
let start = args[0] && await args[0].literal()
|
|
327
|
+
let end = args[1] && await args[1].literal()
|
|
328
|
+
|
|
329
|
+
let new_arr = this.lit.content_addr.slice(start, end)
|
|
330
|
+
result = new_arr
|
|
331
|
+
|
|
332
|
+
let res = await this.account.vm.instantiate({type:'array', value: result, location: config.location}, {chain, pure: true})
|
|
333
|
+
|
|
334
|
+
result = {type:'address', value: res}
|
|
335
|
+
break;
|
|
336
|
+
case 'splice':
|
|
337
|
+
let spl_replacement = args[2]
|
|
338
|
+
if (spl_replacement){
|
|
339
|
+
result = this.lit.content_addr.splice(args[0] && await args[0].literal(), args[1] && await args[1].literal(), spl_replacement.value.path )
|
|
340
|
+
}else result = this.lit.content_addr.splice(args[0] && await args[0].literal(), args[1] && await args[1].literal())
|
|
341
|
+
|
|
342
|
+
store = true;
|
|
343
|
+
|
|
344
|
+
result = {type:'address', value: await this.account.vm.instantiate({type:'array', value: result, location: config.location}, {chain, pure: true})}
|
|
345
|
+
|
|
346
|
+
break;
|
|
347
|
+
case 'index':
|
|
348
|
+
other = await other.literal()
|
|
349
|
+
if (typeof other === 'number'){
|
|
350
|
+
if (other <0){
|
|
351
|
+
result = this.lit.content_addr.slice(other)[0]
|
|
352
|
+
}else result = this.lit.content_addr[other];
|
|
353
|
+
}
|
|
354
|
+
if (result) result = {type:'address', value: result}
|
|
355
|
+
break;
|
|
356
|
+
case 'to_string':
|
|
357
|
+
other = other && await other.literal()
|
|
358
|
+
|
|
359
|
+
result = ''
|
|
360
|
+
for (let i=0; i< this.lit.content_addr.length; i++){
|
|
361
|
+
let item = this.lit.content_addr[i];
|
|
362
|
+
|
|
363
|
+
let cont = await this.account.vm.resolve_address(item);
|
|
364
|
+
cont = await this.account.vm.cloth_content(cont)
|
|
365
|
+
cont = await cont.literal()
|
|
366
|
+
if (other === 'ascii'){
|
|
367
|
+
if (typeof cont === 'number'){
|
|
368
|
+
result = `${result}${String.fromCharCode(cont)}`
|
|
369
|
+
}else result = `${result}void`
|
|
370
|
+
}else result = `${result}${cont}`
|
|
371
|
+
}
|
|
372
|
+
break;
|
|
373
|
+
case 'is_empty':
|
|
374
|
+
result = !this.lit.content_addr.length
|
|
375
|
+
break;
|
|
376
|
+
case 'clear':
|
|
377
|
+
this.lit.content_addr = []
|
|
378
|
+
store = true;
|
|
379
|
+
break
|
|
380
|
+
case "join":
|
|
381
|
+
let str_val = ''
|
|
382
|
+
let separator = (other && await other.literal()) || ','
|
|
383
|
+
for (let i=0; i< this.lit.content_addr.length; i++){
|
|
384
|
+
let item = this.lit.content_addr[i]
|
|
385
|
+
let val = await this.account.vm.cloth_content(await this.account.vm.resolve_address(item))
|
|
386
|
+
|
|
387
|
+
let cont = await val.literal()
|
|
388
|
+
if (['number', 'string', 'void', 'boolean'].includes(typeof cont))str_val = `${str_val}${i ? separator: ''}${cont}`
|
|
389
|
+
}
|
|
390
|
+
result = str_val
|
|
391
|
+
break;
|
|
392
|
+
case 'map':
|
|
393
|
+
let confg = other.value;
|
|
394
|
+
let map_arr = []
|
|
395
|
+
for (let i=0; i< this.lit.content_addr.length; i++){
|
|
396
|
+
let item = this.lit.content_addr[i];
|
|
397
|
+
|
|
398
|
+
let res = await this.account.vm.execute(confg, {call_config: {
|
|
399
|
+
identifier: confg.address,
|
|
400
|
+
arguments: [
|
|
401
|
+
{type:'address', value: item, position: 0},
|
|
402
|
+
{...await this.account.vm.parse_aircode(i, {config, chain}), position:1}
|
|
403
|
+
],
|
|
404
|
+
location: config.location
|
|
405
|
+
}, chain})
|
|
406
|
+
if (res && res.type!== 'address'){
|
|
407
|
+
console.log("Datatypes.js:Query")
|
|
408
|
+
}
|
|
409
|
+
map_arr.push(res.value)
|
|
410
|
+
}
|
|
411
|
+
if (args[1] && await args[1].literal()){
|
|
412
|
+
this.lit.content_addr = map_arr
|
|
413
|
+
store = true
|
|
414
|
+
}else result = {type:'address', value: await this.account.vm.instantiate({type:'array', value: map_arr, location: config.location}, {chain, pure: true})}
|
|
415
|
+
|
|
416
|
+
break;
|
|
417
|
+
case 'filter':
|
|
418
|
+
let fconfg = other.value;
|
|
419
|
+
let fil_arr = []
|
|
420
|
+
for (let i=0; i< this.lit.content_addr.length; i++){
|
|
421
|
+
let item = this.lit.content_addr[i];
|
|
422
|
+
|
|
423
|
+
let res = await this.account.vm.execute(fconfg, {call_config: {
|
|
424
|
+
identifier: fconfg.address,
|
|
425
|
+
arguments: [
|
|
426
|
+
{type:'address', value: item, position: 0},
|
|
427
|
+
{...await this.account.vm.parse_aircode(i, {config, chain}), position:1}
|
|
428
|
+
],
|
|
429
|
+
location: config.location
|
|
430
|
+
}, chain, cloth: true})
|
|
431
|
+
|
|
432
|
+
if (res && !!await res.literal())
|
|
433
|
+
fil_arr.push(item)
|
|
434
|
+
}
|
|
435
|
+
if (args[1] && await args[1].literal()){
|
|
436
|
+
this.lit.content_addr = fil_arr
|
|
437
|
+
store = true
|
|
438
|
+
}else result = {
|
|
439
|
+
type:'address',
|
|
440
|
+
value: await this.account.vm.instantiate({
|
|
441
|
+
type:'array',
|
|
442
|
+
value: fil_arr,
|
|
443
|
+
location: config.location},
|
|
444
|
+
{chain, pure: true})
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
break;
|
|
448
|
+
case 'find':
|
|
449
|
+
let fnconfg = other.value;
|
|
450
|
+
for (let i=0; i< this.lit.content_addr.length; i++){
|
|
451
|
+
let item = this.lit.content_addr[i];
|
|
452
|
+
|
|
453
|
+
let index = await this.account.vm.parse_aircode(i, {config, chain})
|
|
454
|
+
let res = await this.account.vm.execute(fnconfg, {call_config: {
|
|
455
|
+
identifier: fnconfg.address,
|
|
456
|
+
arguments: [
|
|
457
|
+
{type:'address', value: item, position: 0},
|
|
458
|
+
{...index, position:1}
|
|
459
|
+
],
|
|
460
|
+
location: config.location
|
|
461
|
+
}, chain, cloth: true})
|
|
462
|
+
|
|
463
|
+
if (res && !!await res.literal())
|
|
464
|
+
{
|
|
465
|
+
result = index
|
|
466
|
+
break
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
case 'includes':
|
|
470
|
+
other = await other.literal()
|
|
471
|
+
for (let i=0; i< this.lit.content_addr.length; i++){
|
|
472
|
+
let item = this.lit.content_addr[i];
|
|
473
|
+
let val = await this.account.vm.cloth_content(await this.account.vm.resolve_address(item))
|
|
474
|
+
|
|
475
|
+
if (await val.literal() === other){
|
|
476
|
+
result = true;
|
|
477
|
+
break
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
result = result || false
|
|
481
|
+
break;
|
|
482
|
+
case 'copy':
|
|
483
|
+
result = {
|
|
484
|
+
type:'address',
|
|
485
|
+
value: await this.account.vm.instantiate({
|
|
486
|
+
type:'array',
|
|
487
|
+
value: [...this.lit.content_addr],
|
|
488
|
+
location: config.location},
|
|
489
|
+
{chain, pure: true})
|
|
490
|
+
}
|
|
491
|
+
break;
|
|
492
|
+
case 'reverse':
|
|
493
|
+
this.lit.content_addr.reverse()
|
|
494
|
+
store = true
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (store) {
|
|
499
|
+
let oracle = this.account.manager.oracle
|
|
500
|
+
let obj = {content: JSON.stringify(this.lit.content_addr), __classifier__: 'array', uid: this.lit.uid}
|
|
501
|
+
|
|
502
|
+
let path_split = this.value.path.split('/')
|
|
503
|
+
await oracle.fs.store(obj, {path: path_split.slice(0,-1).join('/'), hash: path_split[path_split.length-1], is_instance: true, type: 'twain'})
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
return result
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
twain = async(op, args, options)=>{
|
|
510
|
+
let {config, chain} = options
|
|
511
|
+
await this.literal()
|
|
512
|
+
|
|
513
|
+
let result = null, store, other = args[0];
|
|
514
|
+
switch(op){
|
|
515
|
+
case 'entries':
|
|
516
|
+
result = []
|
|
517
|
+
for (let p in this.lit.content_addr){
|
|
518
|
+
let pair = this.lit.content_addr[p]
|
|
519
|
+
|
|
520
|
+
result.push(await this.account.vm.instantiate({
|
|
521
|
+
type:'array',
|
|
522
|
+
value: pair,
|
|
523
|
+
location: config.location},
|
|
524
|
+
{chain, pure: true}))
|
|
525
|
+
}
|
|
526
|
+
result = {type:'address', value: await this.account.vm.instantiate({
|
|
527
|
+
type:'array',
|
|
528
|
+
value: result,
|
|
529
|
+
location: config.location},
|
|
530
|
+
{chain, pure: true})
|
|
531
|
+
}
|
|
532
|
+
break;
|
|
533
|
+
case 'keys':
|
|
534
|
+
result = []
|
|
535
|
+
for (let p in this.lit.content_addr){
|
|
536
|
+
let pair = this.lit.content_addr[p]
|
|
537
|
+
|
|
538
|
+
result.push(pair[0])
|
|
539
|
+
}
|
|
540
|
+
result = {type:'address', value: await this.account.vm.instantiate({
|
|
541
|
+
type:'array',
|
|
542
|
+
value: result,
|
|
543
|
+
location: config.location},
|
|
544
|
+
{chain, pure: true})
|
|
545
|
+
}
|
|
546
|
+
break;
|
|
547
|
+
|
|
548
|
+
case 'values':
|
|
549
|
+
result = []
|
|
550
|
+
for (let p in this.lit.content_addr){
|
|
551
|
+
let pair = this.lit.content_addr[p]
|
|
552
|
+
|
|
553
|
+
result.push(pair[1])
|
|
554
|
+
}
|
|
555
|
+
result = {type:'address', value: await this.account.vm.instantiate({
|
|
556
|
+
type:'array',
|
|
557
|
+
value: result,
|
|
558
|
+
location: config.location},
|
|
559
|
+
{chain, pure: true})
|
|
560
|
+
}
|
|
561
|
+
break;
|
|
562
|
+
case 'get':
|
|
563
|
+
if(typeof other === 'string'){}
|
|
564
|
+
else other = other && await other.literal()
|
|
565
|
+
|
|
566
|
+
let hash = await this.account.manager.oracle.hash(other, 'sha1')
|
|
567
|
+
let val = this.lit.content_addr[hash]
|
|
568
|
+
if (val)result = {type: 'address', value: val[1]}
|
|
569
|
+
break;
|
|
570
|
+
case 'set':
|
|
571
|
+
other = other && await other.literal()
|
|
572
|
+
let shash = await this.account.manager.oracle.hash(other, 'sha1')
|
|
573
|
+
|
|
574
|
+
this.lit.content_addr[shash] = [args[0].value.path, args[1].value.path]
|
|
575
|
+
store = true;
|
|
576
|
+
break;
|
|
577
|
+
case 'remove':
|
|
578
|
+
other = other && await other.literal()
|
|
579
|
+
let rhash = await this.account.manager.oracle.hash(other, 'sha1')
|
|
580
|
+
let rval = this.lit.content_addr[rhash]
|
|
581
|
+
if(rval)result = true
|
|
582
|
+
else result = false;
|
|
583
|
+
|
|
584
|
+
delete this.lit.content_addr[rhash]
|
|
585
|
+
store = true;
|
|
586
|
+
break
|
|
587
|
+
case 'copy':
|
|
588
|
+
result = {type:'address', value: await this.account.vm.instantiate({
|
|
589
|
+
type:'twain',
|
|
590
|
+
value: this.lit.content_addr,
|
|
591
|
+
location: config.location},
|
|
592
|
+
{chain, pure: true})
|
|
593
|
+
}
|
|
594
|
+
break;
|
|
595
|
+
case 'clear':
|
|
596
|
+
this.lit.content_addr = {}
|
|
597
|
+
store = true;
|
|
598
|
+
break
|
|
599
|
+
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
if (store) {
|
|
603
|
+
let oracle = this.account.manager.oracle
|
|
604
|
+
let obj = {content: JSON.stringify(this.lit.content_addr), __classifier__: 'twain', uid: this.lit.uid}
|
|
605
|
+
|
|
606
|
+
let path_split = this.value.path.split('/')
|
|
607
|
+
await oracle.fs.store(obj, {path: path_split.slice(0,-1).join('/'), hash: path_split[path_split.length-1], is_instance: true, type: 'twain'})
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
return result
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
factorial = (value)=>{
|
|
614
|
+
if (value === 0)
|
|
615
|
+
return 1
|
|
616
|
+
return value * this.factorial(value - 1)
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
export default Datatypes;
|
package/Objects/Manager.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import create_server from "../utils/create_server";
|
|
2
2
|
import { post_request } from "../utils/services";
|
|
3
3
|
import Account from "./Account";
|
|
4
|
-
import Blockweb from "./Blockweb";
|
|
5
4
|
import Oracle from "./Oracle";
|
|
5
|
+
import Blockweb from "./Blockweb";
|
|
6
6
|
import Repository from "./Repository";
|
|
7
7
|
|
|
8
8
|
class Manager {
|
|
@@ -10,6 +10,7 @@ class Manager {
|
|
|
10
10
|
this.name = name;
|
|
11
11
|
this.options = options || {};
|
|
12
12
|
|
|
13
|
+
this.trinity = options.trinity;
|
|
13
14
|
this.sync_server = options.sync_server;
|
|
14
15
|
if (this.sync_server && !this.sync_server.domain) {
|
|
15
16
|
this.sync_server.domain = `${this.sync_server.hostname}:${this.sync_server.port}`;
|
|
@@ -17,8 +18,8 @@ class Manager {
|
|
|
17
18
|
this.server = options.server;
|
|
18
19
|
this.accounts = new Object();
|
|
19
20
|
|
|
20
|
-
this.oracle = new Oracle(this);
|
|
21
21
|
this.web = new Blockweb(this);
|
|
22
|
+
this.oracle = new Oracle(this);
|
|
22
23
|
|
|
23
24
|
this.repository = new Repository(this);
|
|
24
25
|
}
|
|
@@ -32,6 +33,7 @@ class Manager {
|
|
|
32
33
|
|
|
33
34
|
this.post_request = post_request;
|
|
34
35
|
|
|
36
|
+
await this.oracle.sync()
|
|
35
37
|
await this.repository.sync(this.name);
|
|
36
38
|
};
|
|
37
39
|
|
|
@@ -44,7 +46,13 @@ class Manager {
|
|
|
44
46
|
await account.sync();
|
|
45
47
|
|
|
46
48
|
this.accounts[name] = account;
|
|
49
|
+
|
|
50
|
+
return account;
|
|
47
51
|
};
|
|
52
|
+
|
|
53
|
+
get_account = name=>{
|
|
54
|
+
return this.accounts[name]
|
|
55
|
+
}
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
export default Manager;
|