Add --initialize command

The --initialize command initialises the data folder, if it is not already
initialised. It creates a ledger file and adds the genesis block.
This commit is contained in:
Dimitrios Siganos 2021-09-21 21:16:51 +01:00
commit fc239a8808
No known key found for this signature in database
GPG key ID: 403759C8B5ED69FF
2 changed files with 58 additions and 1 deletions

View file

@ -44,6 +44,7 @@ void nano::add_node_options (boost::program_options::options_description & descr
{
// clang-format off
description_a.add_options ()
("initialize", "Initialize the data folder, if it is not already initialised. This command is meant to be run when the data folder is empty, to populate it with the genesis block.")
("account_create", "Insert next deterministic key in to <wallet>")
("account_get", "Get account number for the <key>")
("account_key", "Get the public key for <account>")
@ -262,7 +263,14 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
std::error_code ec;
boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as<std::string> ()) : nano::working_path ();
if (vm.count ("account_create"))
if (vm.count ("initialize"))
{
auto node_flags = nano::inactive_node_flag_defaults ();
node_flags.read_only = false;
nano::update_flags (node_flags, vm);
nano::inactive_node node (data_path, node_flags);
}
else if (vm.count ("account_create"))
{
if (vm.count ("wallet") == 1)
{

49
systest/node_initialize.sh Executable file
View file

@ -0,0 +1,49 @@
#!/bin/sh
set -e
DATADIR=data.systest
# the caller should set the env var NANO_NODE_EXE to point to the nano_node executable
# if NANO_NODE_EXE is unser ot empty then "../../build/nano_node" is used
NANO_NODE_EXE=${NANO_NODE_EXE:-../../build/nano_node}
clean_data_dir() {
rm -f "$DATADIR"/log/log_*.log
rm -f "$DATADIR"/wallets.ldb*
rm -f "$DATADIR"/data.ldb*
rm -f "$DATADIR"/config-*.toml
}
test_initialize_cmd() {
netmatch="$1"
netcmd="$2"
netarg="$3"
genesishash="$4"
clean_data_dir
# initialise data directory
$NANO_NODE_EXE --initialize --data_path "$DATADIR" "$netcmd" "$netarg"
# check that it is the live network
grep -q "Active network: $netmatch" "$DATADIR"/log/log_*.log
# check that the ledger file is created
test -e "$DATADIR/data.ldb"
$NANO_NODE_EXE --debug_block_count --data_path "$DATADIR" "$netcmd" "$netarg" | grep -q 'Block count: 1'
# check the genesis block is correct
$NANO_NODE_EXE --debug_block_dump --data_path "$DATADIR" "$netcmd" "$netarg" | head -n 1 | grep -qi "$genesishash"
}
mkdir -p "$DATADIR/log"
test_initialize_cmd "live" "" "" "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948"
test_initialize_cmd "live" "--network" "live" "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948"
test_initialize_cmd "beta" "--network" "beta" "01A92459E69440D5C1088D3B31F4CA678BE944BAB3776C2E6B7665E9BD99BD5A"
test_initialize_cmd "test" "--network" "test" "B1D60C0B886B57401EF5A1DAA04340E53726AA6F4D706C085706F31BBD100CEE"
# if it got this far then it is a pass
echo $0: PASSED
exit 0