nimbus-eth2/beacon_chain/conf.nim

105 lines
2.8 KiB
Nim
Raw Normal View History

import
os, options,
confutils/defs, chronicles/options as chroniclesOptions,
json_serialization,
spec/[crypto, datatypes], time
export
json_serialization
type
ValidatorKeyPath* = distinct string
StartUpCommand* = enum
noCommand
createChain
2018-11-29 01:08:34 +00:00
BeaconNodeConf* = object
logLevel* {.
desc: "Sets the log level",
defaultValue: enabledLogLevel
.}: LogLevel
case cmd* {.
command
defaultValue: noCommand.}: StartUpCommand
of noCommand:
dataDir* {.
desc: "The directory where nimbus will store all blockchain data."
shortform: "d"
defaultValue: getConfigDir() / "nimbus".}: DirPath
bootstrapNodes* {.
desc: "Specifies one or more bootstrap nodes to use when connecting to the network."
longform: "bootstrapNode"
shortform: "b".}: seq[string]
bootstrapNodesFile* {.
desc: "Specifies a line-delimited file of bootsrap Ethereum network addresses"
shortform: "f"
defaultValue: "".}: FilePath
tcpPort* {.
desc: "TCP listening port".}: int
udpPort* {.
desc: "UDP listening port".}: int
validators* {.
required
desc: "Path to a validator private key, as generated by validator_keygen"
longform: "validator"
shortform: "v".}: seq[ValidatorPrivKey]
stateSnapshot* {.
desc: "Json file specifying a recent state snapshot"
shortform: "s".}: Option[BeaconState]
of createChain:
validatorsDir* {.
desc: "Directory containing validator descriptors named vXXXXXXX.deposit.json"
shortform: "d".}: DirPath
numValidators* {.
desc: ""
shortform: "n".}: int
firstValidator* {.
desc: "index of first validator to add to validator list"
shortform: "o"
defaultValue: 0.}: int
genesisOffset* {.
desc: "Seconds from now to add to genesis time"
shortForm: "g"
defaultValue: 5 .}: int
outputStateFile* {.
desc: "Output file where to write the initial state snapshot"
longform: "out"
shortform: "o".}: OutFilePath
2018-12-09 08:25:02 +00:00
proc readFileBytes(path: string): seq[byte] =
cast[seq[byte]](readFile(path))
2018-12-05 13:58:41 +00:00
proc loadPrivKey*(p: ValidatorKeyPath): ValidatorPrivKey =
ValidatorPrivKey.init(readFileBytes(string(p) & ".privkey"))
2018-12-05 13:58:41 +00:00
proc parseCmdArg*(T: type ValidatorKeyPath, input: TaintedString): T =
2018-12-08 14:17:47 +00:00
result = T(input)
discard loadPrivKey(result)
2018-11-29 01:08:34 +00:00
template mustBeFilePath(input: TaintedString) =
if not fileExists(string input):
raise newException(ValueError, "")
template handledAsJsonFilename(T: untyped) {.dirty.} =
proc parseCmdArg*(_: type T, input: TaintedString): T =
input.mustBeFilePath
return Json.loadFile(string(input), T)
handledAsJsonFilename BeaconState
handledAsJsonFilename Deposit
handledAsJsonFilename ValidatorPrivKey