godprotocol 1.2.25 → 1.2.27
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/Objects/Account.js +162 -132
- package/Objects/Callable.js +197 -176
- package/Objects/Manager.js +9 -11
- package/Objects/Oracle.js +70 -283
- package/Objects/Virtual_machine.js +303 -263
- package/README.md +0 -0
- package/package.json +22 -15
- package/utils/vm_utils.js +162 -147
- package/repos/fs.js +0 -122
- package/repos/github.js +0 -185
- package/repos/ram.js +0 -47
package/Objects/Callable.js
CHANGED
|
@@ -10,17 +10,17 @@ class Callable extends Vm_utils {
|
|
|
10
10
|
parse_aircode = async (result, { config, chain, id }) => {
|
|
11
11
|
if (result == null) result = "void";
|
|
12
12
|
|
|
13
|
-
let loc = config && config.location.split("/").slice(2).join("/")
|
|
14
|
-
|
|
15
|
-
result = result ===
|
|
16
|
-
if (result ===
|
|
13
|
+
let loc = config && config.location.split("/").slice(2).join("/");
|
|
14
|
+
|
|
15
|
+
result = result === "void" ? result : JSON.stringify(result);
|
|
16
|
+
if (result === "void") return await this.voided();
|
|
17
17
|
|
|
18
18
|
let res = await this.account.compiler.to_sequence(
|
|
19
19
|
result,
|
|
20
20
|
!loc ? "CONSTANTS" : loc
|
|
21
|
-
)
|
|
21
|
+
);
|
|
22
22
|
res = res[0].body[0];
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
await chain.add_config(res);
|
|
25
25
|
result = await this.execute(res, { chain, id });
|
|
26
26
|
|
|
@@ -28,177 +28,195 @@ class Callable extends Vm_utils {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
instantiate = async (config, { chain, value, _id }) => {
|
|
31
|
-
let chn = await chain.chain(config.location)
|
|
32
|
-
let folder = await chn.folder()
|
|
31
|
+
let chn = await chain.chain(config.location);
|
|
32
|
+
let folder = await chn.folder();
|
|
33
33
|
|
|
34
|
-
if ([
|
|
35
|
-
let res = await this.statics(config)
|
|
34
|
+
if (["void", "boolean"].includes(config.type)) {
|
|
35
|
+
let res = await this.statics(config);
|
|
36
36
|
return res;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
let obj = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
} else if (config.type ===
|
|
52
|
-
res = await folder.write(obj)
|
|
53
|
-
obj._id = res._id
|
|
54
|
-
obj.created = res.created
|
|
55
|
-
|
|
56
|
-
if (value){
|
|
57
|
-
let val_obj = await this.cloth(value)
|
|
58
|
-
let obj_obj = await this.cloth_content(obj)
|
|
59
|
-
obj_obj.address = folder.address
|
|
60
|
-
await obj_obj.extend(val_obj)
|
|
61
|
-
}else {
|
|
62
|
-
for (let key in config.value){
|
|
63
|
-
let [prop, value] = config.value[key]
|
|
64
|
-
if(typeof prop ===
|
|
65
|
-
prop = await this.execute(await this.read_config(prop), {chain})
|
|
40
|
+
_id,
|
|
41
|
+
type: config.type,
|
|
42
|
+
created: Date.now(),
|
|
43
|
+
location: folder.address,
|
|
44
|
+
},
|
|
45
|
+
res;
|
|
46
|
+
|
|
47
|
+
if (config.type === "error") {
|
|
48
|
+
obj.value = config.payload;
|
|
49
|
+
res = await folder.write(obj);
|
|
50
|
+
obj._id = res._id;
|
|
51
|
+
} else if (config.type === "twain") {
|
|
52
|
+
res = await folder.write(obj);
|
|
53
|
+
obj._id = res._id;
|
|
54
|
+
obj.created = res.created;
|
|
55
|
+
|
|
56
|
+
if (value) {
|
|
57
|
+
let val_obj = await this.cloth(value);
|
|
58
|
+
let obj_obj = await this.cloth_content(obj);
|
|
59
|
+
obj_obj.address = folder.address;
|
|
60
|
+
await obj_obj.extend(val_obj);
|
|
61
|
+
} else {
|
|
62
|
+
for (let key in config.value) {
|
|
63
|
+
let [prop, value] = config.value[key];
|
|
64
|
+
if (typeof prop === "string") {
|
|
65
|
+
prop = await this.execute(await this.read_config(prop), { chain });
|
|
66
66
|
}
|
|
67
|
-
if(typeof value ===
|
|
68
|
-
value = await this.execute(await this.read_config(value), {
|
|
67
|
+
if (typeof value === "string") {
|
|
68
|
+
value = await this.execute(await this.read_config(value), {
|
|
69
|
+
chain,
|
|
70
|
+
});
|
|
69
71
|
}
|
|
70
|
-
await chn.set({twa: obj, key, prop, value})
|
|
72
|
+
await chn.set({ twa: obj, key, prop, value });
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
|
-
|
|
74
|
-
res = await folder.write(obj, {replace: true})
|
|
75
|
-
}else if (config.type ===
|
|
76
|
-
obj.length = 0
|
|
77
|
-
|
|
78
|
-
res = await folder.write(obj)
|
|
79
|
-
obj._id = res._id
|
|
80
|
-
obj.created = res.created
|
|
81
|
-
|
|
82
|
-
if (value){
|
|
83
|
-
let val_obj = await this.cloth(value)
|
|
84
|
-
let obj_obj = await this.cloth_content(obj)
|
|
85
|
-
obj_obj.address = folder.address
|
|
86
|
-
await obj_obj.extend(val_obj)
|
|
87
|
-
}else {
|
|
88
|
-
for (let i =0; i < config.value.length; i++){
|
|
89
|
-
let item = config.value[i]
|
|
90
|
-
if (typeof item ===
|
|
91
|
-
item = await this.execute(await this.read_config(item), {chain})
|
|
75
|
+
|
|
76
|
+
res = await folder.write(obj, { replace: true });
|
|
77
|
+
} else if (config.type === "array") {
|
|
78
|
+
obj.length = 0;
|
|
79
|
+
|
|
80
|
+
res = await folder.write(obj);
|
|
81
|
+
obj._id = res._id;
|
|
82
|
+
obj.created = res.created;
|
|
83
|
+
|
|
84
|
+
if (value) {
|
|
85
|
+
let val_obj = await this.cloth(value);
|
|
86
|
+
let obj_obj = await this.cloth_content(obj);
|
|
87
|
+
obj_obj.address = folder.address;
|
|
88
|
+
await obj_obj.extend(val_obj);
|
|
89
|
+
} else {
|
|
90
|
+
for (let i = 0; i < config.value.length; i++) {
|
|
91
|
+
let item = config.value[i];
|
|
92
|
+
if (typeof item === "string") {
|
|
93
|
+
item = await this.execute(await this.read_config(item), { chain });
|
|
92
94
|
}
|
|
93
|
-
await chn.insert({arr: obj, item, index: obj.length})
|
|
95
|
+
await chn.insert({ arr: obj, item, index: obj.length });
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
|
-
|
|
97
|
-
res = await folder.write(obj, {replace: true})
|
|
98
|
-
}else if ([
|
|
99
|
-
if (value){
|
|
100
|
-
folder = await this.account.manager.ds.folder(value.value)
|
|
101
|
-
obj._id = value._id
|
|
102
|
-
}else {
|
|
103
|
-
obj.value = config.value
|
|
104
|
-
res = await folder.write(obj)
|
|
105
|
-
obj._id = res._id
|
|
106
|
-
obj.created = res.created
|
|
107
|
-
obj.address = folder.address
|
|
108
|
-
}
|
|
98
|
+
|
|
99
|
+
res = await folder.write(obj, { replace: true });
|
|
100
|
+
} else if (["string", "number", "void", "boolean"].includes(config.type)) {
|
|
101
|
+
if (value) {
|
|
102
|
+
folder = await this.account.manager.ds.folder(value.value);
|
|
103
|
+
obj._id = value._id;
|
|
104
|
+
} else {
|
|
105
|
+
obj.value = config.value;
|
|
106
|
+
res = await folder.write(obj);
|
|
107
|
+
obj._id = res._id;
|
|
108
|
+
obj.created = res.created;
|
|
109
|
+
obj.address = folder.address;
|
|
110
|
+
}
|
|
109
111
|
}
|
|
110
112
|
res = {
|
|
111
113
|
value: folder.address,
|
|
112
|
-
type:
|
|
113
|
-
_id: obj._id
|
|
114
|
-
}
|
|
114
|
+
type: "address",
|
|
115
|
+
_id: obj._id,
|
|
116
|
+
};
|
|
115
117
|
|
|
116
|
-
return res
|
|
118
|
+
return res;
|
|
117
119
|
};
|
|
118
120
|
|
|
119
|
-
callable_address = async (config, o)=>{
|
|
120
|
-
let obj = await this.cloth_content(config)
|
|
121
|
-
obj.address = config.address
|
|
121
|
+
callable_address = async (config, o) => {
|
|
122
|
+
let obj = await this.cloth_content(config);
|
|
123
|
+
obj.address = config.address;
|
|
124
|
+
|
|
125
|
+
return o ? obj : await obj.to_address();
|
|
126
|
+
};
|
|
122
127
|
|
|
123
|
-
return o ? obj : await obj.to_address()
|
|
124
|
-
}
|
|
125
|
-
|
|
126
128
|
execute_call = async (call_config, { chain, thread }) => {
|
|
127
129
|
let result;
|
|
128
|
-
let {identifier, arguments: args, location} = call_config
|
|
129
|
-
|
|
130
|
-
if (location){
|
|
131
|
-
location = await chain.chain(location)
|
|
130
|
+
let { identifier, arguments: args, location } = call_config;
|
|
131
|
+
|
|
132
|
+
if (location) {
|
|
133
|
+
location = await chain.chain(location);
|
|
132
134
|
}
|
|
133
135
|
|
|
134
|
-
if (identifier.type ===
|
|
136
|
+
if (identifier.type === "address") {
|
|
135
137
|
// If call is a reference, such as to a class method
|
|
136
|
-
let {object, value, config: is_config} = identifier
|
|
137
|
-
if (object){
|
|
138
|
-
let spl = this._split_datapath(object)
|
|
139
|
-
let obj = {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
138
|
+
let { object, value, config: is_config } = identifier;
|
|
139
|
+
if (object) {
|
|
140
|
+
let spl = this._split_datapath(object);
|
|
141
|
+
let obj = {
|
|
142
|
+
value: spl[0],
|
|
143
|
+
_id: spl[1],
|
|
144
|
+
type: "address",
|
|
145
|
+
config: is_config,
|
|
146
|
+
};
|
|
147
|
+
obj = await this.cloth(obj);
|
|
148
|
+
|
|
149
|
+
if (value.includes("/")) {
|
|
150
|
+
await obj.run(call_config, { thread, chain });
|
|
151
|
+
} else {
|
|
152
|
+
result = await obj.call(value, { chain, call_config, thread });
|
|
146
153
|
}
|
|
147
|
-
}else {
|
|
148
|
-
let obj = await this.cloth(identifier)
|
|
149
|
-
if ([
|
|
150
|
-
|
|
151
|
-
|
|
154
|
+
} else {
|
|
155
|
+
let obj = await this.cloth(identifier);
|
|
156
|
+
if (["class", "function", "instance"].includes(obj.type)) {
|
|
157
|
+
} else
|
|
158
|
+
result = await this.throw_error({
|
|
159
|
+
type: "TypeError",
|
|
160
|
+
message: `type ${obj.type} is not callable.`,
|
|
161
|
+
});
|
|
152
162
|
}
|
|
153
|
-
} else if ([
|
|
154
|
-
let call = await this.cloth(identifier)
|
|
155
|
-
await call.invoke(args, {chain, call_config, thread})
|
|
156
|
-
} else if (identifier.includes(
|
|
163
|
+
} else if (["function", "class"].includes(identifier.type)) {
|
|
164
|
+
let call = await this.cloth(identifier);
|
|
165
|
+
await call.invoke(args, { chain, call_config, thread });
|
|
166
|
+
} else if (identifier.includes("/")) {
|
|
157
167
|
// If call is a user-defined address
|
|
158
|
-
let folder = await this.account.manager.ds.folder(identifier)
|
|
159
|
-
let payload = await folder.readone()
|
|
160
|
-
|
|
161
|
-
if (payload.object){
|
|
162
|
-
result = await this.execute_call(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
await
|
|
168
|
+
let folder = await this.account.manager.ds.folder(identifier);
|
|
169
|
+
let payload = await folder.readone();
|
|
170
|
+
|
|
171
|
+
if (payload.object) {
|
|
172
|
+
result = await this.execute_call(
|
|
173
|
+
{ ...call_config, identifier: payload },
|
|
174
|
+
{ chain, thread }
|
|
175
|
+
);
|
|
176
|
+
} else {
|
|
177
|
+
if (payload.config && payload._id === payload.value) {
|
|
178
|
+
result = await this.execute_call(
|
|
179
|
+
{ ...call_config, identifier: payload._id },
|
|
180
|
+
{ chain, thread }
|
|
181
|
+
);
|
|
182
|
+
} else {
|
|
183
|
+
let call = await this.cloth(payload);
|
|
184
|
+
await call.invoke(args, { chain, call_config, thread });
|
|
169
185
|
}
|
|
170
186
|
}
|
|
171
|
-
} else if (this.datatypes.includes(identifier)){
|
|
187
|
+
} else if (this.datatypes.includes(identifier)) {
|
|
172
188
|
// If call is Datatype instantiation
|
|
173
|
-
|
|
174
|
-
let _id = call_config.arguments.find(p=>p.identifier ===
|
|
175
|
-
if (_id){
|
|
176
|
-
delete _id.identifier
|
|
177
|
-
_id = await this.cloth({..._id})
|
|
178
|
-
if (_id.type ===
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
189
|
+
|
|
190
|
+
let _id = call_config.arguments.find((p) => p.identifier === "_id");
|
|
191
|
+
if (_id) {
|
|
192
|
+
delete _id.identifier;
|
|
193
|
+
_id = await this.cloth({ ..._id });
|
|
194
|
+
if (_id.type === "string") _id = await this.hash(await _id.literal());
|
|
195
|
+
else _id = null;
|
|
196
|
+
} else _id = null;
|
|
197
|
+
let val = call_config.arguments.find((p) => p.identifier === "value");
|
|
198
|
+
val = (val && val.value) || call_config.arguments[0];
|
|
199
|
+
result = await this.instantiate(
|
|
200
|
+
{ type: identifier, location: call_config.location },
|
|
201
|
+
{ chain, _id, value: val }
|
|
202
|
+
);
|
|
203
|
+
} else if (this.err_objects.includes(identifier)) {
|
|
204
|
+
let message = await (await this.cloth(args[0])).literal();
|
|
205
|
+
result = await this.throw_error({ message, type: identifier });
|
|
188
206
|
} else {
|
|
189
207
|
// If call is a reserved word.
|
|
190
208
|
|
|
191
|
-
let call = await this.callable(identifier)
|
|
192
|
-
let {callable, config} = call;
|
|
193
|
-
let data = {}
|
|
209
|
+
let call = await this.callable(identifier);
|
|
210
|
+
let { callable, config } = call;
|
|
211
|
+
let data = {};
|
|
194
212
|
for (let a = 0; a < args.length; a++) {
|
|
195
213
|
let param;
|
|
196
214
|
let arg = args[a];
|
|
197
|
-
|
|
198
|
-
if (arg.identifier)
|
|
199
|
-
param = config.parameters.find(p=>p.name === arg.identifier)
|
|
200
|
-
|
|
201
|
-
if(!param) {
|
|
215
|
+
|
|
216
|
+
if (arg.identifier)
|
|
217
|
+
param = config.parameters.find((p) => p.name === arg.identifier);
|
|
218
|
+
|
|
219
|
+
if (!param) {
|
|
202
220
|
param = config.parameters[arg.position || a];
|
|
203
221
|
if (!param) {
|
|
204
222
|
let lst_param = config.parameters.slice(-1)[0];
|
|
@@ -207,8 +225,8 @@ class Callable extends Vm_utils {
|
|
|
207
225
|
}
|
|
208
226
|
|
|
209
227
|
let res = await this.cloth(arg);
|
|
210
|
-
|
|
211
|
-
if (param){
|
|
228
|
+
|
|
229
|
+
if (param) {
|
|
212
230
|
if (param.spread) {
|
|
213
231
|
let arr = data[param.name];
|
|
214
232
|
if (!arr) {
|
|
@@ -219,16 +237,16 @@ class Callable extends Vm_utils {
|
|
|
219
237
|
} else data[param.name] = res;
|
|
220
238
|
}
|
|
221
239
|
}
|
|
222
|
-
|
|
223
|
-
result = await callable(data, {vm: this, call_config, chain, thread})
|
|
224
|
-
|
|
225
|
-
if(
|
|
226
|
-
result = await this.voided()
|
|
227
|
-
} else if(identifier ===
|
|
228
|
-
}else if ([
|
|
229
|
-
result = await result.to_address()
|
|
230
|
-
} else if(result && [
|
|
231
|
-
} else {
|
|
240
|
+
|
|
241
|
+
result = await callable(data, { vm: this, call_config, chain, thread });
|
|
242
|
+
|
|
243
|
+
if (["store", "net"].includes(identifier)) {
|
|
244
|
+
result = await this.voided();
|
|
245
|
+
} else if (identifier === "parse" && result) {
|
|
246
|
+
} else if (["Twain", "folder"].includes(identifier)) {
|
|
247
|
+
result = await result.to_address();
|
|
248
|
+
} else if (result && ["address", "function"].includes(result.type)) {
|
|
249
|
+
} else {
|
|
232
250
|
result = await this.parse_aircode(result, {
|
|
233
251
|
config: call_config,
|
|
234
252
|
chain,
|
|
@@ -239,25 +257,30 @@ class Callable extends Vm_utils {
|
|
|
239
257
|
return result;
|
|
240
258
|
};
|
|
241
259
|
|
|
242
|
-
resolve_import = async(config, chain)=>{
|
|
260
|
+
resolve_import = async (config, chain) => {
|
|
243
261
|
let addr = this.resolve_addr(config.address),
|
|
244
262
|
oracle = this.account.manager.oracle;
|
|
245
263
|
|
|
246
|
-
for (let i=0; i< config.identifiers.length; i++){
|
|
247
|
-
let id = config.identifiers[i]
|
|
248
|
-
|
|
249
|
-
let conf = await oracle.read(`${oracle.manager.path}/${addr}/${id}`, {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
type:
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
264
|
+
for (let i = 0; i < config.identifiers.length; i++) {
|
|
265
|
+
let id = config.identifiers[i];
|
|
266
|
+
|
|
267
|
+
let conf = await oracle.read(`${oracle.manager.path}/${addr}/${id}`, {
|
|
268
|
+
config: true,
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
await this.execute(
|
|
272
|
+
{
|
|
273
|
+
type: "assignment",
|
|
274
|
+
identifier: id,
|
|
275
|
+
value: {
|
|
276
|
+
type: "address",
|
|
277
|
+
value: conf.path,
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
{ chain }
|
|
281
|
+
);
|
|
259
282
|
}
|
|
260
|
-
}
|
|
283
|
+
};
|
|
261
284
|
|
|
262
285
|
callable = async (name) => {
|
|
263
286
|
let object = this.objects[name];
|
|
@@ -269,32 +292,30 @@ class Callable extends Vm_utils {
|
|
|
269
292
|
this.objects[name] = config;
|
|
270
293
|
};
|
|
271
294
|
|
|
272
|
-
native_components = async (config, {chain, object}) => {
|
|
295
|
+
native_components = async (config, { chain, object }) => {
|
|
273
296
|
let props = await this.execute(config.props, { chain, cloth: true });
|
|
274
297
|
let children = new Array();
|
|
275
298
|
for (let c = 0; c < config.children.length; c++) {
|
|
276
299
|
let child = config.children[c];
|
|
277
300
|
|
|
278
301
|
let res = await this.execute(child, { chain, cloth: true, object });
|
|
279
|
-
children.push(await res.literal({adm:true}));
|
|
302
|
+
children.push(await res.literal({ adm: true }));
|
|
280
303
|
}
|
|
281
304
|
|
|
282
305
|
let obj = {
|
|
283
306
|
name: config.name,
|
|
284
|
-
props: await props.literal({adm:true}),
|
|
307
|
+
props: await props.literal({ adm: true }),
|
|
285
308
|
children,
|
|
286
309
|
_id: props.config._id,
|
|
287
|
-
path: props.path
|
|
310
|
+
path: props.path,
|
|
288
311
|
};
|
|
289
312
|
|
|
290
|
-
let result = await this.parse_aircode(obj, {config, chain})
|
|
313
|
+
let result = await this.parse_aircode(obj, { config, chain });
|
|
291
314
|
|
|
292
315
|
return result;
|
|
293
316
|
};
|
|
294
317
|
|
|
295
|
-
rerender = async(object)=>{
|
|
296
|
-
|
|
297
|
-
}
|
|
318
|
+
rerender = async (object) => {};
|
|
298
319
|
}
|
|
299
320
|
|
|
300
321
|
export default Callable;
|
package/Objects/Manager.js
CHANGED
|
@@ -372,22 +372,20 @@ class Manager {
|
|
|
372
372
|
app: this.options.app,
|
|
373
373
|
});
|
|
374
374
|
|
|
375
|
-
this.handler = (req, res, cb) => {
|
|
375
|
+
this.handler = async (req, res, cb) => {
|
|
376
376
|
handle(req, res);
|
|
377
377
|
|
|
378
378
|
if (this.options.oracle && !this.served) {
|
|
379
379
|
this.served = true;
|
|
380
380
|
this.oracle = this.options.oracle;
|
|
381
|
-
this.
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
});
|
|
381
|
+
if (this.options.init_account) {
|
|
382
|
+
await this.add_account(this.options.init_account.name, {
|
|
383
|
+
password: this.options.init_account.password,
|
|
384
|
+
init: true,
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
cb && cb();
|
|
388
|
+
}
|
|
391
389
|
}
|
|
392
390
|
};
|
|
393
391
|
}
|