From 2dfc2862fcd603cf593ab905d59ed28546b68e1e Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 9 Apr 2022 22:36:11 +0200 Subject: [PATCH] tor integration in UI --- src/CMakeLists.txt | 2 +- src/gui/qt-daemon/application/mainwindow.cpp | 11 +++++++++++ src/gui/qt-daemon/application/mainwindow.h | 2 ++ src/wallet/view_iface.h | 13 +++++++++++++ src/wallet/wallet_id_adapter.h | 6 ++++++ src/wallet/wallets_manager.cpp | 7 +++++++ src/wallet/wallets_manager.h | 2 ++ 7 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 063a651b..892a8585 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -194,7 +194,7 @@ if(BUILD_GUI) QT5_USE_MODULES(Zano WebEngineWidgets WebChannel) find_package(Qt5PrintSupport REQUIRED) - target_link_libraries(Zano wallet rpc currency_core crypto common zlibstatic ethash Qt5::WebEngineWidgets Qt5::PrintSupport ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) + target_link_libraries(Zano wallet rpc currency_core crypto common zlibstatic ethash tor-connect Qt5::WebEngineWidgets Qt5::PrintSupport ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) if (UNIX AND NOT APPLE) target_link_libraries(Zano rt) endif() diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 646e4d3b..370d06c4 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -947,6 +947,17 @@ bool MainWindow::set_options(const view::gui_options& opt) CATCH_ENTRY2(false); } +bool MainWindow::update_tor_status(const view::current_action_status& opt) +{ + TRY_ENTRY(); + std::string json_str; + epee::serialization::store_t_to_json(opt, json_str, 0, epee::serialization::eol_lf); + LOG_PRINT_L0("SENDING SIGNAL -> [HANDLE_CURRENT_ACTION_STATE]:" << std::endl << json_str); + QMetaObject::invokeMethod(this, "handle_current_action_state", Qt::QueuedConnection, Q_ARG(QString, json_str.c_str())); + return true; + CATCH_ENTRY2(false); +} + bool MainWindow::nativeEventFilter(const QByteArray &eventType, void *message, long *result) { TRY_ENTRY(); diff --git a/src/gui/qt-daemon/application/mainwindow.h b/src/gui/qt-daemon/application/mainwindow.h index 4f7af71d..dfe9ae4b 100644 --- a/src/gui/qt-daemon/application/mainwindow.h +++ b/src/gui/qt-daemon/application/mainwindow.h @@ -197,6 +197,7 @@ signals: void set_options(const QString str); //general function void get_wallet_name(); void handle_deeplink_click(const QString str); + void handle_current_action_state(const QString str); private: //-------------------- i_core_event_handler -------------------- @@ -216,6 +217,7 @@ private: virtual bool init(const std::string& path); virtual bool pos_block_found(const currency::block& block_found); virtual bool set_options(const view::gui_options& opt); + virtual bool update_tor_status(const view::current_action_status& opt); //--------- QAbstractNativeEventFilter --------------------------- virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result); //---------------------------------------------- diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index 8c5e52c4..edf78d14 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -600,6 +600,18 @@ public: END_KV_SERIALIZE_MAP() }; + struct current_action_status + { + uint64_t wallet_id; + std::string status; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(wallet_id) + KV_SERIALIZE(status) + END_KV_SERIALIZE_MAP() + }; + + struct wallet_sync_status_info { bool is_daemon_connected; @@ -828,6 +840,7 @@ public: virtual bool pos_block_found(const currency::block& block_found){ return true; } virtual bool money_transfer_cancel(const transfer_event_info& wsi){ return true; } virtual bool set_options(const gui_options& opt){ return true; } + virtual bool update_tor_status(const current_action_status & opt) { return true; } }; } diff --git a/src/wallet/wallet_id_adapter.h b/src/wallet/wallet_id_adapter.h index b36b5bac..4a4b0a8c 100644 --- a/src/wallet/wallet_id_adapter.h +++ b/src/wallet/wallet_id_adapter.h @@ -16,6 +16,7 @@ public: virtual void on_pos_block_found(size_t wallet_id, const currency::block& /*block*/) {} virtual void on_sync_progress(size_t wallet_id, const uint64_t& /*percents*/) {} virtual void on_transfer_canceled(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti) {} + virtual void on_tor_status_change(size_t wallet_id, const std::string& state) {} }; struct i_wallet_to_i_backend_adapter: public tools::i_wallet2_callback @@ -39,6 +40,11 @@ struct i_wallet_to_i_backend_adapter: public tools::i_wallet2_callback virtual void on_transfer_canceled(const tools::wallet_public::wallet_transfer_info& wti) { m_pbackend->on_transfer_canceled(m_wallet_id, wti); } + virtual void on_tor_status_change(const std::string& state) + { + m_pbackend->on_tor_status_change(m_wallet_id, state); + } + private: i_backend_wallet_callback* m_pbackend; size_t m_wallet_id; diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 9171a27f..075b1bd5 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1871,6 +1871,13 @@ void wallets_manager::on_transfer_canceled(size_t wallet_id, const tools::wallet } m_pview->money_transfer_cancel(tei); } + +void wallets_manager::on_tor_status_change(size_t wallet_id, const std::string& state) +{ + view::current_action_status tsu = { wallet_id , state }; + m_pview->update_tor_status(tsu); +} + void wallets_manager::wallet_vs_options::worker_func() { LOG_PRINT_GREEN("[WALLET_HANDLER] Wallet handler thread started, addr: " << w->get()->get_account().get_public_address_str(), LOG_LEVEL_0); diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index ac64041c..5b919a0b 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -187,6 +187,8 @@ private: virtual void on_pos_block_found(size_t wallet_id, const currency::block& /*block*/); virtual void on_sync_progress(size_t wallet_id, const uint64_t& /*percents*/); virtual void on_transfer_canceled(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti); + virtual void on_tor_status_change(size_t wallet_id, const std::string& state); + std::thread m_main_worker_thread;