Skip to content

Commit

Permalink
feat: base_node prompt user to create id if not found (#3245)
Browse files Browse the repository at this point in the history
Description
Prompt user to create id if not found

Motivation and Context
Improvement to base node startup, specifically on first run.

How Has This Been Tested?
Manually
  • Loading branch information
StriderDM authored Aug 27, 2021
1 parent dc0955c commit 6391941
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
29 changes: 18 additions & 11 deletions applications/tari_app_utilities/src/identity_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ use crate::utilities::ExitCodes;
use log::*;
use rand::rngs::OsRng;
use std::{clone::Clone, fs, path::Path, string::ToString, sync::Arc};
use tari_common::configuration::bootstrap::prompt;
use tari_comms::{multiaddr::Multiaddr, peer_manager::PeerFeatures, NodeIdentity};
use tari_core::transactions::types::PrivateKey;
use tari_crypto::{
keys::SecretKey,
tari_utilities::{hex::Hex, message_format::MessageFormat},
};

pub const LOG_TARGET: &str = "tari_application";

/// Loads the node identity, or creates a new one if the --create-id flag was specified
Expand All @@ -51,17 +53,22 @@ pub fn setup_node_identity<P: AsRef<Path>>(
Ok(id) => Ok(Arc::new(id)),
Err(e) => {
if !create_id {
error!(
target: LOG_TARGET,
"Node identity information not found. {}. You can update the configuration file to point to a \
valid node identity file, or re-run the node with the --create-id flag to create a new identity.",
e
);
return Err(ExitCodes::ConfigError(format!(
"Node identity information not found. {}. You can update the configuration file to point to a \
valid node identity file, or re-run the node with the --create-id flag to create a new identity.",
e
)));
let prompt = prompt("Node identity does not exist.\nWould you like to to create one (Y/n)?");
if !prompt {
error!(
target: LOG_TARGET,
"Node identity information not found. {}. You can update the configuration file to point to a \
valid node identity file, or re-run the node with the --create-id flag to create a new \
identity.",
e
);
return Err(ExitCodes::ConfigError(format!(
"Node identity information not found. {}. You can update the configuration file to point to a \
valid node identity file, or re-run the node with the --create-id flag to create a new \
identity.",
e
)));
};
}

debug!(target: LOG_TARGET, "Node id not found. {}. Creating new ID", e);
Expand Down
2 changes: 1 addition & 1 deletion common/src/configuration/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl ConfigBootstrap {
}
}

fn prompt(question: &str) -> bool {
pub fn prompt(question: &str) -> bool {
println!("{}", question);
let mut input = "".to_string();
io::stdin().read_line(&mut input).unwrap();
Expand Down

0 comments on commit 6391941

Please sign in to comment.