Browse Source

WIP cleanups and stuff

old_duke
Duke Leto 4 years ago
parent
commit
51559b28ba
  1. 20
      src/connection.cpp
  2. 14
      src/connection.h
  3. 4
      src/main.cpp
  4. 40
      src/mainwindow.cpp
  5. 2
      src/mainwindow.h
  6. 4
      src/requestdialog.cpp
  7. 66
      src/rpc.cpp
  8. 6
      src/rpc.h
  9. 6
      src/settings.cpp
  10. 6
      src/settings.h

20
src/connection.cpp

@ -59,7 +59,7 @@ void ConnectionLoader::doAutoConnect(bool tryEzcashdStart) {
}
// Priority 2: Try to connect to detect HUSH3.conf and connect to it.
auto config = autoDetectZcashConf();
auto config = autoDetectHushConf();
main->logger->write(QObject::tr("Attempting autoconnect"));
if (config.get() != nullptr) {
@ -119,7 +119,7 @@ void ConnectionLoader::doAutoConnect(bool tryEzcashdStart) {
if (Settings::getInstance()->useEmbedded()) {
// HUSH3.conf was not found, so create one
qDebug() << "Creating HUSH3.conf";
createZcashConf();
createHushConf();
} else {
// Fall back to manual connect
doManualConnect();
@ -147,14 +147,14 @@ QString randomPassword() {
/**
* This will create a new HUSH3.conf and download params if they cannot be found
*/
void ConnectionLoader::createZcashConf() {
main->logger->write("createZcashConf");
void ConnectionLoader::createHushConf() {
main->logger->write("createHushConf");
auto confLocation = zcashConfWritableLocation();
QFileInfo fi(confLocation);
QDialog d(main);
Ui_createZcashConf ui;
Ui_createHushConf ui;
ui.setupUi(&d);
QPixmap logo(":/img/res/zcashdlogo.gif");
@ -555,7 +555,7 @@ void ConnectionLoader::showError(QString explanation) {
d->close();
}
QString ConnectionLoader::locateZcashConfFile() {
QString ConnectionLoader::locateHushConfFile() {
#ifdef Q_OS_LINUX
auto confLocation = QStandardPaths::locate(QStandardPaths::HomeLocation, ".komodo/HUSH3/HUSH3.conf");
#elif defined(Q_OS_DARWIN)
@ -651,8 +651,8 @@ bool ConnectionLoader::verifyParams() {
/**
* Try to automatically detect a HUSH3/HUSH3.conf file in the correct location and load parameters
*/
std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectZcashConf() {
auto confLocation = locateZcashConfFile();
std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectHushConf() {
auto confLocation = locateHushConfFile();
if (confLocation.isNull()) {
// No Zcash file, just return with nothing
@ -670,11 +670,11 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectZcashConf() {
auto zcashconf = new ConnectionConfig();
zcashconf->host = "127.0.0.1";
zcashconf->connType = ConnectionType::DetectedConfExternalZcashD;
zcashconf->usingZcashConf = true;
zcashconf->usingHushConf = true;
zcashconf->zcashDir = QFileInfo(confLocation).absoluteDir().absolutePath();
zcashconf->zcashDaemon = false;
Settings::getInstance()->setUsingZcashConf(confLocation);
Settings::getInstance()->setUsingHushConf(confLocation);
while (!in.atEnd()) {
QString line = in.readLine();

14
src/connection.h

@ -1,3 +1,5 @@
// Copyright 2019-2020 The Hush developers
// Released under the GPLv3
#ifndef CONNECTION_H
#define CONNECTION_H
@ -18,7 +20,7 @@ struct ConnectionConfig {
QString port;
QString rpcuser;
QString rpcpassword;
bool usingZcashConf;
bool usingHushConf;
bool zcashDaemon;
QString zcashDir;
QString proxy;
@ -40,7 +42,7 @@ public:
void loadConnection();
private:
std::shared_ptr<ConnectionConfig> autoDetectZcashConf();
std::shared_ptr<ConnectionConfig> autoDetectHushConf();
std::shared_ptr<ConnectionConfig> loadFromSettings();
Connection* makeConnection(std::shared_ptr<ConnectionConfig> config);
@ -48,8 +50,8 @@ private:
void doAutoConnect(bool tryEhushdStart = true);
void doManualConnect();
void createZcashConf();
QString locateZcashConfFile();
void createHushConf();
QString locateHushConfFile();
QString zcashConfWritableLocation();
QString zcashParamsDir();
@ -133,8 +135,7 @@ public:
QJsonDocument jd_rpc_call(payload.toObject());
QByteArray ba_rpc_call = jd_rpc_call.toJson();
QNetworkReply *reply = restclient->post(*request, ba_rpc_call);
QNetworkReply *reply = restclient->post(*request, ba_rpc_call);
QObject::connect(reply, &QNetworkReply::finished, [=] {
reply->deleteLater();
@ -146,7 +147,6 @@ public:
auto all = reply->readAll();
auto parsed = QJsonDocument::fromJson(all);
if (reply->error() != QNetworkReply::NoError) {
qDebug() << "Error JSON response: " << parsed.toJson();
qDebug() << reply->errorString();

4
src/main.cpp

@ -224,7 +224,7 @@ public:
// If there was a payment URI on the command line, pay it
if (parser.positionalArguments().length() > 0) {
w->payZcashURI(parser.positionalArguments()[0]);
w->payHushURI(parser.positionalArguments()[0]);
}
// Listen for any secondary instances telling us about a Hush payment URI
@ -232,7 +232,7 @@ public:
QString uri(msg);
// We need to execute this async, otherwise the app seems to crash for some reason.
QTimer::singleShot(1, [=]() { w->payZcashURI(uri); });
QTimer::singleShot(1, [=]() { w->payHushURI(uri); });
});
// For MacOS, we have an event filter

40
src/mainwindow.cpp

@ -73,7 +73,7 @@ MainWindow::MainWindow(QWidget *parent) :
// Pay Hush URI
QObject::connect(ui->actionPay_URI, &QAction::triggered, [=] () {
payZcashURI();
payHushURI();
});
// Import Private Key
@ -341,7 +341,7 @@ void MainWindow::setupSettingsModal() {
isUsingTor = !rpc->getConnection()->config->proxy.isEmpty();
}
settings.chkTor->setChecked(isUsingTor);
if (rpc->getEZcashD() == nullptr) {
if (rpc->getHushd() == nullptr) {
settings.chkTor->setEnabled(false);
settings.lblTor->setEnabled(false);
QString tooltip = tr("Tor configuration is available only when running an embedded hushd.");
@ -365,7 +365,7 @@ void MainWindow::setupSettingsModal() {
isUsingConsolidation = !rpc->getConnection()->config->consolidation.isEmpty() == true;
}
settings.chkConso->setChecked(isUsingConsolidation);
if (rpc->getEZcashD() == nullptr) {
if (rpc->getHushd() == nullptr) {
settings.chkConso->setEnabled(false);
}
@ -376,7 +376,7 @@ void MainWindow::setupSettingsModal() {
isUsingDeletetx = !rpc->getConnection()->config->deletetx.isEmpty() == true;
}
settings.chkDeletetx->setChecked(isUsingDeletetx);
if (rpc->getEZcashD() == nullptr) {
if (rpc->getHushd() == nullptr) {
settings.chkDeletetx->setEnabled(false);
}
@ -387,7 +387,7 @@ void MainWindow::setupSettingsModal() {
isUsingZindex = !rpc->getConnection()->config->zindex.isEmpty() == true;
}
settings.chkzindex->setChecked(isUsingZindex);
if (rpc->getEZcashD() == nullptr) {
if (rpc->getHushd() == nullptr) {
settings.chkzindex->setEnabled(false);
}
@ -457,7 +457,7 @@ void MainWindow::setupSettingsModal() {
if (!isUsingTor && settings.chkTor->isChecked()) {
// If "use tor" was previously unchecked and now checked
Settings::addToZcashConf(zcashConfLocation, "proxy=127.0.0.1:9050");
Settings::addToHushConf(zcashConfLocation, "proxy=127.0.0.1:9050");
rpc->getConnection()->config->proxy = "proxy=127.0.0.1:9050";
QMessageBox::information(this, tr("Enable Tor"),
@ -467,7 +467,7 @@ void MainWindow::setupSettingsModal() {
if (isUsingTor && !settings.chkTor->isChecked()) {
// If "use tor" was previously checked and now is unchecked
Settings::removeFromZcashConf(zcashConfLocation, "proxy");
Settings::removeFromHushConf(zcashConfLocation, "proxy");
rpc->getConnection()->config->proxy.clear();
QMessageBox::information(this, tr("Disable Tor"),
@ -498,55 +498,55 @@ void MainWindow::setupSettingsModal() {
bool showRestartInfo = false;
bool showReindexInfo = false;
if (settings.chkRescan->isChecked()) {
Settings::addToZcashConf(zcashConfLocation, "rescan=1");
Settings::addToHushConf(zcashConfLocation, "rescan=1");
showRestartInfo = true;
}
if (settings.chkReindex->isChecked()) {
Settings::addToZcashConf(zcashConfLocation, "reindex=1");
Settings::addToHushConf(zcashConfLocation, "reindex=1");
showRestartInfo = true;
}
if (!rpc->getConnection()->config->consolidation.isEmpty()==false) {
if (settings.chkConso->isChecked()) {
Settings::addToZcashConf(zcashConfLocation, "consolidation=1");
Settings::addToHushConf(zcashConfLocation, "consolidation=1");
showRestartInfo = true;
}
}
if (!rpc->getConnection()->config->consolidation.isEmpty()) {
if (settings.chkConso->isChecked() == false) {
Settings::removeFromZcashConf(zcashConfLocation, "consolidation");
Settings::removeFromHushConf(zcashConfLocation, "consolidation");
showRestartInfo = true;
}
}
if (!rpc->getConnection()->config->deletetx.isEmpty() == false) {
if (settings.chkDeletetx->isChecked()) {
Settings::addToZcashConf(zcashConfLocation, "deletetx=1");
Settings::addToHushConf(zcashConfLocation, "deletetx=1");
showRestartInfo = true;
}
}
if (!rpc->getConnection()->config->deletetx.isEmpty()) {
if (settings.chkDeletetx->isChecked() == false) {
Settings::removeFromZcashConf(zcashConfLocation, "deletetx");
Settings::removeFromHushConf(zcashConfLocation, "deletetx");
showRestartInfo = true;
}
}
if (!rpc->getConnection()->config->zindex.isEmpty() == false) {
if (settings.chkzindex->isChecked()) {
Settings::addToZcashConf(zcashConfLocation, "zindex=1");
Settings::addToZcashConf(zcashConfLocation, "reindex=1");
Settings::addToHushConf(zcashConfLocation, "zindex=1");
Settings::addToHushConf(zcashConfLocation, "reindex=1");
showReindexInfo = true;
}
}
if (!rpc->getConnection()->config->zindex.isEmpty()) {
if (settings.chkzindex->isChecked() == false) {
Settings::removeFromZcashConf(zcashConfLocation, "zindex");
Settings::addToZcashConf(zcashConfLocation, "reindex=1");
Settings::removeFromHushConf(zcashConfLocation, "zindex");
Settings::addToHushConf(zcashConfLocation, "reindex=1");
showReindexInfo = true;
}
}
@ -701,7 +701,7 @@ void MainWindow::balancesReady() {
// process it.
if (!pendingURIPayment.isEmpty()) {
qDebug() << "Paying hush URI";
payZcashURI(pendingURIPayment);
payHushURI(pendingURIPayment);
pendingURIPayment = "";
}
@ -712,7 +712,7 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event) {
if (event->type() == QEvent::FileOpen) {
QFileOpenEvent *fileEvent = static_cast<QFileOpenEvent*>(event);
if (!fileEvent->url().isEmpty())
payZcashURI(fileEvent->url().toString());
payHushURI(fileEvent->url().toString());
return true;
}
@ -724,7 +724,7 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event) {
// Pay the Hush URI by showing a confirmation window. If the URI parameter is empty, the UI
// will prompt for one. If the myAddr is empty, then the default from address is used to send
// the transaction.
void MainWindow::payZcashURI(QString uri, QString myAddr) {
void MainWindow::payHushURI(QString uri, QString myAddr) {
// If the Payments UI is not ready (i.e, all balances have not loaded), defer the payment URI
if (!uiPaymentsReady) {
qDebug() << "Payment UI not ready, waiting for UI to pay URI";

2
src/mainwindow.h

@ -52,7 +52,7 @@ public:
void stopWebsocket();
void balancesReady();
void payZcashURI(QString uri = "", QString myAddr = "");
void payHushURI(QString uri = "", QString myAddr = "");
void validateAddress();

4
src/requestdialog.cpp

@ -80,7 +80,7 @@ void RequestDialog::showPaymentConfirmation(MainWindow* main, QString paymentURI
req.lblHeader->setText(tr("You are paying a payment request. Your address will not be visible to the person requesting this payment."));
if (d.exec() == QDialog::Accepted) {
main->payZcashURI(paymentURI, req.cmbMyAddress->currentText());
main->payHushURI(paymentURI, req.cmbMyAddress->currentText());
}
}
@ -134,6 +134,6 @@ void RequestDialog::showRequestZcash(MainWindow* main) {
// If the disclosed address in the memo doesn't have a balance, it will automatically fallback to the default
// sapling address
main->payZcashURI(sendURI, req.cmbMyAddress->currentText());
main->payHushURI(sendURI, req.cmbMyAddress->currentText());
}
}

66
src/rpc.cpp

@ -50,8 +50,8 @@ RPC::RPC(MainWindow* main) {
// Set up the timer to watch for tx status
txTimer = new QTimer(main);
QObject::connect(txTimer, &QTimer::timeout, [=]() {
qDebug() << "Watching tx status at " << QDateTime::currentSecsSinceEpoch();
watchTxStatus();
qDebug() << "Not Watching tx status at " << QDateTime::currentSecsSinceEpoch();
//watchTxStatus();
});
// Start at normal updateSpeed. When an operation is pending, this will change to quickUpdateSpeed
txTimer->start(Settings::updateSpeed);
@ -83,8 +83,8 @@ void RPC::setConnection(Connection* c) {
// See if we need to remove the reindex/rescan flags from the zcash.conf file
auto zcashConfLocation = Settings::getInstance()->getZcashdConfLocation();
Settings::removeFromZcashConf(zcashConfLocation, "rescan");
Settings::removeFromZcashConf(zcashConfLocation, "reindex");
Settings::removeFromHushConf(zcashConfLocation, "rescan");
Settings::removeFromHushConf(zcashConfLocation, "reindex");
// Refresh the UI
refreshPrice();
@ -453,7 +453,7 @@ void RPC::refreshReceivedZTrans(QList<QString> zaddrs) {
[=] (QString zaddr) {
QJsonObject payload = {
{"jsonrpc", "1.0"},
{"id", "z_lrba"},
{"id", "slowasfuck"},
{"method", "z_listreceivedbyaddress"},
{"params", QJsonArray {zaddr, 0}} // Accept 0 conf as well.
};
@ -461,6 +461,7 @@ void RPC::refreshReceivedZTrans(QList<QString> zaddrs) {
return payload;
},
[=] (QMap<QString, QJsonValue>* zaddrTxids) {
qint64 numTx = 0;
qDebug() << __func__ << ": processing z_listreceivedbyaddress JSON at " << QDateTime::currentSecsSinceEpoch();
// Process all txids, removing duplicates. This can happen if the same address
// appears multiple times in a single tx's outputs.
@ -468,55 +469,36 @@ void RPC::refreshReceivedZTrans(QList<QString> zaddrs) {
QMap<QString, QString> memos;
for (auto it = zaddrTxids->constBegin(); it != zaddrTxids->constEnd(); it++) {
auto zaddr = it.key();
qint64 numTx = 0;
qDebug() << __func__ << ": processing tx's of " << zaddr << " at " << QDateTime::currentSecsSinceEpoch();
for (const auto& i : it.value().toArray()) {
for (const auto& tx : it.value().toArray()) {
numTx++;
// Mark the address as used
usedAddresses->insert(zaddr, true);
// Filter out change txs
if (! i.toObject()["change"].toBool()) {
auto txid = i.toObject()["txid"].toString();
if (! tx.toObject()["change"].toBool()) {
auto txid = tx.toObject()["txid"].toString();
txids.insert(txid);
// Check for Memos
QString memoBytes = i.toObject()["memo"].toString();
QString memoBytes = tx.toObject()["memo"].toString();
if (!memoBytes.startsWith("f600")) {
QString memo(QByteArray::fromHex(
i.toObject()["memo"].toString().toUtf8()));
QString memo(QByteArray::fromHex(tx.toObject()["memo"].toString().toUtf8()));
if (!memo.trimmed().isEmpty())
memos[zaddr + txid] = memo;
}
qint64 timestamp = tx.toObject()["time"].toInt();
auto amount = tx.toObject()["amount"].toDouble();
auto confirmations = (unsigned long)tx.toObject()["confirmations"].toInt();
// Fill in other data
QList<TransactionItem> txdata;
qDebug() << __func__ << ": Adding " << txid << " at time=" << timestamp << " with " << confirmations << " confs";
TransactionItem tx{ QString("receive"), timestamp, zaddr, txid, amount, confirmations, "", memos.value(zaddr + txid, "") };
txdata.push_front(tx);
for (const auto& j : it.value().toArray()) {
numTx++;
// Filter out change txs
if (j.toObject()["change"].toBool()) {
//qDebug() << __func__ << ": filtered change";
continue;
}
auto zaddr = it.key();
auto txid = j.toObject()["txid"].toString();
// Lookup txid in the map
auto txidInfo = zaddrTxids->find(txid);
qint64 timestamp;
if (!txidInfo->toObject()["time"].isUndefined()) {
timestamp = txidInfo->toObject()["time"].toInt();
} else {
timestamp = txidInfo->toObject()["blocktime"].toInt();
}
auto amount = j.toObject()["amount"].toDouble();
//auto confirmations = (unsigned long)txidInfo["confirmations"].toInt();
auto confirmations = (unsigned long)txidInfo->toObject()["confirmations"].toInt();
//qDebug() << __func__ << ": Adding " << txid << " at time=" << timestamp << " with " << confirmations << " confs";
TransactionItem tx{ QString("receive"), timestamp, zaddr, txid, amount, confirmations, "", memos.value(zaddr + txid, "") };
txdata.push_front(tx);
if(numTx % 1000 == 0) {
qDebug() << "z_listreceivedbyaddress: Processed " << numTx << " transactions for " << zaddr;
}
if(numTx % 1000 == 0) {
qDebug() << "z_listreceivedbyaddress: Processed " << numTx << " transactions for " << zaddr;
}
qDebug() << __func__ << ": Updating transactionsTableModel with numTx=" << numTx;
@ -524,11 +506,9 @@ void RPC::refreshReceivedZTrans(QList<QString> zaddrs) {
}
}
}
delete zaddrTxids;
}
);
delete zaddrTxids;
delete txidDetails;
}
/// This will refresh all the balance data from hushd
@ -569,6 +549,7 @@ void RPC::getInfoThenRefresh(bool force) {
int notarized = reply["notarized"].toInt();
int protocolversion = reply["protocolversion"].toInt();
int lag = curBlock - notarized;
//TODO: teach how to deal with post-340k blocks
int blocks_until_halving= 340000 - curBlock;
char halving_days[8];
sprintf(halving_days, "%.2f", (double) (blocks_until_halving * 150) / (60*60*24) );
@ -984,6 +965,7 @@ void RPC::executeTransaction(Tx tx,
void RPC::watchTxStatus() {
qDebug() << __func__ << " at " << QDateTime::currentSecsSinceEpoch();
if (conn == nullptr)
return noConnection();

6
src/rpc.h

@ -11,8 +11,6 @@
#include "mainwindow.h"
#include "connection.h"
class Turnstile;
struct TransactionItem {
QString type;
qint64 datetime;
@ -38,7 +36,7 @@ public:
~RPC();
void setConnection(Connection* c);
const QProcess* getEZcashD() { return ehushd.get(); }
const QProcess* getHushd() { return ehushd.get(); }
void refresh(bool force = false);
@ -88,7 +86,6 @@ public:
void getAllPrivKeys(const std::function<void(QList<QPair<QString, QString>>)>);
Turnstile* getTurnstile() { return turnstile; }
Connection* getConnection() { return conn; }
private:
@ -131,7 +128,6 @@ private:
Ui::MainWindow* ui;
MainWindow* main;
Turnstile* turnstile;
// Current balance in the UI. If this number updates, then refresh the UI
QString currentBalance;

6
src/settings.cpp

@ -89,7 +89,7 @@ void Settings::saveRestoreTableHeader(QTableView* table, QDialog* d, QString tab
});
}
void Settings::setUsingZcashConf(QString confLocation) {
void Settings::setUsingHushConf(QString confLocation) {
if (!confLocation.isEmpty())
_confLocation = confLocation;
}
@ -329,7 +329,7 @@ QString Settings::getDonationAddr() {
return "zs1aq4xnrkjlnxx0zesqye7jz3dfrf3rjh7q5z6u8l6mwyqqaam3gx3j2fkqakp33v93yavq46j83q";
}
bool Settings::addToZcashConf(QString confLocation, QString line) {
bool Settings::addToHushConf(QString confLocation, QString line) {
QFile file(confLocation);
if (!file.open(QIODevice::ReadWrite | QIODevice::Append))
return false;
@ -352,7 +352,7 @@ void Settings::set_currency_name(QString currency_name) {
}
bool Settings::removeFromZcashConf(QString confLocation, QString option) {
bool Settings::removeFromHushConf(QString confLocation, QString option) {
if (confLocation.isEmpty())
return false;

6
src/settings.h

@ -90,7 +90,7 @@ public:
QString get_currency_name();
void set_currency_name(QString currency_name);
void setUsingZcashConf(QString confLocation);
void setUsingHushConf(QString confLocation);
const QString& getZcashdConfLocation() { return _confLocation; }
void setZECPrice(double p) { zecPrice = p; }
@ -137,8 +137,8 @@ public:
static bool isValidAddress(QString addr);
static bool addToZcashConf(QString confLocation, QString line);
static bool removeFromZcashConf(QString confLocation, QString option);
static bool addToHushConf(QString confLocation, QString line);
static bool removeFromHushConf(QString confLocation, QString option);
static const QString labelRegExp;

Loading…
Cancel
Save