aboutsummaryrefslogtreecommitdiff
path: root/src/simplewallet/simplewallet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/simplewallet/simplewallet.cpp')
-rw-r--r--src/simplewallet/simplewallet.cpp186
1 files changed, 115 insertions, 71 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index b27113473..baa70bc0b 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -873,65 +873,79 @@ bool simple_wallet::set_log(const std::vector<std::string> &args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::ask_wallet_create_if_needed()
{
+ LOG_PRINT_L3("simple_wallet::ask_wallet_create_if_needed() started");
std::string wallet_path;
-
- bool valid_path = false;
- do {
- wallet_path = command_line::input_line(
- tr("Specify wallet file name (e.g., MyWallet). If the wallet doesn't exist, it will be created.\n"
- "Wallet file name: ")
- );
- if (std::cin.eof())
- {
- return false;
- }
- valid_path = tools::wallet2::wallet_valid_path_format(wallet_path);
- if (!valid_path)
- {
- fail_msg_writer() << tr("wallet file path not valid: ") << wallet_path;
- }
- }
- while (!valid_path);
-
+ std::string confirm_creation;
+ bool wallet_name_valid = false;
bool keys_file_exists;
bool wallet_file_exists;
- tools::wallet2::wallet_exists(wallet_path, keys_file_exists, wallet_file_exists);
- LOG_PRINT_L3("wallet_path: " << wallet_path << "");
- LOG_PRINT_L3("keys_file_exists: " << std::boolalpha << keys_file_exists << std::noboolalpha
- << " wallet_file_exists: " << std::boolalpha << wallet_file_exists << std::noboolalpha);
- LOG_PRINT_L1("Loading wallet...");
-
- // add logic to error out if new wallet requested but named wallet file exists
- if (keys_file_exists || wallet_file_exists)
- {
- if (!m_generate_new.empty() || m_restoring)
- {
- fail_msg_writer() << tr("attempting to generate or restore wallet, but specified file(s) exist. Exiting to not risk overwriting.");
- return false;
- }
- }
+ do{
+ LOG_PRINT_L3("User asked to specify wallet file name.");
+ wallet_path = command_line::input_line(
+ tr("Specify wallet file name (e.g., MyWallet). If the wallet doesn't exist, it will be created.\n"
+ "Wallet file name (or Ctrl-C to quit): ")
+ );
+ if(std::cin.eof())
+ {
+ LOG_ERROR("Unexpected std::cin.eof() - Exited simple_wallet::ask_wallet_create_if_needed()");
+ return false;
+ }
+ if(!tools::wallet2::wallet_valid_path_format(wallet_path))
+ {
+ fail_msg_writer() << tr("Wallet name not valid. Please try again or use Ctrl-C to quit.");
+ wallet_name_valid = false;
+ }
+ else
+ {
+ tools::wallet2::wallet_exists(wallet_path, keys_file_exists, wallet_file_exists);
+ LOG_PRINT_L3("wallet_path: " << wallet_path << "");
+ LOG_PRINT_L3("keys_file_exists: " << std::boolalpha << keys_file_exists << std::noboolalpha
+ << " wallet_file_exists: " << std::boolalpha << wallet_file_exists << std::noboolalpha);
- bool r;
- if(keys_file_exists)
- {
- m_wallet_file=wallet_path;
- r = true;
- }else
- {
- if(!wallet_file_exists)
- {
- std::cout << tr("The wallet doesn't exist, generating new one") << std::endl;
- m_generate_new = wallet_path;
- r = true;
- }else
- {
- fail_msg_writer() << tr("keys file not found: failed to open wallet: ") << "\"" << wallet_path << "\".";
- r = false;
- }
- }
+ if((keys_file_exists || wallet_file_exists) && (!m_generate_new.empty() || m_restoring))
+ {
+ fail_msg_writer() << tr("Attempting to generate or restore wallet, but specified file(s) exist. Exiting to not risk overwriting.");
+ return false;
+ }
+ if(wallet_file_exists && keys_file_exists) //Yes wallet, yes keys
+ {
+ success_msg_writer() << tr("Wallet and key files found, loading...");
+ m_wallet_file = wallet_path;
+ return true;
+ }
+ else if(!wallet_file_exists && keys_file_exists) //No wallet, yes keys
+ {
+ success_msg_writer() << tr("Key file found but not wallet file. Regenerating...");
+ m_wallet_file = wallet_path;
+ return true;
+ }
+ else if(wallet_file_exists && !keys_file_exists) //Yes wallet, no keys
+ {
+ fail_msg_writer() << tr("Key file not found. Failed to open wallet: ") << "\"" << wallet_path << "\". Exiting.";
+ return false;
+ }
+ else if(!wallet_file_exists && !keys_file_exists) //No wallet, no keys
+ {
+ message_writer() << tr("No wallet/key file found with that name. Confirm creation of new wallet named: ") << wallet_path;
+ confirm_creation = command_line::input_line(tr("(y)es/(n)o: "));
+ if(std::cin.eof())
+ {
+ LOG_ERROR("Unexpected std::cin.eof() - Exited simple_wallet::ask_wallet_create_if_needed()");
+ return false;
+ }
+ if(is_it_true(confirm_creation))
+ {
+ success_msg_writer() << tr("Generating new wallet...");
+ m_generate_new = wallet_path;
+ return true;
+ }
+ }
+ }
+ } while(!wallet_name_valid);
- return r;
+ LOG_ERROR("Failed out of do-while loop in ask_wallet_create_if_needed()");
+ return false;
}
/*!
@@ -2550,12 +2564,19 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
}
catch (const tools::error::not_enough_money& e)
{
+ LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, sent amount %s") %
+ print_money(e.available()) %
+ print_money(e.tx_amount()));
+ fail_msg_writer() << tr("Not enough money in unlocked balance");
+ }
+ catch (const tools::error::tx_not_possible& e)
+ {
LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)") %
print_money(e.available()) %
print_money(e.tx_amount() + e.fee()) %
print_money(e.tx_amount()) %
print_money(e.fee()));
- fail_msg_writer() << tr("Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees");
+ fail_msg_writer() << tr("Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees, or trying to send more money than the unlocked balance, or not leaving enough for fees");
}
catch (const tools::error::not_enough_outs_to_mix& e)
{
@@ -2811,12 +2832,19 @@ bool simple_wallet::locked_transfer(const std::vector<std::string> &args_)
}
catch (const tools::error::not_enough_money& e)
{
+ LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, sent amount %s") %
+ print_money(e.available()) %
+ print_money(e.tx_amount()));
+ fail_msg_writer() << tr("Not enough money in unlocked balance");
+ }
+ catch (const tools::error::tx_not_possible& e)
+ {
LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)") %
print_money(e.available()) %
print_money(e.tx_amount() + e.fee()) %
print_money(e.tx_amount()) %
print_money(e.fee()));
- fail_msg_writer() << tr("Not enough money to transfer.");
+ fail_msg_writer() << tr("Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees, or trying to send more money than the unlocked balance, or not leaving enough for fees");
}
catch (const tools::error::not_enough_outs_to_mix& e)
{
@@ -2897,11 +2925,8 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
for (size_t n = 0; n < ptx_vector.size(); ++n)
{
total_fee += ptx_vector[n].fee;
- for (const auto &vin: ptx_vector[n].tx.vin)
- {
- if (vin.type() == typeid(txin_to_key))
- total_unmixable += boost::get<txin_to_key>(vin).amount;
- }
+ for (auto i: ptx_vector[n].selected_transfers)
+ total_unmixable += m_wallet->get_transfer_details(i).amount();
}
std::string prompt_str = tr("Sweeping ") + print_money(total_unmixable);
@@ -2970,12 +2995,19 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
}
catch (const tools::error::not_enough_money& e)
{
+ LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, sent amount %s") %
+ print_money(e.available()) %
+ print_money(e.tx_amount()));
+ fail_msg_writer() << tr("Not enough money in unlocked balance");
+ }
+ catch (const tools::error::tx_not_possible& e)
+ {
LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)") %
print_money(e.available()) %
print_money(e.tx_amount() + e.fee()) %
print_money(e.tx_amount()) %
print_money(e.fee()));
- fail_msg_writer() << tr("Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees");
+ fail_msg_writer() << tr("Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees, or trying to send more money than the unlocked balance, or not leaving enough for fees");
}
catch (const tools::error::not_enough_outs_to_mix& e)
{
@@ -3152,11 +3184,8 @@ bool simple_wallet::sweep_all(const std::vector<std::string> &args_)
for (size_t n = 0; n < ptx_vector.size(); ++n)
{
total_fee += ptx_vector[n].fee;
- for (const auto &vin: ptx_vector[n].tx.vin)
- {
- if (vin.type() == typeid(txin_to_key))
- total_sent += boost::get<txin_to_key>(vin).amount;
- }
+ for (auto i: ptx_vector[n].selected_transfers)
+ total_sent += m_wallet->get_transfer_details(i).amount();
}
std::string prompt_str;
@@ -3225,12 +3254,19 @@ bool simple_wallet::sweep_all(const std::vector<std::string> &args_)
}
catch (const tools::error::not_enough_money& e)
{
+ LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, sent amount %s") %
+ print_money(e.available()) %
+ print_money(e.tx_amount()));
+ fail_msg_writer() << tr("Not enough money in unlocked balance");
+ }
+ catch (const tools::error::tx_not_possible& e)
+ {
LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)") %
print_money(e.available()) %
print_money(e.tx_amount() + e.fee()) %
print_money(e.tx_amount()) %
print_money(e.fee()));
- fail_msg_writer() << tr("Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees");
+ fail_msg_writer() << tr("Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees, or trying to send more money than the unlocked balance, or not leaving enough for fees");
}
catch (const tools::error::not_enough_outs_to_mix& e)
{
@@ -3458,11 +3494,19 @@ bool simple_wallet::submit_transfer(const std::vector<std::string> &args_)
}
catch (const tools::error::not_enough_money& e)
{
- fail_msg_writer() << boost::format(tr("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)")) %
+ LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, sent amount %s") %
print_money(e.available()) %
- print_money(e.tx_amount() + e.fee()) %
+ print_money(e.tx_amount()));
+ fail_msg_writer() << tr("Not enough money in unlocked balance");
+ }
+ catch (const tools::error::tx_not_possible& e)
+ {
+ LOG_PRINT_L0(boost::format("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)") %
+ print_money(e.available()) %
+ print_money(e.tx_amount() + e.fee()) %
print_money(e.tx_amount()) %
- print_money(e.fee());
+ print_money(e.fee()));
+ fail_msg_writer() << tr("Failed to find a way to create transactions. This is usually due to dust which is so small it cannot pay for itself in fees, or trying to send more money than the unlocked balance, or not leaving enough for fees");
}
catch (const tools::error::not_enough_outs_to_mix& e)
{
@@ -3831,8 +3875,8 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
m_wallet->get_payments_out(payments, min_height, max_height);
for (std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
const tools::wallet2::confirmed_transfer_details &pd = i->second;
- uint64_t fee = pd.m_amount_in - pd.m_amount_out;
uint64_t change = pd.m_change == (uint64_t)-1 ? 0 : pd.m_change; // change may not be known
+ uint64_t fee = pd.m_amount_in - pd.m_amount_out - change;
std::string dests;
for (const auto &d: pd.m_dests) {
if (!dests.empty())