From 2a27a16c25d7f0f09735bbf8ba266aedc8eae290 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 11 Jul 2023 04:27:11 -0400 Subject: [PATCH] refactor: create the IClientVerifyingProvider child interface and add rpcCall to the client Client instead of exposing the provider in a getter --- src/client/client.ts | 17 +++++++++-------- src/client/verifyingProvider.ts | 6 +++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/client/client.ts b/src/client/client.ts index f0bd04d..9ebae33 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -13,10 +13,11 @@ import { optimisticUpdateVerify, } from "#util.js"; import { equalBytes } from "@noble/curves/abstract/utils.js"; +import { IClientVerifyingProvider } from "#client/verifyingProvider.js"; interface Config extends BaseClientOptions { prover: IClientProver; - provider: IVerifyingProviderConstructor; + provider: IVerifyingProviderConstructor; rpcHandler: Function; } @@ -27,16 +28,12 @@ export default class Client extends BaseClient { super(options); } - private _provider?: IVerifyingProvider; - - get provider(): IVerifyingProvider { - return this._provider as IVerifyingProvider; - } + private provider?: IClientVerifyingProvider; async sync(): Promise { await super.sync(); - if (!this._provider) { + if (!this.provider) { const { blockHash, blockNumber } = await this.getNextValidExecutionInfo(); const factory = this.options.provider; const provider = new factory( @@ -51,7 +48,7 @@ export default class Client extends BaseClient { provider.update(ei.blockNumber, ei.blockHash); }); - this._provider = provider; + this.provider = provider; this.booted = true; } } @@ -123,4 +120,8 @@ export default class Client extends BaseClient { return committee; } + + public async rpcCall(method: string, params: any) { + return this.provider?.rpcMethod(method, params); + } } diff --git a/src/client/verifyingProvider.ts b/src/client/verifyingProvider.ts index 7fd4204..8e2a086 100644 --- a/src/client/verifyingProvider.ts +++ b/src/client/verifyingProvider.ts @@ -48,7 +48,11 @@ import { keccak256 } from "ethereum-cryptography/keccak"; import { fromHexString } from "@chainsafe/ssz"; import { RPC } from "#client/rpc.js"; -export default class VerifyingProvider implements IVerifyingProvider { +export interface IClientVerifyingProvider extends IVerifyingProvider { + rpcMethod(method: string, params: any); +} + +export default class VerifyingProvider implements IClientVerifyingProvider { common: Common; vm: VM | null = null; private blockHashes: { [blockNumberHex: string]: Bytes32 } = {};