@leofcoin/chain 1.4.31 → 1.4.32

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
@@ -656,6 +656,16 @@ class Chain extends Contract {
656
656
  await this.#setup();
657
657
  this.utils = { BigNumber, formatUnits, parseUnits };
658
658
  this.state = new State();
659
+ await peernet.addRequestHandler('bw-request-message', () => {
660
+ return new BWMessage(peernet.client.bw) || { up: 0, down: 0 };
661
+ });
662
+ await peernet.addRequestHandler('lastBlock', this.#lastBlockHandler.bind(this));
663
+ await peernet.addRequestHandler('knownBlocks', this.#knownBlocksHandler.bind(this));
664
+ peernet.subscribe('add-block', this.#addBlock.bind(this));
665
+ peernet.subscribe('add-transaction', this.#addTransaction.bind(this));
666
+ peernet.subscribe('validator:timeout', this.#validatorTimeout.bind(this));
667
+ pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
668
+ // todo some functions rely on state
659
669
  try {
660
670
  let localBlock;
661
671
  try {
@@ -679,19 +689,11 @@ class Chain extends Contract {
679
689
  catch (error) {
680
690
  console.log({ e: error });
681
691
  }
682
- await peernet.addRequestHandler('bw-request-message', () => {
683
- return new BWMessage(peernet.client.bw) || { up: 0, down: 0 };
684
- });
685
- await peernet.addRequestHandler('lastBlock', this.#lastBlockHandler.bind(this));
686
- await peernet.addRequestHandler('knownBlocks', this.#knownBlocksHandler.bind(this));
687
- peernet.subscribe('add-block', this.#addBlock.bind(this));
688
- peernet.subscribe('add-transaction', this.#addTransaction.bind(this));
689
- peernet.subscribe('validator:timeout', this.#validatorTimeout.bind(this));
690
- pubsub.subscribe('peer:connected', this.#peerConnected.bind(this));
691
692
  // load local blocks
692
693
  await this.resolveBlocks();
693
694
  this.#machine = await new Machine(this.#blocks);
694
695
  await this.#loadBlocks(this.#blocks);
696
+ globalThis.pubsub.publish('chain:ready', true);
695
697
  return this;
696
698
  }
697
699
  async #validatorTimeout(validatorInfo) {
@@ -733,6 +735,12 @@ class Chain extends Contract {
733
735
  let response = await peer.request(node.encoded);
734
736
  response = await new globalThis.peernet.protos['peernet-response'](response);
735
737
  let lastBlock = response.decoded.response;
738
+ // try catch known blocks
739
+ node = await new peernet.protos['peernet-request']({ request: 'knownBlocks' });
740
+ node = await peernet.prepareMessage(node);
741
+ response = await peer.request(node.encoded);
742
+ response = await new globalThis.peernet.protos['peernet-response'](response);
743
+ this.#knownBlocks = response.decoded.response;
736
744
  this.#syncChain(lastBlock);
737
745
  }
738
746
  #epochTimeout;
package/exports/node.js CHANGED
@@ -4,6 +4,7 @@ import networks from '@leofcoin/networks';
4
4
 
5
5
  // import config from './config/config'
6
6
  class Node {
7
+ #node;
7
8
  constructor(config, password) {
8
9
  return this._init(config, password);
9
10
  }
@@ -13,8 +14,11 @@ class Node {
13
14
  networkVersion: 'peach',
14
15
  stars: networks.leofcoin.peach.stars
15
16
  }, password) {
16
- globalThis.Peernet ? await new globalThis.Peernet(config, password) : await new Peernet(config, password);
17
+ this.#node = globalThis.Peernet ? await new globalThis.Peernet(config, password) : await new Peernet(config, password);
17
18
  await nodeConfig(config);
19
+ globalThis.pubsub.subscribe('chain:ready', () => {
20
+ this.#node.start();
21
+ });
18
22
  return this;
19
23
  // this.config = await config()
20
24
  }
@@ -1,4 +1,5 @@
1
1
  export default class Node {
2
+ #private;
2
3
  constructor(config: any, password: string);
3
4
  _init(config: {
4
5
  network: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.4.31",
3
+ "version": "1.4.32",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": "./exports/node.js",