Browse Source

more error checking, logging and fix some compiler warnings

language
Duke Leto 2 years ago
parent
commit
cbc77e9d58
  1. 1
      src/addressbook.cpp
  2. 2
      src/firsttimewizard.cpp
  3. 56
      src/mainwindow.cpp
  4. 7
      src/settings.cpp
  5. 1
      src/settings.h
  6. 6
      src/websockets.cpp

1
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) { 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); target->setText(label % "/" % addr % myAddr);
}; };

2
src/firsttimewizard.cpp

@ -133,7 +133,7 @@ NewOrRestorePage::NewOrRestorePage(FirstTimeWizard *parent) : QWizardPage(parent
form.setupUi(pageWidget); form.setupUi(pageWidget);
QGraphicsScene* scene = new QGraphicsScene(); QGraphicsScene* scene = new QGraphicsScene();
QGraphicsView* view = new QGraphicsView(scene); //QGraphicsView* view = new QGraphicsView(scene);
form.Logo->setScene(scene); form.Logo->setScene(scene);
QPixmap pixmap(":/icons/res/dark-01.png"); QPixmap pixmap(":/icons/res/dark-01.png");
scene->addPixmap(pixmap); scene->addPixmap(pixmap);

56
src/mainwindow.cpp

@ -76,12 +76,12 @@ MainWindow::MainWindow(QWidget *parent) :
} }
this->slot_change_theme(theme_name); this->slot_change_theme(theme_name);
ui->setupUi(this); ui->setupUi(this);
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
if (!dir.exists()){ if (!dir.exists()){
qDebug() << __func__ << ": creating dir=" << dir.absolutePath();
QDir().mkpath(dir.absolutePath()); QDir().mkpath(dir.absolutePath());
}else{} }else{}
@ -175,7 +175,6 @@ MainWindow::MainWindow(QWidget *parent) :
restoreSeed.setupUi(&dialog); restoreSeed.setupUi(&dialog);
Settings::saveRestore(&dialog); Settings::saveRestore(&dialog);
rpc->fetchSeed([=](json reply) { rpc->fetchSeed([=](json reply) {
if (isJsonError(reply)) { if (isJsonError(reply)) {
return; return;
@ -246,26 +245,29 @@ MainWindow::MainWindow(QWidget *parent) :
tr("Couldn't save the wallet") + "\n" + reply, tr("Couldn't save the wallet") + "\n" + reply,
QMessageBox::Ok); QMessageBox::Ok);
} else {} } else {
qDebug() << __func__ << ": saved wallet correctly";
}
dialog.close(); dialog.close();
// To rescan, we clear the wallet state, and then reload the connection // To rescan, we clear the wallet state, and then reload the connection
// This will start a sync, and show the scanning status. // This will start a sync, and show the scanning status.
this->getRPC()->clearWallet([=] (auto) { this->getRPC()->clearWallet([=] (auto) {
qDebug() << "Clearing wallet...";
// Save the wallet // Save the wallet
this->getRPC()->saveWallet([=] (auto) { this->getRPC()->saveWallet([=] (auto) {
qDebug() << "Saving wallet...";
// Then reload the connection. The ConnectionLoader deletes itself. // Then reload the connection. The ConnectionLoader deletes itself.
auto cl = new ConnectionLoader(this, rpc); auto cl = new ConnectionLoader(this, rpc);
cl->loadConnection(); cl->loadConnection();
}); });
}); });
} }
}); });
dialog.exec(); dialog.exec();
}); });
// Import Privkey // Import Privkey
@ -432,6 +434,7 @@ void MainWindow::closeEvent(QCloseEvent* event) {
void MainWindow::closeEventpw(QCloseEvent* event) { void MainWindow::closeEventpw(QCloseEvent* event) {
// Let the RPC know to shut down any running service. // Let the RPC know to shut down any running service.
qDebug() << __func__ << ": event=" << event;
rpc->shutdownhushd(); rpc->shutdownhushd();
} }
@ -489,12 +492,16 @@ void MainWindow::encryptWallet() {
unsigned char key[KEY_LEN]; unsigned char key[KEY_LEN];
if (crypto_pwhash if (crypto_pwhash(key, sizeof key, PASSWORD, strlen(PASSWORD), hash,
(key, sizeof key, PASSWORD, strlen(PASSWORD), hash,
crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE, crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE,
crypto_pwhash_ALG_DEFAULT) != 0) { crypto_pwhash_ALG_DEFAULT) != 0) {
/* out of memory */ /* 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<const char*>(key), KEY_LEN).toHex(); QString passphraseHash1 = QByteArray(reinterpret_cast<const char*>(key), KEY_LEN).toHex();
DataStore::getChatDataStore()->setPassword(passphraseHash1); 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 // will prompt for one. If the myAddr is empty, then the default from address is used to send
// the transaction. // the transaction.
void MainWindow::payhushURI(QString uri, QString myAddr) { 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 the Payments UI is not ready (i.e, all balances have not loaded), defer the payment URI
if (!isPaymentsReady()) { if (!isPaymentsReady()) {
qDebug() << "Payment UI not ready, waiting for UI to pay URI"; 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]+")); int lastPost = memo.trimmed().lastIndexOf(QRegExp("[\r\n]+"));
QString lastWord = memo.right(memo.length() - lastPost - 1); QString lastWord = memo.right(memo.length() - lastPost - 1);
if (Settings::getInstance()->isSaplingAddress(lastWord) || if (Settings::getInstance()->isSaplingAddress(lastWord)) {
Settings::getInstance()->isSproutAddress(lastWord)) {
menu.addAction(tr("Reply to ") + lastWord.left(25) + "...", [=]() { menu.addAction(tr("Reply to ") + lastWord.left(25) + "...", [=]() {
// First, cancel any pending stuff in the send tab by pretending to click // First, cancel any pending stuff in the send tab by pretending to click
// the cancel button // 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 // lambda, which can be connected to the appropriate signal
std::function<void(bool)> MainWindow::addZAddrsToComboList(bool sapling) { std::function<void(bool)> MainWindow::addZAddrsToComboList(bool sapling) {
return [=] (bool checked) { return [=] (bool checked) {
@ -2770,9 +2777,7 @@ void MainWindow::updateLabels() {
updateLabelsAutoComplete(); 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); 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); 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); QMessageBox::information(this, "Your new HushChat address was copied to your clipboard!",hushchataddr);
ui->listReceiveAddresses->insertItem(0, hushchataddr); ui->listReceiveAddresses->insertItem(0, hushchataddr);
ui->listReceiveAddresses->setCurrentIndex(0); ui->listReceiveAddresses->setCurrentIndex(0);
qDebug() << __func__ << ": hushchat zaddr=" << hushchataddr << " created";
}); });
} }

7
src/settings.cpp

@ -95,13 +95,6 @@ bool Settings::isSaplingAddress(QString addr) {
(!isTestnet() && addr.startsWith("zs1")); (!isTestnet() && addr.startsWith("zs1"));
} }
bool Settings::isSproutAddress(QString addr) {
if (!isValidAddress(addr))
return false;
return isZAddress(addr) && !isSaplingAddress(addr);
}
bool Settings::isZAddress(QString addr) { bool Settings::isZAddress(QString addr) {
if (!isValidAddress(addr)) if (!isValidAddress(addr))
return false; return false;

1
src/settings.h

@ -42,7 +42,6 @@ public:
void setTestnet(bool isTestnet); void setTestnet(bool isTestnet);
bool isSaplingAddress(QString addr); bool isSaplingAddress(QString addr);
bool isSproutAddress(QString addr);
bool isValidSaplingPrivateKey(QString pk); bool isValidSaplingPrivateKey(QString pk);

6
src/websockets.cpp

@ -705,9 +705,6 @@ void AppDataServer::processSendTx(QJsonObject sendTx, MainWindow* mainwindow, st
auto allBalances = mainwindow->getRPC()->getModel()->getAllBalances(); auto allBalances = mainwindow->getRPC()->getModel()->getAllBalances();
QList<QPair<QString, CAmount>> bals; QList<QPair<QString, CAmount>> bals;
for (auto i : allBalances.keys()) { 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 // Filter out balances that don't have the requisite amount
if (allBalances.value(i) < amt) if (allBalances.value(i) < amt)
continue; continue;
@ -796,9 +793,6 @@ void AppDataServer::processSendManyTx(QJsonObject sendmanyTx, MainWindow* mainwi
auto allBalances = mainwindow->getRPC()->getModel()->getAllBalances(); auto allBalances = mainwindow->getRPC()->getModel()->getAllBalances();
QList<QPair<QString, CAmount>> bals; QList<QPair<QString, CAmount>> bals;
for (auto i : allBalances.keys()) { 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 // Filter out balances that don't have the requisite amount
if (allBalances.value(i) < amt) if (allBalances.value(i) < amt)
continue; continue;

Loading…
Cancel
Save