diff --git a/src/ConcealWallet/ClientHelper.cpp b/src/ConcealWallet/ClientHelper.cpp index 10a6979b..08190833 100644 --- a/src/ConcealWallet/ClientHelper.cpp +++ b/src/ConcealWallet/ClientHelper.cpp @@ -50,7 +50,7 @@ namespace cn else if (deposit.spendingTransactionId == cn::WALLET_LEGACY_INVALID_TRANSACTION_ID) status_str = "Unlocked"; else - status_str = "Spent"; + status_str = "Withdrawn"; return status_str; } @@ -120,7 +120,7 @@ namespace cn std::setw(20) << makeCenteredString(20, deposit_amount(deposit, currency)) << " | " << std::setw(20) << makeCenteredString(20, deposit_interest(deposit, currency)) << " | " << std::setw(16) << makeCenteredString(16, deposit_unlock_height(deposit, txInfo)) << " | " << - std::setw(10) << makeCenteredString(10, deposit_status(deposit)); + std::setw(12) << makeCenteredString(12, deposit_status(deposit)); std::string as_str = full_info.str(); @@ -154,14 +154,14 @@ namespace cn std::stringstream ss_interest(makeCenteredString(20, format_interest)); std::stringstream ss_height(makeCenteredString(16, deposit_height(txInfo))); std::stringstream ss_unlockheight(makeCenteredString(16, deposit_unlock_height(deposit, txInfo))); - std::stringstream ss_status(makeCenteredString(10, deposit_status(deposit))); + std::stringstream ss_status(makeCenteredString(12, deposit_status(deposit))); ss_id >> std::setw(8); ss_amount >> std::setw(20); ss_interest >> std::setw(20); ss_height >> std::setw(16); ss_unlockheight >> std::setw(16); - ss_status >> std::setw(10); + ss_status >> std::setw(12); listed_deposit = ss_id.str() + " | " + ss_amount.str() + " | " + ss_interest.str() + " | " + ss_height.str() + " | " + ss_unlockheight.str() + " | " + ss_status.str() + "\n"; @@ -416,4 +416,29 @@ namespace cn throw std::runtime_error("error saving wallet file '" + walletFilename + "'"); } } + + std::stringstream client_helper::balances(std::unique_ptr& wallet, const Currency& currency) + { + std::stringstream balances; + + uint64_t full_balance = wallet->actualBalance() + wallet->pendingBalance() + wallet->actualDepositBalance() + wallet->pendingDepositBalance(); + std::string full_balance_text = "Total Balance: " + currency.formatAmount(full_balance) + "\n"; + + uint64_t non_deposit_unlocked_balance = wallet->actualBalance(); + std::string non_deposit_unlocked_balance_text = "Available: " + currency.formatAmount(non_deposit_unlocked_balance) + "\n"; + + uint64_t non_deposit_locked_balance = wallet->pendingBalance(); + std::string non_deposit_locked_balance_text = "Locked: " + currency.formatAmount(non_deposit_locked_balance) + "\n"; + + uint64_t deposit_unlocked_balance = wallet->actualDepositBalance(); + std::string deposit_locked_balance_text = "Unlocked Balance: " + currency.formatAmount(deposit_unlocked_balance) + "\n"; + + uint64_t deposit_locked_balance = wallet->pendingDepositBalance(); + std::string deposit_unlocked_balance_text = "Locked Deposits: " + currency.formatAmount(deposit_locked_balance) + "\n"; + + balances << full_balance_text << non_deposit_unlocked_balance_text << non_deposit_locked_balance_text + << deposit_unlocked_balance_text << deposit_locked_balance_text; + + return balances; + } } diff --git a/src/ConcealWallet/ClientHelper.h b/src/ConcealWallet/ClientHelper.h index 02a55097..c94af5da 100644 --- a/src/ConcealWallet/ClientHelper.h +++ b/src/ConcealWallet/ClientHelper.h @@ -102,5 +102,10 @@ namespace cn std::string tryToOpenWalletOrLoadKeysOrThrow(logging::LoggerRef& logger, std::unique_ptr& wallet, const std::string& walletFile, const std::string& password); void save_wallet(cn::IWalletLegacy& wallet, const std::string& walletFilename, logging::LoggerRef& logger); + + /** + * @return - Displays all balances (main + deposits) + */ + std::stringstream balances(std::unique_ptr& wallet, const Currency& currency); }; } \ No newline at end of file diff --git a/src/ConcealWallet/ConcealWallet.cpp b/src/ConcealWallet/ConcealWallet.cpp index 3fafbe1c..6fc0c1ed 100644 --- a/src/ConcealWallet/ConcealWallet.cpp +++ b/src/ConcealWallet/ConcealWallet.cpp @@ -41,6 +41,7 @@ #include "CryptoNoteCore/CryptoNoteTools.h" #include "Wallet/WalletRpcServer.h" +#include "Wallet/WalletUtils.h" #include "WalletLegacy/WalletLegacy.h" #include "Wallet/LegacyKeysImporter.h" #include "WalletLegacy/WalletHelper.h" @@ -331,6 +332,7 @@ conceal_wallet::conceal_wallet(platform_system::Dispatcher& dispatcher, const cn m_consoleHandler.setHandler("withdraw", boost::bind(&conceal_wallet::withdraw, this, boost::arg<1>()), "withdraw - Withdraw a deposit"); m_consoleHandler.setHandler("deposit_info", boost::bind(&conceal_wallet::deposit_info, this, boost::arg<1>()), "deposit_info - Get infomation for deposit "); m_consoleHandler.setHandler("save_txs_to_file", boost::bind(&conceal_wallet::save_all_txs_to_file, this, boost::arg<1>()), "save_txs_to_file - Saves all known transactions to _conceal_transactions.txt"); + m_consoleHandler.setHandler("check_address", boost::bind(&conceal_wallet::check_address, this, boost::arg<1>()), "check_address
- Checks to see if given wallet is valid."); } std::string conceal_wallet::wallet_menu(bool do_ext) @@ -363,6 +365,7 @@ std::string conceal_wallet::wallet_menu(bool do_ext) menu_item += "\"address\" - Shows wallet address.\n"; menu_item += "\"balance\" - Shows wallet main and deposit balance.\n"; menu_item += "\"bc_height\" - Shows current blockchain height.\n"; + menu_item += "\"check_address
\" - Checks to see if given wallet is valid.\n"; menu_item += "\"deposit \" - Create a deposit to the blockchain.\n"; menu_item += "\"deposit_info \" - Display full information for deposit .\n"; menu_item += "\"exit\" - Safely exits the wallet application.\n"; @@ -836,12 +839,12 @@ bool conceal_wallet::reset(const std::vector &args) { bool conceal_wallet::get_reserve_proof(const std::vector &args) { - if (args.size() != 1 && args.size() != 2) { + if (args.size() != 1 && args.size() != 2) + { fail_msg_writer() << "Usage: balance_proof (all|) []"; return true; } - uint64_t reserve = 0; if (args[0] != "all") { if (!m_currency.parseAmount(args[0], reserve)) { @@ -992,23 +995,14 @@ void conceal_wallet::synchronizationProgressUpdated(uint32_t current, uint32_t t bool conceal_wallet::show_balance(const std::vector& args/* = std::vector()*/) { - uint64_t full_balance = m_wallet->actualBalance() + m_wallet->pendingBalance() + m_wallet->actualDepositBalance() + m_wallet->pendingDepositBalance(); - std::string full_balance_text = "Total Balance: " + m_currency.formatAmount(full_balance) + "\n"; - - uint64_t non_deposit_unlocked_balance = m_wallet->actualBalance(); - std::string non_deposit_unlocked_balance_text = "Available: " + m_currency.formatAmount(non_deposit_unlocked_balance) + "\n"; - - uint64_t non_deposit_locked_balance = m_wallet->pendingBalance(); - std::string non_deposit_locked_balance_text = "Locked: " + m_currency.formatAmount(non_deposit_locked_balance) + "\n"; - - uint64_t deposit_unlocked_balance = m_wallet->actualDepositBalance(); - std::string deposit_locked_balance_text = "Unlocked Balance: " + m_currency.formatAmount(deposit_unlocked_balance) + "\n"; - - uint64_t deposit_locked_balance = m_wallet->pendingDepositBalance(); - std::string deposit_unlocked_balance_text = "Locked Deposits: " + m_currency.formatAmount(deposit_locked_balance) + "\n"; + if (!args.empty()) + { + logger(ERROR) << "Usage: balance"; + return true; + } - logger(INFO) << full_balance_text << non_deposit_unlocked_balance_text << non_deposit_locked_balance_text - << deposit_unlocked_balance_text << deposit_locked_balance_text; + std::stringstream balances = m_chelper.balances(m_wallet, m_currency); + logger(INFO) << balances.str(); return true; } @@ -1970,3 +1964,24 @@ bool conceal_wallet::deposit_info(const std::vector &args) return true; } + +bool conceal_wallet::check_address(const std::vector &args) +{ + if (args.size() != 1) + { + logger(ERROR) << "Usage: check_address
"; + return true; + } + + const std::string addr = args[0]; + + if (!cn::validateAddress(addr, m_currency)) + { + logger(ERROR) << "Invalid wallet address: " << addr; + return true; + } + + logger(INFO) << "The wallet " << addr << " seems to be valid, please still be cautious still."; + + return true; +} \ No newline at end of file diff --git a/src/ConcealWallet/ConcealWallet.h b/src/ConcealWallet/ConcealWallet.h index cc5c0e00..02aedb0c 100644 --- a/src/ConcealWallet/ConcealWallet.h +++ b/src/ConcealWallet/ConcealWallet.h @@ -106,6 +106,7 @@ namespace cn bool withdraw(const std::vector &args); bool list_deposits(const std::vector &args); bool deposit_info(const std::vector &args); + bool check_address(const std::vector &args); /* End of Commands */ std::string resolveAlias(const std::string& aliasUrl); diff --git a/src/ConcealWallet/main.cpp b/src/ConcealWallet/main.cpp index f0f88199..55b8f759 100644 --- a/src/ConcealWallet/main.cpp +++ b/src/ConcealWallet/main.cpp @@ -161,12 +161,13 @@ int main(int argc, char* argv[]) std::unique_ptr wallet(new cn::WalletLegacy(currency, *node.get(), logManager, testnet)); std::string walletFileName; + try { walletFileName = m_chelper.tryToOpenWalletOrLoadKeysOrThrow(logger, wallet, wallet_file, wallet_password); - logger(INFO) << "available balance: " << currency.formatAmount(wallet->actualBalance()) << - ", locked amount: " << currency.formatAmount(wallet->pendingBalance()); + std::stringstream balances = m_chelper.balances(wallet, currency); + logger(INFO) << balances.str(); logger(INFO, BRIGHT_GREEN) << "Loaded ok"; }