From fb1626d11d730e8c6d6f632c4be10acf6079cf45 Mon Sep 17 00:00:00 2001 From: Deniod Date: Thu, 11 Jan 2024 17:45:12 +0100 Subject: [PATCH] less DEBUG flood, add an automation that triggers when there are less than 7 free spendable notes and increases their number by executing a transaction with the amount = fee by replacing a sietch transaction. --- src/addressbook.cpp | 2 +- src/chatmodel.cpp | 2 +- src/connection.cpp | 6 ++--- src/controller.cpp | 59 +++++++++++++++++++++++++++++++++++---------- src/mainwindow.cpp | 4 +-- 5 files changed, 53 insertions(+), 20 deletions(-) diff --git a/src/addressbook.cpp b/src/addressbook.cpp index e57f160..67afada 100644 --- a/src/addressbook.cpp +++ b/src/addressbook.cpp @@ -304,7 +304,7 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target) }); auto fnSetTargetLabelAddr = [=] (QLineEdit* target, QString label, QString addr, QString myAddr, QString cid, QString avatar) { - qDebug() << __func__ << ": label=" << label << " cid=" << cid << " avatar=" << avatar; + // qDebug() << __func__ << ": label=" << label << " cid=" << cid << " avatar=" << avatar; target->setText(label % "/" % addr % myAddr); }; diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 6ea9ee1..5f4a601 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -794,7 +794,7 @@ Tx MainWindow::createTxForSafeContactRequest() if (crypto_kx_seed_keypair(pk, sk, MESSAGEAS1) !=0) { this->logger->write("Suspicious client public contact request key, bail out "); - qDebug() << __func__ << ": Suspicious client public send key from crypto_kx_seed_keypair, aborting!"; + // qDebug() << __func__ << ": Suspicious client public send key from crypto_kx_seed_keypair, aborting!"; return tx; } diff --git a/src/connection.cpp b/src/connection.cpp index 528f674..ac1b0a1 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -34,7 +34,7 @@ ConnectionLoader::ConnectionLoader(MainWindow* main, Controller* rpc) connD->setupUi(d); auto theme = Settings::getInstance()->get_theme_name(); - DEBUG("theme " << theme << " has loaded"); + //DEBUG("theme " << theme << " has loaded"); auto size = QSize(512,512); if (theme == "Dark" || theme == "Midnight") { @@ -57,7 +57,7 @@ ConnectionLoader::ConnectionLoader(MainWindow* main, Controller* rpc) ConnectionLoader::~ConnectionLoader() { - DEBUG("destroying ConnectionLoader"); + // DEBUG("destroying ConnectionLoader"); delete isSyncing; delete connD; delete d; @@ -389,7 +389,7 @@ QString litelib_process_response(char* resp) void Executor::run() { auto config = std::shared_ptr(new ConnectionConfig()); - DEBUG("cmd=" << cmd << " args=" << args << " server=" << config->server); + //DEBUG("cmd=" << cmd << " args=" << args << " server=" << config->server); QString response = ""; try { char* resp = litelib_execute(this->cmd.toStdString().c_str(), this->args.toStdString().c_str()); diff --git a/src/controller.cpp b/src/controller.cpp index cd2c639..724cc1d 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -126,7 +126,8 @@ void Controller::setConnection(Connection* c) ui->listChat->verticalScrollBar()->setValue( ui->listChat->verticalScrollBar()->maximum()); - fetchAndProcessUnspentNotes(); + //fetch amounts of notes at startup + fetchAndProcessUnspentNotes(); } @@ -160,14 +161,15 @@ void Controller::fillTxJsonParams(json& allRecepients, Tx tx) DataStore::getSietchDataStore()->clear(); // clears the datastore - // Debugging, um die Daten aus NoteCountDataStore zu zeigen -int spendableNotesCount = NoteCountDataStore::getInstance()->getSpendableNotesCount(); -QString addressWithMaxValue = NoteCountDataStore::getInstance()->getAddressWithMaxValue(); - -qDebug() << "Anzahl der spendablen Notizen über 10000:" << spendableNotesCount; -qDebug() << "Adresse mit dem höchsten Gesamtwert:" << addressWithMaxValue; + // 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(); + const QString possibleCharacters("0123456789abcdef"); int sizerandomString = 512; const int randomStringLength = sizerandomString; @@ -186,10 +188,40 @@ qDebug() << "Adresse mit dem höchsten Gesamtwert:" << addressWithMaxValue; } - for(auto &it: dust) - { + // Create more Notes if spendableNotesCount < 7 + bool extraTransactionAdded = false; + + if (spendableNotesCount < 7) { + // Create a random memo for that + QString randomMemo; + for (int i = 0; i < randomStringLength; ++i) { + int index = QRandomGenerator::system()->bounded(0, possibleCharacters.length()); + randomMemo.append(possibleCharacters.at(index)); + } + + // create the transaction + json extraTransaction = json::object(); + extraTransaction["address"] = addressWithMaxValue.toStdString(); + extraTransaction["amount"] = 12000; + extraTransaction["memo"] = randomMemo.toStdString(); + + // Replace one sietch transaction + if (!dust.empty()) { + dust.front() = extraTransaction; + extraTransactionAdded = true; + } else { + dust.push_back(extraTransaction); + extraTransactionAdded = true; + } + } + + // Set amount = 0 to all sietch transactions + for(auto &it: dust) { + if (!extraTransactionAdded || it["address"] != addressWithMaxValue.toStdString()) { it["amount"] = 0; } + +} // For each addr/amt/memo, construct the JSON and also build the confirm dialog box for (int i=0; i < tx.toAddrs.size(); i++) @@ -249,7 +281,6 @@ qDebug() << "Adresse mit dem höchsten Gesamtwert:" << addressWithMaxValue; } } - } void Controller::noConnection() @@ -1545,8 +1576,11 @@ void Controller::executeStandardUITransaction(Tx tx) // Execute a transaction! void Controller::executeTransaction(Tx tx, const std::function submitted, - const std::function error) + const std::function error) { +// Refresh the available unspent notes + fetchAndProcessUnspentNotes(); + unlockIfEncrypted([=] () { // First, create the json params json params = json::array(); @@ -1572,7 +1606,6 @@ void Controller::executeTransaction(Tx tx, }); } - void Controller::checkForUpdate(bool silent) { // qDebug()<< __func__; @@ -1666,7 +1699,7 @@ void Controller::checkForUpdate(bool silent) // Get the hush->USD price from coinmarketcap using their API void Controller::refreshHUSHPrice() { - qDebug()<< __func__; + // qDebug()<< __func__; if (!zrpc->haveConnection()) return; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9873dd6..8137b60 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -427,7 +427,7 @@ void MainWindow::closeEvent(QCloseEvent* event) { void MainWindow::closeEventpw(QCloseEvent* event) { // Let the RPC know to shut down any running service. - qDebug() << __func__ << ": event=" << event << " this=" << this; + // qDebug() << __func__ << ": event=" << event << " this=" << this; if (rpc) { rpc->shutdownhushd(); } else { @@ -742,7 +742,7 @@ void MainWindow::setMoneyMemo(QString moneymemo) } void MainWindow::setupStatusBar() { - qDebug() << __func__ << endl; + // qDebug() << __func__ << endl; // Status Bar loadingLabel = new QLabel(); loadingMovie = new QMovie(":/icons/res/loading.gif");