godprotocol 1.0.789 → 1.0.791
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/Objects/Account.js +260 -80
- package/Objects/Manager.js +2 -3
- package/Objects/Opcodes.js +75 -12
- package/Objects/Virtual_machine.js +242 -105
- package/build/Account.js +173 -0
- package/build/Block.js +103 -0
- package/build/Blockweb.js +78 -0
- package/build/Chain.js +205 -0
- package/build/Explorer.js +85 -0
- package/build/Filesystem.js +165 -0
- package/build/Frame.js +108 -0
- package/build/Index.js +19 -0
- package/build/Manager.js +178 -0
- package/build/Opcodes.js +102 -0
- package/build/Oracle.js +84 -0
- package/build/Virtual_machine.js +128 -0
- package/build/add.js +41 -0
- package/build/create_server.js +495 -0
- package/build/framer.js +88 -0
- package/build/functions.js +127 -0
- package/build/hash.js +14 -0
- package/build/jmp.js +19 -0
- package/build/main.js +339 -0
- package/build/opcodes.js +42 -0
- package/build/privacy.js +27 -0
- package/build/services.js +96 -0
- package/build/std.js +11 -0
- package/package.json +1 -1
- package/readme.md +94 -71
package/build/Manager.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
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) {
|
|
13
|
+
return e && e.__esModule ? e : {
|
|
14
|
+
"default": e
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function _typeof(o) {
|
|
18
|
+
"@babel/helpers - typeof";
|
|
19
|
+
|
|
20
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
21
|
+
return typeof o;
|
|
22
|
+
} : function (o) {
|
|
23
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
24
|
+
}, _typeof(o);
|
|
25
|
+
}
|
|
26
|
+
function _toConsumableArray(r) {
|
|
27
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
28
|
+
}
|
|
29
|
+
function _nonIterableSpread() {
|
|
30
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
31
|
+
}
|
|
32
|
+
function _unsupportedIterableToArray(r, a) {
|
|
33
|
+
if (r) {
|
|
34
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
35
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
36
|
+
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;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function _iterableToArray(r) {
|
|
40
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
41
|
+
}
|
|
42
|
+
function _arrayWithoutHoles(r) {
|
|
43
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
44
|
+
}
|
|
45
|
+
function _arrayLikeToArray(r, a) {
|
|
46
|
+
(null == a || a > r.length) && (a = r.length);
|
|
47
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
48
|
+
return n;
|
|
49
|
+
}
|
|
50
|
+
function ownKeys(e, r) {
|
|
51
|
+
var t = Object.keys(e);
|
|
52
|
+
if (Object.getOwnPropertySymbols) {
|
|
53
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
54
|
+
r && (o = o.filter(function (r) {
|
|
55
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
56
|
+
})), t.push.apply(t, o);
|
|
57
|
+
}
|
|
58
|
+
return t;
|
|
59
|
+
}
|
|
60
|
+
function _objectSpread(e) {
|
|
61
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
62
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
63
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
64
|
+
_defineProperty(e, r, t[r]);
|
|
65
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
66
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return e;
|
|
70
|
+
}
|
|
71
|
+
function _defineProperties(e, r) {
|
|
72
|
+
for (var t = 0; t < r.length; t++) {
|
|
73
|
+
var o = r[t];
|
|
74
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function _createClass(e, r, t) {
|
|
78
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
79
|
+
writable: !1
|
|
80
|
+
}), e;
|
|
81
|
+
}
|
|
82
|
+
function _classCallCheck(a, n) {
|
|
83
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
84
|
+
}
|
|
85
|
+
function _defineProperty(e, r, t) {
|
|
86
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
87
|
+
value: t,
|
|
88
|
+
enumerable: !0,
|
|
89
|
+
configurable: !0,
|
|
90
|
+
writable: !0
|
|
91
|
+
}) : e[r] = t, e;
|
|
92
|
+
}
|
|
93
|
+
function _toPropertyKey(t) {
|
|
94
|
+
var i = _toPrimitive(t, "string");
|
|
95
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
96
|
+
}
|
|
97
|
+
function _toPrimitive(t, r) {
|
|
98
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
99
|
+
var e = t[Symbol.toPrimitive];
|
|
100
|
+
if (void 0 !== e) {
|
|
101
|
+
var i = e.call(t, r || "default");
|
|
102
|
+
if ("object" != _typeof(i)) return i;
|
|
103
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
104
|
+
}
|
|
105
|
+
return ("string" === r ? String : Number)(t);
|
|
106
|
+
}
|
|
107
|
+
var Manager = /*#__PURE__*/_createClass(function Manager() {
|
|
108
|
+
var _this = this;
|
|
109
|
+
_classCallCheck(this, Manager);
|
|
110
|
+
_defineProperty(this, "start_clock", function () {
|
|
111
|
+
var frequency = Number(process.env.HERTS) || 10;
|
|
112
|
+
_this.clock = setInterval(function () {
|
|
113
|
+
for (var account in _this.tracks) {
|
|
114
|
+
var track = _this.tracks[account];
|
|
115
|
+
var instruction = track.sequence[track.pointer];
|
|
116
|
+
track.account.vm.execute(instruction, track);
|
|
117
|
+
track.pointer++;
|
|
118
|
+
if (track.pointer === track.sequence.length) {
|
|
119
|
+
_this.running--;
|
|
120
|
+
track.account.chain.mine(track.account.vm);
|
|
121
|
+
track.account.flush_buffer(track.pids.splice(-1)[0]);
|
|
122
|
+
delete _this.tracks[account];
|
|
123
|
+
}
|
|
124
|
+
if (track.breakpoint.slice(-1)[0] === track.pointer) {
|
|
125
|
+
track.account.flush_buffer(track.pids.splice(-1)[0]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
!_this.running && clearInterval(_this.clock);
|
|
129
|
+
}, frequency);
|
|
130
|
+
});
|
|
131
|
+
_defineProperty(this, "get_account", function (name) {
|
|
132
|
+
return _this.accounts[name];
|
|
133
|
+
});
|
|
134
|
+
_defineProperty(this, "add_account", function (name, meta) {
|
|
135
|
+
var account = _this.get_account(name);
|
|
136
|
+
if (!account) {
|
|
137
|
+
account = new _Account["default"](name, _objectSpread(_objectSpread({}, meta), {}, {
|
|
138
|
+
manager: _this
|
|
139
|
+
}));
|
|
140
|
+
(0, _framer["default"])(account);
|
|
141
|
+
(0, _opcodes["default"])(account);
|
|
142
|
+
_this.accounts[account.name] = account;
|
|
143
|
+
} else if (meta && meta["private"] && !account["private"]) {
|
|
144
|
+
account["private"] = true;
|
|
145
|
+
}
|
|
146
|
+
return account;
|
|
147
|
+
});
|
|
148
|
+
_defineProperty(this, "push", function (program) {
|
|
149
|
+
var track = _this.tracks[program.account.name];
|
|
150
|
+
if (track) {
|
|
151
|
+
var _track$sequence;
|
|
152
|
+
track.breakpoint.push(track.pointer + program.sequence.length + 1);
|
|
153
|
+
(_track$sequence = track.sequence).splice.apply(_track$sequence, [track.pointer + 1, 0].concat(_toConsumableArray(program.sequence)));
|
|
154
|
+
track.pids.push(program.pid);
|
|
155
|
+
if (!_this.running) {
|
|
156
|
+
_this.running++;
|
|
157
|
+
_this.tracks[program.account.name] = track;
|
|
158
|
+
_this.start_clock();
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
track = _objectSpread(_objectSpread({}, program), {}, {
|
|
162
|
+
pointer: 0,
|
|
163
|
+
pids: [program.pid],
|
|
164
|
+
breakpoint: new Array()
|
|
165
|
+
});
|
|
166
|
+
_this.tracks[track.account.name] = track;
|
|
167
|
+
_this.running++;
|
|
168
|
+
_this.running === 1 && _this.start_clock();
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
this.accounts = new Object();
|
|
172
|
+
this.running = 0;
|
|
173
|
+
this.tracks = new Object();
|
|
174
|
+
this.web = new _Blockweb["default"](this);
|
|
175
|
+
this.oracle = new _Oracle["default"](this);
|
|
176
|
+
});
|
|
177
|
+
var _default = Manager;
|
|
178
|
+
exports["default"] = _default;
|
package/build/Opcodes.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
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) {
|
|
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.");
|
|
72
|
+
}
|
|
73
|
+
return ("string" === r ? String : Number)(t);
|
|
74
|
+
}
|
|
75
|
+
var Opcodes = /*#__PURE__*/ _createClass(function Opcodes() {
|
|
76
|
+
var _this = this;
|
|
77
|
+
_classCallCheck(this, Opcodes);
|
|
78
|
+
_defineProperty(this, "set", function (opcode, circuit) {
|
|
79
|
+
_this.opcodes[opcode] = circuit;
|
|
80
|
+
_this.account.assembler.opcodes.push(opcode);
|
|
81
|
+
});
|
|
82
|
+
_defineProperty(this, "prepare_operation", function (opcode, context) {
|
|
83
|
+
var circ = _this.opcodes[opcode];
|
|
84
|
+
if (typeof circ !== "function") return;
|
|
85
|
+
var buf = context.get_buffer();
|
|
86
|
+
var args = buf && context.account.read(buf.inputs);
|
|
87
|
+
var res = circ(args);
|
|
88
|
+
_this.stdin(res);
|
|
89
|
+
});
|
|
90
|
+
_defineProperty(this, "stdin", function (object, cb) {
|
|
91
|
+
if (object == null) return;
|
|
92
|
+
var code_string = (0, _functions.transpile_object)(object);
|
|
93
|
+
_this.account.assembler.run(code_string, {
|
|
94
|
+
cb: cb,
|
|
95
|
+
pure: true,
|
|
96
|
+
});
|
|
97
|
+
// console.log(`Writing in: ${code_string}`);
|
|
98
|
+
});
|
|
99
|
+
this.opcodes = new Object();
|
|
100
|
+
});
|
|
101
|
+
var _default = Opcodes;
|
|
102
|
+
exports["default"] = _default;
|
package/build/Oracle.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
function _interopRequireDefault(e) {
|
|
9
|
+
return e && e.__esModule ? e : {
|
|
10
|
+
"default": e
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function _typeof(o) {
|
|
14
|
+
"@babel/helpers - typeof";
|
|
15
|
+
|
|
16
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
17
|
+
return typeof o;
|
|
18
|
+
} : function (o) {
|
|
19
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
20
|
+
}, _typeof(o);
|
|
21
|
+
}
|
|
22
|
+
function _defineProperties(e, r) {
|
|
23
|
+
for (var t = 0; t < r.length; t++) {
|
|
24
|
+
var o = r[t];
|
|
25
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function _createClass(e, r, t) {
|
|
29
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
30
|
+
writable: !1
|
|
31
|
+
}), e;
|
|
32
|
+
}
|
|
33
|
+
function _classCallCheck(a, n) {
|
|
34
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
35
|
+
}
|
|
36
|
+
function _defineProperty(e, r, t) {
|
|
37
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
38
|
+
value: t,
|
|
39
|
+
enumerable: !0,
|
|
40
|
+
configurable: !0,
|
|
41
|
+
writable: !0
|
|
42
|
+
}) : e[r] = t, e;
|
|
43
|
+
}
|
|
44
|
+
function _toPropertyKey(t) {
|
|
45
|
+
var i = _toPrimitive(t, "string");
|
|
46
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
47
|
+
}
|
|
48
|
+
function _toPrimitive(t, r) {
|
|
49
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
50
|
+
var e = t[Symbol.toPrimitive];
|
|
51
|
+
if (void 0 !== e) {
|
|
52
|
+
var i = e.call(t, r || "default");
|
|
53
|
+
if ("object" != _typeof(i)) return i;
|
|
54
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
55
|
+
}
|
|
56
|
+
return ("string" === r ? String : Number)(t);
|
|
57
|
+
}
|
|
58
|
+
var Oracle = /*#__PURE__*/_createClass(function Oracle(mgr) {
|
|
59
|
+
var _this = this;
|
|
60
|
+
_classCallCheck(this, Oracle);
|
|
61
|
+
_defineProperty(this, "set", function (path, _ref) {
|
|
62
|
+
var type = _ref.type,
|
|
63
|
+
obj = _ref.obj;
|
|
64
|
+
_this.datapaths[path] = {
|
|
65
|
+
obj: obj,
|
|
66
|
+
type: type
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
_defineProperty(this, "get", function (path) {
|
|
70
|
+
return _this.datapaths[path];
|
|
71
|
+
});
|
|
72
|
+
_defineProperty(this, "write", function (addr, data) {
|
|
73
|
+
var meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
74
|
+
encoding: "utf-8"
|
|
75
|
+
};
|
|
76
|
+
if (typeof data !== "string") data = JSON.stringify(data);
|
|
77
|
+
_this.fs.writeFileSync(addr, data, meta);
|
|
78
|
+
});
|
|
79
|
+
this.fs = _fs["default"];
|
|
80
|
+
this.mgr = mgr;
|
|
81
|
+
this.datapaths = new Object();
|
|
82
|
+
});
|
|
83
|
+
var _default = Oracle;
|
|
84
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _Opcodes2 = _interopRequireDefault(require("./Opcodes"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
|
+
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); }
|
|
10
|
+
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); } }
|
|
11
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
12
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
13
|
+
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); }
|
|
14
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
15
|
+
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); }; }
|
|
16
|
+
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); }
|
|
17
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
18
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
19
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
20
|
+
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; }
|
|
21
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
22
|
+
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); }
|
|
23
|
+
var Virtual_machine = /*#__PURE__*/function (_Opcodes) {
|
|
24
|
+
_inherits(Virtual_machine, _Opcodes);
|
|
25
|
+
var _super = _createSuper(Virtual_machine);
|
|
26
|
+
function Virtual_machine(_context) {
|
|
27
|
+
var _this;
|
|
28
|
+
_classCallCheck(this, Virtual_machine);
|
|
29
|
+
_this = _super.call(this);
|
|
30
|
+
_defineProperty(_assertThisInitialized(_this), "get_context", function (index) {
|
|
31
|
+
return _this.contexts.slice(index == null ? -1 : index)[0];
|
|
32
|
+
});
|
|
33
|
+
_defineProperty(_assertThisInitialized(_this), "parse_arg", function (arg, is_cursor) {
|
|
34
|
+
var context = _this.get_context();
|
|
35
|
+
var args = arg.split("/"),
|
|
36
|
+
i = 0;
|
|
37
|
+
while (args[0] === "..") {
|
|
38
|
+
i++;
|
|
39
|
+
args.splice(0, 1);
|
|
40
|
+
}
|
|
41
|
+
i = (i + 1) * -1;
|
|
42
|
+
context = i ? _this.get_context(i) : context;
|
|
43
|
+
arg = args.join("/");
|
|
44
|
+
while (arg.includes("^")) {
|
|
45
|
+
var blk = context.connections.slice(-1)[0];
|
|
46
|
+
if (!blk) break;
|
|
47
|
+
context = blk.chain;
|
|
48
|
+
var _i = arg.indexOf("^");
|
|
49
|
+
arg = "".concat(arg.slice(0, _i)).concat(arg.slice(_i + 1));
|
|
50
|
+
}
|
|
51
|
+
if (arg.startsWith("{*") && is_cursor) {
|
|
52
|
+
arg = context.explore(arg.slice(2, -1));
|
|
53
|
+
} else if (arg.startsWith("{") && !is_cursor) {
|
|
54
|
+
arg = context.explore(arg.slice(1, -1));
|
|
55
|
+
}
|
|
56
|
+
return arg;
|
|
57
|
+
});
|
|
58
|
+
_defineProperty(_assertThisInitialized(_this), "split_instruction", function (instruction) {
|
|
59
|
+
var split = instruction.split(" ");
|
|
60
|
+
var opcode = split[0],
|
|
61
|
+
args = split.slice(1).join(" ");
|
|
62
|
+
return {
|
|
63
|
+
opcode: opcode,
|
|
64
|
+
args: args
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
_defineProperty(_assertThisInitialized(_this), "execute", function (instruction, track) {
|
|
68
|
+
_this.track = track;
|
|
69
|
+
if (!instruction) return;
|
|
70
|
+
var _this$split_instructi = _this.split_instruction(instruction),
|
|
71
|
+
opcode = _this$split_instructi.opcode,
|
|
72
|
+
args = _this$split_instructi.args;
|
|
73
|
+
var context = _this.get_context();
|
|
74
|
+
if (!context) return;
|
|
75
|
+
context.add_tx(instruction);
|
|
76
|
+
var chain;
|
|
77
|
+
args = _this.parse_arg(args, opcode === "cursor");
|
|
78
|
+
switch (opcode) {
|
|
79
|
+
case "chain":
|
|
80
|
+
chain = context.account.add_chain(args, context);
|
|
81
|
+
_this.contexts.push(chain);
|
|
82
|
+
chain.append_buffer();
|
|
83
|
+
break;
|
|
84
|
+
case "link":
|
|
85
|
+
chain = context.account.manager.web.get(args);
|
|
86
|
+
if (!chain) {
|
|
87
|
+
console.log("LINKing Failed. - ".concat(args));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
chain.append_buffer();
|
|
91
|
+
_this.contexts.push(chain);
|
|
92
|
+
break;
|
|
93
|
+
case "mine":
|
|
94
|
+
var bloc = context.mine(_assertThisInitialized(_this), true);
|
|
95
|
+
_this.account.buff(bloc, _this.track.pids.slice(-1)[0]);
|
|
96
|
+
break;
|
|
97
|
+
case "pop":
|
|
98
|
+
var blk;
|
|
99
|
+
if (context.txs.length > 1) {
|
|
100
|
+
blk = context.mine(_assertThisInitialized(_this));
|
|
101
|
+
} else {
|
|
102
|
+
blk = context.get_latest_block();
|
|
103
|
+
if (blk) _this.get_context(-2).connections.push(blk);
|
|
104
|
+
context.txs = [];
|
|
105
|
+
}
|
|
106
|
+
blk && _this.account.buff(blk, _this.track.pids.slice(-1)[0]);
|
|
107
|
+
_this.contexts.pop();
|
|
108
|
+
break;
|
|
109
|
+
case "cursor":
|
|
110
|
+
context.set_cursor(args);
|
|
111
|
+
break;
|
|
112
|
+
case "write":
|
|
113
|
+
context.account.write(args, context);
|
|
114
|
+
break;
|
|
115
|
+
default:
|
|
116
|
+
_this.prepare_operation(opcode, context);
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
_this.account = _context.account;
|
|
121
|
+
_this.contexts = [_context];
|
|
122
|
+
_this.stack = new Array();
|
|
123
|
+
return _this;
|
|
124
|
+
}
|
|
125
|
+
return _createClass(Virtual_machine);
|
|
126
|
+
}(_Opcodes2["default"]);
|
|
127
|
+
var _default = Virtual_machine;
|
|
128
|
+
exports["default"] = _default;
|
package/build/add.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ops = void 0;
|
|
7
|
+
var ops = [{
|
|
8
|
+
name: "add",
|
|
9
|
+
sign: "+"
|
|
10
|
+
}, {
|
|
11
|
+
name: "multiply",
|
|
12
|
+
sign: "*"
|
|
13
|
+
}, {
|
|
14
|
+
name: "subtract",
|
|
15
|
+
sign: "-"
|
|
16
|
+
}, {
|
|
17
|
+
name: "divide",
|
|
18
|
+
sign: "/"
|
|
19
|
+
}, {
|
|
20
|
+
name: "exp",
|
|
21
|
+
sign: "**"
|
|
22
|
+
}, {
|
|
23
|
+
name: "equal",
|
|
24
|
+
sign: "=="
|
|
25
|
+
}, {
|
|
26
|
+
name: "not_equal",
|
|
27
|
+
sign: "!="
|
|
28
|
+
}, {
|
|
29
|
+
name: "greater_than",
|
|
30
|
+
sign: ">"
|
|
31
|
+
}, {
|
|
32
|
+
name: "less_than",
|
|
33
|
+
sign: "<"
|
|
34
|
+
}, {
|
|
35
|
+
name: "gte",
|
|
36
|
+
sign: ">="
|
|
37
|
+
}, {
|
|
38
|
+
name: "lte",
|
|
39
|
+
sign: "<="
|
|
40
|
+
}];
|
|
41
|
+
exports.ops = ops;
|