godprotocol 1.0.796 → 1.0.798
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/.babelrc +3 -0
- package/Index.js +8 -21
- package/Loader_sequence/main.js +259 -358
- package/Objects/Account.js +178 -337
- package/Objects/Block.js +53 -58
- package/Objects/Blockweb.js +27 -34
- package/Objects/Chain.js +115 -118
- package/Objects/Explorer.js +30 -37
- package/Objects/Filesystem.js +95 -80
- package/Objects/Frame.js +43 -48
- package/Objects/Manager.js +68 -77
- package/Objects/Opcodes.js +32 -97
- package/Objects/Oracle.js +23 -39
- package/Objects/Virtual_machine.js +125 -261
- package/build/Account.js +162 -0
- package/build/Block.js +65 -0
- package/build/Blockweb.js +36 -0
- package/build/Chain.js +119 -0
- package/build/Explorer.js +47 -0
- package/build/Filesystem.js +127 -0
- package/build/Frame.js +52 -0
- package/build/Index.js +15 -0
- package/build/Manager.js +99 -0
- package/build/Opcodes.js +39 -0
- package/build/Oracle.js +42 -0
- package/build/Virtual_machine.js +128 -0
- package/build/add.js +41 -0
- package/build/create_server.js +119 -0
- package/build/framer.js +57 -0
- package/build/functions.js +82 -0
- package/build/hash.js +14 -0
- package/build/jmp.js +19 -0
- package/build/main.js +283 -0
- package/build/opcodes.js +42 -0
- package/build/privacy.js +27 -0
- package/build/services.js +50 -0
- package/build/std.js +11 -0
- package/framer.js +39 -31
- package/opcodes/add.js +14 -40
- package/opcodes/jmp.js +10 -14
- package/opcodes/std.js +5 -9
- package/opcodes.js +25 -29
- package/package.json +3 -3
- package/readme.md +71 -95
- package/types/Account.d.ts +73 -0
- package/types/Block.d.ts +22 -0
- package/types/Blockweb.d.ts +14 -0
- package/types/Chain.d.ts +35 -0
- package/types/Explorer.d.ts +9 -0
- package/types/Filesystem.d.ts +23 -0
- package/types/Frame.d.ts +14 -0
- package/types/Manager.d.ts +21 -0
- package/types/Opcodes.d.ts +11 -0
- package/types/Oracle.d.ts +17 -0
- package/types/Virtual_machine.d.ts +20 -0
- package/types/index.d.ts +4 -0
- package/utils/create_server.js +65 -622
- package/utils/functions.js +31 -43
- package/utils/hash.js +10 -11
- package/utils/privacy.js +10 -15
- package/utils/services.js +32 -33
package/Objects/Frame.js
CHANGED
|
@@ -1,52 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var Frame = /*#__PURE__*/_createClass(function Frame(_object, parent) {
|
|
22
|
-
var _this = this;
|
|
23
|
-
_classCallCheck(this, Frame);
|
|
24
|
-
_defineProperty(this, "frame", function (object) {
|
|
25
|
-
var frame = new Frame(object, _this);
|
|
26
|
-
_this.instructions.push(frame);
|
|
27
|
-
_this.children.push(frame);
|
|
1
|
+
import { array_to_nested_objects } from "../utils/functions";
|
|
2
|
+
|
|
3
|
+
class Frame {
|
|
4
|
+
constructor(object, parent) {
|
|
5
|
+
this.parent = parent;
|
|
6
|
+
|
|
7
|
+
this.object = Array.isArray(object)
|
|
8
|
+
? array_to_nested_objects(object)
|
|
9
|
+
: object;
|
|
10
|
+
|
|
11
|
+
this.children = new Array();
|
|
12
|
+
this.instructions = new Array();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
frame = (object) => {
|
|
16
|
+
let frame = new Frame(object, this);
|
|
17
|
+
|
|
18
|
+
this.instructions.push(frame);
|
|
19
|
+
this.children.push(frame);
|
|
20
|
+
|
|
28
21
|
return frame;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
to_instruction = () => {
|
|
25
|
+
for (let prop in this.object) {
|
|
26
|
+
let val = this.object[prop];
|
|
27
|
+
this.instructions.push(`chain ${prop}`);
|
|
28
|
+
|
|
29
|
+
val && this.frame(val).to_instruction();
|
|
30
|
+
|
|
31
|
+
this.instructions.push(`pop ${prop}`);
|
|
36
32
|
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
flatten_instructions = () => {
|
|
36
|
+
let inss = new Array();
|
|
37
|
+
|
|
38
|
+
for (let i = 0; i < this.instructions.length; i++) {
|
|
39
|
+
let ins = this.instructions[i];
|
|
40
|
+
if (ins instanceof Frame) inss.push(...ins.flatten_instructions());
|
|
41
|
+
else inss.push(ins);
|
|
43
42
|
}
|
|
44
43
|
return inss;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.instructions = new Array();
|
|
50
|
-
});
|
|
51
|
-
var _default = Frame;
|
|
52
|
-
exports["default"] = _default;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default Frame;
|
package/Objects/Manager.js
CHANGED
|
@@ -1,99 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
25
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
26
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
27
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
28
|
-
var Manager = /*#__PURE__*/_createClass(function Manager() {
|
|
29
|
-
var _this = this;
|
|
30
|
-
_classCallCheck(this, Manager);
|
|
31
|
-
_defineProperty(this, "start_clock", function () {
|
|
32
|
-
var frequency = Number(process.env.HERTS) || 10;
|
|
33
|
-
_this.clock = setInterval(function () {
|
|
34
|
-
for (var account in _this.tracks) {
|
|
35
|
-
var track = _this.tracks[account];
|
|
36
|
-
var instruction = track.sequence[track.pointer];
|
|
1
|
+
import framer from "../framer";
|
|
2
|
+
import opcodes from "../opcodes";
|
|
3
|
+
import Account from "./Account";
|
|
4
|
+
import Blockweb from "./Blockweb";
|
|
5
|
+
import Oracle from "./Oracle";
|
|
6
|
+
|
|
7
|
+
class Manager {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.accounts = new Object();
|
|
10
|
+
this.running = 0;
|
|
11
|
+
this.tracks = new Object();
|
|
12
|
+
this.web = new Blockweb(this);
|
|
13
|
+
this.oracle = new Oracle(this);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
start_clock = () => {
|
|
17
|
+
let frequency = Number(process.env.HERTS) || 10;
|
|
18
|
+
this.clock = setInterval(() => {
|
|
19
|
+
for (let account in this.tracks) {
|
|
20
|
+
let track = this.tracks[account];
|
|
21
|
+
|
|
22
|
+
let instruction = track.sequence[track.pointer];
|
|
23
|
+
|
|
37
24
|
track.account.vm.execute(instruction, track);
|
|
38
25
|
track.pointer++;
|
|
26
|
+
|
|
39
27
|
if (track.pointer === track.sequence.length) {
|
|
40
|
-
|
|
28
|
+
this.running--;
|
|
41
29
|
track.account.chain.mine(track.account.vm);
|
|
42
30
|
track.account.flush_buffer(track.pids.splice(-1)[0]);
|
|
43
|
-
|
|
31
|
+
|
|
32
|
+
delete this.tracks[account];
|
|
44
33
|
}
|
|
34
|
+
|
|
45
35
|
if (track.breakpoint.slice(-1)[0] === track.pointer) {
|
|
46
36
|
track.account.flush_buffer(track.pids.splice(-1)[0]);
|
|
47
37
|
}
|
|
48
38
|
}
|
|
49
|
-
|
|
39
|
+
|
|
40
|
+
!this.running && clearInterval(this.clock);
|
|
50
41
|
}, frequency);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
get_account = (name) => this.accounts[name];
|
|
45
|
+
|
|
46
|
+
add_account = (name, meta) => {
|
|
47
|
+
let account = this.get_account(name);
|
|
48
|
+
|
|
57
49
|
if (!account) {
|
|
58
|
-
account = new
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
account["private"] = true;
|
|
50
|
+
account = new Account(name, { ...meta, manager: this });
|
|
51
|
+
framer(account);
|
|
52
|
+
opcodes(account);
|
|
53
|
+
|
|
54
|
+
this.accounts[account.name] = account;
|
|
55
|
+
} else if (meta && meta.private && !account.private) {
|
|
56
|
+
account.private = true;
|
|
66
57
|
}
|
|
58
|
+
|
|
67
59
|
return account;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
push = (program) => {
|
|
63
|
+
let track = this.tracks[program.account.name];
|
|
64
|
+
|
|
71
65
|
if (track) {
|
|
72
|
-
var _track$sequence;
|
|
73
66
|
track.breakpoint.push(track.pointer + program.sequence.length + 1);
|
|
74
|
-
|
|
67
|
+
track.sequence.splice(track.pointer + 1, 0, ...program.sequence);
|
|
75
68
|
track.pids.push(program.pid);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
69
|
+
|
|
70
|
+
if (!this.running) {
|
|
71
|
+
this.running++;
|
|
72
|
+
this.tracks[program.account.name] = track;
|
|
73
|
+
this.start_clock();
|
|
80
74
|
}
|
|
81
75
|
} else {
|
|
82
|
-
track =
|
|
76
|
+
track = {
|
|
77
|
+
...program,
|
|
83
78
|
pointer: 0,
|
|
84
79
|
pids: [program.pid],
|
|
85
|
-
breakpoint: new Array()
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
80
|
+
breakpoint: new Array(),
|
|
81
|
+
};
|
|
82
|
+
this.tracks[track.account.name] = track;
|
|
83
|
+
|
|
84
|
+
this.running++;
|
|
85
|
+
this.running === 1 && this.start_clock();
|
|
90
86
|
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
this.web = new _Blockweb["default"](this);
|
|
96
|
-
this.oracle = new _Oracle["default"](this);
|
|
97
|
-
});
|
|
98
|
-
var _default = Manager;
|
|
99
|
-
exports["default"] = _default;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export default Manager;
|
package/Objects/Opcodes.js
CHANGED
|
@@ -1,102 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
import { transpile_object } from "../utils/functions";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _functions = require("../utils/functions");
|
|
8
|
-
function _typeof(o) {
|
|
9
|
-
"@babel/helpers - typeof";
|
|
10
|
-
return (
|
|
11
|
-
(_typeof =
|
|
12
|
-
"function" == typeof Symbol && "symbol" == typeof Symbol.iterator
|
|
13
|
-
? function (o) {
|
|
14
|
-
return typeof o;
|
|
15
|
-
}
|
|
16
|
-
: function (o) {
|
|
17
|
-
return o &&
|
|
18
|
-
"function" == typeof Symbol &&
|
|
19
|
-
o.constructor === Symbol &&
|
|
20
|
-
o !== Symbol.prototype
|
|
21
|
-
? "symbol"
|
|
22
|
-
: typeof o;
|
|
23
|
-
}),
|
|
24
|
-
_typeof(o)
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
function _defineProperties(e, r) {
|
|
28
|
-
for (var t = 0; t < r.length; t++) {
|
|
29
|
-
var o = r[t];
|
|
30
|
-
(o.enumerable = o.enumerable || !1),
|
|
31
|
-
(o.configurable = !0),
|
|
32
|
-
"value" in o && (o.writable = !0),
|
|
33
|
-
Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function _createClass(e, r, t) {
|
|
37
|
-
return (
|
|
38
|
-
r && _defineProperties(e.prototype, r),
|
|
39
|
-
t && _defineProperties(e, t),
|
|
40
|
-
Object.defineProperty(e, "prototype", { writable: !1 }),
|
|
41
|
-
e
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
function _classCallCheck(a, n) {
|
|
45
|
-
if (!(a instanceof n))
|
|
46
|
-
throw new TypeError("Cannot call a class as a function");
|
|
47
|
-
}
|
|
48
|
-
function _defineProperty(e, r, t) {
|
|
49
|
-
return (
|
|
50
|
-
(r = _toPropertyKey(r)) in e
|
|
51
|
-
? Object.defineProperty(e, r, {
|
|
52
|
-
value: t,
|
|
53
|
-
enumerable: !0,
|
|
54
|
-
configurable: !0,
|
|
55
|
-
writable: !0,
|
|
56
|
-
})
|
|
57
|
-
: (e[r] = t),
|
|
58
|
-
e
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
function _toPropertyKey(t) {
|
|
62
|
-
var i = _toPrimitive(t, "string");
|
|
63
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
64
|
-
}
|
|
65
|
-
function _toPrimitive(t, r) {
|
|
66
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
67
|
-
var e = t[Symbol.toPrimitive];
|
|
68
|
-
if (void 0 !== e) {
|
|
69
|
-
var i = e.call(t, r || "default");
|
|
70
|
-
if ("object" != _typeof(i)) return i;
|
|
71
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
3
|
+
class Opcodes {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.opcodes = new Object();
|
|
72
6
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
_defineProperty(this, "prepare_operation", function (opcode, context) {
|
|
83
|
-
var circ = _this.opcodes[opcode];
|
|
7
|
+
|
|
8
|
+
set = (opcode, circuit) => {
|
|
9
|
+
this.opcodes[opcode] = circuit;
|
|
10
|
+
this.account.assembler.opcodes.push(opcode);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
prepare_operation = (opcode, context) => {
|
|
14
|
+
let circ = this.opcodes[opcode];
|
|
15
|
+
|
|
84
16
|
if (typeof circ !== "function") return;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
17
|
+
|
|
18
|
+
let buf = context.get_buffer();
|
|
19
|
+
|
|
20
|
+
let args = buf && context.account.read(buf.inputs);
|
|
21
|
+
|
|
22
|
+
let res = circ(args);
|
|
23
|
+
|
|
24
|
+
this.stdin(res);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
stdin = (object, cb) => {
|
|
91
28
|
if (object == null) return;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
29
|
+
|
|
30
|
+
let code_string = transpile_object(object);
|
|
31
|
+
|
|
32
|
+
this.account.compiler.run(code_string, { cb, pure: true });
|
|
97
33
|
// console.log(`Writing in: ${code_string}`);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
exports["default"] = _default;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default Opcodes;
|
package/Objects/Oracle.js
CHANGED
|
@@ -1,42 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import fs from "fs";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
15
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
16
|
-
var Oracle = /*#__PURE__*/_createClass(function Oracle(mgr) {
|
|
17
|
-
var _this = this;
|
|
18
|
-
_classCallCheck(this, Oracle);
|
|
19
|
-
_defineProperty(this, "set", function (path, _ref) {
|
|
20
|
-
var type = _ref.type,
|
|
21
|
-
obj = _ref.obj;
|
|
22
|
-
_this.datapaths[path] = {
|
|
23
|
-
obj: obj,
|
|
24
|
-
type: type
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
_defineProperty(this, "get", function (path) {
|
|
28
|
-
return _this.datapaths[path];
|
|
29
|
-
});
|
|
30
|
-
_defineProperty(this, "write", function (addr, data) {
|
|
31
|
-
var meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
32
|
-
encoding: "utf-8"
|
|
3
|
+
class Oracle {
|
|
4
|
+
constructor(mgr) {
|
|
5
|
+
this.fs = fs;
|
|
6
|
+
this.mgr = mgr;
|
|
7
|
+
this.datapaths = new Object();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
set = (path, { type, obj }) => {
|
|
11
|
+
this.datapaths[path] = {
|
|
12
|
+
obj,
|
|
13
|
+
type,
|
|
33
14
|
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
get = (path) => this.datapaths[path];
|
|
18
|
+
|
|
19
|
+
write = (addr, data, meta = { encoding: "utf-8" }) => {
|
|
34
20
|
if (typeof data !== "string") data = JSON.stringify(data);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var _default = Oracle;
|
|
42
|
-
exports["default"] = _default;
|
|
21
|
+
|
|
22
|
+
this.fs.writeFileSync(addr, data, meta);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default Oracle;
|