import { ChainConfig , createIChainForkConfig , createIChainConfig , IChainForkConfig , IChainConfig , parsePartialIChainConfigJson , } from "@chainsafe/lodestar-config" ; import { writeFile , readFile } from "../util" ; import { getNetworkBeaconParams , NetworkName } from "../networks" ; import { getGlobalPaths , IGlobalPaths } from "../paths/global" ; import { IBeaconParamsUnparsed } from "./types" ; import { parseBeaconParamsArgs , parseTerminalPowArgs , ITerminalPowArgs } from "../options" ; type IBeaconParamsCliArgs = { network ? : NetworkName ; paramsFile : string ; } & Partial < IGlobalPaths > ; interface IBeaconParamsArgs { network ? : NetworkName ; paramsFile ? : string ; additionalParamsCli : IBeaconParamsUnparsed ; } see getBeaconConfig export function getBeaconConfigFromArgs ( args ) { return createIChainForkConfig ( getBeaconParamsFromArgs ( args ) ) ; } see getBeaconParams export function getBeaconParamsFromArgs ( args ) { return getBeaconParams ( { network : args . network , paramsFile : getGlobalPaths ( args ) . paramsFile , additionalParamsCli : { ... parseBeaconParamsArgs ( args as Record < string , string | number > ) , ... parseTerminalPowArgs ( args as ITerminalPowArgs ) , } , } ) ; } see getBeaconParams export function getBeaconConfig ( args ) { return createIChainForkConfig ( getBeaconParams ( args ) ) ; } /**
 * Computes merged IBeaconParams type from (in order)
 * - Network params (diff)
 * - existing params file
 * - CLI flags
 */ export function getBeaconParams ( { network , paramsFile , additionalParamsCli } ) { const networkParams = network ? getNetworkBeaconParams ( network ) : { } ; const fileParams = paramsFile ? parsePartialIChainConfigJson ( readBeaconParams ( paramsFile ) ) : { } ; const cliParams = parsePartialIChainConfigJson ( additionalParamsCli ) ; return createIChainConfig ( { ... networkParams , ... fileParams , ... cliParams , } ) ; } export function writeBeaconParams ( filepath , params ) { writeFile ( filepath , ChainConfig . toJson ( params ) ) ; } function readBeaconParams ( filepath ) { return readFile ( filepath ) ?? { } ; }