From 52440749ed54f18ece25e7d3f06014dc066a079b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sun, 24 Oct 2021 17:42:11 +0200 Subject: [PATCH] added api fo exporting tx history from UI --- src/gui/qt-daemon/application/mainwindow.cpp | 11 +++++- src/gui/qt-daemon/application/mainwindow.h | 1 + src/simplewallet/simplewallet.cpp | 41 -------------------- src/wallet/view_iface.h | 14 +++++++ src/wallet/wallets_manager.cpp | 18 +++++++++ src/wallet/wallets_manager.h | 1 + 6 files changed, 44 insertions(+), 42 deletions(-) diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 53ae989a..5f0347e4 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -834,7 +834,16 @@ bool MainWindow::set_is_disabled_notifications(const bool& param) m_config.disable_notifications = param; return m_config.disable_notifications; } - +QString MainWindow::export_wallet_history(const QString& param) +{ + TRY_ENTRY(); + LOG_API_TIMING(); + PREPARE_ARG_FROM_JSON(view::export_wallet_info, ewi); + PREPARE_RESPONSE(view::api_response, ar); + ar.error_code = m_backend.export_wallet_history(ewi); + return MAKE_RESPONSE(ar); + CATCH_ENTRY2(false); +} bool MainWindow::update_wallets_info(const view::wallets_summary_info& wsi) { TRY_ENTRY(); diff --git a/src/gui/qt-daemon/application/mainwindow.h b/src/gui/qt-daemon/application/mainwindow.h index 578892ac..58bcb4ff 100644 --- a/src/gui/qt-daemon/application/mainwindow.h +++ b/src/gui/qt-daemon/application/mainwindow.h @@ -154,6 +154,7 @@ public: bool get_is_disabled_notifications(); bool set_is_disabled_notifications(const bool& param); + QString export_wallet_history(const QString& param); QString get_log_file(); QString check_available_sources(const QString& param); QString open_url_in_browser(const QString& param); diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 1de92a33..cfb48a64 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -838,47 +838,6 @@ bool simple_wallet::export_recent_transfers(const std::vector& args success_msg_writer() << "Failed"; return false; } - - -// std::vector unconfirmed; -// std::vector recent; -// uint64_t total = 0; -// uint64_t last_index = 0; -// m_wallet->get_recent_transfers_history(recent, 0, 0, total, last_index, false); -// m_wallet->get_unconfirmed_transfers(unconfirmed, false); -// //workaround for missed fee -// stringstream ss; -// LOG_PRINT_GREEN("Generating text....", LOG_LEVEL_0); -// ss << "Unconfirmed transfers: " << ENDL; -// for (auto & wti : unconfirmed) -// { -// if(ignore_pos && wti.is_mining) -// continue; -// if (!wti.fee) -// wti.fee = currency::get_tx_fee(wti.tx); -// if(export_to_json) -// ss << epee::serialization::store_t_to_json(wti) << ENDL; -// else -// ss << wti_to_text_line(wti) << ENDL; -// -// } -// ss << "Recent transfers: " << ENDL; -// for (auto & wti : recent) -// { -// if (ignore_pos && wti.is_mining) -// continue; -// if (!wti.fee) -// wti.fee = currency::get_tx_fee(wti.tx); -// -// if (export_to_json) -// ss << epee::serialization::store_t_to_json(wti) << ENDL; -// else -// ss << wti_to_text_line(wti) << ENDL; -// } -// LOG_PRINT_GREEN("Storing text to wallet_recent_transfers.txt....", LOG_LEVEL_0); -// file_io_utils::save_string_to_file(log_space::log_singletone::get_default_log_folder() + "/wallet_recent_transfers.txt", ss.str()); -// LOG_PRINT_GREEN("Done", LOG_LEVEL_0); - return true; } //---------------------------------------------------------------------------------------------------- diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index 1dc31f2c..8c5e52c4 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -284,6 +284,20 @@ public: END_KV_SERIALIZE_MAP() }; + struct export_wallet_info + { + uint64_t wallet_id; + bool include_pos_transactions; + std::string path; + std::string format; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(wallet_id) + KV_SERIALIZE(include_pos_transactions) + KV_SERIALIZE(path) + KV_SERIALIZE(format) + END_KV_SERIALIZE_MAP() + }; struct response_mining_estimate { diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 5941533d..2beb7c2f 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -803,6 +803,24 @@ std::string wallets_manager::get_tx_pool_info(currency::COMMAND_RPC_GET_POOL_INF } +std::string wallets_manager::export_wallet_history(const view::export_wallet_info& ewi) +{ + GET_WALLET_OPT_BY_ID(ewi.wallet_id, wo); + try { + + boost::filesystem::ofstream fstream; + fstream.exceptions(std::ifstream::failbit | std::ifstream::badbit); + fstream.open(ewi.path, std::ios_base::binary | std::ios_base::out | std::ios_base::trunc); + wo.w->get()->export_transaction_history(fstream, ewi.format, ewi.include_pos_transactions); + fstream.close(); + } + catch (...) + { + return API_RETURN_CODE_FAIL; + } + return API_RETURN_CODE_OK; +} + uint64_t wallets_manager::get_default_fee() { return TX_DEFAULT_FEE; diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index 80c25dcb..10d6a103 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -139,6 +139,7 @@ public: std::string get_my_offers(const bc_services::core_offers_filter& filter, std::list& offers); std::string get_fav_offers(const std::list& hashes, const bc_services::core_offers_filter& filter, std::list& offers); std::string get_tx_pool_info(currency::COMMAND_RPC_GET_POOL_INFO::response& res); + std::string export_wallet_history(const view::export_wallet_info& ewi); uint64_t get_default_fee(); std::string get_mining_estimate(uint64_t amuont_coins, uint64_t time,