@leofcoin/chain 1.6.6 → 1.6.7

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.
@@ -3939,7 +3939,7 @@ class Machine {
3939
3939
  console.error(`init error: ${data.message}`);
3940
3940
  break;
3941
3941
  }
3942
- case 'executionError': {
3942
+ case 'executeError': {
3943
3943
  // console.warn(`error executing transaction ${data.message}`);
3944
3944
  pubsub.publish(data.id, { error: data.message });
3945
3945
  break;
@@ -4979,6 +4979,7 @@ class Chain extends VersionControl {
4979
4979
  return this;
4980
4980
  }
4981
4981
  async #invalidTransaction(hash) {
4982
+ hash = new TextDecoder().decode(hash);
4982
4983
  await globalThis.transactionPoolStore.delete(hash);
4983
4984
  console.log(`removed invalid transaction: ${hash}`);
4984
4985
  }
@@ -5090,12 +5091,16 @@ class Chain extends VersionControl {
5090
5091
  }
5091
5092
  try {
5092
5093
  promises = await Promise.allSettled(promises);
5094
+ const noncesByAddress = {};
5093
5095
  for (let transaction of blockMessage.decoded.transactions) {
5094
5096
  globalThis.pubsub.publish('transaction-processed', transaction);
5095
5097
  if (transaction.to === globalThis.peernet.selectedAccount)
5096
5098
  globalThis.pubsub.publish('account-transaction-processed', transaction);
5097
- await globalThis.accountsStore.put(transaction.from, String(transaction.nonce));
5099
+ if (!noncesByAddress[transaction.from] || noncesByAddress?.[transaction.from] < transaction.nonce) {
5100
+ noncesByAddress[transaction.from] = transaction.nonce;
5101
+ }
5098
5102
  }
5103
+ await Promise.all(Object.entries(noncesByAddress).map(([from, nonce]) => globalThis.accountsStore.put(from, String(nonce))));
5099
5104
  if ((await this.lastBlock).index < Number(blockMessage.decoded.index)) {
5100
5105
  await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() });
5101
5106
  await this.updateState(blockMessage);
@@ -5183,15 +5188,18 @@ class Chain extends VersionControl {
5183
5188
  console.log({ latestTransactions });
5184
5189
  // exclude failing tx
5185
5190
  transactions = await this.promiseTransactions(transactions);
5186
- const priority = transactions
5187
- .filter((transaction) => transaction.decoded.priority)
5188
- .sort((a, b) => a.decoded.nonce - b.decoded.nonce);
5189
- for (const transaction of priority) {
5191
+ const normalTransactions = [];
5192
+ const priorityransactions = [];
5193
+ for (const transaction of transactions) {
5194
+ if (transaction.decoded.priority)
5195
+ priorityransactions.push(transaction);
5196
+ else
5197
+ normalTransactions.push(transaction);
5198
+ }
5199
+ for (const transaction of priorityransactions.sort((a, b) => a.decoded.nonce - b.decoded.nonce)) {
5190
5200
  await this.#handleTransaction(transaction, latestTransactions, block);
5191
5201
  }
5192
- await Promise.all(transactions
5193
- .filter((transaction) => !transaction.decoded.priority)
5194
- .map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
5202
+ await Promise.all(normalTransactions.map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
5195
5203
  // don't add empty block
5196
5204
  if (block.transactions.length === 0)
5197
5205
  return;
package/exports/chain.js CHANGED
@@ -307,7 +307,7 @@ class Machine {
307
307
  console.error(`init error: ${data.message}`);
308
308
  break;
309
309
  }
310
- case 'executionError': {
310
+ case 'executeError': {
311
311
  // console.warn(`error executing transaction ${data.message}`);
312
312
  pubsub.publish(data.id, { error: data.message });
313
313
  break;
@@ -1347,6 +1347,7 @@ class Chain extends VersionControl {
1347
1347
  return this;
1348
1348
  }
1349
1349
  async #invalidTransaction(hash) {
1350
+ hash = new TextDecoder().decode(hash);
1350
1351
  await globalThis.transactionPoolStore.delete(hash);
1351
1352
  console.log(`removed invalid transaction: ${hash}`);
1352
1353
  }
@@ -1458,12 +1459,16 @@ class Chain extends VersionControl {
1458
1459
  }
1459
1460
  try {
1460
1461
  promises = await Promise.allSettled(promises);
1462
+ const noncesByAddress = {};
1461
1463
  for (let transaction of blockMessage.decoded.transactions) {
1462
1464
  globalThis.pubsub.publish('transaction-processed', transaction);
1463
1465
  if (transaction.to === globalThis.peernet.selectedAccount)
1464
1466
  globalThis.pubsub.publish('account-transaction-processed', transaction);
1465
- await globalThis.accountsStore.put(transaction.from, String(transaction.nonce));
1467
+ if (!noncesByAddress[transaction.from] || noncesByAddress?.[transaction.from] < transaction.nonce) {
1468
+ noncesByAddress[transaction.from] = transaction.nonce;
1469
+ }
1466
1470
  }
1471
+ await Promise.all(Object.entries(noncesByAddress).map(([from, nonce]) => globalThis.accountsStore.put(from, String(nonce))));
1467
1472
  if ((await this.lastBlock).index < Number(blockMessage.decoded.index)) {
1468
1473
  await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() });
1469
1474
  await this.updateState(blockMessage);
@@ -1551,15 +1556,18 @@ class Chain extends VersionControl {
1551
1556
  console.log({ latestTransactions });
1552
1557
  // exclude failing tx
1553
1558
  transactions = await this.promiseTransactions(transactions);
1554
- const priority = transactions
1555
- .filter((transaction) => transaction.decoded.priority)
1556
- .sort((a, b) => a.decoded.nonce - b.decoded.nonce);
1557
- for (const transaction of priority) {
1559
+ const normalTransactions = [];
1560
+ const priorityransactions = [];
1561
+ for (const transaction of transactions) {
1562
+ if (transaction.decoded.priority)
1563
+ priorityransactions.push(transaction);
1564
+ else
1565
+ normalTransactions.push(transaction);
1566
+ }
1567
+ for (const transaction of priorityransactions.sort((a, b) => a.decoded.nonce - b.decoded.nonce)) {
1558
1568
  await this.#handleTransaction(transaction, latestTransactions, block);
1559
1569
  }
1560
- await Promise.all(transactions
1561
- .filter((transaction) => !transaction.decoded.priority)
1562
- .map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
1570
+ await Promise.all(normalTransactions.map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
1563
1571
  // don't add empty block
1564
1572
  if (block.transactions.length === 0)
1565
1573
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.6.6",
3
+ "version": "1.6.7",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {