@leofcoin/chain 1.7.89 → 1.7.90

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) => {
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) => {
@@ -38,7 +38,7 @@ export default class State extends Contract {
38
38
  hash: string;
39
39
  previousHash: string;
40
40
  };
41
- get lastBlockHeight(): Promise<any> | 0;
41
+ get lastBlockHeight(): 0 | Promise<any>;
42
42
  getBlock(index: any): Promise<any>;
43
43
  getBlocks(from?: any, to?: any): Promise<[]>;
44
44
  get totalSize(): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.7.89",
3
+ "version": "1.7.90",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {