@leofcoin/chain 1.5.14 → 1.5.16

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.
@@ -808,6 +808,28 @@ class EasyWorker {
808
808
  }
809
809
  }
810
810
 
811
+ class LeofcoinError extends Error {
812
+ #message;
813
+ constructor(message, options) {
814
+ super(message, options);
815
+ this.#message = message;
816
+ }
817
+ get message() {
818
+ return `${this.name}: ${this.#message}`;
819
+ }
820
+ }
821
+ class ResolveError extends LeofcoinError {
822
+ name = 'ResolveError';
823
+ }
824
+ class ExecutionError extends LeofcoinError {
825
+ name = 'ExecutionError';
826
+ }
827
+ class ContractDeploymentError extends LeofcoinError {
828
+ name = 'ContractDeploymentError';
829
+ }
830
+ const isResolveError = (error) => error.name === 'ResolveError';
831
+ const isExecutionError = (error) => error.name === 'ExecutionError';
832
+
811
833
  // import State from './state'
812
834
  class Machine {
813
835
  #contracts;
@@ -949,7 +971,7 @@ class Machine {
949
971
  }
950
972
  }
951
973
  catch (error) {
952
- throw new Error(`contract deployment failed for ${parameters[0]}\n${error.message}`);
974
+ throw new ContractDeploymentError(`contract deployment failed for ${parameters[0]}\n${error.message}`);
953
975
  }
954
976
  return new Promise((resolve, reject) => {
955
977
  // @ts-ignore
@@ -957,7 +979,7 @@ class Machine {
957
979
  const onmessage = message => {
958
980
  pubsub.unsubscribe(id, onmessage);
959
981
  if (message?.error)
960
- reject(message.error);
982
+ reject(new ExecutionError(message.error));
961
983
  else
962
984
  resolve(message);
963
985
  };
@@ -1056,21 +1078,6 @@ class Jobber {
1056
1078
  }
1057
1079
  }
1058
1080
 
1059
- class LeofcoinError extends Error {
1060
- #message;
1061
- constructor(message, options) {
1062
- super(message, options);
1063
- this.#message = message;
1064
- }
1065
- get message() {
1066
- return `${this.name}: ${this.#message}`;
1067
- }
1068
- }
1069
- class ResolveError extends LeofcoinError {
1070
- name = 'ResolveError';
1071
- }
1072
- const isResolveError = (error) => error.name === 'ResolveError';
1073
-
1074
1081
  class State extends Contract {
1075
1082
  #resolveErrored;
1076
1083
  #lastResolvedTime;
@@ -1499,7 +1506,7 @@ class State extends Contract {
1499
1506
  if (lastTransactions.includes(hash)) {
1500
1507
  console.log('removing invalid block');
1501
1508
  await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
1502
- blocks.splice(block.index);
1509
+ blocks.splice(block.index - 1, 1);
1503
1510
  return this.#loadBlocks(blocks);
1504
1511
  }
1505
1512
  try {
@@ -1518,8 +1525,15 @@ class State extends Contract {
1518
1525
  }
1519
1526
  catch (error) {
1520
1527
  console.log(error);
1528
+ console.log(blocks, block.index);
1521
1529
  await globalThis.transactionPoolStore.delete(hash);
1522
1530
  console.log('removing invalid transaction');
1531
+ if (isExecutionError(error)) {
1532
+ console.log('removing invalid block');
1533
+ await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
1534
+ blocks.splice(block.index - 1, 1);
1535
+ return this.#loadBlocks(blocks);
1536
+ }
1523
1537
  console.log(error);
1524
1538
  return false;
1525
1539
  }
@@ -1,4 +1,4 @@
1
- import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-505084de.js';
1
+ import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-f07d5ecd.js';
2
2
  import './index-e8f03811.js';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { F as FormatInterface } from './node-browser-505084de.js';
1
+ import { F as FormatInterface } from './node-browser-f07d5ecd.js';
2
2
  import './index-e8f03811.js';
3
3
 
4
4
  var proto$b = {
@@ -5,19 +5,19 @@ var nodeConfig = async (config = {
5
5
  networkName: 'leofcoin:peach',
6
6
  networkVersion: 'v1.0.0'
7
7
  }) => {
8
- await globalThis.peernet.addProto('contract-message', ContractMessage);
9
- await globalThis.peernet.addProto('transaction-message', TransactionMessage);
10
- await globalThis.peernet.addProto('block-message', BlockMessage);
11
- await globalThis.peernet.addProto('bw-message', BWMessage);
12
- await globalThis.peernet.addProto('bw-request-message', BWRequestMessage);
13
- await globalThis.peernet.addProto('validator-message', ValidatorMessage);
8
+ await peernet.addProto('contract-message', ContractMessage);
9
+ await peernet.addProto('transaction-message', TransactionMessage);
10
+ await peernet.addProto('block-message', BlockMessage);
11
+ await peernet.addProto('bw-message', BWMessage);
12
+ await peernet.addProto('bw-request-message', BWRequestMessage);
13
+ await peernet.addProto('validator-message', ValidatorMessage);
14
14
  let name = `.${config.network}`;
15
15
  const parts = config.network.split(':');
16
16
  if (parts[1])
17
17
  name = `.${parts[0]}/${parts[1]}`;
18
- await globalThis.peernet.addStore('contract', 'lfc', name, false);
19
- await globalThis.peernet.addStore('accounts', 'lfc', name, false);
20
- await globalThis.peernet.addStore('transactionPool', 'lfc', name, false);
18
+ await peernet.addStore('contract', 'lfc', name, false);
19
+ await peernet.addStore('accounts', 'lfc', name, false);
20
+ await peernet.addStore('transactionPool', 'lfc', name, false);
21
21
  };
22
22
 
23
23
  const encode$9 = (string) => {
@@ -20216,7 +20216,7 @@ class Identity {
20216
20216
  this.selectedAccount = new TextDecoder().decode(selected);
20217
20217
  }
20218
20218
  else {
20219
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-329e0324-67daaccb.js');
20219
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-329e0324-0b2da3d5.js');
20220
20220
  const { identity, accounts } = await importee.default(password, this.network);
20221
20221
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
20222
20222
  await globalThis.walletStore.put('version', String(1));
@@ -20407,7 +20407,7 @@ class Peernet {
20407
20407
  this.root = options.root;
20408
20408
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
20409
20409
  // FolderMessageResponse
20410
- } = await import(/* webpackChunkName: "messages" */ './messages-000b7f84-fd07a3bf.js');
20410
+ } = await import(/* webpackChunkName: "messages" */ './messages-000b7f84-854cd18c.js');
20411
20411
  /**
20412
20412
  * proto Object containing protos
20413
20413
  * @type {Object}
@@ -20973,9 +20973,11 @@ class Node {
20973
20973
  }, password) {
20974
20974
  this.#node = globalThis.Peernet ? await new globalThis.Peernet(config, password) : await new Peernet(config, password);
20975
20975
  await nodeConfig(config);
20976
- globalThis.pubsub.subscribe('chain:ready', () => {
20977
- if (!this.#node.autoStart)
20978
- this.#node.start();
20976
+ globalThis.pubsub.subscribe('chain:ready', async () => {
20977
+ if (!this.#node.autoStart) {
20978
+ await this.#node.start();
20979
+ pubsub.publish('node:ready', true);
20980
+ }
20979
20981
  });
20980
20982
  return this;
20981
20983
  // this.config = await config()
@@ -1,2 +1,2 @@
1
- export { N as default } from './node-browser-505084de.js';
1
+ export { N as default } from './node-browser-f07d5ecd.js';
2
2
  import './index-e8f03811.js';
package/exports/chain.js CHANGED
@@ -4,7 +4,7 @@ import addresses, { contractFactory, nativeToken, validators, nameService } from
4
4
  import { calculateFee, createContractMessage, signTransaction, contractFactoryMessage, nativeTokenMessage, validatorsMessage, nameServiceMessage } from '@leofcoin/lib';
5
5
  import { randombytes } from '@leofcoin/crypto';
6
6
  import EasyWorker from '@vandeurenglenn/easy-worker';
7
- import { isResolveError, ResolveError } from '@leofcoin/errors';
7
+ import { ContractDeploymentError, ExecutionError, isResolveError, ResolveError, isExecutionError } from '@leofcoin/errors';
8
8
 
9
9
  const limit = 1800;
10
10
  const transactionLimit = 1800;
@@ -407,7 +407,7 @@ class Machine {
407
407
  }
408
408
  }
409
409
  catch (error) {
410
- throw new Error(`contract deployment failed for ${parameters[0]}\n${error.message}`);
410
+ throw new ContractDeploymentError(`contract deployment failed for ${parameters[0]}\n${error.message}`);
411
411
  }
412
412
  return new Promise((resolve, reject) => {
413
413
  // @ts-ignore
@@ -415,7 +415,7 @@ class Machine {
415
415
  const onmessage = message => {
416
416
  pubsub.unsubscribe(id, onmessage);
417
417
  if (message?.error)
418
- reject(message.error);
418
+ reject(new ExecutionError(message.error));
419
419
  else
420
420
  resolve(message);
421
421
  };
@@ -942,7 +942,7 @@ class State extends Contract {
942
942
  if (lastTransactions.includes(hash)) {
943
943
  console.log('removing invalid block');
944
944
  await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
945
- blocks.splice(block.index);
945
+ blocks.splice(block.index - 1, 1);
946
946
  return this.#loadBlocks(blocks);
947
947
  }
948
948
  try {
@@ -961,8 +961,15 @@ class State extends Contract {
961
961
  }
962
962
  catch (error) {
963
963
  console.log(error);
964
+ console.log(blocks, block.index);
964
965
  await globalThis.transactionPoolStore.delete(hash);
965
966
  console.log('removing invalid transaction');
967
+ if (isExecutionError(error)) {
968
+ console.log('removing invalid block');
969
+ await globalThis.blockStore.delete(await (await new BlockMessage(block)).hash());
970
+ blocks.splice(block.index - 1, 1);
971
+ return this.#loadBlocks(blocks);
972
+ }
966
973
  console.log(error);
967
974
  return false;
968
975
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.5.14",
3
+ "version": "1.5.16",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": {