@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.
@@ -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 && peer.readyState === 'open' && peer.peerId !== this.id) {
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 || peer.readyState !== 'open') ;
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-c95add6b.js';
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
- let chunks = 0;
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
  })
@@ -1,4 +1,4 @@
1
- import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-c95add6b.js';
1
+ import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-bd6a5de3.js';
2
2
  import './contract-32687834.js';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { F as FormatInterface } from './node-browser-c95add6b.js';
1
+ import { F as FormatInterface } from './node-browser-bd6a5de3.js';
2
2
  import './contract-32687834.js';
3
3
 
4
4
  var proto$b = {