Revert "Merge branch 'dev'"

This reverts commit 4a7dd7f959, reversing
changes made to a89a0cc1c6.
This commit is contained in:
onryo
2024-01-06 16:27:48 +01:00
parent 4a7dd7f959
commit 3c2414028b
127 changed files with 1747 additions and 770 deletions

View File

@@ -1,4 +1,4 @@
// Copyright 2019-2024 The Hush developers
// Copyright 2019-2023 The Hush developers
// Released under the GPLv3
#include "mainwindow.h"
#include "addressbook.h"
@@ -25,6 +25,7 @@
#include "ui_startupencryption.h"
#include "ui_removeencryption.h"
#include "ui_seedrestore.h"
#include "websockets.h"
#include "sodium.h"
#include "sodium/crypto_generichash_blake2b.h"
#include <QRegularExpression>
@@ -37,7 +38,6 @@
#include <QCoreApplication>
#include <QGuiApplication>
#include <QKeyEvent>
#include "sdl.h"
using json = nlohmann::json;
@@ -159,11 +159,11 @@ MainWindow::MainWindow(QWidget *parent) :
// Rescan
QObject::connect(ui->actionRescan, &QAction::triggered, [=]() {
DEBUG("rescan action triggered");
Ui_Restore restoreSeed;
QDialog dialog(this);
restoreSeed.setupUi(&dialog);
Settings::saveRestore(&dialog);
Ui_Restore restoreSeed;
QDialog dialog(this);
restoreSeed.setupUi(&dialog);
Settings::saveRestore(&dialog);
rpc->fetchSeed([=](json reply) {
if (isJsonError(reply)) {
@@ -209,74 +209,35 @@ MainWindow::MainWindow(QWidget *parent) :
config->server = Settings::getInstance()->getSettings().server;
// 3. Attempt to restore wallet with the seed phrase
{
QString reply = "";
try {
char* resp = litelib_initialize_new_from_phrase(config->dangerous, config->server.toStdString().c_str(),
seed.toStdString().c_str(), birthday, number);
reply = litelib_process_response(resp);
} catch (const std::exception& e) {
qDebug() << __func__ << ": caught an exception, ignoring: " << e.what();
}
char* resp = litelib_initialize_new_from_phrase(config->dangerous, config->server.toStdString().c_str(),
seed.toStdString().c_str(), birthday, number);
QString reply = litelib_process_response(resp);
if (reply.toUpper().trimmed() != "OK") {
qDebug() << "Lite server " << config->server << " is down, getting a random one";
config->server = Settings::getRandomServer();
qDebug() << __func__ << ": new server is " << config->server;
// retry with the new server
char* resp = litelib_initialize_new_from_phrase(config->dangerous,config->server.toStdString().c_str(),
seed.toStdString().c_str(), birthday, number);
reply = litelib_process_response(resp);
}
if (reply.toUpper().trimmed() != "OK") {
QMessageBox::warning(this, tr("Failed to restore wallet"),
tr("Couldn't restore the wallet") + "\n" + "server=" + config->server + "\n" + reply,
QMessageBox::warning(this, tr("Failed to restore wallet"),
tr("Couldn't restore the wallet") + "\n" + reply,
QMessageBox::Ok);
return false;
}
}
}
// 4. Finally attempt to save the wallet
{
QString reply = "";
try {
char* resp = litelib_execute("save", "");
QString reply = litelib_process_response(resp);
} catch (const std::exception& e) {
qDebug() << __func__ << ": caught an exception, ignoring: " << e.what();
}
if (reply.isEmpty()) {
qDebug() << "Lite server " << config->server << " is down, getting a random one";
config->server = Settings::getRandomServer();
qDebug() << __func__ << ": new server is " << config->server;
// make a new connection to the new server
char* resp = litelib_initialize_new_from_phrase(config->dangerous,config->server.toStdString().c_str(),
seed.toStdString().c_str(), birthday, number);
reply = litelib_process_response(resp);
// retry with the new server
try {
resp = litelib_execute("save", "");
reply = litelib_process_response(resp);
} catch (const std::exception& e) {
qDebug() << __func__ << ": caught an exception with new server, something is fucky: " << e.what();
}
}
char* resp = litelib_execute("save", "");
QString reply = litelib_process_response(resp);
QByteArray ba_reply = reply.toUtf8();
QJsonDocument jd_reply = QJsonDocument::fromJson(ba_reply);
QJsonObject parsed = jd_reply.object();
if (parsed.isEmpty() || parsed["result"].isNull()) {
QMessageBox::warning(this, tr("Failed to save wallet"),
tr("Couldn't save the wallet") + "\n" + "server=" + config->server + "\n" + reply,
QMessageBox::warning(this, tr("Failed to save wallet"),
tr("Couldn't save the wallet") + "\n" + reply,
QMessageBox::Ok);
} else {
qDebug() << __func__ << ": saved wallet correctly";
}
}
dialog.close();
// To rescan, we clear the wallet state, and then reload the connection
@@ -289,14 +250,15 @@ MainWindow::MainWindow(QWidget *parent) :
// Then reload the connection. The ConnectionLoader deletes itself.
auto cl = new ConnectionLoader(this, rpc);
cl->loadConnection();
});
});
});
}
});
dialog.exec();
}); // actionReason
});
// Import Privkey
QObject::connect(ui->actionImport_Privatkey, &QAction::triggered, this, &MainWindow::importPrivKey);
@@ -332,6 +294,16 @@ MainWindow::MainWindow(QWidget *parent) :
restoreSavedStates();
if (AppDataServer::getInstance()->isAppConnected()) {
qDebug() << __func__ << ": app is connected to wormhole";
auto ads = AppDataServer::getInstance();
QString wormholecode = "";
if (ads->getAllowInternetConnection())
wormholecode = ads->getWormholeCode(ads->getSecretHex());
createWebsocket(wormholecode);
}
}
bool MainWindow::fileExists(QString path)
@@ -340,6 +312,36 @@ bool MainWindow::fileExists(QString path)
return (check_file.exists() && check_file.isFile());
}
void MainWindow::createWebsocket(QString wormholecode) {
qDebug() << "Listening for app connections on port 8777";
// Create the websocket server, for listening to direct connections
wsserver = new WSServer(8777, false, this);
if (!wormholecode.isEmpty()) {
// Connect to the wormhole service
wormhole = new WormholeClient(this, wormholecode);
}
}
void MainWindow::stopWebsocket() {
delete wsserver;
wsserver = nullptr;
delete wormhole;
wormhole = nullptr;
qDebug() << "Websockets for app connections shut down";
}
bool MainWindow::isWebsocketListening() {
return wsserver != nullptr;
}
void MainWindow::replaceWormholeClient(WormholeClient* newClient) {
delete wormhole;
wormhole = newClient;
}
void MainWindow::restoreSavedStates() {
QSettings s;
restoreGeometry(s.value("geometry").toByteArray());
@@ -931,7 +933,7 @@ void MainWindow::doImport(QList<QString>* keys) {
keys->pop_front();
//bool rescan = keys->isEmpty();
if (key.startsWith("secret")) {
if (key.startsWith("SK") || key.startsWith("secret")) {
rpc->importZPrivKey(key, [=] (auto) { this->doImport(keys); });
} else if (key.startsWith("U") || key.startsWith("5") || key.startsWith("L") || key.startsWith("K")) {
// 5 = uncompressed, len=51
@@ -1095,10 +1097,10 @@ void MainWindow::payhushURI(QString uri, QString myAddr) {
// Save the wallet
this->getRPC()->saveWallet([=] (auto) {
// Then reload the connection. The ConnectionLoader deletes itself.
auto cl = new ConnectionLoader(this, rpc);
auto cl = new ConnectionLoader(this, rpc);
cl->loadProgress();
});
});
});
});
}else if ((pui.rescan->isChecked() == true) && (pui.privKeyTxt->toPlainText().startsWith("secret"))){
@@ -2722,6 +2724,8 @@ MainWindow::~MainWindow()
delete loadingMovie;
delete logger;
delete wsserver;
delete wormhole;
}
void MainWindow::on_givemeZaddr_clicked()
{