@leofcoin/chain 1.4.43 → 1.4.44

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.
@@ -1,4 +1,4 @@
1
- import { B as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, a as arrayify, b as isBytes, C as ContractMessage, T as TransactionMessage, c as CodecHash, d as BlockMessage, e as BWMessage, f as BWRequestMessage } from './contract-32687834.js';
1
+ import { B as BigNumber, L as Logger, v as version$1, h as hexZeroPad, i as isBigNumberish, a as arrayify, b as isBytes, C as ContractMessage, T as TransactionMessage, c as CodecHash, d as BlockMessage, e as BWMessage, f as BWRequestMessage } from './contract-f76383c3.js';
2
2
 
3
3
  const logger$1 = new Logger(version$1);
4
4
  const _constructorGuard = {};
@@ -7778,7 +7778,6 @@ 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);
7782
7781
  try {
7783
7782
  await this.validateNonce(message.decoded.from, message.decoded.nonce);
7784
7783
  // todo check if signature is valid
@@ -8121,7 +8120,7 @@ class Chain extends Contract {
8121
8120
  return this;
8122
8121
  }
8123
8122
  async #invalidTransaction(hash) {
8124
- await transactionPoolStore.delete(hash);
8123
+ await globalThis.transactionPoolStore.delete(hash);
8125
8124
  console.log(`removed invalid transaction: ${hash}`);
8126
8125
  }
8127
8126
  async #validatorTimeout(validatorInfo) {
@@ -8264,9 +8263,12 @@ class Chain extends Contract {
8264
8263
  * @param {Block[]} blocks
8265
8264
  */
8266
8265
  async #loadBlocks(blocks) {
8266
+ let poolTransactionKeys = await globalThis.transactionPoolStore.keys();
8267
8267
  for (const block of blocks) {
8268
8268
  if (block && !block.loaded) {
8269
8269
  for (const transaction of block.transactions) {
8270
+ if (poolTransactionKeys.includes(transaction.hash))
8271
+ await globalThis.transactionPoolStore.delete(transaction.hash);
8270
8272
  try {
8271
8273
  await this.#machine.execute(transaction.to, transaction.method, transaction.params);
8272
8274
  if (transaction.to === nativeToken$1) {
@@ -8394,18 +8396,25 @@ class Chain extends Contract {
8394
8396
  transactions = transactions.sort((a, b) => a.nonce - b.nonce);
8395
8397
  for (let transaction of transactions) {
8396
8398
  const hash = await transaction.hash();
8397
- try {
8398
- const result = await this.#executeTransaction({ ...transaction.decoded, hash });
8399
- console.log({ result });
8400
- block.transactions.push({ hash, ...transaction.decoded });
8401
- block.fees = block.fees.add(await calculateFee(transaction.decoded));
8402
- await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
8403
- }
8404
- catch (e) {
8405
- console.log(keys.includes(hash));
8406
- console.log({ e });
8407
- console.log(hash);
8399
+ const doubleTransaction = this.#blocks.filter(({ transaction }) => transaction.hash === hash);
8400
+ if (doubleTransaction.length > 0) {
8408
8401
  await globalThis.transactionPoolStore.delete(hash);
8402
+ await globalThis.peernet.publish('invalid-transaction', hash);
8403
+ }
8404
+ else {
8405
+ try {
8406
+ const result = await this.#executeTransaction({ ...transaction.decoded, hash });
8407
+ console.log({ result });
8408
+ block.transactions.push({ hash, ...transaction.decoded });
8409
+ block.fees = block.fees.add(await calculateFee(transaction.decoded));
8410
+ await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
8411
+ }
8412
+ catch (e) {
8413
+ console.log(keys.includes(hash));
8414
+ console.log({ e });
8415
+ console.log(hash);
8416
+ await globalThis.transactionPoolStore.delete(hash);
8417
+ }
8409
8418
  }
8410
8419
  }
8411
8420
  console.log(block.transactions);
@@ -8473,7 +8482,6 @@ class Chain extends Contract {
8473
8482
  await Promise.all(block.transactions
8474
8483
  .map(async (transaction) => globalThis.transactionPoolStore.delete(transaction.hash)));
8475
8484
  let blockMessage = await new BlockMessage(block);
8476
- blockMessage = await new BlockMessage(blockMessage.encoded);
8477
8485
  const hash = await blockMessage.hash();
8478
8486
  await globalThis.peernet.put(hash, blockMessage.encoded, 'block');
8479
8487
  await this.#updateState(blockMessage);
@@ -8490,7 +8498,6 @@ class Chain extends Contract {
8490
8498
  async #addTransaction(transaction) {
8491
8499
  try {
8492
8500
  transaction = await new TransactionMessage(transaction);
8493
- transaction = await new TransactionMessage(transaction.encoded);
8494
8501
  const hash = await transaction.hash();
8495
8502
  const has = await globalThis.transactionPoolStore.has(hash);
8496
8503
  if (!has)
@@ -1,5 +1,5 @@
1
- import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './node-browser-35d521b9.js';
2
- import './contract-32687834.js';
1
+ import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './node-browser-cf761de2.js';
2
+ import './contract-f76383c3.js';
3
3
 
4
4
  function commonjsRequire(path) {
5
5
  throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
@@ -4799,12 +4799,13 @@ const isUint8Array = (type) => type === 'uint8Array';
4799
4799
  const isBigNumber = (type) => type === 'bigNumber';
4800
4800
  const tokenize = (key, value) => {
4801
4801
  const optional = key.endsWith('?');
4802
- let type = value;
4803
- type = Array.isArray(type) ? 'array' : typeof type;
4804
- if (value instanceof Uint8Array)
4802
+ let type = value === undefined ? key : value;
4803
+ if (type instanceof Uint8Array)
4805
4804
  type = 'uint8Array';
4806
- else if (value._isBigNumber)
4805
+ else if (type?._isBigNumber || type.isBigNumber)
4807
4806
  type = 'bigNumber';
4807
+ else
4808
+ type = Array.isArray(type) ? 'array' : typeof type;
4808
4809
  const parts = key.split('?');
4809
4810
  const minimumLength = parts[2]?.includes('min') ? parts[2].split['min:'][1] : 0;
4810
4811
  return { type, optional, key: parts[0], minimumLength };
@@ -4816,6 +4817,7 @@ const toType = (data) => {
4816
4817
  // returns the ArrayBuffer as a UintArray
4817
4818
  if (data instanceof ArrayBuffer)
4818
4819
  return new Uint8Array(data);
4820
+ // returns the bigNumbers hex as a UintArray
4819
4821
  if (data._isBigNumber)
4820
4822
  return new TextEncoder().encode(data._hex || data.toHexString());
4821
4823
  // returns the string as a UintArray
@@ -4829,11 +4831,11 @@ const toType = (data) => {
4829
4831
  return new TextEncoder().encode(data.toString());
4830
4832
  throw new Error(`unsuported type ${typeof data || data}`);
4831
4833
  };
4832
- const encode = (proto, input) => {
4834
+ const encode = (proto, input, compress) => {
4833
4835
  const keys = Object.keys(proto);
4834
4836
  const values = Object.values(proto);
4835
4837
  const set = [];
4836
- for (let i = 0; i < keys.length; i++) {
4838
+ for (let i = 0; i < values.length; i++) {
4837
4839
  const token = tokenize(keys[i], values[i]);
4838
4840
  const data = input[token.key];
4839
4841
  if (!token.optional && data === undefined)
@@ -4846,14 +4848,14 @@ const encode = (proto, input) => {
4846
4848
  }
4847
4849
  return index$5(set);
4848
4850
  };
4849
- const decode = (proto, uint8Array) => {
4851
+ const decode = (proto, uint8Array, compressed) => {
4850
4852
  let deconcated = index$4(uint8Array);
4851
4853
  const output = {};
4852
4854
  const keys = Object.keys(proto);
4853
4855
  const values = Object.values(proto);
4854
4856
  if (keys.length !== deconcated.length)
4855
4857
  console.warn(`length mismatch: expected ${keys.length} got ${uint8Array.length}`);
4856
- for (let i = 0; i < keys.length; i++) {
4858
+ for (let i = 0; i < values.length; i++) {
4857
4859
  const token = tokenize(keys[i], values[i]);
4858
4860
  if (isUint8Array(token.type))
4859
4861
  output[token.key] = deconcated[i];
@@ -5822,7 +5824,7 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface$1 {
5822
5824
  this.fromUint8Array(buffer);
5823
5825
  else if (buffer instanceof ArrayBuffer)
5824
5826
  this.fromArrayBuffer(buffer);
5825
- else if (buffer instanceof FormatInterface$1 && buffer?.name === this.name)
5827
+ else if (buffer instanceof FormatInterface && buffer?.name === this.name)
5826
5828
  return buffer;
5827
5829
  else if (typeof buffer === 'string') {
5828
5830
  if (this.isHex(buffer))
@@ -5964,7 +5966,7 @@ class TransactionMessage extends FormatInterface {
5964
5966
 
5965
5967
  var proto$4 = {
5966
5968
  address: String(),
5967
- reward: String()
5969
+ reward: BigNumber.from(0)
5968
5970
  };
5969
5971
 
5970
5972
  class ValidatorMessage extends FormatInterface {
@@ -5981,8 +5983,8 @@ var proto$3 = {
5981
5983
  index: Number(),
5982
5984
  previousHash: String(),
5983
5985
  timestamp: Number(),
5984
- reward: String(),
5985
- fees: String(),
5986
+ reward: BigNumber.from(0),
5987
+ fees: BigNumber.from(0),
5986
5988
  transactions: new Uint8Array(),
5987
5989
  validators: new Uint8Array()
5988
5990
  };
@@ -1,5 +1,5 @@
1
- import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-35d521b9.js';
2
- import './contract-32687834.js';
1
+ import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-cf761de2.js';
2
+ import './contract-f76383c3.js';
3
3
 
4
4
  /**
5
5
  * @params {String} network
@@ -1,5 +1,5 @@
1
- import { F as FormatInterface } from './node-browser-35d521b9.js';
2
- import './contract-32687834.js';
1
+ import { F as FormatInterface } from './node-browser-cf761de2.js';
2
+ import './contract-f76383c3.js';
3
3
 
4
4
  var proto$b = {
5
5
  data: new Uint8Array(),
@@ -1,4 +1,4 @@
1
- import { C as ContractMessage, T as TransactionMessage, d as BlockMessage, e as BWMessage, f as BWRequestMessage, V as ValidatorMessage } from './contract-32687834.js';
1
+ import { C as ContractMessage, T as TransactionMessage, d as BlockMessage, e as BWMessage, f as BWRequestMessage, V as ValidatorMessage } from './contract-f76383c3.js';
2
2
 
3
3
  var nodeConfig = async (config = {
4
4
  network: 'leofcoin:peach',
@@ -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-2c7d7136-110b02cd.js');
20266
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-2c7d7136-ba66b864.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-bcb7873b-d8249d98.js');
20437
+ } = await import(/* webpackChunkName: "messages" */ './messages-bcb7873b-22fd727d.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-91364a04-ef77946f.js');
20509
+ const importee = await import('./client-91364a04-457da758.js');
20510
20510
  /**
20511
20511
  * @access public
20512
20512
  * @type {PeernetClient}
@@ -1,2 +1,2 @@
1
- export { N as default } from './node-browser-35d521b9.js';
2
- import './contract-32687834.js';
1
+ export { N as default } from './node-browser-cf761de2.js';
2
+ import './contract-f76383c3.js';
@@ -4732,12 +4732,13 @@ const isUint8Array = (type) => type === 'uint8Array';
4732
4732
  const isBigNumber = (type) => type === 'bigNumber';
4733
4733
  const tokenize = (key, value) => {
4734
4734
  const optional = key.endsWith('?');
4735
- let type = value;
4736
- type = Array.isArray(type) ? 'array' : typeof type;
4737
- if (value instanceof Uint8Array)
4735
+ let type = value === undefined ? key : value;
4736
+ if (type instanceof Uint8Array)
4738
4737
  type = 'uint8Array';
4739
- else if (value._isBigNumber)
4738
+ else if (type?._isBigNumber || type.isBigNumber)
4740
4739
  type = 'bigNumber';
4740
+ else
4741
+ type = Array.isArray(type) ? 'array' : typeof type;
4741
4742
  const parts = key.split('?');
4742
4743
  const minimumLength = parts[2]?.includes('min') ? parts[2].split['min:'][1] : 0;
4743
4744
  return { type, optional, key: parts[0], minimumLength };
@@ -4749,6 +4750,7 @@ const toType = (data) => {
4749
4750
  // returns the ArrayBuffer as a UintArray
4750
4751
  if (data instanceof ArrayBuffer)
4751
4752
  return new Uint8Array(data);
4753
+ // returns the bigNumbers hex as a UintArray
4752
4754
  if (data._isBigNumber)
4753
4755
  return new TextEncoder().encode(data._hex || data.toHexString());
4754
4756
  // returns the string as a UintArray
@@ -4762,11 +4764,11 @@ const toType = (data) => {
4762
4764
  return new TextEncoder().encode(data.toString());
4763
4765
  throw new Error(`unsuported type ${typeof data || data}`);
4764
4766
  };
4765
- const encode = (proto, input) => {
4767
+ const encode = (proto, input, compress) => {
4766
4768
  const keys = Object.keys(proto);
4767
4769
  const values = Object.values(proto);
4768
4770
  const set = [];
4769
- for (let i = 0; i < keys.length; i++) {
4771
+ for (let i = 0; i < values.length; i++) {
4770
4772
  const token = tokenize(keys[i], values[i]);
4771
4773
  const data = input[token.key];
4772
4774
  if (!token.optional && data === undefined)
@@ -4779,14 +4781,14 @@ const encode = (proto, input) => {
4779
4781
  }
4780
4782
  return index$5(set);
4781
4783
  };
4782
- const decode = (proto, uint8Array) => {
4784
+ const decode = (proto, uint8Array, compressed) => {
4783
4785
  let deconcated = index$4(uint8Array);
4784
4786
  const output = {};
4785
4787
  const keys = Object.keys(proto);
4786
4788
  const values = Object.values(proto);
4787
4789
  if (keys.length !== deconcated.length)
4788
4790
  console.warn(`length mismatch: expected ${keys.length} got ${uint8Array.length}`);
4789
- for (let i = 0; i < keys.length; i++) {
4791
+ for (let i = 0; i < values.length; i++) {
4790
4792
  const token = tokenize(keys[i], values[i]);
4791
4793
  if (isUint8Array(token.type))
4792
4794
  output[token.key] = deconcated[i];
@@ -5755,7 +5757,7 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface$1 {
5755
5757
  this.fromUint8Array(buffer);
5756
5758
  else if (buffer instanceof ArrayBuffer)
5757
5759
  this.fromArrayBuffer(buffer);
5758
- else if (buffer instanceof FormatInterface$1 && buffer?.name === this.name)
5760
+ else if (buffer instanceof FormatInterface && buffer?.name === this.name)
5759
5761
  return buffer;
5760
5762
  else if (typeof buffer === 'string') {
5761
5763
  if (this.isHex(buffer))
@@ -5896,7 +5898,7 @@ class TransactionMessage extends FormatInterface {
5896
5898
 
5897
5899
  var proto$1 = {
5898
5900
  address: String(),
5899
- reward: String()
5901
+ reward: BigNumber.from(0)
5900
5902
  };
5901
5903
 
5902
5904
  class ValidatorMessage extends FormatInterface {
@@ -5913,8 +5915,8 @@ var proto = {
5913
5915
  index: Number(),
5914
5916
  previousHash: String(),
5915
5917
  timestamp: Number(),
5916
- reward: String(),
5917
- fees: String(),
5918
+ reward: BigNumber.from(0),
5919
+ fees: BigNumber.from(0),
5918
5920
  transactions: new Uint8Array(),
5919
5921
  validators: new Uint8Array()
5920
5922
  };
@@ -4732,12 +4732,13 @@ const isUint8Array = (type) => type === 'uint8Array';
4732
4732
  const isBigNumber = (type) => type === 'bigNumber';
4733
4733
  const tokenize = (key, value) => {
4734
4734
  const optional = key.endsWith('?');
4735
- let type = value;
4736
- type = Array.isArray(type) ? 'array' : typeof type;
4737
- if (value instanceof Uint8Array)
4735
+ let type = value === undefined ? key : value;
4736
+ if (type instanceof Uint8Array)
4738
4737
  type = 'uint8Array';
4739
- else if (value._isBigNumber)
4738
+ else if (type?._isBigNumber || type.isBigNumber)
4740
4739
  type = 'bigNumber';
4740
+ else
4741
+ type = Array.isArray(type) ? 'array' : typeof type;
4741
4742
  const parts = key.split('?');
4742
4743
  const minimumLength = parts[2]?.includes('min') ? parts[2].split['min:'][1] : 0;
4743
4744
  return { type, optional, key: parts[0], minimumLength };
@@ -4749,6 +4750,7 @@ const toType = (data) => {
4749
4750
  // returns the ArrayBuffer as a UintArray
4750
4751
  if (data instanceof ArrayBuffer)
4751
4752
  return new Uint8Array(data);
4753
+ // returns the bigNumbers hex as a UintArray
4752
4754
  if (data._isBigNumber)
4753
4755
  return new TextEncoder().encode(data._hex || data.toHexString());
4754
4756
  // returns the string as a UintArray
@@ -4762,11 +4764,11 @@ const toType = (data) => {
4762
4764
  return new TextEncoder().encode(data.toString());
4763
4765
  throw new Error(`unsuported type ${typeof data || data}`);
4764
4766
  };
4765
- const encode = (proto, input) => {
4767
+ const encode = (proto, input, compress) => {
4766
4768
  const keys = Object.keys(proto);
4767
4769
  const values = Object.values(proto);
4768
4770
  const set = [];
4769
- for (let i = 0; i < keys.length; i++) {
4771
+ for (let i = 0; i < values.length; i++) {
4770
4772
  const token = tokenize(keys[i], values[i]);
4771
4773
  const data = input[token.key];
4772
4774
  if (!token.optional && data === undefined)
@@ -4779,14 +4781,14 @@ const encode = (proto, input) => {
4779
4781
  }
4780
4782
  return index$5(set);
4781
4783
  };
4782
- const decode = (proto, uint8Array) => {
4784
+ const decode = (proto, uint8Array, compressed) => {
4783
4785
  let deconcated = index$4(uint8Array);
4784
4786
  const output = {};
4785
4787
  const keys = Object.keys(proto);
4786
4788
  const values = Object.values(proto);
4787
4789
  if (keys.length !== deconcated.length)
4788
4790
  console.warn(`length mismatch: expected ${keys.length} got ${uint8Array.length}`);
4789
- for (let i = 0; i < keys.length; i++) {
4791
+ for (let i = 0; i < values.length; i++) {
4790
4792
  const token = tokenize(keys[i], values[i]);
4791
4793
  if (isUint8Array(token.type))
4792
4794
  output[token.key] = deconcated[i];
@@ -5755,7 +5757,7 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface$1 {
5755
5757
  this.fromUint8Array(buffer);
5756
5758
  else if (buffer instanceof ArrayBuffer)
5757
5759
  this.fromArrayBuffer(buffer);
5758
- else if (buffer instanceof FormatInterface$1 && buffer?.name === this.name)
5760
+ else if (buffer instanceof FormatInterface && buffer?.name === this.name)
5759
5761
  return buffer;
5760
5762
  else if (typeof buffer === 'string') {
5761
5763
  if (this.isHex(buffer))
@@ -5896,7 +5898,7 @@ class TransactionMessage extends FormatInterface {
5896
5898
 
5897
5899
  var proto$2 = {
5898
5900
  address: String(),
5899
- reward: String()
5901
+ reward: BigNumber.from(0)
5900
5902
  };
5901
5903
 
5902
5904
  class ValidatorMessage extends FormatInterface {
@@ -5913,8 +5915,8 @@ var proto$1 = {
5913
5915
  index: Number(),
5914
5916
  previousHash: String(),
5915
5917
  timestamp: Number(),
5916
- reward: String(),
5917
- fees: String(),
5918
+ reward: BigNumber.from(0),
5919
+ fees: BigNumber.from(0),
5918
5920
  transactions: new Uint8Array(),
5919
5921
  validators: new Uint8Array()
5920
5922
  };
package/exports/chain.js CHANGED
@@ -373,7 +373,6 @@ 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);
377
376
  try {
378
377
  await this.validateNonce(message.decoded.from, message.decoded.nonce);
379
378
  // todo check if signature is valid
@@ -716,7 +715,7 @@ class Chain extends Contract {
716
715
  return this;
717
716
  }
718
717
  async #invalidTransaction(hash) {
719
- await transactionPoolStore.delete(hash);
718
+ await globalThis.transactionPoolStore.delete(hash);
720
719
  console.log(`removed invalid transaction: ${hash}`);
721
720
  }
722
721
  async #validatorTimeout(validatorInfo) {
@@ -859,9 +858,12 @@ class Chain extends Contract {
859
858
  * @param {Block[]} blocks
860
859
  */
861
860
  async #loadBlocks(blocks) {
861
+ let poolTransactionKeys = await globalThis.transactionPoolStore.keys();
862
862
  for (const block of blocks) {
863
863
  if (block && !block.loaded) {
864
864
  for (const transaction of block.transactions) {
865
+ if (poolTransactionKeys.includes(transaction.hash))
866
+ await globalThis.transactionPoolStore.delete(transaction.hash);
865
867
  try {
866
868
  await this.#machine.execute(transaction.to, transaction.method, transaction.params);
867
869
  if (transaction.to === nativeToken) {
@@ -989,18 +991,25 @@ class Chain extends Contract {
989
991
  transactions = transactions.sort((a, b) => a.nonce - b.nonce);
990
992
  for (let transaction of transactions) {
991
993
  const hash = await transaction.hash();
992
- try {
993
- const result = await this.#executeTransaction({ ...transaction.decoded, hash });
994
- console.log({ result });
995
- block.transactions.push({ hash, ...transaction.decoded });
996
- block.fees = block.fees.add(await calculateFee(transaction.decoded));
997
- await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
998
- }
999
- catch (e) {
1000
- console.log(keys.includes(hash));
1001
- console.log({ e });
1002
- console.log(hash);
994
+ const doubleTransaction = this.#blocks.filter(({ transaction }) => transaction.hash === hash);
995
+ if (doubleTransaction.length > 0) {
1003
996
  await globalThis.transactionPoolStore.delete(hash);
997
+ await globalThis.peernet.publish('invalid-transaction', hash);
998
+ }
999
+ else {
1000
+ try {
1001
+ const result = await this.#executeTransaction({ ...transaction.decoded, hash });
1002
+ console.log({ result });
1003
+ block.transactions.push({ hash, ...transaction.decoded });
1004
+ block.fees = block.fees.add(await calculateFee(transaction.decoded));
1005
+ await globalThis.accountsStore.put(transaction.decoded.from, new TextEncoder().encode(String(transaction.decoded.nonce)));
1006
+ }
1007
+ catch (e) {
1008
+ console.log(keys.includes(hash));
1009
+ console.log({ e });
1010
+ console.log(hash);
1011
+ await globalThis.transactionPoolStore.delete(hash);
1012
+ }
1004
1013
  }
1005
1014
  }
1006
1015
  console.log(block.transactions);
@@ -1068,7 +1077,6 @@ class Chain extends Contract {
1068
1077
  await Promise.all(block.transactions
1069
1078
  .map(async (transaction) => globalThis.transactionPoolStore.delete(transaction.hash)));
1070
1079
  let blockMessage = await new BlockMessage(block);
1071
- blockMessage = await new BlockMessage(blockMessage.encoded);
1072
1080
  const hash = await blockMessage.hash();
1073
1081
  await globalThis.peernet.put(hash, blockMessage.encoded, 'block');
1074
1082
  await this.#updateState(blockMessage);
@@ -1085,7 +1093,6 @@ class Chain extends Contract {
1085
1093
  async #addTransaction(transaction) {
1086
1094
  try {
1087
1095
  transaction = await new TransactionMessage(transaction);
1088
- transaction = await new TransactionMessage(transaction.encoded);
1089
1096
  const hash = await transaction.hash();
1090
1097
  const has = await globalThis.transactionPoolStore.has(hash);
1091
1098
  if (!has)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.4.43",
3
+ "version": "1.4.44",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": "./exports/node.js",