refactor: store latest optimistic update in the node client class to be referenced

This commit is contained in:
Derrick Hammer 2023-07-12 02:09:35 -04:00
parent 822b0b46b6
commit 30c7caace7
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 8 deletions

View File

@ -28,14 +28,8 @@ interface Config extends BaseClientOptions {
} }
export default class Client extends BaseClient { export default class Client extends BaseClient {
async sync(): Promise<void> {
await super.sync();
this.subscribe();
}
private beaconUrl: string; private beaconUrl: string;
private blockCache = new NodeCache({ stdTTL: 60 * 60 * 12 }); private http: AxiosInstance = consensusClient;
private blockHashCache = new NodeCache({ stdTTL: 60 * 60 * 12 });
constructor(config: Config) { constructor(config: Config) {
super(config); super(config);
@ -48,7 +42,17 @@ export default class Client extends BaseClient {
this.http.defaults.baseURL = this.beaconUrl; this.http.defaults.baseURL = this.beaconUrl;
} }
private http: AxiosInstance = consensusClient; private _latestOptimisticUpdate: any;
get latestOptimisticUpdate(): any {
return this._latestOptimisticUpdate;
}
async sync(): Promise<void> {
await super.sync();
this.subscribe();
}
async syncProver( async syncProver(
startPeriod: number, startPeriod: number,
@ -106,6 +110,8 @@ export default class Client extends BaseClient {
return null; return null;
} }
this._latestOptimisticUpdate = updateJSON;
return { return {
blockHash: toHexString(update.attestedHeader.execution.blockHash), blockHash: toHexString(update.attestedHeader.execution.blockHash),
blockNumber: update.attestedHeader.execution.blockNumber, blockNumber: update.attestedHeader.execution.blockNumber,