godprotocol 1.0.79 → 1.0.81
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/Index.js +6 -1
- package/Loader_sequence/main.js +52 -8
- package/Objects/Account.js +33 -8
- package/Objects/Block.js +4 -1
- package/Objects/Filesystem.js +1 -1
- package/Objects/Manager.js +19 -32
- package/Objects/Opcodes.js +86 -17
- package/Objects/Oracle.js +44 -5
- package/Objects/Virtual_machine.js +8 -0
- package/framer.js +36 -34
- package/opcodes/add.js +0 -15
- package/opcodes/indices.js +31 -0
- package/opcodes/jmp.js +13 -13
- package/opcodes/std.js +5 -1
- package/opcodes.js +20 -2
- package/package.json +4 -3
- package/readme.md +4 -4
- package/tsconfig.json +8 -0
- 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 +78 -65
- package/.babelrc +0 -3
package/Index.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "create_server", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _create_server["default"];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
exports.initiator = exports["default"] = void 0;
|
|
7
13
|
var _Manager = _interopRequireDefault(require("./Objects/Manager"));
|
|
8
14
|
var _create_server = _interopRequireDefault(require("./utils/create_server"));
|
|
@@ -10,6 +16,5 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default":
|
|
|
10
16
|
var manager = new _Manager["default"]();
|
|
11
17
|
var initiator = manager.add_account(process.env.INITIATOR || "initiator");
|
|
12
18
|
exports.initiator = initiator;
|
|
13
|
-
(0, _create_server["default"])(initiator);
|
|
14
19
|
var _default = manager;
|
|
15
20
|
exports["default"] = _default;
|
package/Loader_sequence/main.js
CHANGED
|
@@ -194,14 +194,17 @@ var Loader = /*#__PURE__*/_createClass(function Loader(account) {
|
|
|
194
194
|
_this.push_instruction(["cursor {output}", "write ".concat(_this.is_not_literal(prev_token && prev_token.type) ? "{metadata.output:-1}" : "{datapath:-1}"), "pop ".concat(identifier.value)]);
|
|
195
195
|
} else _this.push_instruction("pop ".concat(identifier.value));
|
|
196
196
|
});
|
|
197
|
+
_defineProperty(this, "marker_pattern", /@[a-zA-Z_][a-zA-Z0-9_]*/);
|
|
197
198
|
_defineProperty(this, "parse_opcode", function (line) {
|
|
198
199
|
var tokens = Array.isArray(line) ? line : _this.parse_tokens(line);
|
|
199
200
|
var op = tokens[0];
|
|
200
201
|
if (op.type !== "opcode") return _this.parse(op);
|
|
201
202
|
_this.push_instruction(["link Accounts/".concat(_this.account.name, "/Opcodes/").concat(op.value), "link Accounts/".concat(_this.account.name, "/Datatypes/Twain")]);
|
|
202
203
|
tokens.slice(1).map(function (tok, i) {
|
|
203
|
-
_this.
|
|
204
|
-
|
|
204
|
+
if (tok.type === "address" && tok.value.match(_this.marker_pattern)) {
|
|
205
|
+
_this.push_instruction(["link ".concat(_this.account.physical_address, "/Datatypes/Number"), "write ".concat(tok.value), "pop Number"]);
|
|
206
|
+
} else _this.parse(tok);
|
|
207
|
+
_this.push_instruction(["cursor op".concat(i), "write ".concat(_this.is_not_literal(tok.type) && !(tok.type === "address" && tok.value.match(_this.marker_pattern)) ? "{metadata.output:-1}" : "{datapath:-1}")]);
|
|
205
208
|
});
|
|
206
209
|
_this.push_instruction(["pop Twain", "cursor inputs", "write {datapath:-1}", op.value, "cursor {output}", "write {datapath:-1}", "pop ".concat(op.value)]);
|
|
207
210
|
});
|
|
@@ -246,19 +249,59 @@ var Loader = /*#__PURE__*/_createClass(function Loader(account) {
|
|
|
246
249
|
(_this$instructions = _this.instructions).push.apply(_this$instructions, _toConsumableArray(_this.instruction_stacks.splice(-1)[0]));
|
|
247
250
|
_this.instruction_indexes.pop();
|
|
248
251
|
});
|
|
252
|
+
_defineProperty(this, "revamp_marks", function () {
|
|
253
|
+
var instruction_stack = _this.instruction_stacks.slice(-1)[0];
|
|
254
|
+
instruction_stack = instruction_stack.map(function (ins) {
|
|
255
|
+
return _this.resolve_offset(ins, true);
|
|
256
|
+
});
|
|
257
|
+
_this.instruction_stacks[_this.instruction_stacks.length - 1] = instruction_stack;
|
|
258
|
+
});
|
|
259
|
+
_defineProperty(this, "handle_marker", function (line) {
|
|
260
|
+
var splits = line.slice(1).split(" ");
|
|
261
|
+
var name = splits[0];
|
|
262
|
+
var curr_stack = _this.stacks.slice(-1)[0];
|
|
263
|
+
var markers = _this.markers[curr_stack];
|
|
264
|
+
if (!markers) {
|
|
265
|
+
markers = new Object();
|
|
266
|
+
_this.markers[curr_stack] = markers;
|
|
267
|
+
}
|
|
268
|
+
markers[name] = _this.instruction_index();
|
|
269
|
+
_this.revamp_marks();
|
|
270
|
+
return splits.slice(1).join(" ");
|
|
271
|
+
});
|
|
272
|
+
_defineProperty(this, "resolve_offset", function (line, revamping) {
|
|
273
|
+
var matches = line.match(_this.marker_pattern),
|
|
274
|
+
value;
|
|
275
|
+
if (matches) {
|
|
276
|
+
var match = matches[0].slice(1);
|
|
277
|
+
var curr_stack = _this.stacks.slice(-1)[0];
|
|
278
|
+
var markers = _this.markers[curr_stack];
|
|
279
|
+
if (!markers) {
|
|
280
|
+
markers = new Object();
|
|
281
|
+
_this.markers[curr_stack] = markers;
|
|
282
|
+
}
|
|
283
|
+
value = markers[match];
|
|
284
|
+
}
|
|
285
|
+
if (typeof value === "number") line = line.replace(_this.marker_pattern, (revamping && value > 0 ? value - 1 : value).toString());
|
|
286
|
+
return line;
|
|
287
|
+
});
|
|
249
288
|
_defineProperty(this, "compile", function (codes) {
|
|
250
289
|
var code_array = codes.split("\n");
|
|
251
290
|
for (var c = 0; c < code_array.length; c++) {
|
|
252
291
|
var line = code_array[c].trim();
|
|
253
292
|
if (!line) continue;
|
|
254
|
-
if (line
|
|
293
|
+
if (line.startsWith(":")) {
|
|
294
|
+
line = _this.handle_marker(line);
|
|
295
|
+
if (!line) continue;
|
|
296
|
+
}
|
|
297
|
+
line = _this.resolve_offset(line);
|
|
298
|
+
if (line === ";") _this.pop();else if (line.startsWith(".") || line.startsWith("@")) _this.parse_routine(line);else if (line.startsWith("//")) continue;else if (line.startsWith(">@")) _this.parse_assignment(line, true);else if (line.startsWith(">")) _this.parse_assignment(line);else _this.parse_opcode(line);
|
|
255
299
|
}
|
|
256
300
|
});
|
|
257
|
-
_defineProperty(this, "run", function (codes,
|
|
258
|
-
if (
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
301
|
+
_defineProperty(this, "run", function (codes, meta) {
|
|
302
|
+
if (!meta) meta = {};
|
|
303
|
+
_this.pure = meta && meta.pure;
|
|
304
|
+
var cb = meta && meta.cb;
|
|
262
305
|
_this.compile(codes);
|
|
263
306
|
|
|
264
307
|
// console.log(JSON.stringify(this.instructions, null, 2), "hiya");
|
|
@@ -278,6 +321,7 @@ var Loader = /*#__PURE__*/_createClass(function Loader(account) {
|
|
|
278
321
|
this.instruction_indexes = new Array();
|
|
279
322
|
this.instruction_stacks = [[]];
|
|
280
323
|
this.stacks = new Array(account.physical_address);
|
|
324
|
+
this.markers = new Array();
|
|
281
325
|
});
|
|
282
326
|
var _default = Loader;
|
|
283
327
|
exports["default"] = _default;
|
package/Objects/Account.js
CHANGED
|
@@ -60,7 +60,7 @@ var Account = /*#__PURE__*/function (_Filesystem) {
|
|
|
60
60
|
var instructions = program.instructions,
|
|
61
61
|
account = program.account;
|
|
62
62
|
account = _this.get_account(account);
|
|
63
|
-
if (!account.validate(program, signature)) return;
|
|
63
|
+
if (!account.validate(program, signature, callback)) return;
|
|
64
64
|
var pid = account.manage_buffer(callback);
|
|
65
65
|
_this.manager.push({
|
|
66
66
|
sequence: instructions,
|
|
@@ -76,7 +76,11 @@ var Account = /*#__PURE__*/function (_Filesystem) {
|
|
|
76
76
|
account = payload.account,
|
|
77
77
|
query = payload.query;
|
|
78
78
|
account = _this.get_account(account);
|
|
79
|
-
if (!account.validate(payload, signature)) return
|
|
79
|
+
if (!account.validate(payload, signature)) return _this.run_callback(callback, {
|
|
80
|
+
"private": account["private"],
|
|
81
|
+
error: true,
|
|
82
|
+
error_message: "Invalid signature"
|
|
83
|
+
});
|
|
80
84
|
var chain = account.manager.web.get(physical_address);
|
|
81
85
|
if (!chain) return _this.run_callback(callback, {
|
|
82
86
|
error: true,
|
|
@@ -93,7 +97,7 @@ var Account = /*#__PURE__*/function (_Filesystem) {
|
|
|
93
97
|
account = payload.account,
|
|
94
98
|
query = payload.query;
|
|
95
99
|
account = _this.get_account(account);
|
|
96
|
-
if (!account.validate(payload, signature)) return;
|
|
100
|
+
if (!account.validate(payload, signature, callback)) return;
|
|
97
101
|
var pid = account.manage_buffer(callback);
|
|
98
102
|
var context = physical_address ? _this.manager.web.get(physical_address) : account.vm.get_context();
|
|
99
103
|
if (!context) return account.flush_buffer(pid);
|
|
@@ -113,13 +117,32 @@ var Account = /*#__PURE__*/function (_Filesystem) {
|
|
|
113
117
|
setTimeout(function () {
|
|
114
118
|
if (!callback) return;
|
|
115
119
|
if (typeof callback === "function") return callback(payload);
|
|
116
|
-
_this.vm.stdin(payload)
|
|
117
|
-
|
|
120
|
+
callback.payload && callback.payload.physical_address && _this.vm.stdin(payload, function () {
|
|
121
|
+
return _this.run(callback);
|
|
122
|
+
});
|
|
118
123
|
}, 0);
|
|
119
124
|
});
|
|
120
|
-
_defineProperty(_assertThisInitialized(_this), "
|
|
125
|
+
_defineProperty(_assertThisInitialized(_this), "flush_stdout", function (block) {
|
|
126
|
+
for (var s = 0; s < _this.stdout.length; s++) {
|
|
127
|
+
var out = _this.stdout[s];
|
|
128
|
+
if (out.pid === _this.vm.track.pid) {
|
|
129
|
+
block.metadata.stdout.push(out.data);
|
|
130
|
+
_this.stdout[s] = null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
_this.stdout = _this.stdout.filter(function (out) {
|
|
134
|
+
return !!out;
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
_defineProperty(_assertThisInitialized(_this), "validate", function (payload, signature, callback) {
|
|
121
138
|
if (!_this["private"]) return true;
|
|
122
|
-
|
|
139
|
+
var valid = (0, _privacy["default"])(_this.name, JSON.stringify(payload), signature);
|
|
140
|
+
if (!valid && callback) _this.run_callback(callback, {
|
|
141
|
+
"private": _this["private"],
|
|
142
|
+
error: true,
|
|
143
|
+
error_message: "Invalid signature"
|
|
144
|
+
});
|
|
145
|
+
return valid;
|
|
123
146
|
});
|
|
124
147
|
_defineProperty(_assertThisInitialized(_this), "stringify", function (str) {
|
|
125
148
|
var obj = {};
|
|
@@ -145,11 +168,13 @@ var Account = /*#__PURE__*/function (_Filesystem) {
|
|
|
145
168
|
_this["private"] = _meta["private"];
|
|
146
169
|
_this.manager = _meta.manager;
|
|
147
170
|
_this.account = _assertThisInitialized(_this);
|
|
171
|
+
_this.stdin = new Array();
|
|
172
|
+
_this.stdout = new Array();
|
|
148
173
|
if (!_this.manager) throw new Error("Manager instance missing.");
|
|
149
174
|
_this.name_hash();
|
|
150
175
|
_this.physical_address = "".concat(_this.base_address, "/").concat(_this.name);
|
|
151
176
|
_this.set_paths(_assertThisInitialized(_this));
|
|
152
|
-
_this.
|
|
177
|
+
_this.assembler = new _main["default"](_assertThisInitialized(_this));
|
|
153
178
|
_this.chain = _this.account_chain(_assertThisInitialized(_this));
|
|
154
179
|
_this.vm = new _Virtual_machine["default"](_this.chain);
|
|
155
180
|
_this.mine_buffer = {};
|
package/Objects/Block.js
CHANGED
|
@@ -32,6 +32,8 @@ var Block = /*#__PURE__*/_createClass(function Block(chain) {
|
|
|
32
32
|
_this.metadata[curs.slice(1, -1)] = content[curs];
|
|
33
33
|
delete content[curs];
|
|
34
34
|
}
|
|
35
|
+
_this.metadata.stdout = new Array();
|
|
36
|
+
_this.chain.account.flush_stdout(_this);
|
|
35
37
|
var datapath = _this.chain.account.save(content, _this.chain);
|
|
36
38
|
_this.datapath = datapath;
|
|
37
39
|
});
|
|
@@ -46,7 +48,8 @@ var Block = /*#__PURE__*/_createClass(function Block(chain) {
|
|
|
46
48
|
obj.children = _this.children.map(function (ch) {
|
|
47
49
|
return new Object({
|
|
48
50
|
hash: ch.hash,
|
|
49
|
-
chain: ch.chain.hash
|
|
51
|
+
chain: ch.chain.hash,
|
|
52
|
+
physical_address: ch.chain.physical_address
|
|
50
53
|
});
|
|
51
54
|
});
|
|
52
55
|
obj.chain = {
|
package/Objects/Filesystem.js
CHANGED
|
@@ -61,7 +61,7 @@ var Filesystem = /*#__PURE__*/_createClass(function Filesystem() {
|
|
|
61
61
|
if (just_obj) return obj;
|
|
62
62
|
addr = "".concat(chain.path, "/").concat((0, _hash.hash)(JSON.stringify(obj)));
|
|
63
63
|
_this;
|
|
64
|
-
if (obj != null) _this.manager.oracle.write(addr, obj);
|
|
64
|
+
if (obj != null) _this.manager.oracle.write(addr, obj, _this.account);
|
|
65
65
|
_this.manager.oracle.set(addr, {
|
|
66
66
|
obj: obj,
|
|
67
67
|
type: type
|
package/Objects/Manager.js
CHANGED
|
@@ -11,12 +11,6 @@ var _Blockweb = _interopRequireDefault(require("./Blockweb"));
|
|
|
11
11
|
var _Oracle = _interopRequireDefault(require("./Oracle"));
|
|
12
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
13
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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
15
|
-
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."); }
|
|
16
|
-
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; } }
|
|
17
|
-
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
18
|
-
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
19
|
-
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; }
|
|
20
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; }
|
|
21
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; }
|
|
22
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); } }
|
|
@@ -33,17 +27,18 @@ var Manager = /*#__PURE__*/_createClass(function Manager() {
|
|
|
33
27
|
_this.clock = setInterval(function () {
|
|
34
28
|
for (var account in _this.tracks) {
|
|
35
29
|
var track = _this.tracks[account];
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
track.
|
|
43
|
-
delete _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();
|
|
44
37
|
}
|
|
45
|
-
if (track.
|
|
46
|
-
|
|
38
|
+
if (!track.length) {
|
|
39
|
+
_this.running -= 1;
|
|
40
|
+
delete _this.tracks[account];
|
|
41
|
+
program.account.chain.mine(program.account.vm);
|
|
47
42
|
}
|
|
48
43
|
}
|
|
49
44
|
!_this.running && clearInterval(_this.clock);
|
|
@@ -58,8 +53,8 @@ var Manager = /*#__PURE__*/_createClass(function Manager() {
|
|
|
58
53
|
account = new _Account["default"](name, _objectSpread(_objectSpread({}, meta), {}, {
|
|
59
54
|
manager: _this
|
|
60
55
|
}));
|
|
61
|
-
(0, _framer["default"])(account);
|
|
62
56
|
(0, _opcodes["default"])(account);
|
|
57
|
+
(0, _framer["default"])(account);
|
|
63
58
|
_this.accounts[account.name] = account;
|
|
64
59
|
} else if (meta && meta["private"] && !account["private"]) {
|
|
65
60
|
account["private"] = true;
|
|
@@ -69,22 +64,14 @@ var Manager = /*#__PURE__*/_createClass(function Manager() {
|
|
|
69
64
|
_defineProperty(this, "push", function (program) {
|
|
70
65
|
var track = _this.tracks[program.account.name];
|
|
71
66
|
if (track) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
track.pids.push(program.pid);
|
|
76
|
-
if (!_this.running) {
|
|
77
|
-
_this.running++;
|
|
78
|
-
_this.tracks[program.account.name] = track;
|
|
79
|
-
_this.start_clock();
|
|
80
|
-
}
|
|
67
|
+
track.push(_objectSpread(_objectSpread({}, program), {}, {
|
|
68
|
+
pointer: 0
|
|
69
|
+
}));
|
|
81
70
|
} else {
|
|
82
|
-
track = _objectSpread(_objectSpread({}, program), {}, {
|
|
83
|
-
pointer: 0
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
87
|
-
_this.tracks[track.account.name] = track;
|
|
71
|
+
track = [_objectSpread(_objectSpread({}, program), {}, {
|
|
72
|
+
pointer: 0
|
|
73
|
+
})];
|
|
74
|
+
_this.tracks[program.account.name] = track;
|
|
88
75
|
_this.running++;
|
|
89
76
|
_this.running === 1 && _this.start_clock();
|
|
90
77
|
}
|
package/Objects/Opcodes.js
CHANGED
|
@@ -1,39 +1,108 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
4
|
+
value: true,
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
var
|
|
8
|
-
function _typeof(o) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
var _framer = require("../framer");
|
|
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() {
|
|
16
76
|
var _this = this;
|
|
17
77
|
_classCallCheck(this, Opcodes);
|
|
18
78
|
_defineProperty(this, "set", function (opcode, circuit) {
|
|
19
79
|
_this.opcodes[opcode] = circuit;
|
|
20
|
-
|
|
80
|
+
_framer.obj.Opcodes[opcode] = null;
|
|
81
|
+
_this.account.assembler.opcodes.push(opcode);
|
|
21
82
|
});
|
|
22
83
|
_defineProperty(this, "prepare_operation", function (opcode, context) {
|
|
23
84
|
var circ = _this.opcodes[opcode];
|
|
24
85
|
if (typeof circ !== "function") return;
|
|
25
86
|
var buf = context.get_buffer();
|
|
26
|
-
var args =
|
|
27
|
-
|
|
87
|
+
var args =
|
|
88
|
+
context.account.read(buf && buf.inputs) ||
|
|
89
|
+
_this.account.stdin.splice(-1)[0];
|
|
90
|
+
var res = circ(args, _this);
|
|
28
91
|
_this.stdin(res);
|
|
29
92
|
});
|
|
30
|
-
_defineProperty(this, "stdin", function (object) {
|
|
93
|
+
_defineProperty(this, "stdin", function (object, cb) {
|
|
31
94
|
if (object == null) return;
|
|
32
|
-
|
|
33
|
-
_this.
|
|
95
|
+
_this.flags.zero = !object;
|
|
96
|
+
if (typeof object === "number") _this.flags.neg = object < 0;
|
|
97
|
+
var code_string =
|
|
98
|
+
typeof object !== "string" ? JSON.stringify(object) : object;
|
|
99
|
+
_this.account.assembler.run(code_string, {
|
|
100
|
+
cb: cb,
|
|
101
|
+
pure: true,
|
|
102
|
+
});
|
|
34
103
|
// console.log(`Writing in: ${code_string}`);
|
|
35
104
|
});
|
|
36
105
|
this.opcodes = new Object();
|
|
37
106
|
});
|
|
38
107
|
var _default = Opcodes;
|
|
39
|
-
exports["default"] = _default;
|
|
108
|
+
exports["default"] = _default;
|
package/Objects/Oracle.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
+
var _generalisedDatastore = _interopRequireDefault(require("generalised-datastore"));
|
|
9
|
+
var _hash = require("../utils/hash");
|
|
8
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
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); }
|
|
10
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); } }
|
|
@@ -27,16 +29,53 @@ var Oracle = /*#__PURE__*/_createClass(function Oracle(mgr) {
|
|
|
27
29
|
_defineProperty(this, "get", function (path) {
|
|
28
30
|
return _this.datapaths[path];
|
|
29
31
|
});
|
|
30
|
-
_defineProperty(this, "
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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) {
|
|
34
37
|
if (typeof data !== "string") data = JSON.stringify(data);
|
|
35
|
-
_this.
|
|
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);
|
|
36
74
|
});
|
|
37
75
|
this.fs = _fs["default"];
|
|
38
76
|
this.mgr = mgr;
|
|
39
77
|
this.datapaths = new Object();
|
|
78
|
+
this.gds = new _generalisedDatastore["default"]("godprotocol").sync();
|
|
40
79
|
});
|
|
41
80
|
var _default = Oracle;
|
|
42
81
|
exports["default"] = _default;
|
|
@@ -73,6 +73,9 @@ var Virtual_machine = /*#__PURE__*/function (_Opcodes) {
|
|
|
73
73
|
var context = _this.get_context();
|
|
74
74
|
if (!context) return;
|
|
75
75
|
context.add_tx(instruction);
|
|
76
|
+
|
|
77
|
+
// console.log(instruction);
|
|
78
|
+
|
|
76
79
|
var chain;
|
|
77
80
|
args = _this.parse_arg(args, opcode === "cursor");
|
|
78
81
|
switch (opcode) {
|
|
@@ -120,6 +123,11 @@ var Virtual_machine = /*#__PURE__*/function (_Opcodes) {
|
|
|
120
123
|
_this.account = _context.account;
|
|
121
124
|
_this.contexts = [_context];
|
|
122
125
|
_this.stack = new Array();
|
|
126
|
+
_this.flags = {
|
|
127
|
+
neg: false,
|
|
128
|
+
equal: false,
|
|
129
|
+
zero: false
|
|
130
|
+
};
|
|
123
131
|
return _this;
|
|
124
132
|
}
|
|
125
133
|
return _createClass(Virtual_machine);
|
package/framer.js
CHANGED
|
@@ -3,48 +3,50 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports["default"] = void 0;
|
|
6
|
+
exports.obj = exports["default"] = void 0;
|
|
7
7
|
var _Frame = _interopRequireDefault(require("./Objects/Frame"));
|
|
8
|
+
var _Opcodes;
|
|
8
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
10
|
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
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; }
|
|
11
12
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
12
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); }
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
14
|
+
var obj = {
|
|
15
|
+
Opcodes: (_Opcodes = {
|
|
16
|
+
add: null,
|
|
17
|
+
equal: null,
|
|
18
|
+
multiply: null,
|
|
19
|
+
subtract: null,
|
|
20
|
+
divide: null,
|
|
21
|
+
exp: null
|
|
22
|
+
}, _defineProperty(_Opcodes, "equal", null), _defineProperty(_Opcodes, "send", null), _defineProperty(_Opcodes, "readonly", null), _defineProperty(_Opcodes, "socket_send", null), _defineProperty(_Opcodes, "jmp", null), _defineProperty(_Opcodes, "stdout", null), _defineProperty(_Opcodes, "stdin", null), _defineProperty(_Opcodes, "run", null), _defineProperty(_Opcodes, "load", null), _defineProperty(_Opcodes, "parse", null), _defineProperty(_Opcodes, "create_account", null), _Opcodes),
|
|
23
|
+
Datatypes: {
|
|
24
|
+
Number: null,
|
|
25
|
+
String: null,
|
|
26
|
+
Twain: null,
|
|
27
|
+
Array: null
|
|
28
|
+
},
|
|
29
|
+
Objects: {
|
|
30
|
+
Blockchain: {
|
|
31
|
+
Chain: null,
|
|
32
|
+
Block: null
|
|
33
|
+
},
|
|
34
|
+
Folder: {
|
|
35
|
+
active_file: null,
|
|
36
|
+
folder: null,
|
|
37
|
+
file: null
|
|
29
38
|
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
Folder: {
|
|
36
|
-
active_file: null,
|
|
37
|
-
folder: null,
|
|
38
|
-
file: null
|
|
39
|
-
},
|
|
40
|
-
File: {
|
|
41
|
-
row: null,
|
|
42
|
-
parse: null,
|
|
43
|
-
column: null,
|
|
44
|
-
write: null
|
|
45
|
-
}
|
|
39
|
+
File: {
|
|
40
|
+
row: null,
|
|
41
|
+
parse: null,
|
|
42
|
+
column: null,
|
|
43
|
+
write: null
|
|
46
44
|
}
|
|
47
|
-
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.obj = obj;
|
|
48
|
+
var framer = function framer(initiator) {
|
|
49
|
+
var frame = new _Frame["default"](obj);
|
|
48
50
|
frame.to_instruction();
|
|
49
51
|
var instructions = frame.flatten_instructions();
|
|
50
52
|
initiator.load({
|
package/opcodes/add.js
CHANGED
|
@@ -22,20 +22,5 @@ var ops = [{
|
|
|
22
22
|
}, {
|
|
23
23
|
name: "equal",
|
|
24
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
25
|
}];
|
|
41
26
|
exports.ops = ops;
|