@leofcoin/chain 1.7.37 → 1.7.43

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.
@@ -1,2 +1,2 @@
1
- export { N as default } from './node-browser-D_OVxIm6.js';
1
+ export { N as default } from './node-browser-lePEPRA6.js';
2
2
  import './index-XTbRdu6H.js';
@@ -64,19 +64,26 @@ class LittlePubSub {
64
64
  return this.subscribers[event].value;
65
65
  return undefined;
66
66
  }
67
- subscribe(event, handler, context) {
67
+ subscribe(event, handler, options) {
68
68
  if (!this.hasSubscribers(event))
69
69
  this.subscribers[event] = { handlers: [], value: undefined };
70
- context = this._handleContext(handler, context);
71
- this.subscribers[event].handlers.push(handler.bind(context));
70
+ const context = this._handleContext(handler, options?.context);
71
+ const _handler = handler.bind(context);
72
+ this.subscribers[event].handlers.push(_handler);
73
+ if (this.subscribers[event].value !== undefined)
74
+ _handler(this.subscribers[event].value, undefined);
72
75
  }
73
- unsubscribe(event, handler, context) {
76
+ unsubscribe(event, handler, options) {
77
+ if (!options)
78
+ options = { keepValue: false };
74
79
  if (!this.hasSubscribers(event))
75
80
  return;
76
- context = this._handleContext(handler, context);
81
+ const context = this._handleContext(handler, options.context);
77
82
  const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
78
83
  this.subscribers[event].handlers.splice(index);
79
- if (this.subscribers[event].handlers.length === 0)
84
+ // delete event if no handlers left but supports keeping value for later use
85
+ // (like when unsubscribing from a value that is still needed because others might subscibe to it)
86
+ if (this.subscribers[event].handlers.length === 0 && !options.keepValue)
80
87
  delete this.subscribers[event];
81
88
  }
82
89
  publish(event, value, verbose) {
@@ -96,13 +103,13 @@ class LittlePubSub {
96
103
  publishVerbose(event, value) {
97
104
  this.publish(event, value, true);
98
105
  }
99
- once(event) {
106
+ once(event, options) {
100
107
  return new Promise((resolve) => {
101
108
  const cb = (value) => {
102
109
  resolve(value);
103
- this.unsubscribe(event, cb);
110
+ this.unsubscribe(event, cb, options);
104
111
  };
105
- this.subscribe(event, cb);
112
+ this.subscribe(event, cb, options);
106
113
  });
107
114
  }
108
115
  }
@@ -476,6 +483,9 @@ worker.onmessage(({ id, type, input }) => {
476
483
  case 'lastBlock':
477
484
  respond(id, lastBlock);
478
485
  break;
486
+ case 'lastBlockHeight':
487
+ respond(id, lastBlock.index);
488
+ break;
479
489
  case 'latestTransactions':
480
490
  respond(id, latestTransactions);
481
491
  break;
@@ -53,7 +53,7 @@ export default class Machine {
53
53
  getBlock(index: any): Promise<any>;
54
54
  addLoadedBlock(block: any): Promise<any>;
55
55
  latestTransactions(): Promise<any>;
56
- delete(hash: any): Promise<void>;
56
+ delete(hash: any): Promise<unknown>;
57
57
  /**
58
58
  *
59
59
  * @returns Promise
@@ -18,7 +18,7 @@ export default class State extends Contract {
18
18
  sync: SyncState;
19
19
  chain: ChainState;
20
20
  };
21
- get blockHashMap(): IterableIterator<[any, any]>;
21
+ get blockHashMap(): MapIterator<[any, any]>;
22
22
  get loaded(): boolean;
23
23
  get resolving(): boolean;
24
24
  get contracts(): Promise<any>;
@@ -38,7 +38,7 @@ export default class State extends Contract {
38
38
  hash: string;
39
39
  previousHash: string;
40
40
  };
41
- get lastBlockHeight(): 0 | Promise<any>;
41
+ get lastBlockHeight(): Promise<any> | 0;
42
42
  getBlock(index: any): Promise<any>;
43
43
  getBlocks(from?: any, to?: any): Promise<[]>;
44
44
  get totalSize(): number;
@@ -64,19 +64,26 @@ class LittlePubSub {
64
64
  return this.subscribers[event].value;
65
65
  return undefined;
66
66
  }
67
- subscribe(event, handler, context) {
67
+ subscribe(event, handler, options) {
68
68
  if (!this.hasSubscribers(event))
69
69
  this.subscribers[event] = { handlers: [], value: undefined };
70
- context = this._handleContext(handler, context);
71
- this.subscribers[event].handlers.push(handler.bind(context));
70
+ const context = this._handleContext(handler, options?.context);
71
+ const _handler = handler.bind(context);
72
+ this.subscribers[event].handlers.push(_handler);
73
+ if (this.subscribers[event].value !== undefined)
74
+ _handler(this.subscribers[event].value, undefined);
72
75
  }
73
- unsubscribe(event, handler, context) {
76
+ unsubscribe(event, handler, options) {
77
+ if (!options)
78
+ options = { keepValue: false };
74
79
  if (!this.hasSubscribers(event))
75
80
  return;
76
- context = this._handleContext(handler, context);
81
+ const context = this._handleContext(handler, options.context);
77
82
  const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
78
83
  this.subscribers[event].handlers.splice(index);
79
- if (this.subscribers[event].handlers.length === 0)
84
+ // delete event if no handlers left but supports keeping value for later use
85
+ // (like when unsubscribing from a value that is still needed because others might subscibe to it)
86
+ if (this.subscribers[event].handlers.length === 0 && !options.keepValue)
80
87
  delete this.subscribers[event];
81
88
  }
82
89
  publish(event, value, verbose) {
@@ -96,13 +103,13 @@ class LittlePubSub {
96
103
  publishVerbose(event, value) {
97
104
  this.publish(event, value, true);
98
105
  }
99
- once(event) {
106
+ once(event, options) {
100
107
  return new Promise((resolve) => {
101
108
  const cb = (value) => {
102
109
  resolve(value);
103
- this.unsubscribe(event, cb);
110
+ this.unsubscribe(event, cb, options);
104
111
  };
105
- this.subscribe(event, cb);
112
+ this.subscribe(event, cb, options);
106
113
  });
107
114
  }
108
115
  }
@@ -476,6 +483,9 @@ worker.onmessage(({ id, type, input }) => {
476
483
  case 'lastBlock':
477
484
  respond(id, lastBlock);
478
485
  break;
486
+ case 'lastBlockHeight':
487
+ respond(id, lastBlock.index);
488
+ break;
479
489
  case 'latestTransactions':
480
490
  respond(id, latestTransactions);
481
491
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.7.37",
3
+ "version": "1.7.43",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {
@@ -55,7 +55,7 @@
55
55
  "@rollup/plugin-typescript": "^11.1.6",
56
56
  "@types/semver": "^7.5.8",
57
57
  "@vandeurenglenn/debug": "^1.2.5",
58
- "rollup": "^4.21.2",
58
+ "rollup": "^4.21.3",
59
59
  "rollup-plugin-modify": "^3.0.0",
60
60
  "tape": "^5.8.1",
61
61
  "tslib": "^2.7.0"
@@ -69,10 +69,10 @@
69
69
  "@leofcoin/messages": "^1.4.15",
70
70
  "@leofcoin/multi-wallet": "^3.1.8",
71
71
  "@leofcoin/networks": "^1.1.6",
72
- "@leofcoin/peernet": "^1.1.79",
73
- "@leofcoin/storage": "^3.5.31",
72
+ "@leofcoin/peernet": "^1.1.80",
73
+ "@leofcoin/storage": "^3.5.32",
74
74
  "@leofcoin/utils": "^1.1.18",
75
- "@leofcoin/workers": "^1.5.4",
75
+ "@leofcoin/workers": "^1.5.7",
76
76
  "@vandeurenglenn/base58": "^1.1.9",
77
77
  "@vandeurenglenn/easy-worker": "^1.0.2",
78
78
  "semver": "^7.6.3"