-
-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {getClient} from "@chainsafe/lodestar-api"; | ||
import {Lightclient} from "@chainsafe/lodestar-light-client"; | ||
import {fromHexString} from "@chainsafe/ssz"; | ||
import {getBeaconConfigFromArgs} from "../../config/beaconParams"; | ||
import {IGlobalArgs} from "../../options"; | ||
import {getCliLogger, initBLS} from "../../util"; | ||
import {getBeaconPaths} from "../beacon/paths"; | ||
import {ILightClientArgs} from "./options"; | ||
|
||
export async function lightclientHandler(args: ILightClientArgs & IGlobalArgs): Promise<void> { | ||
await initBLS(); | ||
|
||
const config = getBeaconConfigFromArgs(args); | ||
const beaconPaths = getBeaconPaths(args); | ||
const logger = getCliLogger(args, beaconPaths, config); | ||
const {beaconApiUrl, checkpointRoot} = args; | ||
const api = getClient({baseUrl: beaconApiUrl}, {config}); | ||
const {data: genesisData} = await api.beacon.getGenesis(); | ||
|
||
const client = await Lightclient.initializeFromCheckpointRoot({ | ||
config, | ||
logger, | ||
beaconApiUrl, | ||
genesisData: { | ||
genesisTime: Number(genesisData.genesisTime), | ||
genesisValidatorsRoot: genesisData.genesisValidatorsRoot, | ||
}, | ||
checkpointRoot: fromHexString(checkpointRoot), | ||
}); | ||
|
||
client.start(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {ICliCommand} from "../../util"; | ||
import {IGlobalArgs} from "../../options"; | ||
import {ILightClientArgs, lightclientOptions} from "./options"; | ||
import {lightclientHandler} from "./handler"; | ||
|
||
export const lightclient: ICliCommand<ILightClientArgs, IGlobalArgs> = { | ||
command: "lightclient", | ||
describe: "Run lightclient", | ||
examples: [ | ||
{ | ||
command: "lightclient --network prater", | ||
description: "Run lightclient with prater network", | ||
}, | ||
], | ||
options: lightclientOptions, | ||
handler: lightclientHandler, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {ICliCommandOptions, ILogArgs} from "../../util"; | ||
import {beaconPathsOptions, logOptions} from "../beacon/options"; | ||
import {IBeaconPaths} from "../beacon/paths"; | ||
|
||
export type ILightClientArgs = ILogArgs & { | ||
logFile: IBeaconPaths["logFile"]; | ||
beaconApiUrl: string; | ||
checkpointRoot: string; | ||
}; | ||
|
||
export const lightclientOptions: ICliCommandOptions<ILightClientArgs> = { | ||
...logOptions, | ||
logFile: beaconPathsOptions.logFile, | ||
beaconApiUrl: { | ||
description: "Url to a beacon node that support lightclient API", | ||
type: "string", | ||
require: true, | ||
}, | ||
checkpointRoot: { | ||
description: "Checkpoint root hex string to sync the lightclient from, start with 0x", | ||
type: "string", | ||
require: true, | ||
}, | ||
}; |