@lunarislab/state-sync 1.1.18 → 1.1.19

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.
@@ -15,6 +15,7 @@ export declare class Watcher<signature extends EventSignature> {
15
15
  protected event: EventSignature;
16
16
  protected requestInterval: number;
17
17
  protected started: boolean;
18
+ protected concurrency: number;
18
19
  constructor(client: StateSync, config: IWatcherConfig<signature>);
19
20
  protected getContracts(): `0x${string}`[];
20
21
  protected _getLogs(contracts: Address[], fromBlock?: bigint): Promise<void>;
@@ -12,6 +12,7 @@ class Watcher {
12
12
  this.client = client;
13
13
  this.currentBlockNum = 0n;
14
14
  this.started = false;
15
+ this.concurrency = 0;
15
16
  this.emitter = new events_1.EventEmitter();
16
17
  this.contracts = new Set(config.contracts) || new Set();
17
18
  this.requestInterval = config.requestInterval || 50;
@@ -25,8 +26,9 @@ class Watcher {
25
26
  async _getLogs(contracts, fromBlock = 0n) {
26
27
  let gap = this.currentBlockNum;
27
28
  let block = fromBlock;
29
+ this.concurrency++;
28
30
  while (block < this.currentBlockNum) {
29
- await new Promise(x => setTimeout(x, this.requestInterval));
31
+ await new Promise(x => setTimeout(x, this.requestInterval * this.concurrency));
30
32
  try {
31
33
  const logs = await this.client.public.getLogs({
32
34
  fromBlock: block,
@@ -45,6 +47,8 @@ class Watcher {
45
47
  continue;
46
48
  }
47
49
  }
50
+ ;
51
+ this.concurrency--;
48
52
  }
49
53
  ;
50
54
  async start(fromBlock) {
@@ -65,7 +69,8 @@ class Watcher {
65
69
  }
66
70
  ;
67
71
  async addContracts(contracts) {
68
- await this._getLogs(contracts);
72
+ if (this.started)
73
+ await this._getLogs(contracts);
69
74
  this.contracts.forEach(c => this.contracts.add(c));
70
75
  }
71
76
  ;
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "viem": "^2.21.58"
9
9
  },
10
10
  "name": "@lunarislab/state-sync",
11
- "version": "1.1.18",
11
+ "version": "1.1.19",
12
12
  "main": "index.js",
13
13
  "scripts": {
14
14
  "test": "ts-node ./test.ts",