@leofcoin/chain 1.5.69 → 1.6.1

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
@@ -800,7 +800,6 @@ class State extends Contract {
800
800
  }
801
801
  this.#machine = await new Machine(this.#blocks);
802
802
  const lastBlock = await this.#machine.lastBlock;
803
- console.log({ lastBlock });
804
803
  if (lastBlock.hash !== '0x0') {
805
804
  this.updateState(new BlockMessage(lastBlock));
806
805
  }
@@ -818,14 +817,13 @@ class State extends Contract {
818
817
  async updateState(message) {
819
818
  try {
820
819
  const hash = await message.hash();
821
- // await this.state.updateState(message)
822
820
  await globalThis.chainStore.put('lastBlock', hash);
823
821
  globalThis.pubsub.publish('lastBlock', message.encoded);
822
+ await this.#machine.updateState();
824
823
  }
825
824
  catch (error) {
826
825
  console.error(error);
827
826
  }
828
- await this.#machine.updateState();
829
827
  }
830
828
  getLatestBlock() {
831
829
  // @ts-ignore
@@ -1435,17 +1433,17 @@ class Chain extends VersionControl {
1435
1433
  await Promise.all(blockMessage.decoded.transactions
1436
1434
  // @ts-ignore
1437
1435
  .map(async (transaction) => {
1436
+ // @ts-ignore
1438
1437
  let hash = transaction.hash;
1439
1438
  if (!hash) {
1440
1439
  hash = await new TransactionMessage(transaction).hash();
1440
+ // @ts-ignore
1441
1441
  transaction.hash = hash;
1442
1442
  }
1443
1443
  (await transactionPoolStore.has(hash)) && (await transactionPoolStore.delete(hash));
1444
1444
  return transaction;
1445
1445
  }));
1446
1446
  await globalThis.blockStore.put(hash, blockMessage.encoded);
1447
- if ((await this.lastBlock).index < Number(blockMessage.decoded.index))
1448
- await this.updateState(blockMessage);
1449
1447
  debug(`added block: ${hash}`);
1450
1448
  let promises = [];
1451
1449
  let contracts = [];
@@ -1466,13 +1464,10 @@ class Chain extends VersionControl {
1466
1464
  globalThis.pubsub.publish('account-transaction-processed', transaction);
1467
1465
  await globalThis.accountsStore.put(transaction.from, String(transaction.nonce));
1468
1466
  }
1469
- // todo finish state
1470
- // for (const contract of contracts) {
1471
- // const state = await this.machine.get(contract, 'state')
1472
- // // await stateStore.put(contract, state)
1473
- // console.log(state);
1474
- // }
1475
- // await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() })
1467
+ if ((await this.lastBlock).index < Number(blockMessage.decoded.index)) {
1468
+ await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() });
1469
+ await this.updateState(blockMessage);
1470
+ }
1476
1471
  globalThis.pubsub.publish('block-processed', blockMessage.decoded);
1477
1472
  }
1478
1473
  catch (error) {
@@ -1627,15 +1622,13 @@ class Chain extends VersionControl {
1627
1622
  let blockMessage = await new BlockMessage(block);
1628
1623
  const hash = await blockMessage.hash();
1629
1624
  await globalThis.peernet.put(hash, blockMessage.encoded, 'block');
1630
- await this.updateState(blockMessage);
1631
1625
  await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() });
1626
+ await this.updateState(blockMessage);
1632
1627
  debug(`created block: ${hash} @${block.index}`);
1633
1628
  globalThis.peernet.publish('add-block', blockMessage.encoded);
1634
1629
  globalThis.pubsub.publish('add-block', blockMessage.decoded);
1635
1630
  }
1636
1631
  catch (error) {
1637
- console.log(error);
1638
- console.log('eeeee');
1639
1632
  throw new Error(`invalid block ${block}`);
1640
1633
  }
1641
1634
  // data = await this.machine.execute(to, method, params)
@@ -1653,8 +1646,6 @@ class Chain extends VersionControl {
1653
1646
  this.#runEpoch();
1654
1647
  }
1655
1648
  catch (e) {
1656
- console.log(e);
1657
- console.log('rrrrr');
1658
1649
  globalThis.peernet.publish('invalid-transaction', hash);
1659
1650
  throw new Error('invalid transaction');
1660
1651
  }
@@ -38,7 +38,7 @@ export default class State extends Contract {
38
38
  */
39
39
  clearAll(): Promise<void>;
40
40
  init(): Promise<void>;
41
- updateState(message: any): Promise<void>;
41
+ updateState(message: BlockMessage): Promise<void>;
42
42
  getLatestBlock(): Promise<BlockMessage['decoded']>;
43
43
  getAndPutBlock(hash: string): Promise<BlockMessage>;
44
44
  resolveBlock(hash: any): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.5.69",
3
+ "version": "1.6.1",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {
@@ -74,17 +74,17 @@
74
74
  "wireit": "^0.9.5"
75
75
  },
76
76
  "dependencies": {
77
- "@leofcoin/addresses": "^1.0.19",
78
- "@leofcoin/errors": "^1.0.3",
79
- "@leofcoin/lib": "^1.2.39",
80
- "@leofcoin/messages": "^1.4.9",
77
+ "@leofcoin/addresses": "^1.0.21",
78
+ "@leofcoin/errors": "^1.0.5",
79
+ "@leofcoin/lib": "^1.2.41",
80
+ "@leofcoin/messages": "^1.4.11",
81
81
  "@leofcoin/multi-wallet": "^2.1.1",
82
- "@leofcoin/networks": "^1.1.2",
82
+ "@leofcoin/networks": "^1.1.4",
83
83
  "@leofcoin/peernet": "^1.1.73",
84
84
  "@leofcoin/peernet-swarm": "^1.0.0",
85
85
  "@leofcoin/storage": "^3.0.6",
86
- "@leofcoin/utils": "^1.1.14",
87
- "@leofcoin/workers": "^1.4.14",
86
+ "@leofcoin/utils": "^1.1.16",
87
+ "@leofcoin/workers": "^1.4.16",
88
88
  "@netpeer/p2pt-swarm": "^1.3.5",
89
89
  "@netpeer/swarm": "^0.8.9",
90
90
  "@vandeurenglenn/base32": "^1.1.0",