@leofcoin/chain 1.1.9 → 1.1.11

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 (67) hide show
  1. package/demo/865.browser.js +10 -0
  2. package/demo/865.machine-worker.js +10 -0
  3. package/demo/chain.browser.js +51312 -6162
  4. package/demo/chain.js +1209 -0
  5. package/demo/generate-account.browser.js +50 -0
  6. package/demo/index.html +8 -1
  7. package/demo/machine-worker.js +17624 -0
  8. package/demo/messages.browser.js +328 -0
  9. package/demo/{911.browser.js → multi-wallet.browser.js} +1 -11010
  10. package/demo/node.browser.js +2458 -3954
  11. package/demo/node.js +1 -0
  12. package/demo/peernet-swarm.browser.js +832 -0
  13. package/demo/storage.browser.js +3724 -0
  14. package/demo/workers/865.js +10 -0
  15. package/demo/workers/block-worker.js +13200 -0
  16. package/demo/workers/machine-worker.js +2912 -1526
  17. package/demo/workers/pool-worker.js +8504 -0
  18. package/demo/{main.browser.js → workers/transaction-worker.js} +1456 -1123
  19. package/demo/workers/workers/865.js +10 -0
  20. package/demo/workers/workers/block-worker.js +13200 -0
  21. package/demo/workers/workers/machine-worker.js +13904 -0
  22. package/demo/workers/workers/pool-worker.js +8504 -0
  23. package/demo/workers/workers/transaction-worker.js +8496 -0
  24. package/dist/865.browser.js +10 -0
  25. package/dist/browser/workers/865.js +10 -0
  26. package/dist/browser/workers/block-worker.js +13200 -0
  27. package/dist/browser/workers/machine-worker.js +13930 -0
  28. package/dist/browser/workers/pool-worker.js +8504 -0
  29. package/{demo/427.browser.js → dist/browser/workers/transaction-worker.js} +1533 -1129
  30. package/dist/chain.browser.js +59742 -0
  31. package/dist/chain.js +207 -187
  32. package/dist/generate-account.browser.js +50 -0
  33. package/dist/messages.browser.js +328 -0
  34. package/dist/module/chain.js +206 -187
  35. package/dist/module/node.js +203 -1
  36. package/dist/module/workers/block-worker.js +93 -0
  37. package/dist/module/workers/machine-worker.js +67 -331
  38. package/dist/module/workers/pool-worker.js +55 -0
  39. package/dist/module/workers/transaction-worker.js +47 -0
  40. package/{demo/peernet-worker.browser.js → dist/multi-wallet.browser.js} +2 -11317
  41. package/dist/node.browser.js +9839 -0
  42. package/dist/node.js +209 -1
  43. package/dist/pako.browser.js +6731 -0
  44. package/dist/peernet-swarm.browser.js +832 -0
  45. package/dist/storage.browser.js +3724 -0
  46. package/dist/workers/block-worker.js +1 -1
  47. package/dist/workers/machine-worker.js +1 -1
  48. package/dist/workers/pool-worker.js +1 -1
  49. package/dist/workers/transaction-worker.js +1 -1
  50. package/dist/wrtc.browser.js +28 -0
  51. package/package.json +9 -4
  52. package/rollup.config.js +41 -11
  53. package/src/chain.js +46 -16
  54. package/src/machine.js +25 -28
  55. package/test/chain.js +1 -1
  56. package/webpack.config.js +17 -4
  57. package/demo/151.browser.js +0 -271
  58. package/demo/205.browser.js +0 -215
  59. package/demo/560.browser.js +0 -3
  60. package/src/workers/block-worker.js +0 -70
  61. package/src/workers/machine-worker.js +0 -174
  62. package/src/workers/pool-worker.js +0 -37
  63. package/src/workers/transaction-worker.js +0 -26
  64. package/workers/block-worker.js +0 -1
  65. package/workers/machine-worker.js +0 -1
  66. package/workers/pool-worker.js +0 -1
  67. package/workers/transaction-worker.js +0 -1
package/dist/chain.js CHANGED
@@ -1,14 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  var utils = require('@leofcoin/utils');
4
- var codecFormatInterface = require('@leofcoin/codec-format-interface');
5
4
  var _BN = require('bn.js');
6
5
  require('@ethersproject/bytes');
7
6
  var logger = require('@ethersproject/logger');
8
7
  require('@ethersproject/bignumber');
9
8
  var crypto = require('crypto');
10
- var child_process = require('child_process');
11
9
  var path = require('path');
10
+ var EasyWorker = require('@vandeurenglenn/easy-worker');
11
+ var codecFormatInterface = require('@leofcoin/codec-format-interface');
12
12
  var MultiWallet = require('@leofcoin/multi-wallet');
13
13
  var index = require('@leofcoin/codec-format-interface/dist/index');
14
14
  var bs32 = require('@vandeurenglenn/base32');
@@ -16,145 +16,10 @@ var bs32 = require('@vandeurenglenn/base32');
16
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
17
 
18
18
  var _BN__default = /*#__PURE__*/_interopDefaultLegacy(_BN);
19
+ var EasyWorker__default = /*#__PURE__*/_interopDefaultLegacy(EasyWorker);
19
20
  var MultiWallet__default = /*#__PURE__*/_interopDefaultLegacy(MultiWallet);
20
21
  var bs32__default = /*#__PURE__*/_interopDefaultLegacy(bs32);
21
22
 
22
- var proto$4 = `
23
- message ContractMessage {
24
- required string creator = 1;
25
- required bytes contract = 2;
26
- repeated string constructorParameters = 3;
27
- }
28
- `;
29
-
30
- class ContractMessage extends codecFormatInterface.FormatInterface {
31
- get keys() {
32
- return ['creator', 'contract', 'constructorParameters']
33
- }
34
-
35
- get messageName() {
36
- return 'ContractMessage'
37
- }
38
-
39
- constructor(buffer) {
40
- super(buffer, proto$4, {name: 'contract-message'});
41
- }
42
- }
43
-
44
- var proto$3 = `
45
-
46
- message TransactionMessage {
47
- required uint64 timestamp = 1;
48
- required string from = 2;
49
- required string to = 3;
50
- required uint64 nonce = 4;
51
- required string method = 5;
52
- repeated string params = 6;
53
- required string signature = 7;
54
- }
55
- `;
56
-
57
- class TransactionMessage extends codecFormatInterface.FormatInterface {
58
- get keys() {
59
- return ['timestamp', 'from', 'to', 'nonce', 'method', 'params', 'signature']
60
- }
61
-
62
- get messageName() {
63
- return 'TransactionMessage'
64
- }
65
-
66
- constructor(buffer) {
67
- const name = 'transaction-message';
68
- super(buffer, proto$3, {name});
69
- }
70
- }
71
-
72
- var proto$2 = `
73
- message ValidatorMessage {
74
- required string address = 1;
75
- required string reward = 2;
76
- }
77
-
78
- message Transaction {
79
- required string hash = 1;
80
- required uint64 timestamp = 2;
81
- required string from = 3;
82
- required string to = 4;
83
- required uint64 nonce = 5;
84
- required string method = 6;
85
- repeated string params = 7;
86
- }
87
-
88
- message BlockMessage {
89
- required uint64 index = 1;
90
- required string previousHash = 3;
91
- required uint64 timestamp = 4;
92
- required uint64 reward = 5;
93
- required string fees = 6;
94
- repeated Transaction transactions = 7;
95
- repeated ValidatorMessage validators = 8;
96
- }
97
- `;
98
-
99
- class BlockMessage extends codecFormatInterface.FormatInterface {
100
- get keys() {
101
- return ['index', 'previousHash', 'timestamp', 'reward', 'fees', 'transactions', 'validators']
102
- }
103
-
104
- get messageName() {
105
- return 'BlockMessage'
106
- }
107
-
108
- constructor(buffer) {
109
- const name = 'block-message';
110
- super(buffer, proto$2, {name});
111
- }
112
- }
113
-
114
- var proto$1 = `
115
-
116
- message BWMessage {
117
- required uint64 up = 1;
118
- required uint64 down = 2;
119
- }
120
- `;
121
-
122
- class BWMessage extends codecFormatInterface.FormatInterface {
123
- get keys() {
124
- return ['up', 'down']
125
- }
126
-
127
- get messageName() {
128
- return 'BWMessage'
129
- }
130
-
131
- constructor(buffer) {
132
- const name = 'bw-message';
133
- super(buffer, proto$1, {name});
134
- }
135
- }
136
-
137
- var proto = `
138
-
139
- message BWRequestMessage {
140
- }
141
- `;
142
-
143
- class BWRequestMessage extends codecFormatInterface.FormatInterface {
144
- get keys() {
145
- return []
146
- }
147
-
148
- get messageName() {
149
- return 'BWRequestMessage'
150
- }
151
-
152
- constructor(buffer) {
153
- const name = 'bw-request-message';
154
- super(buffer, proto, {name});
155
- }
156
- }
157
-
158
23
  var contractFactory$2 = "ihny2gqgorwofhvfgtr5dm2targnxrul5rr4wnyk4vl7akbmwox43nlvpim";
159
24
  var nativeToken$2 = "ihny2gqhe7gazkieey4o3rztfy757ia3as6snrmov4e3vkfdvt2olvx3ste";
160
25
  var nameService$2 = "ihny2gqgztuego4qkbcaqp5ttunly3j3f5vehe65txord7r7osv7xrqxbl6";
@@ -197,7 +62,7 @@ const formatBytes = (bytes, decimals = 2) => {
197
62
  class Machine {
198
63
  #contracts = {}
199
64
  #nonces = {}
200
- lastBlock = {}
65
+ lastBlock = {index: 0, hash: '0x0', previousHash: '0x0'}
201
66
 
202
67
  constructor() {
203
68
  return this.#init()
@@ -239,34 +104,31 @@ class Machine {
239
104
 
240
105
  async #init() {
241
106
  return new Promise(async (resolve) => {
242
- // this.worker = new Worker('./workers/machine-worker.js')
243
- // this.worker.onmessage = this.#onmessage.bind(this)
244
-
245
107
  pubsub.subscribe('machine.ready', () => {
246
108
  resolve(this);
247
109
  });
248
- this.worker = child_process.fork(path.join(__dirname, './workers/machine-worker.js'), {serialization: 'advanced'});
249
- this.worker.on('message', this.#onmessage.bind(this));
250
- const blocks = await blockStore.values();
251
- const contracts = await Promise.all([
252
- contractStore.get(contractFactory$1),
253
- contractStore.get(nativeToken$1),
254
- contractStore.get(validators$1),
255
- contractStore.get(nameService$1)
256
- ]);
257
-
258
- const message = {
259
- type: 'init',
260
- input: {
261
- contracts,
262
- blocks,
263
- peerid: peernet.peerId
264
- }
265
- };
266
- this.worker.send(message);
267
- // this.worker.postMessage(message)
110
+
111
+ this.worker = await new EasyWorker__default["default"](path.join(__dirname, './workers/machine-worker.js'), {serialization: 'advanced', type:'module'});
112
+ this.worker.onmessage(this.#onmessage.bind(this));
113
+
114
+ const blocks = await blockStore.values();
115
+ const contracts = await Promise.all([
116
+ contractStore.get(contractFactory$1),
117
+ contractStore.get(nativeToken$1),
118
+ contractStore.get(validators$1),
119
+ contractStore.get(nameService$1)
120
+ ]);
121
+
122
+ const message = {
123
+ type: 'init',
124
+ input: {
125
+ contracts,
126
+ blocks,
127
+ peerid: peernet.peerId
128
+ }
129
+ };
130
+ this.worker.postMessage(message);
268
131
  })
269
- // return
270
132
 
271
133
  }
272
134
 
@@ -308,7 +170,7 @@ this.worker.on('message', this.#onmessage.bind(this));
308
170
  else resolve(message);
309
171
  };
310
172
  pubsub.subscribe(id, message);
311
- this.worker.send({
173
+ this.worker.postMessage({
312
174
  type: 'execute',
313
175
  id,
314
176
  input: {
@@ -336,7 +198,7 @@ this.worker.on('message', this.#onmessage.bind(this));
336
198
  resolve(message);
337
199
  };
338
200
  pubsub.subscribe(id, message);
339
- this.worker.send({
201
+ this.worker.postMessage({
340
202
  type: 'get',
341
203
  id,
342
204
  input: {
@@ -359,6 +221,142 @@ this.worker.on('message', this.#onmessage.bind(this));
359
221
  }
360
222
  }
361
223
 
224
+ var proto$4 = `
225
+ message ContractMessage {
226
+ required string creator = 1;
227
+ required bytes contract = 2;
228
+ repeated string constructorParameters = 3;
229
+ }
230
+ `;
231
+
232
+ class ContractMessage extends codecFormatInterface.FormatInterface {
233
+ get keys() {
234
+ return ['creator', 'contract', 'constructorParameters']
235
+ }
236
+
237
+ get messageName() {
238
+ return 'ContractMessage'
239
+ }
240
+
241
+ constructor(buffer) {
242
+ super(buffer, proto$4, {name: 'contract-message'});
243
+ }
244
+ }
245
+
246
+ var proto$3 = `
247
+
248
+ message TransactionMessage {
249
+ required uint64 timestamp = 1;
250
+ required string from = 2;
251
+ required string to = 3;
252
+ required uint64 nonce = 4;
253
+ required string method = 5;
254
+ repeated string params = 6;
255
+ required string signature = 7;
256
+ }
257
+ `;
258
+
259
+ class TransactionMessage extends codecFormatInterface.FormatInterface {
260
+ get keys() {
261
+ return ['timestamp', 'from', 'to', 'nonce', 'method', 'params', 'signature']
262
+ }
263
+
264
+ get messageName() {
265
+ return 'TransactionMessage'
266
+ }
267
+
268
+ constructor(buffer) {
269
+ const name = 'transaction-message';
270
+ super(buffer, proto$3, {name});
271
+ }
272
+ }
273
+
274
+ var proto$2 = `
275
+ message ValidatorMessage {
276
+ required string address = 1;
277
+ required string reward = 2;
278
+ }
279
+
280
+ message Transaction {
281
+ required string hash = 1;
282
+ required uint64 timestamp = 2;
283
+ required string from = 3;
284
+ required string to = 4;
285
+ required uint64 nonce = 5;
286
+ required string method = 6;
287
+ repeated string params = 7;
288
+ }
289
+
290
+ message BlockMessage {
291
+ required uint64 index = 1;
292
+ required string previousHash = 3;
293
+ required uint64 timestamp = 4;
294
+ required uint64 reward = 5;
295
+ required string fees = 6;
296
+ repeated Transaction transactions = 7;
297
+ repeated ValidatorMessage validators = 8;
298
+ }
299
+ `;
300
+
301
+ class BlockMessage extends codecFormatInterface.FormatInterface {
302
+ get keys() {
303
+ return ['index', 'previousHash', 'timestamp', 'reward', 'fees', 'transactions', 'validators']
304
+ }
305
+
306
+ get messageName() {
307
+ return 'BlockMessage'
308
+ }
309
+
310
+ constructor(buffer) {
311
+ const name = 'block-message';
312
+ super(buffer, proto$2, {name});
313
+ }
314
+ }
315
+
316
+ var proto$1 = `
317
+
318
+ message BWMessage {
319
+ required uint64 up = 1;
320
+ required uint64 down = 2;
321
+ }
322
+ `;
323
+
324
+ class BWMessage extends codecFormatInterface.FormatInterface {
325
+ get keys() {
326
+ return ['up', 'down']
327
+ }
328
+
329
+ get messageName() {
330
+ return 'BWMessage'
331
+ }
332
+
333
+ constructor(buffer) {
334
+ const name = 'bw-message';
335
+ super(buffer, proto$1, {name});
336
+ }
337
+ }
338
+
339
+ var proto = `
340
+
341
+ message BWRequestMessage {
342
+ }
343
+ `;
344
+
345
+ class BWRequestMessage extends codecFormatInterface.FormatInterface {
346
+ get keys() {
347
+ return []
348
+ }
349
+
350
+ get messageName() {
351
+ return 'BWRequestMessage'
352
+ }
353
+
354
+ constructor(buffer) {
355
+ const name = 'bw-request-message';
356
+ super(buffer, proto, {name});
357
+ }
358
+ }
359
+
362
360
  var contractFactory = "237,198,141,3,123,34,99,114,101,97,116,111,114,34,58,34,51,67,122,86,51,66,98,76,103,117,57,105,55,119,70,115,83,101,82,101,90,113,110,80,111,53,82,114,121,49,118,81,98,82,115,89,114,116,67,67,97,81,103,98,113,80,72,112,116,117,85,111,72,52,34,44,34,99,111,110,116,114,97,99,116,34,58,34,114,101,116,117,114,110,32,99,108,97,115,115,32,70,97,99,116,111,114,121,123,35,110,97,109,101,61,92,34,65,114,116,79,110,108,105,110,101,67,111,110,116,114,97,99,116,70,97,99,116,111,114,121,92,34,59,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,61,48,59,35,99,111,110,116,114,97,99,116,115,61,91,93,59,99,111,110,115,116,114,117,99,116,111,114,40,115,116,97,116,101,41,123,115,116,97,116,101,38,38,40,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,61,115,116,97,116,101,46,99,111,110,116,114,97,99,116,115,44,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,61,115,116,97,116,101,46,116,111,116,97,108,67,111,110,116,114,97,99,116,115,41,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,116,111,116,97,108,67,111,110,116,114,97,99,116,115,58,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,44,99,111,110,116,114,97,99,116,115,58,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,125,125,103,101,116,32,110,97,109,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,110,97,109,101,125,103,101,116,32,99,111,110,116,114,97,99,116,115,40,41,123,114,101,116,117,114,110,91,46,46,46,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,93,125,103,101,116,32,116,111,116,97,108,67,111,110,116,114,97,99,116,115,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,125,105,115,118,97,108,105,100,40,104,97,115,104,44,99,114,101,97,116,111,114,44,99,111,110,116,114,97,99,116,44,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,61,91,93,41,123,99,111,110,115,116,32,109,101,115,115,97,103,101,61,110,101,119,32,67,111,110,116,114,97,99,116,77,101,115,115,97,103,101,40,123,99,114,101,97,116,111,114,58,99,114,101,97,116,111,114,44,99,111,110,116,114,97,99,116,58,99,111,110,116,114,97,99,116,44,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,58,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,125,41,59,114,101,116,117,114,110,32,66,111,111,108,101,97,110,40,109,101,115,115,97,103,101,46,104,97,115,104,61,61,61,104,97,115,104,41,125,97,115,121,110,99,32,100,101,112,108,111,121,67,111,110,116,114,97,99,116,40,99,111,110,116,114,97,99,116,72,97,115,104,44,99,114,101,97,116,111,114,44,99,111,110,116,114,97,99,116,44,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,61,91,93,41,123,105,102,40,99,111,110,116,114,97,99,116,46,99,114,101,97,116,111,114,33,61,61,109,115,103,46,115,101,110,100,101,114,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,111,110,108,121,32,97,32,99,111,110,116,114,97,99,116,32,99,114,101,97,116,111,114,32,99,97,110,32,100,101,112,108,111,121,32,97,32,99,111,110,116,114,97,99,116,92,34,41,59,105,102,40,97,119,97,105,116,32,99,111,110,116,114,97,99,116,83,116,111,114,101,46,104,97,115,40,104,97,115,104,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,100,117,112,108,105,99,97,116,101,32,99,111,110,116,114,97,99,116,92,34,41,59,105,102,40,33,116,104,105,115,46,105,115,86,97,108,105,100,40,99,111,110,116,114,97,99,116,72,97,115,104,44,99,114,101,97,116,111,114,44,99,111,110,116,114,97,99,116,44,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,105,110,118,97,108,105,100,32,99,111,110,116,114,97,99,116,92,34,41,59,97,119,97,105,116,32,99,111,110,116,114,97,99,116,83,116,111,114,101,46,112,117,116,40,104,97,115,104,44,101,110,99,111,100,101,100,41,44,116,104,105,115,46,35,116,111,116,97,108,67,111,110,116,114,97,99,116,115,43,61,49,44,116,104,105,115,46,35,99,111,110,116,114,97,99,116,115,46,112,117,115,104,40,104,97,115,104,41,125,125,59,92,110,34,44,34,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,34,58,91,93,125";
363
361
  var nativeToken = "237,198,141,3,123,34,99,114,101,97,116,111,114,34,58,34,51,67,122,86,51,66,98,76,103,117,57,105,55,119,70,115,83,101,82,101,90,113,110,80,111,53,82,114,121,49,118,81,98,82,115,89,114,116,67,67,97,81,103,98,113,80,72,112,116,117,85,111,72,52,34,44,34,99,111,110,116,114,97,99,116,34,58,34,114,101,116,117,114,110,32,99,108,97,115,115,32,65,114,116,79,110,108,105,110,101,32,101,120,116,101,110,100,115,32,99,108,97,115,115,32,84,111,107,101,110,32,101,120,116,101,110,100,115,32,99,108,97,115,115,32,82,111,108,101,115,123,35,114,111,108,101,115,61,123,79,87,78,69,82,58,91,93,44,77,73,78,84,58,91,93,44,66,85,82,78,58,91,93,125,59,99,111,110,115,116,114,117,99,116,111,114,40,114,111,108,101,115,41,123,105,102,40,114,111,108,101,115,41,123,105,102,40,33,40,114,111,108,101,115,32,105,110,115,116,97,110,99,101,111,102,32,79,98,106,101,99,116,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,101,120,112,101,99,116,101,100,32,114,111,108,101,115,32,116,111,32,98,101,32,97,110,32,111,98,106,101,99,116,92,34,41,59,116,104,105,115,46,35,114,111,108,101,115,61,123,46,46,46,114,111,108,101,115,44,46,46,46,116,104,105,115,46,35,114,111,108,101,115,125,125,101,108,115,101,32,116,104,105,115,46,35,103,114,97,110,116,82,111,108,101,40,109,115,103,46,115,101,110,100,101,114,44,92,34,79,87,78,69,82,92,34,41,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,114,111,108,101,115,58,116,104,105,115,46,114,111,108,101,115,125,125,103,101,116,32,114,111,108,101,115,40,41,123,114,101,116,117,114,110,123,46,46,46,116,104,105,115,46,35,114,111,108,101,115,125,125,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,114,101,116,117,114,110,33,33,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,38,38,45,49,33,61,61,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,105,110,100,101,120,79,102,40,97,100,100,114,101,115,115,41,125,35,103,114,97,110,116,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,96,36,123,114,111,108,101,125,32,114,111,108,101,32,97,108,114,101,97,100,121,32,103,114,97,110,116,101,100,32,102,111,114,32,36,123,97,100,100,114,101,115,115,125,96,41,59,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,112,117,115,104,40,97,100,100,114,101,115,115,41,125,35,114,101,118,111,107,101,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,96,36,123,114,111,108,101,125,32,114,111,108,101,32,97,108,114,101,97,100,121,32,114,101,118,111,107,101,100,32,102,111,114,32,36,123,97,100,100,114,101,115,115,125,96,41,59,105,102,40,92,34,79,87,78,69,82,92,34,61,61,61,114,111,108,101,38,38,49,61,61,61,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,108,101,110,103,116,104,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,97,116,108,101,97,115,116,32,111,110,101,32,111,119,110,101,114,32,105,115,32,110,101,101,100,101,100,33,92,34,41,59,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,115,112,108,105,99,101,40,116,104,105,115,46,35,114,111,108,101,115,91,114,111,108,101,93,46,105,110,100,101,120,79,102,40,97,100,100,114,101,115,115,41,41,125,103,114,97,110,116,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,92,34,79,87,78,69,82,92,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,78,111,116,32,97,108,108,111,119,101,100,92,34,41,59,116,104,105,115,46,35,103,114,97,110,116,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,125,114,101,118,111,107,101,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,97,100,100,114,101,115,115,44,92,34,79,87,78,69,82,92,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,78,111,116,32,97,108,108,111,119,101,100,92,34,41,59,116,104,105,115,46,35,114,101,118,111,107,101,82,111,108,101,40,97,100,100,114,101,115,115,44,114,111,108,101,41,125,125,123,35,110,97,109,101,59,35,115,121,109,98,111,108,59,35,104,111,108,100,101,114,115,61,48,59,35,98,97,108,97,110,99,101,115,61,123,125,59,35,97,112,112,114,111,118,97,108,115,61,123,125,59,35,100,101,99,105,109,97,108,115,61,49,56,59,35,116,111,116,97,108,83,117,112,112,108,121,61,66,105,103,78,117,109,98,101,114,46,102,114,111,109,40,48,41,59,99,111,110,115,116,114,117,99,116,111,114,40,110,97,109,101,44,115,121,109,98,111,108,44,100,101,99,105,109,97,108,115,61,49,56,44,115,116,97,116,101,41,123,105,102,40,33,110,97,109,101,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,110,97,109,101,32,117,110,100,101,102,105,110,101,100,92,34,41,59,105,102,40,33,115,121,109,98,111,108,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,115,121,109,98,111,108,32,117,110,100,101,102,105,110,101,100,92,34,41,59,115,117,112,101,114,40,115,116,97,116,101,63,46,114,111,108,101,115,41,44,116,104,105,115,46,35,110,97,109,101,61,110,97,109,101,44,116,104,105,115,46,35,115,121,109,98,111,108,61,115,121,109,98,111,108,44,116,104,105,115,46,35,100,101,99,105,109,97,108,115,61,100,101,99,105,109,97,108,115,125,103,101,116,32,115,116,97,116,101,40,41,123,114,101,116,117,114,110,123,46,46,46,115,117,112,101,114,46,115,116,97,116,101,44,104,111,108,100,101,114,115,58,116,104,105,115,46,104,111,108,100,101,114,115,44,98,97,108,97,110,99,101,115,58,116,104,105,115,46,98,97,108,97,110,99,101,115,44,97,112,112,114,111,118,97,108,115,58,123,46,46,46,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,125,44,116,111,116,97,108,83,117,112,112,108,121,58,116,104,105,115,46,116,111,116,97,108,83,117,112,112,108,121,125,125,103,101,116,32,116,111,116,97,108,83,117,112,112,108,121,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,125,103,101,116,32,110,97,109,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,110,97,109,101,125,103,101,116,32,115,121,109,98,111,108,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,115,121,109,98,111,108,125,103,101,116,32,104,111,108,100,101,114,115,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,104,111,108,100,101,114,115,125,103,101,116,32,98,97,108,97,110,99,101,115,40,41,123,114,101,116,117,114,110,123,46,46,46,116,104,105,115,46,35,98,97,108,97,110,99,101,115,125,125,109,105,110,116,40,116,111,44,97,109,111,117,110,116,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,109,115,103,46,115,101,110,100,101,114,44,92,34,77,73,78,84,92,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,110,111,116,32,97,108,108,111,119,101,100,92,34,41,59,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,61,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,46,97,100,100,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,105,110,99,114,101,97,115,101,66,97,108,97,110,99,101,40,116,111,44,97,109,111,117,110,116,41,125,98,117,114,110,40,116,111,44,97,109,111,117,110,116,41,123,105,102,40,33,116,104,105,115,46,104,97,115,82,111,108,101,40,109,115,103,46,115,101,110,100,101,114,44,92,34,66,85,82,78,92,34,41,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,110,111,116,32,97,108,108,111,119,101,100,92,34,41,59,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,61,116,104,105,115,46,35,116,111,116,97,108,83,117,112,112,108,121,46,115,117,98,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,100,101,99,114,101,97,115,101,66,97,108,97,110,99,101,40,116,111,44,97,109,111,117,110,116,41,125,35,98,101,102,111,114,101,84,114,97,110,115,102,101,114,40,102,114,111,109,44,116,111,44,97,109,111,117,110,116,41,123,105,102,40,33,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,102,114,111,109,93,124,124,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,102,114,111,109,93,60,97,109,111,117,110,116,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,97,109,111,117,110,116,32,101,120,99,101,101,100,115,32,98,97,108,97,110,99,101,92,34,41,125,35,117,112,100,97,116,101,72,111,108,100,101,114,115,40,97,100,100,114,101,115,115,44,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,41,123,92,34,48,120,48,48,92,34,61,61,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,46,116,111,72,101,120,83,116,114,105,110,103,40,41,63,116,104,105,115,46,35,104,111,108,100,101,114,115,45,61,49,58,92,34,48,120,48,48,92,34,33,61,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,46,116,111,72,101,120,83,116,114,105,110,103,40,41,38,38,92,34,48,120,48,48,92,34,61,61,61,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,46,116,111,72,101,120,83,116,114,105,110,103,40,41,38,38,40,116,104,105,115,46,35,104,111,108,100,101,114,115,43,61,49,41,125,35,105,110,99,114,101,97,115,101,66,97,108,97,110,99,101,40,97,100,100,114,101,115,115,44,97,109,111,117,110,116,41,123,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,124,124,40,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,61,66,105,103,78,117,109,98,101,114,46,102,114,111,109,40,48,41,41,59,99,111,110,115,116,32,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,59,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,46,97,100,100,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,117,112,100,97,116,101,72,111,108,100,101,114,115,40,97,100,100,114,101,115,115,44,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,41,125,35,100,101,99,114,101,97,115,101,66,97,108,97,110,99,101,40,97,100,100,114,101,115,115,44,97,109,111,117,110,116,41,123,99,111,110,115,116,32,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,59,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,61,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,46,115,117,98,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,117,112,100,97,116,101,72,111,108,100,101,114,115,40,97,100,100,114,101,115,115,44,112,114,101,118,105,111,117,115,66,97,108,97,110,99,101,41,125,98,97,108,97,110,99,101,79,102,40,97,100,100,114,101,115,115,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,98,97,108,97,110,99,101,115,91,97,100,100,114,101,115,115,93,125,115,101,116,65,112,112,114,111,118,97,108,40,111,112,101,114,97,116,111,114,44,97,109,111,117,110,116,41,123,99,111,110,115,116,32,111,119,110,101,114,61,103,108,111,98,97,108,84,104,105,115,46,109,115,103,46,115,101,110,100,101,114,59,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,91,111,119,110,101,114,93,124,124,40,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,91,111,119,110,101,114,93,61,123,125,41,44,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,91,111,119,110,101,114,93,91,111,112,101,114,97,116,111,114,93,61,97,109,111,117,110,116,125,97,112,112,114,111,118,101,100,40,111,119,110,101,114,44,111,112,101,114,97,116,111,114,44,97,109,111,117,110,116,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,97,112,112,114,111,118,97,108,115,91,111,119,110,101,114,93,91,111,112,101,114,97,116,111,114,93,61,61,61,97,109,111,117,110,116,125,116,114,97,110,115,102,101,114,40,102,114,111,109,44,116,111,44,97,109,111,117,110,116,41,123,97,109,111,117,110,116,61,66,105,103,78,117,109,98,101,114,46,102,114,111,109,40,97,109,111,117,110,116,41,44,116,104,105,115,46,35,98,101,102,111,114,101,84,114,97,110,115,102,101,114,40,102,114,111,109,44,116,111,44,97,109,111,117,110,116,41,44,116,104,105,115,46,35,100,101,99,114,101,97,115,101,66,97,108,97,110,99,101,40,102,114,111,109,44,97,109,111,117,110,116,41,44,116,104,105,115,46,35,105,110,99,114,101,97,115,101,66,97,108,97,110,99,101,40,116,111,44,97,109,111,117,110,116,41,125,125,123,99,111,110,115,116,114,117,99,116,111,114,40,115,116,97,116,101,41,123,115,117,112,101,114,40,92,34,65,114,116,79,110,108,105,110,101,92,34,44,92,34,65,82,84,92,34,44,49,56,44,115,116,97,116,101,41,125,125,59,92,110,34,44,34,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,34,58,91,93,125";
364
362
  var nameService = "237,198,141,3,123,34,99,114,101,97,116,111,114,34,58,34,51,67,122,86,51,66,98,76,103,117,57,105,55,119,70,115,83,101,82,101,90,113,110,80,111,53,82,114,121,49,118,81,98,82,115,89,114,116,67,67,97,81,103,98,113,80,72,112,116,117,85,111,72,52,34,44,34,99,111,110,116,114,97,99,116,34,58,34,114,101,116,117,114,110,32,99,108,97,115,115,32,78,97,109,101,83,101,114,118,105,99,101,123,35,110,97,109,101,61,92,34,65,114,116,79,110,108,105,110,101,78,97,109,101,83,101,114,118,105,99,101,92,34,59,35,111,119,110,101,114,59,35,112,114,105,99,101,61,48,59,35,114,101,103,105,115,116,114,121,61,123,125,59,35,99,117,114,114,101,110,99,121,59,103,101,116,32,110,97,109,101,40,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,110,97,109,101,125,103,101,116,32,114,101,103,105,115,116,114,121,40,41,123,114,101,116,117,114,110,123,46,46,46,116,104,105,115,46,35,114,101,103,105,115,116,114,121,125,125,103,101,116,32,115,116,97,116,101,40,41,123,125,99,111,110,115,116,114,117,99,116,111,114,40,102,97,99,116,111,114,121,65,100,100,114,101,115,115,44,99,117,114,114,101,110,99,121,44,118,97,108,105,100,97,116,111,114,65,100,100,114,101,115,115,44,112,114,105,99,101,44,115,116,97,116,101,41,123,115,116,97,116,101,63,40,116,104,105,115,46,35,111,119,110,101,114,61,115,116,97,116,101,46,111,119,110,101,114,44,116,104,105,115,46,35,114,101,103,105,115,116,114,121,61,115,116,97,116,101,46,114,101,103,105,115,116,114,121,44,116,104,105,115,46,35,99,117,114,114,101,110,99,121,61,115,116,97,116,101,46,99,117,114,114,101,110,99,121,44,116,104,105,115,46,35,112,114,105,99,101,61,115,116,97,116,101,46,112,114,105,99,101,41,58,40,116,104,105,115,46,35,111,119,110,101,114,61,109,115,103,46,115,101,110,100,101,114,44,116,104,105,115,46,35,112,114,105,99,101,61,112,114,105,99,101,44,116,104,105,115,46,35,114,101,103,105,115,116,114,121,46,65,114,116,79,110,108,105,110,101,67,111,110,116,114,97,99,116,70,97,99,116,111,114,121,61,123,111,119,110,101,114,58,109,115,103,46,115,101,110,100,101,114,44,97,100,100,114,101,115,115,58,102,97,99,116,111,114,121,65,100,100,114,101,115,115,125,44,116,104,105,115,46,35,114,101,103,105,115,116,114,121,46,65,114,116,79,110,108,105,110,101,84,111,107,101,110,61,123,111,119,110,101,114,58,109,115,103,46,115,101,110,100,101,114,44,97,100,100,114,101,115,115,58,99,117,114,114,101,110,99,121,125,44,116,104,105,115,46,35,114,101,103,105,115,116,114,121,46,65,114,116,79,110,108,105,110,101,86,97,108,105,100,97,116,111,114,115,61,123,111,119,110,101,114,58,109,115,103,46,115,101,110,100,101,114,44,97,100,100,114,101,115,115,58,118,97,108,105,100,97,116,111,114,65,100,100,114,101,115,115,125,44,116,104,105,115,46,35,99,117,114,114,101,110,99,121,61,99,117,114,114,101,110,99,121,41,125,99,104,97,110,103,101,79,119,110,101,114,40,111,119,110,101,114,41,123,105,102,40,109,115,103,46,115,101,110,100,101,114,33,61,61,116,104,105,115,46,35,111,119,110,101,114,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,110,111,32,111,119,110,101,114,92,34,41,59,116,104,105,115,46,35,111,119,110,101,114,61,111,119,110,101,114,125,99,104,97,110,103,101,80,114,105,99,101,40,112,114,105,99,101,41,123,105,102,40,109,115,103,46,115,101,110,100,101,114,33,61,61,116,104,105,115,46,35,111,119,110,101,114,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,110,111,32,111,119,110,101,114,92,34,41,59,116,104,105,115,46,35,112,114,105,99,101,61,112,114,105,99,101,125,99,104,97,110,103,101,67,117,114,114,101,110,99,121,40,99,117,114,114,101,110,99,121,41,123,105,102,40,109,115,103,46,115,101,110,100,101,114,33,61,61,116,104,105,115,46,35,111,119,110,101,114,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,110,111,32,111,119,110,101,114,92,34,41,59,116,104,105,115,46,35,99,117,114,114,101,110,99,121,61,99,117,114,114,101,110,99,121,125,97,115,121,110,99,32,112,117,114,99,104,97,115,101,78,97,109,101,40,110,97,109,101,44,97,100,100,114,101,115,115,41,123,105,102,40,97,119,97,105,116,32,109,115,103,46,99,97,108,108,40,116,104,105,115,46,35,99,117,114,114,101,110,99,121,44,92,34,98,97,108,97,110,99,101,79,102,92,34,44,91,109,115,103,46,115,101,110,100,101,114,93,41,60,116,104,105,115,46,35,112,114,105,99,101,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,112,114,105,99,101,32,101,120,99,101,101,100,115,32,98,97,108,97,110,99,101,92,34,41,59,116,114,121,123,97,119,97,105,116,32,109,115,103,46,99,97,108,108,40,116,104,105,115,46,35,99,117,114,114,101,110,99,121,44,92,34,116,114,97,110,115,102,101,114,92,34,44,91,109,115,103,46,115,101,110,100,101,114,44,116,104,105,115,46,35,111,119,110,101,114,44,116,104,105,115,46,35,112,114,105,99,101,93,41,125,99,97,116,99,104,40,101,41,123,116,104,114,111,119,32,101,125,116,104,105,115,46,35,114,101,103,105,115,116,114,121,91,110,97,109,101,93,61,123,111,119,110,101,114,58,109,115,103,46,115,101,110,100,101,114,44,97,100,100,114,101,115,115,58,97,100,100,114,101,115,115,125,125,108,111,111,107,117,112,40,110,97,109,101,41,123,114,101,116,117,114,110,32,116,104,105,115,46,35,114,101,103,105,115,116,114,121,91,110,97,109,101,93,125,116,114,97,110,115,102,101,114,79,119,110,101,114,115,104,105,112,40,110,97,109,101,44,116,111,41,123,105,102,40,109,115,103,46,115,101,110,100,101,114,33,61,61,116,104,105,115,46,35,114,101,103,105,115,116,114,121,46,111,119,110,101,114,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,110,111,116,32,97,32,111,119,110,101,114,92,34,41,59,116,104,105,115,46,35,114,101,103,105,115,116,114,121,91,110,97,109,101,93,46,111,119,110,101,114,61,116,111,125,99,104,97,110,103,101,65,100,100,114,101,115,115,40,110,97,109,101,44,97,100,100,114,101,115,115,41,123,105,102,40,109,115,103,46,115,101,110,100,101,114,33,61,61,116,104,105,115,46,35,114,101,103,105,115,116,114,121,46,111,119,110,101,114,41,116,104,114,111,119,32,110,101,119,32,69,114,114,111,114,40,92,34,110,111,116,32,97,32,111,119,110,101,114,92,34,41,59,116,104,105,115,46,35,114,101,103,105,115,116,114,121,91,110,97,109,101,93,46,97,100,100,114,101,115,115,61,97,100,100,114,101,115,115,125,125,59,92,110,34,44,34,99,111,110,115,116,114,117,99,116,111,114,80,97,114,97,109,101,116,101,114,115,34,58,91,34,105,104,110,121,50,103,113,103,111,114,119,111,102,104,118,102,103,116,114,53,100,109,50,116,97,114,103,110,120,114,117,108,53,114,114,52,119,110,121,107,52,118,108,55,97,107,98,109,119,111,120,52,51,110,108,118,112,105,109,34,44,34,105,104,110,121,50,103,113,104,101,55,103,97,122,107,105,101,101,121,52,111,51,114,122,116,102,121,55,53,55,105,97,51,97,115,54,115,110,114,109,111,118,52,101,51,118,107,102,100,118,116,50,111,108,118,120,51,115,116,101,34,44,34,105,104,110,121,50,103,113,104,108,109,117,98,114,118,107,108,51,105,120,121,102,97,100,111,109,112,118,102,105,105,110,118,119,116,104,105,52,51,119,112,116,52,113,100,102,106,55,54,55,110,104,112,121,106,108,110,119,105,110,34,44,34,49,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,34,93,125";
@@ -491,20 +489,41 @@ class Chain {
491
489
  // handle native contracts
492
490
  }
493
491
 
492
+ promiseRequests(promises) {
493
+ return new Promise(async (resolve, reject) => {
494
+ const timeout = setTimeout(() => {
495
+ resolve([{index: 0, hash: '0x0'}]);
496
+ debug('sync timed out');
497
+ }, 10000);
498
+
499
+ promises = await Promise.allSettled(promises);
500
+ promises = promises.filter(({status}) => status === 'fulfilled');
501
+ clearTimeout(timeout);
502
+
503
+ promises = promises.map(({value}) => new peernet.protos['peernet-response'](value));
504
+ promises = await Promise.all(promises);
505
+ promises = promises.map(node => node.decoded.response);
506
+ resolve(promises);
507
+ })
508
+
509
+ }
510
+
511
+ sync() {
512
+ return this.#sync()
513
+ }
514
+
494
515
  async #sync() {
495
516
  let promises = [];
517
+
518
+ let data = await new peernet.protos['peernet-request']({request: 'lastBlock'});
519
+ const node = await peernet.prepareMessage(data);
520
+
496
521
  for (const peer of peernet.connections) {
497
- if (peer.peerId !== this.id) {
498
- let data = await new peernet.protos['peernet-request']({request: 'lastBlock'});
499
- const node = await peernet.prepareMessage(data);
522
+ if (peer.connected && peer.readyState === 'open' && peer.peerId !== this.id) {
500
523
  promises.push(peer.request(node.encoded));
501
- }
524
+ } else if (!peer.connected || peer.readyState !== 'open') ;
502
525
  }
503
- promises = await Promise.allSettled(promises);
504
- promises = promises.filter(({status}) => status === 'fulfilled');
505
- promises = promises.map(({value}) => new peernet.protos['peernet-response'](value));
506
- promises = await Promise.all(promises);
507
- promises = promises.map(node => node.decoded.response);
526
+ promises = await this.promiseRequests(promises);
508
527
  promises = promises.reduce((set, value) => {
509
528
 
510
529
  if (value.index > set.index) {
@@ -514,9 +533,7 @@ class Chain {
514
533
  return set
515
534
  }, {index: 0, hash: '0x0'});
516
535
  // get lastblock
517
- console.log(promises.hash);
518
536
  if (promises.hash && promises.hash !== '0x0') {
519
- console.log('get');
520
537
  let localBlock = await peernet.get(promises.hash);
521
538
  console.log({localBlock});
522
539
  }
@@ -548,9 +565,6 @@ class Chain {
548
565
  peernet.subscribe('validator:timeout', this.#validatorTimeout.bind(this));
549
566
 
550
567
  pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
551
- // let a = await new BlockMessage(this.#machine.lastBlock)
552
- // console.log(a.decoded);
553
- // console.log(await a.hash);
554
568
 
555
569
  try {
556
570
  let localBlock;
@@ -711,7 +725,8 @@ async resolveBlock(hash) {
711
725
  }
712
726
 
713
727
  async #addBlock(block) {
714
- const blockMessage = await new BlockMessage(block);
728
+ console.log(block);
729
+ const blockMessage = await new BlockMessage(new Uint8Array(Object.values(block)));
715
730
  // if (!Buffer.isBuffer(block)) block = Buffer.from(block, 'hex')
716
731
  // const transactionJob = async transaction => {
717
732
  // try {
@@ -726,14 +741,17 @@ async resolveBlock(hash) {
726
741
  // transaction = new TransactionMessage(transaction)
727
742
  // return transaction
728
743
  // }
744
+
745
+ console.log(blockMessage);
729
746
  await Promise.all(blockMessage.decoded.transactions
730
747
  .map(async transaction => transactionPoolStore.delete(await transaction.hash)));
731
748
  const hash = await blockMessage.hash;
732
749
  // let transactions = blockMessage.decoded.transactions.map(tx => transactionJob(tx))
733
750
  // transactions = await Promise.all(transactions)
734
- this.#lastBlock = { hash, ...blockMessage.decoded };
751
+
735
752
  await blockStore.put(hash, blockMessage.encoded);
736
- await chainStore.put('lastBlock', hash);
753
+
754
+ if (this.lastBlock.index < blockMessage.decoded.index) this.#updateState(blockMessage);
737
755
  debug(`added block: ${hash}`);
738
756
  let promises = [];
739
757
  let contracts = [];
@@ -755,6 +773,8 @@ async resolveBlock(hash) {
755
773
  // // await stateStore.put(contract, state)
756
774
  // console.log(state);
757
775
  // }
776
+
777
+
758
778
  pubsub.publish('block-processed', blockMessage.decoded);
759
779
  } catch (e) {
760
780
  console.log({e});
@@ -762,8 +782,10 @@ async resolveBlock(hash) {
762
782
 
763
783
  }
764
784
 
765
- async #updateState() {
766
-
785
+ async #updateState(message) {
786
+ const hash = await message.hash;
787
+ this.#lastBlock = { hash, ...message.decoded };
788
+ await chainStore.put('lastBlock', hash);
767
789
  }
768
790
 
769
791
 
@@ -925,13 +947,11 @@ async resolveBlock(hash) {
925
947
  const hash = await blockMessage.hash;
926
948
 
927
949
 
928
- this.#lastBlock = { hash, ...blockMessage.decoded };
929
950
  await blockStore.put(hash, blockMessage.encoded);
930
- await chainStore.put('lastBlock', hash);
951
+ this.#updateState(blockMessage);
931
952
  debug(`created block: ${hash}`);
932
953
 
933
954
  peernet.publish('add-block', blockMessage.encoded);
934
- this.#updateState(blockMessage);
935
955
  } catch (e) {
936
956
  console.log(e);
937
957
  throw Error(`invalid block ${block}`)
@@ -0,0 +1,50 @@
1
+ (self["webpackChunk_leofcoin_chain"] = self["webpackChunk_leofcoin_chain"] || []).push([[510],{
2
+
3
+ /***/ 5162:
4
+ /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
5
+
6
+ __webpack_require__.r(__webpack_exports__);
7
+ /* harmony import */ var _leofcoin_multi_wallet__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9755);
8
+
9
+
10
+ /**
11
+ * @params {String} network
12
+ * @return {object} { identity, accounts, config }
13
+ */
14
+ /* harmony default export */ __webpack_exports__["default"] = (async network => {
15
+ let wallet = new _leofcoin_multi_wallet__WEBPACK_IMPORTED_MODULE_0__["default"](network);
16
+ /**
17
+ * @type {string}
18
+ */
19
+ const mnemonic = await wallet.generate();
20
+
21
+ wallet = new _leofcoin_multi_wallet__WEBPACK_IMPORTED_MODULE_0__["default"](network)
22
+ await wallet.recover(mnemonic, network)
23
+ /**
24
+ * @type {object}
25
+ */
26
+ const account = wallet.account(0)
27
+ /**
28
+ * @type {object}
29
+ */
30
+ const external = account.external(0)
31
+ const internal = account.internal(0)
32
+
33
+ return {
34
+ identity: {
35
+ mnemonic,
36
+ // multiWIF: wallet.export(),
37
+ publicKey: external.publicKey,
38
+ privateKey: external.privateKey,
39
+ walletId: external.id
40
+ },
41
+ accounts: [['main account', external.address, internal.address]]
42
+ // config: {
43
+ // }
44
+ }
45
+ });
46
+
47
+
48
+ /***/ })
49
+
50
+ }])