@leofcoin/chain 1.4.59 → 1.4.60

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.
@@ -8188,20 +8188,26 @@ class Chain extends Contract {
8188
8188
  if (!lastBlock)
8189
8189
  lastBlock = await this.#getLatestBlock();
8190
8190
  if (this.#chainSyncing) {
8191
+ console.log('already syncing');
8191
8192
  if (!this.#lastBlockInQue || lastBlock.index > this.#lastBlockInQue.index)
8192
8193
  this.#lastBlockInQue = lastBlock;
8193
8194
  return 'syncing';
8194
8195
  }
8196
+ console.log('starting sync');
8195
8197
  this.#chainSyncing = true;
8196
8198
  const syncPromise = (lastBlock) => new Promise(async (resolve, reject) => {
8197
- setTimeout(() => {
8199
+ const timeout = setTimeout(() => {
8200
+ this.#chainSyncing = false;
8201
+ this.#syncErrorCount = 0;
8198
8202
  reject('timedOut');
8199
- }, 10000);
8203
+ }, 60000);
8200
8204
  try {
8201
8205
  await this.#syncChain(lastBlock);
8206
+ clearTimeout(timeout);
8202
8207
  resolve(true);
8203
8208
  }
8204
8209
  catch (error) {
8210
+ clearTimeout(timeout);
8205
8211
  reject(error);
8206
8212
  }
8207
8213
  });
@@ -8209,12 +8215,16 @@ class Chain extends Contract {
8209
8215
  return 'connectionless';
8210
8216
  try {
8211
8217
  await syncPromise(lastBlock);
8218
+ if (lastBlock.index === this.#lastBlockInQue?.index || lastBlock.index > this.#lastBlockInQue?.index)
8219
+ this.#lastBlockInQue = undefined;
8212
8220
  }
8213
8221
  catch (error) {
8214
8222
  console.log(error);
8215
8223
  this.#syncErrorCount += 1;
8216
- if (this.#syncErrorCount <= 3)
8217
- return this.syncChain(this.#lastBlockInQue);
8224
+ if (this.#syncErrorCount < 3)
8225
+ await syncPromise(lastBlock);
8226
+ this.#chainSyncing = false;
8227
+ this.#syncErrorCount = 0;
8218
8228
  return 'errored';
8219
8229
  }
8220
8230
  this.#syncErrorCount = 0;
@@ -8224,9 +8234,6 @@ class Chain extends Contract {
8224
8234
  return 'synced';
8225
8235
  }
8226
8236
  async #syncChain(lastBlock) {
8227
- if (this.#chainSyncing || !lastBlock || !lastBlock.hash || !lastBlock.index)
8228
- return;
8229
- this.#chainSyncing = true;
8230
8237
  if (this.#knownBlocks?.length === Number(lastBlock.index) + 1) {
8231
8238
  let promises = [];
8232
8239
  promises = await Promise.allSettled(this.#knownBlocks.map(async (address) => {
@@ -8248,8 +8255,6 @@ class Chain extends Contract {
8248
8255
  await this.#loadBlocks(this.blocks.slice(start));
8249
8256
  await this.#updateState(new BlockMessage(this.#blocks[this.#blocks.length - 1]));
8250
8257
  }
8251
- clearTimeout(current);
8252
- this.#chainSyncing = false;
8253
8258
  }
8254
8259
  async #prepareRequest(request) {
8255
8260
  let node = await new globalThis.peernet.protos['peernet-request']({ request });
@@ -1,4 +1,4 @@
1
- import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './node-browser-79442920.js';
1
+ import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './node-browser-39985c71.js';
2
2
  import './index-640d9f36.js';
3
3
 
4
4
  function commonjsRequire(path) {
@@ -1,4 +1,4 @@
1
- import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-79442920.js';
1
+ import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-39985c71.js';
2
2
  import './index-640d9f36.js';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { F as FormatInterface } from './node-browser-79442920.js';
1
+ import { F as FormatInterface } from './node-browser-39985c71.js';
2
2
  import './index-640d9f36.js';
3
3
 
4
4
  var proto$b = {
@@ -20266,7 +20266,7 @@ class Identity {
20266
20266
  globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
20267
20267
  }
20268
20268
  else {
20269
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-4464b87e-d39e42fc.js');
20269
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-cf8b44ca-a27c61c1.js');
20270
20270
  const { identity, accounts } = await importee.default(password, this.network);
20271
20271
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
20272
20272
  await globalThis.walletStore.put('version', String(1));
@@ -20307,7 +20307,7 @@ class Identity {
20307
20307
  globalThis.LeofcoinStorage = LeofcoinStorage;
20308
20308
  globalThis.leofcoin = globalThis.leofcoin || {};
20309
20309
  globalThis.pubsub = globalThis.pubsub || new LittlePubSub();
20310
- globalThis.globalSub = globalThis.globalSub || new LittlePubSub(true);
20310
+ globalThis.globalSub = globalThis.globalSub || new LittlePubSub();
20311
20311
  /**
20312
20312
  * @access public
20313
20313
  * @example
@@ -20437,7 +20437,7 @@ class Peernet {
20437
20437
  this.root = options.root;
20438
20438
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
20439
20439
  // FolderMessageResponse
20440
- } = await import(/* webpackChunkName: "messages" */ './messages-27279443-8ccccaf2.js');
20440
+ } = await import(/* webpackChunkName: "messages" */ './messages-d292642b-e5aa934c.js');
20441
20441
  /**
20442
20442
  * proto Object containing protos
20443
20443
  * @type {Object}
@@ -20516,7 +20516,7 @@ class Peernet {
20516
20516
  if (this.#starting || this.#started)
20517
20517
  return;
20518
20518
  this.#starting = true;
20519
- const importee = await import('./client-4d80940e-a63ca03c.js');
20519
+ const importee = await import('./client-10cfc17d-c47b062b.js');
20520
20520
  /**
20521
20521
  * @access public
20522
20522
  * @type {PeernetClient}
@@ -1,2 +1,2 @@
1
- export { N as default } from './node-browser-79442920.js';
1
+ export { N as default } from './node-browser-39985c71.js';
2
2
  import './index-640d9f36.js';
package/exports/chain.js CHANGED
@@ -774,20 +774,26 @@ class Chain extends Contract {
774
774
  if (!lastBlock)
775
775
  lastBlock = await this.#getLatestBlock();
776
776
  if (this.#chainSyncing) {
777
+ console.log('already syncing');
777
778
  if (!this.#lastBlockInQue || lastBlock.index > this.#lastBlockInQue.index)
778
779
  this.#lastBlockInQue = lastBlock;
779
780
  return 'syncing';
780
781
  }
782
+ console.log('starting sync');
781
783
  this.#chainSyncing = true;
782
784
  const syncPromise = (lastBlock) => new Promise(async (resolve, reject) => {
783
- setTimeout(() => {
785
+ const timeout = setTimeout(() => {
786
+ this.#chainSyncing = false;
787
+ this.#syncErrorCount = 0;
784
788
  reject('timedOut');
785
- }, 10000);
789
+ }, 60000);
786
790
  try {
787
791
  await this.#syncChain(lastBlock);
792
+ clearTimeout(timeout);
788
793
  resolve(true);
789
794
  }
790
795
  catch (error) {
796
+ clearTimeout(timeout);
791
797
  reject(error);
792
798
  }
793
799
  });
@@ -795,12 +801,16 @@ class Chain extends Contract {
795
801
  return 'connectionless';
796
802
  try {
797
803
  await syncPromise(lastBlock);
804
+ if (lastBlock.index === this.#lastBlockInQue?.index || lastBlock.index > this.#lastBlockInQue?.index)
805
+ this.#lastBlockInQue = undefined;
798
806
  }
799
807
  catch (error) {
800
808
  console.log(error);
801
809
  this.#syncErrorCount += 1;
802
- if (this.#syncErrorCount <= 3)
803
- return this.syncChain(this.#lastBlockInQue);
810
+ if (this.#syncErrorCount < 3)
811
+ await syncPromise(lastBlock);
812
+ this.#chainSyncing = false;
813
+ this.#syncErrorCount = 0;
804
814
  return 'errored';
805
815
  }
806
816
  this.#syncErrorCount = 0;
@@ -810,9 +820,6 @@ class Chain extends Contract {
810
820
  return 'synced';
811
821
  }
812
822
  async #syncChain(lastBlock) {
813
- if (this.#chainSyncing || !lastBlock || !lastBlock.hash || !lastBlock.index)
814
- return;
815
- this.#chainSyncing = true;
816
823
  if (this.#knownBlocks?.length === Number(lastBlock.index) + 1) {
817
824
  let promises = [];
818
825
  promises = await Promise.allSettled(this.#knownBlocks.map(async (address) => {
@@ -834,8 +841,6 @@ class Chain extends Contract {
834
841
  await this.#loadBlocks(this.blocks.slice(start));
835
842
  await this.#updateState(new BlockMessage(this.#blocks[this.#blocks.length - 1]));
836
843
  }
837
- clearTimeout(current);
838
- this.#chainSyncing = false;
839
844
  }
840
845
  async #prepareRequest(request) {
841
846
  let node = await new globalThis.peernet.protos['peernet-request']({ request });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.4.59",
3
+ "version": "1.4.60",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": "./exports/node.js",