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.
Files changed (51) hide show
  1. package/.babelrc +3 -0
  2. package/Index.js +8 -19
  3. package/Loader_sequence/main.js +368 -234
  4. package/Objects/Account.js +187 -178
  5. package/Objects/Block.js +60 -61
  6. package/Objects/Blockweb.js +27 -34
  7. package/Objects/Chain.js +115 -118
  8. package/Objects/Explorer.js +30 -37
  9. package/Objects/Filesystem.js +95 -80
  10. package/Objects/Frame.js +43 -48
  11. package/Objects/Manager.js +60 -69
  12. package/Objects/Opcodes.js +39 -101
  13. package/Objects/Oracle.js +50 -66
  14. package/Objects/Virtual_machine.js +132 -132
  15. package/build/Account.js +187 -0
  16. package/build/Block.js +68 -0
  17. package/build/Blockweb.js +36 -0
  18. package/build/Chain.js +119 -0
  19. package/build/Explorer.js +47 -0
  20. package/build/Filesystem.js +127 -0
  21. package/build/Frame.js +52 -0
  22. package/build/Index.js +20 -0
  23. package/build/Manager.js +86 -0
  24. package/build/Opcodes.js +109 -0
  25. package/build/Oracle.js +81 -0
  26. package/build/Virtual_machine.js +136 -0
  27. package/build/add.js +26 -0
  28. package/build/create_server.js +132 -0
  29. package/build/framer.js +59 -0
  30. package/build/functions.js +82 -0
  31. package/build/hash.js +14 -0
  32. package/build/indices.js +31 -0
  33. package/build/jmp.js +19 -0
  34. package/build/main.js +327 -0
  35. package/build/opcodes.js +60 -0
  36. package/build/privacy.js +27 -0
  37. package/build/services.js +50 -0
  38. package/build/std.js +15 -0
  39. package/framer.js +36 -34
  40. package/opcodes/add.js +9 -25
  41. package/opcodes/indices.js +13 -16
  42. package/opcodes/jmp.js +7 -12
  43. package/opcodes/std.js +7 -13
  44. package/opcodes.js +32 -42
  45. package/package.json +1 -1
  46. package/readme.md +4 -4
  47. package/utils/create_server.js +72 -105
  48. package/utils/functions.js +31 -43
  49. package/utils/hash.js +10 -11
  50. package/utils/privacy.js +10 -15
  51. package/utils/services.js +32 -33
@@ -1,136 +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
-
77
- // console.log(instruction);
78
-
79
- var chain;
80
- args = _this.parse_arg(args, opcode === "cursor");
81
- switch (opcode) {
82
- case "chain":
83
- chain = context.account.add_chain(args, context);
84
- _this.contexts.push(chain);
85
- chain.append_buffer();
86
- break;
87
- case "link":
88
- chain = context.account.manager.web.get(args);
89
- if (!chain) {
90
- console.log("LINKing Failed. - ".concat(args));
91
- return;
92
- }
93
- chain.append_buffer();
94
- _this.contexts.push(chain);
95
- break;
96
- case "mine":
97
- var bloc = context.mine(_assertThisInitialized(_this), true);
98
- _this.account.buff(bloc, _this.track.pid);
99
- break;
100
- case "pop":
101
- var blk;
102
- if (context.txs.length > 1) {
103
- blk = context.mine(_assertThisInitialized(_this));
104
- } else {
105
- blk = context.get_latest_block();
106
- if (blk) _this.get_context(-2).connections.push(blk);
107
- context.txs = [];
108
- }
109
- blk && _this.account.buff(blk, _this.track.pid);
110
- _this.contexts.pop();
111
- break;
112
- case "cursor":
113
- context.set_cursor(args);
114
- break;
115
- case "write":
116
- context.account.write(args, context);
117
- break;
118
- default:
119
- _this.prepare_operation(opcode, context);
120
- break;
121
- }
122
- });
123
- _this.account = _context.account;
124
- _this.contexts = [_context];
125
- _this.stack = new Array();
126
- _this.flags = {
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 = {
127
11
  neg: false,
128
12
  equal: false,
129
- zero: false
13
+ zero: false,
130
14
  };
131
- return _this;
132
15
  }
133
- return _createClass(Virtual_machine);
134
- }(_Opcodes2["default"]);
135
- var _default = Virtual_machine;
136
- 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;
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _main = _interopRequireDefault(require("../Loader_sequence/main"));
8
+ var _privacy = _interopRequireDefault(require("../utils/privacy"));
9
+ var _Filesystem2 = _interopRequireDefault(require("./Filesystem"));
10
+ var _Virtual_machine = _interopRequireDefault(require("./Virtual_machine"));
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
12
+ 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); }
13
+ 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); } }
14
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
15
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
16
+ 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); }
17
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
18
+ 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); }; }
19
+ 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); }
20
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
21
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
22
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
23
+ 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; }
24
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
25
+ 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); }
26
+ var Account = /*#__PURE__*/function (_Filesystem) {
27
+ _inherits(Account, _Filesystem);
28
+ var _super = _createSuper(Account);
29
+ function Account(_name) {
30
+ var _this;
31
+ var _meta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
32
+ _classCallCheck(this, Account);
33
+ _this = _super.call(this);
34
+ _defineProperty(_assertThisInitialized(_this), "get_account", function (name) {
35
+ return _this.manager.get_account(name) || _assertThisInitialized(_this);
36
+ });
37
+ _defineProperty(_assertThisInitialized(_this), "manage_buffer", function (callback) {
38
+ var call_session = "".concat(Date.now(), "-").concat(Math.random());
39
+ _this.mine_buffer[call_session] = {
40
+ blocks: [],
41
+ callback: callback
42
+ };
43
+ return call_session;
44
+ });
45
+ _defineProperty(_assertThisInitialized(_this), "buff", function (block, pid) {
46
+ var buffer = _this.mine_buffer[pid];
47
+ if (!buffer) return;
48
+ buffer.blocks.push(block.stringify());
49
+ });
50
+ _defineProperty(_assertThisInitialized(_this), "flush_buffer", function (pid) {
51
+ var buff = _this.mine_buffer[pid];
52
+ if (!buff) return;
53
+ buff.callback && _this.run_callback(buff.callback, buff.blocks);
54
+ delete _this.mine_buffer[pid];
55
+ });
56
+ _defineProperty(_assertThisInitialized(_this), "load", function (_ref) {
57
+ var program = _ref.program,
58
+ signature = _ref.signature,
59
+ callback = _ref.callback;
60
+ var instructions = program.instructions,
61
+ account = program.account;
62
+ account = _this.get_account(account);
63
+ if (!account.validate(program, signature, callback)) return;
64
+ var pid = account.manage_buffer(callback);
65
+ _this.manager.push({
66
+ sequence: instructions,
67
+ account: account,
68
+ pid: pid
69
+ });
70
+ });
71
+ _defineProperty(_assertThisInitialized(_this), "parse", function (_ref2) {
72
+ var payload = _ref2.payload,
73
+ signature = _ref2.signature,
74
+ callback = _ref2.callback;
75
+ var physical_address = payload.physical_address,
76
+ account = payload.account,
77
+ query = payload.query;
78
+ account = _this.get_account(account);
79
+ if (!account.validate(payload, signature)) return _this.run_callback(callback, {
80
+ "private": account["private"],
81
+ error: true,
82
+ error_message: "Invalid signature"
83
+ });
84
+ var chain = account.manager.web.get(physical_address);
85
+ if (!chain) return _this.run_callback(callback, {
86
+ error: true,
87
+ error_message: "Address not found"
88
+ });
89
+ var data = query ? chain.explore(query) : chain;
90
+ _this.run_callback(callback, data && data.stringify());
91
+ });
92
+ _defineProperty(_assertThisInitialized(_this), "run", function (request) {
93
+ var payload = request.payload,
94
+ signature = request.signature,
95
+ callback = request.callback;
96
+ var physical_address = payload.physical_address,
97
+ account = payload.account,
98
+ query = payload.query;
99
+ account = _this.get_account(account);
100
+ if (!account.validate(payload, signature, callback)) return;
101
+ var pid = account.manage_buffer(callback);
102
+ var context = physical_address ? _this.manager.web.get(physical_address) : account.vm.get_context();
103
+ if (!context) return account.flush_buffer(pid);
104
+ var blk = query ? context.explore(query) : context.get_latest_block();
105
+ if (blk && blk.metadata && blk.metadata.program) {
106
+ var program = _this.read(blk.metadata.program);
107
+ account.vm.contexts.push(context);
108
+ program.push("pop");
109
+ Array.isArray(program) && program.length && _this.manager.push({
110
+ sequence: program,
111
+ account: account,
112
+ pid: pid
113
+ });
114
+ } else account.flush_buffer(pid);
115
+ });
116
+ _defineProperty(_assertThisInitialized(_this), "run_callback", function (callback, payload) {
117
+ setTimeout(function () {
118
+ if (!callback) return;
119
+ if (typeof callback === "function") return callback(payload);
120
+ callback.payload && callback.payload.physical_address && _this.vm.stdin(payload, function () {
121
+ return _this.run(callback);
122
+ });
123
+ }, 0);
124
+ });
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) {
138
+ if (!_this["private"]) return true;
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;
146
+ });
147
+ _defineProperty(_assertThisInitialized(_this), "stringify", function (str) {
148
+ var obj = {};
149
+ obj.name = _this.name;
150
+ obj.hash = _this.hash;
151
+ obj.path = _this.path;
152
+ obj["private"] = _this["private"];
153
+ obj.chain = _this.chain.stringify();
154
+ obj.physical_address = _this.physical_address;
155
+ return str ? JSON.stringify(obj) : obj;
156
+ });
157
+ _defineProperty(_assertThisInitialized(_this), "create_account", function (payload) {
158
+ var name = payload.name,
159
+ meta = payload.meta;
160
+ return _this.manager.add_account(name, meta);
161
+ });
162
+ _defineProperty(_assertThisInitialized(_this), "endpoint", function (endpoint, payload) {
163
+ var method = _this[endpoint];
164
+ typeof method === "function" && method(payload);
165
+ });
166
+ _meta = _meta || {};
167
+ _this.name = _name;
168
+ _this["private"] = _meta["private"];
169
+ _this.manager = _meta.manager;
170
+ _this.account = _assertThisInitialized(_this);
171
+ _this.stdin = new Array();
172
+ _this.stdout = new Array();
173
+ if (!_this.manager) throw new Error("Manager instance missing.");
174
+ _this.name_hash();
175
+ _this.physical_address = "".concat(_this.base_address, "/").concat(_this.name);
176
+ _this.set_paths(_assertThisInitialized(_this));
177
+ _this.assembler = new _main["default"](_assertThisInitialized(_this));
178
+ _this.chain = _this.account_chain(_assertThisInitialized(_this));
179
+ _this.vm = new _Virtual_machine["default"](_this.chain);
180
+ _this.mine_buffer = {};
181
+ console.log("Account Instance: ".concat(_this.name));
182
+ return _this;
183
+ }
184
+ return _createClass(Account);
185
+ }(_Filesystem2["default"]);
186
+ var _default = Account;
187
+ exports["default"] = _default;
package/build/Block.js ADDED
@@ -0,0 +1,68 @@
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 Block = /*#__PURE__*/_createClass(function Block(chain) {
16
+ var _this = this;
17
+ _classCallCheck(this, Block);
18
+ _defineProperty(this, "generate_hash", function () {
19
+ _this.previous_hash = _this.chain.get_latest_block();
20
+ if (_this.previous_hash) _this.previous_hash = _this.previous_hash.hash;
21
+ _this.hash = (0, _hash.hash)(JSON.stringify(_this.data));
22
+ });
23
+ _defineProperty(this, "store", function (no_curs) {
24
+ var content = _this.chain.buffs.splice(-1)[0];
25
+ if (!no_curs) _this.cursor = _this.chain.cursors.splice(-1)[0];
26
+ if (!content) return;
27
+ var cursors = Object.keys(content).filter(function (c) {
28
+ return c.startsWith("{") && c.endsWith("}");
29
+ });
30
+ for (var c = 0; c < cursors.length; c++) {
31
+ var curs = cursors[c];
32
+ _this.metadata[curs.slice(1, -1)] = content[curs];
33
+ delete content[curs];
34
+ }
35
+ _this.metadata.stdout = new Array();
36
+ _this.chain.account.flush_stdout(_this);
37
+ var datapath = _this.chain.account.save(content, _this.chain);
38
+ _this.datapath = datapath;
39
+ });
40
+ _defineProperty(this, "stringify", function (str) {
41
+ var obj = {};
42
+ obj.metadata = _this.metadata;
43
+ obj.datapath = _this.datapath;
44
+ obj.timelapse = _this.timelapse;
45
+ obj.index = _this.index;
46
+ obj.hash = _this.hash;
47
+ obj.data = _this.data;
48
+ obj.children = _this.children.map(function (ch) {
49
+ return new Object({
50
+ hash: ch.hash,
51
+ chain: ch.chain.hash,
52
+ physical_address: ch.chain.physical_address
53
+ });
54
+ });
55
+ obj.chain = {
56
+ hash: _this.chain.hash,
57
+ physical_address: _this.chain.physical_address
58
+ };
59
+ return str ? JSON.stringify(obj) : obj;
60
+ });
61
+ this.chain = chain;
62
+ this.data = this.chain.txs;
63
+ this.metadata = {};
64
+ this.children = new Array();
65
+ this.index = this.chain.blocks.length;
66
+ });
67
+ var _default = Block;
68
+ exports["default"] = _default;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _Chain = _interopRequireDefault(require("./Chain"));
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 Blockweb = /*#__PURE__*/_createClass(function Blockweb(mgr) {
17
+ var _this = this;
18
+ _classCallCheck(this, Blockweb);
19
+ _defineProperty(this, "get", function (addr) {
20
+ var hash = _this.physical_addresses[addr];
21
+ var chain = _this.chains[hash];
22
+ return chain;
23
+ });
24
+ _defineProperty(this, "set", function (parent, name) {
25
+ var chain = new _Chain["default"](parent, name);
26
+ _this.chains[chain.hash] = chain;
27
+ _this.physical_addresses[chain.physical_address] = chain.hash;
28
+ _this.chains[chain.hash] = chain;
29
+ return chain;
30
+ });
31
+ this.mgr = mgr;
32
+ this.physical_addresses = new Object();
33
+ this.chains = new Object();
34
+ });
35
+ var _default = Blockweb;
36
+ exports["default"] = _default;