import { Options } from "yargs" ; import { IBeaconParamsUnparsed } from "../config/types" ; import { ObjectKeys , ICliCommandOptions } from "../util" ; import { ChainConfig , IChainConfig } from "@chainsafe/lodestar-config" ; export type ITerminalPowArgs = { "terminal-total-difficulty-override" ? : string ; "terminal-block-hash-override" ? : string ; "terminal-block-hash-epoch-override" ? : string ; } ; export type IParamsArgs = Record < never , never > & ITerminalPowArgs ; const getArgKey = ( key ) : string => `params.${ key }` ; export function parseBeaconParamsArgs ( args ) { return ( ( ObjectKeys ( ChainConfig . fields ) as unknown ) as ( keyof IChainConfig ) [ ] ) . reduce ( ( beaconParams , key ) => { const value = args [ getArgKey ( key ) ] ; if ( value != null ) beaconParams [ key ] = value ; return beaconParams ; } , { } ) ; } const paramsOptionsByName = ( ( ObjectKeys ( ChainConfig . fields ) as unknown ) as ( keyof IChainConfig ) [ ] ) . reduce ( ( options , key ) : Record < string , Options > => ( { ... options , [ getArgKey ( key ) ] : { hidden : true , type : "string" , group : "params" , } , } ) , { } ) ; const terminalArgsToParamsMap = { "terminal-total-difficulty-override" : "TERMINAL_TOTAL_DIFFICULTY" , "terminal-block-hash-override" : "TERMINAL_BLOCK_HASH" , "terminal-block-hash-epoch-override" : "TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH" , } ; export function parseTerminalPowArgs ( args ) { const parsedArgs = ObjectKeys ( terminalArgsToParamsMap ) . reduce ( ( beaconParams , key ) => { const paramOption = terminalArgsToParamsMap [ key ] ; const value = args [ key ] ; if ( paramOption != null && value != null ) beaconParams [ paramOption ] = value ; return beaconParams ; } , { } ) ; return parsedArgs ; } export const paramsOptions = { ... paramsOptionsByName , "terminal-total-difficulty-override" : { description : "Terminal PoW block TTD override" , type : "string" , } , "terminal-block-hash-override" : { description : "Terminal PoW block hash override" , type : "string" , } , "terminal-block-hash-epoch-override" : { description : "Terminal PoW block hash override activation epoch" , type : "string" , } , } ;