diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim index f2f9f8833..2abc8e9f1 100644 --- a/beacon_chain/conf.nim +++ b/beacon_chain/conf.nim @@ -45,7 +45,7 @@ type list = "Lists details about all wallets" DepositsCmd* {.pure.} = enum - # create = "Creates validator keystores and deposits" + create = "Creates validator keystores and deposits" `import` = "Imports password-protected keystores interactively" # status = "Displays status information about all deposits" exit = "Submits a validator voluntary exit" @@ -378,7 +378,6 @@ type of deposits: case depositsCmd* {.command.}: DepositsCmd - #[ of DepositsCmd.create: totalDeposits* {. defaultValue: 1 @@ -411,9 +410,10 @@ type desc: "Output wallet file" name: "new-wallet-file" }: Option[OutFile] + #[ of DepositsCmd.status: discard - #]# + ]# of DepositsCmd.`import`: importedDepositsDir* {. @@ -653,11 +653,9 @@ func outWalletName*(config: BeaconNodeConf): Option[WalletName] = of WalletsCmd.restore: config.restoredWalletNameFlag of WalletsCmd.list: fail() of deposits: - # TODO: Uncomment when the deposits create command is restored - #case config.depositsCmd - #of DepositsCmd.create: config.newWalletNameFlag - #else: fail() - fail() + case config.depositsCmd + of DepositsCmd.create: config.newWalletNameFlag + else: fail() else: fail() @@ -672,11 +670,9 @@ func outWalletFile*(config: BeaconNodeConf): Option[OutFile] = of WalletsCmd.restore: config.restoredWalletFileFlag of WalletsCmd.list: fail() of deposits: - # TODO: Uncomment when the deposits create command is restored - #case config.depositsCmd - #of DepositsCmd.create: config.newWalletFileFlag - #else: fail() - fail() + case config.depositsCmd + of DepositsCmd.create: config.newWalletFileFlag + else: fail() else: fail() diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index b1641e308..6c812feac 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -1740,11 +1740,19 @@ proc doCreateTestnet(config: BeaconNodeConf, rng: var BrHmacDrbgContext) {.raise writeFile(bootstrapFile, bootstrapEnr.tryGet().toURI) echo "Wrote ", bootstrapFile +proc findWalletWithoutErrors(config: BeaconNodeConf, + name: WalletName): Option[WalletPathPair] = + let res = findWallet(config, name) + if res.isErr: + fatal "Failed to locate wallet", error = res.error + quit 1 + res.get + proc doDeposits(config: BeaconNodeConf, rng: var BrHmacDrbgContext) {. raises: [Defect, CatchableError].} = case config.depositsCmd - #[ of DepositsCmd.create: + let metadata = config.loadEth2Network() var seed: KeySeed defer: burnMem(seed) var walletPath: WalletPathPair @@ -1752,7 +1760,7 @@ proc doDeposits(config: BeaconNodeConf, rng: var BrHmacDrbgContext) {. if config.existingWalletId.isSome: let id = config.existingWalletId.get - found = findWalletWithoutErrors(id) + found = findWalletWithoutErrors(config, id) if found.isSome: walletPath = found.get @@ -1767,7 +1775,7 @@ proc doDeposits(config: BeaconNodeConf, rng: var BrHmacDrbgContext) {. # The failure will be reported in `unlockWalletInteractively`. quit 1 else: - var walletRes = createWalletInteractively(rng[], config) + var walletRes = createWalletInteractively(rng, config) if walletRes.isErr: fatal "Unable to create wallet", err = walletRes.error quit 1 @@ -1786,8 +1794,8 @@ proc doDeposits(config: BeaconNodeConf, rng: var BrHmacDrbgContext) {. quit QuitFailure let deposits = generateDeposits( - runtimePreset, - rng[], + metadata.runtimePreset, + rng, seed, walletPath.wallet.nextAccount, config.totalDeposits, @@ -1805,7 +1813,7 @@ proc doDeposits(config: BeaconNodeConf, rng: var BrHmacDrbgContext) {. config.outValidatorsDir / "deposit_data-" & $epochTime() & ".json" let launchPadDeposits = - mapIt(deposits.value, LaunchPadDeposit.init(runtimePreset, it)) + mapIt(deposits.value, LaunchPadDeposit.init(metadata.runtimePreset, it)) Json.saveFile(depositDataPath, launchPadDeposits) echo "Deposit data written to \"", depositDataPath, "\"" @@ -1820,12 +1828,12 @@ proc doDeposits(config: BeaconNodeConf, rng: var BrHmacDrbgContext) {. except CatchableError as err: fatal "Failed to create launchpad deposit data file", err = err.msg quit 1 - + #[ of DepositsCmd.status: echo "The status command is not implemented yet" quit 1 + ]# - #]# of DepositsCmd.`import`: let validatorKeysDir = if config.importedDepositsDir.isSome: config.importedDepositsDir.get @@ -1850,19 +1858,12 @@ proc doDeposits(config: BeaconNodeConf, rng: var BrHmacDrbgContext) {. proc doWallets(config: BeaconNodeConf, rng: var BrHmacDrbgContext) {. raises: [Defect, CatchableError].} = - template findWalletWithoutErrors(name: WalletName): auto = - let res = keystore_management.findWallet(config, name) - if res.isErr: - fatal "Failed to locate wallet", error = res.error - quit 1 - res.get - case config.walletsCmd: of WalletsCmd.create: if config.createdWalletNameFlag.isSome: let name = config.createdWalletNameFlag.get - existingWallet = findWalletWithoutErrors(name) + existingWallet = findWalletWithoutErrors(config, name) if existingWallet.isSome: echo "The Wallet '" & name.string & "' already exists." quit 1