diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index e349d9e..955d9cd 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,11 +1,11 @@ { - "name": "@lumeweb/libethclient", + "name": "@lumeweb/libethsync", "version": "0.1.0-develop.41", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@lumeweb/libethclient", + "name": "@lumeweb/libethsync", "version": "0.1.0-develop.41", "dependencies": { "@chainsafe/as-sha256": "^0.3.1", @@ -28,6 +28,7 @@ "axios-retry": "^3.5.1", "detect-node": "^2.1.0", "ethereum-cryptography": "^2.0.0", + "events": "^3.3.0", "node-cache": "^5.1.2", "rlp": "^3.0.0", "web3-types": "^1.0.1" @@ -8734,7 +8735,6 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", - "dev": true, "engines": { "node": ">=0.8.x" } diff --git a/package.json b/package.json index 5e17853..3c8f49e 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "axios-retry": "^3.5.1", "detect-node": "^2.1.0", "ethereum-cryptography": "^2.0.0", + "events": "^3.3.0", "node-cache": "^5.1.2", "rlp": "^3.0.0", "web3-types": "^1.0.1" diff --git a/src/baseClient.ts b/src/baseClient.ts index 55d8abf..9df5c00 100644 --- a/src/baseClient.ts +++ b/src/baseClient.ts @@ -20,6 +20,7 @@ import { } from "#types.js"; import { assertValidLightClientUpdate } from "@lodestar/light-client/validation"; import * as capella from "@lodestar/types/capella"; +import { EventEmitter } from "events"; export interface BaseClientOptions { prover: IProver; @@ -30,7 +31,7 @@ export interface BaseClientOptions { loggerErr: (...any) => void; } -export default abstract class BaseClient { +export default abstract class BaseClient extends EventEmitter { protected latestCommittee?: Uint8Array[]; protected latestBlockHash?: string; protected config: ClientConfig = getDefaultClientConfig(); @@ -45,6 +46,7 @@ export default abstract class BaseClient { private optimisticMutex = new Mutex(); constructor(options: BaseClientOptions) { + super(); this.options = options; } @@ -143,6 +145,8 @@ export default abstract class BaseClient { startCommittee = validOrCommittee as Uint8Array[]; + this.emit("update", update); + if (this.options.syncDelay) { await new Promise((resolve) => setTimeout(resolve, this.options.syncDelay),