@leofcoin/chain 1.4.40 → 1.4.41

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.
@@ -8082,6 +8082,7 @@ class Chain extends Contract {
8082
8082
  await globalThis.peernet.addRequestHandler('lastBlock', this.#lastBlockHandler.bind(this));
8083
8083
  await globalThis.peernet.addRequestHandler('knownBlocks', this.#knownBlocksHandler.bind(this));
8084
8084
  globalThis.peernet.subscribe('add-block', this.#addBlock.bind(this));
8085
+ globalThis.peernet.subscribe('invalid-transaction', this.#invalidTransaction.bind(this));
8085
8086
  globalThis.peernet.subscribe('add-transaction', this.#addTransaction.bind(this));
8086
8087
  globalThis.peernet.subscribe('validator:timeout', this.#validatorTimeout.bind(this));
8087
8088
  globalThis.pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
@@ -8118,6 +8119,10 @@ class Chain extends Contract {
8118
8119
  globalThis.globalThis.pubsub.publish('chain:ready', true);
8119
8120
  return this;
8120
8121
  }
8122
+ async #invalidTransaction(hash) {
8123
+ await transactionPoolStore.delete(hash);
8124
+ console.log(`removed invalid transaction: ${hash}`);
8125
+ }
8121
8126
  async #validatorTimeout(validatorInfo) {
8122
8127
  setTimeout(() => {
8123
8128
  this.#jail.splice(this.#jail.indexOf(validatorInfo.address), 1);
@@ -8180,7 +8185,7 @@ class Chain extends Contract {
8180
8185
  await Promise.all(pool.map(async ({ hash }) => {
8181
8186
  const result = await globalThis.peernet.get(hash);
8182
8187
  const node = await new TransactionMessage(result);
8183
- await globalThis.transactionPoolStore.put(hash, node.encoded);
8188
+ await globalThis.transactionPoolStore.put(await node.hash(), node.encoded);
8184
8189
  }));
8185
8190
  if (pool.length > 0)
8186
8191
  this.#runEpoch();
@@ -8292,6 +8297,7 @@ class Chain extends Contract {
8292
8297
  }
8293
8298
  catch (error) {
8294
8299
  console.log({ error });
8300
+ globalThis.peernet.pubsub.publish('invalid-transaction', hash);
8295
8301
  globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: 'fail', hash, error: error });
8296
8302
  throw { error, hash, from, to, params, nonce };
8297
8303
  }
package/exports/chain.js CHANGED
@@ -677,6 +677,7 @@ class Chain extends Contract {
677
677
  await globalThis.peernet.addRequestHandler('lastBlock', this.#lastBlockHandler.bind(this));
678
678
  await globalThis.peernet.addRequestHandler('knownBlocks', this.#knownBlocksHandler.bind(this));
679
679
  globalThis.peernet.subscribe('add-block', this.#addBlock.bind(this));
680
+ globalThis.peernet.subscribe('invalid-transaction', this.#invalidTransaction.bind(this));
680
681
  globalThis.peernet.subscribe('add-transaction', this.#addTransaction.bind(this));
681
682
  globalThis.peernet.subscribe('validator:timeout', this.#validatorTimeout.bind(this));
682
683
  globalThis.pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
@@ -713,6 +714,10 @@ class Chain extends Contract {
713
714
  globalThis.globalThis.pubsub.publish('chain:ready', true);
714
715
  return this;
715
716
  }
717
+ async #invalidTransaction(hash) {
718
+ await transactionPoolStore.delete(hash);
719
+ console.log(`removed invalid transaction: ${hash}`);
720
+ }
716
721
  async #validatorTimeout(validatorInfo) {
717
722
  setTimeout(() => {
718
723
  this.#jail.splice(this.#jail.indexOf(validatorInfo.address), 1);
@@ -775,7 +780,7 @@ class Chain extends Contract {
775
780
  await Promise.all(pool.map(async ({ hash }) => {
776
781
  const result = await globalThis.peernet.get(hash);
777
782
  const node = await new TransactionMessage(result);
778
- await globalThis.transactionPoolStore.put(hash, node.encoded);
783
+ await globalThis.transactionPoolStore.put(await node.hash(), node.encoded);
779
784
  }));
780
785
  if (pool.length > 0)
781
786
  this.#runEpoch();
@@ -887,6 +892,7 @@ class Chain extends Contract {
887
892
  }
888
893
  catch (error) {
889
894
  console.log({ error });
895
+ globalThis.peernet.pubsub.publish('invalid-transaction', hash);
890
896
  globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: 'fail', hash, error: error });
891
897
  throw { error, hash, from, to, params, nonce };
892
898
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.4.40",
3
+ "version": "1.4.41",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": "./exports/node.js",