From 6f7fd863f01ed84596cc9661a989cac6c8d15816 Mon Sep 17 00:00:00 2001 From: lucretius Date: Sun, 21 Jan 2024 12:26:07 +0100 Subject: [PATCH 1/6] Sticky Server and Note Automation as GUI setting --- lib/Cargo.lock | 2 +- lib/Cargo.toml | 2 +- src/controller.cpp | 17 ++++++++----- src/mainwindow.cpp | 15 ++++++++++- src/sendtab.cpp | 4 +-- src/settings.cpp | 17 +++++++++++++ src/settings.h | 6 +++++ src/settings.ui | 63 ++++++++++++++++++++++++++++++++++++++-------- 8 files changed, 105 insertions(+), 21 deletions(-) diff --git a/lib/Cargo.lock b/lib/Cargo.lock index 2166ad1..b74002a 100644 --- a/lib/Cargo.lock +++ b/lib/Cargo.lock @@ -1849,7 +1849,7 @@ dependencies = [ [[package]] name = "silentdragonlitelib" version = "0.1.0" -source = "git+https://git.hush.is/hush/silentdragonlite-cli?rev=568d7b7860ec0b848cb84474f38b25bed890de09#568d7b7860ec0b848cb84474f38b25bed890de09" +source = "git+https://git.hush.is/hush/silentdragonlite-cli?rev=1334c89e0f4ddd23725020e16753d0ea95c09bf5#1334c89e0f4ddd23725020e16753d0ea95c09bf5" dependencies = [ "base58", "bellman", diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 2bc90af..c25ef8d 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -12,4 +12,4 @@ crate-type = ["staticlib"] libc = "0.2.58" lazy_static = "1.4.0" blake3 = "0.3.4" -silentdragonlitelib = { git = "https://git.hush.is/hush/silentdragonlite-cli", rev = "568d7b7860ec0b848cb84474f38b25bed890de09" } +silentdragonlitelib = { git = "https://git.hush.is/hush/silentdragonlite-cli", rev = "1334c89e0f4ddd23725020e16753d0ea95c09bf5" } diff --git a/src/controller.cpp b/src/controller.cpp index c597158..89e061d 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -35,8 +35,11 @@ Controller::Controller(MainWindow* main) auto current_server = Settings::getInstance()->getSettings().server; main->ui->current_server->setText(current_server); - auto stickyServer = Settings::getInstance()->getSettings().stickyServer; - main->ui->sticky_server->setText( stickyServer ? "True" : "False" ); + bool isStickyServerEnabled = Settings::getInstance()->getUseStickyServer(); + qDebug() << "Sticky Server Status senden" << isStickyServerEnabled; + main->ui->sticky_server->setText( isStickyServerEnabled ? "True" : "False" ); + + //auto stickyServer = Settings::getInstance()->getSettings().stickyServer; // Setup balances table model balancesTableModel = new BalancesTableModel(main->ui->balancesTable); @@ -166,8 +169,6 @@ void Controller::fillTxJsonParams(json& allRecepients, Tx tx) // Only for Debugging/Testing: How many free Notes are available? int spendableNotesCount = NoteCountDataStore::getInstance()->getSpendableNotesCount(); QString addressWithMaxValue = NoteCountDataStore::getInstance()->getAddressWithMaxValue(); - - qDebug() << "Available notes over fee:" << spendableNotesCount; // Clear NoteCountDataStore DataStore::getNoteCountDataStore()->clear(); @@ -191,8 +192,12 @@ void Controller::fillTxJsonParams(json& allRecepients, Tx tx) } CAmount balanceAvailable = getModel()->getBalVerified(); - // Create more Notes if spendableNotesCount < 30 and enough funds are available - if (spendableNotesCount < 30 && balanceAvailable.toDecimalString().toDouble() > (dustTransactions.size() * 0.0001)) { + bool isNoteAutomationEnabled = Settings::getInstance()->getUseNoteAutomation(); + // Create more Notes if spendableNotesCount < 30 and enough funds are available and note automation is checked in settings tab + + if (spendableNotesCount < 30 && + balanceAvailable.toDecimalString().toDouble() > (dustTransactions.size() * 0.0001) && + isNoteAutomationEnabled) { // Create extra transaction for (size_t i = 0; i < dustTransactions.size(); ++i) { // Generate random memo diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8137b60..650209f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -838,7 +838,13 @@ void MainWindow::setupSettingsModal() { // Fetch prices settings.chkFetchPrices->setChecked(Settings::getInstance()->getAllowFetchPrices()); - + + // Check Status of StickyServer + settings.chkUseStickyServer->setChecked(Settings::getInstance()->getUseStickyServer()); + + // Check Status of Note Automation + settings.chkUseNoteAutomation->setChecked(Settings::getInstance()->getUseNoteAutomation()) + // List of default servers settings.cmbServer->addItem("https://lite.hush.is"); settings.cmbServer->addItem("https://lite.hush.land"); @@ -867,6 +873,13 @@ void MainWindow::setupSettingsModal() { // Allow fetching prices Settings::getInstance()->setAllowFetchPrices(settings.chkFetchPrices->isChecked()); + // Set State for Use Sticky Server + Settings::getInstance()->setUseStickyServer(settings.chkUseStickyServer->isChecked()); + + // Set State for Use Note Automation + Settings::getInstance()->setUseNoteAutomation(settings.chkUseNoteAutomation->isChecked()); + + // Save the server bool reloadConnection = false; if (conf.server != settings.cmbServer->currentText().trimmed()) { diff --git a/src/sendtab.cpp b/src/sendtab.cpp index 38bd5e1..d32a987 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -881,8 +881,8 @@ void MainWindow::sendButton() { ui->tabWidget->setCurrentIndex(0); }); - auto stickyServer = Settings::getInstance()->getSettings().stickyServer; - if(stickyServer) { + bool isStickyServerEnabled = Settings::getInstance()->getUseStickyServer(); + if(isStickyServerEnabled) { qDebug() << "Not changing servers because stickyServer=1"; } else { // After each transaction, change servers to spread out diff --git a/src/settings.cpp b/src/settings.cpp index 3389412..c0b2aa2 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -139,6 +139,7 @@ double Settings::getHUSHPrice() { double Settings::getEURPrice() { return EURPrice; } + double Settings::getBTCPrice() { return BTCPrice; } @@ -250,6 +251,22 @@ void Settings::setAllowFetchPrices(bool allow) { QSettings().setValue("options/allowfetchprices", allow); } +bool Settings::getUseStickyServer() { + return QSettings().value("connection/stickyServer", false).toBool(); +} + +void Settings::setUseStickyServer(bool allow) { + QSettings().setValue("connection/stickyServer", allow); +} + +bool Settings::getUseNoteAutomation() { + return QSettings().value("options/useNoteAutomation", true).toBool(); +} + +void Settings::setUseNoteAutomation(bool allow) { + QSettings().setValue("options/useNoteAutomation", allow); +} + QString Settings::get_currency_name() { // Load from the QT Settings. return QSettings().value("options/currency_name", false).toString(); diff --git a/src/settings.h b/src/settings.h index 376131b..30b9434 100644 --- a/src/settings.h +++ b/src/settings.h @@ -66,6 +66,12 @@ public: bool getCheckForUpdates(); void setCheckForUpdates(bool allow); + bool getUseStickyServer(); + void setUseStickyServer(bool allow); + + bool getUseNoteAutomation(); + void setUseNoteAutomation(bool allow); + QString get_theme_name(); void set_theme_name(QString theme_name); diff --git a/src/settings.ui b/src/settings.ui index 5bf80df..4eed716 100644 --- a/src/settings.ui +++ b/src/settings.ui @@ -38,7 +38,7 @@ - 1 + 0 @@ -79,6 +79,20 @@ + + + + Use Sticky Server + + + + + + + Uses a fixed server instead of random + + + @@ -87,7 +101,7 @@ 20 - 40 + 20 @@ -102,7 +116,7 @@ 80 - 110 + 190 111 25 @@ -178,11 +192,27 @@ Connect to git on startup to check for updates + + + + 10 + 110 + 200 + 23 + + + + Use Note Automation + + + true + + - 9 - 113 + 10 + 190 47 17 @@ -203,8 +233,8 @@ - 10 - 180 + 0 + 300 691 16 @@ -222,7 +252,7 @@ - 9 + 10 90 601 17 @@ -236,7 +266,7 @@ 10 - 150 + 230 61 20 @@ -258,7 +288,7 @@ 80 - 150 + 230 111 25 @@ -320,6 +350,19 @@ + + + + 10 + 140 + 601 + 17 + + + + Increases the number of zutxo for instant hushchat + + From 24d262dcb9862102e692dda7e165a60775f33510 Mon Sep 17 00:00:00 2001 From: lucretius Date: Sun, 21 Jan 2024 12:28:35 +0100 Subject: [PATCH 2/6] deactivate debug for StickyServer --- src/controller.cpp | 3 --- src/settings.cpp | 1 - 2 files changed, 4 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index 89e061d..89fc73f 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -36,11 +36,8 @@ Controller::Controller(MainWindow* main) main->ui->current_server->setText(current_server); bool isStickyServerEnabled = Settings::getInstance()->getUseStickyServer(); - qDebug() << "Sticky Server Status senden" << isStickyServerEnabled; main->ui->sticky_server->setText( isStickyServerEnabled ? "True" : "False" ); - //auto stickyServer = Settings::getInstance()->getSettings().stickyServer; - // Setup balances table model balancesTableModel = new BalancesTableModel(main->ui->balancesTable); main->ui->balancesTable->setModel(balancesTableModel); diff --git a/src/settings.cpp b/src/settings.cpp index c0b2aa2..f68965a 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -139,7 +139,6 @@ double Settings::getHUSHPrice() { double Settings::getEURPrice() { return EURPrice; } - double Settings::getBTCPrice() { return BTCPrice; } From 95090a90ad3cdc654d143abf53d806af498876e0 Mon Sep 17 00:00:00 2001 From: lucretius Date: Sun, 21 Jan 2024 12:53:07 +0100 Subject: [PATCH 3/6] add missing semicolon --- src/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 650209f..231dad7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -843,7 +843,7 @@ void MainWindow::setupSettingsModal() { settings.chkUseStickyServer->setChecked(Settings::getInstance()->getUseStickyServer()); // Check Status of Note Automation - settings.chkUseNoteAutomation->setChecked(Settings::getInstance()->getUseNoteAutomation()) + settings.chkUseNoteAutomation->setChecked(Settings::getInstance()->getUseNoteAutomation()); // List of default servers settings.cmbServer->addItem("https://lite.hush.is"); From 366f6e24bce526acca24c5a2594bfbfe67e5ca9b Mon Sep 17 00:00:00 2001 From: lucretius Date: Sun, 21 Jan 2024 13:17:00 +0100 Subject: [PATCH 4/6] fix for getRandomServer() --- src/settings.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/settings.cpp b/src/settings.cpp index f68965a..f8cbaa1 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -342,8 +342,10 @@ QString Settings::getRandomServer() { qDebug() << __func__ << ": caught an exception, ignoring: " << e.what(); } - // if we see a valid connection, return this server - if (response.toUpper().trimmed() == "OK") { + // if we see a valid connection, return this server. when the server is alive, + //it tries to read the wallet. This causes an error because it cannot find it (SDL only has a non-encrypted wallet.dat during storage processes) + // We can use that. + if (response.contains("Error: Cannot read wallet.")) { qDebug() << "Choosing lite server " << server; return server; } From d0b8ab074e4ea8f7a200dd06836cbf577f91f0fa Mon Sep 17 00:00:00 2001 From: lucretius Date: Sun, 21 Jan 2024 16:57:00 +0100 Subject: [PATCH 5/6] add new method for litelib to check if server is online --- lib/silentdragonlitelib.h | 1 + lib/src/lib.rs | 18 ++++++++++++++++++ src/settings.cpp | 14 ++++++-------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/silentdragonlitelib.h b/lib/silentdragonlitelib.h index ef856d8..982b2d5 100644 --- a/lib/silentdragonlitelib.h +++ b/lib/silentdragonlitelib.h @@ -14,6 +14,7 @@ extern char * litelib_initialize_existing (bool dangerous,const char* server); extern char * litelib_execute (const char* s, const char* args); extern void litelib_rust_free_string (char* s); extern char * blake3_PW (char* pw); +extern bool litelib_check_server_online (const char* server); #ifdef __cplusplus } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index d78c23d..afb398f 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -245,6 +245,24 @@ pub extern fn litelib_execute(cmd: *const c_char, args: *const c_char) -> *mut c return c_str.into_raw(); } +// Check is Server Connection is fine +#[no_mangle] +pub extern "C" fn litelib_check_server_online(server: *const c_char) -> bool { + let server_str = unsafe { + assert!(!server.is_null()); + + CStr::from_ptr(server).to_string_lossy().into_owned() + }; + + let server = LightClientConfig::get_server_or_default(Some(server_str)); + let result = LightClientConfig::create(server, false); + + match result { + Ok(_) => true, + Err(_) => false, + } +} + /** * Callers that receive string return values from other functions should call this to return the string * back to rust, so it can be freed. Failure to call this function will result in a memory leak diff --git a/src/settings.cpp b/src/settings.cpp index f8cbaa1..5e2470c 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -37,16 +37,15 @@ Config Settings::getSettings() { if (server.trimmed().isEmpty()) { server = Settings::getRandomServer(); - QString response = ""; + bool isOnline = false; // make sure existing server in conf is alive, otherwise choose random one try { - char* resp = litelib_initialize_existing(false, server.toStdString().c_str()); - response = litelib_process_response(resp); + bool isOnline = litelib_check_server_online(server.toStdString().c_str()); } catch (const std::exception& e) { qDebug() << __func__ << ": caught an exception, ignoring: " << e.what(); } - if (response.toUpper().trimmed() != "OK") { + if (!isOnline) { qDebug() << "Lite server in conf " << server << " is down, getting a random one"; server = Settings::getRandomServer(); s.setValue("connection/server", server); @@ -333,11 +332,10 @@ QString Settings::getRandomServer() { while (tries < servers.size() ) { qDebug() << "Checking if lite server " << server << " is a alive, try=" << tries; - QString response = ""; + bool isOnline = ""; try { - char* resp = litelib_initialize_existing(false, server.toStdString().c_str()); - response = litelib_process_response(resp); + isOnline = litelib_check_server_online(server.toStdString().c_str()); } catch (const std::exception& e) { qDebug() << __func__ << ": caught an exception, ignoring: " << e.what(); } @@ -345,7 +343,7 @@ QString Settings::getRandomServer() { // if we see a valid connection, return this server. when the server is alive, //it tries to read the wallet. This causes an error because it cannot find it (SDL only has a non-encrypted wallet.dat during storage processes) // We can use that. - if (response.contains("Error: Cannot read wallet.")) { + if (isOnline) { qDebug() << "Choosing lite server " << server; return server; } From 8da49166a83473beaa353588c38cca08e4e90df3 Mon Sep 17 00:00:00 2001 From: lucretius Date: Sun, 21 Jan 2024 17:07:12 +0100 Subject: [PATCH 6/6] delete not needed commentar --- src/settings.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/settings.cpp b/src/settings.cpp index 5e2470c..40a9224 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -340,9 +340,7 @@ QString Settings::getRandomServer() { qDebug() << __func__ << ": caught an exception, ignoring: " << e.what(); } - // if we see a valid connection, return this server. when the server is alive, - //it tries to read the wallet. This causes an error because it cannot find it (SDL only has a non-encrypted wallet.dat during storage processes) - // We can use that. + // if we see a valid connection, return this server. if (isOnline) { qDebug() << "Choosing lite server " << server; return server;