From b85e1779ee7e4d8fccb6c7b8ee0e66f332823d19 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 11 Jul 2023 04:15:35 -0400 Subject: [PATCH] feat: add getter for provider --- src/client/client.ts | 53 ++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/client/client.ts b/src/client/client.ts index 57e68b9..f0bd04d 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -21,13 +21,41 @@ interface Config extends BaseClientOptions { } export default class Client extends BaseClient { - private provider?: IVerifyingProvider; protected declare options: Config; constructor(options: Config) { super(options); } + private _provider?: IVerifyingProvider; + + get provider(): IVerifyingProvider { + return this._provider as IVerifyingProvider; + } + + async sync(): Promise { + await super.sync(); + + if (!this._provider) { + const { blockHash, blockNumber } = await this.getNextValidExecutionInfo(); + const factory = this.options.provider; + const provider = new factory( + this.options.rpcHandler, + blockNumber, + blockHash, + ); + this.subscribe((ei) => { + console.log( + `Received a new blockheader: ${ei.blockNumber} ${ei.blockHash}`, + ); + provider.update(ei.blockNumber, ei.blockHash); + }); + + this._provider = provider; + this.booted = true; + } + } + protected async getLatestExecution(): Promise { const updateJSON = await this.options.prover.callback( "consensus_optimistic_update", @@ -50,29 +78,6 @@ export default class Client extends BaseClient { }; } - async sync(): Promise { - await super.sync(); - - if (!this.provider) { - const { blockHash, blockNumber } = await this.getNextValidExecutionInfo(); - const factory = this.options.provider; - const provider = new factory( - this.options.rpcHandler, - blockNumber, - blockHash, - ); - this.subscribe((ei) => { - console.log( - `Received a new blockheader: ${ei.blockNumber} ${ei.blockHash}`, - ); - provider.update(ei.blockNumber, ei.blockHash); - }); - - this.provider = provider; - this.booted = true; - } - } - protected syncFromGenesis(): Promise { return Promise.resolve([]); }