godprotocol 1.0.796 → 1.0.798

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 (61) hide show
  1. package/.babelrc +3 -0
  2. package/Index.js +8 -21
  3. package/Loader_sequence/main.js +259 -358
  4. package/Objects/Account.js +178 -337
  5. package/Objects/Block.js +53 -58
  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 +68 -77
  12. package/Objects/Opcodes.js +32 -97
  13. package/Objects/Oracle.js +23 -39
  14. package/Objects/Virtual_machine.js +125 -261
  15. package/build/Account.js +162 -0
  16. package/build/Block.js +65 -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 +15 -0
  23. package/build/Manager.js +99 -0
  24. package/build/Opcodes.js +39 -0
  25. package/build/Oracle.js +42 -0
  26. package/build/Virtual_machine.js +128 -0
  27. package/build/add.js +41 -0
  28. package/build/create_server.js +119 -0
  29. package/build/framer.js +57 -0
  30. package/build/functions.js +82 -0
  31. package/build/hash.js +14 -0
  32. package/build/jmp.js +19 -0
  33. package/build/main.js +283 -0
  34. package/build/opcodes.js +42 -0
  35. package/build/privacy.js +27 -0
  36. package/build/services.js +50 -0
  37. package/build/std.js +11 -0
  38. package/framer.js +39 -31
  39. package/opcodes/add.js +14 -40
  40. package/opcodes/jmp.js +10 -14
  41. package/opcodes/std.js +5 -9
  42. package/opcodes.js +25 -29
  43. package/package.json +3 -3
  44. package/readme.md +71 -95
  45. package/types/Account.d.ts +73 -0
  46. package/types/Block.d.ts +22 -0
  47. package/types/Blockweb.d.ts +14 -0
  48. package/types/Chain.d.ts +35 -0
  49. package/types/Explorer.d.ts +9 -0
  50. package/types/Filesystem.d.ts +23 -0
  51. package/types/Frame.d.ts +14 -0
  52. package/types/Manager.d.ts +21 -0
  53. package/types/Opcodes.d.ts +11 -0
  54. package/types/Oracle.d.ts +17 -0
  55. package/types/Virtual_machine.d.ts +20 -0
  56. package/types/index.d.ts +4 -0
  57. package/utils/create_server.js +65 -622
  58. package/utils/functions.js +31 -43
  59. package/utils/hash.js +10 -11
  60. package/utils/privacy.js +10 -15
  61. package/utils/services.js +32 -33
@@ -1,342 +1,183 @@
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) {
12
- return e && e.__esModule ? e : { default: e };
13
- }
14
- function _typeof(o) {
15
- "@babel/helpers - typeof";
16
- return (
17
- (_typeof =
18
- "function" == typeof Symbol && "symbol" == typeof Symbol.iterator
19
- ? function (o) {
20
- return typeof o;
21
- }
22
- : function (o) {
23
- return o &&
24
- "function" == typeof Symbol &&
25
- o.constructor === Symbol &&
26
- o !== Symbol.prototype
27
- ? "symbol"
28
- : typeof o;
29
- }),
30
- _typeof(o)
31
- );
32
- }
33
- function _defineProperties(e, r) {
34
- for (var t = 0; t < r.length; t++) {
35
- var o = r[t];
36
- (o.enumerable = o.enumerable || !1),
37
- (o.configurable = !0),
38
- "value" in o && (o.writable = !0),
39
- Object.defineProperty(e, _toPropertyKey(o.key), o);
1
+ import Loader_sequence from "../Loader_sequence/main";
2
+ import validate_signature from "../utils/privacy";
3
+ import Filesystem from "./Filesystem";
4
+ import Virtual_machine from "./Virtual_machine";
5
+
6
+ class Account extends Filesystem {
7
+ constructor(name, meta = {}) {
8
+ super();
9
+
10
+ meta = meta || {};
11
+
12
+ this.name = name;
13
+ this.private = meta.private;
14
+ this.manager = meta.manager;
15
+ this.account = this;
16
+
17
+ if (!this.manager) throw new Error("Manager instance missing.");
18
+
19
+ this.name_hash();
20
+ this.physical_address = `${this.base_address}/${this.name}`;
21
+ this.set_paths(this);
22
+
23
+ this.compiler = new Loader_sequence(this);
24
+
25
+ this.chain = this.account_chain(this);
26
+ this.vm = new Virtual_machine(this.chain);
27
+
28
+ this.mine_buffer = {};
29
+
30
+ console.log(`Account Instance: ${this.name}`);
40
31
  }
41
- }
42
- function _createClass(e, r, t) {
43
- return (
44
- r && _defineProperties(e.prototype, r),
45
- t && _defineProperties(e, t),
46
- Object.defineProperty(e, "prototype", { writable: !1 }),
47
- e
48
- );
49
- }
50
- function _classCallCheck(a, n) {
51
- if (!(a instanceof n))
52
- throw new TypeError("Cannot call a class as a function");
53
- }
54
- function _inherits(t, e) {
55
- if ("function" != typeof e && null !== e)
56
- throw new TypeError("Super expression must either be null or a function");
57
- (t.prototype = Object.create(e && e.prototype, {
58
- constructor: { value: t, writable: !0, configurable: !0 },
59
- })),
60
- Object.defineProperty(t, "prototype", { writable: !1 }),
61
- e && _setPrototypeOf(t, e);
62
- }
63
- function _setPrototypeOf(t, e) {
64
- return (
65
- (_setPrototypeOf = Object.setPrototypeOf
66
- ? Object.setPrototypeOf.bind()
67
- : function (t, e) {
68
- return (t.__proto__ = e), t;
69
- }),
70
- _setPrototypeOf(t, e)
71
- );
72
- }
73
- function _createSuper(t) {
74
- var r = _isNativeReflectConstruct();
75
- return function () {
76
- var e,
77
- o = _getPrototypeOf(t);
78
- if (r) {
79
- var s = _getPrototypeOf(this).constructor;
80
- e = Reflect.construct(o, arguments, s);
81
- } else e = o.apply(this, arguments);
82
- return _possibleConstructorReturn(this, e);
32
+
33
+ get_account = (name) => {
34
+ return this.manager.get_account(name) || this;
83
35
  };
84
- }
85
- function _possibleConstructorReturn(t, e) {
86
- if (e && ("object" == _typeof(e) || "function" == typeof e)) return e;
87
- if (void 0 !== e)
88
- throw new TypeError(
89
- "Derived constructors may only return object or undefined"
90
- );
91
- return _assertThisInitialized(t);
92
- }
93
- function _assertThisInitialized(e) {
94
- if (void 0 === e)
95
- throw new ReferenceError(
96
- "this hasn't been initialised - super() hasn't been called"
97
- );
98
- return e;
99
- }
100
- function _isNativeReflectConstruct() {
101
- try {
102
- var t = !Boolean.prototype.valueOf.call(
103
- Reflect.construct(Boolean, [], function () {})
104
- );
105
- } catch (t) {}
106
- return (_isNativeReflectConstruct = function _isNativeReflectConstruct() {
107
- return !!t;
108
- })();
109
- }
110
- function _getPrototypeOf(t) {
111
- return (
112
- (_getPrototypeOf = Object.setPrototypeOf
113
- ? Object.getPrototypeOf.bind()
114
- : function (t) {
115
- return t.__proto__ || Object.getPrototypeOf(t);
116
- }),
117
- _getPrototypeOf(t)
118
- );
119
- }
120
- function _defineProperty(e, r, t) {
121
- return (
122
- (r = _toPropertyKey(r)) in e
123
- ? Object.defineProperty(e, r, {
124
- value: t,
125
- enumerable: !0,
126
- configurable: !0,
127
- writable: !0,
128
- })
129
- : (e[r] = t),
130
- e
131
- );
132
- }
133
- function _toPropertyKey(t) {
134
- var i = _toPrimitive(t, "string");
135
- return "symbol" == _typeof(i) ? i : i + "";
136
- }
137
- function _toPrimitive(t, r) {
138
- if ("object" != _typeof(t) || !t) return t;
139
- var e = t[Symbol.toPrimitive];
140
- if (void 0 !== e) {
141
- var i = e.call(t, r || "default");
142
- if ("object" != _typeof(i)) return i;
143
- throw new TypeError("@@toPrimitive must return a primitive value.");
144
- }
145
- return ("string" === r ? String : Number)(t);
146
- }
147
- var Account = /*#__PURE__*/ (function (_Filesystem) {
148
- _inherits(Account, _Filesystem);
149
- var _super = _createSuper(Account);
150
- function Account(_name) {
151
- var _this;
152
- var _meta =
153
- arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
154
- _classCallCheck(this, Account);
155
- _this = _super.call(this);
156
- _defineProperty(
157
- _assertThisInitialized(_this),
158
- "get_account",
159
- function (name) {
160
- return _this.manager.get_account(name) || _assertThisInitialized(_this);
161
- }
162
- );
163
- _defineProperty(
164
- _assertThisInitialized(_this),
165
- "manage_buffer",
166
- function (callback) {
167
- var call_session = "".concat(Date.now(), "-").concat(Math.random());
168
- _this.mine_buffer[call_session] = {
169
- blocks: [],
170
- callback: callback,
171
- };
172
- return call_session;
173
- }
174
- );
175
- _defineProperty(
176
- _assertThisInitialized(_this),
177
- "buff",
178
- function (block, pid) {
179
- var buffer = _this.mine_buffer[pid];
180
- if (!buffer) return;
181
- buffer.blocks.push(block.stringify());
182
- }
183
- );
184
- _defineProperty(
185
- _assertThisInitialized(_this),
186
- "flush_buffer",
187
- function (pid) {
188
- var buff = _this.mine_buffer[pid];
189
- if (!buff) return;
190
- buff.callback && _this.run_callback(buff.callback, buff.blocks);
191
- delete _this.mine_buffer[pid];
192
- }
193
- );
194
- _defineProperty(_assertThisInitialized(_this), "load", function (_ref) {
195
- var program = _ref.program,
196
- signature = _ref.signature,
197
- callback = _ref.callback;
198
- var instructions = program.instructions,
199
- account = program.account;
200
- account = _this.get_account(account);
201
- if (!account.validate(program, signature, callback)) return;
202
- var pid = account.manage_buffer(callback);
203
- _this.manager.push({
204
- sequence: instructions,
205
- account: account,
206
- pid: pid,
36
+
37
+ manage_buffer = (callback) => {
38
+ let call_session = `${Date.now()}-${Math.random()}`;
39
+ this.mine_buffer[call_session] = { blocks: [], callback };
40
+
41
+ return call_session;
42
+ };
43
+
44
+ buff = (block, pid) => {
45
+ let buffer = this.mine_buffer[pid];
46
+ if (!buffer) return;
47
+
48
+ buffer.blocks.push(block.stringify());
49
+ };
50
+
51
+ flush_buffer = (pid) => {
52
+ let buff = this.mine_buffer[pid];
53
+ if (!buff) return;
54
+
55
+ buff.callback && this.run_callback(buff.callback, buff.blocks);
56
+ delete this.mine_buffer[pid];
57
+ };
58
+
59
+ load = ({ program, signature, callback }) => {
60
+ let { instructions, account } = program;
61
+ account = this.get_account(account);
62
+
63
+ if (!account.validate(payload, signature, callback)) return;
64
+
65
+ let pid = account.manage_buffer(callback);
66
+
67
+ this.manager.push({ sequence: instructions, account, pid });
68
+ };
69
+
70
+ parse = ({ payload, signature, callback }) => {
71
+ let { physical_address, account, query } = payload;
72
+ account = this.get_account(account);
73
+
74
+ if (!account.validate(payload, signature))
75
+ return this.run_callback(callback, {
76
+ private: account.private,
77
+ error: true,
78
+ error_message: "Invalid signature",
207
79
  });
208
- });
209
- _defineProperty(_assertThisInitialized(_this), "parse", function (_ref2) {
210
- var payload = _ref2.payload,
211
- signature = _ref2.signature,
212
- callback = _ref2.callback;
213
- var physical_address = payload.physical_address,
214
- account = payload.account,
215
- query = payload.query;
216
- account = _this.get_account(account);
217
- if (!account.validate(payload, signature))
218
- return _this.run_callback(callback, {
219
- private: account["private"],
220
- error: true,
221
- error_message: "Invalid signature",
222
- });
223
- var chain = account.manager.web.get(physical_address);
224
- if (!chain)
225
- return _this.run_callback(callback, {
226
- error: true,
227
- error_message: "Address not found",
80
+
81
+ let chain = account.manager.web.get(physical_address);
82
+
83
+ if (!chain)
84
+ return this.run_callback(callback, {
85
+ error: true,
86
+ error_message: "Address not found",
87
+ });
88
+
89
+ let data = query ? chain.explore(query) : chain;
90
+
91
+ this.run_callback(callback, data && data.stringify());
92
+ };
93
+
94
+ run = (request) => {
95
+ let { payload, signature, callback } = request;
96
+
97
+ let { physical_address, account, query } = payload;
98
+ account = this.get_account(account);
99
+
100
+ if (!account.validate(payload, signature, callback)) return;
101
+
102
+ let pid = account.manage_buffer(callback);
103
+
104
+ let context = physical_address
105
+ ? this.manager.web.get(physical_address)
106
+ : account.vm.get_context();
107
+
108
+ if (!context) return account.flush_buffer(pid);
109
+
110
+ let blk = query ? context.explore(query) : context.get_latest_block();
111
+
112
+ if (blk && blk.metadata && blk.metadata.program) {
113
+ let program = this.read(blk.metadata.program);
114
+
115
+ account.vm.contexts.push(context);
116
+ program.push("pop");
117
+
118
+ Array.isArray(program) &&
119
+ program.length &&
120
+ this.manager.push({
121
+ sequence: program,
122
+ account,
123
+ pid,
228
124
  });
229
- var data = query ? chain.explore(query) : chain;
230
- _this.run_callback(callback, data && data.stringify());
231
- });
232
- _defineProperty(_assertThisInitialized(_this), "run", function (request) {
233
- var payload = request.payload,
234
- signature = request.signature,
235
- callback = request.callback;
236
- var physical_address = payload.physical_address,
237
- account = payload.account,
238
- query = payload.query;
239
- account = _this.get_account(account);
240
- if (!account.validate(payload, signature, callback)) return;
241
- var pid = account.manage_buffer(callback);
242
- var context = physical_address
243
- ? _this.manager.web.get(physical_address)
244
- : account.vm.get_context();
245
- if (!context) return account.flush_buffer(pid);
246
- var blk = query ? context.explore(query) : context.get_latest_block();
247
- if (blk && blk.metadata && blk.metadata.program) {
248
- var program = _this.read(blk.metadata.program);
249
- account.vm.contexts.push(context);
250
- program.push("pop");
251
- Array.isArray(program) &&
252
- program.length &&
253
- _this.manager.push({
254
- sequence: program,
255
- account: account,
256
- pid: pid,
257
- });
258
- } else account.flush_buffer(pid);
259
- });
260
- _defineProperty(
261
- _assertThisInitialized(_this),
262
- "run_callback",
263
- function (callback, payload) {
264
- setTimeout(function () {
265
- if (!callback) return;
266
- if (typeof callback === "function") return callback(payload);
267
- callback.payload &&
268
- callback.payload.physical_address &&
269
- _this.vm.stdin(payload, function () {
270
- return _this.run(callback);
271
- });
272
- }, 0);
273
- }
274
- );
275
- _defineProperty(
276
- _assertThisInitialized(_this),
277
- "validate",
278
- function (payload, signature, callback) {
279
- if (!_this["private"]) return true;
280
- var valid = (0, _privacy["default"])(
281
- _this.name,
282
- JSON.stringify(payload),
283
- signature
284
- );
285
- if (!valid)
286
- _this.run_callback(callback, {
287
- private: _this["private"],
288
- error: true,
289
- error_message: "Invalid signature",
290
- });
291
- return valid;
292
- }
293
- );
294
- _defineProperty(_assertThisInitialized(_this), "stringify", function (str) {
295
- var obj = {};
296
- obj.name = _this.name;
297
- obj.hash = _this.hash;
298
- obj.path = _this.path;
299
- obj["private"] = _this["private"];
300
- obj.chain = _this.chain.stringify();
301
- obj.physical_address = _this.physical_address;
302
- return str ? JSON.stringify(obj) : obj;
303
- });
304
- _defineProperty(
305
- _assertThisInitialized(_this),
306
- "create_account",
307
- function (payload) {
308
- var name = payload.name,
309
- meta = payload.meta;
310
- return _this.manager.add_account(name, meta);
311
- }
312
- );
313
- _defineProperty(
314
- _assertThisInitialized(_this),
315
- "endpoint",
316
- function (endpoint, payload) {
317
- var method = _this[endpoint];
318
- typeof method === "function" && method(payload);
319
- }
125
+ } else account.flush_buffer(pid);
126
+ };
127
+
128
+ run_callback = (callback, payload) => {
129
+ setTimeout(() => {
130
+ if (!callback) return;
131
+
132
+ if (typeof callback === "function") return callback(payload);
133
+
134
+ callback.payload &&
135
+ callback.payload.physical_address &&
136
+ this.vm.stdin(payload, () => this.run(callback));
137
+ }, 0);
138
+ };
139
+
140
+ validate = (payload, signature, callback) => {
141
+ if (!this.private) return true;
142
+
143
+ let valid = validate_signature(
144
+ this.name,
145
+ JSON.stringify(payload),
146
+ signature
320
147
  );
321
- _meta = _meta || {};
322
- _this.name = _name;
323
- _this["private"] = _meta["private"];
324
- _this.manager = _meta.manager;
325
- _this.account = _assertThisInitialized(_this);
326
- if (!_this.manager) throw new Error("Manager instance missing.");
327
- _this.name_hash();
328
- _this.physical_address = ""
329
- .concat(_this.base_address, "/")
330
- .concat(_this.name);
331
- _this.set_paths(_assertThisInitialized(_this));
332
- _this.assembler = new _main["default"](_assertThisInitialized(_this));
333
- _this.chain = _this.account_chain(_assertThisInitialized(_this));
334
- _this.vm = new _Virtual_machine["default"](_this.chain);
335
- _this.mine_buffer = {};
336
- console.log("Account Instance: ".concat(_this.name));
337
- return _this;
338
- }
339
- return _createClass(Account);
340
- })(_Filesystem2["default"]);
341
- var _default = Account;
342
- exports["default"] = _default;
148
+ if (!valid)
149
+ this.run_callback(callback, {
150
+ private: this.private,
151
+ error: true,
152
+ error_message: "Invalid signature",
153
+ });
154
+
155
+ return valid;
156
+ };
157
+
158
+ stringify = (str) => {
159
+ let obj = {};
160
+
161
+ obj.name = this.name;
162
+ obj.hash = this.hash;
163
+ obj.path = this.path;
164
+ obj.private = this.private;
165
+ obj.chain = this.chain.stringify();
166
+ obj.physical_address = this.physical_address;
167
+
168
+ return str ? JSON.stringify(obj) : obj;
169
+ };
170
+
171
+ create_account = (payload) => {
172
+ let { name, meta } = payload;
173
+
174
+ return this.manager.add_account(name, meta);
175
+ };
176
+
177
+ endpoint = (endpoint, payload) => {
178
+ let method = this[endpoint];
179
+ typeof method === "function" && method(payload);
180
+ };
181
+ }
182
+
183
+ export default Account;
package/Objects/Block.js CHANGED
@@ -1,65 +1,60 @@
1
- "use strict";
1
+ import { hash } from "../utils/hash";
2
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];
3
+ class Block {
4
+ constructor(chain) {
5
+ this.chain = chain;
6
+ this.data = this.chain.txs;
7
+ this.metadata = {};
8
+ this.children = new Array();
9
+ this.index = this.chain.blocks.length;
10
+ }
11
+
12
+ generate_hash = () => {
13
+ this.previous_hash = this.chain.get_latest_block();
14
+ if (this.previous_hash) this.previous_hash = this.previous_hash.hash;
15
+
16
+ this.hash = hash(JSON.stringify(this.data));
17
+ };
18
+
19
+ store = (no_curs) => {
20
+ let content = this.chain.buffs.splice(-1)[0];
21
+ if (!no_curs) this.cursor = this.chain.cursors.splice(-1)[0];
26
22
  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];
23
+
24
+ let cursors = Object.keys(content).filter(
25
+ (c) => c.startsWith("{") && c.endsWith("}")
26
+ );
27
+
28
+ for (let c = 0; c < cursors.length; c++) {
29
+ let curs = cursors[c];
30
+
31
+ this.metadata[curs.slice(1, -1)] = content[curs];
33
32
  delete content[curs];
34
33
  }
35
- var datapath = _this.chain.account.save(content, _this.chain);
36
- _this.datapath = datapath;
37
- });
38
- _defineProperty(this, "stringify", function (str) {
39
- var obj = {};
40
- obj.metadata = _this.metadata;
41
- obj.datapath = _this.datapath;
42
- obj.timelapse = _this.timelapse;
43
- obj.index = _this.index;
44
- obj.hash = _this.hash;
45
- obj.data = _this.data;
46
- obj.children = _this.children.map(function (ch) {
47
- return new Object({
48
- hash: ch.hash,
49
- chain: ch.chain.hash
50
- });
51
- });
34
+
35
+ let datapath = this.chain.account.save(content, this.chain);
36
+ this.datapath = datapath;
37
+ };
38
+
39
+ stringify = (str) => {
40
+ let obj = {};
41
+
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(
49
+ (ch) => new Object({ hash: ch.hash, chain: ch.chain.hash })
50
+ );
52
51
  obj.chain = {
53
- hash: _this.chain.hash,
54
- physical_address: _this.chain.physical_address
52
+ hash: this.chain.hash,
53
+ physical_address: this.chain.physical_address,
55
54
  };
55
+
56
56
  return str ? JSON.stringify(obj) : obj;
57
- });
58
- this.chain = chain;
59
- this.data = this.chain.txs;
60
- this.metadata = {};
61
- this.children = new Array();
62
- this.index = this.chain.blocks.length;
63
- });
64
- var _default = Block;
65
- exports["default"] = _default;
57
+ };
58
+ }
59
+
60
+ export default Block;