@leofcoin/chain 1.4.89 → 1.4.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.
@@ -2216,6 +2216,13 @@ class State extends Contract {
2216
2216
  }
2217
2217
  return latest;
2218
2218
  }
2219
+ #loadBlockTransactions = (transactions) => Promise.all(transactions.map((transaction) => new TransactionMessage(transaction)));
2220
+ #getLastTransactions = async () => {
2221
+ let lastTransactions = (await Promise.all(this.#blocks.filter(block => block.loaded).slice(-128)
2222
+ .map(block => this.#loadBlockTransactions(block))))
2223
+ .reduce((all, transactions) => [...all, ...transactions], []);
2224
+ return Promise.all(lastTransactions.map(transaction => transaction.hash()));
2225
+ };
2219
2226
  /**
2220
2227
  *
2221
2228
  * @param {Block[]} blocks
@@ -2226,9 +2233,17 @@ class State extends Contract {
2226
2233
  if (block && !block.loaded) {
2227
2234
  if (block.index === 0)
2228
2235
  this.#loaded = true;
2236
+ block.transactions = await this.#loadBlockTransactions(block.transactions);
2229
2237
  for (const transaction of block.transactions) {
2230
- if (poolTransactionKeys.includes(transaction.hash))
2231
- await globalThis.transactionPoolStore.delete(transaction.hash);
2238
+ const lastTransactions = await this.#getLastTransactions();
2239
+ const hash = await transaction.hash();
2240
+ if (poolTransactionKeys.includes(hash))
2241
+ await globalThis.transactionPoolStore.delete(hash);
2242
+ if (lastTransactions.includes(hash)) {
2243
+ console.log('removing invalid block');
2244
+ await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
2245
+ return this.#loadBlocks(blocks);
2246
+ }
2232
2247
  try {
2233
2248
  await this.#machine.execute(transaction.to, transaction.method, transaction.params);
2234
2249
  if (transaction.to === nativeToken$2) {
package/exports/chain.js CHANGED
@@ -836,6 +836,13 @@ class State extends Contract {
836
836
  }
837
837
  return latest;
838
838
  }
839
+ #loadBlockTransactions = (transactions) => Promise.all(transactions.map((transaction) => new TransactionMessage(transaction)));
840
+ #getLastTransactions = async () => {
841
+ let lastTransactions = (await Promise.all(this.#blocks.filter(block => block.loaded).slice(-128)
842
+ .map(block => this.#loadBlockTransactions(block))))
843
+ .reduce((all, transactions) => [...all, ...transactions], []);
844
+ return Promise.all(lastTransactions.map(transaction => transaction.hash()));
845
+ };
839
846
  /**
840
847
  *
841
848
  * @param {Block[]} blocks
@@ -846,9 +853,17 @@ class State extends Contract {
846
853
  if (block && !block.loaded) {
847
854
  if (block.index === 0)
848
855
  this.#loaded = true;
856
+ block.transactions = await this.#loadBlockTransactions(block.transactions);
849
857
  for (const transaction of block.transactions) {
850
- if (poolTransactionKeys.includes(transaction.hash))
851
- await globalThis.transactionPoolStore.delete(transaction.hash);
858
+ const lastTransactions = await this.#getLastTransactions();
859
+ const hash = await transaction.hash();
860
+ if (poolTransactionKeys.includes(hash))
861
+ await globalThis.transactionPoolStore.delete(hash);
862
+ if (lastTransactions.includes(hash)) {
863
+ console.log('removing invalid block');
864
+ await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
865
+ return this.#loadBlocks(blocks);
866
+ }
852
867
  try {
853
868
  await this.#machine.execute(transaction.to, transaction.method, transaction.params);
854
869
  if (transaction.to === nativeToken) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.4.89",
3
+ "version": "1.4.90",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": "./exports/node.js",