2024-02-18 01:16:49 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
2022-02-11 20:40:49 +00:00
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2023-01-20 14:14:37 +00:00
|
|
|
{.push raises: [].}
|
2022-02-11 20:40:49 +00:00
|
|
|
|
|
|
|
import
|
|
|
|
std/os,
|
|
|
|
./validators/keystore_management,
|
|
|
|
./conf
|
|
|
|
|
2022-06-21 08:29:16 +00:00
|
|
|
proc doWallets*(config: BeaconNodeConf, rng: var HmacDrbgContext) {.
|
2023-08-25 09:29:07 +00:00
|
|
|
raises: [CatchableError].} =
|
2022-02-11 20:40:49 +00:00
|
|
|
case config.walletsCmd:
|
|
|
|
of WalletsCmd.create:
|
|
|
|
if config.createdWalletNameFlag.isSome:
|
|
|
|
let
|
|
|
|
name = config.createdWalletNameFlag.get
|
|
|
|
existingWallet = findWallet(config, name).valueOr:
|
|
|
|
fatal "Failed to locate wallet", error = error
|
|
|
|
quit 1
|
|
|
|
if existingWallet.isSome:
|
|
|
|
echo "The Wallet '" & name.string & "' already exists."
|
|
|
|
quit 1
|
|
|
|
|
|
|
|
var wallet = createWalletInteractively(rng, config).valueOr:
|
|
|
|
fatal "Unable to create wallet", err = error
|
|
|
|
quit 1
|
|
|
|
burnMem(wallet.seed)
|
|
|
|
|
|
|
|
of WalletsCmd.list:
|
|
|
|
for kind, walletFile in walkDir(config.walletsDir):
|
|
|
|
if kind != pcFile: continue
|
|
|
|
if checkSensitiveFilePermissions(walletFile):
|
|
|
|
let walletRes = loadWallet(walletFile)
|
|
|
|
if walletRes.isOk:
|
|
|
|
echo walletRes.get.longName
|
|
|
|
else:
|
|
|
|
warn "Found corrupt wallet file",
|
|
|
|
wallet = walletFile, error = walletRes.error
|
|
|
|
else:
|
|
|
|
warn "Found wallet file with insecure permissions",
|
|
|
|
wallet = walletFile
|
|
|
|
|
|
|
|
of WalletsCmd.restore:
|
|
|
|
restoreWalletInteractively(rng, config)
|