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) {
qDebug() << __func__ << ": label=" << label << " cid=" << cid << " avatar=" << avatar;
target->setText(label % "/" % addr % myAddr);
};

2
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);

56
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<const char*>(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<void(bool)> 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";
});
});
}

7
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;

1
src/settings.h

@ -42,7 +42,6 @@ public:
void setTestnet(bool isTestnet);
bool isSaplingAddress(QString addr);
bool isSproutAddress(QString addr);
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();
QList<QPair<QString, CAmount>> 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<QPair<QString, CAmount>> 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;

Loading…
Cancel
Save