godprotocol 1.1.2 → 1.1.31
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 +100 -27
- package/Objects/Blockweb.js +15 -28
- package/Objects/Callable.js +240 -15
- package/Objects/Chain.js +197 -28
- package/Objects/Datatypes.js +620 -0
- package/Objects/Manager.js +11 -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 +360 -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/render.js +24 -0
- package/callables/functions/twain.js +11 -0
- package/callables/register.js +35 -7
- package/package.json +1 -1
- package/utils/create_server.js +61 -22
- 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
package/Datatypes/arr.js
CHANGED
|
@@ -1,10 +1,283 @@
|
|
|
1
1
|
import Storage from "./functions/storage";
|
|
2
2
|
|
|
3
3
|
class Arr extends Storage {
|
|
4
|
-
constructor(
|
|
5
|
-
super();
|
|
4
|
+
constructor(payload, manager) {
|
|
5
|
+
super(payload.config, manager);
|
|
6
6
|
|
|
7
|
-
this.
|
|
7
|
+
this.instance_object = payload;
|
|
8
|
+
this.value = payload.value
|
|
9
|
+
this.type = 'array'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
call = async (name, args, options={})=>{
|
|
13
|
+
let {config, chain} = options;
|
|
14
|
+
let result, other, me = await this.statics_()
|
|
15
|
+
|
|
16
|
+
other = args[0] && await args[0].statics_()
|
|
17
|
+
|
|
18
|
+
let spli = this.value.value.split('/');
|
|
19
|
+
let config_hash = spli.slice(-1)[0], store;
|
|
20
|
+
|
|
21
|
+
switch(name){
|
|
22
|
+
case 'push':
|
|
23
|
+
result = me.push( await this.account.vm.instance_address(other))
|
|
24
|
+
store = true;
|
|
25
|
+
|
|
26
|
+
break;
|
|
27
|
+
case 'length':
|
|
28
|
+
result = me.length;
|
|
29
|
+
break;
|
|
30
|
+
case 'pop':
|
|
31
|
+
if (other){
|
|
32
|
+
result = me.splice(other, 1)[0]
|
|
33
|
+
}else result = me.pop()
|
|
34
|
+
|
|
35
|
+
store= true
|
|
36
|
+
|
|
37
|
+
if(result){
|
|
38
|
+
result = {type:'address',value: result}
|
|
39
|
+
}
|
|
40
|
+
break
|
|
41
|
+
case 'extend':
|
|
42
|
+
result = me.push(...other)
|
|
43
|
+
store = true
|
|
44
|
+
|
|
45
|
+
break;
|
|
46
|
+
case 'slice':
|
|
47
|
+
let start = args[0] && await args[0].literal()
|
|
48
|
+
let end = args[1] && await args[1].literal()
|
|
49
|
+
|
|
50
|
+
let new_arr = me.slice(start, end)
|
|
51
|
+
result = new_arr
|
|
52
|
+
break;
|
|
53
|
+
case 'splice':
|
|
54
|
+
let spl_replacement = args[2] && await args[2].statics_()
|
|
55
|
+
if (spl_replacement){
|
|
56
|
+
result = me.splice(args[0] && await args[0].literal(), args[1] && await args[1].literal(), await await this.account.vm.instance_address(spl_replacement) )
|
|
57
|
+
}else result = me.splice(args[0] && await args[0].literal(), args[1] && await args[1].literal())
|
|
58
|
+
|
|
59
|
+
store = true;
|
|
60
|
+
break;
|
|
61
|
+
case 'replace':
|
|
62
|
+
me[await args[0].literal()] = await this.account.vm.instance_address(await args[1].statics_())
|
|
63
|
+
store = true;
|
|
64
|
+
break
|
|
65
|
+
case 'index':
|
|
66
|
+
let i = args[0] && await args[0].literal()
|
|
67
|
+
if (i< 0){
|
|
68
|
+
result = me.slice(i)[0]
|
|
69
|
+
}else result = me[i]
|
|
70
|
+
if (result)result = {type:'address', value: result}
|
|
71
|
+
else result = null
|
|
72
|
+
break;
|
|
73
|
+
case 'copy':
|
|
74
|
+
result = me;
|
|
75
|
+
break;
|
|
76
|
+
case 'deepcopy':
|
|
77
|
+
break;
|
|
78
|
+
case 'reverse':
|
|
79
|
+
me = [...me].reverse()
|
|
80
|
+
result = {type:'address', value: await this.account.vm.instance_address(this.instance_object)}
|
|
81
|
+
|
|
82
|
+
if (other){
|
|
83
|
+
store = true;
|
|
84
|
+
}else {
|
|
85
|
+
result = me
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
case "is_empty":
|
|
89
|
+
result = !me.length
|
|
90
|
+
break;
|
|
91
|
+
case 'clear':
|
|
92
|
+
me = []
|
|
93
|
+
store = true;
|
|
94
|
+
break;
|
|
95
|
+
case 'join':
|
|
96
|
+
let str_val = ''
|
|
97
|
+
let separator = (other && await args[0].literal()) || ','
|
|
98
|
+
for (let i=0; i< me.length; i++){
|
|
99
|
+
let item = me[i]
|
|
100
|
+
let val = await this.account.vm.cloth_object(item)
|
|
101
|
+
|
|
102
|
+
if (['number', 'string', 'void', 'boolean'].includes(val.type))str_val = `${str_val}${i ? separator: ''}${await val.literal()}`
|
|
103
|
+
}
|
|
104
|
+
result = str_val
|
|
105
|
+
break;
|
|
106
|
+
case 'repeat':
|
|
107
|
+
me = Array.from({ length: other? await args[0].literal(): 0 }, () => me).flat()
|
|
108
|
+
|
|
109
|
+
store = true;
|
|
110
|
+
result = me.length;
|
|
111
|
+
break;
|
|
112
|
+
case 'padstart':
|
|
113
|
+
let p_length = args[0] && await args[0].literal()
|
|
114
|
+
let value = args[1] && args[1]
|
|
115
|
+
if (me.length >= p_length){ me = me;
|
|
116
|
+
}else {
|
|
117
|
+
let padding = Array(p_length - me.length).fill(['array', 'twain'].includes(value && value.type) ? value.value.address : value.instance_object.address);
|
|
118
|
+
me = [...padding, ...me];
|
|
119
|
+
|
|
120
|
+
store = true;
|
|
121
|
+
}
|
|
122
|
+
result = {type:'address', value: await this.account.vm.instance_address(this.instance_object)}
|
|
123
|
+
|
|
124
|
+
break;
|
|
125
|
+
case 'padend':
|
|
126
|
+
let ps_length = args[0] && await args[0].literal()
|
|
127
|
+
let svalue = args[1] && args[1]
|
|
128
|
+
if (me.length >= ps_length) {me = me;
|
|
129
|
+
}else {
|
|
130
|
+
let spadding = Array(ps_length - me.length).fill(['array', 'twain'].includes(svalue && svalue.type) ? svalue.value.address : svalue.instance_object.address);
|
|
131
|
+
me = [...me, ...spadding];
|
|
132
|
+
|
|
133
|
+
store = true;
|
|
134
|
+
}
|
|
135
|
+
result = {type:'address', value: await this.account.vm.instance_address(this.instance_object)}
|
|
136
|
+
|
|
137
|
+
break;
|
|
138
|
+
case 'to_string':
|
|
139
|
+
let str = ''
|
|
140
|
+
if(other){
|
|
141
|
+
other = await args[0].literal()
|
|
142
|
+
}
|
|
143
|
+
for (let a=0; a< me.length; a++){
|
|
144
|
+
let item = me[a]
|
|
145
|
+
let val = await this.account.vm.cloth_object(item)
|
|
146
|
+
if (other === 'ascii'){
|
|
147
|
+
if (val.type!=='number'){
|
|
148
|
+
str = `${str}void`
|
|
149
|
+
}else {
|
|
150
|
+
val = await val.literal()
|
|
151
|
+
str = `${str}${String.fromCharCode(val)}`
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
result = str
|
|
156
|
+
break;
|
|
157
|
+
case 'map':
|
|
158
|
+
result = new Array()
|
|
159
|
+
for (let a=0; a< me.length; a++){
|
|
160
|
+
let item = me[a]
|
|
161
|
+
let res = await this.account.vm.execute({
|
|
162
|
+
type: 'call',
|
|
163
|
+
arguments: [
|
|
164
|
+
{type:'address', value: item},
|
|
165
|
+
{type: 'number', value: a, location: `${config.location}/${await this.account.manager.oracle.hash(a)}`}
|
|
166
|
+
],
|
|
167
|
+
identifier: args[0].value.address,
|
|
168
|
+
location: config.location,
|
|
169
|
+
}, {chain})
|
|
170
|
+
|
|
171
|
+
result[a] = res.type === 'instance' ? res.address : res.value
|
|
172
|
+
}
|
|
173
|
+
break;
|
|
174
|
+
case 'findindex':
|
|
175
|
+
for (let a=0; a< me.length; a++){
|
|
176
|
+
let item = me[a]
|
|
177
|
+
let res = await this.account.vm.execute({
|
|
178
|
+
type: 'call',
|
|
179
|
+
arguments: [
|
|
180
|
+
{type:'address', value: item},
|
|
181
|
+
{type: 'number', value: a, location: `${config.location}/${await this.account.manager.oracle.hash(a)}`}
|
|
182
|
+
],
|
|
183
|
+
identifier: args[0].value.address,
|
|
184
|
+
location: config.location,
|
|
185
|
+
}, {chain, cloth: true})
|
|
186
|
+
|
|
187
|
+
if(await res.literal()){
|
|
188
|
+
result = a
|
|
189
|
+
break
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (result == null)result = -1
|
|
193
|
+
break;
|
|
194
|
+
case 'find':
|
|
195
|
+
for (let a=0; a< me.length; a++){
|
|
196
|
+
let item = me[a]
|
|
197
|
+
let res = await this.account.vm.execute({
|
|
198
|
+
type: 'call',
|
|
199
|
+
arguments: [
|
|
200
|
+
{type:'address', value: item},
|
|
201
|
+
{type: 'number', value: a, location: `${config.location}/${await this.account.manager.oracle.hash(a)}`}
|
|
202
|
+
],
|
|
203
|
+
identifier: args[0].value.address,
|
|
204
|
+
location: config.location,
|
|
205
|
+
}, {chain, cloth: true})
|
|
206
|
+
|
|
207
|
+
if(await res.literal()){
|
|
208
|
+
result = {type:'address', value: res. type === 'instance'? res.address: res.value}
|
|
209
|
+
break
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
break;
|
|
213
|
+
case 'filter':
|
|
214
|
+
result = []
|
|
215
|
+
for (let a=0; a< me.length; a++){
|
|
216
|
+
let item = me[a]
|
|
217
|
+
let res = await this.account.vm.execute({
|
|
218
|
+
type: 'call',
|
|
219
|
+
arguments: [
|
|
220
|
+
{type:'address', value: item},
|
|
221
|
+
{type: 'number', value: a, location: `${config.location}/${await this.account.manager.oracle.hash(a)}`}
|
|
222
|
+
],
|
|
223
|
+
identifier: args[0].value.address,
|
|
224
|
+
location: config.location,
|
|
225
|
+
}, {chain, cloth: true})
|
|
226
|
+
|
|
227
|
+
if(await res.literal()){
|
|
228
|
+
result.push(item)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
break
|
|
232
|
+
case 'includes':
|
|
233
|
+
if(!['number', 'string', 'void', 'boolean'].includes(other.type)) result = false;
|
|
234
|
+
else {
|
|
235
|
+
let search = other? await args[0].literal(): null
|
|
236
|
+
if (!other)result = false;
|
|
237
|
+
else {
|
|
238
|
+
for (let a=0; a< me.length; a++){
|
|
239
|
+
let item = me[a]
|
|
240
|
+
let obj = await this.account.vm.cloth_object(item)
|
|
241
|
+
|
|
242
|
+
if(['array', 'twain'].includes(obj.type)){
|
|
243
|
+
result = false
|
|
244
|
+
}
|
|
245
|
+
else if(await obj.literal() === search){
|
|
246
|
+
result = true;
|
|
247
|
+
break
|
|
248
|
+
}else result = false
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
}
|
|
254
|
+
if(store){
|
|
255
|
+
await this.account.manager.oracle.write(spli.slice(0,-1).join('/'), {type: this.type, values: me}, {config_hash, config: true})
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return result
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
configs = (name)=>{
|
|
262
|
+
let conf = {push: {
|
|
263
|
+
parameters: [{name: 'item', position: 0}]
|
|
264
|
+
}}
|
|
265
|
+
|
|
266
|
+
return conf[name]
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
push = async({item})=>{
|
|
270
|
+
if (!item)return null;
|
|
271
|
+
|
|
272
|
+
let path = this.config.path;
|
|
273
|
+
|
|
274
|
+
this.value.push(item.to_static())
|
|
275
|
+
|
|
276
|
+
this.config.content = this.to_static()
|
|
277
|
+
|
|
278
|
+
await this.manager.oracle.fs.write(path, JSON.stringify(this.config))
|
|
279
|
+
|
|
280
|
+
return this.value.length;
|
|
8
281
|
}
|
|
9
282
|
}
|
|
10
283
|
|
package/Datatypes/bool.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import Storage from "./functions/storage";
|
|
2
2
|
|
|
3
3
|
class Bool extends Storage {
|
|
4
|
-
constructor(
|
|
5
|
-
super();
|
|
4
|
+
constructor(payload, account) {
|
|
5
|
+
super(payload.config, account);
|
|
6
6
|
|
|
7
|
-
this.
|
|
7
|
+
this.instance_object = payload.value;
|
|
8
|
+
this.value = JSON.parse(payload.value.value)
|
|
9
|
+
this.type = 'boolean'
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
12
|
|
package/Datatypes/callable.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import Storage from "./functions/storage";
|
|
2
2
|
|
|
3
3
|
class Callable extends Storage {
|
|
4
|
-
constructor(
|
|
5
|
-
super();
|
|
4
|
+
constructor(payload, account) {
|
|
5
|
+
super(payload.config, account);
|
|
6
6
|
|
|
7
|
-
this.value = value;
|
|
7
|
+
this.value = payload.value;
|
|
8
|
+
this.type = 'callable'
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
11
|
|
package/Datatypes/cls.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Storage from "./functions/storage";
|
|
2
|
+
|
|
3
|
+
class Cls extends Storage{
|
|
4
|
+
constructor(payload, account){
|
|
5
|
+
super(payload.config, account)
|
|
6
|
+
|
|
7
|
+
this.value = payload.value;
|
|
8
|
+
this.type = 'class'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
initiate = async({chain, class_chain, ass_chain})=>{
|
|
12
|
+
let config = this.value
|
|
13
|
+
let conf = this.config.content;
|
|
14
|
+
let vm = this.account.vm;
|
|
15
|
+
|
|
16
|
+
let obj = {__classifier__: config.identifier, __class_config__: this.config.path}
|
|
17
|
+
|
|
18
|
+
let storage_chain = await chain.chain(config.location)
|
|
19
|
+
let addr = await storage_chain.write(obj)
|
|
20
|
+
|
|
21
|
+
class_chain = await storage_chain.chain(config.identifier)
|
|
22
|
+
let ths = {object: addr, type: 'instance'}
|
|
23
|
+
await class_chain.write(ths)
|
|
24
|
+
console.log(obj, config)
|
|
25
|
+
|
|
26
|
+
if (conf.methods.__init__){
|
|
27
|
+
console.log(conf.methods)
|
|
28
|
+
|
|
29
|
+
await vm.execute({
|
|
30
|
+
type:'call',
|
|
31
|
+
identifier: `${config.identifier}/__init__`,
|
|
32
|
+
arguments: config.arguments,
|
|
33
|
+
object: addr,
|
|
34
|
+
}, {chain, ass_chain})
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
return ths
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default Cls
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import Arr from "./arr";
|
|
2
|
+
import Storage from "./functions/storage";
|
|
3
|
+
|
|
4
|
+
class Conf extends Storage{
|
|
5
|
+
constructor(object, account){
|
|
6
|
+
super(object, account)
|
|
7
|
+
|
|
8
|
+
this.value = object
|
|
9
|
+
this.type = 'config'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
persist = async()=>{
|
|
13
|
+
await this.manager.oracle.fs.write(`${this.value.path}/.config`, JSON.stringify(this.value))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
set_next = async(addr)=>{
|
|
17
|
+
this.value.next = addr;
|
|
18
|
+
|
|
19
|
+
await this.persist()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
history = async(query)=>{
|
|
23
|
+
let res = []
|
|
24
|
+
let arr, pure;
|
|
25
|
+
if (typeof query === 'number'){
|
|
26
|
+
if(query >= 0){}
|
|
27
|
+
else{
|
|
28
|
+
arr= []
|
|
29
|
+
let x=query
|
|
30
|
+
while (x < 0){
|
|
31
|
+
arr.push(x)
|
|
32
|
+
x++
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let i = 0;
|
|
38
|
+
let age = this.value.age;
|
|
39
|
+
|
|
40
|
+
while(i < arr.length){
|
|
41
|
+
let timestep = arr[i], my_age;
|
|
42
|
+
if (timestep < 0){
|
|
43
|
+
my_age = age + timestep + 1
|
|
44
|
+
}else {
|
|
45
|
+
my_age = timestep;
|
|
46
|
+
}
|
|
47
|
+
if (my_age > age)continue;
|
|
48
|
+
|
|
49
|
+
let config = await this.manager.oracle.fs.get_config(this.value.path, null, {age: my_age})
|
|
50
|
+
|
|
51
|
+
res.push(pure?config: await config.read())
|
|
52
|
+
i++
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return new Arr({value:res}, this.manager)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
read = async()=>{
|
|
59
|
+
let current = this.value.current;
|
|
60
|
+
if (!current)return
|
|
61
|
+
|
|
62
|
+
return await this.manager.oracle.fs.read_file(current)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
set_previous = async(addr)=>{
|
|
66
|
+
this.value.previous = addr;
|
|
67
|
+
|
|
68
|
+
await this.persist()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
push = async(parent)=>{
|
|
72
|
+
this.value.lapse++
|
|
73
|
+
|
|
74
|
+
await this.persist()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
link = async(addr)=>{
|
|
78
|
+
if (!addr )return;
|
|
79
|
+
|
|
80
|
+
console.log(this.value, addr)
|
|
81
|
+
if (this.value.current){
|
|
82
|
+
let conf = await this.manager.oracle.fs.get_config(this.value.current)
|
|
83
|
+
await conf.set_next(addr)
|
|
84
|
+
|
|
85
|
+
let addr_conf = await this.manager.oracle.fs.get_config(`${addr}`)
|
|
86
|
+
|
|
87
|
+
await addr_conf.set_previous(this.value.current)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.value.age++
|
|
91
|
+
this.value.current = addr;
|
|
92
|
+
await this.persist()
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default Conf
|
|
97
|
+
|
|
98
|
+
// test = [1,2,3]
|
|
99
|
+
// ./test
|
|
100
|
+
// ./0
|
|
101
|
+
// ./num1 {content:1, previous: null}
|
|
102
|
+
// ./config {recent: './num1'}
|
|
103
|
+
// ./1
|
|
104
|
+
// ./num2 {content:2, previous: null}
|
|
105
|
+
// ./config {recent: './num2'}
|
|
106
|
+
// ./2
|
|
107
|
+
// ./num3 {content:3, previous:.null}
|
|
108
|
+
// ./config {recent: './num3'}
|
|
109
|
+
|
|
110
|
+
// ./.config
|
|
111
|
+
// {type:'array', recent: './2'}
|
|
112
|
+
|
|
113
|
+
// test[1] = 4
|
|
114
|
+
// ./1
|
|
115
|
+
// ./num4 {content:4, previous: './num2'}
|
|
116
|
+
// ./config {recent: './num4'}
|
|
117
|
+
//
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Datatypes from "godprotocol/Objects/Datatypes";
|
|
2
|
+
|
|
3
|
+
class Func extends Datatypes{
|
|
4
|
+
constructor(payload, account){
|
|
5
|
+
super()
|
|
6
|
+
|
|
7
|
+
this.account = account
|
|
8
|
+
this.value = payload;
|
|
9
|
+
this.type = 'function'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
literal = ()=>{
|
|
13
|
+
return `[${this.value.value || this.value.name}]`
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
sync = async()=>{
|
|
17
|
+
return this
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export default Func
|
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
class Storage {
|
|
2
|
-
constructor() {
|
|
2
|
+
constructor(manager) {
|
|
3
|
+
this.manager = manager
|
|
4
|
+
this.oracle = this.manager.oracle
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
sync = async(manager)=>{
|
|
8
|
+
if (!this.manager){
|
|
9
|
+
this.manager = manager
|
|
10
|
+
this.oracle = this.manager.oracle
|
|
11
|
+
}
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
persist =async (content, options={})=>{
|
|
16
|
+
return await this.oracle.write(this.path, content, options)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
retrieve = async (options)=>{
|
|
20
|
+
return await this.oracle.read(this.path, options)
|
|
21
|
+
}
|
|
3
22
|
}
|
|
4
23
|
|
|
5
24
|
export default Storage;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import Datatypes from "godprotocol/Objects/Datatypes";
|
|
2
|
+
|
|
3
|
+
class Instance extends Datatypes{
|
|
4
|
+
constructor(payload, account){
|
|
5
|
+
super()
|
|
6
|
+
|
|
7
|
+
this.account = account
|
|
8
|
+
this.value = payload;
|
|
9
|
+
this.type = 'instance'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
operate = async(op, args, options={})=>{
|
|
13
|
+
let {classifier} = options;
|
|
14
|
+
let value;
|
|
15
|
+
switch(classifier){
|
|
16
|
+
case 'twain':
|
|
17
|
+
value = await this.twain(op, args, options)
|
|
18
|
+
break;
|
|
19
|
+
case 'number':
|
|
20
|
+
value = await this.number(op, args)
|
|
21
|
+
break;
|
|
22
|
+
case 'array':
|
|
23
|
+
value = await this.array(op, args, options)
|
|
24
|
+
break;
|
|
25
|
+
case 'string':
|
|
26
|
+
value = await this.string(op, args)
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
set = async(last, value)=>{
|
|
34
|
+
let prop = await last.literal()
|
|
35
|
+
let oracle = this.account.manager.oracle
|
|
36
|
+
let hsh = await oracle.hash(prop)
|
|
37
|
+
|
|
38
|
+
let {content, path} = this.value
|
|
39
|
+
|
|
40
|
+
let prop_path = `${path}/${hsh}`
|
|
41
|
+
await oracle.fs.mkdir(prop_path)
|
|
42
|
+
let prop_conf = await oracle.fs.read(`${prop_path}/.config`)
|
|
43
|
+
if (!prop_conf) prop_conf = {index: -1}
|
|
44
|
+
|
|
45
|
+
if (value.type !== 'address'){
|
|
46
|
+
value = {type: 'address', value: value.value.path}
|
|
47
|
+
}
|
|
48
|
+
await oracle.fs.write(`${prop_path}/${prop_conf.index + 1}`, JSON.stringify([last.value.path, value.value]))
|
|
49
|
+
prop_conf.index += 1
|
|
50
|
+
await oracle.fs.write(`${prop_path}/.config`, JSON.stringify(prop_conf))
|
|
51
|
+
content[hsh] = prop_conf.index
|
|
52
|
+
|
|
53
|
+
let path_conf = await oracle.fs.read(`${path}/.config`)
|
|
54
|
+
|
|
55
|
+
let n_hash = await oracle.hash(content)
|
|
56
|
+
await oracle.fs.write(`${path}/${n_hash}`, JSON.stringify({content, type: 'instance', previous: `${path}/${path_conf.current}`}))
|
|
57
|
+
path_conf.current = n_hash;
|
|
58
|
+
await oracle.fs.write(`${path}/.config`, JSON.stringify(path_conf))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get = async (prop, options={})=>{
|
|
62
|
+
let oracle = this.account.manager.oracle
|
|
63
|
+
let hsh = await oracle.hash(prop)
|
|
64
|
+
let {config, chain} = options;
|
|
65
|
+
let {content, path} = this.value, result;
|
|
66
|
+
|
|
67
|
+
let classifier = await oracle.hash('__classifier__')
|
|
68
|
+
let pair = await oracle.fs.read(`${path}/${classifier}/${content[classifier]}`);
|
|
69
|
+
let val = await oracle.fs.read(pair[1])
|
|
70
|
+
|
|
71
|
+
let is_datatype = this.account.vm.datatypes.includes(val)
|
|
72
|
+
|
|
73
|
+
if(Object.keys(content).includes(hsh)){
|
|
74
|
+
result = await oracle.fs.read(`${path}/${hsh}/${content[hsh]}`)
|
|
75
|
+
|
|
76
|
+
if (result){
|
|
77
|
+
let res = await oracle.fs.read(result[1])
|
|
78
|
+
if(!res) result = {type: 'address', value: result[1]}
|
|
79
|
+
else result = res
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
}else {
|
|
83
|
+
if (is_datatype){
|
|
84
|
+
let res = {
|
|
85
|
+
type:'address',
|
|
86
|
+
value: prop,
|
|
87
|
+
object: path
|
|
88
|
+
}
|
|
89
|
+
if(val === 'array' && typeof prop === 'number' && options.obj){
|
|
90
|
+
result = await this.operate('index', [options.obj], {classifier: val})
|
|
91
|
+
}else if (val === 'twain'){
|
|
92
|
+
if (!this.is_literal && options.obj){
|
|
93
|
+
result = await this.operate('get', [options.obj], {classifier: val})
|
|
94
|
+
result= await this.account.vm.operate_result(result, config, chain)
|
|
95
|
+
}else result = res
|
|
96
|
+
} else result = res
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
literal = async ()=>{
|
|
105
|
+
let oracle = this.account.manager.oracle;
|
|
106
|
+
if (!this.lit){
|
|
107
|
+
this.lit = {}
|
|
108
|
+
let {content, path} = this.value;
|
|
109
|
+
|
|
110
|
+
for (let hsh in content){
|
|
111
|
+
let value = content[hsh];
|
|
112
|
+
|
|
113
|
+
let addr = `${path}/${hsh}`;
|
|
114
|
+
let pair = await oracle.fs.read(`${addr}/${value}`);
|
|
115
|
+
let prop = await oracle.fs.read(pair[0])
|
|
116
|
+
let val = await oracle.fs.read(pair[1])
|
|
117
|
+
|
|
118
|
+
this.lit[prop] = val
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (this.lit.__classifier__ === 'twain'){
|
|
123
|
+
let vm = this.account.vm;
|
|
124
|
+
if(!this.lit.content_addr) this.lit.content_addr = {...this.lit.content}
|
|
125
|
+
|
|
126
|
+
for (let p in this.lit.content_addr){
|
|
127
|
+
let [prop, value] = this.lit.content_addr[p]
|
|
128
|
+
prop = await vm.cloth_content(await vm.resolve_address(prop))
|
|
129
|
+
value = await vm.cloth_content(await vm.resolve_address(value))
|
|
130
|
+
|
|
131
|
+
delete this.lit.content[p]
|
|
132
|
+
this.lit.content[await prop.literal()] = await value.literal()
|
|
133
|
+
}
|
|
134
|
+
}else if (this.lit.__classifier__ === 'array'){
|
|
135
|
+
let vm = this.account.vm;
|
|
136
|
+
|
|
137
|
+
if(!this.lit.content_addr)
|
|
138
|
+
this.lit.content_addr = [...this.lit.content]
|
|
139
|
+
for (let i=0; i< this.lit.content_addr.length; i++){
|
|
140
|
+
let item = this.lit.content_addr[i]
|
|
141
|
+
item = await vm.cloth_content(await vm.resolve_address(item))
|
|
142
|
+
|
|
143
|
+
this.lit.content[i] = await item.literal()
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
return this.lit.content;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
sync = async()=>{
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export default Instance
|