godprotocol 1.0.842 → 1.1.0
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/Executables/callables.js +131 -0
- package/Executables/executables.js +230 -0
- package/Executables/functions/adminstrator/adm_register.js +29 -0
- package/Executables/functions/adminstrator/native_components.js +10 -0
- package/Executables/functions/adminstrator/query_selectors.js +10 -0
- package/Executables/functions/adminstrator/render.js +24 -0
- package/Executables/functions/array_register.js +161 -0
- package/Executables/functions/assign.js +19 -0
- package/Executables/functions/display.js +55 -0
- package/Executables/functions/folder.js +95 -0
- package/Executables/functions/folder_register.js +87 -0
- package/Executables/functions/importcheck.js +13 -0
- package/Executables/functions/indices.js +56 -0
- package/Executables/functions/len.js +22 -0
- package/Executables/functions/methods/array.js +272 -0
- package/Executables/functions/methods/string.js +197 -0
- package/Executables/functions/methods/twain.js +148 -0
- package/Executables/functions/op.js +15 -0
- package/Executables/functions/price_register.js +30 -0
- package/Executables/functions/pricing.js +26 -0
- package/Executables/functions/servers/account.js +81 -0
- package/Executables/functions/servers/account_register.js +56 -0
- package/Executables/functions/servers/block.js +21 -0
- package/Executables/functions/servers/block_register.js +18 -0
- package/Executables/functions/servers/chain.js +42 -0
- package/Executables/functions/servers/chain_register.js +28 -0
- package/Executables/functions/set_error_catch.js +34 -0
- package/Executables/functions/string_register.js +130 -0
- package/Executables/functions/twain_register.js +56 -0
- package/Executables/functions/typecast.js +43 -0
- package/Executables/functions/utils.js +9 -0
- package/Executables/stack.js +53 -0
- package/Index.js +2 -55
- package/Loader_sequence/main.js +371 -124
- package/Loader_sequence/repository.js +1 -1
- package/Objects/Account.js +101 -34
- package/Objects/Block.js +24 -18
- package/Objects/Blockweb.js +1 -1
- package/Objects/Chain.js +127 -29
- package/Objects/Explorer.js +3 -17
- package/Objects/Fee.js +33 -0
- package/Objects/Filesystem.js +98 -25
- package/Objects/Frame.js +10 -3
- package/Objects/Manager.js +193 -23
- package/Objects/Opcodes.js +48 -10
- package/Objects/Oracle.js +11 -8
- package/Objects/Protocol.js +5 -0
- package/Objects/Virtual_machine.js +130 -59
- package/Trinity.js +20 -0
- package/callables.js +172 -0
- package/framer.js +65 -12
- package/opcodes/add.js +6 -1
- package/opcodes/indices.js +60 -6
- package/opcodes/jmp.js +2 -0
- package/opcodes/std.js +5 -2
- package/opcodes.js +56 -18
- package/package.json +2 -2
- package/starter_scripts/constants.seq +11 -0
- package/utils/create_server.js +15 -7
- package/utils/hash.js +2 -2
- package/utils/logger.js +79 -0
- package/utils/services.js +5 -3
- package/utils/type_coersion.js +3 -0
- package/utils/vm_utils.js +292 -0
package/opcodes.js
CHANGED
|
@@ -1,29 +1,55 @@
|
|
|
1
1
|
// import { socket_send } from "./Socket";
|
|
2
|
+
import callables from "./callables";
|
|
2
3
|
import { ops } from "./opcodes/add";
|
|
3
|
-
import { getter, setter } from "./opcodes/indices";
|
|
4
|
+
import { del, getter, setter, slice } from "./opcodes/indices";
|
|
4
5
|
import { jmp } from "./opcodes/jmp";
|
|
5
6
|
import { stdout } from "./opcodes/std";
|
|
6
7
|
import { post_request } from "./utils/services";
|
|
7
8
|
|
|
8
9
|
const opcodes = (account) => {
|
|
10
|
+
callables(account)
|
|
11
|
+
|
|
9
12
|
let set = account.vm.set;
|
|
10
13
|
|
|
11
14
|
ops.map((op) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
if(op.jmp){
|
|
16
|
+
let flag = op.name
|
|
17
|
+
account.vm.flags[flag] = false
|
|
18
|
+
|
|
19
|
+
set(`jmp_${flag}`, (args, vm) => jmp(args, vm, { flag }));
|
|
20
|
+
set(`jmp_not_${flag}`, (args, vm) =>
|
|
21
|
+
jmp(args, vm, { flag, inverse: true })
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
set(op.name, (args) => {
|
|
26
|
+
if (!args) return;
|
|
27
|
+
try {
|
|
28
|
+
let {op0, op1}=args;
|
|
29
|
+
|
|
30
|
+
let type0 = op0.type
|
|
31
|
+
let type1 = op1.type
|
|
32
|
+
|
|
33
|
+
let val0 = op0.static_value;
|
|
34
|
+
let val1 = op1.static_value;
|
|
21
35
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
if(op.name ==='divide' && val1 === 0){
|
|
37
|
+
return account.vm.stderr({name:'Zero_division_error', message: 'Do not divide by zero'})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let result = eval(`val0 ${op.sign} val1`);
|
|
41
|
+
|
|
42
|
+
if (op.jmp) {
|
|
43
|
+
result = !!result;
|
|
44
|
+
account.vm.flags[op.name] = result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return result;
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.log("opcodes: ", e.message);
|
|
50
|
+
console.log(e)
|
|
51
|
+
}
|
|
52
|
+
});
|
|
27
53
|
});
|
|
28
54
|
|
|
29
55
|
Object.keys(account.vm.flags).map((flag) => {
|
|
@@ -34,24 +60,36 @@ const opcodes = (account) => {
|
|
|
34
60
|
});
|
|
35
61
|
set("jmp", jmp);
|
|
36
62
|
|
|
63
|
+
// Indices
|
|
37
64
|
set("setter", setter);
|
|
38
65
|
set("getter", getter);
|
|
66
|
+
set("del", del);
|
|
67
|
+
set("slice", slice);
|
|
39
68
|
|
|
40
69
|
set("send", (data) => post_request(data, account.vm.stdin));
|
|
41
70
|
// set("socket_send", socket_send);
|
|
42
71
|
|
|
43
72
|
set("stdout", stdout);
|
|
73
|
+
set("stdin",args=>account. vm.stdin(args&&args.op0));
|
|
74
|
+
|
|
75
|
+
/* Aliases */
|
|
76
|
+
set('quit', account.vm.quit)
|
|
77
|
+
set('exit', account.vm.quit)
|
|
78
|
+
|
|
79
|
+
set('ret', arg=>account.vm.quit(arg, 'ret'))
|
|
80
|
+
|
|
81
|
+
set('exec', account.vm.exec)
|
|
44
82
|
|
|
45
|
-
set(
|
|
83
|
+
set('config', account.vm.set_config)
|
|
46
84
|
|
|
47
85
|
set("add_server", (args) => account.add_server(args && args.op0));
|
|
48
86
|
|
|
49
87
|
["run", "load", "parse"].map((op) =>
|
|
50
|
-
set(op, (arg) => arg && arg.op0 && manager.endpoint(op, arg && arg.op0))
|
|
88
|
+
set(op, (arg) => arg && arg.op0 && account.manager.endpoint(op, arg && arg.op0))
|
|
51
89
|
);
|
|
52
90
|
|
|
53
91
|
set("add_account", (arg) =>
|
|
54
|
-
|
|
92
|
+
account. manager.add_account({ ...arg.op0, string: true })
|
|
55
93
|
);
|
|
56
94
|
};
|
|
57
95
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "godprotocol",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A data mediator.",
|
|
5
5
|
"main": "Index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"crypto": "^1.0.1",
|
|
47
47
|
"elliptic": "^6.5.5",
|
|
48
48
|
"fs": "^0.0.1-security",
|
|
49
|
-
"generalised-datastore": "^2.0.
|
|
49
|
+
"generalised-datastore": "^2.0.112"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"ignore": [
|
package/utils/create_server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import http from "http";
|
|
2
2
|
import { is_port_available } from "./functions";
|
|
3
3
|
|
|
4
|
-
let PORT = Number(process.env.PORT) ||
|
|
4
|
+
let PORT = Number(process.env.PORT) || 1408;
|
|
5
5
|
|
|
6
6
|
const cb = (res, data) => {
|
|
7
7
|
if (typeof data !== "string") data = JSON.stringify(data);
|
|
@@ -31,6 +31,18 @@ const handle_routes = (req, res, app, manager) => {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
req.on("end", () => {
|
|
34
|
+
if (req.method === 'GET'){
|
|
35
|
+
console.log(req.url)
|
|
36
|
+
if(req.url === '/' ){
|
|
37
|
+
res.writeHead(404, { "Content-Type": "text/html" });
|
|
38
|
+
res.end(`<h1>God Protocol</h1>`);
|
|
39
|
+
}
|
|
40
|
+
else if(req.url.startsWith('/Accounts') ){
|
|
41
|
+
manager.handle_route({req, res});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
34
46
|
try {
|
|
35
47
|
data = JSON.parse(data);
|
|
36
48
|
} catch (e) {
|
|
@@ -41,6 +53,7 @@ const handle_routes = (req, res, app, manager) => {
|
|
|
41
53
|
});
|
|
42
54
|
}
|
|
43
55
|
|
|
56
|
+
|
|
44
57
|
if (req.url === "/create_account") {
|
|
45
58
|
let account = manager.add_account(null, { ...data, string: true });
|
|
46
59
|
|
|
@@ -50,12 +63,7 @@ const handle_routes = (req, res, app, manager) => {
|
|
|
50
63
|
cb(res, datagram)
|
|
51
64
|
);
|
|
52
65
|
} else {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (typeof extension !== "function") {
|
|
56
|
-
res.writeHead(404, { "Content-Type": "application/json" });
|
|
57
|
-
res.end(JSON.stringify({ error: true, error_message: "Not Found" }));
|
|
58
|
-
} else extension(data, { req, res });
|
|
66
|
+
manager.handle_route({req,res, data})
|
|
59
67
|
}
|
|
60
68
|
});
|
|
61
69
|
|
package/utils/hash.js
CHANGED
package/utils/logger.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const blessed = require('blessed');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
// const screen = blessed.screen({
|
|
5
|
+
// smartCSR: true,
|
|
6
|
+
// title:'God Protocol'
|
|
7
|
+
// })
|
|
8
|
+
|
|
9
|
+
class Logger {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.log_boxes= new Array()
|
|
12
|
+
|
|
13
|
+
// this. clock_box = blessed.box({
|
|
14
|
+
// left: 'left',
|
|
15
|
+
// width: '100%',
|
|
16
|
+
// height: 'shrink',
|
|
17
|
+
// content: '',
|
|
18
|
+
// tags: true,
|
|
19
|
+
// border: {
|
|
20
|
+
// type: 'line'
|
|
21
|
+
// },
|
|
22
|
+
// style: {
|
|
23
|
+
// border: {
|
|
24
|
+
// fg: 'cyan'
|
|
25
|
+
// }
|
|
26
|
+
// }
|
|
27
|
+
// })
|
|
28
|
+
|
|
29
|
+
// screen.append(this.clock_box)
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
log=(data_logger)=> {
|
|
36
|
+
// this.clock_box.setContent(data_logger())
|
|
37
|
+
// this.update_log_box_positions()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
update_log_box_positions() {
|
|
42
|
+
// this.log_boxes.forEach((box, index) => {
|
|
43
|
+
// box.top = index;
|
|
44
|
+
// });
|
|
45
|
+
|
|
46
|
+
// this.clock_box.top = this.log_boxes.length;
|
|
47
|
+
// screen.render();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
store_log=(message)=> {
|
|
51
|
+
// const logBox = blessed.box({
|
|
52
|
+
// top: this.log_boxes.length,
|
|
53
|
+
// left: 'left',
|
|
54
|
+
// width: '100%',
|
|
55
|
+
// height: 3,
|
|
56
|
+
// content: message,
|
|
57
|
+
// tags: true,
|
|
58
|
+
// border: {
|
|
59
|
+
// type: 'line'
|
|
60
|
+
// },
|
|
61
|
+
// style: {
|
|
62
|
+
// border: {
|
|
63
|
+
// fg: 'green'
|
|
64
|
+
// }
|
|
65
|
+
// }
|
|
66
|
+
// });
|
|
67
|
+
|
|
68
|
+
// screen.append(logBox);
|
|
69
|
+
// this.log_boxes.push(logBox);
|
|
70
|
+
// this. update_log_box_positions();
|
|
71
|
+
// screen.render();
|
|
72
|
+
// console.log(message)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
export default Logger;
|
package/utils/services.js
CHANGED
|
@@ -12,13 +12,15 @@ const post_request = (payload, cb) => {
|
|
|
12
12
|
// },
|
|
13
13
|
// };
|
|
14
14
|
|
|
15
|
+
let data = typeof payload.data !== 'string' ? JSON.stringify(payload.data) : payload.data
|
|
16
|
+
|
|
15
17
|
let req = http.request(
|
|
16
18
|
{
|
|
17
19
|
...payload.options,
|
|
18
20
|
method: "POST",
|
|
19
21
|
headers: {
|
|
20
22
|
"Content-Type": "application/json",
|
|
21
|
-
"Content-Length": Buffer.byteLength(
|
|
23
|
+
"Content-Length": Buffer.byteLength(data),
|
|
22
24
|
},
|
|
23
25
|
},
|
|
24
26
|
(res) => {
|
|
@@ -37,11 +39,11 @@ const post_request = (payload, cb) => {
|
|
|
37
39
|
);
|
|
38
40
|
|
|
39
41
|
req.on("error", (e) => {
|
|
40
|
-
cb(e.message);
|
|
42
|
+
cb && cb(e.message);
|
|
41
43
|
console.error(`Problem with request: ${e.message}`);
|
|
42
44
|
});
|
|
43
45
|
|
|
44
|
-
req.write(
|
|
46
|
+
req.write(data);
|
|
45
47
|
|
|
46
48
|
req.end();
|
|
47
49
|
};
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { generate_random_string } from "generalised-datastore/utils/functions";
|
|
2
|
+
import Executables from "../Executables/executables";
|
|
3
|
+
|
|
4
|
+
class Vm_utils extends Executables{
|
|
5
|
+
constructor(){
|
|
6
|
+
super()
|
|
7
|
+
|
|
8
|
+
setTimeout(() => {
|
|
9
|
+
this. air_object_paths = new Array(
|
|
10
|
+
`${this.account.physical_address}/language/natives/datatypes/string/String`,
|
|
11
|
+
`${this.account.physical_address}/language/natives/datatypes/number/Number`,
|
|
12
|
+
`${this.account.physical_address}/language/natives/datatypes/twain/Twain`,
|
|
13
|
+
`${this.account.physical_address}/language/natives/datatypes/array/Array`,
|
|
14
|
+
`${this.account.physical_address}/language/natives/datatypes/boolean/Boolean`,
|
|
15
|
+
`${this.account.physical_address}/language/natives/datatypes/void/Void`,
|
|
16
|
+
`${this.account.physical_address}/language/natives/server/chain/Chain`,
|
|
17
|
+
`${this.account.physical_address}/language/natives/server/block/Block`,
|
|
18
|
+
`${this.account.physical_address}/language/natives/server/chain/Chain`,
|
|
19
|
+
)
|
|
20
|
+
}, 0);
|
|
21
|
+
|
|
22
|
+
this.error_instance_address = "Accounts/initiator/language/natives/errors"
|
|
23
|
+
|
|
24
|
+
this.air_types = new Array('boolean', 'string', 'twain', 'array', 'number', 'void')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
set_config = (config)=>{
|
|
28
|
+
config = config.op0;
|
|
29
|
+
let chain = this.handle_chain(config.__address__);
|
|
30
|
+
chain.set_obj_config(config)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get_context = (index) => {
|
|
34
|
+
return this.contexts.slice(index == null ? -1 : index)[0];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
parse_arg = (arg, opcode) => {
|
|
38
|
+
let context = this.get_context();
|
|
39
|
+
|
|
40
|
+
let args = arg.split("/"),
|
|
41
|
+
i = 0;
|
|
42
|
+
|
|
43
|
+
while (args[0] === "..") {
|
|
44
|
+
i++;
|
|
45
|
+
|
|
46
|
+
args.splice(0, 1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
i = (i + 1) * -1;
|
|
50
|
+
context = i ? this.get_context(i) : context;
|
|
51
|
+
|
|
52
|
+
arg = args.join("/");
|
|
53
|
+
|
|
54
|
+
while (arg.includes("^")) {
|
|
55
|
+
let blk = context.connections.slice(-1)[0];
|
|
56
|
+
if (!blk) break;
|
|
57
|
+
context = blk.chain;
|
|
58
|
+
let i = arg.indexOf("^");
|
|
59
|
+
arg = `${arg.slice(0, i)}${arg.slice(i + 1)}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let is_cursor = opcode === 'cursor'
|
|
63
|
+
if (arg.startsWith("{*") && is_cursor) {
|
|
64
|
+
arg = context.explore(arg.slice(2, -1));
|
|
65
|
+
} else if (arg.startsWith("{") && !is_cursor) {
|
|
66
|
+
arg = context.explore(arg.slice(1, -1));
|
|
67
|
+
if (['chain', 'link'].includes(opcode) && arg.includes('/')){
|
|
68
|
+
arg = this.account.read(arg)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return arg;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
split_instruction = (instruction) => {
|
|
76
|
+
let split = instruction.split(" ");
|
|
77
|
+
let opcode = split[0],
|
|
78
|
+
args = split.slice(1).join(" ");
|
|
79
|
+
|
|
80
|
+
return { opcode, args };
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
handle_chain = (args, context)=>{
|
|
84
|
+
if (!args) return
|
|
85
|
+
if(!context) context = this.account.chain
|
|
86
|
+
|
|
87
|
+
let web = context.account.manager.web, chain;
|
|
88
|
+
|
|
89
|
+
if (args.includes('/')){
|
|
90
|
+
chain = web.get(args)||web.split_set(args);
|
|
91
|
+
} else chain = context.account.add_chain(args, context);
|
|
92
|
+
|
|
93
|
+
return chain
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
read_chain = (addr, options)=>{
|
|
97
|
+
options = options || {}
|
|
98
|
+
let {no_callable, tell_callable, index} = options, callable;
|
|
99
|
+
|
|
100
|
+
if(!addr) return this.stderr(`Physical address cannot be undefined`)
|
|
101
|
+
let chn = addr.physical_address? addr: this.handle_chain(addr)
|
|
102
|
+
|
|
103
|
+
if (!chn)return this.stderr(`Address chain:${addr.physical_address ||addr} not found`)
|
|
104
|
+
|
|
105
|
+
let output;
|
|
106
|
+
if (chn.datapath && !no_callable){
|
|
107
|
+
output = chn.datapath
|
|
108
|
+
callable = true;
|
|
109
|
+
}else {
|
|
110
|
+
callable = false
|
|
111
|
+
if (!chn.height) return no_callable?null: this.stderr(`Chain has no height - ${addr.physical_address || addr}`)
|
|
112
|
+
|
|
113
|
+
let recent = chn.get_block(index)
|
|
114
|
+
|
|
115
|
+
output = recent.metadata.output;
|
|
116
|
+
|
|
117
|
+
if (!output)return;
|
|
118
|
+
}
|
|
119
|
+
output = this.account.read(output)
|
|
120
|
+
|
|
121
|
+
return tell_callable? {output, callable} :output;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
connect_block = block=>{
|
|
125
|
+
if(!block){
|
|
126
|
+
console.log(`Checkengine`)
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
let prev_context = this.get_context(-2);
|
|
130
|
+
if (prev_context) {
|
|
131
|
+
if(block.chain.datapath){
|
|
132
|
+
block.metadata.output = block.datapath
|
|
133
|
+
}
|
|
134
|
+
prev_context.pending_children.push(block);
|
|
135
|
+
prev_context.connections.push(block);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
get_type_address =type=>{
|
|
140
|
+
return this.air_object_paths.find(p=>p.includes(type))
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
parse_composite_content = (content, options)=>{
|
|
144
|
+
let {item_type, location} = options;
|
|
145
|
+
|
|
146
|
+
if (item_type === 'static_object'){
|
|
147
|
+
for (let c = 0; c< content.length; c++){
|
|
148
|
+
let cont = content[c]
|
|
149
|
+
let cont_addr = `${location}_${c}`
|
|
150
|
+
this.write_chain(cont, cont_addr)
|
|
151
|
+
content[c] = cont_addr;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return content;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
air_object = (content, options)=>{
|
|
159
|
+
let {location, callback, local_address, metadata} = options;
|
|
160
|
+
|
|
161
|
+
if (Array.isArray(content)){
|
|
162
|
+
content= this.parse_composite_content(content, options)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
let static_location = `${local_address || location}_${generate_random_string(8, 'alnum')}`
|
|
166
|
+
|
|
167
|
+
let statc = this.static_cast(content, static_location)
|
|
168
|
+
let type = typeof statc === 'string' ? 'void' : statc.type
|
|
169
|
+
|
|
170
|
+
this.stdin(statc,()=> this.exec({
|
|
171
|
+
executable: this.get_type_address(type),
|
|
172
|
+
location,
|
|
173
|
+
metadata:{callback, ...metadata},
|
|
174
|
+
arguments: {
|
|
175
|
+
argc:1,
|
|
176
|
+
argv:[{position: 0, address: static_location, name:'value'}]
|
|
177
|
+
}}),
|
|
178
|
+
{address: static_location}
|
|
179
|
+
)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
id_hash = (data)=>{
|
|
183
|
+
let res = this.account.manager.oracle.hash(data, 'sha-1')
|
|
184
|
+
if (!isNaN(Number(res[0]))){
|
|
185
|
+
res = `_${res}`
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return res;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
get_voided_block = ()=>{
|
|
192
|
+
if(!this.account.initiated)return
|
|
193
|
+
|
|
194
|
+
let Void = this.account.get_datatype_chain(`Void`)
|
|
195
|
+
this.flags.void = true;
|
|
196
|
+
return Void && Void.get_latest_block()
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
modify_twain = (twa, chain, config)=>{
|
|
200
|
+
|
|
201
|
+
if (twa.__index__){
|
|
202
|
+
if (typeof twa.__index__ === 'number') twa.__index__ = chain.height
|
|
203
|
+
else twa.__index__[config.name] = chain.height
|
|
204
|
+
}
|
|
205
|
+
return twa
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
slice_trace = (s)=>{
|
|
209
|
+
let s_length = this.stacktrace.length;
|
|
210
|
+
for(let i=0; i < s_length - s; i++ ) this.pop_context()
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
push_context = context => {
|
|
214
|
+
this.contexts.push(context)
|
|
215
|
+
this.stacktrace.push(context.physical_address)
|
|
216
|
+
// console.log(`>> Current Stack - ${context.physical_address}`)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
pop_context = () => {
|
|
220
|
+
let context = this.contexts.pop()
|
|
221
|
+
let addr = this.stacktrace.pop()
|
|
222
|
+
|
|
223
|
+
// console.log(`> Current Stack - ${this.contexts.slice(-1)[0].physical_address}`)
|
|
224
|
+
|
|
225
|
+
if(context && context.physical_address !== addr)
|
|
226
|
+
this.stderr(`Stack missalignment - ${context.physical_address} : ${addr}`)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
run_opcode = (arg_arr, opcode)=>{
|
|
231
|
+
let circ = this.opcodes[opcode]
|
|
232
|
+
|
|
233
|
+
if (!circ)return this.stderr(`Opcode:${opcode} not set`)
|
|
234
|
+
|
|
235
|
+
let arg = {}
|
|
236
|
+
arg_arr.map((a,i)=>{
|
|
237
|
+
arg[`op${i.toString()}`] = a
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
return circ(arg, this)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
static_cast = (content, addr)=>{
|
|
244
|
+
let res_obj = {}
|
|
245
|
+
let type = typeof content;
|
|
246
|
+
if(type === 'object' || type === 'undefined'){
|
|
247
|
+
if(content == null){
|
|
248
|
+
res_obj = "{'type':'void','static_value':Void,'__address__':'Accounts/initiator/Datatypes/Void'}"
|
|
249
|
+
}else if (Array.isArray(content)){
|
|
250
|
+
res_obj = {type:'array', static_value: content}
|
|
251
|
+
}else res_obj = {type:'twain', static_value: content}
|
|
252
|
+
}else {
|
|
253
|
+
res_obj = {type, static_value: content}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (addr && typeof res_obj !== 'string') {
|
|
257
|
+
res_obj.__address__ = addr
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return res_obj
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
is_readonly = (args)=>{
|
|
264
|
+
if (args.op1.startsWith('__') && args.op1.endsWith('__') && args.op1 !== '__'){
|
|
265
|
+
let val = args.op0[args.op1]
|
|
266
|
+
let chn = this.handle_chain(`${val}/.config`)
|
|
267
|
+
let recent = chn.get_latest_block()
|
|
268
|
+
let value;
|
|
269
|
+
if(recent){
|
|
270
|
+
value = recent.metadata.output;
|
|
271
|
+
value = this.account.read(value)
|
|
272
|
+
if (value && !['function', 'class'].includes(value.type)){
|
|
273
|
+
return this.stderr('Cannot delete `readonly` property')
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
static_value = (value, blow)=>{
|
|
280
|
+
if (value && value.__print__){
|
|
281
|
+
if(this.air_object_paths.includes(value.__classifier__)){
|
|
282
|
+
value = this.read_chain(value.value)
|
|
283
|
+
}else if (blow){
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return value
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export default Vm_utils
|