Skip to content

Commit

Permalink
remove test net temp code
Browse files Browse the repository at this point in the history
merge conflicts

remove tor
  • Loading branch information
SWvheerden committed Feb 2, 2021
1 parent 70e2659 commit 68003c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 75 deletions.
39 changes: 7 additions & 32 deletions applications/tari_console_wallet/src/init/mod.rs
Expand Up @@ -130,12 +130,11 @@ fn prompt_password(prompt: &str) -> Result<String, ExitCodes> {
/// Allows the user to change the password of the wallet.
pub async fn change_password(
config: &GlobalConfig,
node_identity: Option<Arc<NodeIdentity>>,
arg_password: Option<String>,
shutdown_signal: ShutdownSignal,
) -> Result<(), ExitCodes>
{
let mut wallet = init_wallet(config, node_identity, arg_password, None, shutdown_signal).await?;
let mut wallet = init_wallet(config, arg_password, None, shutdown_signal).await?;

let passphrase = prompt_password("New wallet password: ")?;
let confirmed = prompt_password("Confirm new password: ")?;
Expand Down Expand Up @@ -213,7 +212,6 @@ pub fn wallet_mode(bootstrap: ConfigBootstrap, boot_mode: WalletBoot) -> WalletM
/// Setup the app environment and state for use by the UI
pub async fn init_wallet(
config: &GlobalConfig,
node_identity: Option<Arc<NodeIdentity>>,
arg_password: Option<String>,
master_key: Option<PrivateKey>,
shutdown_signal: ShutdownSignal,
Expand Down Expand Up @@ -259,15 +257,6 @@ pub async fn init_wallet(
target: LOG_TARGET,
"Databases Initialized. Wallet encrypted? {}.", wallet_encrypted
);
// TODO remove after next TestNet
// If we know node_identity is not passed in anymore we dont have to check if we need to write it to db. This
// assumes that if its passed in we need to still save it the database.
if let Some(mut id_arc) = node_identity {
let v = (*Arc::make_mut(&mut id_arc)).clone();
wallet_backend
.write(WriteOperation::Insert(DbKeyValuePair::Identity(Box::new(v))))
.map_err(|e| ExitCodes::WalletError(format!("Error creating Wallet database backends. {}", e)))?;
}
let node_identity = match wallet_backend
.fetch(&DbKey::Identity)
.map_err(|e| ExitCodes::WalletError(format!("Error creating Wallet database backends. {}", e)))?
Expand All @@ -294,26 +283,12 @@ pub async fn init_wallet(
let transport_type = setup_wallet_transport_type(&config);
let transport_type = match transport_type {
Tor(mut tor_config) => {
tor_config.identity = match tor_config.identity {
Some(v) => {
// This is temp code and should be removed after testnet
wallet_backend
.write(WriteOperation::Insert(DbKeyValuePair::TorId((*v).clone())))
.map_err(|e| {
ExitCodes::WalletError(format!("Error creating Wallet database backends. {}", e))
})?;
std::fs::remove_file(&config.console_wallet_tor_identity_file)
.map_err(|e| ExitCodes::WalletError(format!("Could not delete identity file {}", e)))?;
Some(v)
},
_ => {
match wallet_backend.fetch(&DbKey::TorId).map_err(|e| {
ExitCodes::WalletError(format!("Error creating Wallet database backends. {}", e))
})? {
Some(DbValue::TorId(v)) => Some(Box::new(v)),
_ => None,
}
},
tor_config.identity = match wallet_backend
.fetch(&DbKey::TorId)
.map_err(|e| ExitCodes::WalletError(format!("Error creating Wallet database backends. {}", e)))?
{
Some(DbValue::TorId(v)) => Some(Box::new(v)),
_ => None,
};
Tor(tor_config)
},
Expand Down
50 changes: 7 additions & 43 deletions applications/tari_console_wallet/src/main.rs
Expand Up @@ -18,13 +18,8 @@ use init::{
};
use log::*;
use recovery::prompt_private_key_from_seed_words;
use tari_app_utilities::{
identity_management::setup_node_identity,
initialization::init_configuration,
utilities::ExitCodes,
};
use tari_app_utilities::{initialization::init_configuration, utilities::ExitCodes};
use tari_common::configuration::bootstrap::ApplicationType;
use tari_comms::peer_manager::PeerFeatures;
use tari_shutdown::Shutdown;
use wallet_modes::{command_mode, grpc_mode, recovery_mode, script_mode, tui_mode, WalletMode};

Expand Down Expand Up @@ -78,54 +73,23 @@ fn main_inner() -> Result<(), ExitCodes> {
None
};

let id_exists = config.console_wallet_identity_file.exists();
let create_id = !id_exists || bootstrap.create_id;

// Load or create the Node identity
// TODO remove after test net
// If we know wallets dont have a node_id file anymore, we dont have to check to see if we can load one.
let node_identity = match setup_node_identity(
&config.console_wallet_identity_file,
&config.public_address,
create_id,
PeerFeatures::COMMUNICATION_CLIENT,
) {
Ok(v) => Some(v),
_ => None,
};

if node_identity.is_none() {
warn!(
target: LOG_TARGET,
"Wallet has no identity, new wallet identity will be created"
);
if bootstrap.init {
info!(target: LOG_TARGET, "Default configuration created. Done.");
}

if node_identity.is_some() {
// This is for wallets that still have a file with the password in it, we need to remove the file to protect the
// sensitive tari_comms private key
// TODO remove after test net
// If we know files dont exist anymore we dont have to check for a file and delete a file
std::fs::remove_file(&config.console_wallet_identity_file)
.map_err(|e| ExitCodes::WalletError(format!("Could not delete identity file {}", e)))?;
}
// get command line password if provided
let arg_password = bootstrap.password.clone();

let mut shutdown = Shutdown::new();
let shutdown_signal = shutdown.to_signal();

if bootstrap.change_password {
info!(target: LOG_TARGET, "Change password requested.");
return runtime.block_on(change_password(&config, node_identity, arg_password, shutdown_signal));
return runtime.block_on(change_password(&config, arg_password, shutdown_signal));
}

// initialize wallet
let mut wallet = runtime.block_on(init_wallet(
&config,
node_identity,
arg_password,
master_key,
shutdown_signal,
))?;
let mut wallet = runtime.block_on(init_wallet(&config, arg_password, master_key, shutdown_signal))?;

// get base node/s
let base_node_config = runtime.block_on(get_base_node_peer_config(&config, &mut wallet))?;
Expand Down

0 comments on commit 68003c5

Please sign in to comment.