@leofcoin/chain 1.4.39 → 1.4.40

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.
@@ -8179,8 +8179,11 @@ class Chain extends Contract {
8179
8179
  pool = pool.filter(item => !item.has);
8180
8180
  await Promise.all(pool.map(async ({ hash }) => {
8181
8181
  const result = await globalThis.peernet.get(hash);
8182
- await globalThis.peernet.put(hash, result);
8182
+ const node = await new TransactionMessage(result);
8183
+ await globalThis.transactionPoolStore.put(hash, node.encoded);
8183
8184
  }));
8185
+ if (pool.length > 0)
8186
+ this.#runEpoch();
8184
8187
  console.log(pool);
8185
8188
  if (lastBlock)
8186
8189
  this.#syncChain(lastBlock);
@@ -8288,9 +8291,9 @@ class Chain extends Contract {
8288
8291
  return result || 'no state change';
8289
8292
  }
8290
8293
  catch (error) {
8291
- console.log(error);
8294
+ console.log({ error });
8292
8295
  globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: 'fail', hash, error: error });
8293
- throw error;
8296
+ throw { error, hash, from, to, params, nonce };
8294
8297
  }
8295
8298
  }
8296
8299
  async #addBlock(block) {
@@ -8369,6 +8372,7 @@ class Chain extends Contract {
8369
8372
  let transactions = await globalThis.transactionPoolStore.values(this.transactionLimit);
8370
8373
  if (Object.keys(transactions)?.length === 0)
8371
8374
  return;
8375
+ const keys = await globalThis.transactionPoolStore.keys();
8372
8376
  let block = {
8373
8377
  transactions: [],
8374
8378
  validators: [],
@@ -8384,15 +8388,20 @@ class Chain extends Contract {
8384
8388
  for (let transaction of transactions) {
8385
8389
  const hash = await transaction.hash();
8386
8390
  try {
8387
- await this.#executeTransaction({ ...transaction.decoded, hash });
8391
+ const result = await this.#executeTransaction({ ...transaction.decoded, hash });
8392
+ console.log({ result });
8388
8393
  block.transactions.push({ hash, ...transaction.decoded });
8389
8394
  block.fees = block.fees.add(await calculateFee(transaction.decoded));
8390
8395
  await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
8391
8396
  }
8392
8397
  catch (e) {
8398
+ console.log(keys.includes(hash));
8399
+ console.log({ e });
8400
+ console.log(hash);
8393
8401
  await globalThis.transactionPoolStore.delete(hash);
8394
8402
  }
8395
8403
  }
8404
+ console.log(block.transactions);
8396
8405
  // don't add empty block
8397
8406
  if (block.transactions.length === 0)
8398
8407
  return;
package/exports/chain.js CHANGED
@@ -774,8 +774,11 @@ class Chain extends Contract {
774
774
  pool = pool.filter(item => !item.has);
775
775
  await Promise.all(pool.map(async ({ hash }) => {
776
776
  const result = await globalThis.peernet.get(hash);
777
- await globalThis.peernet.put(hash, result);
777
+ const node = await new TransactionMessage(result);
778
+ await globalThis.transactionPoolStore.put(hash, node.encoded);
778
779
  }));
780
+ if (pool.length > 0)
781
+ this.#runEpoch();
779
782
  console.log(pool);
780
783
  if (lastBlock)
781
784
  this.#syncChain(lastBlock);
@@ -883,9 +886,9 @@ class Chain extends Contract {
883
886
  return result || 'no state change';
884
887
  }
885
888
  catch (error) {
886
- console.log(error);
889
+ console.log({ error });
887
890
  globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: 'fail', hash, error: error });
888
- throw error;
891
+ throw { error, hash, from, to, params, nonce };
889
892
  }
890
893
  }
891
894
  async #addBlock(block) {
@@ -964,6 +967,7 @@ class Chain extends Contract {
964
967
  let transactions = await globalThis.transactionPoolStore.values(this.transactionLimit);
965
968
  if (Object.keys(transactions)?.length === 0)
966
969
  return;
970
+ const keys = await globalThis.transactionPoolStore.keys();
967
971
  let block = {
968
972
  transactions: [],
969
973
  validators: [],
@@ -979,15 +983,20 @@ class Chain extends Contract {
979
983
  for (let transaction of transactions) {
980
984
  const hash = await transaction.hash();
981
985
  try {
982
- await this.#executeTransaction({ ...transaction.decoded, hash });
986
+ const result = await this.#executeTransaction({ ...transaction.decoded, hash });
987
+ console.log({ result });
983
988
  block.transactions.push({ hash, ...transaction.decoded });
984
989
  block.fees = block.fees.add(await calculateFee(transaction.decoded));
985
990
  await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
986
991
  }
987
992
  catch (e) {
993
+ console.log(keys.includes(hash));
994
+ console.log({ e });
995
+ console.log(hash);
988
996
  await globalThis.transactionPoolStore.delete(hash);
989
997
  }
990
998
  }
999
+ console.log(block.transactions);
991
1000
  // don't add empty block
992
1001
  if (block.transactions.length === 0)
993
1002
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.4.39",
3
+ "version": "1.4.40",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": "./exports/node.js",