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.
- package/.babelrc +3 -0
- package/Index.js +8 -21
- package/Loader_sequence/main.js +259 -358
- package/Objects/Account.js +178 -337
- package/Objects/Block.js +53 -58
- package/Objects/Blockweb.js +27 -34
- package/Objects/Chain.js +115 -118
- package/Objects/Explorer.js +30 -37
- package/Objects/Filesystem.js +95 -80
- package/Objects/Frame.js +43 -48
- package/Objects/Manager.js +68 -77
- package/Objects/Opcodes.js +32 -97
- package/Objects/Oracle.js +23 -39
- package/Objects/Virtual_machine.js +125 -261
- package/build/Account.js +162 -0
- package/build/Block.js +65 -0
- package/build/Blockweb.js +36 -0
- package/build/Chain.js +119 -0
- package/build/Explorer.js +47 -0
- package/build/Filesystem.js +127 -0
- package/build/Frame.js +52 -0
- package/build/Index.js +15 -0
- package/build/Manager.js +99 -0
- package/build/Opcodes.js +39 -0
- package/build/Oracle.js +42 -0
- package/build/Virtual_machine.js +128 -0
- package/build/add.js +41 -0
- package/build/create_server.js +119 -0
- package/build/framer.js +57 -0
- package/build/functions.js +82 -0
- package/build/hash.js +14 -0
- package/build/jmp.js +19 -0
- package/build/main.js +283 -0
- package/build/opcodes.js +42 -0
- package/build/privacy.js +27 -0
- package/build/services.js +50 -0
- package/build/std.js +11 -0
- package/framer.js +39 -31
- package/opcodes/add.js +14 -40
- package/opcodes/jmp.js +10 -14
- package/opcodes/std.js +5 -9
- package/opcodes.js +25 -29
- package/package.json +3 -3
- package/readme.md +71 -95
- package/types/Account.d.ts +73 -0
- package/types/Block.d.ts +22 -0
- package/types/Blockweb.d.ts +14 -0
- package/types/Chain.d.ts +35 -0
- package/types/Explorer.d.ts +9 -0
- package/types/Filesystem.d.ts +23 -0
- package/types/Frame.d.ts +14 -0
- package/types/Manager.d.ts +21 -0
- package/types/Opcodes.d.ts +11 -0
- package/types/Oracle.d.ts +17 -0
- package/types/Virtual_machine.d.ts +20 -0
- package/types/index.d.ts +4 -0
- package/utils/create_server.js +65 -622
- 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/Account.js
CHANGED
|
@@ -1,342 +1,183 @@
|
|
|
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
|
-
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
|
-
|
|
43
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
-
|
|
1
|
+
import { hash } from "../utils/hash";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
obj
|
|
42
|
-
|
|
43
|
-
obj.
|
|
44
|
-
obj.
|
|
45
|
-
obj.
|
|
46
|
-
obj.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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:
|
|
54
|
-
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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;
|