From cdc46b302242871b56032770f22cd6dd7a7a6f17 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 23 Oct 2018 22:13:45 -0700 Subject: [PATCH] Rename to save Z txs --- src/mainwindow.cpp | 23 ++++++++--------------- src/rpc.cpp | 18 ++++++++++++++++-- src/senttxstore.cpp | 2 +- src/settings.cpp | 12 ++++-------- src/settings.h | 4 ++-- src/settings.ui | 10 +++++----- src/txtablemodel.cpp | 4 ++-- src/ui_settings.h | 8 ++++---- 8 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 78de9ef..1c7c6d4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -49,14 +49,6 @@ MainWindow::MainWindow(QWidget *parent) : aboutDialog.exec(); }); - // Set up delete sent history action - QObject::connect(ui->actionDelete_Sent_History, &QAction::triggered, [=] () { - bool confirm = QMessageBox::information(this, "Delete Sent History?", - "Shielded z-Address sent transactions are stored locally in your wallet. You may delete this saved information safely any time for your privacy.\nDo you want to delete this now?", - QMessageBox::Yes, QMessageBox::No); - if (confirm) SentTxStore::deleteHistory(); - }); - // Initialize to the balances tab ui->tabWidget->setCurrentIndex(0); @@ -130,13 +122,13 @@ void MainWindow::setupSettingsModal() { // Setup save sent check box QObject::connect(settings.chkSaveTxs, &QCheckBox::stateChanged, [=](auto checked) { - Settings::getInstance()->setSaveSent(checked); + Settings::getInstance()->setSaveZtxs(checked); }); // Setup clear button QObject::connect(settings.btnClearSaved, &QCheckBox::clicked, [=]() { if (QMessageBox::warning(this, "Clear saved history?", - "Shielded z-Address sent transactions are stored locally in your wallet. You may delete this saved information safely any time for your privacy.\nDo you want to delete this now ?", + "Shielded z-Address transactions are stored locally in your wallet, outside zcashd. You may delete this saved information safely any time for your privacy.\nDo you want to delete the saved shielded transactions now ?", QMessageBox::Yes, QMessageBox::Cancel)) { SentTxStore::deleteHistory(); // Reload after the clear button so existing txs disappear @@ -145,7 +137,7 @@ void MainWindow::setupSettingsModal() { }); // Save sent transactions - settings.chkSaveTxs->setChecked(Settings::getInstance()->getSaveSent()); + settings.chkSaveTxs->setChecked(Settings::getInstance()->getSaveZtxs()); // Connection Settings QIntValidator validator(0, 65535); @@ -185,11 +177,12 @@ void MainWindow::setupSettingsModal() { settings.port->text(), settings.rpcuser->text(), settings.rpcpassword->text()); + + this->rpc->reloadConnectionInfo(); + } - // Then refresh everything. - this->rpc->reloadConnectionInfo(); - this->rpc->refresh(); - } + // Then refresh everything. + this->rpc->refresh(); }; }); diff --git a/src/rpc.cpp b/src/rpc.cpp index debed9c..7eee173 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -332,8 +332,21 @@ void RPC::getBatchRPC( waitTimer->start(100); } -/// Batch RPC methods +// Refresh received z txs by calling z_listreceivedbyaddress/gettransaction void RPC::refreshReceivedZTrans(QList zaddrs, QList txidFilter) { + // We'll only refresh the received Z txs if settings allows us. + if (!Settings::getInstance()->getSaveZtxs()) { + QList emptylist; + transactionsTableModel->addZRecvData(emptylist); + return; + } + + + // This method is complicated because z_listreceivedbyaddress only returns the txid, and + // we have to make a follow up call to gettransaction to get details of that transaction. + // Additionally, it has to be done in batches, because there are multiple z-Addresses, + // and each z-Addr can have multiple received txs. + // 1. For each z-Addr, get list of received txs getBatchRPC(zaddrs, [=] (QString zaddr) { @@ -347,7 +360,8 @@ void RPC::refreshReceivedZTrans(QList zaddrs, QList txidFilter return payload; }, [=] (QMap* zaddrTxids) { - // Process all txids + // Process all txids, removing duplicates. This can happen if the same address + // appears multiple times in a single tx's outputs. QSet txids; for (auto it = zaddrTxids->constBegin(); it != zaddrTxids->constEnd(); it++) { for (auto& i : it.value().get()) { diff --git a/src/senttxstore.cpp b/src/senttxstore.cpp index 5e8b2bb..caf2128 100644 --- a/src/senttxstore.cpp +++ b/src/senttxstore.cpp @@ -51,7 +51,7 @@ QList SentTxStore::readSentTxFile() { void SentTxStore::addToSentTx(Tx tx, QString txid) { // Save transactions only if the settings are allowed - if (!Settings::getInstance()->getSaveSent()) + if (!Settings::getInstance()->getSaveZtxs()) return; QFile data(writeableFile()); diff --git a/src/settings.cpp b/src/settings.cpp index e39ac2e..5e2481a 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -11,17 +11,13 @@ Settings::~Settings() { delete uisettings; } -bool Settings::getSaveSent() { +bool Settings::getSaveZtxs() { // Load from the QT Settings. - QSettings s; - - return s.value("options/savesenttx", true).toBool(); + return QSettings().value("options/savesenttx", true).toBool(); } -void Settings::setSaveSent(bool savesent) { - QSettings s; - - s.setValue("options/savesenttx", savesent); +void Settings::setSaveZtxs(bool save) { + QSettings().setValue("options/savesenttx", save); } Settings* Settings::init() { diff --git a/src/settings.h b/src/settings.h index 570c4d2..5142f9d 100644 --- a/src/settings.h +++ b/src/settings.h @@ -36,8 +36,8 @@ public: int getBlockNumber(); void setBlockNumber(int number); - bool getSaveSent(); - void setSaveSent(bool savesent); + bool getSaveZtxs(); + void setSaveZtxs(bool save); bool isSaplingActive(); diff --git a/src/settings.ui b/src/settings.ui index 62109af..01dfd4d 100644 --- a/src/settings.ui +++ b/src/settings.ui @@ -6,8 +6,8 @@ 0 0 - 441 - 430 + 455 + 391 @@ -155,7 +155,7 @@ - Outgoing shielded transactions can be saved locally in the UI for convinence. These are not saved with zcashd. + Shielded transactions are saved locally and shown in the Transactions tab. If you uncheck this, shielded transactions will not appear in the transactions tab. true @@ -165,14 +165,14 @@ - Clear Saved + Delete History - Save sent shielded transactions + Remember Shielded Transactions diff --git a/src/txtablemodel.cpp b/src/txtablemodel.cpp index ebabcef..7a9eb97 100644 --- a/src/txtablemodel.cpp +++ b/src/txtablemodel.cpp @@ -40,7 +40,7 @@ void TxTableModel::addTData(const QList& data) { void TxTableModel::updateAllData() { auto newmodeldata = new QList(); - if (tTrans != nullptr) std::copy( tTrans->begin(), tTrans->end(), std::back_inserter(*newmodeldata)); + if (tTrans != nullptr) std::copy( tTrans->begin(), tTrans->end(), std::back_inserter(*newmodeldata)); if (zsTrans != nullptr) std::copy(zsTrans->begin(), zsTrans->end(), std::back_inserter(*newmodeldata)); if (zrTrans != nullptr) std::copy(zrTrans->begin(), zrTrans->end(), std::back_inserter(*newmodeldata)); @@ -48,7 +48,7 @@ void TxTableModel::updateAllData() { std::sort(newmodeldata->begin(), newmodeldata->end(), [=] (auto a, auto b) { return a.datetime > b.datetime; // reverse sort }); - + // And then swap out the modeldata with the new one. delete modeldata; modeldata = newmodeldata; diff --git a/src/ui_settings.h b/src/ui_settings.h index 253c9dd..96ba06a 100644 --- a/src/ui_settings.h +++ b/src/ui_settings.h @@ -58,7 +58,7 @@ public: { if (Settings->objectName().isEmpty()) Settings->setObjectName(QStringLiteral("Settings")); - Settings->resize(441, 430); + Settings->resize(455, 391); Settings->setModal(true); verticalLayout = new QVBoxLayout(Settings); verticalLayout->setObjectName(QStringLiteral("verticalLayout")); @@ -196,9 +196,9 @@ public: label_3->setText(QApplication::translate("Settings", "RPC Username", nullptr)); label_4->setText(QApplication::translate("Settings", "RPC Password", nullptr)); tabWidget->setTabText(tabWidget->indexOf(tab), QApplication::translate("Settings", "zcashd connection", nullptr)); - label_5->setText(QApplication::translate("Settings", "Outgoing shielded transactions can be saved locally in the UI for convinence. These are not saved with zcashd.", nullptr)); - btnClearSaved->setText(QApplication::translate("Settings", "Clear Saved", nullptr)); - chkSaveTxs->setText(QApplication::translate("Settings", "Save sent shielded transactions", nullptr)); + label_5->setText(QApplication::translate("Settings", "Shielded transactions are saved locally and shown in the Transactions tab. If you uncheck this, shielded transactions will not appear in the transactions tab.", nullptr)); + btnClearSaved->setText(QApplication::translate("Settings", "Delete History", nullptr)); + chkSaveTxs->setText(QApplication::translate("Settings", "Remember Shielded Transactions", nullptr)); tabWidget->setTabText(tabWidget->indexOf(tab_2), QApplication::translate("Settings", "Options", nullptr)); } // retranslateUi