From cbc77e9d58c4808297f63c6da1950ba9a5945b2c Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 21 Dec 2021 12:37:13 -0500 Subject: [PATCH] more error checking, logging and fix some compiler warnings --- src/addressbook.cpp | 1 + src/firsttimewizard.cpp | 2 +- src/mainwindow.cpp | 56 ++++++++++++++++++++++------------------- src/settings.cpp | 7 ------ src/settings.h | 1 - src/websockets.cpp | 6 ----- 6 files changed, 32 insertions(+), 41 deletions(-) diff --git a/src/addressbook.cpp b/src/addressbook.cpp index 2a80795..76d708c 100644 --- a/src/addressbook.cpp +++ b/src/addressbook.cpp @@ -304,6 +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; target->setText(label % "/" % addr % myAddr); }; diff --git a/src/firsttimewizard.cpp b/src/firsttimewizard.cpp index 5ebadb1..b897b23 100644 --- a/src/firsttimewizard.cpp +++ b/src/firsttimewizard.cpp @@ -133,7 +133,7 @@ NewOrRestorePage::NewOrRestorePage(FirstTimeWizard *parent) : QWizardPage(parent form.setupUi(pageWidget); QGraphicsScene* scene = new QGraphicsScene(); - QGraphicsView* view = new QGraphicsView(scene); + //QGraphicsView* view = new QGraphicsView(scene); form.Logo->setScene(scene); QPixmap pixmap(":/icons/res/dark-01.png"); scene->addPixmap(pixmap); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8bbffc6..2ed601f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -76,12 +76,12 @@ MainWindow::MainWindow(QWidget *parent) : } this->slot_change_theme(theme_name); - ui->setupUi(this); auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); if (!dir.exists()){ + qDebug() << __func__ << ": creating dir=" << dir.absolutePath(); QDir().mkpath(dir.absolutePath()); }else{} @@ -175,7 +175,6 @@ MainWindow::MainWindow(QWidget *parent) : restoreSeed.setupUi(&dialog); Settings::saveRestore(&dialog); - rpc->fetchSeed([=](json reply) { if (isJsonError(reply)) { return; @@ -246,26 +245,29 @@ MainWindow::MainWindow(QWidget *parent) : tr("Couldn't save the wallet") + "\n" + reply, QMessageBox::Ok); - } else {} + } else { + qDebug() << __func__ << ": saved wallet correctly"; + } - dialog.close(); - // To rescan, we clear the wallet state, and then reload the connection + dialog.close(); + // To rescan, we clear the wallet state, and then reload the connection // This will start a sync, and show the scanning status. this->getRPC()->clearWallet([=] (auto) { + qDebug() << "Clearing wallet..."; // Save the wallet this->getRPC()->saveWallet([=] (auto) { + qDebug() << "Saving wallet..."; // Then reload the connection. The ConnectionLoader deletes itself. auto cl = new ConnectionLoader(this, rpc); - cl->loadConnection(); - }); - }); - + cl->loadConnection(); + }); + }); - } + } - }); - - dialog.exec(); + }); + + dialog.exec(); }); // Import Privkey @@ -432,6 +434,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; rpc->shutdownhushd(); } @@ -489,12 +492,16 @@ void MainWindow::encryptWallet() { unsigned char key[KEY_LEN]; - if (crypto_pwhash - (key, sizeof key, PASSWORD, strlen(PASSWORD), hash, + if (crypto_pwhash(key, sizeof key, PASSWORD, strlen(PASSWORD), hash, crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE, crypto_pwhash_ALG_DEFAULT) != 0) { /* out of memory */ -} + QMessageBox::information(this, tr("Out of memory!"), + QString("Please close some other programs to free up memory and try again"), + QMessageBox::Ok + ); + exit(1); + } QString passphraseHash1 = QByteArray(reinterpret_cast(key), KEY_LEN).toHex(); DataStore::getChatDataStore()->setPassword(passphraseHash1); @@ -995,6 +1002,7 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event) { // will prompt for one. If the myAddr is empty, then the default from address is used to send // the transaction. void MainWindow::payhushURI(QString uri, QString myAddr) { + qDebug() << __func__ << ": uri=" << uri << " myAddr=" << myAddr; // If the Payments UI is not ready (i.e, all balances have not loaded), defer the payment URI if (!isPaymentsReady()) { qDebug() << "Payment UI not ready, waiting for UI to pay URI"; @@ -1441,8 +1449,7 @@ void MainWindow::setupTransactionsTab() { int lastPost = memo.trimmed().lastIndexOf(QRegExp("[\r\n]+")); QString lastWord = memo.right(memo.length() - lastPost - 1); - if (Settings::getInstance()->isSaplingAddress(lastWord) || - Settings::getInstance()->isSproutAddress(lastWord)) { + if (Settings::getInstance()->isSaplingAddress(lastWord)) { menu.addAction(tr("Reply to ") + lastWord.left(25) + "...", [=]() { // First, cancel any pending stuff in the send tab by pretending to click // the cancel button @@ -2429,7 +2436,7 @@ void MainWindow::addNewZaddr(bool sapling) { } -// Adds sapling or sprout z-addresses to the combo box. Technically, returns a +// Adds sapling z-addresses to the combo box. Technically, returns a // lambda, which can be connected to the appropriate signal std::function MainWindow::addZAddrsToComboList(bool sapling) { return [=] (bool checked) { @@ -2770,9 +2777,7 @@ void MainWindow::updateLabels() { updateLabelsAutoComplete(); } -void MainWindow::slot_change_currency(const QString& currency_name) - -{ +void MainWindow::slot_change_currency(const QString& currency_name) { Settings::getInstance()->set_currency_name(currency_name); @@ -2788,9 +2793,7 @@ void MainWindow::slot_change_currency(const QString& currency_name) } } -void MainWindow::slot_change_theme(const QString& theme_name) - -{ +void MainWindow::slot_change_theme(const QString& theme_name) { Settings::getInstance()->set_theme_name(theme_name); @@ -2842,8 +2845,9 @@ void MainWindow::on_givemeZaddr_clicked() QMessageBox::information(this, "Your new HushChat address was copied to your clipboard!",hushchataddr); ui->listReceiveAddresses->insertItem(0, hushchataddr); ui->listReceiveAddresses->setCurrentIndex(0); + qDebug() << __func__ << ": hushchat zaddr=" << hushchataddr << " created"; - }); + }); } diff --git a/src/settings.cpp b/src/settings.cpp index f8f46b7..95ff7c3 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -95,13 +95,6 @@ bool Settings::isSaplingAddress(QString addr) { (!isTestnet() && addr.startsWith("zs1")); } -bool Settings::isSproutAddress(QString addr) { - if (!isValidAddress(addr)) - return false; - - return isZAddress(addr) && !isSaplingAddress(addr); -} - bool Settings::isZAddress(QString addr) { if (!isValidAddress(addr)) return false; diff --git a/src/settings.h b/src/settings.h index 8343424..581cd9d 100644 --- a/src/settings.h +++ b/src/settings.h @@ -42,7 +42,6 @@ public: void setTestnet(bool isTestnet); bool isSaplingAddress(QString addr); - bool isSproutAddress(QString addr); bool isValidSaplingPrivateKey(QString pk); diff --git a/src/websockets.cpp b/src/websockets.cpp index d65c6de..4d36616 100644 --- a/src/websockets.cpp +++ b/src/websockets.cpp @@ -705,9 +705,6 @@ void AppDataServer::processSendTx(QJsonObject sendTx, MainWindow* mainwindow, st auto allBalances = mainwindow->getRPC()->getModel()->getAllBalances(); QList> bals; for (auto i : allBalances.keys()) { - // Filter out sprout addresses - if (Settings::getInstance()->isSproutAddress(i)) - continue; // Filter out balances that don't have the requisite amount if (allBalances.value(i) < amt) continue; @@ -796,9 +793,6 @@ void AppDataServer::processSendManyTx(QJsonObject sendmanyTx, MainWindow* mainwi auto allBalances = mainwindow->getRPC()->getModel()->getAllBalances(); QList> bals; for (auto i : allBalances.keys()) { - // Filter out sprout addresses - if (Settings::getInstance()->isSproutAddress(i)) - continue; // Filter out balances that don't have the requisite amount if (allBalances.value(i) < amt) continue;