@leofcoin/chain 1.7.26 → 1.7.27

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.
@@ -1466,6 +1466,8 @@ var hasRequiredRange;
1466
1466
  function requireRange () {
1467
1467
  if (hasRequiredRange) return range;
1468
1468
  hasRequiredRange = 1;
1469
+ const SPACE_CHARACTERS = /\s+/g;
1470
+
1469
1471
  // hoisted class for cyclic dependency
1470
1472
  class Range {
1471
1473
  constructor (range, options) {
@@ -1486,7 +1488,7 @@ function requireRange () {
1486
1488
  // just put it in the set and return
1487
1489
  this.raw = range.value;
1488
1490
  this.set = [[range]];
1489
- this.format();
1491
+ this.formatted = undefined;
1490
1492
  return this
1491
1493
  }
1492
1494
 
@@ -1497,10 +1499,7 @@ function requireRange () {
1497
1499
  // First reduce all whitespace as much as possible so we do not have to rely
1498
1500
  // on potentially slow regexes like \s*. This is then stored and used for
1499
1501
  // future error messages as well.
1500
- this.raw = range
1501
- .trim()
1502
- .split(/\s+/)
1503
- .join(' ');
1502
+ this.raw = range.trim().replace(SPACE_CHARACTERS, ' ');
1504
1503
 
1505
1504
  // First, split on ||
1506
1505
  this.set = this.raw
@@ -1534,14 +1533,29 @@ function requireRange () {
1534
1533
  }
1535
1534
  }
1536
1535
 
1537
- this.format();
1536
+ this.formatted = undefined;
1537
+ }
1538
+
1539
+ get range () {
1540
+ if (this.formatted === undefined) {
1541
+ this.formatted = '';
1542
+ for (let i = 0; i < this.set.length; i++) {
1543
+ if (i > 0) {
1544
+ this.formatted += '||';
1545
+ }
1546
+ const comps = this.set[i];
1547
+ for (let k = 0; k < comps.length; k++) {
1548
+ if (k > 0) {
1549
+ this.formatted += ' ';
1550
+ }
1551
+ this.formatted += comps[k].toString().trim();
1552
+ }
1553
+ }
1554
+ }
1555
+ return this.formatted
1538
1556
  }
1539
1557
 
1540
1558
  format () {
1541
- this.range = this.set
1542
- .map((comps) => comps.join(' ').trim())
1543
- .join('||')
1544
- .trim();
1545
1559
  return this.range
1546
1560
  }
1547
1561
 
@@ -3278,7 +3292,13 @@ class Machine {
3278
3292
  const value = await this.#askWorker('get', { contract, method: 'state', params: [] });
3279
3293
  state[contract] = value;
3280
3294
  }));
3281
- const accounts = await Promise.all((await accountsStore.keys()).map((address) => accountsStore.get(address)));
3295
+ let accounts;
3296
+ try {
3297
+ accounts = await Promise.all((await accountsStore.keys()).map((address) => accountsStore.get(address)));
3298
+ }
3299
+ catch (error) {
3300
+ accounts = [];
3301
+ }
3282
3302
  const tasks = [
3283
3303
  stateStore.put('lastBlock', JSON.stringify(await this.lastBlock)),
3284
3304
  stateStore.put('states', JSON.stringify(state)),
@@ -4460,7 +4480,10 @@ class Chain extends VersionControl {
4460
4480
  // // await transactionStore.put(transaction.hash, transaction.encoded)
4461
4481
  // if (!contracts.includes(transaction.to)) {
4462
4482
  // contracts.push(transaction.to)
4463
- // }
4483
+ // // Todo: go trough all accounts
4484
+ // //@ts-ignore
4485
+ // promises.push(this.#executeTransaction(transaction))
4486
+ // }
4464
4487
  // // Todo: go trough all accounts
4465
4488
  // //@ts-ignore
4466
4489
  // promises.push(this.#executeTransaction(transaction))
@@ -44,62 +44,67 @@ var bytecodes = {
44
44
  validators: validators
45
45
  };
46
46
 
47
- class LittlePubSub {
48
- subscribers = {};
49
- verbose;
50
- constructor(verbose) {
51
- this.verbose = verbose;
52
- }
53
- _handleContext(handler, context) {
54
- if (typeof context === 'undefined') {
55
- context = handler;
56
- }
57
- return context;
58
- }
59
- hasSubscribers(event) {
60
- return this.subscribers[event] ? true : false;
61
- }
62
- subscribe(event, handler, context) {
63
- if (!this.hasSubscribers(event))
64
- this.subscribers[event] = { handlers: [], value: undefined };
65
- context = this._handleContext(handler, context);
66
- this.subscribers[event].handlers.push(handler.bind(context));
67
- }
68
- unsubscribe(event, handler, context) {
69
- if (!this.hasSubscribers(event))
70
- return;
71
- context = this._handleContext(handler, context);
72
- const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
73
- this.subscribers[event].handlers.splice(index);
74
- if (this.subscribers[event].handlers.length === 0)
75
- delete this.subscribers[event];
76
- }
77
- publish(event, value, verbose) {
78
- // always set value even when having no subscribers
79
- if (!this.hasSubscribers(event))
80
- this.subscribers[event] = {
81
- handlers: []
82
- };
83
- const oldValue = this.subscribers[event]?.value;
84
- if (this.verbose || verbose || oldValue !== value) {
85
- this.subscribers[event].value = value;
86
- for (const handler of this.subscribers[event].handlers) {
87
- handler(value, oldValue);
88
- }
89
- }
90
- }
91
- publishVerbose(event, value) {
92
- this.publish(event, value, true);
93
- }
94
- once(event) {
95
- return new Promise((resolve) => {
96
- const cb = (value) => {
97
- resolve(value);
98
- this.unsubscribe(event, cb);
99
- };
100
- this.subscribe(event, cb);
101
- });
102
- }
47
+ class LittlePubSub {
48
+ subscribers = {};
49
+ verbose;
50
+ constructor(verbose) {
51
+ this.verbose = verbose;
52
+ }
53
+ _handleContext(handler, context) {
54
+ if (typeof context === 'undefined') {
55
+ context = handler;
56
+ }
57
+ return context;
58
+ }
59
+ hasSubscribers(event) {
60
+ return this.subscribers[event] ? true : false;
61
+ }
62
+ getValue(event) {
63
+ if (this.subscribers[event])
64
+ return this.subscribers[event].value;
65
+ return undefined;
66
+ }
67
+ subscribe(event, handler, context) {
68
+ if (!this.hasSubscribers(event))
69
+ this.subscribers[event] = { handlers: [], value: undefined };
70
+ context = this._handleContext(handler, context);
71
+ this.subscribers[event].handlers.push(handler.bind(context));
72
+ }
73
+ unsubscribe(event, handler, context) {
74
+ if (!this.hasSubscribers(event))
75
+ return;
76
+ context = this._handleContext(handler, context);
77
+ const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
78
+ this.subscribers[event].handlers.splice(index);
79
+ if (this.subscribers[event].handlers.length === 0)
80
+ delete this.subscribers[event];
81
+ }
82
+ publish(event, value, verbose) {
83
+ // always set value even when having no subscribers
84
+ if (!this.hasSubscribers(event))
85
+ this.subscribers[event] = {
86
+ handlers: []
87
+ };
88
+ const oldValue = this.subscribers[event]?.value;
89
+ if (this.verbose || verbose || oldValue !== value) {
90
+ this.subscribers[event].value = value;
91
+ for (const handler of this.subscribers[event].handlers) {
92
+ handler(value, oldValue);
93
+ }
94
+ }
95
+ }
96
+ publishVerbose(event, value) {
97
+ this.publish(event, value, true);
98
+ }
99
+ once(event) {
100
+ return new Promise((resolve) => {
101
+ const cb = (value) => {
102
+ resolve(value);
103
+ this.unsubscribe(event, cb);
104
+ };
105
+ this.subscribe(event, cb);
106
+ });
107
+ }
103
108
  }
104
109
 
105
110
  const pubsub = new LittlePubSub();
package/exports/chain.js CHANGED
@@ -393,7 +393,13 @@ class Machine {
393
393
  const value = await this.#askWorker('get', { contract, method: 'state', params: [] });
394
394
  state[contract] = value;
395
395
  }));
396
- const accounts = await Promise.all((await accountsStore.keys()).map((address) => accountsStore.get(address)));
396
+ let accounts;
397
+ try {
398
+ accounts = await Promise.all((await accountsStore.keys()).map((address) => accountsStore.get(address)));
399
+ }
400
+ catch (error) {
401
+ accounts = [];
402
+ }
397
403
  const tasks = [
398
404
  stateStore.put('lastBlock', JSON.stringify(await this.lastBlock)),
399
405
  stateStore.put('states', JSON.stringify(state)),
@@ -1575,7 +1581,10 @@ class Chain extends VersionControl {
1575
1581
  // // await transactionStore.put(transaction.hash, transaction.encoded)
1576
1582
  // if (!contracts.includes(transaction.to)) {
1577
1583
  // contracts.push(transaction.to)
1578
- // }
1584
+ // // Todo: go trough all accounts
1585
+ // //@ts-ignore
1586
+ // promises.push(this.#executeTransaction(transaction))
1587
+ // }
1579
1588
  // // Todo: go trough all accounts
1580
1589
  // //@ts-ignore
1581
1590
  // promises.push(this.#executeTransaction(transaction))
@@ -44,62 +44,67 @@ var bytecodes = {
44
44
  validators: validators
45
45
  };
46
46
 
47
- class LittlePubSub {
48
- subscribers = {};
49
- verbose;
50
- constructor(verbose) {
51
- this.verbose = verbose;
52
- }
53
- _handleContext(handler, context) {
54
- if (typeof context === 'undefined') {
55
- context = handler;
56
- }
57
- return context;
58
- }
59
- hasSubscribers(event) {
60
- return this.subscribers[event] ? true : false;
61
- }
62
- subscribe(event, handler, context) {
63
- if (!this.hasSubscribers(event))
64
- this.subscribers[event] = { handlers: [], value: undefined };
65
- context = this._handleContext(handler, context);
66
- this.subscribers[event].handlers.push(handler.bind(context));
67
- }
68
- unsubscribe(event, handler, context) {
69
- if (!this.hasSubscribers(event))
70
- return;
71
- context = this._handleContext(handler, context);
72
- const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
73
- this.subscribers[event].handlers.splice(index);
74
- if (this.subscribers[event].handlers.length === 0)
75
- delete this.subscribers[event];
76
- }
77
- publish(event, value, verbose) {
78
- // always set value even when having no subscribers
79
- if (!this.hasSubscribers(event))
80
- this.subscribers[event] = {
81
- handlers: []
82
- };
83
- const oldValue = this.subscribers[event]?.value;
84
- if (this.verbose || verbose || oldValue !== value) {
85
- this.subscribers[event].value = value;
86
- for (const handler of this.subscribers[event].handlers) {
87
- handler(value, oldValue);
88
- }
89
- }
90
- }
91
- publishVerbose(event, value) {
92
- this.publish(event, value, true);
93
- }
94
- once(event) {
95
- return new Promise((resolve) => {
96
- const cb = (value) => {
97
- resolve(value);
98
- this.unsubscribe(event, cb);
99
- };
100
- this.subscribe(event, cb);
101
- });
102
- }
47
+ class LittlePubSub {
48
+ subscribers = {};
49
+ verbose;
50
+ constructor(verbose) {
51
+ this.verbose = verbose;
52
+ }
53
+ _handleContext(handler, context) {
54
+ if (typeof context === 'undefined') {
55
+ context = handler;
56
+ }
57
+ return context;
58
+ }
59
+ hasSubscribers(event) {
60
+ return this.subscribers[event] ? true : false;
61
+ }
62
+ getValue(event) {
63
+ if (this.subscribers[event])
64
+ return this.subscribers[event].value;
65
+ return undefined;
66
+ }
67
+ subscribe(event, handler, context) {
68
+ if (!this.hasSubscribers(event))
69
+ this.subscribers[event] = { handlers: [], value: undefined };
70
+ context = this._handleContext(handler, context);
71
+ this.subscribers[event].handlers.push(handler.bind(context));
72
+ }
73
+ unsubscribe(event, handler, context) {
74
+ if (!this.hasSubscribers(event))
75
+ return;
76
+ context = this._handleContext(handler, context);
77
+ const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
78
+ this.subscribers[event].handlers.splice(index);
79
+ if (this.subscribers[event].handlers.length === 0)
80
+ delete this.subscribers[event];
81
+ }
82
+ publish(event, value, verbose) {
83
+ // always set value even when having no subscribers
84
+ if (!this.hasSubscribers(event))
85
+ this.subscribers[event] = {
86
+ handlers: []
87
+ };
88
+ const oldValue = this.subscribers[event]?.value;
89
+ if (this.verbose || verbose || oldValue !== value) {
90
+ this.subscribers[event].value = value;
91
+ for (const handler of this.subscribers[event].handlers) {
92
+ handler(value, oldValue);
93
+ }
94
+ }
95
+ }
96
+ publishVerbose(event, value) {
97
+ this.publish(event, value, true);
98
+ }
99
+ once(event) {
100
+ return new Promise((resolve) => {
101
+ const cb = (value) => {
102
+ resolve(value);
103
+ this.unsubscribe(event, cb);
104
+ };
105
+ this.subscribe(event, cb);
106
+ });
107
+ }
103
108
  }
104
109
 
105
110
  const pubsub = new LittlePubSub();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.7.26",
3
+ "version": "1.7.27",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {