Merge pull request 'Update lib with WalletTx version changes, Sticky Server and Note Automation as GUI setting, fix for getRandomServer' (#145) from lucretius/SilentDragonLite:dev into dev
Reviewed-on: https://git.hush.is/hush/SilentDragonLite/pulls/145
This commit is contained in:
2
lib/Cargo.lock
generated
2
lib/Cargo.lock
generated
@@ -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",
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -35,8 +35,8 @@ 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();
|
||||
main->ui->sticky_server->setText( isStickyServerEnabled ? "True" : "False" );
|
||||
|
||||
// Setup balances table model
|
||||
balancesTableModel = new BalancesTableModel(main->ui->balancesTable);
|
||||
@@ -166,8 +166,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 +189,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
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
@@ -250,6 +249,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();
|
||||
@@ -317,17 +332,16 @@ 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();
|
||||
}
|
||||
|
||||
// if we see a valid connection, return this server
|
||||
if (response.toUpper().trimmed() == "OK") {
|
||||
// if we see a valid connection, return this server.
|
||||
if (isOnline) {
|
||||
qDebug() << "Choosing lite server " << server;
|
||||
return server;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
@@ -79,6 +79,20 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="chkUseStickyServer">
|
||||
<property name="text">
|
||||
<string>Use Sticky Server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="text">
|
||||
<string>Uses a fixed server instead of random </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
@@ -87,7 +101,7 @@
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
@@ -102,7 +116,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>80</x>
|
||||
<y>110</y>
|
||||
<y>190</y>
|
||||
<width>111</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
@@ -178,11 +192,27 @@
|
||||
<string>Connect to git on startup to check for updates</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QCheckBox" name="chkUseNoteAutomation">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>110</y>
|
||||
<width>200</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Use Note Automation</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_20">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>9</x>
|
||||
<y>113</y>
|
||||
<x>10</x>
|
||||
<y>190</y>
|
||||
<width>47</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
@@ -203,8 +233,8 @@
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>180</y>
|
||||
<x>0</x>
|
||||
<y>300</y>
|
||||
<width>691</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
@@ -222,7 +252,7 @@
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>9</x>
|
||||
<x>10</x>
|
||||
<y>90</y>
|
||||
<width>601</width>
|
||||
<height>17</height>
|
||||
@@ -236,7 +266,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>150</y>
|
||||
<y>230</y>
|
||||
<width>61</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
@@ -258,7 +288,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>80</x>
|
||||
<y>150</y>
|
||||
<y>230</y>
|
||||
<width>111</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
@@ -320,6 +350,19 @@
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>140</y>
|
||||
<width>601</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Increases the number of zutxo for instant hushchat</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user