From a901ee76f4703d6e7f4793e96cfe173037f2103f Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 14 Jul 2023 11:16:38 -0400 Subject: [PATCH] feat: add loggerInfo and loggerErr callbacks to client options --- src/baseClient.ts | 8 ++++++-- src/client/client.ts | 2 +- src/client/index.ts | 4 ++++ src/node/index.ts | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/baseClient.ts b/src/baseClient.ts index 4d3b6ef..5266034 100644 --- a/src/baseClient.ts +++ b/src/baseClient.ts @@ -26,6 +26,8 @@ export interface BaseClientOptions { store: IStore; optimisticUpdateCallback: OptimisticUpdateCallback; syncDelay?: number; + loggerInfo: (...any) => void; + loggerErr: (...any) => void; } export default abstract class BaseClient { @@ -131,7 +133,9 @@ export default abstract class BaseClient { ); if (!(validOrCommittee as boolean)) { - console.log(`Found invalid update at period(${curPeriod})`); + this.options.loggerInfo( + `Found invalid update at period(${curPeriod})`, + ); return { syncCommittee: startCommittee, period: curPeriod, @@ -239,7 +243,7 @@ export default abstract class BaseClient { this._latestOptimisticUpdate = capella.ssz.LightClientOptimisticUpdate.serialize(update); - console.log( + this.options.loggerInfo( `Optimistic update verified for slot ${update.attestedHeader.beacon.slot}`, ); diff --git a/src/client/client.ts b/src/client/client.ts index 44df736..8c191c4 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -29,7 +29,7 @@ export default class Client extends BaseClient { blockHash, ); this.subscribe((ei) => { - console.log( + this.options.loggerInfo( `Received a new blockheader: ${ei.blockNumber} ${ei.blockHash}`, ); provider.update(ei.blockNumber, ei.blockHash); diff --git a/src/client/index.ts b/src/client/index.ts index b950081..9950aba 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -9,6 +9,8 @@ function createDefaultClient( proverHandler: ProverRequestCallback, rpcHandler: Function, optimisticUpdateHandler: OptimisticUpdateCallback, + loggerInfo: (...any) => void, + loggerErr: (...any) => void, ): Client { return new Client({ prover: new Prover(proverHandler), @@ -16,6 +18,8 @@ function createDefaultClient( provider: VerifyingProvider, rpcHandler, optimisticUpdateCallback: optimisticUpdateHandler, + loggerInfo, + loggerErr, }); } diff --git a/src/node/index.ts b/src/node/index.ts index 33f926e..94835e7 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -20,6 +20,8 @@ function createDefaultClient(beaconUrl: string): Client { return capella.ssz.LightClientOptimisticUpdate.fromJson(update); }, + loggerInfo: console.log, + loggerErr: console.error, }; const client = new Client(options);