@leofcoin/chain 1.7.146 → 1.7.148

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.
@@ -4880,6 +4880,7 @@ class State extends Contract {
4880
4880
  localHash = await globalThis.stateStore.get('lastBlock');
4881
4881
  }
4882
4882
  catch (error) {
4883
+ globalThis.stateStore.put('lastBlock', new TextEncoder().encode('0x0'));
4883
4884
  debug$1('no local state found');
4884
4885
  }
4885
4886
  debug$1(`resolving block: ${hash} @${index !== undefined ? index : 'unknown'}`);
@@ -5903,12 +5904,13 @@ class Chain extends VersionControl {
5903
5904
  if (lastBlock.hash === '0x0')
5904
5905
  return;
5905
5906
  const higherThenCurrentLocal = !localBlock?.index ? true : lastBlock.index > localBlock.index;
5906
- if (Object.keys(lastBlock).length > 0) {
5907
+ if (lastBlock) {
5907
5908
  if (!this.lastBlock || higherThenCurrentLocal) {
5908
5909
  this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
5909
- await this.#makeRequest(peer, 'stateInfo');
5910
- await this.syncChain(lastBlock);
5911
- // this.machine.states.info = stateInfo
5910
+ console.log({ knownBlocks: this.knownBlocks });
5911
+ for (const hash of this.knownBlocks) {
5912
+ this.wantList.push(hash);
5913
+ }
5912
5914
  }
5913
5915
  }
5914
5916
  if (this.wantList.length > 0) {
@@ -5927,6 +5929,9 @@ class Chain extends VersionControl {
5927
5929
  if (this.#participating && peerTransactionPool.length > 0)
5928
5930
  return this.#runEpoch();
5929
5931
  }, 3000);
5932
+ const stateInfo = await this.#makeRequest(peer, 'stateInfo');
5933
+ await this.syncChain(lastBlock);
5934
+ this.machine.states.info = stateInfo;
5930
5935
  }
5931
5936
  #epochTimeout;
5932
5937
  async #transactionPoolHandler() {
package/exports/chain.js CHANGED
@@ -1020,6 +1020,7 @@ class State extends Contract {
1020
1020
  localHash = await globalThis.stateStore.get('lastBlock');
1021
1021
  }
1022
1022
  catch (error) {
1023
+ globalThis.stateStore.put('lastBlock', new TextEncoder().encode('0x0'));
1023
1024
  debug$1('no local state found');
1024
1025
  }
1025
1026
  debug$1(`resolving block: ${hash} @${index !== undefined ? index : 'unknown'}`);
@@ -2043,12 +2044,13 @@ class Chain extends VersionControl {
2043
2044
  if (lastBlock.hash === '0x0')
2044
2045
  return;
2045
2046
  const higherThenCurrentLocal = !localBlock?.index ? true : lastBlock.index > localBlock.index;
2046
- if (Object.keys(lastBlock).length > 0) {
2047
+ if (lastBlock) {
2047
2048
  if (!this.lastBlock || higherThenCurrentLocal) {
2048
2049
  this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
2049
- await this.#makeRequest(peer, 'stateInfo');
2050
- await this.syncChain(lastBlock);
2051
- // this.machine.states.info = stateInfo
2050
+ console.log({ knownBlocks: this.knownBlocks });
2051
+ for (const hash of this.knownBlocks) {
2052
+ this.wantList.push(hash);
2053
+ }
2052
2054
  }
2053
2055
  }
2054
2056
  if (this.wantList.length > 0) {
@@ -2067,6 +2069,9 @@ class Chain extends VersionControl {
2067
2069
  if (this.#participating && peerTransactionPool.length > 0)
2068
2070
  return this.#runEpoch();
2069
2071
  }, 3000);
2072
+ const stateInfo = await this.#makeRequest(peer, 'stateInfo');
2073
+ await this.syncChain(lastBlock);
2074
+ this.machine.states.info = stateInfo;
2070
2075
  }
2071
2076
  #epochTimeout;
2072
2077
  async #transactionPoolHandler() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.7.146",
3
+ "version": "1.7.148",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {