godprotocol 1.0.841 → 1.0.842
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 +15 -17
- package/Loader_sequence/main.js +447 -292
- package/Loader_sequence/repository.js +27 -43
- package/Objects/Account.js +262 -237
- package/Objects/Block.js +78 -76
- package/Objects/Blockweb.js +36 -40
- package/Objects/Chain.js +164 -157
- package/Objects/Explorer.js +36 -39
- package/Objects/Filesystem.js +99 -82
- package/Objects/Frame.js +43 -48
- package/Objects/Manager.js +115 -108
- package/Objects/Opcodes.js +44 -44
- package/Objects/Oracle.js +93 -129
- package/Objects/Virtual_machine.js +145 -145
- package/framer.js +42 -35
- package/opcodes/add.js +9 -25
- package/opcodes/indices.js +15 -14
- package/opcodes/jmp.js +7 -12
- package/opcodes/std.js +7 -13
- package/opcodes.js +41 -58
- package/package.json +2 -3
- package/utils/create_server.js +71 -106
- package/utils/functions.js +31 -43
- package/utils/hash.js +10 -11
- package/utils/privacy.js +10 -15
- package/utils/services.js +32 -33
package/Objects/Block.js
CHANGED
|
@@ -1,82 +1,84 @@
|
|
|
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
|
-
|
|
1
|
+
import { hash } from "../utils/hash";
|
|
2
|
+
import { _id } from "generalised-datastore/utils/functions";
|
|
3
|
+
|
|
4
|
+
class Block {
|
|
5
|
+
constructor(chain) {
|
|
6
|
+
this.chain = chain;
|
|
7
|
+
this.data = this.chain.txs;
|
|
8
|
+
this.metadata = {};
|
|
9
|
+
this.children = new Array();
|
|
10
|
+
this.index = this.chain.blocks.length;
|
|
11
|
+
this._id = _id(this.chain.hash);
|
|
12
|
+
|
|
13
|
+
this.blocks_folder = this.chain.account.manager.oracle.gds.folder(
|
|
14
|
+
process.env.BLOCKS_FOLDER || "blocks"
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
generate_hash = () => {
|
|
19
|
+
this.previous_hash = this.chain.get_latest_block();
|
|
20
|
+
if (this.previous_hash) this.previous_hash = this.previous_hash.hash;
|
|
21
|
+
|
|
22
|
+
this.hash = hash(JSON.stringify(this.data));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
store = (no_curs) => {
|
|
26
|
+
let content = this.chain.buffs.splice(-1)[0];
|
|
27
|
+
if (!no_curs) this.cursor = this.chain.cursors.splice(-1)[0];
|
|
27
28
|
if (!content) return;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
|
|
30
|
+
let cursors = Object.keys(content).filter(
|
|
31
|
+
(c) => c.startsWith("{") && c.endsWith("}")
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
for (let c = 0; c < cursors.length; c++) {
|
|
35
|
+
let curs = cursors[c];
|
|
36
|
+
|
|
37
|
+
this.metadata[curs.slice(1, -1)] = content[curs];
|
|
34
38
|
delete content[curs];
|
|
35
39
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
obj
|
|
45
|
-
|
|
46
|
-
obj.
|
|
47
|
-
obj.
|
|
48
|
-
obj.
|
|
49
|
-
obj.
|
|
50
|
-
obj.
|
|
51
|
-
obj.
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
this.metadata.stdout = new Array();
|
|
41
|
+
this.chain.account.flush_stdout(this);
|
|
42
|
+
|
|
43
|
+
let datapath = this.chain.account.save(content, this.chain);
|
|
44
|
+
this.datapath = datapath;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
stringify = (str) => {
|
|
48
|
+
let obj = {};
|
|
49
|
+
|
|
50
|
+
obj.metadata = this.metadata;
|
|
51
|
+
obj.datapath = this.datapath;
|
|
52
|
+
obj.timelapse = this.timelapse;
|
|
53
|
+
obj.index = this.index;
|
|
54
|
+
obj.hash = this.hash;
|
|
55
|
+
obj.previous_hash = this.previous_hash;
|
|
56
|
+
obj.data = this.data;
|
|
57
|
+
obj._id = this._id;
|
|
58
|
+
obj.children = this.children.map((ch) => ch._id);
|
|
54
59
|
obj.chain = {
|
|
55
|
-
hash:
|
|
56
|
-
physical_address:
|
|
60
|
+
hash: this.chain.hash,
|
|
61
|
+
physical_address: this.chain.physical_address,
|
|
57
62
|
};
|
|
63
|
+
|
|
58
64
|
return str ? JSON.stringify(obj) : obj;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return blck;
|
|
80
|
-
});
|
|
81
|
-
var _default = Block;
|
|
82
|
-
exports["default"] = _default;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
static build = (data, chain) => {
|
|
68
|
+
let blck = new Block(chain);
|
|
69
|
+
blck.chain = chain;
|
|
70
|
+
blck.metadata = data.metadata;
|
|
71
|
+
blck.datapath = data.datapath;
|
|
72
|
+
blck.timelapse = data.timelapse;
|
|
73
|
+
blck.index = data.index;
|
|
74
|
+
blck.hash = data.hash;
|
|
75
|
+
blck.data = data.data;
|
|
76
|
+
blck.children = data.children || [];
|
|
77
|
+
|
|
78
|
+
blck._id = data._id;
|
|
79
|
+
|
|
80
|
+
return blck;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export default Block;
|
package/Objects/Blockweb.js
CHANGED
|
@@ -1,47 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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];
|
|
1
|
+
import Chain from "./Chain";
|
|
2
|
+
|
|
3
|
+
class Blockweb {
|
|
4
|
+
constructor(mgr) {
|
|
5
|
+
this.mgr = mgr;
|
|
6
|
+
this.physical_addresses = new Object();
|
|
7
|
+
this.chains = new Object();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get = (addr) => {
|
|
11
|
+
let hash = this.physical_addresses[addr];
|
|
12
|
+
|
|
13
|
+
let chain = this.chains[hash];
|
|
14
|
+
|
|
22
15
|
return chain;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
split_set = (physical_address) => {
|
|
19
|
+
let spli = physical_address.split("/");
|
|
20
|
+
|
|
21
|
+
let chain = this.get(physical_address);
|
|
27
22
|
if (!chain) {
|
|
28
|
-
chain =
|
|
23
|
+
chain = this.set(spli.slice(0, -1).join("/"), spli.slice(-1)[0]);
|
|
29
24
|
}
|
|
30
25
|
return chain;
|
|
31
|
-
}
|
|
32
|
-
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
set = (parent, name) => {
|
|
33
29
|
if (typeof parent === "string") {
|
|
34
|
-
parent =
|
|
30
|
+
parent = this.get(parent) || this.split_set(parent);
|
|
35
31
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
|
|
33
|
+
let chain = new Chain(parent, name);
|
|
34
|
+
this.chains[chain.hash] = chain;
|
|
35
|
+
|
|
36
|
+
this.physical_addresses[chain.physical_address] = chain.hash;
|
|
37
|
+
this.chains[chain.hash] = chain;
|
|
38
|
+
|
|
40
39
|
return chain;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
var _default = Blockweb;
|
|
47
|
-
exports["default"] = _default;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default Blockweb;
|
package/Objects/Chain.js
CHANGED
|
@@ -1,158 +1,165 @@
|
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
_this.height = _this.blocks.length;
|
|
39
|
-
}
|
|
40
|
-
_this.folder.config.add_entry("object", _this.stringify());
|
|
41
|
-
});
|
|
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;
|
|
1
|
+
import { hash } from "../utils/hash";
|
|
2
|
+
import Block from "./Block";
|
|
3
|
+
import Explorer from "./Explorer";
|
|
4
|
+
|
|
5
|
+
class Chain extends Explorer {
|
|
6
|
+
constructor(parent, name) {
|
|
7
|
+
super();
|
|
8
|
+
|
|
9
|
+
this.parent = parent;
|
|
10
|
+
this.account = this.parent.account;
|
|
11
|
+
this.name = name || this.parent.name;
|
|
12
|
+
this.physical_address =
|
|
13
|
+
this.parent.manager || !name
|
|
14
|
+
? this.parent.physical_address
|
|
15
|
+
: `${this.parent.physical_address}/${this.name}`;
|
|
16
|
+
|
|
17
|
+
this.pending_children = new Array();
|
|
18
|
+
this.connections = new Array();
|
|
19
|
+
|
|
20
|
+
this.blocks = new Array();
|
|
21
|
+
this.txs = new Array();
|
|
22
|
+
|
|
23
|
+
this.height = 0;
|
|
24
|
+
this.cursor = -1;
|
|
25
|
+
this.cursors = new Array();
|
|
26
|
+
this.buffs = new Array();
|
|
27
|
+
|
|
28
|
+
this.generate_hash();
|
|
29
|
+
|
|
30
|
+
this.folder = this.account.manager.oracle.gds.folder(this.hash);
|
|
31
|
+
this.height = this.folder.config.stats.total_files;
|
|
32
|
+
this.prev_hash = this.folder.config.stats.recent_file;
|
|
33
|
+
|
|
34
|
+
this.account.set_paths(this);
|
|
35
|
+
|
|
36
|
+
this.manage_config(true);
|
|
154
37
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
38
|
+
|
|
39
|
+
manage_config = (init) => {
|
|
40
|
+
if (init) {
|
|
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,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
this.folder.write(data);
|
|
121
|
+
return block;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
add_block = (block) => {
|
|
125
|
+
let recent_blk = this.get_latest_block();
|
|
126
|
+
block.previous_hash = recent_blk && recent_blk._id;
|
|
127
|
+
this.blocks.push(block);
|
|
128
|
+
this.height = this.blocks.length;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
get_latest_block = () => {
|
|
132
|
+
let blk = this.blocks.slice(-1)[0];
|
|
133
|
+
blk = this.build_block(blk);
|
|
134
|
+
|
|
135
|
+
return blk;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
stringify = (str) => {
|
|
139
|
+
let obj = {};
|
|
140
|
+
|
|
141
|
+
obj.physical_address = this.physical_address;
|
|
142
|
+
obj.height = this.blocks.length;
|
|
143
|
+
obj.parent = this.parent.path;
|
|
144
|
+
obj.account = this.parent.account.name;
|
|
145
|
+
obj.name = this.name;
|
|
146
|
+
obj.connections = this.connections.map((b) =>
|
|
147
|
+
b.stringify
|
|
148
|
+
? new Object({
|
|
149
|
+
chain: b.chain.hash,
|
|
150
|
+
block: { hash: b.hash, _id: b._id },
|
|
151
|
+
})
|
|
152
|
+
: b
|
|
153
|
+
);
|
|
154
|
+
obj.hash = this.hash;
|
|
155
|
+
obj.blocks = this.blocks.map((blk) => blk.hash || blk);
|
|
156
|
+
|
|
157
|
+
return str ? JSON.stringify(obj) : obj;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
add_chain = (name) => {
|
|
161
|
+
return this.account.add_chain(name, this);
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default Chain;
|