@leofcoin/chain 1.7.89 → 1.7.91

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.
@@ -4232,13 +4232,17 @@ class Machine {
4232
4232
  }
4233
4233
  async updateState() {
4234
4234
  try {
4235
- if ((await this.lastBlock).index > this.states.lastBlock.index ||
4236
- ((await this.lastBlock).hash !== this.states.lastBlock.hash && (await this.lastBlock).index === 0)) {
4235
+ const lastBlock = await this.lastBlock;
4236
+ const lastBlockIndex = Number(lastBlock.index);
4237
+ const statesLastBlockIndex = Number(this.states.lastBlock.index);
4238
+ if (lastBlockIndex > statesLastBlockIndex ||
4239
+ (lastBlock.hash !== this.states.lastBlock.hash && Number(lastBlockIndex) === 0)) {
4237
4240
  // todo only get state for changed contracts
4238
- const blocks = (await this.blocks).slice(this.states.lastBlock.index);
4241
+ const blocks = (await this.blocks).slice(statesLastBlockIndex);
4239
4242
  let transactions = [];
4240
4243
  for (const block of blocks) {
4241
- transactions = [...transactions, ...block.transactions];
4244
+ if (block?.transactions)
4245
+ transactions = [...transactions, ...block.transactions];
4242
4246
  }
4243
4247
  transactions = await Promise.all(transactions.map(async (transaction) => new TransactionMessage(await transactionStore.get(transaction))));
4244
4248
  const contractsToGet = transactions.reduce((set, current) => {
@@ -5022,7 +5026,7 @@ class State extends Contract {
5022
5026
  if (!localBlock || Number(localBlock.index) < Number(lastBlock.index)) {
5023
5027
  // TODO: check if valid
5024
5028
  const localIndex = localBlock ? Number(localBlock.index) : 0;
5025
- const index = lastBlock.index;
5029
+ const index = Number(lastBlock.index);
5026
5030
  await this.resolveBlock(lastBlock.hash);
5027
5031
  console.log('ok');
5028
5032
  let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index + 1 : index + -localIndex + 1) : index + 1;
package/exports/chain.js CHANGED
@@ -378,13 +378,17 @@ class Machine {
378
378
  }
379
379
  async updateState() {
380
380
  try {
381
- if ((await this.lastBlock).index > this.states.lastBlock.index ||
382
- ((await this.lastBlock).hash !== this.states.lastBlock.hash && (await this.lastBlock).index === 0)) {
381
+ const lastBlock = await this.lastBlock;
382
+ const lastBlockIndex = Number(lastBlock.index);
383
+ const statesLastBlockIndex = Number(this.states.lastBlock.index);
384
+ if (lastBlockIndex > statesLastBlockIndex ||
385
+ (lastBlock.hash !== this.states.lastBlock.hash && Number(lastBlockIndex) === 0)) {
383
386
  // todo only get state for changed contracts
384
- const blocks = (await this.blocks).slice(this.states.lastBlock.index);
387
+ const blocks = (await this.blocks).slice(statesLastBlockIndex);
385
388
  let transactions = [];
386
389
  for (const block of blocks) {
387
- transactions = [...transactions, ...block.transactions];
390
+ if (block?.transactions)
391
+ transactions = [...transactions, ...block.transactions];
388
392
  }
389
393
  transactions = await Promise.all(transactions.map(async (transaction) => new TransactionMessage(await transactionStore.get(transaction))));
390
394
  const contractsToGet = transactions.reduce((set, current) => {
@@ -1168,7 +1172,7 @@ class State extends Contract {
1168
1172
  if (!localBlock || Number(localBlock.index) < Number(lastBlock.index)) {
1169
1173
  // TODO: check if valid
1170
1174
  const localIndex = localBlock ? Number(localBlock.index) : 0;
1171
- const index = lastBlock.index;
1175
+ const index = Number(lastBlock.index);
1172
1176
  await this.resolveBlock(lastBlock.hash);
1173
1177
  console.log('ok');
1174
1178
  let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index + 1 : index + -localIndex + 1) : index + 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.7.89",
3
+ "version": "1.7.91",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {