godprotocol 1.0.839 → 1.0.841
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 +17 -15
- package/Loader_sequence/main.js +292 -439
- package/Loader_sequence/repository.js +44 -27
- package/Objects/Account.js +237 -262
- package/Objects/Block.js +76 -77
- package/Objects/Blockweb.js +40 -36
- package/Objects/Chain.js +157 -162
- package/Objects/Explorer.js +47 -30
- package/Objects/Filesystem.js +82 -98
- package/Objects/Frame.js +48 -43
- package/Objects/Manager.js +108 -112
- package/Objects/Opcodes.js +44 -44
- package/Objects/Oracle.js +131 -91
- package/Objects/Virtual_machine.js +145 -145
- package/framer.js +35 -42
- package/opcodes/add.js +25 -9
- package/opcodes/indices.js +14 -15
- package/opcodes/jmp.js +12 -7
- package/opcodes/std.js +13 -7
- package/opcodes.js +58 -41
- package/package.json +3 -2
- package/utils/create_server.js +106 -71
- package/utils/functions.js +43 -31
- package/utils/hash.js +11 -10
- package/utils/privacy.js +15 -10
- package/utils/services.js +33 -32
package/Objects/Block.js
CHANGED
|
@@ -1,83 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (!no_curs) this.cursor = this.chain.cursors.splice(-1)[0];
|
|
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
|
+
var _functions = require("generalised-datastore/utils/functions");
|
|
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 Block = /*#__PURE__*/_createClass(function Block(chain) {
|
|
17
|
+
var _this = this;
|
|
18
|
+
_classCallCheck(this, Block);
|
|
19
|
+
_defineProperty(this, "generate_hash", function () {
|
|
20
|
+
_this.previous_hash = _this.chain.get_latest_block();
|
|
21
|
+
if (_this.previous_hash) _this.previous_hash = _this.previous_hash.hash;
|
|
22
|
+
_this.hash = (0, _hash.hash)(JSON.stringify(_this.data));
|
|
23
|
+
});
|
|
24
|
+
_defineProperty(this, "store", function (no_curs) {
|
|
25
|
+
var content = _this.chain.buffs.splice(-1)[0];
|
|
26
|
+
if (!no_curs) _this.cursor = _this.chain.cursors.splice(-1)[0];
|
|
28
27
|
if (!content) return;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
let curs = cursors[c];
|
|
36
|
-
|
|
37
|
-
this.metadata[curs.slice(1, -1)] = content[curs];
|
|
28
|
+
var cursors = Object.keys(content).filter(function (c) {
|
|
29
|
+
return c.startsWith("{") && c.endsWith("}");
|
|
30
|
+
});
|
|
31
|
+
for (var c = 0; c < cursors.length; c++) {
|
|
32
|
+
var curs = cursors[c];
|
|
33
|
+
_this.metadata[curs.slice(1, -1)] = content[curs];
|
|
38
34
|
delete content[curs];
|
|
39
35
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
obj.
|
|
51
|
-
obj.
|
|
52
|
-
obj.
|
|
53
|
-
obj.
|
|
54
|
-
obj.
|
|
55
|
-
obj.
|
|
56
|
-
|
|
57
|
-
|
|
36
|
+
_this.metadata.stdout = new Array();
|
|
37
|
+
_this.chain.account.flush_stdout(_this);
|
|
38
|
+
var datapath = _this.chain.account.save(content, _this.chain);
|
|
39
|
+
_this.datapath = datapath;
|
|
40
|
+
});
|
|
41
|
+
_defineProperty(this, "stringify", function (str) {
|
|
42
|
+
var obj = {};
|
|
43
|
+
obj.metadata = _this.metadata;
|
|
44
|
+
obj.datapath = _this.datapath;
|
|
45
|
+
obj.timelapse = _this.timelapse;
|
|
46
|
+
obj.index = _this.index;
|
|
47
|
+
obj.hash = _this.hash;
|
|
48
|
+
obj.previous_hash = _this.previous_hash;
|
|
49
|
+
obj.data = _this.data;
|
|
50
|
+
obj._id = _this._id;
|
|
51
|
+
obj.children = _this.children.map(function (ch) {
|
|
52
|
+
return ch._id;
|
|
53
|
+
});
|
|
58
54
|
obj.chain = {
|
|
59
|
-
hash:
|
|
60
|
-
physical_address:
|
|
55
|
+
hash: _this.chain.hash,
|
|
56
|
+
physical_address: _this.chain.physical_address
|
|
61
57
|
};
|
|
62
|
-
|
|
63
58
|
return str ? JSON.stringify(obj) : obj;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
59
|
+
});
|
|
60
|
+
this.chain = chain;
|
|
61
|
+
this.data = this.chain.txs;
|
|
62
|
+
this.metadata = {};
|
|
63
|
+
this.children = new Array();
|
|
64
|
+
this.index = this.chain.blocks.length;
|
|
65
|
+
this._id = (0, _functions._id)(this.chain.hash);
|
|
66
|
+
this.blocks_folder = this.chain.account.manager.oracle.gds.folder(process.env.BLOCKS_FOLDER || "blocks");
|
|
67
|
+
});
|
|
68
|
+
_defineProperty(Block, "build", function (data, chain) {
|
|
69
|
+
var blck = new Block(chain);
|
|
70
|
+
blck.chain = chain;
|
|
71
|
+
blck.metadata = data.metadata;
|
|
72
|
+
blck.datapath = data.datapath;
|
|
73
|
+
blck.timelapse = data.timelapse;
|
|
74
|
+
blck.index = data.index;
|
|
75
|
+
blck.hash = data.hash;
|
|
76
|
+
blck.data = data.data;
|
|
77
|
+
blck.children = data.children || [];
|
|
78
|
+
blck._id = data._id;
|
|
79
|
+
return blck;
|
|
80
|
+
});
|
|
81
|
+
var _default = Block;
|
|
82
|
+
exports["default"] = _default;
|
package/Objects/Blockweb.js
CHANGED
|
@@ -1,43 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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];
|
|
15
22
|
return chain;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let chain = this.get(physical_address);
|
|
23
|
+
});
|
|
24
|
+
_defineProperty(this, "split_set", function (physical_address) {
|
|
25
|
+
var spli = physical_address.split("/");
|
|
26
|
+
var chain = _this.get(physical_address);
|
|
22
27
|
if (!chain) {
|
|
23
|
-
chain =
|
|
28
|
+
chain = _this.set(spli.slice(0, -1).join("/"), spli.slice(-1)[0]);
|
|
24
29
|
}
|
|
25
30
|
return chain;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
set = (parent, name) => {
|
|
31
|
+
});
|
|
32
|
+
_defineProperty(this, "set", function (parent, name) {
|
|
29
33
|
if (typeof parent === "string") {
|
|
30
|
-
parent =
|
|
34
|
+
parent = _this.get(parent) || _this.split_set(parent);
|
|
31
35
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.physical_addresses[chain.physical_address] = chain.hash;
|
|
37
|
-
this.chains[chain.hash] = chain;
|
|
38
|
-
|
|
36
|
+
var chain = new _Chain["default"](parent, name);
|
|
37
|
+
_this.chains[chain.hash] = chain;
|
|
38
|
+
_this.physical_addresses[chain.physical_address] = chain.hash;
|
|
39
|
+
_this.chains[chain.hash] = chain;
|
|
39
40
|
return chain;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
});
|
|
42
|
+
this.mgr = mgr;
|
|
43
|
+
this.physical_addresses = new Object();
|
|
44
|
+
this.chains = new Object();
|
|
45
|
+
});
|
|
46
|
+
var _default = Blockweb;
|
|
47
|
+
exports["default"] = _default;
|
package/Objects/Chain.js
CHANGED
|
@@ -1,163 +1,158 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
let dir = this.account.manager.oracle.fs.readdirSync(this.folder.path);
|
|
42
|
-
this.blocks = dir.filter((d) => d !== ".config");
|
|
43
|
-
this.height = this.blocks.length;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this.folder.config.add_entry("object", this.stringify());
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
append_buffer = () => {
|
|
50
|
-
this.buffs.push({});
|
|
51
|
-
this.cursors.push(this.cursor);
|
|
52
|
-
this.cursor = -1;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
set_cursor = (cursor) => {
|
|
56
|
-
this.cursor = cursor;
|
|
57
|
-
this.cursors.push(cursor);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
get_buffer = () => {
|
|
61
|
-
this.cursor = this.cursors.pop();
|
|
62
|
-
return this.buffs.slice(-1)[0];
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
generate_hash = () => {
|
|
66
|
-
this.hash = hash(this.physical_address);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
build_block = (blk) => {
|
|
70
|
-
if (typeof blk === "string") {
|
|
71
|
-
let blk_data = this.folder.readone(blk, { depth: 1 });
|
|
72
|
-
|
|
73
|
-
blk = Block.build(blk_data, this);
|
|
74
|
-
}
|
|
75
|
-
return blk;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
get_block = (index) => {
|
|
79
|
-
let blk = this.blocks[index];
|
|
80
|
-
return this.build_block(blk);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
add_tx = (instruction) => {
|
|
84
|
-
if (!this.txs.length) this.start_time = Date.now();
|
|
85
|
-
|
|
86
|
-
this.txs.push(instruction);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
mine = (vm, no_curs) => {
|
|
90
|
-
let block = new Block(this);
|
|
91
|
-
|
|
92
|
-
block.generate_hash();
|
|
93
|
-
this.add_block(block);
|
|
94
|
-
|
|
95
|
-
block.store(no_curs);
|
|
96
|
-
|
|
97
|
-
block.children = this.pending_children;
|
|
98
|
-
this.pending_children = new Array();
|
|
99
|
-
|
|
100
|
-
let prev_context = vm.get_context(-2);
|
|
101
|
-
if (prev_context) {
|
|
102
|
-
prev_context.pending_children.push(block);
|
|
103
|
-
prev_context.connections.push(block);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
this.txs = new Array();
|
|
107
|
-
|
|
108
|
-
block.timelapse = Date.now() - this.start_time;
|
|
109
|
-
|
|
110
|
-
this.manage_config();
|
|
111
|
-
|
|
112
|
-
let data = block.stringify();
|
|
113
|
-
|
|
114
|
-
data = this.account.manager.oracle.handle_compression({
|
|
115
|
-
addr: this.folder.folder_path,
|
|
116
|
-
data,
|
|
117
|
-
no_string: true,
|
|
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
|
+
var _Block = _interopRequireDefault(require("./Block"));
|
|
9
|
+
var _Explorer2 = _interopRequireDefault(require("./Explorer"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
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); }
|
|
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); } }
|
|
13
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
14
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
15
|
+
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); }
|
|
16
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
17
|
+
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); }; }
|
|
18
|
+
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); }
|
|
19
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
20
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
21
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
22
|
+
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; }
|
|
23
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
24
|
+
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); }
|
|
25
|
+
var Chain = /*#__PURE__*/function (_Explorer) {
|
|
26
|
+
_inherits(Chain, _Explorer);
|
|
27
|
+
var _super = _createSuper(Chain);
|
|
28
|
+
function Chain(parent, _name) {
|
|
29
|
+
var _this;
|
|
30
|
+
_classCallCheck(this, Chain);
|
|
31
|
+
_this = _super.call(this);
|
|
32
|
+
_defineProperty(_assertThisInitialized(_this), "manage_config", function (init) {
|
|
33
|
+
if (init) {
|
|
34
|
+
var dir = _this.account.manager.oracle.fs.readdirSync(_this.folder.path);
|
|
35
|
+
_this.blocks = dir.filter(function (d) {
|
|
36
|
+
return d !== ".config";
|
|
37
|
+
});
|
|
38
|
+
_this.height = _this.blocks.length;
|
|
39
|
+
}
|
|
40
|
+
_this.folder.config.add_entry("object", _this.stringify());
|
|
118
41
|
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
42
|
+
_defineProperty(_assertThisInitialized(_this), "append_buffer", function () {
|
|
43
|
+
_this.buffs.push({});
|
|
44
|
+
_this.cursors.push(_this.cursor);
|
|
45
|
+
_this.cursor = -1;
|
|
46
|
+
});
|
|
47
|
+
_defineProperty(_assertThisInitialized(_this), "set_cursor", function (cursor) {
|
|
48
|
+
_this.cursor = cursor;
|
|
49
|
+
_this.cursors.push(cursor);
|
|
50
|
+
});
|
|
51
|
+
_defineProperty(_assertThisInitialized(_this), "get_buffer", function () {
|
|
52
|
+
_this.cursor = _this.cursors.pop();
|
|
53
|
+
return _this.buffs.slice(-1)[0];
|
|
54
|
+
});
|
|
55
|
+
_defineProperty(_assertThisInitialized(_this), "generate_hash", function () {
|
|
56
|
+
_this.hash = (0, _hash.hash)(_this.physical_address);
|
|
57
|
+
});
|
|
58
|
+
_defineProperty(_assertThisInitialized(_this), "build_block", function (blk) {
|
|
59
|
+
if (typeof blk === "string") {
|
|
60
|
+
var blk_data = _this.folder.readone(blk, {
|
|
61
|
+
depth: 1
|
|
62
|
+
});
|
|
63
|
+
blk = _Block["default"].build(blk_data, _assertThisInitialized(_this));
|
|
64
|
+
}
|
|
65
|
+
return blk;
|
|
66
|
+
});
|
|
67
|
+
_defineProperty(_assertThisInitialized(_this), "get_block", function (index) {
|
|
68
|
+
var blk = _this.blocks[index];
|
|
69
|
+
return _this.build_block(blk);
|
|
70
|
+
});
|
|
71
|
+
_defineProperty(_assertThisInitialized(_this), "add_tx", function (instruction) {
|
|
72
|
+
if (!_this.txs.length) _this.start_time = Date.now();
|
|
73
|
+
_this.txs.push(instruction);
|
|
74
|
+
});
|
|
75
|
+
_defineProperty(_assertThisInitialized(_this), "mine", function (vm, no_curs) {
|
|
76
|
+
var block = new _Block["default"](_assertThisInitialized(_this));
|
|
77
|
+
block.generate_hash();
|
|
78
|
+
_this.add_block(block);
|
|
79
|
+
block.store(no_curs);
|
|
80
|
+
block.children = _this.pending_children;
|
|
81
|
+
_this.pending_children = new Array();
|
|
82
|
+
var prev_context = vm.get_context(-2);
|
|
83
|
+
if (prev_context) {
|
|
84
|
+
prev_context.pending_children.push(block);
|
|
85
|
+
prev_context.connections.push(block);
|
|
86
|
+
}
|
|
87
|
+
_this.txs = new Array();
|
|
88
|
+
block.timelapse = Date.now() - _this.start_time;
|
|
89
|
+
_this.manage_config();
|
|
90
|
+
var data = block.stringify();
|
|
91
|
+
data = _this.account.manager.oracle.handle_compression({
|
|
92
|
+
addr: _this.folder.folder_path,
|
|
93
|
+
data: data,
|
|
94
|
+
no_string: true
|
|
95
|
+
});
|
|
96
|
+
_this.folder.write(data);
|
|
97
|
+
return block;
|
|
98
|
+
});
|
|
99
|
+
_defineProperty(_assertThisInitialized(_this), "add_block", function (block) {
|
|
100
|
+
var recent_blk = _this.get_latest_block();
|
|
101
|
+
block.previous_hash = recent_blk && recent_blk._id;
|
|
102
|
+
_this.blocks.push(block);
|
|
103
|
+
_this.height = _this.blocks.length;
|
|
104
|
+
});
|
|
105
|
+
_defineProperty(_assertThisInitialized(_this), "get_latest_block", function () {
|
|
106
|
+
var blk = _this.blocks.slice(-1)[0];
|
|
107
|
+
blk = _this.build_block(blk);
|
|
108
|
+
return blk;
|
|
109
|
+
});
|
|
110
|
+
_defineProperty(_assertThisInitialized(_this), "stringify", function (str) {
|
|
111
|
+
var obj = {};
|
|
112
|
+
obj.physical_address = _this.physical_address;
|
|
113
|
+
obj.height = _this.blocks.length;
|
|
114
|
+
obj.parent = _this.parent.path;
|
|
115
|
+
obj.account = _this.parent.account.name;
|
|
116
|
+
obj.name = _this.name;
|
|
117
|
+
obj.connections = _this.connections.map(function (b) {
|
|
118
|
+
return b.stringify ? new Object({
|
|
119
|
+
chain: b.chain.hash,
|
|
120
|
+
block: {
|
|
121
|
+
hash: b.hash,
|
|
122
|
+
_id: b._id
|
|
123
|
+
}
|
|
124
|
+
}) : b;
|
|
125
|
+
});
|
|
126
|
+
obj.hash = _this.hash;
|
|
127
|
+
obj.blocks = _this.blocks.map(function (blk) {
|
|
128
|
+
return blk.hash || blk;
|
|
129
|
+
});
|
|
130
|
+
return str ? JSON.stringify(obj) : obj;
|
|
131
|
+
});
|
|
132
|
+
_defineProperty(_assertThisInitialized(_this), "add_chain", function (name) {
|
|
133
|
+
return _this.account.add_chain(name, _assertThisInitialized(_this));
|
|
134
|
+
});
|
|
135
|
+
_this.parent = parent;
|
|
136
|
+
_this.account = _this.parent.account;
|
|
137
|
+
_this.name = _name || _this.parent.name;
|
|
138
|
+
_this.physical_address = _this.parent.manager || !_name ? _this.parent.physical_address : "".concat(_this.parent.physical_address, "/").concat(_this.name);
|
|
139
|
+
_this.pending_children = new Array();
|
|
140
|
+
_this.connections = new Array();
|
|
141
|
+
_this.blocks = new Array();
|
|
142
|
+
_this.txs = new Array();
|
|
143
|
+
_this.height = 0;
|
|
144
|
+
_this.cursor = -1;
|
|
145
|
+
_this.cursors = new Array();
|
|
146
|
+
_this.buffs = new Array();
|
|
147
|
+
_this.generate_hash();
|
|
148
|
+
_this.folder = _this.account.manager.oracle.gds.folder(_this.hash);
|
|
149
|
+
_this.height = _this.folder.config.stats.total_files;
|
|
150
|
+
_this.prev_hash = _this.folder.config.stats.recent_file;
|
|
151
|
+
_this.account.set_paths(_assertThisInitialized(_this));
|
|
152
|
+
_this.manage_config(true);
|
|
153
|
+
return _this;
|
|
154
|
+
}
|
|
155
|
+
return _createClass(Chain);
|
|
156
|
+
}(_Explorer2["default"]);
|
|
157
|
+
var _default = Chain;
|
|
158
|
+
exports["default"] = _default;
|