Skip to content

Commit

Permalink
feat: allow to configure api client when initializing light client (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig authored and philknows committed Oct 18, 2024
1 parent e6662fa commit 06f4d85
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/light-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import {

const config = getChainForkConfigFromNetwork("sepolia");
const logger = getConsoleLogger({logDebug: Boolean(process.env.DEBUG)});
const api = getApiFromUrl({urls: ["https://lodestar-sepolia.chainsafe.io"]}, {config});
const api = getApiFromUrl("https://lodestar-sepolia.chainsafe.io", "sepolia");

const lightclient = await Lightclient.initializeFromCheckpointRoot({
config,
Expand All @@ -82,11 +82,11 @@ await lightclient.start();
logger.info("Lightclient synced");

lightclient.emitter.on(LightclientEvent.lightClientFinalityHeader, async (finalityUpdate) => {
logger.info(finalityUpdate);
logger.info("Received finality update", {slot: finalityUpdate.beacon.slot});
});

lightclient.emitter.on(LightclientEvent.lightClientOptimisticHeader, async (optimisticUpdate) => {
logger.info(optimisticUpdate);
logger.info("Received optimistic update", {slot: optimisticUpdate.beacon.slot});
});
```

Expand Down
6 changes: 3 additions & 3 deletions packages/light-client/src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {getClient, ApiClient} from "@lodestar/api";
import {getClient, ApiClient, ApiRequestInit} from "@lodestar/api";
import {ChainForkConfig, createChainForkConfig} from "@lodestar/config";
import {NetworkName, networksChainConfig} from "@lodestar/config/networks";

export function getApiFromUrl(url: string, network: NetworkName): ApiClient {
export function getApiFromUrl(url: string, network: NetworkName, init?: ApiRequestInit): ApiClient {
if (!(network in networksChainConfig)) {
throw Error(`Invalid network name "${network}". Valid options are: ${Object.keys(networksChainConfig).join()}`);
}

return getClient({urls: [url]}, {config: createChainForkConfig(networksChainConfig[network])});
return getClient({urls: [url], globalInit: init}, {config: createChainForkConfig(networksChainConfig[network])});
}

export function getChainForkConfigFromNetwork(network: NetworkName): ChainForkConfig {
Expand Down

0 comments on commit 06f4d85

Please sign in to comment.