@leofcoin/chain 1.4.40 → 1.4.42

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.
@@ -7778,6 +7778,7 @@ class Transaction extends Protocol {
7778
7778
  throw new Error(`transaction not signed`);
7779
7779
  if (message.decoded.nonce === undefined)
7780
7780
  throw new Error(`nonce required`);
7781
+ message = new TransactionMessage(message.encoded);
7781
7782
  try {
7782
7783
  await this.validateNonce(message.decoded.from, message.decoded.nonce);
7783
7784
  // todo check if signature is valid
@@ -8082,6 +8083,7 @@ class Chain extends Contract {
8082
8083
  await globalThis.peernet.addRequestHandler('lastBlock', this.#lastBlockHandler.bind(this));
8083
8084
  await globalThis.peernet.addRequestHandler('knownBlocks', this.#knownBlocksHandler.bind(this));
8084
8085
  globalThis.peernet.subscribe('add-block', this.#addBlock.bind(this));
8086
+ globalThis.peernet.subscribe('invalid-transaction', this.#invalidTransaction.bind(this));
8085
8087
  globalThis.peernet.subscribe('add-transaction', this.#addTransaction.bind(this));
8086
8088
  globalThis.peernet.subscribe('validator:timeout', this.#validatorTimeout.bind(this));
8087
8089
  globalThis.pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
@@ -8118,6 +8120,10 @@ class Chain extends Contract {
8118
8120
  globalThis.globalThis.pubsub.publish('chain:ready', true);
8119
8121
  return this;
8120
8122
  }
8123
+ async #invalidTransaction(hash) {
8124
+ await transactionPoolStore.delete(hash);
8125
+ console.log(`removed invalid transaction: ${hash}`);
8126
+ }
8121
8127
  async #validatorTimeout(validatorInfo) {
8122
8128
  setTimeout(() => {
8123
8129
  this.#jail.splice(this.#jail.indexOf(validatorInfo.address), 1);
@@ -8180,7 +8186,7 @@ class Chain extends Contract {
8180
8186
  await Promise.all(pool.map(async ({ hash }) => {
8181
8187
  const result = await globalThis.peernet.get(hash);
8182
8188
  const node = await new TransactionMessage(result);
8183
- await globalThis.transactionPoolStore.put(hash, node.encoded);
8189
+ await globalThis.transactionPoolStore.put(await node.hash(), node.encoded);
8184
8190
  }));
8185
8191
  if (pool.length > 0)
8186
8192
  this.#runEpoch();
@@ -8292,6 +8298,7 @@ class Chain extends Contract {
8292
8298
  }
8293
8299
  catch (error) {
8294
8300
  console.log({ error });
8301
+ globalThis.peernet.pubsub.publish('invalid-transaction', hash);
8295
8302
  globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: 'fail', hash, error: error });
8296
8303
  throw { error, hash, from, to, params, nonce };
8297
8304
  }
@@ -8483,6 +8490,7 @@ class Chain extends Contract {
8483
8490
  async #addTransaction(transaction) {
8484
8491
  try {
8485
8492
  transaction = await new TransactionMessage(transaction);
8493
+ transaction = await new TransactionMessage(transaction.encoded);
8486
8494
  const hash = await transaction.hash();
8487
8495
  const has = await globalThis.transactionPoolStore.has(hash);
8488
8496
  if (!has)
@@ -1,4 +1,4 @@
1
- import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './node-browser-bd6a5de3.js';
1
+ import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './node-browser-35d521b9.js';
2
2
  import './contract-32687834.js';
3
3
 
4
4
  function commonjsRequire(path) {
@@ -1,4 +1,4 @@
1
- import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-bd6a5de3.js';
1
+ import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-35d521b9.js';
2
2
  import './contract-32687834.js';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { F as FormatInterface } from './node-browser-bd6a5de3.js';
1
+ import { F as FormatInterface } from './node-browser-35d521b9.js';
2
2
  import './contract-32687834.js';
3
3
 
4
4
  var proto$b = {
@@ -20263,7 +20263,7 @@ class Identity {
20263
20263
  globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
20264
20264
  }
20265
20265
  else {
20266
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-712688fc-ad40bdec.js');
20266
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-2c7d7136-110b02cd.js');
20267
20267
  const { identity, accounts } = await importee.default(password, this.network);
20268
20268
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
20269
20269
  await globalThis.walletStore.put('version', String(1));
@@ -20434,7 +20434,7 @@ class Peernet {
20434
20434
  this.root = options.root;
20435
20435
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
20436
20436
  // FolderMessageResponse
20437
- } = await import(/* webpackChunkName: "messages" */ './messages-3f370680-fb7e5b5b.js');
20437
+ } = await import(/* webpackChunkName: "messages" */ './messages-bcb7873b-d8249d98.js');
20438
20438
  /**
20439
20439
  * proto Object containing protos
20440
20440
  * @type {Object}
@@ -20506,7 +20506,7 @@ class Peernet {
20506
20506
  if (this.#starting || this.#started)
20507
20507
  return;
20508
20508
  this.#starting = true;
20509
- const importee = await import('./client-de444350-a666f9b6.js');
20509
+ const importee = await import('./client-91364a04-ef77946f.js');
20510
20510
  /**
20511
20511
  * @access public
20512
20512
  * @type {PeernetClient}
@@ -20517,7 +20517,7 @@ class Peernet {
20517
20517
  }
20518
20518
  #peerLeft(peer) {
20519
20519
  for (const [id, _peer] of Object.entries(this.#connections)) {
20520
- if (peer.id === peer.id) {
20520
+ if (_peer.id === peer.id) {
20521
20521
  delete this.#connections[id];
20522
20522
  this.removePeer(_peer);
20523
20523
  }
@@ -1,2 +1,2 @@
1
- export { N as default } from './node-browser-bd6a5de3.js';
1
+ export { N as default } from './node-browser-35d521b9.js';
2
2
  import './contract-32687834.js';
package/exports/chain.js CHANGED
@@ -373,6 +373,7 @@ class Transaction extends Protocol {
373
373
  throw new Error(`transaction not signed`);
374
374
  if (message.decoded.nonce === undefined)
375
375
  throw new Error(`nonce required`);
376
+ message = new TransactionMessage(message.encoded);
376
377
  try {
377
378
  await this.validateNonce(message.decoded.from, message.decoded.nonce);
378
379
  // todo check if signature is valid
@@ -677,6 +678,7 @@ class Chain extends Contract {
677
678
  await globalThis.peernet.addRequestHandler('lastBlock', this.#lastBlockHandler.bind(this));
678
679
  await globalThis.peernet.addRequestHandler('knownBlocks', this.#knownBlocksHandler.bind(this));
679
680
  globalThis.peernet.subscribe('add-block', this.#addBlock.bind(this));
681
+ globalThis.peernet.subscribe('invalid-transaction', this.#invalidTransaction.bind(this));
680
682
  globalThis.peernet.subscribe('add-transaction', this.#addTransaction.bind(this));
681
683
  globalThis.peernet.subscribe('validator:timeout', this.#validatorTimeout.bind(this));
682
684
  globalThis.pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
@@ -713,6 +715,10 @@ class Chain extends Contract {
713
715
  globalThis.globalThis.pubsub.publish('chain:ready', true);
714
716
  return this;
715
717
  }
718
+ async #invalidTransaction(hash) {
719
+ await transactionPoolStore.delete(hash);
720
+ console.log(`removed invalid transaction: ${hash}`);
721
+ }
716
722
  async #validatorTimeout(validatorInfo) {
717
723
  setTimeout(() => {
718
724
  this.#jail.splice(this.#jail.indexOf(validatorInfo.address), 1);
@@ -775,7 +781,7 @@ class Chain extends Contract {
775
781
  await Promise.all(pool.map(async ({ hash }) => {
776
782
  const result = await globalThis.peernet.get(hash);
777
783
  const node = await new TransactionMessage(result);
778
- await globalThis.transactionPoolStore.put(hash, node.encoded);
784
+ await globalThis.transactionPoolStore.put(await node.hash(), node.encoded);
779
785
  }));
780
786
  if (pool.length > 0)
781
787
  this.#runEpoch();
@@ -887,6 +893,7 @@ class Chain extends Contract {
887
893
  }
888
894
  catch (error) {
889
895
  console.log({ error });
896
+ globalThis.peernet.pubsub.publish('invalid-transaction', hash);
890
897
  globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: 'fail', hash, error: error });
891
898
  throw { error, hash, from, to, params, nonce };
892
899
  }
@@ -1078,6 +1085,7 @@ class Chain extends Contract {
1078
1085
  async #addTransaction(transaction) {
1079
1086
  try {
1080
1087
  transaction = await new TransactionMessage(transaction);
1088
+ transaction = await new TransactionMessage(transaction.encoded);
1081
1089
  const hash = await transaction.hash();
1082
1090
  const has = await globalThis.transactionPoolStore.has(hash);
1083
1091
  if (!has)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.4.40",
3
+ "version": "1.4.42",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": "./exports/node.js",