@leofcoin/chain 1.5.16 → 1.5.18

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.
package/exports/chain.js CHANGED
@@ -961,13 +961,13 @@ class State extends Contract {
961
961
  }
962
962
  catch (error) {
963
963
  console.log(error);
964
- console.log(blocks, block.index);
965
964
  await globalThis.transactionPoolStore.delete(hash);
966
965
  console.log('removing invalid transaction');
967
966
  if (isExecutionError(error)) {
968
- console.log('removing invalid block');
967
+ console.log(`removing invalid block ${block.index}`);
969
968
  await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
970
- blocks.splice(block.index - 1, 1);
969
+ const deletedBlock = blocks.splice(block.index, 1);
970
+ console.log(`removed block ${deletedBlock[0].index}`);
971
971
  return this.#loadBlocks(blocks);
972
972
  }
973
973
  console.log(error);
@@ -5894,21 +5894,21 @@ class BlockMessage extends FormatInterface {
5894
5894
  const name = 'block-message';
5895
5895
  super(buffer, proto, { name });
5896
5896
  }
5897
- encode() {
5898
- const decoded = this.decoded;
5897
+ encode(decoded) {
5898
+ decoded = decoded || this.decoded;
5899
5899
  const validators = [];
5900
5900
  const transactions = [];
5901
5901
  for (const validator of decoded.validators) {
5902
5902
  if (validator instanceof ValidatorMessage)
5903
- validators.push(validator.encoded);
5903
+ validators.push(validator.encode());
5904
5904
  else
5905
- validators.push(new ValidatorMessage(validator).encoded);
5905
+ validators.push(new ValidatorMessage(validator).encode());
5906
5906
  }
5907
5907
  for (const transaction of decoded.transactions) {
5908
5908
  if (transaction instanceof TransactionMessage)
5909
- transactions.push(transaction.encoded);
5909
+ transactions.push(transaction.encode());
5910
5910
  else
5911
- transactions.push(new TransactionMessage(transaction).encoded);
5911
+ transactions.push(new TransactionMessage(transaction).encode());
5912
5912
  }
5913
5913
  return super.encode({
5914
5914
  ...decoded,
@@ -5916,8 +5916,9 @@ class BlockMessage extends FormatInterface {
5916
5916
  transactions: index$5(transactions)
5917
5917
  });
5918
5918
  }
5919
- decode() {
5920
- super.decode();
5919
+ decode(encoded) {
5920
+ encoded = encoded || this.encoded;
5921
+ super.decode(encoded);
5921
5922
  // @ts-ignore
5922
5923
  this.decoded.transactions = index$4(this.decoded.transactions).map(transaction => new TransactionMessage(transaction).decoded);
5923
5924
  // @ts-ignore
@@ -6019,28 +6020,28 @@ class EasyWorker {
6019
6020
  }
6020
6021
  }
6021
6022
 
6022
- const worker = new EasyWorker();
6023
-
6024
- globalThis.BigNumber = BigNumber;
6025
- globalThis.contracts = {};
6026
-
6027
- const run = async (blocks) => {
6028
- blocks = await Promise.all(blocks.map(block => new BlockMessage(block)));
6029
- blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp);
6030
-
6031
- blocks = await Promise.all(blocks.map(block => new Promise(async (resolve, reject) => {
6032
- // todo: tx worker or nah?
6033
- const size = block.encoded.length || block.encoded.byteLength;
6034
- console.log(`loaded block: ${await block.hash()} @${block.decoded.index} ${formatBytes(size)}`);
6035
- resolve(block);
6036
- })));
6037
- return blocks
6038
- };
6039
-
6040
- const tasks = async blocks => {
6041
- blocks = await run(blocks);
6042
- worker.postMessage(blocks);
6043
- };
6044
-
6045
-
6023
+ const worker = new EasyWorker();
6024
+
6025
+ globalThis.BigNumber = BigNumber;
6026
+ globalThis.contracts = {};
6027
+
6028
+ const run = async (blocks) => {
6029
+ blocks = await Promise.all(blocks.map(block => new BlockMessage(block)));
6030
+ blocks = blocks.sort((a, b) => a.decoded.timestamp - b.decoded.timestamp);
6031
+
6032
+ blocks = await Promise.all(blocks.map(block => new Promise(async (resolve, reject) => {
6033
+ // todo: tx worker or nah?
6034
+ const size = block.encoded.length || block.encoded.byteLength;
6035
+ console.log(`loaded block: ${await block.hash()} @${block.decoded.index} ${formatBytes(size)}`);
6036
+ resolve(block);
6037
+ })));
6038
+ return blocks
6039
+ };
6040
+
6041
+ const tasks = async blocks => {
6042
+ blocks = await run(blocks);
6043
+ worker.postMessage(blocks);
6044
+ };
6045
+
6046
+
6046
6047
  worker.onmessage(data => tasks(data));