@leofcoin/chain 1.7.112 → 1.7.113
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/exports/browser/{client-DgmVTCEc-WVRX01s7.js → client-bgSiSUVr-WviWWZtO.js} +23 -81
- package/exports/browser/{messages-Bx4w-Pqo-DSXPMvjy.js → messages-C3VxYRj3-pcgSwlQ_.js} +1 -1
- package/exports/browser/{node-browser-Dk2CzshW.js → node-browser-B7Z9OIT2.js} +2 -2
- package/exports/browser/node-browser.js +1 -1
- package/exports/browser/workers/block-worker.js +13 -23
- package/exports/workers/block-worker.js +13 -23
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { L as LittlePubSub } from './node-browser-
|
|
1
|
+
import { L as LittlePubSub } from './node-browser-B7Z9OIT2.js';
|
|
2
2
|
import './identity-Cn0iQbY3-CeW0giQS.js';
|
|
3
3
|
import './index-DUfUgiQY.js';
|
|
4
4
|
|
|
@@ -428,7 +428,6 @@ class Client {
|
|
|
428
428
|
#connections = {};
|
|
429
429
|
#stars = {};
|
|
430
430
|
#starListeners = {};
|
|
431
|
-
#handlersSetup = false;
|
|
432
431
|
#reinitLock = null;
|
|
433
432
|
#connectEvent = 'peer:connected';
|
|
434
433
|
#retryOptions = { retries: 5, factor: 2, minTimeout: 1000, maxTimeout: 30000 };
|
|
@@ -451,15 +450,6 @@ class Client {
|
|
|
451
450
|
getPeer(peerId) {
|
|
452
451
|
return this.#connections[peerId];
|
|
453
452
|
}
|
|
454
|
-
/**
|
|
455
|
-
*
|
|
456
|
-
* @param options {object}
|
|
457
|
-
* @param options.peerId {string}
|
|
458
|
-
* @param options.networkVersion {string}
|
|
459
|
-
* @param options.version {string}
|
|
460
|
-
* @param options.stars {string[]}
|
|
461
|
-
* @param options.connectEvent {string} defaults to peer:connected, can be renamed to handle different protocols, like peer:discovered (setup peer props before fireing the connect event)
|
|
462
|
-
*/
|
|
463
453
|
constructor(options) {
|
|
464
454
|
const { peerId, networkVersion, version, connectEvent, stars } = {
|
|
465
455
|
...defaultOptions,
|
|
@@ -486,7 +476,6 @@ class Client {
|
|
|
486
476
|
debug('reinit: start');
|
|
487
477
|
try {
|
|
488
478
|
await this.close();
|
|
489
|
-
// clear internal maps so setupStar starts fresh
|
|
490
479
|
this.#stars = {};
|
|
491
480
|
this.#connections = {};
|
|
492
481
|
for (const star of this.starsConfig) {
|
|
@@ -495,8 +484,7 @@ class Client {
|
|
|
495
484
|
}
|
|
496
485
|
catch (e) {
|
|
497
486
|
// If last star fails and none connected, surface error
|
|
498
|
-
if (
|
|
499
|
-
Object.keys(this.#stars).length === 0)
|
|
487
|
+
if (Object.keys(this.#stars).length === 0)
|
|
500
488
|
throw new Error(`No star available to connect`);
|
|
501
489
|
}
|
|
502
490
|
}
|
|
@@ -538,7 +526,6 @@ class Client {
|
|
|
538
526
|
throw lastErr;
|
|
539
527
|
}
|
|
540
528
|
async _init() {
|
|
541
|
-
// reconnectJob()
|
|
542
529
|
if (!globalThis.RTCPeerConnection)
|
|
543
530
|
globalThis.wrtc = (await import('./browser-Cjcx-T47-D0KbGYCz.js').then(function (n) { return n.b; })).default;
|
|
544
531
|
for (const star of this.starsConfig) {
|
|
@@ -561,8 +548,6 @@ class Client {
|
|
|
561
548
|
else {
|
|
562
549
|
globalThis.addEventListener('beforeunload', this.close.bind(this));
|
|
563
550
|
}
|
|
564
|
-
// Setup resume/sleep detection so we can reinit connections after wake
|
|
565
|
-
this._setupResumeHandler();
|
|
566
551
|
}
|
|
567
552
|
setupStarListeners(starConnection, starId) {
|
|
568
553
|
// create stable references to handlers so we can unsubscribe later
|
|
@@ -584,46 +569,6 @@ class Client {
|
|
|
584
569
|
{ topic: 'signal', handler: onSignal }
|
|
585
570
|
];
|
|
586
571
|
}
|
|
587
|
-
_setupResumeHandler() {
|
|
588
|
-
if (this.#handlersSetup)
|
|
589
|
-
return;
|
|
590
|
-
this.#handlersSetup = true;
|
|
591
|
-
const THRESHOLD = 10 * 1000; // 10s gap indicates sleep/wake
|
|
592
|
-
let last = Date.now();
|
|
593
|
-
const check = () => {
|
|
594
|
-
const now = Date.now();
|
|
595
|
-
const delta = now - last;
|
|
596
|
-
last = now;
|
|
597
|
-
if (delta > THRESHOLD) {
|
|
598
|
-
debug(`resume detected (gap ${delta}ms)`);
|
|
599
|
-
this.reinit().catch((e) => debug('reinit error', e));
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
// Start interval checker
|
|
603
|
-
const iv = setInterval(check, 2000);
|
|
604
|
-
// Browser specific events
|
|
605
|
-
if (typeof document !== 'undefined' && document.addEventListener) {
|
|
606
|
-
document.addEventListener('visibilitychange', () => {
|
|
607
|
-
if (document.visibilityState === 'visible') {
|
|
608
|
-
// small delay to let timers update
|
|
609
|
-
setTimeout(() => check(), 50);
|
|
610
|
-
}
|
|
611
|
-
});
|
|
612
|
-
window.addEventListener('online', () => setTimeout(() => check(), 50));
|
|
613
|
-
}
|
|
614
|
-
// Node: listen for SIGCONT (process continued) as well
|
|
615
|
-
if (globalThis.process?.on) {
|
|
616
|
-
try {
|
|
617
|
-
process.on('SIGCONT', () => setTimeout(() => check(), 50));
|
|
618
|
-
}
|
|
619
|
-
catch (e) {
|
|
620
|
-
// ignore
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
// keep reference so it can be cleared on close
|
|
624
|
-
// @ts-ignore
|
|
625
|
-
this._resumeInterval = iv;
|
|
626
|
-
}
|
|
627
572
|
#starJoined = (id) => {
|
|
628
573
|
if (this.#stars[id]) {
|
|
629
574
|
this.#stars[id].close(0);
|
|
@@ -719,6 +664,7 @@ class Client {
|
|
|
719
664
|
debug(`peer ${from} already connected`);
|
|
720
665
|
return;
|
|
721
666
|
}
|
|
667
|
+
// peer.channels[channelName]
|
|
722
668
|
if (String(peer.channelName) !== String(channelName)) {
|
|
723
669
|
console.warn(`channelNames don't match: got ${peer.channelName}, expected: ${channelName}.`);
|
|
724
670
|
// Destroy the existing peer connection
|
|
@@ -742,7 +688,8 @@ class Client {
|
|
|
742
688
|
to: peer.peerId,
|
|
743
689
|
channelName: peer.channelName,
|
|
744
690
|
version,
|
|
745
|
-
signal
|
|
691
|
+
signal,
|
|
692
|
+
initiator: peer.initiator
|
|
746
693
|
}
|
|
747
694
|
});
|
|
748
695
|
};
|
|
@@ -799,35 +746,30 @@ class Client {
|
|
|
799
746
|
peer.destroy();
|
|
800
747
|
};
|
|
801
748
|
async close() {
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
this._resumeInterval = null;
|
|
749
|
+
for (const peerId in this.#connections) {
|
|
750
|
+
const peer = this.#connections[peerId];
|
|
751
|
+
if (peer) {
|
|
752
|
+
peer.destroy();
|
|
753
|
+
delete this.#connections[peerId];
|
|
754
|
+
}
|
|
809
755
|
}
|
|
810
756
|
for (const star in this.#stars) {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
const listeners
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
catch (e) {
|
|
821
|
-
// ignore
|
|
822
|
-
}
|
|
757
|
+
// unsubscribe handlers we registered earlier
|
|
758
|
+
const listeners = this.#starListeners[star];
|
|
759
|
+
if (listeners && listeners.length) {
|
|
760
|
+
for (const { topic, handler } of listeners) {
|
|
761
|
+
try {
|
|
762
|
+
this.#stars[star].pubsub.unsubscribe(topic, handler);
|
|
763
|
+
}
|
|
764
|
+
catch (e) {
|
|
765
|
+
// ignore
|
|
823
766
|
}
|
|
824
767
|
}
|
|
825
768
|
}
|
|
769
|
+
if (this.#stars[star].connectionState() === 'open') {
|
|
770
|
+
await this.#stars[star].send({ url: 'leave', params: this.peerId });
|
|
771
|
+
}
|
|
826
772
|
}
|
|
827
|
-
// Ensure we wait for all peer and star close/destroy operations.
|
|
828
|
-
// Previous code passed an array of arrays to Promise.allSettled which
|
|
829
|
-
// resolves immediately; flatten into a single array of promises (or
|
|
830
|
-
// values) so we actually wait for async close operations.
|
|
831
773
|
const peerClosers = Object.values(this.#connections).map((connection) => {
|
|
832
774
|
try {
|
|
833
775
|
// destroy() may be sync or return a promise
|
|
@@ -8490,7 +8490,7 @@ class Peernet {
|
|
|
8490
8490
|
this.root = options.root;
|
|
8491
8491
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
8492
8492
|
// FolderMessageResponse
|
|
8493
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
8493
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-C3VxYRj3-pcgSwlQ_.js');
|
|
8494
8494
|
/**
|
|
8495
8495
|
* proto Object containing protos
|
|
8496
8496
|
* @type {Object}
|
|
@@ -8584,7 +8584,7 @@ class Peernet {
|
|
|
8584
8584
|
if (this.#starting || this.#started)
|
|
8585
8585
|
return;
|
|
8586
8586
|
this.#starting = true;
|
|
8587
|
-
const importee = await import('./client-
|
|
8587
|
+
const importee = await import('./client-bgSiSUVr-WviWWZtO.js');
|
|
8588
8588
|
/**
|
|
8589
8589
|
* @access public
|
|
8590
8590
|
* @type {PeernetClient}
|
|
@@ -1,33 +1,23 @@
|
|
|
1
1
|
import { E as EasyWorker, B as BlockMessage } from './worker-CPvGlmOu-CPvGlmOu.js';
|
|
2
2
|
|
|
3
3
|
const worker = new EasyWorker();
|
|
4
|
-
|
|
5
4
|
globalThis.BigNumber = BigNumber;
|
|
6
5
|
globalThis.contracts = {};
|
|
7
|
-
|
|
8
6
|
const run = async (blocks) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const index = block.decoded.index;
|
|
21
|
-
resolve({ ...block.decoded, hash, blockInfo: { hash, size, index } });
|
|
22
|
-
})
|
|
23
|
-
)
|
|
24
|
-
);
|
|
25
|
-
return blocks
|
|
7
|
+
blocks = await Promise.all(blocks.map((block) => new BlockMessage(block)));
|
|
8
|
+
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp);
|
|
9
|
+
blocks = await Promise.all(blocks.map((block) => new Promise(async (resolve, reject) => {
|
|
10
|
+
// todo: tx worker or nah?
|
|
11
|
+
await block.encode();
|
|
12
|
+
const size = block.encoded.length || block.encoded.byteLength;
|
|
13
|
+
const hash = await block.hash();
|
|
14
|
+
const index = block.decoded.index;
|
|
15
|
+
resolve({ ...block.decoded, hash, blockInfo: { hash, size, index } });
|
|
16
|
+
})));
|
|
17
|
+
return blocks;
|
|
26
18
|
};
|
|
27
|
-
|
|
28
19
|
const tasks = async (blocks) => {
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
blocks = await run(blocks);
|
|
21
|
+
worker.postMessage(blocks);
|
|
31
22
|
};
|
|
32
|
-
|
|
33
23
|
worker.onmessage((data) => tasks(data));
|
|
@@ -1,33 +1,23 @@
|
|
|
1
1
|
import { E as EasyWorker, B as BlockMessage } from './worker-CPvGlmOu-CPvGlmOu.js';
|
|
2
2
|
|
|
3
3
|
const worker = new EasyWorker();
|
|
4
|
-
|
|
5
4
|
globalThis.BigNumber = BigNumber;
|
|
6
5
|
globalThis.contracts = {};
|
|
7
|
-
|
|
8
6
|
const run = async (blocks) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const index = block.decoded.index;
|
|
21
|
-
resolve({ ...block.decoded, hash, blockInfo: { hash, size, index } });
|
|
22
|
-
})
|
|
23
|
-
)
|
|
24
|
-
);
|
|
25
|
-
return blocks
|
|
7
|
+
blocks = await Promise.all(blocks.map((block) => new BlockMessage(block)));
|
|
8
|
+
blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp);
|
|
9
|
+
blocks = await Promise.all(blocks.map((block) => new Promise(async (resolve, reject) => {
|
|
10
|
+
// todo: tx worker or nah?
|
|
11
|
+
await block.encode();
|
|
12
|
+
const size = block.encoded.length || block.encoded.byteLength;
|
|
13
|
+
const hash = await block.hash();
|
|
14
|
+
const index = block.decoded.index;
|
|
15
|
+
resolve({ ...block.decoded, hash, blockInfo: { hash, size, index } });
|
|
16
|
+
})));
|
|
17
|
+
return blocks;
|
|
26
18
|
};
|
|
27
|
-
|
|
28
19
|
const tasks = async (blocks) => {
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
blocks = await run(blocks);
|
|
21
|
+
worker.postMessage(blocks);
|
|
31
22
|
};
|
|
32
|
-
|
|
33
23
|
worker.onmessage((data) => tasks(data));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/chain",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.113",
|
|
4
4
|
"description": "Official javascript implementation",
|
|
5
5
|
"private": false,
|
|
6
6
|
"exports": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"author": "",
|
|
50
50
|
"license": "MIT",
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@rollup/plugin-commonjs": "^
|
|
52
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
53
53
|
"@rollup/plugin-json": "^6.1.0",
|
|
54
54
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
55
55
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"@leofcoin/messages": "^1.4.40",
|
|
70
70
|
"@leofcoin/multi-wallet": "^3.1.8",
|
|
71
71
|
"@leofcoin/networks": "^1.1.25",
|
|
72
|
-
"@leofcoin/peernet": "^1.1.
|
|
72
|
+
"@leofcoin/peernet": "^1.1.102",
|
|
73
73
|
"@leofcoin/storage": "^3.5.38",
|
|
74
74
|
"@leofcoin/utils": "^1.1.40",
|
|
75
75
|
"@leofcoin/workers": "^1.5.27",
|