feat: add getter for provider
This commit is contained in:
parent
9ef95b339e
commit
b85e1779ee
|
@ -21,13 +21,41 @@ interface Config extends BaseClientOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Client extends BaseClient {
|
export default class Client extends BaseClient {
|
||||||
private provider?: IVerifyingProvider;
|
|
||||||
protected declare options: Config;
|
protected declare options: Config;
|
||||||
|
|
||||||
constructor(options: Config) {
|
constructor(options: Config) {
|
||||||
super(options);
|
super(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _provider?: IVerifyingProvider;
|
||||||
|
|
||||||
|
get provider(): IVerifyingProvider {
|
||||||
|
return this._provider as IVerifyingProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
async sync(): Promise<void> {
|
||||||
|
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<ExecutionInfo | null> {
|
protected async getLatestExecution(): Promise<ExecutionInfo | null> {
|
||||||
const updateJSON = await this.options.prover.callback(
|
const updateJSON = await this.options.prover.callback(
|
||||||
"consensus_optimistic_update",
|
"consensus_optimistic_update",
|
||||||
|
@ -50,29 +78,6 @@ export default class Client extends BaseClient {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async sync(): Promise<void> {
|
|
||||||
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<Uint8Array[]> {
|
protected syncFromGenesis(): Promise<Uint8Array[]> {
|
||||||
return Promise.resolve([]);
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue