From 30c7caace7813d7fa1d9d1d70c4bb9545292cdc4 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 12 Jul 2023 02:09:35 -0400 Subject: [PATCH] refactor: store latest optimistic update in the node client class to be referenced --- src/node/client.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/node/client.ts b/src/node/client.ts index 1e92914..45f402d 100644 --- a/src/node/client.ts +++ b/src/node/client.ts @@ -28,14 +28,8 @@ interface Config extends BaseClientOptions { } export default class Client extends BaseClient { - async sync(): Promise { - await super.sync(); - - this.subscribe(); - } private beaconUrl: string; - private blockCache = new NodeCache({ stdTTL: 60 * 60 * 12 }); - private blockHashCache = new NodeCache({ stdTTL: 60 * 60 * 12 }); + private http: AxiosInstance = consensusClient; constructor(config: Config) { super(config); @@ -48,7 +42,17 @@ export default class Client extends BaseClient { this.http.defaults.baseURL = this.beaconUrl; } - private http: AxiosInstance = consensusClient; + private _latestOptimisticUpdate: any; + + get latestOptimisticUpdate(): any { + return this._latestOptimisticUpdate; + } + + async sync(): Promise { + await super.sync(); + + this.subscribe(); + } async syncProver( startPeriod: number, @@ -106,6 +110,8 @@ export default class Client extends BaseClient { return null; } + this._latestOptimisticUpdate = updateJSON; + return { blockHash: toHexString(update.attestedHeader.execution.blockHash), blockNumber: update.attestedHeader.execution.blockNumber,