godprotocol 1.0.79 → 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.
Files changed (62) hide show
  1. package/Index.js +8 -14
  2. package/Loader_sequence/main.js +384 -206
  3. package/Objects/Account.js +191 -157
  4. package/Objects/Block.js +60 -58
  5. package/Objects/Blockweb.js +27 -34
  6. package/Objects/Chain.js +115 -118
  7. package/Objects/Explorer.js +30 -37
  8. package/Objects/Filesystem.js +95 -80
  9. package/Objects/Frame.js +43 -48
  10. package/Objects/Manager.js +67 -89
  11. package/Objects/Opcodes.js +43 -36
  12. package/Objects/Oracle.js +63 -40
  13. package/Objects/Virtual_machine.js +135 -127
  14. package/build/Account.js +187 -0
  15. package/build/Block.js +68 -0
  16. package/build/Blockweb.js +36 -0
  17. package/build/Chain.js +119 -0
  18. package/build/Explorer.js +47 -0
  19. package/build/Filesystem.js +127 -0
  20. package/build/Frame.js +52 -0
  21. package/build/Index.js +20 -0
  22. package/build/Manager.js +86 -0
  23. package/build/Opcodes.js +109 -0
  24. package/build/Oracle.js +81 -0
  25. package/build/Virtual_machine.js +136 -0
  26. package/build/add.js +26 -0
  27. package/build/create_server.js +132 -0
  28. package/build/framer.js +59 -0
  29. package/build/functions.js +82 -0
  30. package/build/hash.js +14 -0
  31. package/build/indices.js +31 -0
  32. package/build/jmp.js +19 -0
  33. package/build/main.js +327 -0
  34. package/build/opcodes.js +60 -0
  35. package/build/privacy.js +27 -0
  36. package/build/services.js +50 -0
  37. package/build/std.js +15 -0
  38. package/framer.js +58 -54
  39. package/opcodes/add.js +9 -40
  40. package/opcodes/indices.js +28 -0
  41. package/opcodes/jmp.js +12 -17
  42. package/opcodes/std.js +7 -9
  43. package/opcodes.js +36 -28
  44. package/package.json +4 -3
  45. package/tsconfig.json +8 -0
  46. package/types/Account.d.ts +73 -0
  47. package/types/Block.d.ts +22 -0
  48. package/types/Blockweb.d.ts +14 -0
  49. package/types/Chain.d.ts +35 -0
  50. package/types/Explorer.d.ts +9 -0
  51. package/types/Filesystem.d.ts +23 -0
  52. package/types/Frame.d.ts +14 -0
  53. package/types/Manager.d.ts +21 -0
  54. package/types/Opcodes.d.ts +11 -0
  55. package/types/Oracle.d.ts +17 -0
  56. package/types/Virtual_machine.d.ts +20 -0
  57. package/types/index.d.ts +4 -0
  58. package/utils/create_server.js +88 -108
  59. package/utils/functions.js +31 -43
  60. package/utils/hash.js +10 -11
  61. package/utils/privacy.js +10 -15
  62. package/utils/services.js +32 -33
@@ -1,99 +1,77 @@
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 _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
- 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
- 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
- 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); } }
23
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
24
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
25
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
26
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
27
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
28
- var Manager = /*#__PURE__*/_createClass(function Manager() {
29
- var _this = this;
30
- _classCallCheck(this, Manager);
31
- _defineProperty(this, "start_clock", function () {
32
- var frequency = Number(process.env.HERTS) || 10;
33
- _this.clock = setInterval(function () {
34
- for (var account in _this.tracks) {
35
- var track = _this.tracks[account];
36
- var instruction = track.sequence[track.pointer];
37
- track.account.vm.execute(instruction, track);
38
- track.pointer++;
39
- if (track.pointer === track.sequence.length) {
40
- _this.running--;
41
- track.account.chain.mine(track.account.vm);
42
- track.account.flush_buffer(track.pids.splice(-1)[0]);
43
- delete _this.tracks[account];
1
+ import framer from "../framer";
2
+ import opcodes from "../opcodes";
3
+ import Account from "./Account";
4
+ import Blockweb from "./Blockweb";
5
+ import Oracle from "./Oracle";
6
+
7
+ class Manager {
8
+ constructor() {
9
+ this.accounts = new Object();
10
+ this.running = 0;
11
+ this.tracks = new Object();
12
+ this.web = new Blockweb(this);
13
+ this.oracle = new Oracle(this);
14
+ }
15
+
16
+ start_clock = () => {
17
+ let frequency = Number(process.env.HERTS) || 10;
18
+ this.clock = setInterval(() => {
19
+ for (let account in this.tracks) {
20
+ let track = this.tracks[account];
21
+ let program = track.slice(-1)[0];
22
+
23
+ let instruction = program.sequence[program.pointer];
24
+
25
+ program.account.vm.execute(instruction, program);
26
+ program.pointer++;
27
+
28
+ if (program.pointer === program.sequence.length) {
29
+ program.account.flush_buffer(program.pid);
30
+
31
+ track.pop();
44
32
  }
45
- if (track.breakpoint.slice(-1)[0] === track.pointer) {
46
- track.account.flush_buffer(track.pids.splice(-1)[0]);
33
+ if (!track.length) {
34
+ this.running -= 1;
35
+ delete this.tracks[account];
36
+ program.account.chain.mine(program.account.vm);
47
37
  }
48
38
  }
49
- !_this.running && clearInterval(_this.clock);
39
+
40
+ !this.running && clearInterval(this.clock);
50
41
  }, frequency);
51
- });
52
- _defineProperty(this, "get_account", function (name) {
53
- return _this.accounts[name];
54
- });
55
- _defineProperty(this, "add_account", function (name, meta) {
56
- var account = _this.get_account(name);
42
+ };
43
+
44
+ get_account = (name) => this.accounts[name];
45
+
46
+ add_account = (name, meta) => {
47
+ let account = this.get_account(name);
48
+
57
49
  if (!account) {
58
- account = new _Account["default"](name, _objectSpread(_objectSpread({}, meta), {}, {
59
- manager: _this
60
- }));
61
- (0, _framer["default"])(account);
62
- (0, _opcodes["default"])(account);
63
- _this.accounts[account.name] = account;
64
- } else if (meta && meta["private"] && !account["private"]) {
65
- account["private"] = true;
50
+ account = new Account(name, { ...meta, manager: this });
51
+ opcodes(account);
52
+ framer(account);
53
+
54
+ this.accounts[account.name] = account;
55
+ } else if (meta && meta.private && !account.private) {
56
+ account.private = true;
66
57
  }
58
+
67
59
  return account;
68
- });
69
- _defineProperty(this, "push", function (program) {
70
- var track = _this.tracks[program.account.name];
60
+ };
61
+
62
+ push = (program) => {
63
+ let track = this.tracks[program.account.name];
64
+
71
65
  if (track) {
72
- var _track$sequence;
73
- track.breakpoint.push(track.pointer + program.sequence.length + 1);
74
- (_track$sequence = track.sequence).splice.apply(_track$sequence, [track.pointer + 1, 0].concat(_toConsumableArray(program.sequence)));
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
- }
66
+ track.push({ ...program, pointer: 0 });
81
67
  } else {
82
- track = _objectSpread(_objectSpread({}, program), {}, {
83
- pointer: 0,
84
- pids: [program.pid],
85
- breakpoint: new Array()
86
- });
87
- _this.tracks[track.account.name] = track;
88
- _this.running++;
89
- _this.running === 1 && _this.start_clock();
68
+ track = [{ ...program, pointer: 0 }];
69
+ this.tracks[program.account.name] = track;
70
+
71
+ this.running++;
72
+ this.running === 1 && this.start_clock();
90
73
  }
91
- });
92
- this.accounts = new Object();
93
- this.running = 0;
94
- this.tracks = new Object();
95
- this.web = new _Blockweb["default"](this);
96
- this.oracle = new _Oracle["default"](this);
97
- });
98
- var _default = Manager;
99
- exports["default"] = _default;
74
+ };
75
+ }
76
+
77
+ export default Manager;
@@ -1,39 +1,46 @@
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 _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 Opcodes = /*#__PURE__*/_createClass(function Opcodes() {
16
- var _this = this;
17
- _classCallCheck(this, Opcodes);
18
- _defineProperty(this, "set", function (opcode, circuit) {
19
- _this.opcodes[opcode] = circuit;
20
- _this.account.compiler.opcodes.push(opcode);
21
- });
22
- _defineProperty(this, "prepare_operation", function (opcode, context) {
23
- var circ = _this.opcodes[opcode];
1
+ import { obj } from "../framer";
2
+ import { transpile_object } from "../utils/functions";
3
+
4
+ class Opcodes {
5
+ constructor() {
6
+ this.opcodes = new Object();
7
+ }
8
+
9
+ set = (opcode, circuit) => {
10
+ this.opcodes[opcode] = circuit;
11
+ obj.Opcodes[opcode] = null;
12
+
13
+ this.account.assembler.opcodes.push(opcode);
14
+ };
15
+
16
+ prepare_operation = (opcode, context) => {
17
+ let circ = this.opcodes[opcode];
18
+
24
19
  if (typeof circ !== "function") return;
25
- var buf = context.get_buffer();
26
- var args = buf && context.account.read(buf.inputs);
27
- var res = circ(args);
28
- _this.stdin(res);
29
- });
30
- _defineProperty(this, "stdin", function (object) {
20
+
21
+ let buf = context.get_buffer();
22
+
23
+ let args =
24
+ context.account.read(buf && buf.inputs) ||
25
+ this.account.stdin.splice(-1)[0];
26
+
27
+ let res = circ(args, this);
28
+
29
+ this.stdin(res);
30
+ };
31
+
32
+ stdin = (object, cb) => {
31
33
  if (object == null) return;
32
- var code_string = (0, _functions.transpile_object)(object);
33
- _this.account.compiler.run(code_string, true);
34
+
35
+ this.flags.zero = !object;
36
+ if (typeof object === "number") this.flags.neg = object < 0;
37
+
38
+ let code_string =
39
+ typeof object !== "string" ? JSON.stringify(object) : object;
40
+
41
+ this.account.assembler.run(code_string, { cb, pure: true });
34
42
  // console.log(`Writing in: ${code_string}`);
35
- });
36
- this.opcodes = new Object();
37
- });
38
- var _default = Opcodes;
39
- exports["default"] = _default;
43
+ };
44
+ }
45
+
46
+ export default Opcodes;
package/Objects/Oracle.js CHANGED
@@ -1,42 +1,65 @@
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) { 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 _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; }
14
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
15
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
- var Oracle = /*#__PURE__*/_createClass(function Oracle(mgr) {
17
- var _this = this;
18
- _classCallCheck(this, Oracle);
19
- _defineProperty(this, "set", function (path, _ref) {
20
- var type = _ref.type,
21
- obj = _ref.obj;
22
- _this.datapaths[path] = {
23
- obj: obj,
24
- type: type
25
- };
26
- });
27
- _defineProperty(this, "get", function (path) {
28
- return _this.datapaths[path];
29
- });
30
- _defineProperty(this, "write", function (addr, data) {
31
- var meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
32
- encoding: "utf-8"
1
+ import fs from "fs";
2
+ import GDS from "generalised-datastore";
3
+ import { hash } from "../utils/hash";
4
+
5
+ class Oracle {
6
+ constructor(mgr) {
7
+ this.fs = fs;
8
+ this.mgr = mgr;
9
+ this.datapaths = new Object();
10
+ this.gds = new GDS("godprotocol").sync();
11
+ }
12
+
13
+ set = (path, { type, obj }) => {
14
+ this.datapaths[path] = {
15
+ obj,
16
+ type,
33
17
  };
18
+ };
19
+
20
+ get = (path) => this.datapaths[path];
21
+
22
+ hash = (data) => {
23
+ data = JSON.stringify(data);
24
+ return hash(hash);
25
+ };
26
+
27
+ write = (addr, data, account) => {
34
28
  if (typeof data !== "string") data = JSON.stringify(data);
35
- _this.fs.writeFileSync(addr, data, meta);
36
- });
37
- this.fs = _fs["default"];
38
- this.mgr = mgr;
39
- this.datapaths = new Object();
40
- });
41
- var _default = Oracle;
42
- exports["default"] = _default;
29
+
30
+ let folder = this.gds.folder(
31
+ hash(account.vm.get_context().physical_address)
32
+ );
33
+ folder.write({ data: addr });
34
+
35
+ this.fs.writeFileSync(addr, data, { encoding: "utf-8" });
36
+ };
37
+
38
+ fetch = (payload, callback) => {
39
+ let { physical_address, query, account, signature } = payload,
40
+ result;
41
+
42
+ account = this.mgr.get_account(account);
43
+ if (account && account.private)
44
+ if (!account.validate({ physical_address, query }, signature, callback))
45
+ return;
46
+
47
+ try {
48
+ let operation = this.gds.folder(hash(physical_address))[query.operation];
49
+
50
+ result = operation && operation(query.query, query.options);
51
+
52
+ if (result) {
53
+ if (account) {
54
+ let content = account.read(result.data);
55
+ if (content != null) result.content = content;
56
+ }
57
+ }
58
+ } catch (e) {
59
+ result = { error: true, message: e.message, payload };
60
+ }
61
+ typeof callback === "function" && callback(result);
62
+ };
63
+ }
64
+
65
+ export default Oracle;
@@ -1,128 +1,136 @@
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.pid);
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.pid);
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;
1
+ import Opcodes from "./Opcodes";
2
+
3
+ class Virtual_machine extends Opcodes {
4
+ constructor(context) {
5
+ super();
6
+
7
+ this.account = context.account;
8
+ this.contexts = [context];
9
+ this.stack = new Array();
10
+ this.flags = {
11
+ neg: false,
12
+ equal: false,
13
+ zero: false,
14
+ };
124
15
  }
125
- return _createClass(Virtual_machine);
126
- }(_Opcodes2["default"]);
127
- var _default = Virtual_machine;
128
- exports["default"] = _default;
16
+
17
+ get_context = (index) => {
18
+ return this.contexts.slice(index == null ? -1 : index)[0];
19
+ };
20
+
21
+ parse_arg = (arg, is_cursor) => {
22
+ let context = this.get_context();
23
+
24
+ let args = arg.split("/"),
25
+ i = 0;
26
+
27
+ while (args[0] === "..") {
28
+ i++;
29
+
30
+ args.splice(0, 1);
31
+ }
32
+
33
+ i = (i + 1) * -1;
34
+ context = i ? this.get_context(i) : context;
35
+
36
+ arg = args.join("/");
37
+
38
+ while (arg.includes("^")) {
39
+ let blk = context.connections.slice(-1)[0];
40
+ if (!blk) break;
41
+ context = blk.chain;
42
+ let i = arg.indexOf("^");
43
+ arg = `${arg.slice(0, i)}${arg.slice(i + 1)}`;
44
+ }
45
+
46
+ if (arg.startsWith("{*") && is_cursor) {
47
+ arg = context.explore(arg.slice(2, -1));
48
+ } else if (arg.startsWith("{") && !is_cursor) {
49
+ arg = context.explore(arg.slice(1, -1));
50
+ }
51
+
52
+ return arg;
53
+ };
54
+
55
+ split_instruction = (instruction) => {
56
+ let split = instruction.split(" ");
57
+ let opcode = split[0],
58
+ args = split.slice(1).join(" ");
59
+
60
+ return { opcode, args };
61
+ };
62
+
63
+ execute = (instruction, track) => {
64
+ this.track = track;
65
+
66
+ if (!instruction) return;
67
+
68
+ let { opcode, args } = this.split_instruction(instruction);
69
+
70
+ let context = this.get_context();
71
+
72
+ if (!context) return;
73
+
74
+ context.add_tx(instruction);
75
+
76
+ // console.log(instruction);
77
+
78
+ let chain;
79
+
80
+ args = this.parse_arg(args, opcode === "cursor");
81
+
82
+ switch (opcode) {
83
+ case "chain":
84
+ chain = context.account.add_chain(args, context);
85
+ this.contexts.push(chain);
86
+
87
+ chain.append_buffer();
88
+
89
+ break;
90
+ case "link":
91
+ chain = context.account.manager.web.get(args);
92
+
93
+ if (!chain) {
94
+ console.log(`LINKing Failed. - ${args}`);
95
+ return;
96
+ }
97
+
98
+ chain.append_buffer();
99
+
100
+ this.contexts.push(chain);
101
+
102
+ break;
103
+ case "mine":
104
+ let bloc = context.mine(this, true);
105
+
106
+ this.account.buff(bloc, this.track.pid);
107
+
108
+ break;
109
+ case "pop":
110
+ let blk;
111
+ if (context.txs.length > 1) {
112
+ blk = context.mine(this);
113
+ } else {
114
+ blk = context.get_latest_block();
115
+ if (blk) this.get_context(-2).connections.push(blk);
116
+
117
+ context.txs = [];
118
+ }
119
+ blk && this.account.buff(blk, this.track.pid);
120
+
121
+ this.contexts.pop();
122
+ break;
123
+ case "cursor":
124
+ context.set_cursor(args);
125
+ break;
126
+ case "write":
127
+ context.account.write(args, context);
128
+ break;
129
+ default:
130
+ this.prepare_operation(opcode, context);
131
+ break;
132
+ }
133
+ };
134
+ }
135
+
136
+ export default Virtual_machine;