From a637768756d7da3bfeaf0e60ddc9bf6d6ba534bc Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Sat, 19 Feb 2022 21:05:18 +0000 Subject: [PATCH 01/48] Withdraw deposit without vector --- include/IWalletLegacy.h | 2 + src/WalletLegacy/WalletLegacy.cpp | 30 +++- src/WalletLegacy/WalletLegacy.h | 1 + src/WalletLegacy/WalletLegacyEvent.h | 13 ++ src/WalletLegacy/WalletTransactionSender.cpp | 152 ++++++++++++++++++- src/WalletLegacy/WalletTransactionSender.h | 19 ++- 6 files changed, 209 insertions(+), 8 deletions(-) diff --git a/include/IWalletLegacy.h b/include/IWalletLegacy.h index a1dab3d1..5971c6b0 100644 --- a/include/IWalletLegacy.h +++ b/include/IWalletLegacy.h @@ -98,6 +98,7 @@ class IWalletLegacyObserver { virtual void externalTransactionCreated(TransactionId transactionId) {} virtual void sendTransactionCompleted(TransactionId transactionId, std::error_code result) {} virtual void transactionUpdated(TransactionId transactionId) {} + virtual void depositUpdated(const DepositId& depositId) {} virtual void depositsUpdated(const std::vector& depositIds) {} }; @@ -152,6 +153,7 @@ class IWalletLegacy { virtual std::list selectFusionTransfersToSend(uint64_t threshold, size_t minInputCount, size_t maxInputCount) = 0; virtual TransactionId sendFusionTransaction(const std::list& fusionInputs, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0) = 0; virtual TransactionId deposit(uint32_t term, uint64_t amount, uint64_t fee, uint64_t mixIn = 0) = 0; + virtual TransactionId withdrawDeposit(const DepositId& depositId, uint64_t fee) = 0; virtual TransactionId withdrawDeposits(const std::vector& depositIds, uint64_t fee) = 0; virtual std::error_code cancelTransaction(size_t transferId) = 0; diff --git a/src/WalletLegacy/WalletLegacy.cpp b/src/WalletLegacy/WalletLegacy.cpp index 5b23fa60..83cb2131 100644 --- a/src/WalletLegacy/WalletLegacy.cpp +++ b/src/WalletLegacy/WalletLegacy.cpp @@ -804,6 +804,34 @@ TransactionId WalletLegacy::deposit(uint32_t term, uint64_t amount, uint64_t fee return txId; } +TransactionId WalletLegacy::withdrawDeposit(const DepositId& depositId, uint64_t fee) { + throwIfNotInitialised(); + + TransactionId txId = 0; + std::unique_ptr request; + std::deque> events; + + fee = cn::parameters::MINIMUM_FEE; + + { + std::unique_lock lock(m_cacheMutex); + request = m_sender->makeWithdrawDepositRequest(txId, events, depositId, fee); + + if (request != nullptr) { + pushBalanceUpdatedEvents(events); + } + } + + notifyClients(events); + + if (request != nullptr) { + m_asyncContextCounter.addAsyncContext(); + request->perform(m_node, std::bind(&WalletLegacy::sendTransactionCallback, this, std::placeholders::_1, std::placeholders::_2)); + } + + return txId; +} + TransactionId WalletLegacy::withdrawDeposits(const std::vector& depositIds, uint64_t fee) { throwIfNotInitialised(); @@ -815,7 +843,7 @@ TransactionId WalletLegacy::withdrawDeposits(const std::vector& depos { std::unique_lock lock(m_cacheMutex); - request = m_sender->makeWithdrawDepositRequest(txId, events, depositIds, fee); + request = m_sender->makeWithdrawDepositsRequest(txId, events, depositIds, fee); if (request != nullptr) { pushBalanceUpdatedEvents(events); diff --git a/src/WalletLegacy/WalletLegacy.h b/src/WalletLegacy/WalletLegacy.h index b99f3e95..20c2dbac 100644 --- a/src/WalletLegacy/WalletLegacy.h +++ b/src/WalletLegacy/WalletLegacy.h @@ -102,6 +102,7 @@ class WalletLegacy : virtual std::list selectFusionTransfersToSend(uint64_t threshold, size_t minInputCount, size_t maxInputCount); virtual TransactionId sendFusionTransaction(const std::list& fusionInputs, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0); virtual TransactionId deposit(uint32_t term, uint64_t amount, uint64_t fee, uint64_t mixIn = parameters::MINIMUM_MIXIN) override; + virtual TransactionId withdrawDeposit(const DepositId& depositId, uint64_t fee) override; virtual TransactionId withdrawDeposits(const std::vector& depositIds, uint64_t fee) override; virtual std::error_code cancelTransaction(size_t transactionId) override; diff --git a/src/WalletLegacy/WalletLegacyEvent.h b/src/WalletLegacy/WalletLegacyEvent.h index 56ebf5b4..2dbcbe25 100644 --- a/src/WalletLegacy/WalletLegacyEvent.h +++ b/src/WalletLegacy/WalletLegacyEvent.h @@ -67,6 +67,19 @@ class WalletExternalTransactionCreatedEvent : public WalletLegacyEvent TransactionId m_id; }; +class WalletDepositUpdatedEvent : public WalletLegacyEvent { +public: + WalletDepositUpdatedEvent(DepositId& depositId) : updatedDeposit(depositId) {} + + virtual ~WalletDepositUpdatedEvent() {} + + virtual void notify(tools::ObserverManager& observer) override { + observer.notify(&IWalletLegacyObserver::depositUpdated, updatedDeposit); + } +private: + DepositId updatedDeposit; +}; + class WalletDepositsUpdatedEvent : public WalletLegacyEvent { public: WalletDepositsUpdatedEvent(std::vector&& depositIds) : updatedDeposits(depositIds) {} diff --git a/src/WalletLegacy/WalletTransactionSender.cpp b/src/WalletLegacy/WalletTransactionSender.cpp index cef1b55a..4c437267 100644 --- a/src/WalletLegacy/WalletTransactionSender.cpp +++ b/src/WalletLegacy/WalletTransactionSender.cpp @@ -151,6 +151,16 @@ namespace return amount; } + void countDepositTotalSumAndInterestSum(const DepositId &depositId, WalletUserTransactionsCache &depositsCache, + uint64_t &totalSum, uint64_t &interestsSum) + { + totalSum = 0; + interestsSum = 0; + Deposit &deposit = depositsCache.getDeposit(depositId); + totalSum += deposit.amount + deposit.interest; + interestsSum += deposit.interest; + } + void countDepositsTotalSumAndInterestSum(const std::vector &depositIds, WalletUserTransactionsCache &depositsCache, uint64_t &totalSum, uint64_t &interestsSum) { @@ -297,6 +307,27 @@ namespace cn } std::unique_ptr WalletTransactionSender::makeWithdrawDepositRequest(TransactionId &transactionId, + std::deque> &events, + const DepositId &depositId, + uint64_t fee) + { + + std::shared_ptr context = std::make_shared(); + context->dustPolicy.dustThreshold = m_currency.defaultDustThreshold(); + + context->foundMoney = selectDepositTransfers(depositId, context->selectedTransfers); + throwIf(context->foundMoney < fee, error::WRONG_AMOUNT); + + transactionId = m_transactionsCache.addNewTransaction(context->foundMoney, fee, std::string(), {}, 0, {}); + context->transactionId = transactionId; + context->mixIn = 0; + + setSpendingTransactionToDeposit(transactionId, depositId); + + return doSendDepositWithdrawTransaction(std::move(context), events, depositId); + } + + std::unique_ptr WalletTransactionSender::makeWithdrawDepositsRequest(TransactionId &transactionId, std::deque> &events, const std::vector &depositIds, uint64_t fee) @@ -305,7 +336,7 @@ namespace cn std::shared_ptr context = std::make_shared(); context->dustPolicy.dustThreshold = m_currency.defaultDustThreshold(); - context->foundMoney = selectDepositTransfers(depositIds, context->selectedTransfers); + context->foundMoney = selectDepositsTransfers(depositIds, context->selectedTransfers); throwIf(context->foundMoney < fee, error::WRONG_AMOUNT); transactionId = m_transactionsCache.addNewTransaction(context->foundMoney, fee, std::string(), {}, 0, {}); @@ -314,7 +345,7 @@ namespace cn setSpendingTransactionToDeposits(transactionId, depositIds); - return doSendDepositWithdrawTransaction(std::move(context), events, depositIds); + return doSendDepositsWithdrawTransaction(std::move(context), events, depositIds); } std::shared_ptr WalletTransactionSender::makeSendFusionRequest(TransactionId &transactionId, std::deque> &events, @@ -532,7 +563,7 @@ namespace cn std::vector deposits{depositId}; - return std::unique_ptr(new WalletRelayDepositTransactionRequest(lowlevelTransaction, std::bind(&WalletTransactionSender::relayDepositTransactionCallback, this, context, + return std::unique_ptr(new WalletRelayDepositTransactionRequest(lowlevelTransaction, std::bind(&WalletTransactionSender::relayDepositsTransactionCallback, this, context, deposits, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))); } catch (std::system_error &ec) @@ -548,6 +579,71 @@ namespace cn } std::unique_ptr WalletTransactionSender::doSendDepositWithdrawTransaction(std::shared_ptr &&context, + std::deque> &events, const DepositId &depositId) + { + if (m_isStoping) + { + events.push_back(makeCompleteEvent(m_transactionsCache, context->transactionId, make_error_code(error::TX_CANCELLED))); + return std::unique_ptr(); + } + + try + { + WalletLegacyTransaction &transactionInfo = m_transactionsCache.getTransaction(context->transactionId); + + std::unique_ptr transaction = createTransaction(); + std::vector inputs = prepareMultisignatureInputs(context->selectedTransfers); + + std::vector outputAmounts = splitAmount(context->foundMoney - transactionInfo.fee, context->dustPolicy.dustThreshold); + + for (const auto &input : inputs) + { + transaction->addInput(input); + } + + for (auto amount : outputAmounts) + { + transaction->addOutput(amount, m_keys.address); + } + + transaction->setUnlockTime(transactionInfo.unlockTime); + + assert(inputs.size() == context->selectedTransfers.size()); + for (size_t i = 0; i < inputs.size(); ++i) + { + transaction->signInputMultisignature(i, context->selectedTransfers[i].transactionPublicKey, context->selectedTransfers[i].outputInTransaction, m_keys); + } + + transactionInfo.hash = transaction->getTransactionHash(); + + Transaction lowlevelTransaction = convertTransaction(*transaction, static_cast(m_upperTransactionSizeLimit)); + + uint64_t interestsSum; + uint64_t totalSum; + countDepositTotalSumAndInterestSum(depositId, m_transactionsCache, totalSum, interestsSum); + + UnconfirmedSpentDepositDetails unconfirmed; + unconfirmed.depositsSum = totalSum; + unconfirmed.fee = transactionInfo.fee; + unconfirmed.transactionId = context->transactionId; + m_transactionsCache.addDepositSpendingTransaction(transaction->getTransactionHash(), unconfirmed); + + return std::unique_ptr(new WalletRelayDepositTransactionRequest(lowlevelTransaction, + std::bind(&WalletTransactionSender::relayDepositTransactionCallback, this, context, depositId, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))); + } + catch (std::system_error &ec) + { + events.push_back(makeCompleteEvent(m_transactionsCache, context->transactionId, ec.code())); + } + catch (std::exception &) + { + events.push_back(makeCompleteEvent(m_transactionsCache, context->transactionId, make_error_code(error::INTERNAL_WALLET_ERROR))); + } + + return std::unique_ptr(); + } + + std::unique_ptr WalletTransactionSender::doSendDepositsWithdrawTransaction(std::shared_ptr &&context, std::deque> &events, const std::vector &depositIds) { if (m_isStoping) @@ -598,7 +694,7 @@ namespace cn m_transactionsCache.addDepositSpendingTransaction(transaction->getTransactionHash(), unconfirmed); return std::unique_ptr(new WalletRelayDepositTransactionRequest(lowlevelTransaction, - std::bind(&WalletTransactionSender::relayDepositTransactionCallback, this, context, depositIds, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))); + std::bind(&WalletTransactionSender::relayDepositsTransactionCallback, this, context, depositIds, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))); } catch (std::system_error &ec) { @@ -624,6 +720,21 @@ namespace cn } void WalletTransactionSender::relayDepositTransactionCallback(std::shared_ptr context, + DepositId deposit, + std::deque> &events, + std::unique_ptr &nextRequest, + std::error_code ec) + { + if (m_isStoping) + { + return; + } + + events.push_back(makeCompleteEvent(m_transactionsCache, context->transactionId, ec)); + events.push_back(std::unique_ptr(new WalletDepositUpdatedEvent(deposit))); + } + + void WalletTransactionSender::relayDepositsTransactionCallback(std::shared_ptr context, std::vector deposits, std::deque> &events, std::unique_ptr &nextRequest, @@ -902,7 +1013,32 @@ namespace cn return foundMoney; } - uint64_t WalletTransactionSender::selectDepositTransfers(const std::vector &depositIds, std::vector &selectedTransfers) + uint64_t WalletTransactionSender::selectDepositTransfers(const DepositId &depositId, std::vector &selectedTransfers) + { + uint64_t foundMoney = 0; + + Hash transactionHash; + uint32_t outputInTransaction; + throwIf(m_transactionsCache.getDepositInTransactionInfo(depositId, transactionHash, outputInTransaction) == false, error::DEPOSIT_DOESNOT_EXIST); + + { + TransactionOutputInformation transfer; + ITransfersContainer::TransferState state; + throwIf(m_transferDetails.getTransfer(transactionHash, outputInTransaction, transfer, state) == false, error::DEPOSIT_DOESNOT_EXIST); + throwIf(state != ITransfersContainer::TransferState::TransferAvailable, error::DEPOSIT_LOCKED); + selectedTransfers.push_back(std::move(transfer)); + } + + Deposit deposit; + bool r = m_transactionsCache.getDeposit(depositId, deposit); + assert(r); + + foundMoney += deposit.amount + deposit.interest; + + return foundMoney; + } + + uint64_t WalletTransactionSender::selectDepositsTransfers(const std::vector &depositIds, std::vector &selectedTransfers) { uint64_t foundMoney = 0; @@ -930,6 +1066,12 @@ namespace cn return foundMoney; } + void WalletTransactionSender::setSpendingTransactionToDeposit(TransactionId transactionId, const DepositId &depositId) + { + Deposit &deposit = m_transactionsCache.getDeposit(depositId); + deposit.spendingTransactionId = transactionId; + } + void WalletTransactionSender::setSpendingTransactionToDeposits(TransactionId transactionId, const std::vector &depositIds) { for (auto id : depositIds) diff --git a/src/WalletLegacy/WalletTransactionSender.h b/src/WalletLegacy/WalletTransactionSender.h index b2abb642..07e7ead7 100644 --- a/src/WalletLegacy/WalletTransactionSender.h +++ b/src/WalletLegacy/WalletTransactionSender.h @@ -49,10 +49,15 @@ class WalletTransactionSender uint64_t mixIn = 0); std::unique_ptr makeWithdrawDepositRequest(TransactionId& transactionId, + std::deque>& events, + const DepositId& depositId, + uint64_t fee); + + std::unique_ptr makeWithdrawDepositsRequest(TransactionId& transactionId, std::deque>& events, const std::vector& depositIds, uint64_t fee); - + std::shared_ptr makeSendFusionRequest(TransactionId& transactionId, std::deque>& events, const std::vector& transfers, const std::list& fusionInputs, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0); @@ -62,6 +67,9 @@ std::shared_ptr makeSendFusionRequest(TransactionId& transactionI std::unique_ptr doSendTransaction(std::shared_ptr&& context, std::deque>& events, crypto::SecretKey& transactionSK); std::unique_ptr doSendMultisigTransaction(std::shared_ptr&& context, std::deque>& events); std::unique_ptr doSendDepositWithdrawTransaction(std::shared_ptr&& context, + std::deque>& events, + const DepositId& depositId); + std::unique_ptr doSendDepositsWithdrawTransaction(std::shared_ptr&& context, std::deque>& events, const std::vector& depositIds); @@ -90,6 +98,11 @@ std::shared_ptr makeSendFusionRequest(TransactionId& transactionI std::unique_ptr& nextRequest, std::error_code ec); void relayDepositTransactionCallback(std::shared_ptr context, + DepositId deposit, + std::deque>& events, + std::unique_ptr& nextRequest, + std::error_code ec); + void relayDepositsTransactionCallback(std::shared_ptr context, std::vector deposits, std::deque>& events, std::unique_ptr& nextRequest, @@ -101,8 +114,10 @@ std::shared_ptr makeSendFusionRequest(TransactionId& transactionI uint64_t selectNTransfersToSend(std::vector& selectedTransfers); uint64_t selectTransfersToSend(uint64_t neededMoney, bool addDust, uint64_t dust, std::vector& selectedTransfers); - uint64_t selectDepositTransfers(const std::vector& depositIds, std::vector& selectedTransfers); + uint64_t selectDepositTransfers(const DepositId& depositId, std::vector& selectedTransfers); + uint64_t selectDepositsTransfers(const std::vector& depositIds, std::vector& selectedTransfers); + void setSpendingTransactionToDeposit(TransactionId transactionId, const DepositId& depositId); void setSpendingTransactionToDeposits(TransactionId transactionId, const std::vector& depositIds); const Currency& m_currency; From 984f8f3f569d4b51179400ad0e88816a504f3efe Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Sat, 19 Feb 2022 21:09:23 +0000 Subject: [PATCH 02/48] List wallet deposits Same logic as list_transfers --- src/SimpleWallet/SimpleWallet.cpp | 88 +++++++++++++++++++++++++++++++ src/SimpleWallet/SimpleWallet.h | 2 + 2 files changed, 90 insertions(+) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index dc62f627..f7f74e9f 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -550,6 +550,40 @@ bool askAliasesTransfersConfirmation(const std::map 0) { + logger(INFO, rowColor) << "deposits:"; + for (DepositId id = txInfo.firstDepositId; id < txInfo.firstDepositId + txInfo.depositCount; ++id) { + Deposit d; + wallet.getDeposit(id, d); + std::string is_locked = !d.locked ? "Unlocked" : "Locked"; + + logger(INFO, rowColor) + << "ID: " << id << "\n" + << "Amount: " << currency.formatAmount(d.amount) + << "Interest: " << currency.formatAmount(d.interest) + << "Term: " << d.term + << "Unlock Height: " << d.unlockHeight + << "Locked: " << is_locked; + } + } + } + + logger(INFO, rowColor) << " "; //just to make logger print one endline +} + } bool processServerFeeAddressResponse(const std::string& response, std::string& fee_address) { @@ -636,6 +670,7 @@ simple_wallet::simple_wallet(platform_system::Dispatcher& dispatcher, const cn:: m_consoleHandler.setHandler("exit", boost::bind(&simple_wallet::exit, this, boost::arg<1>()), "Close wallet"); m_consoleHandler.setHandler("get_reserve_proof", boost::bind(&simple_wallet::get_reserve_proof, this, boost::arg<1>()), "all| [] - Generate a signature proving that you own at least , optionally with a challenge string . "); m_consoleHandler.setHandler("save_keys", boost::bind(&simple_wallet::save_keys_to_file, this, boost::arg<1>()), "Saves wallet private keys to \"_conceal_backup.txt\""); + m_consoleHandler.setHandler("list_deposits", boost::bind(&simple_wallet::list_deposits, this, boost::arg<1>()), "Show all known deposits from this wallet"); } std::string simple_wallet::simple_menu() @@ -648,6 +683,7 @@ std::string simple_wallet::simple_menu() menu_item += "\"exit\" - Safely exits the wallet application.\n"; menu_item += "\"export_keys\" - Displays backup keys.\n"; menu_item += "\"help\" | \"ext_help\" - Shows this help dialog or extended help dialog.\n"; + menu_item += "\"list_deposits\" - Show all known deposits, optionally from a certain height. | \n"; menu_item += "\"list_transfers\" - Show all known transfers, optionally from a certain height. | \n"; menu_item += "\"reset\" - Reset cached blockchain data and starts synchronizing from block 0.\n"; menu_item += "\"transfer
\" - Transfers to
. | [-p] []...[] []...[]\n"; @@ -1955,6 +1991,58 @@ bool simple_wallet::save_keys_to_file(const std::vector& args) return true; } +bool simple_wallet::list_deposits(const std::vector &args) +{ + bool haveDeposits = false; + bool haveBlockHeight = false; + std::string blockHeightString = ""; + uint32_t blockHeight = 0; + WalletLegacyTransaction txInfo; + + + /* get block height from arguments */ + if (args.empty()) + { + haveBlockHeight = false; + } + else + { + blockHeightString = args[0]; + haveBlockHeight = true; + blockHeight = atoi(blockHeightString.c_str()); + } + + size_t depositsCount = m_wallet->getDepositCount(); + + for (size_t id = 0; id < depositsCount; ++id) + { + m_wallet->getTransaction(id, txInfo); + if (txInfo.state != WalletLegacyTransactionState::Active || txInfo.blockHeight == WALLET_LEGACY_UNCONFIRMED_TRANSACTION_HEIGHT) { + continue; + } + + if (!haveDeposits) { + printListTransfersHeader(logger); + haveDeposits = true; + } + + if (haveBlockHeight == false) { + printListDepositsItem(logger, txInfo, *m_wallet, m_currency); + } + else + { + if (txInfo.blockHeight >= blockHeight) + printListDepositsItem(logger, txInfo, *m_wallet, m_currency); + } + } + + if (!haveDeposits) { + success_msg_writer() << "No deposits"; + } + + return true; +} + int main(int argc, char* argv[]) { #ifdef _WIN32 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); diff --git a/src/SimpleWallet/SimpleWallet.h b/src/SimpleWallet/SimpleWallet.h index bc14695c..941f3d0e 100644 --- a/src/SimpleWallet/SimpleWallet.h +++ b/src/SimpleWallet/SimpleWallet.h @@ -96,6 +96,8 @@ namespace cn bool set_log(const std::vector &args); bool save_keys_to_file(const std::vector &args); + bool list_deposits(const std::vector &args); + std::string simple_menu(); std::string extended_menu(); From c07834c1c8ce0eab31110f04eae29294e46b9fd8 Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Sat, 19 Feb 2022 21:12:43 +0000 Subject: [PATCH 03/48] Deposit CCX function --- src/SimpleWallet/SimpleWallet.cpp | 109 ++++++++++++++++++++++++++++++ src/SimpleWallet/SimpleWallet.h | 1 + 2 files changed, 110 insertions(+) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index f7f74e9f..1b13ab42 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -671,6 +671,7 @@ simple_wallet::simple_wallet(platform_system::Dispatcher& dispatcher, const cn:: m_consoleHandler.setHandler("get_reserve_proof", boost::bind(&simple_wallet::get_reserve_proof, this, boost::arg<1>()), "all| [] - Generate a signature proving that you own at least , optionally with a challenge string . "); m_consoleHandler.setHandler("save_keys", boost::bind(&simple_wallet::save_keys_to_file, this, boost::arg<1>()), "Saves wallet private keys to \"_conceal_backup.txt\""); m_consoleHandler.setHandler("list_deposits", boost::bind(&simple_wallet::list_deposits, this, boost::arg<1>()), "Show all known deposits from this wallet"); + m_consoleHandler.setHandler("deposit", boost::bind(&simple_wallet::deposit, this, boost::arg<1>()), "deposit - Create a deposit"); } std::string simple_wallet::simple_menu() @@ -680,6 +681,7 @@ std::string simple_wallet::simple_menu() menu_item += "\"address\" - Shows wallet address.\n"; menu_item += "\"balance\" - Shows wallet balance.\n"; menu_item += "\"bc_height\" - Shows current blockchain height.\n"; + menu_item += "\"deposit \" - Create a deposit to the blockchain.\n"; menu_item += "\"exit\" - Safely exits the wallet application.\n"; menu_item += "\"export_keys\" - Displays backup keys.\n"; menu_item += "\"help\" | \"ext_help\" - Shows this help dialog or extended help dialog.\n"; @@ -2043,6 +2045,113 @@ bool simple_wallet::list_deposits(const std::vector &args) return true; } +bool simple_wallet::deposit(const std::vector &args) +{ + if (args.size() != 2) + { + logger(ERROR) << "Usage: deposit "; + return true; + } + + try + { + /** + * Change arg to uint64_t using boost then + * multiply by min_term so user can type in months + **/ + uint64_t deposit_term = boost::lexical_cast(args[0]) * 21900; + + /* Now validate the deposit term and the amount */ + if (deposit_term < cn::parameters::DEPOSIT_MIN_TERM_V3) + { + logger(ERROR, BRIGHT_RED) << "Deposit term is too small, min=21900, given=" << deposit_term; + return true; + } + + if (deposit_term > cn::parameters::DEPOSIT_MAX_TERM_V3) + { + logger(ERROR, BRIGHT_RED) << "Deposit term is too big, min=" << cn::parameters::DEPOSIT_MAX_TERM_V3 + << ", given=" << deposit_term; + return true; + } + + uint64_t deposit_amount = boost::lexical_cast(args[1]); + bool ok = m_currency.parseAmount(args[1], deposit_amount); + + if (!ok || 0 == deposit_amount) + { + logger(ERROR, BRIGHT_RED) << "amount is wrong: " << deposit_amount << + ", expected number from 1 to " << m_currency.formatAmount(cn::parameters::MONEY_SUPPLY); + return true; + } + + if (deposit_amount < cn::parameters::DEPOSIT_MIN_AMOUNT) + { + logger(ERROR, BRIGHT_RED) << "Deposit amount is too small, min=" << cn::parameters::DEPOSIT_MIN_AMOUNT + << ", given=" << m_currency.formatAmount(deposit_amount); + return true; + } + + if (!confirm_deposit(deposit_term, deposit_amount)) + { + logger(ERROR) << "Deposit is not being created." + return true; + } + + /* Use defaults for fee + mix in */ + uint64_t deposit_fee = cn::parameters::MINIMUM_FEE_V2; + uint64_t deposit_mix_in = cn::parameters::MINIMUM_MIXIN; + + cn::WalletHelper::SendCompleteResultObserver sent; + WalletHelper::IWalletRemoveObserverGuard removeGuard(*m_wallet, sent); + + cn::TransactionId tx = m_wallet->deposit(deposit_term, deposit_amount, deposit_fee, deposit_mix_in); + + if (tx == WALLET_LEGACY_INVALID_DEPOSIT_ID) + { + fail_msg_writer() << "Can't deposit money"; + return true; + } + + std::error_code sendError = sent.wait(tx); + removeGuard.removeObserver(); + + if (sendError) + { + fail_msg_writer() << sendError.message(); + return true; + } + + cn::Deposit d_info; + m_wallet->getDeposit(tx, d_info); + success_msg_writer(true) << "Money successfully sent, transaction hash: " << common::podToHex(d_info.transactionHash); + + try + { + cn::WalletHelper::storeWallet(*m_wallet, m_wallet_file); + } + catch (const std::exception& e) + { + fail_msg_writer() << e.what(); + return true; + } + } + catch (const std::system_error& e) + { + fail_msg_writer() << e.what(); + } + catch (const std::exception& e) + { + fail_msg_writer() << e.what(); + } + catch (...) + { + fail_msg_writer() << "unknown error"; + } + + return true; +} + int main(int argc, char* argv[]) { #ifdef _WIN32 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); diff --git a/src/SimpleWallet/SimpleWallet.h b/src/SimpleWallet/SimpleWallet.h index 941f3d0e..6bd63e21 100644 --- a/src/SimpleWallet/SimpleWallet.h +++ b/src/SimpleWallet/SimpleWallet.h @@ -96,6 +96,7 @@ namespace cn bool set_log(const std::vector &args); bool save_keys_to_file(const std::vector &args); + bool deposit(const std::vector &args); bool list_deposits(const std::vector &args); std::string simple_menu(); From 3da34bdcb1241f3d536f70104feae397ecd68c4d Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Sat, 19 Feb 2022 21:15:13 +0000 Subject: [PATCH 04/48] Withdraw CCX function --- src/SimpleWallet/SimpleWallet.cpp | 61 +++++++++++++++++++++++++++++++ src/SimpleWallet/SimpleWallet.h | 1 + 2 files changed, 62 insertions(+) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 1b13ab42..c84cc144 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -672,6 +672,7 @@ simple_wallet::simple_wallet(platform_system::Dispatcher& dispatcher, const cn:: m_consoleHandler.setHandler("save_keys", boost::bind(&simple_wallet::save_keys_to_file, this, boost::arg<1>()), "Saves wallet private keys to \"_conceal_backup.txt\""); m_consoleHandler.setHandler("list_deposits", boost::bind(&simple_wallet::list_deposits, this, boost::arg<1>()), "Show all known deposits from this wallet"); m_consoleHandler.setHandler("deposit", boost::bind(&simple_wallet::deposit, this, boost::arg<1>()), "deposit - Create a deposit"); + m_consoleHandler.setHandler("withdraw", boost::bind(&simple_wallet::withdraw, this, boost::arg<1>()), "withdraw - Withdraw a deposit"); } std::string simple_wallet::simple_menu() @@ -691,6 +692,7 @@ std::string simple_wallet::simple_menu() menu_item += "\"transfer
\" - Transfers to
. | [-p] []...[] []...[]\n"; menu_item += "\"save\" - Save wallet synchronized blockchain data.\n"; menu_item += "\"save_keys\" - Saves wallet private keys to \"_conceal_backup.txt\".\n"; + menu_item += "\"withdraw \" - Withdraw a deposit from the blockchain.\n"; return menu_item; } @@ -2152,6 +2154,65 @@ bool simple_wallet::deposit(const std::vector &args) return true; } +bool simple_wallet::withdraw(const std::vector &args) +{ + if (args.size() != 1) + { + logger(ERROR) << "Usage: withdraw "; + return true; + } + + try + { + if (m_wallet->getDepositCount() == 0) + { + logger(ERROR) << "No deposits have been made in this wallet."; + return true; + } + + uint64_t deposit_id = boost::lexical_cast(args[0]); + uint64_t deposit_fee = cn::parameters::MINIMUM_FEE_V2; + + cn::WalletHelper::SendCompleteResultObserver sent; + WalletHelper::IWalletRemoveObserverGuard removeGuard(*m_wallet, sent); + + cn::TransactionId tx = m_wallet->withdrawDeposit(deposit_id, deposit_fee); + + if (tx == WALLET_LEGACY_INVALID_DEPOSIT_ID) + { + fail_msg_writer() << "Can't withdraw money"; + return true; + } + + std::error_code sendError = sent.wait(tx); + removeGuard.removeObserver(); + + if (sendError) + { + fail_msg_writer() << sendError.message(); + return true; + } + + cn::Deposit d_info; + m_wallet->getDeposit(tx, d_info); + success_msg_writer(true) << "Money has successfully been withdrawn\n\ttransaction hash: " << common::podToHex(d_info.transactionHash); + + try + { + cn::WalletHelper::storeWallet(*m_wallet, m_wallet_file); + } + catch (const std::exception& e) + { + fail_msg_writer() << e.what(); + return true; + } + } + catch (std::exception &e) + { + fail_msg_writer() << "failed to withdraw deposit: " << e.what(); + } +} + int main(int argc, char* argv[]) { #ifdef _WIN32 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); diff --git a/src/SimpleWallet/SimpleWallet.h b/src/SimpleWallet/SimpleWallet.h index 6bd63e21..d1cf11ef 100644 --- a/src/SimpleWallet/SimpleWallet.h +++ b/src/SimpleWallet/SimpleWallet.h @@ -97,6 +97,7 @@ namespace cn bool save_keys_to_file(const std::vector &args); bool deposit(const std::vector &args); + bool withdraw(const std::vector &args); bool list_deposits(const std::vector &args); std::string simple_menu(); From c606cd17689c8d7582c80ea91317547864964df3 Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Mon, 21 Feb 2022 18:05:38 +0000 Subject: [PATCH 05/48] Confirm deposit --- src/SimpleWallet/SimpleWallet.cpp | 32 +++++++++++++++++++++++++++++++ src/SimpleWallet/SimpleWallet.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index c84cc144..ab59894b 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -2213,6 +2213,38 @@ bool simple_wallet::withdraw(const std::vector &args) } } +bool simple_wallet::confirm_deposit(uint64_t term, uint64_t amount) +{ + uint64_t intrest = m_currency.calculateInterestV3(amount, term); + + logger(INFO) << "Confirm deposit details:\n" + << "\tAmount: " << amount << "\n" + << "\tMonths: " << term / 21900 << "\n" + << "\tIntrest: " << intrest << "\n" + << "Create deposit? (y/n) "; + + char c; + do { + std::string answer; + std::getline(std::cin, answer); + c = answer[0]; + + if (!(c == 'Y' || c == 'y' || c == 'N' || c == 'n')) + { + logger(ERROR) << "Unknown command: " << c; + } + else + { + break; + } + } while (true); + + if (c == 'N' || c == 'n') + return false; + + return true; +} + int main(int argc, char* argv[]) { #ifdef _WIN32 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); diff --git a/src/SimpleWallet/SimpleWallet.h b/src/SimpleWallet/SimpleWallet.h index d1cf11ef..cfcf27c3 100644 --- a/src/SimpleWallet/SimpleWallet.h +++ b/src/SimpleWallet/SimpleWallet.h @@ -99,6 +99,7 @@ namespace cn bool deposit(const std::vector &args); bool withdraw(const std::vector &args); bool list_deposits(const std::vector &args); + bool confirm_deposit(uint64_t term, uint64_t amount); std::string simple_menu(); std::string extended_menu(); From c009c7cad96369dbe14b3b89e4cbae6adb243bd6 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Mon, 21 Feb 2022 18:12:49 +0000 Subject: [PATCH 06/48] Missing semi-colon 90s error, flashbacks --- src/SimpleWallet/SimpleWallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index ab59894b..e6eefd66 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -2096,7 +2096,7 @@ bool simple_wallet::deposit(const std::vector &args) if (!confirm_deposit(deposit_term, deposit_amount)) { - logger(ERROR) << "Deposit is not being created." + logger(ERROR) << "Deposit is not being created."; return true; } From 0fe420ee01e7a168eea1aad420617e633e5be83a Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Sun, 27 Feb 2022 14:47:11 +0000 Subject: [PATCH 07/48] Remove do while true Return false instead of breaking Fix spelling --- src/SimpleWallet/SimpleWallet.cpp | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index e6eefd66..d8a9677b 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -2215,29 +2215,24 @@ bool simple_wallet::withdraw(const std::vector &args) bool simple_wallet::confirm_deposit(uint64_t term, uint64_t amount) { - uint64_t intrest = m_currency.calculateInterestV3(amount, term); + uint64_t interest = m_currency.calculateInterestV3(amount, term); logger(INFO) << "Confirm deposit details:\n" - << "\tAmount: " << amount << "\n" + << "\tAmount: " << m_currency.formatAmount(amount) << "\n" << "\tMonths: " << term / 21900 << "\n" - << "\tIntrest: " << intrest << "\n" + << "\tInterest: " << m_currency.formatAmount(interest) << "\n" << "Create deposit? (y/n) "; char c; - do { - std::string answer; - std::getline(std::cin, answer); - c = answer[0]; + std::string answer; + std::getline(std::cin, answer); + c = answer[0]; - if (!(c == 'Y' || c == 'y' || c == 'N' || c == 'n')) - { - logger(ERROR) << "Unknown command: " << c; - } - else - { - break; - } - } while (true); + if (!(c == 'Y' || c == 'y' || c == 'N' || c == 'n')) + { + logger(ERROR) << "Unknown command: " << c; + return false; + } if (c == 'N' || c == 'n') return false; From 6209c34f1b2840e8f76c58b2fb748e2884385cc8 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Mon, 28 Feb 2022 15:42:10 +0000 Subject: [PATCH 08/48] Update confirm deposit function --- src/SimpleWallet/SimpleWallet.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index d8a9677b..1713fc93 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -2220,24 +2220,26 @@ bool simple_wallet::confirm_deposit(uint64_t term, uint64_t amount) logger(INFO) << "Confirm deposit details:\n" << "\tAmount: " << m_currency.formatAmount(amount) << "\n" << "\tMonths: " << term / 21900 << "\n" - << "\tInterest: " << m_currency.formatAmount(interest) << "\n" - << "Create deposit? (y/n) "; + << "\tInterest: " << m_currency.formatAmount(interest) << "\n"; - char c; - std::string answer; - std::getline(std::cin, answer); - c = answer[0]; - - if (!(c == 'Y' || c == 'y' || c == 'N' || c == 'n')) + while (true) { - logger(ERROR) << "Unknown command: " << c; - return false; - } + logger(INFO) << "Is this correct? (Y/N): "; - if (c == 'N' || c == 'n') - return false; + char c; + std::cin >> c; + c = std::tolower(c); - return true; + if (c == 'y') + return true; + else if (c == 'n') + return false; + else + logger(ERROR) << "Bad input, please enter either Y or N."; + } + } + + return false; } int main(int argc, char* argv[]) { From 1c54517068e37f11d2c575cf40d78732573f3de4 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Mon, 28 Feb 2022 17:35:55 +0000 Subject: [PATCH 09/48] Stray brace --- src/SimpleWallet/SimpleWallet.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 1713fc93..5c5370ce 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -2236,7 +2236,6 @@ bool simple_wallet::confirm_deposit(uint64_t term, uint64_t amount) return false; else logger(ERROR) << "Bad input, please enter either Y or N."; - } } return false; From c5cb645f91a51cfd6f3493291da7ce0114a899a3 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Mon, 28 Feb 2022 18:31:20 +0000 Subject: [PATCH 10/48] Trigger rebuild for tests Ive been sus of tests for a while now, thinking one every X times during tests it fails --- src/SimpleWallet/SimpleWallet.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 5c5370ce..08f9c5a3 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -2231,11 +2231,17 @@ bool simple_wallet::confirm_deposit(uint64_t term, uint64_t amount) c = std::tolower(c); if (c == 'y') + { return true; + } else if (c == 'n') + { return false; + } else + { logger(ERROR) << "Bad input, please enter either Y or N."; + } } return false; From cc170ba15de07f5ff2310156800a63b4ed527cf1 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Tue, 1 Mar 2022 18:50:28 +0000 Subject: [PATCH 11/48] Update deposit command Im absolutly sure that `confirm_deposit()` works as intended This follows the same logic as the tests (TestWalletLegacy.cpp) --- src/SimpleWallet/SimpleWallet.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 08f9c5a3..92d83617 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -2100,6 +2100,8 @@ bool simple_wallet::deposit(const std::vector &args) return true; } + logger(INFO) << "Creating deposit..."; + /* Use defaults for fee + mix in */ uint64_t deposit_fee = cn::parameters::MINIMUM_FEE_V2; uint64_t deposit_mix_in = cn::parameters::MINIMUM_MIXIN; @@ -2124,9 +2126,10 @@ bool simple_wallet::deposit(const std::vector &args) return true; } - cn::Deposit d_info; - m_wallet->getDeposit(tx, d_info); - success_msg_writer(true) << "Money successfully sent, transaction hash: " << common::podToHex(d_info.transactionHash); + cn::WalletLegacyTransaction d_info; + m_wallet->getTransaction(tx, d_info); + success_msg_writer(true) << "Money successfully sent, transaction hash: " << common::podToHex(d_info.transactionHash) + << "\n\tID: " << d_info.firstDepositId; try { @@ -2211,6 +2214,8 @@ bool simple_wallet::withdraw(const std::vector &args) { fail_msg_writer() << "failed to withdraw deposit: " << e.what(); } + + return true; } bool simple_wallet::confirm_deposit(uint64_t term, uint64_t amount) From 61c5520a02fe53a087088b556d5d0f82dbd2e11c Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Tue, 1 Mar 2022 19:27:24 +0000 Subject: [PATCH 12/48] Fix hash output Maybe we should make this universal across Deposit and WalletLegacyTransaction --- src/SimpleWallet/SimpleWallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 92d83617..1e713f5f 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -2128,7 +2128,7 @@ bool simple_wallet::deposit(const std::vector &args) cn::WalletLegacyTransaction d_info; m_wallet->getTransaction(tx, d_info); - success_msg_writer(true) << "Money successfully sent, transaction hash: " << common::podToHex(d_info.transactionHash) + success_msg_writer(true) << "Money successfully sent, transaction hash: " << common::podToHex(d_info.hash) << "\n\tID: " << d_info.firstDepositId; try From b783465b72ad10384e5dc62cfeece5363093058c Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Thu, 3 Mar 2022 17:47:40 +0000 Subject: [PATCH 13/48] Remove possible infinate loop while(true) with a return true statement? Just to be on the safe side --- src/SimpleWallet/SimpleWallet.cpp | 39 ++++++++++++++----------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 1e713f5f..aee6ed8b 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -2196,9 +2196,9 @@ bool simple_wallet::withdraw(const std::vector &args) return true; } - cn::Deposit d_info; - m_wallet->getDeposit(tx, d_info); - success_msg_writer(true) << "Money has successfully been withdrawn\n\ttransaction hash: " << common::podToHex(d_info.transactionHash); + cn::WalletLegacyTransaction d_info; + m_wallet->getTransaction(tx, d_info); + success_msg_writer(true) << "Money successfully sent, transaction hash: " << common::podToHex(d_info.hash); try { @@ -2227,26 +2227,23 @@ bool simple_wallet::confirm_deposit(uint64_t term, uint64_t amount) << "\tMonths: " << term / 21900 << "\n" << "\tInterest: " << m_currency.formatAmount(interest) << "\n"; - while (true) - { - logger(INFO) << "Is this correct? (Y/N): "; + logger(INFO) << "Is this correct? (Y/N): \n"; - char c; - std::cin >> c; - c = std::tolower(c); + char c; + std::cin >> c; + c = std::tolower(c); - if (c == 'y') - { - return true; - } - else if (c == 'n') - { - return false; - } - else - { - logger(ERROR) << "Bad input, please enter either Y or N."; - } + if (c == 'y') + { + return true; + } + else if (c == 'n') + { + return false; + } + else + { + logger(ERROR) << "Bad input, please enter either Y or N."; } return false; From ce563169b83717b534c0f9dde7a7450af612ff60 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Mon, 7 Mar 2022 12:30:05 +0000 Subject: [PATCH 14/48] List actual deposit info, not the tx that made the deposit --- src/SimpleWallet/SimpleWallet.cpp | 109 +++++++++++++++++------------- 1 file changed, 62 insertions(+), 47 deletions(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index aee6ed8b..f818048b 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -415,6 +415,18 @@ void printListTransfersHeader(LoggerRef& logger) { logger(INFO) << std::string(header.size(), '-'); } +void printListDepositsHeader(LoggerRef& logger) { + std::string header = makeCenteredString(4, "ID") + " "; + header += makeCenteredString(TOTAL_AMOUNT_MAX_WIDTH, "Amount") + " "; + header += makeCenteredString(TOTAL_AMOUNT_MAX_WIDTH, "Interest") + " "; + header += makeCenteredString(4, "Term") + " "; + header += makeCenteredString(8, "Status"); + header += makeCenteredString(UNLOCK_TIME_MAX_WIDTH, "Unlock Height"); + + logger(INFO) << header; + logger(INFO) << std::string(header.size(), '-'); +} + void printListTransfersItem(LoggerRef& logger, const WalletLegacyTransaction& txInfo, IWalletLegacy& wallet, const Currency& currency) { std::vector extraVec = common::asBinaryArray(txInfo.extra); @@ -551,59 +563,55 @@ bool askAliasesTransfersConfirmation(const std::map 0) + { + logger(INFO) << "Deposits:"; - logger(INFO, rowColor) - << " " << std::setw(HASH_MAX_WIDTH) << common::podToHex(txInfo.hash) - << " " << std::setw(TOTAL_AMOUNT_MAX_WIDTH) << currency.formatAmount(txInfo.totalAmount) - << " " << std::setw(FEE_MAX_WIDTH) << currency.formatAmount(txInfo.fee) - << " " << std::setw(BLOCK_MAX_WIDTH) << txInfo.blockHeight - << " " << std::setw(UNLOCK_TIME_MAX_WIDTH) << txInfo.unlockTime; + for (DepositId id = txInfo.firstDepositId; id < txInfo.firstDepositId + txInfo.depositCount; ++id) + { + wallet.getDeposit(id, deposit); + std::string is_locked_str = !deposit.locked ? "Unlocked" : "Locked"; - if (txInfo.totalAmount < 0) { - if (txInfo.depositCount > 0) { - logger(INFO, rowColor) << "deposits:"; - for (DepositId id = txInfo.firstDepositId; id < txInfo.firstDepositId + txInfo.depositCount; ++id) { - Deposit d; - wallet.getDeposit(id, d); - std::string is_locked = !d.locked ? "Unlocked" : "Locked"; - - logger(INFO, rowColor) - << "ID: " << id << "\n" - << "Amount: " << currency.formatAmount(d.amount) - << "Interest: " << currency.formatAmount(d.interest) - << "Term: " << d.term - << "Unlock Height: " << d.unlockHeight - << "Locked: " << is_locked; - } + logger(INFO, is_locked_clr) + << "ID: " << id << "\n" + << "Amount: " << currency.formatAmount(deposit.amount) + << "Interest: " << currency.formatAmount(deposit.interest) + << "Term: " << deposit.term + << "Status: " << is_locked_str + << "Unlock Height: " << deposit.unlockHeight; } } - logger(INFO, rowColor) << " "; //just to make logger print one endline + logger(INFO) << " "; //just to make logger print one endline } } -bool processServerFeeAddressResponse(const std::string& response, std::string& fee_address) { - try { - std::stringstream stream(response); - JsonValue json; - stream >> json; - - auto rootIt = json.getObject().find("fee_address"); - if (rootIt == json.getObject().end()) { - return false; - } +bool processServerFeeAddressResponse(const std::string& response, std::string& fee_address) +{ + try + { + std::stringstream stream(response); + JsonValue json; + stream >> json; - fee_address = rootIt->second.getString(); - } - catch (std::exception&) { - return false; + auto rootIt = json.getObject().find("fee_address"); + if (rootIt == json.getObject().end()) { + return false; } - return true; + fee_address = rootIt->second.getString(); + } + catch (std::exception&) + { + return false; + } + + return true; } std::string simple_wallet::get_commands_str(bool do_ext) { @@ -2002,6 +2010,7 @@ bool simple_wallet::list_deposits(const std::vector &args) std::string blockHeightString = ""; uint32_t blockHeight = 0; WalletLegacyTransaction txInfo; + Deposit deposit; /* get block height from arguments */ @@ -2021,26 +2030,32 @@ bool simple_wallet::list_deposits(const std::vector &args) for (size_t id = 0; id < depositsCount; ++id) { m_wallet->getTransaction(id, txInfo); - if (txInfo.state != WalletLegacyTransactionState::Active || txInfo.blockHeight == WALLET_LEGACY_UNCONFIRMED_TRANSACTION_HEIGHT) { + if (txInfo.state != WalletLegacyTransactionState::Active || txInfo.blockHeight == WALLET_LEGACY_UNCONFIRMED_TRANSACTION_HEIGHT) + { continue; } - if (!haveDeposits) { - printListTransfersHeader(logger); + if (!haveDeposits) + { + printListDepositsHeader(logger); haveDeposits = true; } - if (haveBlockHeight == false) { - printListDepositsItem(logger, txInfo, *m_wallet, m_currency); + if (haveBlockHeight == false) + { + printListDepositsItem(logger, txInfo, *m_wallet, m_currency, deposit); } else { if (txInfo.blockHeight >= blockHeight) - printListDepositsItem(logger, txInfo, *m_wallet, m_currency); + { + printListDepositsItem(logger, txInfo, *m_wallet, m_currency, deposit); + } } } - if (!haveDeposits) { + if (!haveDeposits) + { success_msg_writer() << "No deposits"; } From 628a9eff4dcca99c23906850c18967406a4ba49d Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Sat, 12 Mar 2022 18:01:33 +0000 Subject: [PATCH 15/48] Adjust `list_deposits` output Old output used to have a header to list each detail, now the output will list: ``` --- Deposit Info --- ID: Amount: Interest: Term: Status: Unlock Height: ``` deposit details will either be `BRIGHT_RED` if locked or `BRIGHT_GREEN` if unlocked --- src/SimpleWallet/SimpleWallet.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index f818048b..a10b027f 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -421,7 +421,6 @@ void printListDepositsHeader(LoggerRef& logger) { header += makeCenteredString(TOTAL_AMOUNT_MAX_WIDTH, "Interest") + " "; header += makeCenteredString(4, "Term") + " "; header += makeCenteredString(8, "Status"); - header += makeCenteredString(UNLOCK_TIME_MAX_WIDTH, "Unlock Height"); logger(INFO) << header; logger(INFO) << std::string(header.size(), '-'); @@ -576,11 +575,11 @@ void printListDepositsItem(LoggerRef& logger, const WalletLegacyTransaction& txI wallet.getDeposit(id, deposit); std::string is_locked_str = !deposit.locked ? "Unlocked" : "Locked"; + logger(INFO, BRIGHT_YELLOW) << "\t--- Deposit Info ---"; logger(INFO, is_locked_clr) << "ID: " << id << "\n" << "Amount: " << currency.formatAmount(deposit.amount) << "Interest: " << currency.formatAmount(deposit.interest) - << "Term: " << deposit.term << "Status: " << is_locked_str << "Unlock Height: " << deposit.unlockHeight; } @@ -2037,7 +2036,7 @@ bool simple_wallet::list_deposits(const std::vector &args) if (!haveDeposits) { - printListDepositsHeader(logger); + //printListDepositsHeader(logger); haveDeposits = true; } From 9994e6284445eea4c0c68f82ce40ee03d7d8fccd Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Fri, 25 Mar 2022 20:06:06 +0000 Subject: [PATCH 16/48] Don't overthink it man. Works on my machine --- src/SimpleWallet/SimpleWallet.cpp | 85 ++++++++----------------------- 1 file changed, 20 insertions(+), 65 deletions(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index a10b027f..16061513 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -416,14 +416,14 @@ void printListTransfersHeader(LoggerRef& logger) { } void printListDepositsHeader(LoggerRef& logger) { - std::string header = makeCenteredString(4, "ID") + " "; - header += makeCenteredString(TOTAL_AMOUNT_MAX_WIDTH, "Amount") + " "; - header += makeCenteredString(TOTAL_AMOUNT_MAX_WIDTH, "Interest") + " "; - header += makeCenteredString(4, "Term") + " "; + std::string header = makeCenteredString(8, "ID") + " | "; + header += makeCenteredString(20, "Amount") + " | "; + header += makeCenteredString(20, "Interest") + " | "; + header += makeCenteredString(16, "Unlocked Height") + " | "; header += makeCenteredString(8, "Status"); logger(INFO) << header; - logger(INFO) << std::string(header.size(), '-'); + logger(INFO) << std::string(header.size(), '='); } void printListTransfersItem(LoggerRef& logger, const WalletLegacyTransaction& txInfo, IWalletLegacy& wallet, const Currency& currency) { @@ -564,24 +564,20 @@ bool askAliasesTransfersConfirmation(const std::map 0) + for (DepositId id = 0; id < wallet.getDepositCount(); ++id) { - logger(INFO) << "Deposits:"; - - for (DepositId id = txInfo.firstDepositId; id < txInfo.firstDepositId + txInfo.depositCount; ++id) + if (id != cn::WALLET_LEGACY_INVALID_DEPOSIT_ID) { wallet.getDeposit(id, deposit); - std::string is_locked_str = !deposit.locked ? "Unlocked" : "Locked"; - logger(INFO, BRIGHT_YELLOW) << "\t--- Deposit Info ---"; - logger(INFO, is_locked_clr) - << "ID: " << id << "\n" - << "Amount: " << currency.formatAmount(deposit.amount) - << "Interest: " << currency.formatAmount(deposit.interest) - << "Status: " << is_locked_str - << "Unlock Height: " << deposit.unlockHeight; + std::string is_locked_clr = !deposit.locked ? BRIGHT_GREEN : BRIGHT_RED; + std::string is_locked_str = !deposit.locked ? "Unlocked" : "Locked"; + + logger(INFO, is_locked_clr) << std::left << std::setw(8) << makeCenteredString(8, std::to_string(id)) + << " | " << std::setw(20) << makeCenteredString(20, currency.formatAmount(deposit.amount)) + << " | " << std::setw(20) << makeCenteredString(20, currency.formatAmount(deposit.interest)) + << " | " << std::setw(16) << makeCenteredString(16, std::to_string(deposit.height + deposit.term)) + << " | " << std::setw(8) << makeCenteredString(8, is_locked_str); } } @@ -2004,60 +2000,19 @@ bool simple_wallet::save_keys_to_file(const std::vector& args) bool simple_wallet::list_deposits(const std::vector &args) { - bool haveDeposits = false; - bool haveBlockHeight = false; - std::string blockHeightString = ""; - uint32_t blockHeight = 0; + bool haveDeposits = m_wallet->getDepositCount() > 0; WalletLegacyTransaction txInfo; Deposit deposit; - - /* get block height from arguments */ - if (args.empty()) - { - haveBlockHeight = false; - } - else - { - blockHeightString = args[0]; - haveBlockHeight = true; - blockHeight = atoi(blockHeightString.c_str()); - } - - size_t depositsCount = m_wallet->getDepositCount(); - - for (size_t id = 0; id < depositsCount; ++id) - { - m_wallet->getTransaction(id, txInfo); - if (txInfo.state != WalletLegacyTransactionState::Active || txInfo.blockHeight == WALLET_LEGACY_UNCONFIRMED_TRANSACTION_HEIGHT) - { - continue; - } - - if (!haveDeposits) - { - //printListDepositsHeader(logger); - haveDeposits = true; - } - - if (haveBlockHeight == false) - { - printListDepositsItem(logger, txInfo, *m_wallet, m_currency, deposit); - } - else - { - if (txInfo.blockHeight >= blockHeight) - { - printListDepositsItem(logger, txInfo, *m_wallet, m_currency, deposit); - } - } - } - if (!haveDeposits) { success_msg_writer() << "No deposits"; + return true; } + printListDepositsHeader(logger); + printListDepositsItem(logger, txInfo, *m_wallet, m_currency, deposit); + return true; } From e911539c033f5281a79a75b0a35b138c83e22b5d Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Sun, 27 Mar 2022 02:28:09 +0100 Subject: [PATCH 17/48] Store deposit height & unlockHeight when inserting new deposit Fixes calling `cn::Deposit::unlockHeight` + `cn::Deposit::height` --- src/WalletLegacy/WalletUserTransactionsCache.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/WalletLegacy/WalletUserTransactionsCache.cpp b/src/WalletLegacy/WalletUserTransactionsCache.cpp index a01b7abc..6259f046 100644 --- a/src/WalletLegacy/WalletUserTransactionsCache.cpp +++ b/src/WalletLegacy/WalletUserTransactionsCache.cpp @@ -617,6 +617,8 @@ DepositId WalletUserTransactionsCache::insertNewDeposit(const TransactionOutputI deposit.spendingTransactionId = WALLET_LEGACY_INVALID_TRANSACTION_ID; deposit.interest = currency.calculateInterest(deposit.amount, deposit.term, height); deposit.locked = true; + deposit.height = height; + deposit.unlockHeight = deposit.height + deposit.term; return insertDeposit(deposit, depositOutput.outputInTransaction, depositOutput.transactionHash); } From 9567b81e3f7fb443fae823198fe7f40fe3a5b067 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Sun, 27 Mar 2022 02:29:28 +0100 Subject: [PATCH 18/48] Update output for list_deposits --- src/SimpleWallet/SimpleWallet.cpp | 34 +++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 16061513..0425e2b9 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -420,7 +420,7 @@ void printListDepositsHeader(LoggerRef& logger) { header += makeCenteredString(20, "Amount") + " | "; header += makeCenteredString(20, "Interest") + " | "; header += makeCenteredString(16, "Unlocked Height") + " | "; - header += makeCenteredString(8, "Status"); + header += makeCenteredString(10, "State"); logger(INFO) << header; logger(INFO) << std::string(header.size(), '='); @@ -566,19 +566,27 @@ void printListDepositsItem(LoggerRef& logger, const WalletLegacyTransaction& txI { for (DepositId id = 0; id < wallet.getDepositCount(); ++id) { - if (id != cn::WALLET_LEGACY_INVALID_DEPOSIT_ID) - { - wallet.getDeposit(id, deposit); + bool r = wallet.getDeposit(id, deposit); - std::string is_locked_clr = !deposit.locked ? BRIGHT_GREEN : BRIGHT_RED; - std::string is_locked_str = !deposit.locked ? "Unlocked" : "Locked"; - - logger(INFO, is_locked_clr) << std::left << std::setw(8) << makeCenteredString(8, std::to_string(id)) - << " | " << std::setw(20) << makeCenteredString(20, currency.formatAmount(deposit.amount)) - << " | " << std::setw(20) << makeCenteredString(20, currency.formatAmount(deposit.interest)) - << " | " << std::setw(16) << makeCenteredString(16, std::to_string(deposit.height + deposit.term)) - << " | " << std::setw(8) << makeCenteredString(8, is_locked_str); - } + if (!r) + logger(ERROR) << "Couldn't get deposit information for: " << id; + + std::string is_locked_clr = !deposit.locked ? BRIGHT_GREEN : BRIGHT_RED; + + /* follow gui logic */ + std::string state = ""; + if (deposit.locked) + state = "Locked"; + else if (deposit.spendingTransactionId == cn::WALLET_LEGACY_INVALID_TRANSACTION_ID) + state = "Unlocked"; + else + state = "Spent"; + + logger(INFO, is_locked_clr) << std::left << std::setw(8) << makeCenteredString(8, std::to_string(id)) + << " | " << std::setw(20) << makeCenteredString(20, currency.formatAmount(deposit.amount)) + << " | " << std::setw(20) << makeCenteredString(20, currency.formatAmount(deposit.interest)) + << " | " << std::setw(16) << makeCenteredString(16, std::to_string(deposit.unlockHeight)) + << " | " << std::setw(10) << makeCenteredString(10, state); } logger(INFO) << " "; //just to make logger print one endline From 54c22307c88c26488309d03985dee47a3523bd4d Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Sun, 27 Mar 2022 22:21:42 +0100 Subject: [PATCH 19/48] Store deposit height & unlockHeight when doing multisig tx --- src/WalletLegacy/WalletTransactionSender.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/WalletLegacy/WalletTransactionSender.cpp b/src/WalletLegacy/WalletTransactionSender.cpp index 4c437267..42bf35ea 100644 --- a/src/WalletLegacy/WalletTransactionSender.cpp +++ b/src/WalletLegacy/WalletTransactionSender.cpp @@ -549,6 +549,7 @@ namespace cn deposit.creatingTransactionId = context->transactionId; deposit.spendingTransactionId = WALLET_LEGACY_INVALID_TRANSACTION_ID; uint32_t height = transactionInfo.blockHeight; + deposit.unlockHeight = transactionInfo.blockHeight + context->depositTerm; deposit.interest = m_currency.calculateInterest(deposit.amount, deposit.term, height); deposit.locked = true; DepositId depositId = m_transactionsCache.insertDeposit(deposit, depositIndex, transaction->getTransactionHash()); @@ -1081,4 +1082,4 @@ namespace cn } } -} /* namespace cn */ \ No newline at end of file +} /* namespace cn */ From f8ee2dbc5c774fe66126eab0ba6a7385b84c2b05 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Sun, 27 Mar 2022 22:25:15 +0100 Subject: [PATCH 20/48] Store deposit height and use that to calculate interest --- src/WalletLegacy/WalletTransactionSender.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WalletLegacy/WalletTransactionSender.cpp b/src/WalletLegacy/WalletTransactionSender.cpp index 42bf35ea..0f13c70b 100644 --- a/src/WalletLegacy/WalletTransactionSender.cpp +++ b/src/WalletLegacy/WalletTransactionSender.cpp @@ -548,9 +548,9 @@ namespace cn deposit.term = context->depositTerm; deposit.creatingTransactionId = context->transactionId; deposit.spendingTransactionId = WALLET_LEGACY_INVALID_TRANSACTION_ID; - uint32_t height = transactionInfo.blockHeight; + deposit.height = transactionInfo.blockHeight; deposit.unlockHeight = transactionInfo.blockHeight + context->depositTerm; - deposit.interest = m_currency.calculateInterest(deposit.amount, deposit.term, height); + deposit.interest = m_currency.calculateInterest(deposit.amount, deposit.term, deposit.height); deposit.locked = true; DepositId depositId = m_transactionsCache.insertDeposit(deposit, depositIndex, transaction->getTransactionHash()); transactionInfo.firstDepositId = depositId; From 1a843ea69525b45dee92a13e40a8bd4810ff0b4b Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Tue, 29 Mar 2022 02:06:13 +0100 Subject: [PATCH 21/48] Serialize and add deposit to Legacy --- src/WalletLegacy/WalletUserTransactionsCache.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/WalletLegacy/WalletUserTransactionsCache.cpp b/src/WalletLegacy/WalletUserTransactionsCache.cpp index 6259f046..d3b33c37 100644 --- a/src/WalletLegacy/WalletUserTransactionsCache.cpp +++ b/src/WalletLegacy/WalletUserTransactionsCache.cpp @@ -47,6 +47,8 @@ void serialize(LegacyDeposit& deposit, ISerializer& serializer) { serializer(deposit.term, "term"); serializer(deposit.amount, "amount"); serializer(deposit.interest, "interest"); + serializer(deposit.height, "height"); + serializer(deposit.unlockedHeight, "unlockedHeight"); } void serialize(LegacyDepositInfo& depositInfo, ISerializer& serializer) { @@ -101,6 +103,8 @@ void convertLegacyDeposits(const std::vector& legacyDeposits, info.deposit.term = legacyDepositInfo.deposit.term; info.deposit.locked = true; info.outputInTransaction = legacyDepositInfo.outputInTransaction; + info.deposit.height = legacyDepositInfo.deposit.height; + info.deposit.unlockHeight = legacyDepositInfo.deposit.unlockHeight; deposits.push_back(std::move(info)); } From 65d6a8d86d582b7b4a3964fb440cd5d9bf998e27 Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Tue, 29 Mar 2022 02:18:18 +0100 Subject: [PATCH 22/48] Deposit changes * adds new file DepositHelper to feed infomation * adds get_deposit(id) to iwalletlegacy so we can call deposit = get_deposit(id) * add height and unlockheight to legacydeposit * add notes to previous work --- include/IWalletLegacy.h | 2 + src/SimpleWallet/DepositHelper.cpp | 132 ++++++++++++++++++ src/SimpleWallet/DepositHelper.h | 81 +++++++++++ src/SimpleWallet/SimpleWallet.cpp | 85 +++++++++-- src/SimpleWallet/SimpleWallet.h | 3 + src/WalletLegacy/WalletLegacy.cpp | 5 + src/WalletLegacy/WalletLegacy.h | 2 + src/WalletLegacy/WalletTransactionSender.cpp | 4 +- .../WalletUserTransactionsCache.cpp | 4 +- 9 files changed, 301 insertions(+), 17 deletions(-) create mode 100644 src/SimpleWallet/DepositHelper.cpp create mode 100644 src/SimpleWallet/DepositHelper.h diff --git a/include/IWalletLegacy.h b/include/IWalletLegacy.h index 5971c6b0..dff2e6b1 100644 --- a/include/IWalletLegacy.h +++ b/include/IWalletLegacy.h @@ -156,6 +156,8 @@ class IWalletLegacy { virtual TransactionId withdrawDeposit(const DepositId& depositId, uint64_t fee) = 0; virtual TransactionId withdrawDeposits(const std::vector& depositIds, uint64_t fee) = 0; virtual std::error_code cancelTransaction(size_t transferId) = 0; + virtual Deposit get_deposit(DepositId depositId) = 0; + }; diff --git a/src/SimpleWallet/DepositHelper.cpp b/src/SimpleWallet/DepositHelper.cpp new file mode 100644 index 00000000..39f7652e --- /dev/null +++ b/src/SimpleWallet/DepositHelper.cpp @@ -0,0 +1,132 @@ +#include +#include + +#include "DepositHelper.h" + +#include "CryptoNoteConfig.h" + +#include "Common/StringTools.h" + +namespace cn +{ + uint32_t deposit_helper::deposit_term(cn::Deposit deposit) + { + return deposit.term; + } + + std::string deposit_helper::deposit_amount(cn::Deposit deposit, const Currency& currency) + { + return currency.formatAmount(deposit.amount); + } + + std::string deposit_helper::deposit_interest(cn::Deposit deposit, const Currency& currency) + { + return currency.formatAmount(deposit.interest); + } + + std::string deposit_helper::deposit_status(cn::Deposit deposit) + { + std::string status_str = ""; + + if (deposit.locked) + status_str = "Locked"; + else if (deposit.spendingTransactionId == cn::WALLET_LEGACY_INVALID_TRANSACTION_ID) + status_str = "Unlocked"; + else + status_str = "Spent"; + + return status_str; + } + + size_t deposit_helper::deposit_creating_tx_id(cn::Deposit deposit) + { + return deposit.creatingTransactionId; + } + + size_t deposit_helper::deposit_spending_tx_id(cn::Deposit deposit) + { + return deposit.spendingTransactionId; + } + + uint64_t deposit_helper::deposit_unlock_height(cn::Deposit deposit) + { + uint64_t u_height = deposit.unlockHeight; + + if (u_height == 0) + u_height = deposit.height + deposit.term; + + if (u_height == 0 || u_height % 21900) + u_height = 0; + + return u_height; + } + + uint64_t deposit_helper::deposit_height(cn::Deposit deposit) + { + return deposit.height; + } + + std::string deposit_helper::get_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency) + { + std::string unlock_str = ""; + + bool bad_unlock = deposit.unlockHeight > cn::parameters::CRYPTONOTE_MAX_BLOCK_NUMBER; + if (bad_unlock) + unlock_str = "Please wait."; + else + unlock_str = std::to_string(deposit_unlock_height(deposit)); + + bool bad_unlock2 = unlock_str == "0"; + if (bad_unlock2) + unlock_str = "ERROR"; + + std::stringstream full_info; + + full_info << std::left << + std::setw(8) << std::to_string(did) << " | " << + std::setw(20) << deposit_amount(deposit, currency) << " | " << + std::setw(20) << deposit_interest(deposit, currency) << " | " << + std::setw(16) << unlock_str << " | " << + std::setw(10) << deposit_status(deposit); + + std::string as_str = full_info.str(); + + return as_str; + } + + std::string deposit_helper::get_full_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency) + { + std::string unlock_str = ""; + + bool bad_unlock = deposit_unlock_height(deposit) > cn::parameters::CRYPTONOTE_MAX_BLOCK_NUMBER; + if (bad_unlock) + unlock_str = "Please wait."; + else + unlock_str = std::to_string(deposit_unlock_height(deposit)); + + bool bad_unlock2 = unlock_str == "0"; + if (bad_unlock2) + unlock_str = "ERROR"; + + uint64_t unlocked = deposit_height(deposit) + deposit_term(deposit); + std::string unlocked_str = ""; + + bool bad_unlock3 = unlocked_str == "0" || unlocked % 21900; + if (bad_unlock3) + unlocked_str = "ERROR"; + + std::stringstream full_info; + + full_info << + "ID: " << std::to_string(did) << "\n" << + "Amount: " << deposit_amount(deposit, currency) << "\n" << + "Interest: " << deposit_interest(deposit, currency) << "\n" << + "Height: " << deposit_height(deposit) << "\n" << + "Unlock Height: " << unlock_str << " | " << unlocked << "\n" << + "Status: " << deposit_status(deposit) << "\n"; + + std::string as_str = full_info.str(); + + return as_str; + } +} \ No newline at end of file diff --git a/src/SimpleWallet/DepositHelper.h b/src/SimpleWallet/DepositHelper.h new file mode 100644 index 00000000..8dfdf17d --- /dev/null +++ b/src/SimpleWallet/DepositHelper.h @@ -0,0 +1,81 @@ + + + +#include + +#include "IWalletLegacy.h" + +#include "CryptoNoteCore/Currency.h" + +namespace cn +{ + class deposit_helper + { + public: + /** + * @param deposit - obtain information from deposit + * @return - returns deposit term, should be multiple of 21900 + **/ + uint32_t deposit_term(cn::Deposit deposit); + + /** + * @param deposit - obtain information from deposit + * @param currency - format output amount + * @return - returns deposit amount as string + **/ + std::string deposit_amount(cn::Deposit deposit, const Currency& currency); + + /** + * @param deposit - obtain information from deposit + * @param currency - format output amount + * @return - returns deposit interest based of amount and term as string + **/ + std::string deposit_interest(cn::Deposit deposit, const Currency& currency); + + /** + * @param deposit - obtain information from deposit + * @return - "Locked", "Unlocked" or "Spent" depending on state of deposit + **/ + std::string deposit_status(cn::Deposit deposit); + + /** + * @param deposit - obtain information from deposit + * @return - returns deposit creatingTransactionId + **/ + size_t deposit_creating_tx_id(cn::Deposit deposit); + + /** + * @param deposit - obtain information from deposit + * @return - returns deposit spendingTransactionId + **/ + size_t deposit_spending_tx_id(cn::Deposit deposit); + + /** + * @param deposit - obtain information from deposit + * @return - returns unlock height from height deposited + term + **/ + uint64_t deposit_unlock_height(cn::Deposit deposit); + + /** + * @param deposit - obtain information from deposit + * @return - returns deposit height + **/ + uint64_t deposit_height(cn::Deposit deposit); + + /** + * @param deposit - obtain information from deposit + * @param did - id to search deposit + * @param currency - used to supply amount and interest + * @return - returns deposit info string in single row style + **/ + std::string get_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency); + + /** + * @param deposit - obtain information from deposit + * @param did - id to search deposit + * @param currency - used to supply amount and interest + * @return - returns full deposit info string + **/ + std::string get_full_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency); + }; +} \ No newline at end of file diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 0425e2b9..c6389b81 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -419,10 +419,10 @@ void printListDepositsHeader(LoggerRef& logger) { std::string header = makeCenteredString(8, "ID") + " | "; header += makeCenteredString(20, "Amount") + " | "; header += makeCenteredString(20, "Interest") + " | "; - header += makeCenteredString(16, "Unlocked Height") + " | "; + header += makeCenteredString(16, "Unlock Height") + " | "; header += makeCenteredString(10, "State"); - logger(INFO) << header; + logger(INFO) << "\n" << header; logger(INFO) << std::string(header.size(), '='); } @@ -561,31 +561,65 @@ bool askAliasesTransfersConfirmation(const std::map cn::parameters::CRYPTONOTE_MAX_BLOCK_NUMBER; + std::string unlock_str = ""; + + if (bad_unlock) + unlock_str = "Please wait."; + else + unlock_str = std::to_string(deposit.unlockHeight); + /* now print this deposits information */ logger(INFO, is_locked_clr) << std::left << std::setw(8) << makeCenteredString(8, std::to_string(id)) << " | " << std::setw(20) << makeCenteredString(20, currency.formatAmount(deposit.amount)) << " | " << std::setw(20) << makeCenteredString(20, currency.formatAmount(deposit.interest)) - << " | " << std::setw(16) << makeCenteredString(16, std::to_string(deposit.unlockHeight)) + << " | " << std::setw(16) << makeCenteredString(16, unlock_str) << " | " << std::setw(10) << makeCenteredString(10, state); } @@ -684,6 +718,7 @@ simple_wallet::simple_wallet(platform_system::Dispatcher& dispatcher, const cn:: m_consoleHandler.setHandler("list_deposits", boost::bind(&simple_wallet::list_deposits, this, boost::arg<1>()), "Show all known deposits from this wallet"); m_consoleHandler.setHandler("deposit", boost::bind(&simple_wallet::deposit, this, boost::arg<1>()), "deposit - Create a deposit"); m_consoleHandler.setHandler("withdraw", boost::bind(&simple_wallet::withdraw, this, boost::arg<1>()), "withdraw - Withdraw a deposit"); + m_consoleHandler.setHandler("deposit_info", boost::bind(&simple_wallet::deposit_info, this, boost::arg<1>()), "deposit_info - Get infomation for deposit "); } std::string simple_wallet::simple_menu() @@ -694,6 +729,7 @@ std::string simple_wallet::simple_menu() menu_item += "\"balance\" - Shows wallet balance.\n"; menu_item += "\"bc_height\" - Shows current blockchain height.\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"; menu_item += "\"export_keys\" - Displays backup keys.\n"; menu_item += "\"help\" | \"ext_help\" - Shows this help dialog or extended help dialog.\n"; @@ -1946,8 +1982,8 @@ bool simple_wallet::run() { std::cout << std::endl; - std::string addr_start = m_wallet->getAddress().substr(0, 6); - m_consoleHandler.start(false, "[wallet " + addr_start + "]: ", common::console::Color::BrightYellow); + std::string addr_start = m_wallet->getAddress().substr(0, 10); + m_consoleHandler.start(false, "[" + addr_start + "]: ", common::console::Color::BrightYellow); return true; } //---------------------------------------------------------------------------------------------------- @@ -2009,8 +2045,6 @@ bool simple_wallet::save_keys_to_file(const std::vector& args) bool simple_wallet::list_deposits(const std::vector &args) { bool haveDeposits = m_wallet->getDepositCount() > 0; - WalletLegacyTransaction txInfo; - Deposit deposit; if (!haveDeposits) { @@ -2019,7 +2053,15 @@ bool simple_wallet::list_deposits(const std::vector &args) } printListDepositsHeader(logger); - printListDepositsItem(logger, txInfo, *m_wallet, m_currency, deposit); + //printListDepositsItem(logger, *m_wallet, m_currency); + + /* go through deposits ids for the amount of deposits in wallet */ + for (DepositId id = 0; id < m_wallet->getDepositCount(); ++id) + { + /* get deposit info from id and store it to deposit */ + Deposit deposit = m_wallet->get_deposit(id); + logger(INFO) << m_dhelper.get_deposit_info(deposit, id, m_currency); + } return true; } @@ -2195,6 +2237,21 @@ bool simple_wallet::withdraw(const std::vector &args) return true; } +bool simple_wallet::deposit_info(const std::vector &args) +{ + if (args.size() != 1) + { + logger(ERROR) << "Usage: withdraw "; + return true; + } + uint64_t deposit_id = boost::lexical_cast(args[0]); + cn::Deposit deposit = m_wallet->get_deposit(deposit_id); + + logger(INFO) << m_dhelper.get_full_deposit_info(deposit, deposit_id, m_currency); + + return true; +} + bool simple_wallet::confirm_deposit(uint64_t term, uint64_t amount) { uint64_t interest = m_currency.calculateInterestV3(amount, term); diff --git a/src/SimpleWallet/SimpleWallet.h b/src/SimpleWallet/SimpleWallet.h index cfcf27c3..873956a7 100644 --- a/src/SimpleWallet/SimpleWallet.h +++ b/src/SimpleWallet/SimpleWallet.h @@ -16,6 +16,7 @@ #include "IWalletLegacy.h" #include "PasswordContainer.h" +#include "DepositHelper.h" #include "Common/ConsoleHandler.h" #include "CryptoNoteCore/CryptoNoteBasicImpl.h" @@ -99,6 +100,7 @@ namespace cn bool deposit(const std::vector &args); bool withdraw(const std::vector &args); bool list_deposits(const std::vector &args); + bool deposit_info(const std::vector &args); bool confirm_deposit(uint64_t term, uint64_t amount); std::string simple_menu(); @@ -185,6 +187,7 @@ namespace cn logging::LoggerManager& logManager; platform_system::Dispatcher& m_dispatcher; logging::LoggerRef logger; + cn::deposit_helper m_dhelper; std::unique_ptr m_node; std::unique_ptr m_wallet; diff --git a/src/WalletLegacy/WalletLegacy.cpp b/src/WalletLegacy/WalletLegacy.cpp index 83cb2131..81da6201 100644 --- a/src/WalletLegacy/WalletLegacy.cpp +++ b/src/WalletLegacy/WalletLegacy.cpp @@ -1496,6 +1496,11 @@ bool WalletLegacy::checkWalletPassword(std::istream& source, const std::string& return serializer.deserialize(source, password); } +Deposit WalletLegacy::get_deposit(DepositId depositId) +{ + return m_transactionsCache.getDeposit(depositId); +} + //KK diff --git a/src/WalletLegacy/WalletLegacy.h b/src/WalletLegacy/WalletLegacy.h index 20c2dbac..3cc53513 100644 --- a/src/WalletLegacy/WalletLegacy.h +++ b/src/WalletLegacy/WalletLegacy.h @@ -108,6 +108,8 @@ class WalletLegacy : virtual void getAccountKeys(AccountKeys& keys) override; + virtual Deposit get_deposit(DepositId depositId); + private: // IBlockchainSynchronizerObserver diff --git a/src/WalletLegacy/WalletTransactionSender.cpp b/src/WalletLegacy/WalletTransactionSender.cpp index 0f13c70b..431fd3b2 100644 --- a/src/WalletLegacy/WalletTransactionSender.cpp +++ b/src/WalletLegacy/WalletTransactionSender.cpp @@ -549,9 +549,9 @@ namespace cn deposit.creatingTransactionId = context->transactionId; deposit.spendingTransactionId = WALLET_LEGACY_INVALID_TRANSACTION_ID; deposit.height = transactionInfo.blockHeight; - deposit.unlockHeight = transactionInfo.blockHeight + context->depositTerm; deposit.interest = m_currency.calculateInterest(deposit.amount, deposit.term, deposit.height); deposit.locked = true; + deposit.unlockHeight = transactionInfo.blockHeight + context->depositTerm; DepositId depositId = m_transactionsCache.insertDeposit(deposit, depositIndex, transaction->getTransactionHash()); transactionInfo.firstDepositId = depositId; transactionInfo.depositCount = 1; @@ -1082,4 +1082,4 @@ namespace cn } } -} /* namespace cn */ +} /* namespace cn */ \ No newline at end of file diff --git a/src/WalletLegacy/WalletUserTransactionsCache.cpp b/src/WalletLegacy/WalletUserTransactionsCache.cpp index d3b33c37..4e72dd17 100644 --- a/src/WalletLegacy/WalletUserTransactionsCache.cpp +++ b/src/WalletLegacy/WalletUserTransactionsCache.cpp @@ -28,6 +28,8 @@ struct LegacyDeposit { uint32_t term; uint64_t amount; uint64_t interest; + uint64_t height; + uint64_t unlockedHeight; }; struct LegacyDepositInfo { @@ -622,7 +624,7 @@ DepositId WalletUserTransactionsCache::insertNewDeposit(const TransactionOutputI deposit.interest = currency.calculateInterest(deposit.amount, deposit.term, height); deposit.locked = true; deposit.height = height; - deposit.unlockHeight = deposit.height + deposit.term; + deposit.unlockHeight = height + depositOutput.term; return insertDeposit(deposit, depositOutput.outputInTransaction, depositOutput.transactionHash); } From d4427d036455a88b2722b96cb860f802e290542b Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Tue, 29 Mar 2022 02:38:04 +0100 Subject: [PATCH 23/48] Clear deposits on reset --- src/WalletLegacy/WalletUserTransactionsCache.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/WalletLegacy/WalletUserTransactionsCache.cpp b/src/WalletLegacy/WalletUserTransactionsCache.cpp index 4e72dd17..b5978d51 100644 --- a/src/WalletLegacy/WalletUserTransactionsCache.cpp +++ b/src/WalletLegacy/WalletUserTransactionsCache.cpp @@ -547,6 +547,7 @@ WalletLegacyTransfer& WalletUserTransactionsCache::getTransfer(TransferId transf void WalletUserTransactionsCache::reset() { m_transactions.clear(); m_transfers.clear(); + m_deposits.clear(); m_unconfirmedTransactions.reset(); } From 771e7487802471be23a4609b9939fbd348fc2f8d Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Tue, 29 Mar 2022 18:20:24 +0100 Subject: [PATCH 24/48] Serialise height & unlockHeight --- src/WalletLegacy/WalletLegacySerialization.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/WalletLegacy/WalletLegacySerialization.cpp b/src/WalletLegacy/WalletLegacySerialization.cpp index c136c75c..dcf04cbc 100644 --- a/src/WalletLegacy/WalletLegacySerialization.cpp +++ b/src/WalletLegacy/WalletLegacySerialization.cpp @@ -97,6 +97,8 @@ void serialize(Deposit& deposit, cn::ISerializer& serializer) { serializer(deposit.amount, "amount"); serializer(deposit.interest, "interest"); serializer(deposit.locked, "locked"); + serializer(deposit.height, "height"); + serializer(deposit.unlockHeight, "unlockHeight"); } void serialize(DepositInfo& depositInfo, cn::ISerializer& serializer) { From 31ee9c5d4766d55c6e3a2dea0572d3d58e0d0f05 Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Wed, 30 Mar 2022 00:37:13 +0100 Subject: [PATCH 25/48] Update v1 serializer Adds saveDeposits and loadDeposits to wallet serializer. This copies wallet serializer v2 with slight modifications --- src/Wallet/WalletGreen.cpp | 1 + src/Wallet/WalletSerializationV1.cpp | 91 ++++++++++++++++++++++++++++ src/Wallet/WalletSerializationV1.h | 5 ++ 3 files changed, 97 insertions(+) diff --git a/src/Wallet/WalletGreen.cpp b/src/Wallet/WalletGreen.cpp index 86f1ace6..4b11e9bd 100644 --- a/src/Wallet/WalletGreen.cpp +++ b/src/Wallet/WalletGreen.cpp @@ -1098,6 +1098,7 @@ namespace cn m_unlockTransactionsJob, m_transactions, m_transfers, + m_deposits, m_transactionSoftLockTime, m_uncommitedTransactions); diff --git a/src/Wallet/WalletSerializationV1.cpp b/src/Wallet/WalletSerializationV1.cpp index ab5f9dac..fd4f9365 100644 --- a/src/Wallet/WalletSerializationV1.cpp +++ b/src/Wallet/WalletSerializationV1.cpp @@ -104,6 +104,37 @@ struct WalletTransferDto { uint32_t version; }; +struct WalletDepositDto { + WalletDepositDto() { + } + + WalletDepositDto(const cn::Deposit& wd) { + creatingTransactionId = wd.creatingTransactionId; + spendingTransactionId = wd.spendingTransactionId; + term = wd.term; + amount = wd.amount; + interest = wd.interest; + height = wd.height; + unlockHeight = wd.unlockHeight; + locked = wd.locked; + transactionHash = wd.transactionHash; + outputInTransaction = wd.outputInTransaction; + address = wd.address; + } + + size_t creatingTransactionId; + size_t spendingTransactionId; + uint32_t term; + uint64_t amount; + uint64_t interest; + uint64_t height; + uint64_t unlockHeight; + bool locked; + uint32_t outputInTransaction; + crypto::Hash transactionHash; + std::string address; +}; + void serialize(WalletRecordDto& value, cn::ISerializer& serializer) { serializer(value.spendPublicKey, "spend_public_key"); serializer(value.spendSecretKey, "spend_secret_key"); @@ -157,6 +188,20 @@ void serialize(WalletTransferDto& value, cn::ISerializer& serializer) { } } +void serialize(WalletDepositDto& value, cn::ISerializer& serializer) { + serializer(value.height, "height"); + serializer(value.transactionHash, "transactionHash"); + serializer(value.outputInTransaction, "outputInTransaction"); + serializer(value.creatingTransactionId, "creatingTransactionId"); + serializer(value.spendingTransactionId, "spendingTransactionId"); + serializer(value.amount, "amount"); + serializer(value.term, "term"); + serializer(value.interest, "interest"); + serializer(value.unlockHeight, "unlockHeight"); + serializer(value.locked, "locked"); + serializer(value.address, "address"); +} + template std::string serialize(Object& obj, const std::string& name) { std::stringstream stream; @@ -282,6 +327,7 @@ WalletSerializer::WalletSerializer( UnlockTransactionJobs& unlockTransactions, WalletTransactions& transactions, WalletTransfers& transfers, + WalletDeposits& deposits, uint32_t transactionSoftLockTime, UncommitedTransactions& uncommitedTransactions ) : @@ -295,6 +341,7 @@ WalletSerializer::WalletSerializer( m_unlockTransactions(unlockTransactions), m_transactions(transactions), m_transfers(transfers), + m_deposits(deposits), m_transactionSoftLockTime(transactionSoftLockTime), uncommitedTransactions(uncommitedTransactions) { } @@ -315,6 +362,7 @@ void WalletSerializer::save(const std::string& password, common::IOutputStream& if (saveDetails) { saveTransactions(destination, cryptoContext); saveTransfers(destination, cryptoContext); + saveDeposits(destination, cryptoContext); } if (saveCache) { @@ -519,6 +567,7 @@ void WalletSerializer::loadWallet(common::IInputStream &source, const crypto::ch if (details) { loadTransactions(source, cryptoContext); loadTransfers(source, cryptoContext, version); + loadDeposits(source, cryptoContext); } if (version < 5) { @@ -906,6 +955,48 @@ void WalletSerializer::loadTransfers(common::IInputStream& source, CryptoContext } } +void WalletSerializer::saveDeposits(common::IOutputStream& source, CryptoContext& cryptoContext) { + uint64_t count = m_deposits.size(); + + serializeEncrypted(count, "depositCount", cryptoContext, source); + cryptoContext.incIv(); + + for (const auto& tx: m_deposits) { + WalletDepositDto dto(tx); + serializeEncrypted(dto, "deposit", cryptoContext, source); + cryptoContext.incIv(); + } +} + +void WalletSerializer::loadDeposits(common::IInputStream& source, CryptoContext& cryptoContext) { + uint64_t count = 0; + deserializeEncrypted(count, "depositCount", cryptoContext, source); + cryptoContext.incIv(); + + m_deposits.reserve(count); + + for (uint64_t i = 0; i < count; ++i) { + WalletDepositDto dto; + deserializeEncrypted(dto, "deposit", cryptoContext, source); + cryptoContext.incIv(); + + Deposit dp; + dp.creatingTransactionId = dto.creatingTransactionId; + dp.spendingTransactionId = dto.spendingTransactionId; + dp.term = dto.term; + dp.amount = dto.amount; + dp.interest = dto.interest; + dp.height = dto.height; + dp.unlockHeight = dto.unlockHeight; + dp.locked = dto.locked; + dp.transactionHash = dto.transactionHash; + dp.outputInTransaction = dto.outputInTransaction; + dp.address = dto.address; + + m_deposits.get().emplace_back(std::move(dp)); + } +} + void WalletSerializer::addWalletV1Details(const std::vector& txs, const std::vector& trs) { size_t txId = 0; m_transfers.reserve(trs.size()); diff --git a/src/Wallet/WalletSerializationV1.h b/src/Wallet/WalletSerializationV1.h index 13214281..28d4d811 100644 --- a/src/Wallet/WalletSerializationV1.h +++ b/src/Wallet/WalletSerializationV1.h @@ -41,6 +41,7 @@ class WalletSerializer UnlockTransactionJobs &unlockTransactions, WalletTransactions &transactions, WalletTransfers &transfers, + WalletDeposits& deposits, uint32_t transactionSoftLockTime, UncommitedTransactions &uncommitedTransactions); @@ -88,6 +89,9 @@ class WalletSerializer void loadTransactions(common::IInputStream &source, CryptoContext &cryptoContext); void loadTransfers(common::IInputStream &source, CryptoContext &cryptoContext, uint32_t version); + void loadDeposits(common::IInputStream &source, CryptoContext &cryptoContext); + void saveDeposits(common::IOutputStream& source, CryptoContext& cryptoContext); + void loadWalletV1Keys(cn::BinaryInputStreamSerializer &serializer); void loadWalletV1Details(cn::BinaryInputStreamSerializer &serializer); void addWalletV1Details(const std::vector &txs, const std::vector &trs); @@ -106,6 +110,7 @@ class WalletSerializer UnlockTransactionJobs &m_unlockTransactions; WalletTransactions &m_transactions; WalletTransfers &m_transfers; + WalletDeposits& m_deposits; uint32_t m_transactionSoftLockTime; UncommitedTransactions &uncommitedTransactions; }; From 75ef183fc416f25e1ac1f18f98adb0afcd812192 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Wed, 30 Mar 2022 00:52:51 +0100 Subject: [PATCH 26/48] Trigger rebuild --- src/Wallet/WalletSerializationV1.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Wallet/WalletSerializationV1.h b/src/Wallet/WalletSerializationV1.h index 28d4d811..aef0b803 100644 --- a/src/Wallet/WalletSerializationV1.h +++ b/src/Wallet/WalletSerializationV1.h @@ -70,6 +70,8 @@ class WalletSerializer void saveTransactions(common::IOutputStream &destination, CryptoContext &cryptoContext); void saveTransfers(common::IOutputStream &destination, CryptoContext &cryptoContext); + void saveDeposits(common::IOutputStream& source, CryptoContext& cryptoContext); + uint32_t loadVersion(common::IInputStream &source); void loadIv(common::IInputStream &source, crypto::chacha8_iv &iv); void generateKey(const std::string &password, crypto::chacha8_key &key); @@ -90,7 +92,6 @@ class WalletSerializer void loadTransfers(common::IInputStream &source, CryptoContext &cryptoContext, uint32_t version); void loadDeposits(common::IInputStream &source, CryptoContext &cryptoContext); - void saveDeposits(common::IOutputStream& source, CryptoContext& cryptoContext); void loadWalletV1Keys(cn::BinaryInputStreamSerializer &serializer); void loadWalletV1Details(cn::BinaryInputStreamSerializer &serializer); From 7008bcf39136e415f8a065958e0b9786026ab05d Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Wed, 30 Mar 2022 02:32:38 +0100 Subject: [PATCH 27/48] Add height to tx context & deposit request --- src/WalletLegacy/WalletLegacy.cpp | 2 +- src/WalletLegacy/WalletSendTransactionContext.h | 1 + src/WalletLegacy/WalletTransactionSender.cpp | 6 ++++-- src/WalletLegacy/WalletTransactionSender.h | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/WalletLegacy/WalletLegacy.cpp b/src/WalletLegacy/WalletLegacy.cpp index 81da6201..632c49f4 100644 --- a/src/WalletLegacy/WalletLegacy.cpp +++ b/src/WalletLegacy/WalletLegacy.cpp @@ -787,7 +787,7 @@ TransactionId WalletLegacy::deposit(uint32_t term, uint64_t amount, uint64_t fee { std::unique_lock lock(m_cacheMutex); - request = m_sender->makeDepositRequest(txId, events, term, amount, fee, mixIn); + request = m_sender->makeDepositRequest(txId, events, term, amount, fee, mixIn, m_node.getLastLocalBlockHeight()); if (request != nullptr) { pushBalanceUpdatedEvents(events); diff --git a/src/WalletLegacy/WalletSendTransactionContext.h b/src/WalletLegacy/WalletSendTransactionContext.h index 0cd4118d..09ba57f9 100644 --- a/src/WalletLegacy/WalletSendTransactionContext.h +++ b/src/WalletLegacy/WalletSendTransactionContext.h @@ -37,6 +37,7 @@ struct SendTransactionContext std::vector messages; uint64_t ttl; uint32_t depositTerm; + uint64_t height; }; } //namespace cn diff --git a/src/WalletLegacy/WalletTransactionSender.cpp b/src/WalletLegacy/WalletTransactionSender.cpp index 431fd3b2..4d7828cb 100644 --- a/src/WalletLegacy/WalletTransactionSender.cpp +++ b/src/WalletLegacy/WalletTransactionSender.cpp @@ -277,6 +277,7 @@ namespace cn uint64_t term, uint64_t amount, uint64_t fee, + uint64_t height, uint64_t mixIn) { @@ -296,6 +297,7 @@ namespace cn context->transactionId = transactionId; context->mixIn = mixIn; context->depositTerm = static_cast(term); + context->height = height; if (context->mixIn != 0) { @@ -548,10 +550,10 @@ namespace cn deposit.term = context->depositTerm; deposit.creatingTransactionId = context->transactionId; deposit.spendingTransactionId = WALLET_LEGACY_INVALID_TRANSACTION_ID; - deposit.height = transactionInfo.blockHeight; + deposit.height = context->height; deposit.interest = m_currency.calculateInterest(deposit.amount, deposit.term, deposit.height); deposit.locked = true; - deposit.unlockHeight = transactionInfo.blockHeight + context->depositTerm; + deposit.unlockHeight = context->height + context->depositTerm; DepositId depositId = m_transactionsCache.insertDeposit(deposit, depositIndex, transaction->getTransactionHash()); transactionInfo.firstDepositId = depositId; transactionInfo.depositCount = 1; diff --git a/src/WalletLegacy/WalletTransactionSender.h b/src/WalletLegacy/WalletTransactionSender.h index 07e7ead7..7cf0dc7f 100644 --- a/src/WalletLegacy/WalletTransactionSender.h +++ b/src/WalletLegacy/WalletTransactionSender.h @@ -46,6 +46,7 @@ class WalletTransactionSender uint64_t term, uint64_t amount, uint64_t fee, + uint64_t height, uint64_t mixIn = 0); std::unique_ptr makeWithdrawDepositRequest(TransactionId& transactionId, From 651ca92df8939e2d7084a10d507ada0f300a5bec Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Sat, 2 Apr 2022 19:59:00 +0100 Subject: [PATCH 28/48] Touchups * add height to deposit request, which uses current node height * add legacy deposit info to serialize --- include/IWalletLegacy.h | 2 +- src/SimpleWallet/DepositHelper.cpp | 4 ++++ src/SimpleWallet/SimpleWallet.cpp | 3 ++- src/WalletLegacy/WalletLegacy.cpp | 4 ++-- src/WalletLegacy/WalletLegacy.h | 2 +- src/WalletLegacy/WalletUserTransactionsCache.cpp | 4 ++++ 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/IWalletLegacy.h b/include/IWalletLegacy.h index dff2e6b1..9a0714ce 100644 --- a/include/IWalletLegacy.h +++ b/include/IWalletLegacy.h @@ -152,7 +152,7 @@ class IWalletLegacy { virtual size_t estimateFusion(const uint64_t& threshold) = 0; virtual std::list selectFusionTransfersToSend(uint64_t threshold, size_t minInputCount, size_t maxInputCount) = 0; virtual TransactionId sendFusionTransaction(const std::list& fusionInputs, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0) = 0; - virtual TransactionId deposit(uint32_t term, uint64_t amount, uint64_t fee, uint64_t mixIn = 0) = 0; + virtual TransactionId deposit(uint32_t term, uint64_t amount, uint64_t fee, uint64_t height, uint64_t mixIn = 0) = 0; virtual TransactionId withdrawDeposit(const DepositId& depositId, uint64_t fee) = 0; virtual TransactionId withdrawDeposits(const std::vector& depositIds, uint64_t fee) = 0; virtual std::error_code cancelTransaction(size_t transferId) = 0; diff --git a/src/SimpleWallet/DepositHelper.cpp b/src/SimpleWallet/DepositHelper.cpp index 39f7652e..4a7b4a3c 100644 --- a/src/SimpleWallet/DepositHelper.cpp +++ b/src/SimpleWallet/DepositHelper.cpp @@ -78,6 +78,10 @@ namespace cn bool bad_unlock2 = unlock_str == "0"; if (bad_unlock2) + unlock_str = std::to_string(deposit_height(deposit) + deposit_term(deposit)); + + bool bad_unlock3 = unlock_str == "0"; + if (bad_unlock3) unlock_str = "ERROR"; std::stringstream full_info; diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index c6389b81..d0193ce2 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -2124,11 +2124,12 @@ bool simple_wallet::deposit(const std::vector &args) /* Use defaults for fee + mix in */ uint64_t deposit_fee = cn::parameters::MINIMUM_FEE_V2; uint64_t deposit_mix_in = cn::parameters::MINIMUM_MIXIN; + uint64_t bc_height = m_node->getLastLocalBlockHeight(); cn::WalletHelper::SendCompleteResultObserver sent; WalletHelper::IWalletRemoveObserverGuard removeGuard(*m_wallet, sent); - cn::TransactionId tx = m_wallet->deposit(deposit_term, deposit_amount, deposit_fee, deposit_mix_in); + cn::TransactionId tx = m_wallet->deposit(deposit_term, deposit_amount, deposit_fee, deposit_mix_in, bc_height); if (tx == WALLET_LEGACY_INVALID_DEPOSIT_ID) { diff --git a/src/WalletLegacy/WalletLegacy.cpp b/src/WalletLegacy/WalletLegacy.cpp index 632c49f4..34d5c8e7 100644 --- a/src/WalletLegacy/WalletLegacy.cpp +++ b/src/WalletLegacy/WalletLegacy.cpp @@ -776,7 +776,7 @@ TransactionId WalletLegacy::sendFusionTransaction(const std::list lock(m_cacheMutex); - request = m_sender->makeDepositRequest(txId, events, term, amount, fee, mixIn, m_node.getLastLocalBlockHeight()); + request = m_sender->makeDepositRequest(txId, events, term, amount, fee, mixIn, height); if (request != nullptr) { pushBalanceUpdatedEvents(events); diff --git a/src/WalletLegacy/WalletLegacy.h b/src/WalletLegacy/WalletLegacy.h index 3cc53513..55b86cee 100644 --- a/src/WalletLegacy/WalletLegacy.h +++ b/src/WalletLegacy/WalletLegacy.h @@ -101,7 +101,7 @@ class WalletLegacy : virtual size_t estimateFusion(const uint64_t& threshold); virtual std::list selectFusionTransfersToSend(uint64_t threshold, size_t minInputCount, size_t maxInputCount); virtual TransactionId sendFusionTransaction(const std::list& fusionInputs, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0); - virtual TransactionId deposit(uint32_t term, uint64_t amount, uint64_t fee, uint64_t mixIn = parameters::MINIMUM_MIXIN) override; + virtual TransactionId deposit(uint32_t term, uint64_t amount, uint64_t fee, uint64_t height, uint64_t mixIn = parameters::MINIMUM_MIXIN) override; virtual TransactionId withdrawDeposit(const DepositId& depositId, uint64_t fee) override; virtual TransactionId withdrawDeposits(const std::vector& depositIds, uint64_t fee) override; virtual std::error_code cancelTransaction(size_t transactionId) override; diff --git a/src/WalletLegacy/WalletUserTransactionsCache.cpp b/src/WalletLegacy/WalletUserTransactionsCache.cpp index b5978d51..64c00195 100644 --- a/src/WalletLegacy/WalletUserTransactionsCache.cpp +++ b/src/WalletLegacy/WalletUserTransactionsCache.cpp @@ -123,6 +123,10 @@ bool WalletUserTransactionsCache::serialize(cn::ISerializer& s) { s(m_unconfirmedTransactions, "unconfirmed"); s(m_deposits, "deposits"); + std::vector legacyDeposits; + convertLegacyDeposits(legacyDeposits, m_deposits); + restoreTransactionOutputToDepositIndex(); + if (s.type() == cn::ISerializer::INPUT) { updateUnconfirmedTransactions(); deleteOutdatedTransactions(); From 5fef87fff58f3f515f160863a07bcf2615cd463f Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Sun, 3 Apr 2022 19:20:10 +0100 Subject: [PATCH 29/48] Cleanup * remove testing logic from deposit_info * add makeCenteredString to common namespace, allows us to use it universally --- src/Common/StringTools.cpp | 9 +++++++ src/Common/StringTools.h | 4 ++- src/SimpleWallet/DepositHelper.cpp | 33 ++++++++---------------- src/SimpleWallet/SimpleWallet.cpp | 41 ++++++++++++------------------ 4 files changed, 39 insertions(+), 48 deletions(-) diff --git a/src/Common/StringTools.cpp b/src/Common/StringTools.cpp index 61b81395..10bbb817 100644 --- a/src/Common/StringTools.cpp +++ b/src/Common/StringTools.cpp @@ -339,5 +339,14 @@ std::string timeIntervalToString(uint64_t intervalInSeconds) { ".s" + std::to_string(seconds); } +std::string makeCenteredString(size_t width, const std::string& text) { + if (text.size() >= width) { + return text; + } + + size_t offset = (width - text.size() + 1) / 2; + return std::string(offset, ' ') + text + std::string(width - text.size() - offset, ' '); +} + } diff --git a/src/Common/StringTools.h b/src/Common/StringTools.h index b94add6a..89ff4211 100644 --- a/src/Common/StringTools.h +++ b/src/Common/StringTools.h @@ -106,4 +106,6 @@ bool parseIpAddressAndPort(uint32_t& ip, uint32_t& port, const std::string& addr std::string timeIntervalToString(uint64_t intervalInSeconds); -} +std::string makeCenteredString(size_t width, const std::string& text); + +} \ No newline at end of file diff --git a/src/SimpleWallet/DepositHelper.cpp b/src/SimpleWallet/DepositHelper.cpp index 4a7b4a3c..b7716d21 100644 --- a/src/SimpleWallet/DepositHelper.cpp +++ b/src/SimpleWallet/DepositHelper.cpp @@ -50,15 +50,7 @@ namespace cn uint64_t deposit_helper::deposit_unlock_height(cn::Deposit deposit) { - uint64_t u_height = deposit.unlockHeight; - - if (u_height == 0) - u_height = deposit.height + deposit.term; - - if (u_height == 0 || u_height % 21900) - u_height = 0; - - return u_height; + return deposit.unlockHeight; } uint64_t deposit_helper::deposit_height(cn::Deposit deposit) @@ -87,11 +79,11 @@ namespace cn std::stringstream full_info; full_info << std::left << - std::setw(8) << std::to_string(did) << " | " << - std::setw(20) << deposit_amount(deposit, currency) << " | " << - std::setw(20) << deposit_interest(deposit, currency) << " | " << - std::setw(16) << unlock_str << " | " << - std::setw(10) << deposit_status(deposit); + std::setw(8) << common::makeCenteredString(8, std::to_string(did)) << " | " << + std::setw(20) << common::makeCenteredString(20, deposit_amount(deposit, currency)) << " | " << + std::setw(20) << common::makeCenteredString(20, deposit_interest(deposit, currency)) << " | " << + std::setw(16) << common::makeCenteredString(16, unlock_str) << " | " << + std::setw(10) << common::makeCenteredString(10, deposit_status(deposit)); std::string as_str = full_info.str(); @@ -110,14 +102,11 @@ namespace cn bool bad_unlock2 = unlock_str == "0"; if (bad_unlock2) - unlock_str = "ERROR"; - - uint64_t unlocked = deposit_height(deposit) + deposit_term(deposit); - std::string unlocked_str = ""; - - bool bad_unlock3 = unlocked_str == "0" || unlocked % 21900; + unlock_str = std::to_string(deposit_height(deposit) + deposit_term(deposit)); + + bool bad_unlock3 = unlock_str == "0"; if (bad_unlock3) - unlocked_str = "ERROR"; + unlock_str = "ERROR"; std::stringstream full_info; @@ -126,7 +115,7 @@ namespace cn "Amount: " << deposit_amount(deposit, currency) << "\n" << "Interest: " << deposit_interest(deposit, currency) << "\n" << "Height: " << deposit_height(deposit) << "\n" << - "Unlock Height: " << unlock_str << " | " << unlocked << "\n" << + "Unlock Height: " << unlock_str << "\n" << "Status: " << deposit_status(deposit) << "\n"; std::string as_str = full_info.str(); diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index d0193ce2..ebf1e4cf 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -387,15 +387,6 @@ std::string tryToOpenWalletOrLoadKeysOrThrow(LoggerRef& logger, std::unique_ptr< } } -std::string makeCenteredString(size_t width, const std::string& text) { - if (text.size() >= width) { - return text; - } - - size_t offset = (width - text.size() + 1) / 2; - return std::string(offset, ' ') + text + std::string(width - text.size() - offset, ' '); -} - const size_t TIMESTAMP_MAX_WIDTH = 32; const size_t HASH_MAX_WIDTH = 64; const size_t TOTAL_AMOUNT_MAX_WIDTH = 20; @@ -404,23 +395,23 @@ const size_t BLOCK_MAX_WIDTH = 7; const size_t UNLOCK_TIME_MAX_WIDTH = 11; void printListTransfersHeader(LoggerRef& logger) { - std::string header = makeCenteredString(TIMESTAMP_MAX_WIDTH, "timestamp (UTC)") + " "; - header += makeCenteredString(HASH_MAX_WIDTH, "hash") + " "; - header += makeCenteredString(TOTAL_AMOUNT_MAX_WIDTH, "total amount") + " "; - header += makeCenteredString(FEE_MAX_WIDTH, "fee") + " "; - header += makeCenteredString(BLOCK_MAX_WIDTH, "block") + " "; - header += makeCenteredString(UNLOCK_TIME_MAX_WIDTH, "unlock time"); + std::string header = common::makeCenteredString(TIMESTAMP_MAX_WIDTH, "timestamp (UTC)") + " "; + header += common::makeCenteredString(HASH_MAX_WIDTH, "hash") + " "; + header += common::makeCenteredString(TOTAL_AMOUNT_MAX_WIDTH, "total amount") + " "; + header += common::makeCenteredString(FEE_MAX_WIDTH, "fee") + " "; + header += common::makeCenteredString(BLOCK_MAX_WIDTH, "block") + " "; + header += common::makeCenteredString(UNLOCK_TIME_MAX_WIDTH, "unlock time"); logger(INFO) << header; logger(INFO) << std::string(header.size(), '-'); } void printListDepositsHeader(LoggerRef& logger) { - std::string header = makeCenteredString(8, "ID") + " | "; - header += makeCenteredString(20, "Amount") + " | "; - header += makeCenteredString(20, "Interest") + " | "; - header += makeCenteredString(16, "Unlock Height") + " | "; - header += makeCenteredString(10, "State"); + std::string header = common::makeCenteredString(8, "ID") + " | "; + header += common::makeCenteredString(20, "Amount") + " | "; + header += common::makeCenteredString(20, "Interest") + " | "; + header += common::makeCenteredString(16, "Unlock Height") + " | "; + header += common::makeCenteredString(10, "State"); logger(INFO) << "\n" << header; logger(INFO) << std::string(header.size(), '='); @@ -616,11 +607,11 @@ void printListDepositsItem(LoggerRef& logger, IWalletLegacy& wallet, const Curre unlock_str = std::to_string(deposit.unlockHeight); /* now print this deposits information */ - logger(INFO, is_locked_clr) << std::left << std::setw(8) << makeCenteredString(8, std::to_string(id)) - << " | " << std::setw(20) << makeCenteredString(20, currency.formatAmount(deposit.amount)) - << " | " << std::setw(20) << makeCenteredString(20, currency.formatAmount(deposit.interest)) - << " | " << std::setw(16) << makeCenteredString(16, unlock_str) - << " | " << std::setw(10) << makeCenteredString(10, state); + logger(INFO, is_locked_clr) << std::left << std::setw(8) << common::makeCenteredString(8, std::to_string(id)) + << " | " << std::setw(20) << common::makeCenteredString(20, currency.formatAmount(deposit.amount)) + << " | " << std::setw(20) << common::makeCenteredString(20, currency.formatAmount(deposit.interest)) + << " | " << std::setw(16) << common::makeCenteredString(16, unlock_str) + << " | " << std::setw(10) << common::makeCenteredString(10, state); } logger(INFO) << " "; //just to make logger print one endline From bd791089d0ab62f59bc1a66f29e4d39992c2ab70 Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Tue, 5 Apr 2022 21:49:24 +0100 Subject: [PATCH 30/48] Remove deposits from serialisation v1 This was apart of testing during the PR and it's safe to say we don't need this. --- src/Wallet/WalletGreen.cpp | 1 - src/Wallet/WalletSerializationV1.cpp | 91 ------------------- src/Wallet/WalletSerializationV1.h | 6 -- .../WalletLegacySerialization.cpp | 2 - 4 files changed, 100 deletions(-) diff --git a/src/Wallet/WalletGreen.cpp b/src/Wallet/WalletGreen.cpp index 4b11e9bd..86f1ace6 100644 --- a/src/Wallet/WalletGreen.cpp +++ b/src/Wallet/WalletGreen.cpp @@ -1098,7 +1098,6 @@ namespace cn m_unlockTransactionsJob, m_transactions, m_transfers, - m_deposits, m_transactionSoftLockTime, m_uncommitedTransactions); diff --git a/src/Wallet/WalletSerializationV1.cpp b/src/Wallet/WalletSerializationV1.cpp index fd4f9365..ab5f9dac 100644 --- a/src/Wallet/WalletSerializationV1.cpp +++ b/src/Wallet/WalletSerializationV1.cpp @@ -104,37 +104,6 @@ struct WalletTransferDto { uint32_t version; }; -struct WalletDepositDto { - WalletDepositDto() { - } - - WalletDepositDto(const cn::Deposit& wd) { - creatingTransactionId = wd.creatingTransactionId; - spendingTransactionId = wd.spendingTransactionId; - term = wd.term; - amount = wd.amount; - interest = wd.interest; - height = wd.height; - unlockHeight = wd.unlockHeight; - locked = wd.locked; - transactionHash = wd.transactionHash; - outputInTransaction = wd.outputInTransaction; - address = wd.address; - } - - size_t creatingTransactionId; - size_t spendingTransactionId; - uint32_t term; - uint64_t amount; - uint64_t interest; - uint64_t height; - uint64_t unlockHeight; - bool locked; - uint32_t outputInTransaction; - crypto::Hash transactionHash; - std::string address; -}; - void serialize(WalletRecordDto& value, cn::ISerializer& serializer) { serializer(value.spendPublicKey, "spend_public_key"); serializer(value.spendSecretKey, "spend_secret_key"); @@ -188,20 +157,6 @@ void serialize(WalletTransferDto& value, cn::ISerializer& serializer) { } } -void serialize(WalletDepositDto& value, cn::ISerializer& serializer) { - serializer(value.height, "height"); - serializer(value.transactionHash, "transactionHash"); - serializer(value.outputInTransaction, "outputInTransaction"); - serializer(value.creatingTransactionId, "creatingTransactionId"); - serializer(value.spendingTransactionId, "spendingTransactionId"); - serializer(value.amount, "amount"); - serializer(value.term, "term"); - serializer(value.interest, "interest"); - serializer(value.unlockHeight, "unlockHeight"); - serializer(value.locked, "locked"); - serializer(value.address, "address"); -} - template std::string serialize(Object& obj, const std::string& name) { std::stringstream stream; @@ -327,7 +282,6 @@ WalletSerializer::WalletSerializer( UnlockTransactionJobs& unlockTransactions, WalletTransactions& transactions, WalletTransfers& transfers, - WalletDeposits& deposits, uint32_t transactionSoftLockTime, UncommitedTransactions& uncommitedTransactions ) : @@ -341,7 +295,6 @@ WalletSerializer::WalletSerializer( m_unlockTransactions(unlockTransactions), m_transactions(transactions), m_transfers(transfers), - m_deposits(deposits), m_transactionSoftLockTime(transactionSoftLockTime), uncommitedTransactions(uncommitedTransactions) { } @@ -362,7 +315,6 @@ void WalletSerializer::save(const std::string& password, common::IOutputStream& if (saveDetails) { saveTransactions(destination, cryptoContext); saveTransfers(destination, cryptoContext); - saveDeposits(destination, cryptoContext); } if (saveCache) { @@ -567,7 +519,6 @@ void WalletSerializer::loadWallet(common::IInputStream &source, const crypto::ch if (details) { loadTransactions(source, cryptoContext); loadTransfers(source, cryptoContext, version); - loadDeposits(source, cryptoContext); } if (version < 5) { @@ -955,48 +906,6 @@ void WalletSerializer::loadTransfers(common::IInputStream& source, CryptoContext } } -void WalletSerializer::saveDeposits(common::IOutputStream& source, CryptoContext& cryptoContext) { - uint64_t count = m_deposits.size(); - - serializeEncrypted(count, "depositCount", cryptoContext, source); - cryptoContext.incIv(); - - for (const auto& tx: m_deposits) { - WalletDepositDto dto(tx); - serializeEncrypted(dto, "deposit", cryptoContext, source); - cryptoContext.incIv(); - } -} - -void WalletSerializer::loadDeposits(common::IInputStream& source, CryptoContext& cryptoContext) { - uint64_t count = 0; - deserializeEncrypted(count, "depositCount", cryptoContext, source); - cryptoContext.incIv(); - - m_deposits.reserve(count); - - for (uint64_t i = 0; i < count; ++i) { - WalletDepositDto dto; - deserializeEncrypted(dto, "deposit", cryptoContext, source); - cryptoContext.incIv(); - - Deposit dp; - dp.creatingTransactionId = dto.creatingTransactionId; - dp.spendingTransactionId = dto.spendingTransactionId; - dp.term = dto.term; - dp.amount = dto.amount; - dp.interest = dto.interest; - dp.height = dto.height; - dp.unlockHeight = dto.unlockHeight; - dp.locked = dto.locked; - dp.transactionHash = dto.transactionHash; - dp.outputInTransaction = dto.outputInTransaction; - dp.address = dto.address; - - m_deposits.get().emplace_back(std::move(dp)); - } -} - void WalletSerializer::addWalletV1Details(const std::vector& txs, const std::vector& trs) { size_t txId = 0; m_transfers.reserve(trs.size()); diff --git a/src/Wallet/WalletSerializationV1.h b/src/Wallet/WalletSerializationV1.h index aef0b803..13214281 100644 --- a/src/Wallet/WalletSerializationV1.h +++ b/src/Wallet/WalletSerializationV1.h @@ -41,7 +41,6 @@ class WalletSerializer UnlockTransactionJobs &unlockTransactions, WalletTransactions &transactions, WalletTransfers &transfers, - WalletDeposits& deposits, uint32_t transactionSoftLockTime, UncommitedTransactions &uncommitedTransactions); @@ -70,8 +69,6 @@ class WalletSerializer void saveTransactions(common::IOutputStream &destination, CryptoContext &cryptoContext); void saveTransfers(common::IOutputStream &destination, CryptoContext &cryptoContext); - void saveDeposits(common::IOutputStream& source, CryptoContext& cryptoContext); - uint32_t loadVersion(common::IInputStream &source); void loadIv(common::IInputStream &source, crypto::chacha8_iv &iv); void generateKey(const std::string &password, crypto::chacha8_key &key); @@ -91,8 +88,6 @@ class WalletSerializer void loadTransactions(common::IInputStream &source, CryptoContext &cryptoContext); void loadTransfers(common::IInputStream &source, CryptoContext &cryptoContext, uint32_t version); - void loadDeposits(common::IInputStream &source, CryptoContext &cryptoContext); - void loadWalletV1Keys(cn::BinaryInputStreamSerializer &serializer); void loadWalletV1Details(cn::BinaryInputStreamSerializer &serializer); void addWalletV1Details(const std::vector &txs, const std::vector &trs); @@ -111,7 +106,6 @@ class WalletSerializer UnlockTransactionJobs &m_unlockTransactions; WalletTransactions &m_transactions; WalletTransfers &m_transfers; - WalletDeposits& m_deposits; uint32_t m_transactionSoftLockTime; UncommitedTransactions &uncommitedTransactions; }; diff --git a/src/WalletLegacy/WalletLegacySerialization.cpp b/src/WalletLegacy/WalletLegacySerialization.cpp index dcf04cbc..c136c75c 100644 --- a/src/WalletLegacy/WalletLegacySerialization.cpp +++ b/src/WalletLegacy/WalletLegacySerialization.cpp @@ -97,8 +97,6 @@ void serialize(Deposit& deposit, cn::ISerializer& serializer) { serializer(deposit.amount, "amount"); serializer(deposit.interest, "interest"); serializer(deposit.locked, "locked"); - serializer(deposit.height, "height"); - serializer(deposit.unlockHeight, "unlockHeight"); } void serialize(DepositInfo& depositInfo, cn::ISerializer& serializer) { From 206afdac62a2edce996ea770233eecc89d40de29 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Wed, 6 Apr 2022 21:11:26 +0100 Subject: [PATCH 31/48] Print deposit balances * removes unused function from namespace --- src/SimpleWallet/SimpleWallet.cpp | 90 ++++++++----------------------- 1 file changed, 21 insertions(+), 69 deletions(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index ebf1e4cf..7a2eab50 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -552,71 +552,6 @@ bool askAliasesTransfersConfirmation(const std::map cn::parameters::CRYPTONOTE_MAX_BLOCK_NUMBER; - std::string unlock_str = ""; - - if (bad_unlock) - unlock_str = "Please wait."; - else - unlock_str = std::to_string(deposit.unlockHeight); - - /* now print this deposits information */ - logger(INFO, is_locked_clr) << std::left << std::setw(8) << common::makeCenteredString(8, std::to_string(id)) - << " | " << std::setw(20) << common::makeCenteredString(20, currency.formatAmount(deposit.amount)) - << " | " << std::setw(20) << common::makeCenteredString(20, currency.formatAmount(deposit.interest)) - << " | " << std::setw(16) << common::makeCenteredString(16, unlock_str) - << " | " << std::setw(10) << common::makeCenteredString(10, state); - } - - logger(INFO) << " "; //just to make logger print one endline -} - } bool processServerFeeAddressResponse(const std::string& response, std::string& fee_address) @@ -717,7 +652,7 @@ std::string simple_wallet::simple_menu() std::string menu_item = "\t\tConceal Wallet Menu\n\n"; menu_item += "[ ] = Optional arg\n"; menu_item += "\"address\" - Shows wallet address.\n"; - menu_item += "\"balance\" - Shows wallet balance.\n"; + menu_item += "\"balance\" - Shows wallet main and deposit balance.\n"; menu_item += "\"bc_height\" - Shows current blockchain height.\n"; menu_item += "\"deposit \" - Create a deposit to the blockchain.\n"; menu_item += "\"deposit_info \" - Display full information for deposit .\n"; @@ -1414,8 +1349,26 @@ void simple_wallet::synchronizationProgressUpdated(uint32_t current, uint32_t to } bool simple_wallet::show_balance(const std::vector& args/* = std::vector()*/) { - success_msg_writer() << "available balance: " << m_currency.formatAmount(m_wallet->actualBalance()) << - ", locked amount: " << m_currency.formatAmount(m_wallet->pendingBalance()); + std::string header = common::makeCenteredString(14, " ") + " | "; + header += common::makeCenteredString(20, "Available") + " | "; + header += common::makeCenteredString(20, "Locked"); + + logger(INFO) << "\n" << header; + logger(INFO) << std::string(header.size(), '='); + + std::stringstream wal_funds; + wal_funds << std::left << + std::setw(14) << common::makeCenteredString(14, "Wallet Funds") << " | " << + std::setw(20) << common::makeCenteredString(20, m_currency.formatAmount(m_wallet->actualBalance())) << " | " << + std::setw(20) << common::makeCenteredString(20, m_currency.formatAmount(m_wallet->pendingBalance())); + + std::stringstream dep_funds; + dep_funds << std::left << + std::setw(14) << common::makeCenteredString(14, "Deposit Funds") << " | " << + std::setw(20) << common::makeCenteredString(20, m_currency.formatAmount(m_wallet->actualDepositBalance())) << " | " << + std::setw(20) << common::makeCenteredString(20, m_currency.formatAmount(m_wallet->pendingDepositBalance())); + + logger(INFO) << wal_funds.str() << "\n" << dep_funds.str(); return true; } @@ -2044,7 +1997,6 @@ bool simple_wallet::list_deposits(const std::vector &args) } printListDepositsHeader(logger); - //printListDepositsItem(logger, *m_wallet, m_currency); /* go through deposits ids for the amount of deposits in wallet */ for (DepositId id = 0; id < m_wallet->getDepositCount(); ++id) From 3c4416d05719d255a648133e0a73d1638d45b01c Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Fri, 8 Apr 2022 13:07:30 +0100 Subject: [PATCH 32/48] Keep support for GUI With the new changes, the height would only of been imported from `concealwallet`s deposit request. This keeps support for the GUI, `if t_height == 0` it hasn't came from simplewallet --- src/WalletLegacy/WalletTransactionSender.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/WalletLegacy/WalletTransactionSender.cpp b/src/WalletLegacy/WalletTransactionSender.cpp index 4d7828cb..152e026d 100644 --- a/src/WalletLegacy/WalletTransactionSender.cpp +++ b/src/WalletLegacy/WalletTransactionSender.cpp @@ -544,13 +544,17 @@ namespace cn } transactionInfo.hash = transaction->getTransactionHash(); + + uint64_t t_height = context->height; + if (t_height == 0) + t_height = transactionInfo.blockHeight; Deposit deposit; deposit.amount = std::abs(transactionInfo.totalAmount) - transactionInfo.fee; deposit.term = context->depositTerm; deposit.creatingTransactionId = context->transactionId; deposit.spendingTransactionId = WALLET_LEGACY_INVALID_TRANSACTION_ID; - deposit.height = context->height; + deposit.height = t_height; deposit.interest = m_currency.calculateInterest(deposit.amount, deposit.term, deposit.height); deposit.locked = true; deposit.unlockHeight = context->height + context->depositTerm; @@ -1084,4 +1088,4 @@ namespace cn } } -} /* namespace cn */ \ No newline at end of file +} /* namespace cn */ From 4df5ef013033deb16707f7ecafce89dc84ecefd2 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Sat, 9 Apr 2022 23:16:53 +0100 Subject: [PATCH 33/48] Use same logic for unlockHeight --- src/WalletLegacy/WalletTransactionSender.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WalletLegacy/WalletTransactionSender.cpp b/src/WalletLegacy/WalletTransactionSender.cpp index 152e026d..ef1286c7 100644 --- a/src/WalletLegacy/WalletTransactionSender.cpp +++ b/src/WalletLegacy/WalletTransactionSender.cpp @@ -557,7 +557,7 @@ namespace cn deposit.height = t_height; deposit.interest = m_currency.calculateInterest(deposit.amount, deposit.term, deposit.height); deposit.locked = true; - deposit.unlockHeight = context->height + context->depositTerm; + deposit.unlockHeight = t_height + context->depositTerm; DepositId depositId = m_transactionsCache.insertDeposit(deposit, depositIndex, transaction->getTransactionHash()); transactionInfo.firstDepositId = depositId; transactionInfo.depositCount = 1; From 86307e59c02bb0216047f24231a43230d2879ccc Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Mon, 11 Apr 2022 18:09:19 +0100 Subject: [PATCH 34/48] Don't use context, always use txInfo for height --- src/WalletLegacy/WalletTransactionSender.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/WalletLegacy/WalletTransactionSender.cpp b/src/WalletLegacy/WalletTransactionSender.cpp index ef1286c7..555bba38 100644 --- a/src/WalletLegacy/WalletTransactionSender.cpp +++ b/src/WalletLegacy/WalletTransactionSender.cpp @@ -545,9 +545,7 @@ namespace cn transactionInfo.hash = transaction->getTransactionHash(); - uint64_t t_height = context->height; - if (t_height == 0) - t_height = transactionInfo.blockHeight; + uint64_t t_height = transactionInfo.blockHeight; Deposit deposit; deposit.amount = std::abs(transactionInfo.totalAmount) - transactionInfo.fee; From 5a6504330ba68efe438dd8dc318f973e413131bc Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Wed, 13 Apr 2022 12:55:46 +0100 Subject: [PATCH 35/48] Get deposit height from the transaction that made the deposit * this was suggested by Ax, it seems to work as an alternative serialise new data * also removes table format from balance --- src/SimpleWallet/DepositHelper.cpp | 14 +++++++------- src/SimpleWallet/DepositHelper.h | 10 ++++++---- src/SimpleWallet/SimpleWallet.cpp | 15 ++++++--------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/SimpleWallet/DepositHelper.cpp b/src/SimpleWallet/DepositHelper.cpp index b7716d21..34f90216 100644 --- a/src/SimpleWallet/DepositHelper.cpp +++ b/src/SimpleWallet/DepositHelper.cpp @@ -53,12 +53,12 @@ namespace cn return deposit.unlockHeight; } - uint64_t deposit_helper::deposit_height(cn::Deposit deposit) + uint64_t deposit_helper::deposit_height(cn::WalletLegacyTransaction txInfo) { - return deposit.height; + return txInfo.blockHeight; } - std::string deposit_helper::get_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency) + std::string deposit_helper::get_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency, cn::WalletLegacyTransaction txInfo) { std::string unlock_str = ""; @@ -70,7 +70,7 @@ namespace cn bool bad_unlock2 = unlock_str == "0"; if (bad_unlock2) - unlock_str = std::to_string(deposit_height(deposit) + deposit_term(deposit)); + unlock_str = std::to_string(deposit_height(txInfo) + deposit_term(deposit)); bool bad_unlock3 = unlock_str == "0"; if (bad_unlock3) @@ -90,7 +90,7 @@ namespace cn return as_str; } - std::string deposit_helper::get_full_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency) + std::string deposit_helper::get_full_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency, cn::WalletLegacyTransaction txInfo) { std::string unlock_str = ""; @@ -102,7 +102,7 @@ namespace cn bool bad_unlock2 = unlock_str == "0"; if (bad_unlock2) - unlock_str = std::to_string(deposit_height(deposit) + deposit_term(deposit)); + unlock_str = std::to_string(deposit_height(txInfo) + deposit_term(deposit)); bool bad_unlock3 = unlock_str == "0"; if (bad_unlock3) @@ -114,7 +114,7 @@ namespace cn "ID: " << std::to_string(did) << "\n" << "Amount: " << deposit_amount(deposit, currency) << "\n" << "Interest: " << deposit_interest(deposit, currency) << "\n" << - "Height: " << deposit_height(deposit) << "\n" << + "Height: " << deposit_height(txInfo) << "\n" << "Unlock Height: " << unlock_str << "\n" << "Status: " << deposit_status(deposit) << "\n"; diff --git a/src/SimpleWallet/DepositHelper.h b/src/SimpleWallet/DepositHelper.h index 8dfdf17d..0cb6d477 100644 --- a/src/SimpleWallet/DepositHelper.h +++ b/src/SimpleWallet/DepositHelper.h @@ -57,25 +57,27 @@ namespace cn uint64_t deposit_unlock_height(cn::Deposit deposit); /** - * @param deposit - obtain information from deposit + * @param txInfo - obtain height from transaction * @return - returns deposit height **/ - uint64_t deposit_height(cn::Deposit deposit); + uint64_t deposit_height(cn::WalletLegacyTransaction txInfo); /** * @param deposit - obtain information from deposit * @param did - id to search deposit * @param currency - used to supply amount and interest + * @param txInfo - obtain height from transaction * @return - returns deposit info string in single row style **/ - std::string get_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency); + std::string get_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency, cn::WalletLegacyTransaction txInfo); /** * @param deposit - obtain information from deposit * @param did - id to search deposit * @param currency - used to supply amount and interest + * @param txInfo - obtain height from transaction * @return - returns full deposit info string **/ - std::string get_full_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency); + std::string get_full_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency, cn::WalletLegacyTransaction txInfo); }; } \ No newline at end of file diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 7a2eab50..808fa27e 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -1348,14 +1348,8 @@ void simple_wallet::synchronizationProgressUpdated(uint32_t current, uint32_t to } } -bool simple_wallet::show_balance(const std::vector& args/* = std::vector()*/) { - std::string header = common::makeCenteredString(14, " ") + " | "; - header += common::makeCenteredString(20, "Available") + " | "; - header += common::makeCenteredString(20, "Locked"); - - logger(INFO) << "\n" << header; - logger(INFO) << std::string(header.size(), '='); - +bool simple_wallet::show_balance(const std::vector& args/* = std::vector()*/) +{ std::stringstream wal_funds; wal_funds << std::left << std::setw(14) << common::makeCenteredString(14, "Wallet Funds") << " | " << @@ -2003,7 +1997,10 @@ bool simple_wallet::list_deposits(const std::vector &args) { /* get deposit info from id and store it to deposit */ Deposit deposit = m_wallet->get_deposit(id); - logger(INFO) << m_dhelper.get_deposit_info(deposit, id, m_currency); + cn::WalletLegacyTransaction txInfo; + m_wallet->getTransaction(id, txInfo); + + logger(INFO) << m_dhelper.get_deposit_info(deposit, id, m_currency, txInfo); } return true; From 50159de060d3fbbd1ee36a60f8abab5d8c5694d5 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Wed, 13 Apr 2022 19:02:38 +0100 Subject: [PATCH 36/48] Update deposit info --- src/SimpleWallet/SimpleWallet.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 808fa27e..a9182deb 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -2187,8 +2187,10 @@ bool simple_wallet::deposit_info(const std::vector &args) } uint64_t deposit_id = boost::lexical_cast(args[0]); cn::Deposit deposit = m_wallet->get_deposit(deposit_id); + cn::WalletLegacyTransaction txInfo; + m_wallet->getTransaction(deposit_id, txInfo); - logger(INFO) << m_dhelper.get_full_deposit_info(deposit, deposit_id, m_currency); + logger(INFO) << m_dhelper.get_full_deposit_info(deposit, deposit_id, m_currency, txInfo); return true; } From 2d641483970455e4135984aa3c6b44c5f934690c Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Wed, 13 Apr 2022 21:31:57 +0100 Subject: [PATCH 37/48] Trigger rebuild --- src/SimpleWallet/SimpleWallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index a9182deb..b64f6a5b 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -2185,6 +2185,7 @@ bool simple_wallet::deposit_info(const std::vector &args) logger(ERROR) << "Usage: withdraw "; return true; } + uint64_t deposit_id = boost::lexical_cast(args[0]); cn::Deposit deposit = m_wallet->get_deposit(deposit_id); cn::WalletLegacyTransaction txInfo; From dbb9c0bbb827fd920e70099b010e52d13c24da92 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Sun, 17 Apr 2022 20:52:01 +0100 Subject: [PATCH 38/48] Update SimpleWallet.cpp --- src/SimpleWallet/SimpleWallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index b64f6a5b..6b2b9029 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -1998,7 +1998,7 @@ bool simple_wallet::list_deposits(const std::vector &args) /* get deposit info from id and store it to deposit */ Deposit deposit = m_wallet->get_deposit(id); cn::WalletLegacyTransaction txInfo; - m_wallet->getTransaction(id, txInfo); + m_wallet->getDeposit(id, txInfo); logger(INFO) << m_dhelper.get_deposit_info(deposit, id, m_currency, txInfo); } @@ -2189,7 +2189,7 @@ bool simple_wallet::deposit_info(const std::vector &args) uint64_t deposit_id = boost::lexical_cast(args[0]); cn::Deposit deposit = m_wallet->get_deposit(deposit_id); cn::WalletLegacyTransaction txInfo; - m_wallet->getTransaction(deposit_id, txInfo); + m_wallet->getDeposit(deposit_id, txInfo); logger(INFO) << m_dhelper.get_full_deposit_info(deposit, deposit_id, m_currency, txInfo); From 7d26351a75a5039911803ab48965053ca2debd0b Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Thu, 28 Apr 2022 22:05:47 +0100 Subject: [PATCH 39/48] Get TX from deposits creating ID --- src/SimpleWallet/SimpleWallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 6b2b9029..1f03f773 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -1998,7 +1998,7 @@ bool simple_wallet::list_deposits(const std::vector &args) /* get deposit info from id and store it to deposit */ Deposit deposit = m_wallet->get_deposit(id); cn::WalletLegacyTransaction txInfo; - m_wallet->getDeposit(id, txInfo); + m_wallet->getTransaction(deposit.creatingTransactionId, txInfo); logger(INFO) << m_dhelper.get_deposit_info(deposit, id, m_currency, txInfo); } From 7fc0a8434a700cfb3958466998abf338308eccae Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Thu, 28 Apr 2022 22:29:14 +0100 Subject: [PATCH 40/48] Use same logic here --- src/SimpleWallet/SimpleWallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 1f03f773..4c3cad7a 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -2189,7 +2189,7 @@ bool simple_wallet::deposit_info(const std::vector &args) uint64_t deposit_id = boost::lexical_cast(args[0]); cn::Deposit deposit = m_wallet->get_deposit(deposit_id); cn::WalletLegacyTransaction txInfo; - m_wallet->getDeposit(deposit_id, txInfo); + m_wallet->getTransaction(deposit.creatingTransactionId, txInfo); logger(INFO) << m_dhelper.get_full_deposit_info(deposit, deposit_id, m_currency, txInfo); From 4b2a70d11bd5ce35ca6037e7f86c8b9706577814 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Thu, 26 May 2022 10:05:29 +0100 Subject: [PATCH 41/48] Account for deposit balances in `show_balance` * this was taken from Ax's suggestion within the discord * makes use of `splitUrlToHostAndUri()` --- src/SimpleWallet/SimpleWallet.cpp | 62 +++++++++++++++++++------------ 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index e6e3ba6f..f97dccad 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -1350,19 +1350,23 @@ void simple_wallet::synchronizationProgressUpdated(uint32_t current, uint32_t to bool simple_wallet::show_balance(const std::vector& args/* = std::vector()*/) { - std::stringstream wal_funds; - wal_funds << std::left << - std::setw(14) << common::makeCenteredString(14, "Wallet Funds") << " | " << - std::setw(20) << common::makeCenteredString(20, m_currency.formatAmount(m_wallet->actualBalance())) << " | " << - std::setw(20) << common::makeCenteredString(20, m_currency.formatAmount(m_wallet->pendingBalance())); + 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"; - std::stringstream dep_funds; - dep_funds << std::left << - std::setw(14) << common::makeCenteredString(14, "Deposit Funds") << " | " << - std::setw(20) << common::makeCenteredString(20, m_currency.formatAmount(m_wallet->actualDepositBalance())) << " | " << - std::setw(20) << common::makeCenteredString(20, m_currency.formatAmount(m_wallet->pendingDepositBalance())); + 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"; - logger(INFO) << wal_funds.str() << "\n" << dep_funds.str(); + 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"; + + logger(INFO) << full_balance_text << non_deposit_unlocked_balance_text << non_deposit_locked_balance_text + << deposit_unlocked_balance_text << deposit_locked_balance_text; return true; } @@ -1759,22 +1763,32 @@ bool simple_wallet::optimize_all_outputs(const std::vector& args) { //---------------------------------------------------------------------------------------------------- -std::string simple_wallet::resolveAlias(const std::string& aliasUrl) { +std::string simple_wallet::resolveAlias(const std::string& aliasUrl) +{ std::string host; - std::string uri; - std::vectorrecords; - std::string address; + std::string uri; + std::vectorrecords; + std::string address; - if (!common::fetch_dns_txt(aliasUrl, records)) { - throw std::runtime_error("Failed to lookup DNS record"); - } + if (!splitUrlToHostAndUri(aliasUrl, host, uri)) + { + throw std::runtime_error("Failed to split URL to Host and URI"); + } - for (const auto& record : records) { - if (processServerAliasResponse(record, address)) { - return address; - } - } - throw std::runtime_error("Failed to parse server response"); + if (!common::fetch_dns_txt(aliasUrl, records)) + { + throw std::runtime_error("Failed to lookup DNS record"); + } + + for (const auto& record : records) + { + if (processServerAliasResponse(record, address)) + { + return address; + } + } + + throw std::runtime_error("Failed to parse server response"); } //---------------------------------------------------------------------------------------------------- From 1ab0a2d06d65c2eedd10517394f29c8238682158 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Tue, 31 May 2022 17:26:46 +0100 Subject: [PATCH 42/48] Revert requested * https://github.com/cartoon-face/conceal-core/commits/feat-banking/src/WalletLegacy/WalletUserTransactionsCache.cpp hasn't been reverted yet --- src/WalletLegacy/WalletUserTransactionsCache.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/WalletLegacy/WalletUserTransactionsCache.cpp b/src/WalletLegacy/WalletUserTransactionsCache.cpp index 64c00195..84776d4e 100644 --- a/src/WalletLegacy/WalletUserTransactionsCache.cpp +++ b/src/WalletLegacy/WalletUserTransactionsCache.cpp @@ -27,9 +27,7 @@ struct LegacyDeposit { TransactionId spendingTransactionId; uint32_t term; uint64_t amount; - uint64_t interest; - uint64_t height; - uint64_t unlockedHeight; + uint64_t interest }; struct LegacyDepositInfo { @@ -49,8 +47,6 @@ void serialize(LegacyDeposit& deposit, ISerializer& serializer) { serializer(deposit.term, "term"); serializer(deposit.amount, "amount"); serializer(deposit.interest, "interest"); - serializer(deposit.height, "height"); - serializer(deposit.unlockedHeight, "unlockedHeight"); } void serialize(LegacyDepositInfo& depositInfo, ISerializer& serializer) { @@ -105,8 +101,6 @@ void convertLegacyDeposits(const std::vector& legacyDeposits, info.deposit.term = legacyDepositInfo.deposit.term; info.deposit.locked = true; info.outputInTransaction = legacyDepositInfo.outputInTransaction; - info.deposit.height = legacyDepositInfo.deposit.height; - info.deposit.unlockHeight = legacyDepositInfo.deposit.unlockHeight; deposits.push_back(std::move(info)); } @@ -123,10 +117,6 @@ bool WalletUserTransactionsCache::serialize(cn::ISerializer& s) { s(m_unconfirmedTransactions, "unconfirmed"); s(m_deposits, "deposits"); - std::vector legacyDeposits; - convertLegacyDeposits(legacyDeposits, m_deposits); - restoreTransactionOutputToDepositIndex(); - if (s.type() == cn::ISerializer::INPUT) { updateUnconfirmedTransactions(); deleteOutdatedTransactions(); @@ -628,8 +618,6 @@ DepositId WalletUserTransactionsCache::insertNewDeposit(const TransactionOutputI deposit.spendingTransactionId = WALLET_LEGACY_INVALID_TRANSACTION_ID; deposit.interest = currency.calculateInterest(deposit.amount, deposit.term, height); deposit.locked = true; - deposit.height = height; - deposit.unlockHeight = height + depositOutput.term; return insertDeposit(deposit, depositOutput.outputInTransaction, depositOutput.transactionHash); } From 813af26fd0be29bdf55f4142fca13f845a2e1dd0 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Tue, 31 May 2022 17:34:01 +0100 Subject: [PATCH 43/48] Missing semi --- src/WalletLegacy/WalletUserTransactionsCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WalletLegacy/WalletUserTransactionsCache.cpp b/src/WalletLegacy/WalletUserTransactionsCache.cpp index 84776d4e..dc8173de 100644 --- a/src/WalletLegacy/WalletUserTransactionsCache.cpp +++ b/src/WalletLegacy/WalletUserTransactionsCache.cpp @@ -27,7 +27,7 @@ struct LegacyDeposit { TransactionId spendingTransactionId; uint32_t term; uint64_t amount; - uint64_t interest + uint64_t interest; }; struct LegacyDepositInfo { From d33f70d6fa0a1ad62298c0140e8e7a3206eaeeac Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Thu, 2 Jun 2022 14:17:44 +0100 Subject: [PATCH 44/48] Remove height from deposit request --- include/IWalletLegacy.h | 2 +- src/SimpleWallet/SimpleWallet.cpp | 3 +-- src/WalletLegacy/WalletLegacy.cpp | 4 ++-- src/WalletLegacy/WalletLegacy.h | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/IWalletLegacy.h b/include/IWalletLegacy.h index 9a0714ce..dff2e6b1 100644 --- a/include/IWalletLegacy.h +++ b/include/IWalletLegacy.h @@ -152,7 +152,7 @@ class IWalletLegacy { virtual size_t estimateFusion(const uint64_t& threshold) = 0; virtual std::list selectFusionTransfersToSend(uint64_t threshold, size_t minInputCount, size_t maxInputCount) = 0; virtual TransactionId sendFusionTransaction(const std::list& fusionInputs, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0) = 0; - virtual TransactionId deposit(uint32_t term, uint64_t amount, uint64_t fee, uint64_t height, uint64_t mixIn = 0) = 0; + virtual TransactionId deposit(uint32_t term, uint64_t amount, uint64_t fee, uint64_t mixIn = 0) = 0; virtual TransactionId withdrawDeposit(const DepositId& depositId, uint64_t fee) = 0; virtual TransactionId withdrawDeposits(const std::vector& depositIds, uint64_t fee) = 0; virtual std::error_code cancelTransaction(size_t transferId) = 0; diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index f97dccad..8584114a 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -2078,12 +2078,11 @@ bool simple_wallet::deposit(const std::vector &args) /* Use defaults for fee + mix in */ uint64_t deposit_fee = cn::parameters::MINIMUM_FEE_V2; uint64_t deposit_mix_in = cn::parameters::MINIMUM_MIXIN; - uint64_t bc_height = m_node->getLastLocalBlockHeight(); cn::WalletHelper::SendCompleteResultObserver sent; WalletHelper::IWalletRemoveObserverGuard removeGuard(*m_wallet, sent); - cn::TransactionId tx = m_wallet->deposit(deposit_term, deposit_amount, deposit_fee, deposit_mix_in, bc_height); + cn::TransactionId tx = m_wallet->deposit(deposit_term, deposit_amount, deposit_fee, deposit_mix_in); if (tx == WALLET_LEGACY_INVALID_DEPOSIT_ID) { diff --git a/src/WalletLegacy/WalletLegacy.cpp b/src/WalletLegacy/WalletLegacy.cpp index 34d5c8e7..632c49f4 100644 --- a/src/WalletLegacy/WalletLegacy.cpp +++ b/src/WalletLegacy/WalletLegacy.cpp @@ -776,7 +776,7 @@ TransactionId WalletLegacy::sendFusionTransaction(const std::list lock(m_cacheMutex); - request = m_sender->makeDepositRequest(txId, events, term, amount, fee, mixIn, height); + request = m_sender->makeDepositRequest(txId, events, term, amount, fee, mixIn, m_node.getLastLocalBlockHeight()); if (request != nullptr) { pushBalanceUpdatedEvents(events); diff --git a/src/WalletLegacy/WalletLegacy.h b/src/WalletLegacy/WalletLegacy.h index 55b86cee..3cc53513 100644 --- a/src/WalletLegacy/WalletLegacy.h +++ b/src/WalletLegacy/WalletLegacy.h @@ -101,7 +101,7 @@ class WalletLegacy : virtual size_t estimateFusion(const uint64_t& threshold); virtual std::list selectFusionTransfersToSend(uint64_t threshold, size_t minInputCount, size_t maxInputCount); virtual TransactionId sendFusionTransaction(const std::list& fusionInputs, uint64_t fee, const std::string& extra = "", uint64_t mixIn = 0, uint64_t unlockTimestamp = 0); - virtual TransactionId deposit(uint32_t term, uint64_t amount, uint64_t fee, uint64_t height, uint64_t mixIn = parameters::MINIMUM_MIXIN) override; + virtual TransactionId deposit(uint32_t term, uint64_t amount, uint64_t fee, uint64_t mixIn = parameters::MINIMUM_MIXIN) override; virtual TransactionId withdrawDeposit(const DepositId& depositId, uint64_t fee) override; virtual TransactionId withdrawDeposits(const std::vector& depositIds, uint64_t fee) override; virtual std::error_code cancelTransaction(size_t transactionId) override; From 0c701c1a391c7a384931c8f2299c03b504265f2a Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Thu, 2 Jun 2022 16:52:41 +0100 Subject: [PATCH 45/48] Remove height from make deposit request Reverted back to original state --- src/WalletLegacy/WalletLegacy.cpp | 2 +- src/WalletLegacy/WalletSendTransactionContext.h | 1 - src/WalletLegacy/WalletTransactionSender.cpp | 2 -- src/WalletLegacy/WalletTransactionSender.h | 1 - 4 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/WalletLegacy/WalletLegacy.cpp b/src/WalletLegacy/WalletLegacy.cpp index 632c49f4..81da6201 100644 --- a/src/WalletLegacy/WalletLegacy.cpp +++ b/src/WalletLegacy/WalletLegacy.cpp @@ -787,7 +787,7 @@ TransactionId WalletLegacy::deposit(uint32_t term, uint64_t amount, uint64_t fee { std::unique_lock lock(m_cacheMutex); - request = m_sender->makeDepositRequest(txId, events, term, amount, fee, mixIn, m_node.getLastLocalBlockHeight()); + request = m_sender->makeDepositRequest(txId, events, term, amount, fee, mixIn); if (request != nullptr) { pushBalanceUpdatedEvents(events); diff --git a/src/WalletLegacy/WalletSendTransactionContext.h b/src/WalletLegacy/WalletSendTransactionContext.h index 09ba57f9..0cd4118d 100644 --- a/src/WalletLegacy/WalletSendTransactionContext.h +++ b/src/WalletLegacy/WalletSendTransactionContext.h @@ -37,7 +37,6 @@ struct SendTransactionContext std::vector messages; uint64_t ttl; uint32_t depositTerm; - uint64_t height; }; } //namespace cn diff --git a/src/WalletLegacy/WalletTransactionSender.cpp b/src/WalletLegacy/WalletTransactionSender.cpp index 555bba38..710ad1da 100644 --- a/src/WalletLegacy/WalletTransactionSender.cpp +++ b/src/WalletLegacy/WalletTransactionSender.cpp @@ -277,7 +277,6 @@ namespace cn uint64_t term, uint64_t amount, uint64_t fee, - uint64_t height, uint64_t mixIn) { @@ -297,7 +296,6 @@ namespace cn context->transactionId = transactionId; context->mixIn = mixIn; context->depositTerm = static_cast(term); - context->height = height; if (context->mixIn != 0) { diff --git a/src/WalletLegacy/WalletTransactionSender.h b/src/WalletLegacy/WalletTransactionSender.h index 7cf0dc7f..07e7ead7 100644 --- a/src/WalletLegacy/WalletTransactionSender.h +++ b/src/WalletLegacy/WalletTransactionSender.h @@ -46,7 +46,6 @@ class WalletTransactionSender uint64_t term, uint64_t amount, uint64_t fee, - uint64_t height, uint64_t mixIn = 0); std::unique_ptr makeWithdrawDepositRequest(TransactionId& transactionId, From f2fabc03bdc41bd1cc2c87690c31581c4d077be4 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Tue, 7 Jun 2022 11:52:28 +0100 Subject: [PATCH 46/48] Make help & ext_help stand out --- src/SimpleWallet/SimpleWallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 8584114a..578049e1 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -650,7 +650,8 @@ simple_wallet::simple_wallet(platform_system::Dispatcher& dispatcher, const cn:: std::string simple_wallet::simple_menu() { std::string menu_item = "\t\tConceal Wallet Menu\n\n"; - menu_item += "[ ] = Optional arg\n"; + menu_item += "[ ] = Optional arg\n\n"; + menu_item += "\"help\" | \"ext_help\" - Shows this help dialog or extended help dialog.\n\n"; 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"; @@ -658,7 +659,6 @@ std::string simple_wallet::simple_menu() menu_item += "\"deposit_info \" - Display full information for deposit .\n"; menu_item += "\"exit\" - Safely exits the wallet application.\n"; menu_item += "\"export_keys\" - Displays backup keys.\n"; - menu_item += "\"help\" | \"ext_help\" - Shows this help dialog or extended help dialog.\n"; menu_item += "\"list_deposits\" - Show all known deposits, optionally from a certain height. | \n"; menu_item += "\"list_transfers\" - Show all known transfers, optionally from a certain height. | \n"; menu_item += "\"reset\" - Reset cached blockchain data and starts synchronizing from block 0.\n"; From f0a9e1451233b693a827e67d9fa8aea13fdb1bd8 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Tue, 7 Jun 2022 15:56:13 +0100 Subject: [PATCH 47/48] Remove optional arg message --- src/SimpleWallet/SimpleWallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SimpleWallet/SimpleWallet.cpp b/src/SimpleWallet/SimpleWallet.cpp index 578049e1..258acdce 100644 --- a/src/SimpleWallet/SimpleWallet.cpp +++ b/src/SimpleWallet/SimpleWallet.cpp @@ -659,7 +659,7 @@ std::string simple_wallet::simple_menu() menu_item += "\"deposit_info \" - Display full information for deposit .\n"; menu_item += "\"exit\" - Safely exits the wallet application.\n"; menu_item += "\"export_keys\" - Displays backup keys.\n"; - menu_item += "\"list_deposits\" - Show all known deposits, optionally from a certain height. | \n"; + menu_item += "\"list_deposits\" - Show all known deposits.\n"; menu_item += "\"list_transfers\" - Show all known transfers, optionally from a certain height. | \n"; menu_item += "\"reset\" - Reset cached blockchain data and starts synchronizing from block 0.\n"; menu_item += "\"transfer
\" - Transfers to
. | [-p] []...[] []...[]\n"; From acbe69440caf673397feba083575d4512bec5fc4 Mon Sep 17 00:00:00 2001 From: Jay Taylor <92698655+cartoon-face@users.noreply.github.com> Date: Tue, 7 Jun 2022 16:03:06 +0100 Subject: [PATCH 48/48] Use TxInfo for unlock height using tx height + deposit term --- src/SimpleWallet/DepositHelper.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/SimpleWallet/DepositHelper.cpp b/src/SimpleWallet/DepositHelper.cpp index 34f90216..6d09aa2d 100644 --- a/src/SimpleWallet/DepositHelper.cpp +++ b/src/SimpleWallet/DepositHelper.cpp @@ -61,19 +61,16 @@ namespace cn std::string deposit_helper::get_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency, cn::WalletLegacyTransaction txInfo) { std::string unlock_str = ""; + uint64_t actual_unlock_height = deposit_height(txInfo) + deposit_term(deposit); - bool bad_unlock = deposit.unlockHeight > cn::parameters::CRYPTONOTE_MAX_BLOCK_NUMBER; + bool bad_unlock = actual_unlock_height > cn::parameters::CRYPTONOTE_MAX_BLOCK_NUMBER; if (bad_unlock) unlock_str = "Please wait."; else - unlock_str = std::to_string(deposit_unlock_height(deposit)); + unlock_str = std::to_string(actual_unlock_height); bool bad_unlock2 = unlock_str == "0"; if (bad_unlock2) - unlock_str = std::to_string(deposit_height(txInfo) + deposit_term(deposit)); - - bool bad_unlock3 = unlock_str == "0"; - if (bad_unlock3) unlock_str = "ERROR"; std::stringstream full_info; @@ -93,19 +90,16 @@ namespace cn std::string deposit_helper::get_full_deposit_info(cn::Deposit deposit, cn::DepositId did, const Currency& currency, cn::WalletLegacyTransaction txInfo) { std::string unlock_str = ""; + uint64_t actual_unlock_height = deposit_height(txInfo) + deposit_term(deposit); - bool bad_unlock = deposit_unlock_height(deposit) > cn::parameters::CRYPTONOTE_MAX_BLOCK_NUMBER; + bool bad_unlock = actual_unlock_height > cn::parameters::CRYPTONOTE_MAX_BLOCK_NUMBER; if (bad_unlock) unlock_str = "Please wait."; else - unlock_str = std::to_string(deposit_unlock_height(deposit)); + unlock_str = std::to_string(actual_unlock_height); bool bad_unlock2 = unlock_str == "0"; if (bad_unlock2) - unlock_str = std::to_string(deposit_height(txInfo) + deposit_term(deposit)); - - bool bad_unlock3 = unlock_str == "0"; - if (bad_unlock3) unlock_str = "ERROR"; std::stringstream full_info; @@ -122,4 +116,4 @@ namespace cn return as_str; } -} \ No newline at end of file +}