@xyo-network/xl1-protocol-sdk 1.26.32 → 1.26.33

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.
@@ -3731,6 +3731,7 @@ var prettifyZodError = (error) => {
3731
3731
  };
3732
3732
 
3733
3733
  // src/simple/block/SimpleBlockViewer.ts
3734
+ var MIN_HEAD_POLL_INTERVAL_MS = 5e3;
3734
3735
  var SimpleBlockViewer = class extends AbstractCreatableProvider {
3735
3736
  moniker = SimpleBlockViewer.defaultMoniker;
3736
3737
  _store;
@@ -3738,10 +3739,16 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3738
3739
  finalizationViewer;
3739
3740
  payloadCache = new LruCacheMap({ max: 1e4 });
3740
3741
  signedHydratedBlockWithDataLakePayloadsCache = new LruCacheMap({ max: 2e3, ttl: 1e3 * 60 * 60 });
3742
+ _headPollHash;
3743
+ _headPollInProgress = false;
3744
+ _headPollTimer = null;
3741
3745
  _signedHydratedBlockCache;
3742
3746
  get finalizedArchivist() {
3743
3747
  return this.params.finalizedArchivist;
3744
3748
  }
3749
+ get headPollIntervalMs() {
3750
+ return this.params.headPollIntervalMs;
3751
+ }
3745
3752
  get hydratedBlockCache() {
3746
3753
  if (this._signedHydratedBlockCache) return this._signedHydratedBlockCache;
3747
3754
  const context = this.getBlockContextRead();
@@ -3755,9 +3762,14 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3755
3762
  return this._store;
3756
3763
  }
3757
3764
  static async paramsHandler(params) {
3765
+ const headPollIntervalMs = params.headPollIntervalMs;
3766
+ if (headPollIntervalMs !== void 0) {
3767
+ assertEx32(headPollIntervalMs >= MIN_HEAD_POLL_INTERVAL_MS, () => `headPollIntervalMs must be at least ${MIN_HEAD_POLL_INTERVAL_MS}ms`);
3768
+ }
3758
3769
  return {
3759
3770
  ...await super.paramsHandler(params),
3760
- finalizedArchivist: assertEx32(params.finalizedArchivist, () => "finalizedArchivist is required")
3771
+ finalizedArchivist: assertEx32(params.finalizedArchivist, () => "finalizedArchivist is required"),
3772
+ headPollIntervalMs
3761
3773
  };
3762
3774
  }
3763
3775
  async blockByHash(hash) {
@@ -3876,11 +3888,57 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3876
3888
  head: (await this.finalizationViewer.head())[0]
3877
3889
  };
3878
3890
  }
3891
+ async startHandler() {
3892
+ await super.startHandler();
3893
+ if (this.headPollIntervalMs === void 0) return;
3894
+ await this.pollHead(false);
3895
+ this.startHeadPolling();
3896
+ }
3897
+ async stopHandler() {
3898
+ this.stopHeadPolling();
3899
+ this._headPollHash = void 0;
3900
+ await super.stopHandler();
3901
+ }
3879
3902
  async blockByNumberWithContext(chainContext, blockNumber) {
3880
3903
  const block = asSignedHydratedBlockWithHashMeta(await hydratedBlockByNumber(chainContext, blockNumber)) ?? null;
3881
3904
  const [result] = block ? await addDataLakePayloads(block, this.dataLakeViewer) : [null, []];
3882
3905
  return result;
3883
3906
  }
3907
+ async pollHead(emitOnChange) {
3908
+ if (this._headPollInProgress) return;
3909
+ this._headPollInProgress = true;
3910
+ try {
3911
+ const block = await this.currentBlock();
3912
+ const hash = block[0]._hash;
3913
+ if (this._headPollHash === void 0) {
3914
+ this._headPollHash = hash;
3915
+ return;
3916
+ }
3917
+ if (hash !== this._headPollHash) {
3918
+ this._headPollHash = hash;
3919
+ if (emitOnChange) {
3920
+ await this.emit("headUpdated", { block });
3921
+ }
3922
+ }
3923
+ } catch (ex) {
3924
+ this.logger?.error("Error polling block head", ex);
3925
+ } finally {
3926
+ this._headPollInProgress = false;
3927
+ }
3928
+ }
3929
+ startHeadPolling() {
3930
+ if (this.headPollIntervalMs === void 0) return;
3931
+ this.stopHeadPolling();
3932
+ this._headPollTimer = setInterval(() => {
3933
+ void this.pollHead(true);
3934
+ }, this.headPollIntervalMs);
3935
+ }
3936
+ stopHeadPolling() {
3937
+ if (this._headPollTimer) {
3938
+ clearInterval(this._headPollTimer);
3939
+ this._headPollTimer = null;
3940
+ }
3941
+ }
3884
3942
  };
3885
3943
  __publicField(SimpleBlockViewer, "defaultMoniker", BlockViewerMoniker2);
3886
3944
  __publicField(SimpleBlockViewer, "dependencies", [FinalizationViewerMoniker]);