Skip to content

Commit

Permalink
Merge pull request #305 from cartoon-face/development
Browse files Browse the repository at this point in the history
`concealwallet` Improvements
  • Loading branch information
AxVultis authored Aug 28, 2022
2 parents d92c5d7 + adc36ea commit b7922bb
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 24 deletions.
33 changes: 29 additions & 4 deletions src/ConcealWallet/ClientHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -416,4 +416,29 @@ namespace cn
throw std::runtime_error("error saving wallet file '" + walletFilename + "'");
}
}

std::stringstream client_helper::balances(std::unique_ptr<cn::IWalletLegacy>& 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;
}
}
5 changes: 5 additions & 0 deletions src/ConcealWallet/ClientHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,10 @@ namespace cn
std::string tryToOpenWalletOrLoadKeysOrThrow(logging::LoggerRef& logger, std::unique_ptr<cn::IWalletLegacy>& 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<cn::IWalletLegacy>& wallet, const Currency& currency);
};
}
51 changes: 33 additions & 18 deletions src/ConcealWallet/ConcealWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 <id> - Withdraw a deposit");
m_consoleHandler.setHandler("deposit_info", boost::bind(&conceal_wallet::deposit_info, this, boost::arg<1>()), "deposit_info <id> - Get infomation for deposit <id>");
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 <wallet_name>_conceal_transactions.txt");
m_consoleHandler.setHandler("check_address", boost::bind(&conceal_wallet::check_address, this, boost::arg<1>()), "check_address <address> - Checks to see if given wallet is valid.");
}

std::string conceal_wallet::wallet_menu(bool do_ext)
Expand Down Expand Up @@ -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 <address>\" - Checks to see if given wallet is valid.\n";
menu_item += "\"deposit <months> <amount>\" - Create a deposit to the blockchain.\n";
menu_item += "\"deposit_info <id>\" - Display full information for deposit <id>.\n";
menu_item += "\"exit\" - Safely exits the wallet application.\n";
Expand Down Expand Up @@ -836,12 +839,12 @@ bool conceal_wallet::reset(const std::vector<std::string> &args) {

bool conceal_wallet::get_reserve_proof(const std::vector<std::string> &args)
{
if (args.size() != 1 && args.size() != 2) {
if (args.size() != 1 && args.size() != 2)
{
fail_msg_writer() << "Usage: balance_proof (all|<amount>) [<message>]";
return true;
}


uint64_t reserve = 0;
if (args[0] != "all") {
if (!m_currency.parseAmount(args[0], reserve)) {
Expand Down Expand Up @@ -992,23 +995,14 @@ void conceal_wallet::synchronizationProgressUpdated(uint32_t current, uint32_t t

bool conceal_wallet::show_balance(const std::vector<std::string>& args/* = std::vector<std::string>()*/)
{
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;
}
Expand Down Expand Up @@ -1970,3 +1964,24 @@ bool conceal_wallet::deposit_info(const std::vector<std::string> &args)

return true;
}

bool conceal_wallet::check_address(const std::vector<std::string> &args)
{
if (args.size() != 1)
{
logger(ERROR) << "Usage: check_address <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;
}
1 change: 1 addition & 0 deletions src/ConcealWallet/ConcealWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace cn
bool withdraw(const std::vector<std::string> &args);
bool list_deposits(const std::vector<std::string> &args);
bool deposit_info(const std::vector<std::string> &args);
bool check_address(const std::vector<std::string> &args);
/* End of Commands */

std::string resolveAlias(const std::string& aliasUrl);
Expand Down
5 changes: 3 additions & 2 deletions src/ConcealWallet/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,13 @@ int main(int argc, char* argv[])
std::unique_ptr<cn::IWalletLegacy> 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";
}
Expand Down

0 comments on commit b7922bb

Please sign in to comment.