Browse Source

Integrate Tor explorer

custom_themes
Duke 1 year ago
parent
commit
dca66b70ed
  1. 95
      src/mainwindow.cpp
  2. 1
      src/mainwindow.h
  3. 2
      src/sd.h
  4. 27
      src/settings.cpp
  5. 6
      src/settings.h
  6. 12
      src/settings.ui

95
src/mainwindow.cpp

@ -304,21 +304,29 @@ void MainWindow::setupStatusBar() {
menu.addAction("Copy block explorer link", [=]() {
QString url;
auto explorer = Settings::getInstance()->getExplorer();
if (Settings::getInstance()->isTestnet()) {
url = explorer.testnetTxExplorerUrl + txid;
} else {
url = explorer.txExplorerUrl + txid;
}
url = explorer.txExplorerUrl + txid;
DEBUG("explorer url=" << url);
QGuiApplication::clipboard()->setText(url);
});
menu.addAction("Copy Tor block explorer link", [=]() {
QString url;
auto explorer = Settings::getInstance()->getExplorer();
url = explorer.onionTxExplorerUrl + txid;
DEBUG("explorer url=" << url);
QGuiApplication::clipboard()->setText(url);
});
menu.addAction("View tx on block explorer", [=]() {
QString url;
auto explorer = Settings::getInstance()->getExplorer();
if (Settings::getInstance()->isTestnet()) {
url = explorer.testnetTxExplorerUrl + txid;
} else {
url = explorer.txExplorerUrl + txid;
}
url = explorer.txExplorerUrl + txid;
DEBUG("explorer url=" << url);
QDesktopServices::openUrl(QUrl(url));
});
menu.addAction("View tx via Tor block explorer", [=]() {
QString url;
auto explorer = Settings::getInstance()->getExplorer();
url = explorer.onionTxExplorerUrl + txid;
DEBUG("explorer url=" << url);
QDesktopServices::openUrl(QUrl(url));
});
}
@ -504,8 +512,8 @@ void MainWindow::setupSettingsModal() {
auto explorer = Settings::getInstance()->getExplorer();
settings.txExplorerUrl->setText(explorer.txExplorerUrl);
settings.addressExplorerUrl->setText(explorer.addressExplorerUrl);
settings.testnetTxExplorerUrl->setText(explorer.testnetTxExplorerUrl);
settings.testnetAddressExplorerUrl->setText(explorer.testnetAddressExplorerUrl);
settings.onionTxExplorerUrl->setText(explorer.onionTxExplorerUrl);
settings.onionAddressExplorerUrl->setText(explorer.onionAddressExplorerUrl);
// format systems language
QString defaultLocale = QLocale::system().name(); // e.g. "de_DE"
@ -656,8 +664,8 @@ void MainWindow::setupSettingsModal() {
Settings::getInstance()->saveExplorer(
settings.txExplorerUrl->text(),
settings.addressExplorerUrl->text(),
settings.testnetTxExplorerUrl->text(),
settings.testnetAddressExplorerUrl->text());
settings.onionTxExplorerUrl->text(),
settings.onionAddressExplorerUrl->text());
// Check to see if rescan or reindex have been enabled
bool showRestartInfo = false;
@ -1393,22 +1401,31 @@ void MainWindow::setupBalancesTab() {
menu.addAction(tr("View on block explorer"), [=] () {
QString url;
auto explorer = Settings::getInstance()->getExplorer();
if (Settings::getInstance()->isTestnet()) {
url = explorer.testnetAddressExplorerUrl + addr;
} else {
url = explorer.addressExplorerUrl + addr;
}
url = explorer.addressExplorerUrl + addr;
DEBUG("explorer url=" << url);
QDesktopServices::openUrl(QUrl(url));
});
menu.addAction(tr("View on Tor block explorer"), [=] () {
QString url;
auto explorer = Settings::getInstance()->getExplorer();
url = explorer.onionAddressExplorerUrl + addr;
DEBUG("explorer url=" << url);
QDesktopServices::openUrl(QUrl(url));
});
menu.addAction("Copy explorer link", [=]() {
QString url;
auto explorer = Settings::getInstance()->getExplorer();
if (Settings::getInstance()->isTestnet()) {
url = explorer.testnetAddressExplorerUrl + addr;
} else {
url = explorer.addressExplorerUrl + addr;
}
url = explorer.addressExplorerUrl + addr;
DEBUG("explorer url=" << url);
QGuiApplication::clipboard()->setText(url);
});
menu.addAction("Copy Tor explorer link", [=]() {
QString url;
auto explorer = Settings::getInstance()->getExplorer();
url = explorer.onionAddressExplorerUrl + addr;
QGuiApplication::clipboard()->setText(url);
});
@ -1918,22 +1935,32 @@ void MainWindow::setupTransactionsTab() {
menu.addAction(tr("View on block explorer"), [=] () {
QString url;
auto explorer = Settings::getInstance()->getExplorer();
if (Settings::getInstance()->isTestnet()) {
url = explorer.testnetTxExplorerUrl + txid;
} else {
url = explorer.txExplorerUrl + txid;
}
url = explorer.txExplorerUrl + txid;
DEBUG("explorer url=" << url);
QDesktopServices::openUrl(QUrl(url));
});
menu.addAction(tr("View on Tor block explorer"), [=] () {
QString url;
auto explorer = Settings::getInstance()->getExplorer();
url = explorer.onionTxExplorerUrl + txid;
DEBUG("explorer url=" << url);
QDesktopServices::openUrl(QUrl(url));
});
menu.addAction(tr("Copy block explorer link"), [=] () {
QString url;
auto explorer = Settings::getInstance()->getExplorer();
if (Settings::getInstance()->isTestnet()) {
url = explorer.testnetTxExplorerUrl + txid;
} else {
url = explorer.txExplorerUrl + txid;
}
url = explorer.txExplorerUrl + txid;
DEBUG("explorer url=" << url);
QGuiApplication::clipboard()->setText(url);
});
menu.addAction(tr("Copy Tor block explorer link"), [=] () {
QString url;
auto explorer = Settings::getInstance()->getExplorer();
url = explorer.onionTxExplorerUrl + txid;
DEBUG("explorer url=" << url);
QGuiApplication::clipboard()->setText(url);
});

1
src/mainwindow.h

@ -129,7 +129,6 @@ private:
void telegram();
void reportbug();
void addressBook();
void postToZBoard();
void importPrivKey();
void exportAllKeys();
void exportKeys(QString addr = "");

2
src/sd.h

@ -1,5 +1,5 @@
// Copyright 2019-2023 The Hush Developers
// Released under the GPLv3
#define DEBUG(x) (qDebug() << __func__ << ": " << x)
#define DEBUG(x) (qDebug() << QString(__func__) << ": " << x)

27
src/settings.cpp

@ -2,6 +2,7 @@
// Released under the GPLv3
#include "mainwindow.h"
#include "settings.h"
#include "sd.h"
extern bool isdragonx;
@ -45,31 +46,35 @@ Explorer Settings::getExplorer() {
explorer = "https://explorer.dragonx.is";
}
auto txExplorerUrl = s.value("explorer/txExplorerUrl", explorer + "/tx/").toString();
auto addressExplorerUrl = s.value("explorer/addressExplorerUrl", explorer + "/address/").toString();
auto testnetTxExplorerUrl = s.value("explorer/testnetTxExplorerUrl").toString();
auto testnetAddressExplorerUrl = s.value("explorer/testnetAddressExplorerUrl").toString();
QString onionExplorer = "http://jlqhwhak65kokg3pdjp3ufy6almf5spnhsfnugtjsc4z7wtapgozxyad.onion";
auto txExplorerUrl = s.value("explorer/txExplorerUrl", explorer + "/tx/").toString();
auto addressExplorerUrl = s.value("explorer/addressExplorerUrl", explorer + "/address/").toString();
auto onionTxExplorerUrl = s.value("explorer/onionTxExplorerUrl", onionExplorer + "/tx/").toString();
auto onionAddressExplorerUrl = s.value("explorer/onionAddressExplorerUrl", onionExplorer + "/address/").toString();
// Some users have the old malicious explorer URL saved in their config file, help them out
if (txExplorerUrl == "https://explorer.myhush.org/tx/") {
txExplorerUrl = explorer + "/tx/";
saveExplorer(txExplorerUrl, addressExplorerUrl, testnetTxExplorerUrl, testnetAddressExplorerUrl);
saveExplorer(txExplorerUrl, addressExplorerUrl, onionTxExplorerUrl, onionAddressExplorerUrl);
}
if (addressExplorerUrl == "https://explorer.myhush.org/address/") {
addressExplorerUrl = explorer + "/address/";
saveExplorer(txExplorerUrl, addressExplorerUrl, testnetTxExplorerUrl, testnetAddressExplorerUrl);
saveExplorer(txExplorerUrl, addressExplorerUrl, onionTxExplorerUrl, onionAddressExplorerUrl);
}
return Explorer{txExplorerUrl, addressExplorerUrl, testnetTxExplorerUrl, testnetAddressExplorerUrl};
//DEBUG("explorer values: " << txExplorerUrl << " " << addressExplorerUrl << " " << onionTxExplorerUrl << " " << onionAddressExplorerUrl );
DEBUG("onionTxExplorerUrl=" % onionTxExplorerUrl);
DEBUG("onionAddressExplorerUrl=" % onionAddressExplorerUrl);
return Explorer{txExplorerUrl, addressExplorerUrl, onionTxExplorerUrl, onionAddressExplorerUrl};
}
void Settings::saveExplorer(const QString& txExplorerUrl, const QString& addressExplorerUrl, const QString& testnetTxExplorerUrl, const QString& testnetAddressExplorerUrl) {
void Settings::saveExplorer(const QString& txExplorerUrl, const QString& addressExplorerUrl, const QString& onionTxExplorerUrl, const QString& onionAddressExplorerUrl) {
QSettings s;
s.setValue("explorer/txExplorerUrl", txExplorerUrl);
s.setValue("explorer/addressExplorerUrl", addressExplorerUrl);
s.setValue("explorer/testnetTxExplorerUrl", testnetTxExplorerUrl);
s.setValue("explorer/testnetAddressExplorerUrl", testnetAddressExplorerUrl);
s.setValue("explorer/onionTxExplorerUrl", onionTxExplorerUrl);
s.setValue("explorer/onionAddressExplorerUrl", onionAddressExplorerUrl);
//DEBUG("saving explorer values: " << txExplorerUrl << " " << addressExplorerUrl << " " << onionTxExplorerUrl << " " << onionAddressExplorerUrl );
}
Config Settings::getSettings() {

6
src/settings.h

@ -15,8 +15,8 @@ struct Config {
struct Explorer {
QString txExplorerUrl;
QString addressExplorerUrl;
QString testnetTxExplorerUrl;
QString testnetAddressExplorerUrl;
QString onionTxExplorerUrl;
QString onionAddressExplorerUrl;
};
struct ToFields;
@ -38,7 +38,7 @@ public:
static Settings* getInstance();
Explorer getExplorer();
void saveExplorer(const QString& txExplorerUrl, const QString& addressExplorerUrl, const QString& testnetTxExplorerUrl, const QString& testnetAddressExplorerUrl);
void saveExplorer(const QString& txExplorerUrl, const QString& addressExplorerUrl, const QString& onionTxExplorerUrl, const QString& onionAddressExplorerUrl);
Config getSettings();
void saveSettings(const QString& host, const QString& port, const QString& username, const QString& password);

12
src/settings.ui

@ -704,10 +704,10 @@
</rect>
</property>
<property name="text">
<string>Testnet Tx Explorer URL</string>
<string>Onion Tx Explorer URL</string>
</property>
</widget>
<widget class="QLineEdit" name="testnetTxExplorerUrl">
<widget class="QLineEdit" name="onionTxExplorerUrl">
<property name="geometry">
<rect>
<x>9</x>
@ -717,7 +717,7 @@
</rect>
</property>
<property name="text">
<string notr="true">https://explorer.testnet.z.cash/tx/</string>
<string notr="true">http://jlqhwhak65kokg3pdjp3ufy6almf5spnhsfnugtjsc4z7wtapgozxyad.onion/tx/</string>
</property>
</widget>
<widget class="QLabel" name="label_17">
@ -730,10 +730,10 @@
</rect>
</property>
<property name="text">
<string>Testnet Address Explorer URL</string>
<string>Onion Address Explorer URL</string>
</property>
</widget>
<widget class="QLineEdit" name="testnetAddressExplorerUrl">
<widget class="QLineEdit" name="onionAddressExplorerUrl">
<property name="geometry">
<rect>
<x>9</x>
@ -743,7 +743,7 @@
</rect>
</property>
<property name="text">
<string notr="true">https://explorer.testnet.hush.is/address/</string>
<string notr="true">http://jlqhwhak65kokg3pdjp3ufy6almf5spnhsfnugtjsc4z7wtapgozxyad.onion/tx/</string>
</property>
</widget>
</widget>

Loading…
Cancel
Save