@leofcoin/chain 1.4.32 → 1.4.34

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.
Files changed (2) hide show
  1. package/exports/chain.js +5 -3
  2. package/package.json +1 -1
package/exports/chain.js CHANGED
@@ -610,7 +610,7 @@ class Chain extends Contract {
610
610
  let promises = [];
611
611
  let data = await new peernet.protos['peernet-request']({ request: 'lastBlock' });
612
612
  let node = await peernet.prepareMessage(data);
613
- for (const peer of peernet.connections) {
613
+ for (const peer of peernet?.connections) {
614
614
  if (peer.connected && peer.readyState === 'open' && peer.peerId !== this.id) {
615
615
  promises.push(async () => {
616
616
  try {
@@ -682,8 +682,10 @@ class Chain extends Contract {
682
682
  this.#lastBlock = { ...localBlock.decoded, hash: await localBlock.hash() };
683
683
  }
684
684
  else {
685
- const latestBlock = await this.#getLatestBlock();
686
- await this.#syncChain(latestBlock);
685
+ if (globalThis.peernet?.connections.length > 0) {
686
+ const latestBlock = await this.#getLatestBlock();
687
+ await this.#syncChain(latestBlock);
688
+ }
687
689
  }
688
690
  }
689
691
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.4.32",
3
+ "version": "1.4.34",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": "./exports/node.js",