godprotocol 1.0.81 → 1.0.82
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 -19
- package/Loader_sequence/main.js +368 -234
- package/Objects/Account.js +187 -178
- package/Objects/Block.js +60 -61
- 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 +60 -69
- package/Objects/Opcodes.js +39 -101
- package/Objects/Oracle.js +50 -66
- package/Objects/Virtual_machine.js +132 -132
- package/build/Account.js +187 -0
- package/build/Block.js +68 -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 +20 -0
- package/build/Manager.js +86 -0
- package/build/Opcodes.js +109 -0
- package/build/Oracle.js +81 -0
- package/build/Virtual_machine.js +136 -0
- package/build/add.js +26 -0
- package/build/create_server.js +132 -0
- package/build/framer.js +59 -0
- package/build/functions.js +82 -0
- package/build/hash.js +14 -0
- package/build/indices.js +31 -0
- package/build/jmp.js +19 -0
- package/build/main.js +327 -0
- package/build/opcodes.js +60 -0
- package/build/privacy.js +27 -0
- package/build/services.js +50 -0
- package/build/std.js +15 -0
- package/framer.js +36 -34
- package/opcodes/add.js +9 -25
- package/opcodes/indices.js +13 -16
- package/opcodes/jmp.js +7 -12
- package/opcodes/std.js +7 -13
- package/opcodes.js +32 -42
- package/package.json +1 -1
- package/readme.md +4 -4
- package/utils/create_server.js +72 -105
- 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/build/Chain.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _hash = require("../utils/hash");
|
|
8
|
+
var _Block = _interopRequireDefault(require("./Block"));
|
|
9
|
+
var _Explorer2 = _interopRequireDefault(require("./Explorer"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
12
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
13
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
14
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
15
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
16
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
17
|
+
function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
|
|
18
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
19
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
20
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
21
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
22
|
+
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; }
|
|
23
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
24
|
+
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); }
|
|
25
|
+
var Chain = /*#__PURE__*/function (_Explorer) {
|
|
26
|
+
_inherits(Chain, _Explorer);
|
|
27
|
+
var _super = _createSuper(Chain);
|
|
28
|
+
function Chain(parent, _name) {
|
|
29
|
+
var _this;
|
|
30
|
+
_classCallCheck(this, Chain);
|
|
31
|
+
_this = _super.call(this);
|
|
32
|
+
_defineProperty(_assertThisInitialized(_this), "append_buffer", function () {
|
|
33
|
+
_this.buffs.push({});
|
|
34
|
+
_this.cursors.push(_this.cursor);
|
|
35
|
+
_this.cursor = -1;
|
|
36
|
+
});
|
|
37
|
+
_defineProperty(_assertThisInitialized(_this), "set_cursor", function (cursor) {
|
|
38
|
+
_this.cursor = cursor;
|
|
39
|
+
_this.cursors.push(cursor);
|
|
40
|
+
});
|
|
41
|
+
_defineProperty(_assertThisInitialized(_this), "get_buffer", function () {
|
|
42
|
+
_this.cursor = _this.cursors.pop();
|
|
43
|
+
return _this.buffs.slice(-1)[0];
|
|
44
|
+
});
|
|
45
|
+
_defineProperty(_assertThisInitialized(_this), "generate_hash", function () {
|
|
46
|
+
_this.hash = (0, _hash.hash)(_this.physical_address);
|
|
47
|
+
});
|
|
48
|
+
_defineProperty(_assertThisInitialized(_this), "get_block", function (index) {
|
|
49
|
+
return _this.blocks[index];
|
|
50
|
+
});
|
|
51
|
+
_defineProperty(_assertThisInitialized(_this), "add_tx", function (instruction) {
|
|
52
|
+
if (!_this.txs.length) _this.start_time = Date.now();
|
|
53
|
+
_this.txs.push(instruction);
|
|
54
|
+
});
|
|
55
|
+
_defineProperty(_assertThisInitialized(_this), "mine", function (vm, no_curs) {
|
|
56
|
+
var block = new _Block["default"](_assertThisInitialized(_this));
|
|
57
|
+
block.generate_hash();
|
|
58
|
+
_this.add_block(block);
|
|
59
|
+
block.store(no_curs);
|
|
60
|
+
block.children = _this.pending_children;
|
|
61
|
+
_this.pending_children = new Array();
|
|
62
|
+
var prev_context = vm.get_context(-2);
|
|
63
|
+
if (prev_context) {
|
|
64
|
+
prev_context.pending_children.push(block);
|
|
65
|
+
prev_context.connections.push(block);
|
|
66
|
+
}
|
|
67
|
+
_this.txs = new Array();
|
|
68
|
+
block.timelapse = Date.now() - _this.start_time;
|
|
69
|
+
return block;
|
|
70
|
+
});
|
|
71
|
+
_defineProperty(_assertThisInitialized(_this), "add_block", function (block) {
|
|
72
|
+
_this.blocks.push(block);
|
|
73
|
+
_this.height = _this.blocks.length;
|
|
74
|
+
});
|
|
75
|
+
_defineProperty(_assertThisInitialized(_this), "get_latest_block", function () {
|
|
76
|
+
return _this.blocks.slice(-1)[0];
|
|
77
|
+
});
|
|
78
|
+
_defineProperty(_assertThisInitialized(_this), "stringify", function (str) {
|
|
79
|
+
var obj = {};
|
|
80
|
+
obj.physical_address = _this.physical_address;
|
|
81
|
+
obj.height = _this.blocks.length;
|
|
82
|
+
obj.parent = _this.parent.path;
|
|
83
|
+
obj.account = _this.parent.account.name;
|
|
84
|
+
obj.name = _this.name;
|
|
85
|
+
obj.connections = _this.connections.map(function (b) {
|
|
86
|
+
return new Object({
|
|
87
|
+
chain: b.chain.hash,
|
|
88
|
+
block: b.hash
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
obj.hash = _this.hash;
|
|
92
|
+
obj.blocks = _this.blocks.map(function (blk) {
|
|
93
|
+
return blk.hash;
|
|
94
|
+
});
|
|
95
|
+
return str ? JSON.stringify(obj) : obj;
|
|
96
|
+
});
|
|
97
|
+
_defineProperty(_assertThisInitialized(_this), "add_chain", function (name) {
|
|
98
|
+
return _this.account.add_chain(name, _assertThisInitialized(_this));
|
|
99
|
+
});
|
|
100
|
+
_this.parent = parent;
|
|
101
|
+
_this.account = _this.parent.account;
|
|
102
|
+
_this.name = _name || _this.parent.name;
|
|
103
|
+
_this.physical_address = _this.parent.manager || !_name ? _this.parent.physical_address : "".concat(_this.parent.physical_address, "/").concat(_this.name);
|
|
104
|
+
_this.pending_children = new Array();
|
|
105
|
+
_this.connections = new Array();
|
|
106
|
+
_this.blocks = new Array();
|
|
107
|
+
_this.txs = new Array();
|
|
108
|
+
_this.height = 0;
|
|
109
|
+
_this.cursor = -1;
|
|
110
|
+
_this.cursors = new Array();
|
|
111
|
+
_this.buffs = new Array();
|
|
112
|
+
_this.generate_hash();
|
|
113
|
+
_this.account.set_paths(_assertThisInitialized(_this));
|
|
114
|
+
return _this;
|
|
115
|
+
}
|
|
116
|
+
return _createClass(Chain);
|
|
117
|
+
}(_Explorer2["default"]);
|
|
118
|
+
var _default = Chain;
|
|
119
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
8
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
9
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
10
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
11
|
+
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; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
13
|
+
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); }
|
|
14
|
+
var Explorer = /*#__PURE__*/_createClass(function Explorer() {
|
|
15
|
+
var _this = this;
|
|
16
|
+
_classCallCheck(this, Explorer);
|
|
17
|
+
_defineProperty(this, "chain_props", ["blocks"]);
|
|
18
|
+
_defineProperty(this, "explore", function (query) {
|
|
19
|
+
if (!query) return;
|
|
20
|
+
if (query.startsWith("{")) query = query.slice(1, -1);
|
|
21
|
+
query = query.split(":");
|
|
22
|
+
query[0] = query[0].split(".");
|
|
23
|
+
var q2 = Number(query[1]),
|
|
24
|
+
prop;
|
|
25
|
+
if (_this.chain_props.includes(query[0][0])) prop = query[0][0];
|
|
26
|
+
var obj;
|
|
27
|
+
if (isNaN(q2)) {
|
|
28
|
+
obj = _this[prop || "connections"].find(function (c) {
|
|
29
|
+
return c.hash === query[1];
|
|
30
|
+
});
|
|
31
|
+
} else if (q2 >= 0) {
|
|
32
|
+
obj = _this[prop || "connections"].find(function (q) {
|
|
33
|
+
return q.index === q2;
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
obj = _this[prop || "connections"].slice(q2)[0];
|
|
37
|
+
}
|
|
38
|
+
if (!prop) for (var q = 0; q < query[0].length; q++) {
|
|
39
|
+
var que = query[0][q];
|
|
40
|
+
if (!obj) break;
|
|
41
|
+
obj = obj[que];
|
|
42
|
+
}
|
|
43
|
+
return obj;
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
var _default = Explorer;
|
|
47
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _hash = require("../utils/hash");
|
|
8
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
9
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
10
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
11
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
12
|
+
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; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
14
|
+
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); }
|
|
15
|
+
var Filesystem = /*#__PURE__*/_createClass(function Filesystem() {
|
|
16
|
+
var _this = this;
|
|
17
|
+
_classCallCheck(this, Filesystem);
|
|
18
|
+
_defineProperty(this, "parse_path", function (path) {
|
|
19
|
+
if (!path || path && !path.includes("/")) return path;
|
|
20
|
+
return _this.read(path);
|
|
21
|
+
});
|
|
22
|
+
_defineProperty(this, "read", function (datapath) {
|
|
23
|
+
if (!datapath) return null;
|
|
24
|
+
var type_folder = _this.account.manager.oracle.get(datapath);
|
|
25
|
+
if (!type_folder) return datapath;
|
|
26
|
+
var content;
|
|
27
|
+
if (type_folder.type === "twain") {
|
|
28
|
+
content = {};
|
|
29
|
+
for (var prop in type_folder.obj) {
|
|
30
|
+
var val = type_folder.obj[prop];
|
|
31
|
+
content[_this.parse_path(prop)] = _this.parse_path(val);
|
|
32
|
+
}
|
|
33
|
+
} else if (type_folder.type === "array") {
|
|
34
|
+
content = [];
|
|
35
|
+
type_folder.obj.map(function (t) {
|
|
36
|
+
content.push(_this.parse_path(t));
|
|
37
|
+
});
|
|
38
|
+
} else content = type_folder.obj;
|
|
39
|
+
return content;
|
|
40
|
+
});
|
|
41
|
+
_defineProperty(this, "save", function (content, chain, just_obj) {
|
|
42
|
+
var addr, obj;
|
|
43
|
+
var type = _this.get_type(chain);
|
|
44
|
+
if (type === "array" || type === "string") {
|
|
45
|
+
obj = [];
|
|
46
|
+
for (var curs in content) {
|
|
47
|
+
obj.splice(Number(curs) || -1, 0, content[curs]);
|
|
48
|
+
}
|
|
49
|
+
if (type === "string") obj = obj.join(" ");
|
|
50
|
+
} else if (type === "twain") {
|
|
51
|
+
obj = {};
|
|
52
|
+
for (var _curs in content) {
|
|
53
|
+
obj[_curs] = content[_curs];
|
|
54
|
+
}
|
|
55
|
+
} else if (type === "number") {
|
|
56
|
+
obj = Number(content["-1"]);
|
|
57
|
+
if (isNaN(obj)) obj = -1;
|
|
58
|
+
} else {
|
|
59
|
+
obj = null;
|
|
60
|
+
}
|
|
61
|
+
if (just_obj) return obj;
|
|
62
|
+
addr = "".concat(chain.path, "/").concat((0, _hash.hash)(JSON.stringify(obj)));
|
|
63
|
+
_this;
|
|
64
|
+
if (obj != null) _this.manager.oracle.write(addr, obj, _this.account);
|
|
65
|
+
_this.manager.oracle.set(addr, {
|
|
66
|
+
obj: obj,
|
|
67
|
+
type: type
|
|
68
|
+
});
|
|
69
|
+
return addr;
|
|
70
|
+
});
|
|
71
|
+
_defineProperty(this, "data_addr", function (type) {
|
|
72
|
+
return "".concat(_this.physical_address, "/Datatypes/").concat(type);
|
|
73
|
+
});
|
|
74
|
+
_defineProperty(this, "get_type", function (chain) {
|
|
75
|
+
switch (chain.physical_address) {
|
|
76
|
+
case _this.data_addr("Number"):
|
|
77
|
+
return "number";
|
|
78
|
+
case _this.data_addr("String"):
|
|
79
|
+
return "string";
|
|
80
|
+
case _this.data_addr("Twain"):
|
|
81
|
+
return "twain";
|
|
82
|
+
case _this.data_addr("Array"):
|
|
83
|
+
return "array";
|
|
84
|
+
case _this.data_addr("Boolean"):
|
|
85
|
+
return "boolean";
|
|
86
|
+
case _this.data_addr("Void"):
|
|
87
|
+
return "void";
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
_defineProperty(this, "write", function (arg, context) {
|
|
91
|
+
var content = context.get_buffer();
|
|
92
|
+
if (!content || !arg) return;
|
|
93
|
+
content[context.cursor] = arg;
|
|
94
|
+
// console.log(`Writing: ${arg}`);
|
|
95
|
+
});
|
|
96
|
+
_defineProperty(this, "name_hash", function () {
|
|
97
|
+
_this.hash = (0, _hash.hash)(_this.name);
|
|
98
|
+
});
|
|
99
|
+
_defineProperty(this, "set_paths", function (chain) {
|
|
100
|
+
if (chain.parent && chain.parent.manager) {
|
|
101
|
+
chain.path = chain.parent.path;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
chain.path = "".concat(chain.parent ? chain.parent.path : _this.base_address, "/").concat(chain.hash);
|
|
105
|
+
var fs = _this.manager.oracle.fs;
|
|
106
|
+
if (!fs.existsSync(chain.path)) {
|
|
107
|
+
fs.mkdirSync(chain.path, {
|
|
108
|
+
recursive: true
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
_defineProperty(this, "add_chain", function (name, parent) {
|
|
113
|
+
var chain = _this.manager.web.get("".concat(parent.physical_address, "/").concat(name));
|
|
114
|
+
if (!chain) chain = _this.manager.web.set(parent, name);
|
|
115
|
+
return chain;
|
|
116
|
+
});
|
|
117
|
+
_defineProperty(this, "account_chain", function (account) {
|
|
118
|
+
var chain = _this.manager.web.get(account.physical_address);
|
|
119
|
+
if (!chain) {
|
|
120
|
+
chain = _this.manager.web.set(account);
|
|
121
|
+
}
|
|
122
|
+
return chain;
|
|
123
|
+
});
|
|
124
|
+
this.base_address = process.env.BASE_ADDRESS || "Accounts";
|
|
125
|
+
});
|
|
126
|
+
var _default = Filesystem;
|
|
127
|
+
exports["default"] = _default;
|
package/build/Frame.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _functions = require("../utils/functions");
|
|
8
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
9
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
10
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
12
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
13
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
14
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
15
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
16
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
17
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
18
|
+
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; }
|
|
19
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
20
|
+
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); }
|
|
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);
|
|
28
|
+
return frame;
|
|
29
|
+
});
|
|
30
|
+
_defineProperty(this, "to_instruction", function () {
|
|
31
|
+
for (var prop in _this.object) {
|
|
32
|
+
var val = _this.object[prop];
|
|
33
|
+
_this.instructions.push("chain ".concat(prop));
|
|
34
|
+
val && _this.frame(val).to_instruction();
|
|
35
|
+
_this.instructions.push("pop ".concat(prop));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
_defineProperty(this, "flatten_instructions", function () {
|
|
39
|
+
var inss = new Array();
|
|
40
|
+
for (var i = 0; i < _this.instructions.length; i++) {
|
|
41
|
+
var ins = _this.instructions[i];
|
|
42
|
+
if (ins instanceof Frame) inss.push.apply(inss, _toConsumableArray(ins.flatten_instructions()));else inss.push(ins);
|
|
43
|
+
}
|
|
44
|
+
return inss;
|
|
45
|
+
});
|
|
46
|
+
this.parent = parent;
|
|
47
|
+
this.object = Array.isArray(_object) ? (0, _functions.array_to_nested_objects)(_object) : _object;
|
|
48
|
+
this.children = new Array();
|
|
49
|
+
this.instructions = new Array();
|
|
50
|
+
});
|
|
51
|
+
var _default = Frame;
|
|
52
|
+
exports["default"] = _default;
|
package/build/Index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "create_server", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _create_server["default"];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
exports.initiator = exports["default"] = void 0;
|
|
13
|
+
var _Manager = _interopRequireDefault(require("./Objects/Manager"));
|
|
14
|
+
var _create_server = _interopRequireDefault(require("./utils/create_server"));
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
16
|
+
var manager = new _Manager["default"]();
|
|
17
|
+
var initiator = manager.add_account(process.env.INITIATOR || "initiator");
|
|
18
|
+
exports.initiator = initiator;
|
|
19
|
+
var _default = manager;
|
|
20
|
+
exports["default"] = _default;
|
package/build/Manager.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _framer = _interopRequireDefault(require("../framer"));
|
|
8
|
+
var _opcodes = _interopRequireDefault(require("../opcodes"));
|
|
9
|
+
var _Account = _interopRequireDefault(require("./Account"));
|
|
10
|
+
var _Blockweb = _interopRequireDefault(require("./Blockweb"));
|
|
11
|
+
var _Oracle = _interopRequireDefault(require("./Oracle"));
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
14
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
17
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
18
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
19
|
+
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; }
|
|
20
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
21
|
+
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); }
|
|
22
|
+
var Manager = /*#__PURE__*/_createClass(function Manager() {
|
|
23
|
+
var _this = this;
|
|
24
|
+
_classCallCheck(this, Manager);
|
|
25
|
+
_defineProperty(this, "start_clock", function () {
|
|
26
|
+
var frequency = Number(process.env.HERTS) || 10;
|
|
27
|
+
_this.clock = setInterval(function () {
|
|
28
|
+
for (var account in _this.tracks) {
|
|
29
|
+
var track = _this.tracks[account];
|
|
30
|
+
var program = track.slice(-1)[0];
|
|
31
|
+
var instruction = program.sequence[program.pointer];
|
|
32
|
+
program.account.vm.execute(instruction, program);
|
|
33
|
+
program.pointer++;
|
|
34
|
+
if (program.pointer === program.sequence.length) {
|
|
35
|
+
program.account.flush_buffer(program.pid);
|
|
36
|
+
track.pop();
|
|
37
|
+
}
|
|
38
|
+
if (!track.length) {
|
|
39
|
+
_this.running -= 1;
|
|
40
|
+
delete _this.tracks[account];
|
|
41
|
+
program.account.chain.mine(program.account.vm);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
!_this.running && clearInterval(_this.clock);
|
|
45
|
+
}, frequency);
|
|
46
|
+
});
|
|
47
|
+
_defineProperty(this, "get_account", function (name) {
|
|
48
|
+
return _this.accounts[name];
|
|
49
|
+
});
|
|
50
|
+
_defineProperty(this, "add_account", function (name, meta) {
|
|
51
|
+
var account = _this.get_account(name);
|
|
52
|
+
if (!account) {
|
|
53
|
+
account = new _Account["default"](name, _objectSpread(_objectSpread({}, meta), {}, {
|
|
54
|
+
manager: _this
|
|
55
|
+
}));
|
|
56
|
+
(0, _opcodes["default"])(account);
|
|
57
|
+
(0, _framer["default"])(account);
|
|
58
|
+
_this.accounts[account.name] = account;
|
|
59
|
+
} else if (meta && meta["private"] && !account["private"]) {
|
|
60
|
+
account["private"] = true;
|
|
61
|
+
}
|
|
62
|
+
return account;
|
|
63
|
+
});
|
|
64
|
+
_defineProperty(this, "push", function (program) {
|
|
65
|
+
var track = _this.tracks[program.account.name];
|
|
66
|
+
if (track) {
|
|
67
|
+
track.push(_objectSpread(_objectSpread({}, program), {}, {
|
|
68
|
+
pointer: 0
|
|
69
|
+
}));
|
|
70
|
+
} else {
|
|
71
|
+
track = [_objectSpread(_objectSpread({}, program), {}, {
|
|
72
|
+
pointer: 0
|
|
73
|
+
})];
|
|
74
|
+
_this.tracks[program.account.name] = track;
|
|
75
|
+
_this.running++;
|
|
76
|
+
_this.running === 1 && _this.start_clock();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
this.accounts = new Object();
|
|
80
|
+
this.running = 0;
|
|
81
|
+
this.tracks = new Object();
|
|
82
|
+
this.web = new _Blockweb["default"](this);
|
|
83
|
+
this.oracle = new _Oracle["default"](this);
|
|
84
|
+
});
|
|
85
|
+
var _default = Manager;
|
|
86
|
+
exports["default"] = _default;
|
package/build/Opcodes.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _framer = require("../framer");
|
|
8
|
+
var _functions = require("../utils/functions");
|
|
9
|
+
function _typeof(o) {
|
|
10
|
+
"@babel/helpers - typeof";
|
|
11
|
+
return (
|
|
12
|
+
(_typeof =
|
|
13
|
+
"function" == typeof Symbol && "symbol" == typeof Symbol.iterator
|
|
14
|
+
? function (o) {
|
|
15
|
+
return typeof o;
|
|
16
|
+
}
|
|
17
|
+
: function (o) {
|
|
18
|
+
return o &&
|
|
19
|
+
"function" == typeof Symbol &&
|
|
20
|
+
o.constructor === Symbol &&
|
|
21
|
+
o !== Symbol.prototype
|
|
22
|
+
? "symbol"
|
|
23
|
+
: typeof o;
|
|
24
|
+
}),
|
|
25
|
+
_typeof(o)
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
function _defineProperties(e, r) {
|
|
29
|
+
for (var t = 0; t < r.length; t++) {
|
|
30
|
+
var o = r[t];
|
|
31
|
+
(o.enumerable = o.enumerable || !1),
|
|
32
|
+
(o.configurable = !0),
|
|
33
|
+
"value" in o && (o.writable = !0),
|
|
34
|
+
Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function _createClass(e, r, t) {
|
|
38
|
+
return (
|
|
39
|
+
r && _defineProperties(e.prototype, r),
|
|
40
|
+
t && _defineProperties(e, t),
|
|
41
|
+
Object.defineProperty(e, "prototype", { writable: !1 }),
|
|
42
|
+
e
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
function _classCallCheck(a, n) {
|
|
46
|
+
if (!(a instanceof n))
|
|
47
|
+
throw new TypeError("Cannot call a class as a function");
|
|
48
|
+
}
|
|
49
|
+
function _defineProperty(e, r, t) {
|
|
50
|
+
return (
|
|
51
|
+
(r = _toPropertyKey(r)) in e
|
|
52
|
+
? Object.defineProperty(e, r, {
|
|
53
|
+
value: t,
|
|
54
|
+
enumerable: !0,
|
|
55
|
+
configurable: !0,
|
|
56
|
+
writable: !0,
|
|
57
|
+
})
|
|
58
|
+
: (e[r] = t),
|
|
59
|
+
e
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
function _toPropertyKey(t) {
|
|
63
|
+
var i = _toPrimitive(t, "string");
|
|
64
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
65
|
+
}
|
|
66
|
+
function _toPrimitive(t, r) {
|
|
67
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
68
|
+
var e = t[Symbol.toPrimitive];
|
|
69
|
+
if (void 0 !== e) {
|
|
70
|
+
var i = e.call(t, r || "default");
|
|
71
|
+
if ("object" != _typeof(i)) return i;
|
|
72
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
73
|
+
}
|
|
74
|
+
return ("string" === r ? String : Number)(t);
|
|
75
|
+
}
|
|
76
|
+
var Opcodes = /*#__PURE__*/ _createClass(function Opcodes() {
|
|
77
|
+
var _this = this;
|
|
78
|
+
_classCallCheck(this, Opcodes);
|
|
79
|
+
_defineProperty(this, "set", function (opcode, circuit) {
|
|
80
|
+
_this.opcodes[opcode] = circuit;
|
|
81
|
+
_framer.obj.Opcodes[opcode] = null;
|
|
82
|
+
_this.account.assembler.opcodes.push(opcode);
|
|
83
|
+
});
|
|
84
|
+
_defineProperty(this, "prepare_operation", function (opcode, context) {
|
|
85
|
+
var circ = _this.opcodes[opcode];
|
|
86
|
+
if (typeof circ !== "function") return;
|
|
87
|
+
var buf = context.get_buffer();
|
|
88
|
+
var args =
|
|
89
|
+
context.account.read(buf && buf.inputs) ||
|
|
90
|
+
_this.account.stdin.splice(-1)[0];
|
|
91
|
+
var res = circ(args, _this);
|
|
92
|
+
_this.stdin(res);
|
|
93
|
+
});
|
|
94
|
+
_defineProperty(this, "stdin", function (object, cb) {
|
|
95
|
+
if (object == null) return;
|
|
96
|
+
_this.flags.zero = !object;
|
|
97
|
+
if (typeof object === "number") _this.flags.neg = object < 0;
|
|
98
|
+
var code_string =
|
|
99
|
+
typeof object !== "string" ? JSON.stringify(object) : object;
|
|
100
|
+
_this.account.assembler.run(code_string, {
|
|
101
|
+
cb: cb,
|
|
102
|
+
pure: true,
|
|
103
|
+
});
|
|
104
|
+
// console.log(`Writing in: ${code_string}`);
|
|
105
|
+
});
|
|
106
|
+
this.opcodes = new Object();
|
|
107
|
+
});
|
|
108
|
+
var _default = Opcodes;
|
|
109
|
+
exports["default"] = _default;
|
package/build/Oracle.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
+
var _generalisedDatastore = _interopRequireDefault(require("generalised-datastore"));
|
|
9
|
+
var _hash = require("../utils/hash");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
12
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
13
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
14
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
15
|
+
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; }
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
17
|
+
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); }
|
|
18
|
+
var Oracle = /*#__PURE__*/_createClass(function Oracle(mgr) {
|
|
19
|
+
var _this = this;
|
|
20
|
+
_classCallCheck(this, Oracle);
|
|
21
|
+
_defineProperty(this, "set", function (path, _ref) {
|
|
22
|
+
var type = _ref.type,
|
|
23
|
+
obj = _ref.obj;
|
|
24
|
+
_this.datapaths[path] = {
|
|
25
|
+
obj: obj,
|
|
26
|
+
type: type
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
_defineProperty(this, "get", function (path) {
|
|
30
|
+
return _this.datapaths[path];
|
|
31
|
+
});
|
|
32
|
+
_defineProperty(this, "hash", function (data) {
|
|
33
|
+
data = JSON.stringify(data);
|
|
34
|
+
return (0, _hash.hash)(_hash.hash);
|
|
35
|
+
});
|
|
36
|
+
_defineProperty(this, "write", function (addr, data, account) {
|
|
37
|
+
if (typeof data !== "string") data = JSON.stringify(data);
|
|
38
|
+
var folder = _this.gds.folder((0, _hash.hash)(account.vm.get_context().physical_address));
|
|
39
|
+
folder.write({
|
|
40
|
+
data: addr
|
|
41
|
+
});
|
|
42
|
+
_this.fs.writeFileSync(addr, data, {
|
|
43
|
+
encoding: "utf-8"
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
_defineProperty(this, "fetch", function (payload, callback) {
|
|
47
|
+
var physical_address = payload.physical_address,
|
|
48
|
+
query = payload.query,
|
|
49
|
+
account = payload.account,
|
|
50
|
+
signature = payload.signature,
|
|
51
|
+
result;
|
|
52
|
+
account = _this.mgr.get_account(account);
|
|
53
|
+
if (account && account["private"]) if (!account.validate({
|
|
54
|
+
physical_address: physical_address,
|
|
55
|
+
query: query
|
|
56
|
+
}, signature, callback)) return;
|
|
57
|
+
try {
|
|
58
|
+
var operation = _this.gds.folder((0, _hash.hash)(physical_address))[query.operation];
|
|
59
|
+
result = operation && operation(query.query, query.options);
|
|
60
|
+
if (result) {
|
|
61
|
+
if (account) {
|
|
62
|
+
var content = account.read(result.data);
|
|
63
|
+
if (content != null) result.content = content;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} catch (e) {
|
|
67
|
+
result = {
|
|
68
|
+
error: true,
|
|
69
|
+
message: e.message,
|
|
70
|
+
payload: payload
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
typeof callback === "function" && callback(result);
|
|
74
|
+
});
|
|
75
|
+
this.fs = _fs["default"];
|
|
76
|
+
this.mgr = mgr;
|
|
77
|
+
this.datapaths = new Object();
|
|
78
|
+
this.gds = new _generalisedDatastore["default"]("godprotocol").sync();
|
|
79
|
+
});
|
|
80
|
+
var _default = Oracle;
|
|
81
|
+
exports["default"] = _default;
|