@leofcoin/chain 1.4.37 → 1.4.38
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/chain.js +13 -2
- package/exports/browser/{client-033977a1-60f68d3b.js → client-de444350-a666f9b6.js} +25 -16
- package/exports/browser/{index-123daa04-05013cc5.js → index-712688fc-ad40bdec.js} +1 -1
- package/exports/browser/{messages-5ddc1083-1bd0ab64.js → messages-3f370680-fb7e5b5b.js} +1 -1
- package/exports/browser/{node-browser-c95add6b.js → node-browser-bd6a5de3.js} +4248 -145
- package/exports/browser/node-browser.js +1 -1
- package/exports/chain.js +13 -2
- package/exports/typings/chain.d.ts +1 -0
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -8022,7 +8022,7 @@ class Chain extends Contract {
|
|
|
8022
8022
|
let data = await new globalThis.peernet.protos['peernet-request']({ request: 'lastBlock' });
|
|
8023
8023
|
let node = await globalThis.peernet.prepareMessage(data);
|
|
8024
8024
|
for (const peer of globalThis.peernet?.connections) {
|
|
8025
|
-
if (peer.connected
|
|
8025
|
+
if (peer.connected) {
|
|
8026
8026
|
promises.push(async () => {
|
|
8027
8027
|
try {
|
|
8028
8028
|
const result = await peer.request(node.encoded);
|
|
@@ -8033,7 +8033,11 @@ class Chain extends Contract {
|
|
|
8033
8033
|
}
|
|
8034
8034
|
});
|
|
8035
8035
|
}
|
|
8036
|
-
else if (!peer.connected
|
|
8036
|
+
else if (!peer.connected) {
|
|
8037
|
+
globalThis.peernet.removePeer(peer);
|
|
8038
|
+
// todo: remove peer
|
|
8039
|
+
// reinitiate channel?
|
|
8040
|
+
}
|
|
8037
8041
|
}
|
|
8038
8042
|
promises = await this.promiseRequests(promises);
|
|
8039
8043
|
let latest = { index: 0, hash: '0x0', previousHash: '0x0' };
|
|
@@ -8119,6 +8123,13 @@ class Chain extends Contract {
|
|
|
8119
8123
|
}, validatorInfo.timeout);
|
|
8120
8124
|
this.#jail.push(validatorInfo.address);
|
|
8121
8125
|
}
|
|
8126
|
+
async triggerSync() {
|
|
8127
|
+
if (this.#chainSyncing)
|
|
8128
|
+
return 'already syncing';
|
|
8129
|
+
const latest = await this.#getLatestBlock();
|
|
8130
|
+
await this.#syncChain(latest);
|
|
8131
|
+
return 'synced';
|
|
8132
|
+
}
|
|
8122
8133
|
async #syncChain(lastBlock) {
|
|
8123
8134
|
if (this.#chainSyncing || !lastBlock || !lastBlock.hash || !lastBlock.hash)
|
|
8124
8135
|
return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './node-browser-
|
|
1
|
+
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './node-browser-bd6a5de3.js';
|
|
2
2
|
import './contract-32687834.js';
|
|
3
3
|
|
|
4
4
|
function commonjsRequire(path) {
|
|
@@ -10624,6 +10624,29 @@ var p2pt_umd = {
|
|
|
10624
10624
|
}
|
|
10625
10625
|
}
|
|
10626
10626
|
|
|
10627
|
+
_trySend(peer, data) {
|
|
10628
|
+
let shouldTry = data.msg.length > 0;
|
|
10629
|
+
let chunks = 0;
|
|
10630
|
+
let remaining = '';
|
|
10631
|
+
|
|
10632
|
+
while (shouldTry) {
|
|
10633
|
+
data.c = chunks;
|
|
10634
|
+
|
|
10635
|
+
remaining = data.msg.slice(MAX_MESSAGE_LENGTH);
|
|
10636
|
+
data.msg = data.msg.slice(0, MAX_MESSAGE_LENGTH);
|
|
10637
|
+
|
|
10638
|
+
if (!remaining) { data.last = true; }
|
|
10639
|
+
if (peer.connected) {
|
|
10640
|
+
peer.send(JSON_MESSAGE_IDENTIFIER + JSON.stringify(data));
|
|
10641
|
+
data.msg = remaining;
|
|
10642
|
+
chunks++;
|
|
10643
|
+
shouldTry = data.msg.length > 0;
|
|
10644
|
+
} else {
|
|
10645
|
+
shouldTry = false;
|
|
10646
|
+
this._removePeer(peer);
|
|
10647
|
+
}
|
|
10648
|
+
}
|
|
10649
|
+
}
|
|
10627
10650
|
/**
|
|
10628
10651
|
* Send a msg and get response for it
|
|
10629
10652
|
* @param Peer peer simple-peer object to send msg to
|
|
@@ -10664,21 +10687,7 @@ var p2pt_umd = {
|
|
|
10664
10687
|
return reject(Error('Connection to peer closed' + e))
|
|
10665
10688
|
}
|
|
10666
10689
|
|
|
10667
|
-
|
|
10668
|
-
let remaining = '';
|
|
10669
|
-
while (data.msg.length > 0) {
|
|
10670
|
-
data.c = chunks;
|
|
10671
|
-
|
|
10672
|
-
remaining = data.msg.slice(MAX_MESSAGE_LENGTH);
|
|
10673
|
-
data.msg = data.msg.slice(0, MAX_MESSAGE_LENGTH);
|
|
10674
|
-
|
|
10675
|
-
if (!remaining) { data.last = true; }
|
|
10676
|
-
|
|
10677
|
-
peer.send(JSON_MESSAGE_IDENTIFIER + JSON.stringify(data));
|
|
10678
|
-
|
|
10679
|
-
data.msg = remaining;
|
|
10680
|
-
chunks++;
|
|
10681
|
-
}
|
|
10690
|
+
this._trySend(peer, data);
|
|
10682
10691
|
|
|
10683
10692
|
debug$2('sent a message to ' + peer.id);
|
|
10684
10693
|
})
|