From 422d66288ec421aa55031fda64a8566d329d8013 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Fri, 2 Apr 2021 21:08:48 +0200 Subject: [PATCH 01/12] [Refactoring] Move processBalanceChangeInternal to walletModel --- src/qt/walletmodel.cpp | 26 +++++++++++++------------- src/qt/walletmodel.h | 1 + 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 636c74fb7958f..8a3d9f6fee513 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -200,35 +200,35 @@ static bool IsImportingOrReindexing() std::atomic processingBalance{false}; -static bool processBalanceChangeInternal(WalletModel* walletModel) +bool WalletModel::processBalanceChangeInternal() { - int chainHeight = walletModel->getLastBlockProcessedNum(); - const uint256& blockHash = walletModel->getLastBlockProcessed(); + int chainHeight = getLastBlockProcessedNum(); + const uint256& blockHash = getLastBlockProcessed(); - if (walletModel->hasForceCheckBalance() || chainHeight != walletModel->getCacheNumBLocks()) { + if (hasForceCheckBalance() || chainHeight != getCacheNumBLocks()) { // Try to get lock only if needed - TRY_LOCK(pwalletMain->cs_wallet, lockWallet); + TRY_LOCK(wallet->cs_wallet, lockWallet); if (!lockWallet) return false; - walletModel->setfForceCheckBalanceChanged(false); + setfForceCheckBalanceChanged(false); // Balance and number of transactions might have changed - walletModel->setCacheNumBlocks(chainHeight); - walletModel->setCacheBlockHash(blockHash); - walletModel->checkBalanceChanged(walletModel->getBalances()); - QMetaObject::invokeMethod(walletModel, "updateTxModelData", Qt::QueuedConnection); - QMetaObject::invokeMethod(walletModel, "pollFinished", Qt::QueuedConnection); + setCacheNumBlocks(chainHeight); + setCacheBlockHash(blockHash); + checkBalanceChanged(getBalances()); + QMetaObject::invokeMethod(this, "updateTxModelData", Qt::QueuedConnection); + QMetaObject::invokeMethod(this, "pollFinished", Qt::QueuedConnection); // Address in receive tab may have been used - Q_EMIT walletModel->notifyReceiveAddressChanged(); + Q_EMIT notifyReceiveAddressChanged(); } return true; } static void processBalanceChange(WalletModel* walletModel) { - if (!processBalanceChangeInternal(walletModel)) { + if (!walletModel || !walletModel->processBalanceChangeInternal()) { processingBalance = false; } } diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 08f20d95fd726..65906c4a7509e 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -342,6 +342,7 @@ class WalletModel : public QObject void setCacheBlockHash(const uint256& _blockHash) { m_cached_best_block_hash = _blockHash; } void setfForceCheckBalanceChanged(bool _fForceCheckBalanceChanged) { fForceCheckBalanceChanged = _fForceCheckBalanceChanged; } Q_INVOKABLE void checkBalanceChanged(const interfaces::WalletBalances& new_balances); + bool processBalanceChangeInternal(); void stop(); From cebc900120ff9b9d4cdae81484327895d19c6d61 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Sat, 3 Apr 2021 13:44:28 +0200 Subject: [PATCH 02/12] [Refacotring] Make WalletModel::getBalances private `getBalances` is meant to be used only for the internal polling update process. Now that `processBalanceChangeInternal` has been encapsulated, there is no more need to expose `getBalances`. The rest of the GUI should be using `GetWalletBalances`, which returns cached data. --- src/qt/walletmodel.cpp | 2 +- src/qt/walletmodel.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 8a3d9f6fee513..37c5d1c75c1ef 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -271,7 +271,7 @@ void WalletModel::updateTxModelData() void WalletModel::emitBalanceChanged() { // Force update of UI elements even when no values have changed - Q_EMIT balanceChanged(walletWrapper.getBalances()); + Q_EMIT balanceChanged(getBalances()); } void WalletModel::checkBalanceChanged(const interfaces::WalletBalances& newBalance) diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 65906c4a7509e..a976c5e29a9bc 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -335,7 +335,6 @@ class WalletModel : public QObject uint256 getLastBlockProcessed() const; int getLastBlockProcessedNum() const; - interfaces::WalletBalances getBalances() { return walletWrapper.getBalances(); }; bool hasForceCheckBalance() { return fForceCheckBalanceChanged; } void setCacheNumBlocks(int _cachedNumBlocks) { cachedNumBlocks = _cachedNumBlocks; } int getCacheNumBLocks() { return cachedNumBlocks; } @@ -383,6 +382,8 @@ class WalletModel : public QObject QTimer* pollTimer; QFuture pollFuture; + interfaces::WalletBalances getBalances() { return walletWrapper.getBalances(); }; + void subscribeToCoreSignals(); void unsubscribeFromCoreSignals(); From bffe2c56ecfe9c70bb33066865a7e4e29fdb8737 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Fri, 2 Apr 2021 21:11:38 +0200 Subject: [PATCH 03/12] [BUG] Incorrect usage of pwalletMain inside GUI walletModel --- src/qt/walletmodel.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 37c5d1c75c1ef..3efbe4b136448 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -377,7 +377,7 @@ bool WalletModel::validateAddress(const QString& address, bool fStaking, bool& i bool WalletModel::updateAddressBookLabels(const CWDestination& dest, const std::string& strName, const std::string& strPurpose) { - auto optAdd = pwalletMain->GetAddressBookEntry(dest); + auto optAdd = wallet->GetAddressBookEntry(dest); // Check if we have a new address or an updated label if (!optAdd) { return wallet->SetAddressBook(dest, strName, strPurpose); @@ -737,7 +737,7 @@ static void NotifyKeyStoreStatusChanged(WalletModel* walletmodel, CCryptoKeyStor static void NotifyAddressBookChanged(WalletModel* walletmodel, CWallet* wallet, const CWDestination& address, const std::string& label, bool isMine, const std::string& purpose, ChangeType status) { - QString strAddress = QString::fromStdString(pwalletMain->ParseIntoAddress(address, purpose)); + QString strAddress = QString::fromStdString(wallet->ParseIntoAddress(address, purpose)); QString strLabel = QString::fromStdString(label); QString strPurpose = QString::fromStdString(purpose); @@ -878,26 +878,26 @@ int64_t WalletModel::getCreationTime() const { int64_t WalletModel::getKeyCreationTime(const CPubKey& key) { - return pwalletMain->GetKeyCreationTime(key); + return wallet->GetKeyCreationTime(key); } int64_t WalletModel::getKeyCreationTime(const CTxDestination& address) { if (this->isMine(address)) { - return pwalletMain->GetKeyCreationTime(address); + return wallet->GetKeyCreationTime(address); } return 0; } int64_t WalletModel::getKeyCreationTime(const std::string& address) { - return pwalletMain->GetKeyCreationTime(Standard::DecodeDestination(address)); + return wallet->GetKeyCreationTime(Standard::DecodeDestination(address)); } int64_t WalletModel::getKeyCreationTime(const libzcash::SaplingPaymentAddress& address) { if (this->isMine(address)) { - return pwalletMain->GetKeyCreationTime(address); + return wallet->GetKeyCreationTime(address); } return 0; } @@ -944,7 +944,7 @@ bool WalletModel::updateAddressBookPurpose(const QString &addressStr, const std: CKeyID keyID; if (!getKeyId(address, keyID)) return false; - return pwalletMain->SetAddressBook(keyID, getLabelForAddress(address), purpose); + return wallet->SetAddressBook(keyID, getLabelForAddress(address), purpose); } bool WalletModel::getKeyId(const CTxDestination& address, CKeyID& keyID) From 50867e2f967f1335f2217197cdace22abc021756 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Fri, 2 Apr 2021 21:14:53 +0200 Subject: [PATCH 04/12] [Cleanup][Trivial] Remove unused argument in NotifyKeyStoreStatusChanged --- src/qt/walletmodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 3efbe4b136448..0ec26aafdd662 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -729,7 +729,7 @@ bool WalletModel::backupWallet(const QString& filename) // Handlers for core signals -static void NotifyKeyStoreStatusChanged(WalletModel* walletmodel, CCryptoKeyStore* wallet) +static void NotifyKeyStoreStatusChanged(WalletModel* walletmodel) { qDebug() << "NotifyKeyStoreStatusChanged"; QMetaObject::invokeMethod(walletmodel, "updateStatus", Qt::QueuedConnection); @@ -809,7 +809,7 @@ static void NotifyWalletBacked(WalletModel* model, const bool& fSuccess, const s void WalletModel::subscribeToCoreSignals() { // Connect signals to wallet - m_handler_notify_status_changed = interfaces::MakeHandler(wallet->NotifyStatusChanged.connect(std::bind(&NotifyKeyStoreStatusChanged, this, std::placeholders::_1))); + m_handler_notify_status_changed = interfaces::MakeHandler(wallet->NotifyStatusChanged.connect(std::bind(&NotifyKeyStoreStatusChanged, this))); m_handler_notify_addressbook_changed = interfaces::MakeHandler(wallet->NotifyAddressBookChanged.connect(std::bind(NotifyAddressBookChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6))); m_handler_notify_transaction_changed = interfaces::MakeHandler(wallet->NotifyTransactionChanged.connect(std::bind(NotifyTransactionChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))); m_handler_show_progress = interfaces::MakeHandler(wallet->ShowProgress.connect(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2))); From 733fbc3610baf412162d9a0393238a70f8d9f091 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Fri, 2 Apr 2021 21:34:08 +0200 Subject: [PATCH 05/12] [Trivial] Cleanup walletmodel includes --- src/qt/pivx/masternodewizarddialog.cpp | 1 + src/qt/pivx/topbar.h | 1 + src/qt/walletmodel.cpp | 27 +++++++++++--------------- src/qt/walletmodel.h | 6 +----- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/qt/pivx/masternodewizarddialog.cpp b/src/qt/pivx/masternodewizarddialog.cpp index 3a39b381b1449..60e1107ebe339 100644 --- a/src/qt/pivx/masternodewizarddialog.cpp +++ b/src/qt/pivx/masternodewizarddialog.cpp @@ -11,6 +11,7 @@ #include "qt/pivx/mnmodel.h" #include "qt/pivx/guitransactionsutils.h" #include "qt/pivx/qtutils.h" +#include "qt/walletmodeltransaction.h" #include #include diff --git a/src/qt/pivx/topbar.h b/src/qt/pivx/topbar.h index 677683c945b37..065a77aaaa449 100644 --- a/src/qt/pivx/topbar.h +++ b/src/qt/pivx/topbar.h @@ -6,6 +6,7 @@ #define TOPBAR_H #include +#include "qt/askpassphrasedialog.h" #include "qt/pivx/pwidget.h" #include "qt/pivx/lockunlock.h" #include "amount.h" diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 0ec26aafdd662..0cab925b7d193 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -6,26 +6,21 @@ #include "walletmodel.h" -#include "addresstablemodel.h" -#include "qt/clientmodel.h" -#include "guiconstants.h" -#include "optionsmodel.h" -#include "recentrequeststablemodel.h" -#include "transactiontablemodel.h" -#include "init.h" // for ShutdownRequested(). Future: move to an interface wrapper - -#include "base58.h" -#include "coincontrol.h" -#include "db.h" -#include "keystore.h" +#include "init.h" // for ShutdownRequested() #include "interfaces/handler.h" #include "sapling/key_io_sapling.h" #include "sapling/sapling_operation.h" +#include "sapling/transaction_builder.h" #include "spork.h" -#include "sync.h" -#include "guiinterface.h" -#include "wallet/wallet.h" -#include "wallet/walletdb.h" // for BackupWallet + +#include "qt/addresstablemodel.h" +#include "qt/clientmodel.h" +#include "qt/guiconstants.h" +#include "qt/optionsmodel.h" +#include "qt/recentrequeststablemodel.h" +#include "qt/transactiontablemodel.h" +#include "qt/walletmodeltransaction.h" + #include #include diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index a976c5e29a9bc..8b43ead69d28d 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -7,16 +7,12 @@ #ifndef PIVX_QT_WALLETMODEL_H #define PIVX_QT_WALLETMODEL_H -#include "askpassphrasedialog.h" -#include "paymentrequestplus.h" -#include "walletmodeltransaction.h" - #include "interfaces/wallet.h" #include "operationresult.h" #include "support/allocators/zeroafterfree.h" -#include "wallet/wallet.h" #include "pairresult.h" +#include "qt/paymentrequestplus.h" #include #include From 87d4979efb16201bfd6fdbdc29ac5a5b84a428cc Mon Sep 17 00:00:00 2001 From: random-zebra Date: Fri, 2 Apr 2021 23:48:48 +0200 Subject: [PATCH 06/12] [Refactoring] Move SST / custom fee handling to walletmodel - encapsulate SST settings, and save only in wallet DB - emit signal when SST changes (to sync GUI with RPC) --- src/qt/optionsdialog.cpp | 2 - src/qt/optionsmodel.cpp | 91 ------------------- src/qt/optionsmodel.h | 12 --- .../settings/settingswalletoptionswidget.cpp | 56 ++++++++++-- .../settings/settingswalletoptionswidget.h | 10 +- src/qt/pivx/settings/settingswidget.cpp | 14 +-- src/qt/walletmodel.cpp | 57 +++++++++--- src/qt/walletmodel.h | 13 ++- src/wallet/rpcwallet.cpp | 21 +---- src/wallet/wallet.cpp | 13 +++ src/wallet/wallet.h | 9 ++ 11 files changed, 147 insertions(+), 151 deletions(-) diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index bd2206cc3a52b..3f24ef06217c9 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -197,7 +197,6 @@ void OptionsDialog::setMapper() /* Wallet */ mapper->addMapping(ui->spendZeroConfChange, OptionsModel::SpendZeroConfChange); mapper->addMapping(ui->coinControlFeatures, OptionsModel::CoinControlFeatures); - mapper->addMapping(ui->spinBoxStakeSplitThreshold, OptionsModel::StakeSplitThreshold); /* Network */ mapper->addMapping(ui->mapPortUpnp, OptionsModel::MapPortUPnP); @@ -264,7 +263,6 @@ void OptionsDialog::on_resetButton_clicked() void OptionsDialog::on_okButton_clicked() { mapper->submit(); - pwalletMain->MarkDirty(); accept(); } diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 3346d57425d5e..bdb2e4cfadbc8 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -47,7 +47,6 @@ void OptionsModel::Init() // Ensure restart flag is unset on client startup setRestartRequired(false); - setSSTChanged(false); // These are Qt-only settings: @@ -127,8 +126,6 @@ void OptionsModel::setWalletDefaultOptions(QSettings& settings, bool reset) if (!gArgs.SoftSetBoolArg("-spendzeroconfchange", settings.value("bSpendZeroConfChange").toBool())) addOverriddenOption("-spendzeroconfchange"); if (reset) { - setStakeSplitThreshold(CWallet::DEFAULT_STAKE_SPLIT_THRESHOLD); - setUseCustomFee(false); refreshDataView(); } } @@ -261,16 +258,6 @@ QVariant OptionsModel::data(const QModelIndex& index, int role) const return settings.value("bSpendZeroConfChange"); case ShowMasternodesTab: return settings.value("fShowMasternodesTab"); - case StakeSplitThreshold: - { - // Return CAmount/qlonglong as double - const CAmount nStakeSplitThreshold = (pwalletMain) ? pwalletMain->nStakeSplitThreshold : CWallet::DEFAULT_STAKE_SPLIT_THRESHOLD; - return QVariant(static_cast(nStakeSplitThreshold / static_cast(COIN))); - } - case fUseCustomFee: - return QVariant((pwalletMain) ? pwalletMain->fUseCustomFee : false); - case nCustomFee: - return QVariant(static_cast((pwalletMain) ? pwalletMain->nCustomFee : CWallet::GetRequiredFee(1000))); #endif case DisplayUnit: return nDisplayUnit; @@ -375,18 +362,7 @@ bool OptionsModel::setData(const QModelIndex& index, const QVariant& value, int setRestartRequired(true); } break; - case fUseCustomFee: - setUseCustomFee(value.toBool()); - break; - case nCustomFee: - setCustomFeeValue(value.toLongLong()); - break; #endif - case StakeSplitThreshold: - // Write double as qlonglong/CAmount - setStakeSplitThreshold(static_cast(value.toDouble() * COIN)); - setSSTChanged(true); - break; case DisplayUnit: setDisplayUnit(value); break; @@ -478,61 +454,6 @@ void OptionsModel::setDisplayUnit(const QVariant& value) } } -/* Update StakeSplitThreshold's value in wallet */ -void OptionsModel::setStakeSplitThreshold(const CAmount nStakeSplitThreshold) -{ - if (pwalletMain && pwalletMain->nStakeSplitThreshold != nStakeSplitThreshold) { - CWalletDB walletdb(pwalletMain->GetDBHandle()); - LOCK(pwalletMain->cs_wallet); - { - pwalletMain->nStakeSplitThreshold = nStakeSplitThreshold; - walletdb.WriteStakeSplitThreshold(nStakeSplitThreshold); - } - } -} - -/* returns default minimum value for stake split threshold as doulbe */ -double OptionsModel::getSSTMinimum() const -{ - return static_cast(CWallet::minStakeSplitThreshold / COIN); -} - -/* Verify that StakeSplitThreshold's value is either 0 or above the min. Else reset */ -bool OptionsModel::isSSTValid() -{ - if (pwalletMain && pwalletMain->nStakeSplitThreshold && - pwalletMain->nStakeSplitThreshold < CWallet::minStakeSplitThreshold) { - setStakeSplitThreshold(CWallet::minStakeSplitThreshold); - return false; - } - return true; -} - -/* Update Custom Fee value in wallet */ -void OptionsModel::setUseCustomFee(bool fUse) -{ - if (pwalletMain && pwalletMain->fUseCustomFee != fUse) { - CWalletDB walletdb(pwalletMain->GetDBHandle()); - { - LOCK(pwalletMain->cs_wallet); - pwalletMain->fUseCustomFee = fUse; - walletdb.WriteUseCustomFee(fUse); - } - } -} - -void OptionsModel::setCustomFeeValue(const CAmount& value) -{ - if (pwalletMain && pwalletMain->nCustomFee != value) { - CWalletDB walletdb(pwalletMain->GetDBHandle()); - { - LOCK(pwalletMain->cs_wallet); - pwalletMain->nCustomFee = value; - walletdb.WriteCustomFeeValue(value); - } - } -} - bool OptionsModel::getProxySettings(QNetworkProxy& proxy) const { // Directly query current base proxy, because @@ -561,15 +482,3 @@ bool OptionsModel::isRestartRequired() QSettings settings; return settings.value("fRestartRequired", false).toBool(); } - -void OptionsModel::setSSTChanged(bool fChanged) -{ - QSettings settings; - return settings.setValue("fSSTChanged", fChanged); -} - -bool OptionsModel::isSSTChanged() -{ - QSettings settings; - return settings.value("fSSTChanged", false).toBool(); -} diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 4657786a95d3c..1c9bc7c5efd95 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -55,10 +55,7 @@ class OptionsModel : public QAbstractListModel AnonymizePivxAmount, //int ShowMasternodesTab, // bool Listen, // bool - StakeSplitThreshold, // CAmount (LongLong) ShowColdStakingScreen, // bool - fUseCustomFee, // bool - nCustomFee, // CAmount (LongLong) OptionIDRowCount, }; @@ -71,13 +68,6 @@ class OptionsModel : public QAbstractListModel void refreshDataView(); /** Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal */ void setDisplayUnit(const QVariant& value); - /* Update StakeSplitThreshold's value in wallet */ - void setStakeSplitThreshold(const CAmount value); - double getSSTMinimum() const; - bool isSSTValid(); - /* Update Custom Fee value in wallet */ - void setUseCustomFee(bool fUse); - void setCustomFeeValue(const CAmount& value); /* Explicit getters */ bool isHideCharts() { return fHideCharts; } @@ -93,8 +83,6 @@ class OptionsModel : public QAbstractListModel /* Restart flag helper */ void setRestartRequired(bool fRequired); bool isRestartRequired(); - void setSSTChanged(bool fChanged); - bool isSSTChanged(); bool resetSettings; bool isColdStakingScreenEnabled() { return showColdStakingScreen; } diff --git a/src/qt/pivx/settings/settingswalletoptionswidget.cpp b/src/qt/pivx/settings/settingswalletoptionswidget.cpp index 8ad57c92bffe0..26a61951c170f 100644 --- a/src/qt/pivx/settings/settingswalletoptionswidget.cpp +++ b/src/qt/pivx/settings/settingswalletoptionswidget.cpp @@ -57,19 +57,17 @@ SettingsWalletOptionsWidget::SettingsWalletOptionsWidget(PIVXGUI* _window, QWidg connect(ui->pushButtonClean, &QPushButton::clicked, [this] { Q_EMIT discardSettings(); }); } -void SettingsWalletOptionsWidget::onResetClicked(){ - if (clientModel) { - OptionsModel *optionsModel = clientModel->getOptionsModel(); - QSettings settings; - optionsModel->setWalletDefaultOptions(settings, true); - optionsModel->setNetworkDefaultOptions(settings, true); - inform(tr("Options reset succeed")); - } +void SettingsWalletOptionsWidget::onResetClicked() +{ + QSettings settings; + walletModel->resetWalletOptions(settings); + clientModel->getOptionsModel()->setNetworkDefaultOptions(settings, true); + inform(tr("Options reset succeed")); } -void SettingsWalletOptionsWidget::setMapper(QDataWidgetMapper *mapper){ +void SettingsWalletOptionsWidget::setMapper(QDataWidgetMapper *mapper) +{ mapper->addMapping(ui->radioButtonSpend, OptionsModel::SpendZeroConfChange); - mapper->addMapping(ui->spinBoxStakeSplitThreshold, OptionsModel::StakeSplitThreshold); // Network mapper->addMapping(ui->checkBoxMap, OptionsModel::MapPortUPnP); @@ -79,11 +77,49 @@ void SettingsWalletOptionsWidget::setMapper(QDataWidgetMapper *mapper){ mapper->addMapping(ui->lineEditPort, OptionsModel::ProxyPort); } +void SettingsWalletOptionsWidget::loadWalletModel() +{ + reloadWalletOptions(); + connect(walletModel, &WalletModel::notifySSTChanged, this, &SettingsWalletOptionsWidget::setSpinBoxStakeSplitThreshold); +} + +void SettingsWalletOptionsWidget::reloadWalletOptions() +{ + setSpinBoxStakeSplitThreshold(static_cast(walletModel->getWalletStakeSplitThreshold()) / COIN); +} + void SettingsWalletOptionsWidget::setSpinBoxStakeSplitThreshold(double val) { ui->spinBoxStakeSplitThreshold->setValue(val); } +double SettingsWalletOptionsWidget::getSpinBoxStakeSplitThreshold() const +{ + return ui->spinBoxStakeSplitThreshold->value(); +} + +bool SettingsWalletOptionsWidget::saveWalletOnlyOptions() +{ + // stake split threshold + const CAmount sstOld = walletModel->getWalletStakeSplitThreshold(); + const CAmount sstNew = static_cast(getSpinBoxStakeSplitThreshold() * COIN); + if (sstNew != sstOld) { + const double stakeSplitMinimum = walletModel->getSSTMinimum(); + if (sstNew != 0 && sstNew < static_cast(stakeSplitMinimum * COIN)) { + setSpinBoxStakeSplitThreshold(stakeSplitMinimum); + inform(tr("Stake Split too low, it shall be either >= %1 or equal to 0 (to disable stake splitting)").arg(stakeSplitMinimum)); + return false; + } + walletModel->setWalletStakeSplitThreshold(sstNew); + } + return true; +} + +void SettingsWalletOptionsWidget::discardWalletOnlyOptions() +{ + reloadWalletOptions(); +} + SettingsWalletOptionsWidget::~SettingsWalletOptionsWidget(){ delete ui; } diff --git a/src/qt/pivx/settings/settingswalletoptionswidget.h b/src/qt/pivx/settings/settingswalletoptionswidget.h index 0af64006d9e3c..55a3f7f84905f 100644 --- a/src/qt/pivx/settings/settingswalletoptionswidget.h +++ b/src/qt/pivx/settings/settingswalletoptionswidget.h @@ -21,7 +21,9 @@ class SettingsWalletOptionsWidget : public PWidget ~SettingsWalletOptionsWidget(); void setMapper(QDataWidgetMapper *mapper); - void setSpinBoxStakeSplitThreshold(double val); + + void discardWalletOnlyOptions(); + bool saveWalletOnlyOptions(); Q_SIGNALS: void saveSettings(); @@ -32,6 +34,12 @@ public Q_SLOTS: private: Ui::SettingsWalletOptionsWidget *ui; + + void loadWalletModel() override; + void reloadWalletOptions(); + + void setSpinBoxStakeSplitThreshold(double val); + double getSpinBoxStakeSplitThreshold() const; }; #endif // SETTINGSWALLETOPTIONSWIDGET_H diff --git a/src/qt/pivx/settings/settingswidget.cpp b/src/qt/pivx/settings/settingswidget.cpp index b5e637ace3bdc..62f5a6dd6e6c2 100644 --- a/src/qt/pivx/settings/settingswidget.cpp +++ b/src/qt/pivx/settings/settingswidget.cpp @@ -213,6 +213,7 @@ void SettingsWidget::loadWalletModel() this->settingsBitToolWidget->setWalletModel(this->walletModel); //this->settingsMultisendWidget->setWalletModel(this->walletModel); no visible for now this->settingsDisplayOptionsWidget->setWalletModel(this->walletModel); + this->settingsWalletOptionsWidget->setWalletModel(this->walletModel); } void SettingsWidget::onResetAction() @@ -230,15 +231,13 @@ void SettingsWidget::onResetAction() void SettingsWidget::onSaveOptionsClicked() { + // Save settings that are stored inside the wallet only + if (!settingsWalletOptionsWidget->saveWalletOnlyOptions()) { + return; + } + if (mapper->submit()) { OptionsModel* optionsModel = this->clientModel->getOptionsModel(); - if (optionsModel->isSSTChanged() && !optionsModel->isSSTValid()) { - const double stakeSplitMinimum = optionsModel->getSSTMinimum(); - settingsWalletOptionsWidget->setSpinBoxStakeSplitThreshold(stakeSplitMinimum); - inform(tr("Stake Split too low, it shall be either >= %1 or equal to 0 (to disable stake splitting)").arg(stakeSplitMinimum)); - return; - } - pwalletMain->MarkDirty(); if (optionsModel->isRestartRequired()) { bool fAcceptRestart = openStandardDialog(tr("Restart required"), tr("Your wallet needs to be restarted to apply the changes\n"), tr("Restart Now"), tr("Restart Later")); @@ -422,6 +421,7 @@ void SettingsWidget::onDiscardChanges() return; clientModel->getOptionsModel()->refreshDataView(); } + settingsWalletOptionsWidget->discardWalletOnlyOptions(); } void SettingsWidget::setMapper() diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 0cab925b7d193..00d60a795692c 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -45,7 +45,6 @@ WalletModel::WalletModel(CWallet* wallet, OptionsModel* optionsModel, QObject* p pollTimer = new QTimer(this); connect(pollTimer, &QTimer::timeout, this, &WalletModel::pollBalanceChanged); pollTimer->start(MODEL_UPDATE_DELAY * 5); - subscribeToCoreSignals(); } @@ -54,6 +53,13 @@ WalletModel::~WalletModel() unsubscribeFromCoreSignals(); } +void WalletModel::resetWalletOptions(QSettings& settings) +{ + setWalletStakeSplitThreshold(CWallet::DEFAULT_STAKE_SPLIT_THRESHOLD); + setWalletCustomFee(false, DEFAULT_TRANSACTION_FEE); + optionsModel->setWalletDefaultOptions(settings, false); +} + bool WalletModel::isTestNetwork() const { return Params().IsTestnet(); @@ -302,26 +308,47 @@ void WalletModel::setWalletDefaultFee(CAmount fee) bool WalletModel::hasWalletCustomFee() { - if (!optionsModel) return false; - return optionsModel->data(optionsModel->index(OptionsModel::fUseCustomFee), Qt::EditRole).toBool(); + LOCK(wallet->cs_wallet); + return wallet->fUseCustomFee; } bool WalletModel::getWalletCustomFee(CAmount& nFeeRet) { - nFeeRet = static_cast(optionsModel->data(optionsModel->index(OptionsModel::nCustomFee), Qt::EditRole).toLongLong()); - return hasWalletCustomFee(); + LOCK(wallet->cs_wallet); + nFeeRet = wallet->nCustomFee; + return wallet->fUseCustomFee; } -void WalletModel::setWalletCustomFee(bool fUseCustomFee, const CAmount& nFee) +void WalletModel::setWalletCustomFee(bool fUseCustomFee, const CAmount nFee) { - if (!optionsModel) return; - optionsModel->setData(optionsModel->index(OptionsModel::fUseCustomFee), fUseCustomFee); - // do not update custom fee value when fUseCustomFee is set to false - if (fUseCustomFee) { - optionsModel->setData(optionsModel->index(OptionsModel::nCustomFee), static_cast(nFee)); + LOCK(wallet->cs_wallet); + CWalletDB db(wallet->GetDBHandle()); + if (wallet->fUseCustomFee != fUseCustomFee) { + wallet->fUseCustomFee = fUseCustomFee; + db.WriteUseCustomFee(fUseCustomFee); + } + if (wallet->nCustomFee != nFee) { + wallet->nCustomFee = nFee; + db.WriteCustomFeeValue(nFee); } } +void WalletModel::setWalletStakeSplitThreshold(const CAmount nStakeSplitThreshold) +{ + wallet->SetStakeSplitThreshold(nStakeSplitThreshold); +} + +CAmount WalletModel::getWalletStakeSplitThreshold() const +{ + return wallet->GetStakeSplitThreshold(); +} + +/* returns default minimum value for stake split threshold as doulbe */ +double WalletModel::getSSTMinimum() const +{ + return static_cast(CWallet::minStakeSplitThreshold) / COIN; +} + void WalletModel::updateTransaction() { // Balance and number of transactions might have changed @@ -777,6 +804,12 @@ static void NotifyWatchonlyChanged(WalletModel* walletmodel, bool fHaveWatchonly Q_ARG(bool, fHaveWatchonly)); } +static void NotifySSTChanged(WalletModel* walletmodel, const CAmount stakeSplitThreshold) +{ + const double val = static_cast(stakeSplitThreshold) / COIN; + Q_EMIT walletmodel->notifySSTChanged(val); +} + static void NotifyWalletBacked(WalletModel* model, const bool& fSuccess, const std::string& filename) { std::string message; @@ -806,6 +839,7 @@ void WalletModel::subscribeToCoreSignals() // Connect signals to wallet m_handler_notify_status_changed = interfaces::MakeHandler(wallet->NotifyStatusChanged.connect(std::bind(&NotifyKeyStoreStatusChanged, this))); m_handler_notify_addressbook_changed = interfaces::MakeHandler(wallet->NotifyAddressBookChanged.connect(std::bind(NotifyAddressBookChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6))); + m_handler_notify_sst_changed = interfaces::MakeHandler(wallet->NotifySSTChanged.connect(std::bind(NotifySSTChanged, this, std::placeholders::_1))); m_handler_notify_transaction_changed = interfaces::MakeHandler(wallet->NotifyTransactionChanged.connect(std::bind(NotifyTransactionChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))); m_handler_show_progress = interfaces::MakeHandler(wallet->ShowProgress.connect(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2))); m_handler_notify_watch_only_changed = interfaces::MakeHandler(wallet->NotifyWatchonlyChanged.connect(std::bind(NotifyWatchonlyChanged, this, std::placeholders::_1))); @@ -817,6 +851,7 @@ void WalletModel::unsubscribeFromCoreSignals() // Disconnect signals from wallet m_handler_notify_status_changed->disconnect(); m_handler_notify_addressbook_changed->disconnect(); + m_handler_notify_sst_changed->disconnect(); m_handler_notify_transaction_changed->disconnect(); m_handler_show_progress->disconnect(); m_handler_notify_watch_only_changed->disconnect(); diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 8b43ead69d28d..6c1a598bfb7d8 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -19,6 +19,7 @@ #include #include +#include class AddressTableModel; class ClientModel; @@ -147,6 +148,7 @@ class WalletModel : public QObject TransactionTableModel* getTransactionTableModel(); RecentRequestsTableModel* getRecentRequestsTableModel(); + void resetWalletOptions(QSettings& settings); bool isTestNetwork() const; bool isRegTestNetwork() const; bool isShutdownRequested(); @@ -204,7 +206,12 @@ class WalletModel : public QObject void setWalletDefaultFee(CAmount fee = DEFAULT_TRANSACTION_FEE); bool hasWalletCustomFee(); bool getWalletCustomFee(CAmount& nFeeRet); - void setWalletCustomFee(bool fUseCustomFee, const CAmount& nFee = DEFAULT_TRANSACTION_FEE); + void setWalletCustomFee(bool fUseCustomFee, const CAmount nFee = DEFAULT_TRANSACTION_FEE); + + void setWalletStakeSplitThreshold(const CAmount nStakeSplitThreshold); + CAmount getWalletStakeSplitThreshold() const; + /* Minimum stake split threshold*/ + double getSSTMinimum() const; const CWalletTx* getTx(uint256 id); @@ -351,6 +358,7 @@ class WalletModel : public QObject // Listeners std::unique_ptr m_handler_notify_status_changed; std::unique_ptr m_handler_notify_addressbook_changed; + std::unique_ptr m_handler_notify_sst_changed; std::unique_ptr m_handler_notify_transaction_changed; std::unique_ptr m_handler_show_progress; std::unique_ptr m_handler_notify_watch_only_changed; @@ -410,6 +418,9 @@ class WalletModel : public QObject // Receive tab address may have changed void notifyReceiveAddressChanged(); + /** notify stake-split threshold changed */ + void notifySSTChanged(const double sstVal); + public Q_SLOTS: /* Wallet balances changes */ void balanceNotify(); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6b27ba5655a71..5fe611aa42ecf 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3862,21 +3862,10 @@ UniValue setstakesplitthreshold(const JSONRPCRequest& request) throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf(_("The threshold value cannot be less than %s"), FormatMoney(CWallet::minStakeSplitThreshold))); - EnsureWalletIsUnlocked(); - - CWalletDB walletdb(pwalletMain->GetDBHandle()); - LOCK(pwalletMain->cs_wallet); - { - UniValue result(UniValue::VOBJ); - pwalletMain->nStakeSplitThreshold = nStakeSplitThreshold; - result.pushKV("threshold", ValueFromAmount(pwalletMain->nStakeSplitThreshold)); - if (walletdb.WriteStakeSplitThreshold(nStakeSplitThreshold)) { - result.pushKV("saved", "true"); - } else - result.pushKV("saved", "false"); - - return result; - } + UniValue result(UniValue::VOBJ); + result.pushKV("threshold", request.params[0]); + result.pushKV("saved", pwalletMain->SetStakeSplitThreshold(nStakeSplitThreshold)); + return result; } UniValue getstakesplitthreshold(const JSONRPCRequest& request) @@ -3892,7 +3881,7 @@ UniValue getstakesplitthreshold(const JSONRPCRequest& request) "\nExamples:\n" + HelpExampleCli("getstakesplitthreshold", "") + HelpExampleRpc("getstakesplitthreshold", "")); - return ValueFromAmount(pwalletMain->nStakeSplitThreshold); + return ValueFromAmount(pwalletMain->GetStakeSplitThreshold()); } UniValue autocombinerewards(const JSONRPCRequest& request) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index beee18dc5e26d..38727671c2715 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3829,6 +3829,19 @@ std::set CWallet::ListLockedCoins() return setLockedCoins; } +bool CWallet::SetStakeSplitThreshold(const CAmount sst) +{ + LOCK(cs_wallet); + if (nStakeSplitThreshold != sst) { + nStakeSplitThreshold = sst; + if (!CWalletDB(*dbw).WriteStakeSplitThreshold(sst)) { + return false; + } + NotifySSTChanged(sst); + } + return true; +} + /** @} */ // end of Actions class CAffectedKeysVisitor : public boost::static_visitor diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 5791665acfef2..fcc354d9ccd57 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -850,6 +850,12 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface bool IsAbortingRescan() { return fAbortRescan; } bool IsScanning() { return fScanningWallet; } + /* + * Stake Split threshold + */ + bool SetStakeSplitThreshold(const CAmount sst); + CAmount GetStakeSplitThreshold() const { LOCK(cs_wallet); return nStakeSplitThreshold; } + // keystore implementation PairResult getNewAddress(CTxDestination& ret, const std::string addressLabel, const std::string purpose, const CChainParams::Base58Type addrType = CChainParams::PUBKEY_ADDRESS); @@ -1182,6 +1188,9 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface /** notify wallet file backed up */ boost::signals2::signal NotifyWalletBacked; + + /** notify stake-split threshold changed */ + boost::signals2::signal NotifySSTChanged; }; /** A key allocated from the key pool. */ From 4ca5a2ab54c2e8617a506a6ff9a6548d255267b2 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Sat, 3 Apr 2021 01:30:17 +0200 Subject: [PATCH 07/12] [Refactoring][GUI] GetAvailableP2CSCoins inside walletModel --- src/qt/pivx/coldstakingmodel.cpp | 2 +- src/qt/walletmodel.cpp | 5 +++++ src/qt/walletmodel.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/qt/pivx/coldstakingmodel.cpp b/src/qt/pivx/coldstakingmodel.cpp index 9b86108fbe4cf..22fc9f19654c6 100644 --- a/src/qt/pivx/coldstakingmodel.cpp +++ b/src/qt/pivx/coldstakingmodel.cpp @@ -32,7 +32,7 @@ void ColdStakingModel::refresh() cachedAmount = 0; // First get all of the p2cs utxo inside the wallet std::vector utxoList; - pwalletMain->GetAvailableP2CSCoins(utxoList); + model->getAvailableP2CSCoins(utxoList); if (!utxoList.empty()) { // Loop over each COutput into a CSDelegation diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 00d60a795692c..d4bba497542be 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -171,6 +171,11 @@ bool WalletModel::isColdStaking() const return false; } +void WalletModel::getAvailableP2CSCoins(std::vector& vCoins) const +{ + return wallet->GetAvailableP2CSCoins(vCoins); +} + void WalletModel::updateStatus() { if (!wallet) return; diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 6c1a598bfb7d8..ebb6a5f9eb4d4 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -175,6 +175,7 @@ class WalletModel : public QObject CAmount getDelegatedBalance() const; bool isColdStaking() const; + void getAvailableP2CSCoins(std::vector& vCoins) const; EncryptionStatus getEncryptionStatus() const; bool isWalletUnlocked() const; From beb1cf61f7d5bcc688d59cdf3f652bc18d706bc4 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Sat, 3 Apr 2021 01:45:22 +0200 Subject: [PATCH 08/12] [Refactoring][GUI] remove pwalletMain direct access in mnmodel --- src/qt/pivx/masternodeswidget.cpp | 2 +- src/qt/pivx/mnmodel.cpp | 16 +++++++--------- src/qt/pivx/mnmodel.h | 4 +++- src/qt/walletmodel.cpp | 11 +++++++++++ src/qt/walletmodel.h | 2 ++ 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/qt/pivx/masternodeswidget.cpp b/src/qt/pivx/masternodeswidget.cpp index d9297ac48f9a9..8fefa18403e2e 100644 --- a/src/qt/pivx/masternodeswidget.cpp +++ b/src/qt/pivx/masternodeswidget.cpp @@ -77,7 +77,7 @@ MasterNodesWidget::MasterNodesWidget(PIVXGUI *parent) : new MNHolder(isLightTheme()), this ); - mnModel = new MNModel(this); + mnModel = new MNModel(this, walletModel); this->setStyleSheet(parent->styleSheet()); diff --git a/src/qt/pivx/mnmodel.cpp b/src/qt/pivx/mnmodel.cpp index 04ae3c5430cb0..9c80eac19cac2 100644 --- a/src/qt/pivx/mnmodel.cpp +++ b/src/qt/pivx/mnmodel.cpp @@ -12,7 +12,9 @@ #include "uint256.h" #include "wallet/wallet.h" -MNModel::MNModel(QObject *parent) : QAbstractTableModel(parent) +MNModel::MNModel(QObject *parent, WalletModel* _model) : + QAbstractTableModel(parent), + walletModel(_model) { updateMNList(); } @@ -34,11 +36,8 @@ void MNModel::updateMNList() pmn->vin = txIn; } nodes.insert(QString::fromStdString(mne.getAlias()), std::make_pair(QString::fromStdString(mne.getIp()), pmn)); - if (pwalletMain) { - const CWalletTx *walletTx = pwalletMain->GetWalletTx(txHash); - bool txAccepted = walletTx && - WITH_LOCK(pwalletMain->cs_wallet, return walletTx->GetDepthInMainChain()) >= MasternodeCollateralMinConf(); - collateralTxAccepted.insert(mne.getTxHash(), txAccepted); + if (walletModel) { + collateralTxAccepted.insert(mne.getTxHash(), walletModel->getWalletTxDepth(txHash) >= MasternodeCollateralMinConf()); } } Q_EMIT dataChanged(index(0, 0, QModelIndex()), index(end, 5, QModelIndex()) ); @@ -109,9 +108,8 @@ QVariant MNModel::data(const QModelIndex &index, int role) const case WAS_COLLATERAL_ACCEPTED:{ if (!isAvailable) return false; std::string txHash = rec->vin.prevout.hash.GetHex(); - if (!collateralTxAccepted.value(txHash)) { - const CWalletTx *walletTx = pwalletMain->GetWalletTx(rec->vin.prevout.hash); - return walletTx && WITH_LOCK(pwalletMain->cs_wallet, return walletTx->GetDepthInMainChain()) > 0; + if (!collateralTxAccepted.value(txHash) && walletModel) { + return walletModel->getWalletTxDepth(rec->vin.prevout.hash) > 0; } return true; } diff --git a/src/qt/pivx/mnmodel.h b/src/qt/pivx/mnmodel.h index ca10bf15d1d73..e425e5ea92c1c 100644 --- a/src/qt/pivx/mnmodel.h +++ b/src/qt/pivx/mnmodel.h @@ -8,13 +8,14 @@ #include #include "masternode.h" #include "masternodeconfig.h" +#include "qt/walletmodel.h" class MNModel : public QAbstractTableModel { Q_OBJECT public: - explicit MNModel(QObject *parent = nullptr); + explicit MNModel(QObject *parent, WalletModel* _model); ~MNModel() override { nodes.clear(); collateralTxAccepted.clear(); @@ -56,6 +57,7 @@ class MNModel : public QAbstractTableModel private: + WalletModel* walletModel; // alias mn node ---> pair QMap> nodes; QMap collateralTxAccepted; diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index d4bba497542be..6bc7eb8423898 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -1020,6 +1020,17 @@ bool WalletModel::getMNCollateralCandidate(COutPoint& outPoint) return false; } +// Depth of a wallet transaction or -1 if not found +int WalletModel::getWalletTxDepth(const uint256& txHash) const +{ + const CWalletTx *walletTx = wallet->GetWalletTx(txHash); + if (!walletTx) { + return -1; + } + LOCK(wallet->cs_wallet); + return walletTx->GetDepthInMainChain(); +} + bool WalletModel::isSpent(const COutPoint& outpoint) const { LOCK(wallet->cs_wallet); diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index ebb6a5f9eb4d4..e2ef22b2d78c2 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -295,6 +295,8 @@ class WalletModel : public QObject bool IsShieldedDestination(const CWDestination& address); bool isUsed(CTxDestination address); bool getMNCollateralCandidate(COutPoint& outPoint); + // Depth of a wallet transaction or -1 if not found + int getWalletTxDepth(const uint256& txHash) const; bool isSpent(const COutPoint& outpoint) const; class ListCoinsKey { From 5afa2eab01f14816213b3fa13123202ec68ad977 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Sat, 3 Apr 2021 02:13:42 +0200 Subject: [PATCH 09/12] [Cleanup] Kill MultiSend for good multisend is disabled since long ago, and it won't be re-entroduced in its current form. Remove all related dead code, including the GUI widgets, which have also lots of direct accesses to pwalletMain. --- src/Makefile.qt.include | 8 - src/qt/CMakeLists.txt | 2 - src/qt/pivx/pivxgui.cpp | 4 +- .../settings/forms/settingsmultisenddialog.ui | 433 --------------- .../settings/forms/settingsmultisendwidget.ui | 497 ------------------ src/qt/pivx/settings/forms/settingswidget.ui | 28 - .../pivx/settings/settingsmultisenddialog.cpp | 76 --- .../pivx/settings/settingsmultisenddialog.h | 31 -- .../pivx/settings/settingsmultisendwidget.cpp | 376 ------------- .../pivx/settings/settingsmultisendwidget.h | 67 --- src/qt/pivx/settings/settingswidget.cpp | 18 - src/qt/pivx/settings/settingswidget.h | 3 - src/wallet/rpcwallet.cpp | 193 ------- src/wallet/wallet.cpp | 143 ----- src/wallet/wallet.h | 12 - src/wallet/walletdb.cpp | 92 ---- src/wallet/walletdb.h | 5 - 17 files changed, 1 insertion(+), 1987 deletions(-) delete mode 100644 src/qt/pivx/settings/forms/settingsmultisenddialog.ui delete mode 100644 src/qt/pivx/settings/forms/settingsmultisendwidget.ui delete mode 100644 src/qt/pivx/settings/settingsmultisenddialog.cpp delete mode 100644 src/qt/pivx/settings/settingsmultisenddialog.h delete mode 100644 src/qt/pivx/settings/settingsmultisendwidget.cpp delete mode 100644 src/qt/pivx/settings/settingsmultisendwidget.h diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index e60c9252b3995..2d1bf151b05e4 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -59,8 +59,6 @@ QT_FORMS_UI = \ qt/pivx/settings/forms/settingsfaqwidget.ui \ qt/pivx/settings/forms/settingsinformationwidget.ui \ qt/pivx/settings/forms/settingsmainoptionswidget.ui \ - qt/pivx/settings/forms/settingsmultisenddialog.ui \ - qt/pivx/settings/forms/settingsmultisendwidget.ui \ qt/pivx/settings/forms/settingssignmessagewidgets.ui \ qt/pivx/settings/forms/settingswalletoptionswidget.ui \ qt/pivx/settings/forms/settingswalletrepairwidget.ui \ @@ -148,8 +146,6 @@ QT_MOC_CPP = \ qt/pivx/settings/moc_settingsfaqwidget.cpp \ qt/pivx/settings/moc_settingsinformationwidget.cpp \ qt/pivx/settings/moc_settingsmainoptionswidget.cpp \ - qt/pivx/settings/moc_settingsmultisenddialog.cpp \ - qt/pivx/settings/moc_settingsmultisendwidget.cpp \ qt/pivx/settings/moc_settingssignmessagewidgets.cpp \ qt/pivx/settings/moc_settingswalletoptionswidget.cpp \ qt/pivx/settings/moc_settingswalletrepairwidget.cpp \ @@ -269,8 +265,6 @@ BITCOIN_QT_H = \ qt/pivx/settings/settingsfaqwidget.h \ qt/pivx/settings/settingsinformationwidget.h \ qt/pivx/settings/settingsmainoptionswidget.h \ - qt/pivx/settings/settingsmultisenddialog.h \ - qt/pivx/settings/settingsmultisendwidget.h \ qt/pivx/settings/settingssignmessagewidgets.h \ qt/pivx/settings/settingswalletoptionswidget.h \ qt/pivx/settings/settingswalletrepairwidget.h \ @@ -592,8 +586,6 @@ BITCOIN_QT_WALLET_CPP = \ qt/pivx/settings/settingsfaqwidget.cpp \ qt/pivx/settings/settingsinformationwidget.cpp \ qt/pivx/settings/settingsmainoptionswidget.cpp \ - qt/pivx/settings/settingsmultisenddialog.cpp \ - qt/pivx/settings/settingsmultisendwidget.cpp \ qt/pivx/settings/settingssignmessagewidgets.cpp \ qt/pivx/settings/settingswalletoptionswidget.cpp \ qt/pivx/settings/settingswalletrepairwidget.cpp \ diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index fa45f530d5a56..fb24b33f374fb 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -164,8 +164,6 @@ SET(QT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/pivx/settings/settingsfaqwidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/pivx/settings/settingsinformationwidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/pivx/settings/settingsmainoptionswidget.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/pivx/settings/settingsmultisenddialog.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/pivx/settings/settingsmultisendwidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/pivx/settings/settingssignmessagewidgets.cpp ${CMAKE_CURRENT_SOURCE_DIR}/pivx/settings/settingswalletoptionswidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/pivx/settings/settingswalletrepairwidget.cpp diff --git a/src/qt/pivx/pivxgui.cpp b/src/qt/pivx/pivxgui.cpp index 9bf67562db8d9..f7bae2b13fab5 100644 --- a/src/qt/pivx/pivxgui.cpp +++ b/src/qt/pivx/pivxgui.cpp @@ -653,7 +653,7 @@ void PIVXGUI::incomingTransaction(const QString& date, int unit, const CAmount& // Only send notifications when not disabled if (!bdisableSystemnotifications) { // On new transaction, make an info balloon - message((amount) < 0 ? (pwalletMain->fMultiSendNotify == true ? tr("Sent MultiSend transaction") : tr("Sent transaction")) : tr("Incoming transaction"), + message(amount < 0 ? tr("Sent transaction") : tr("Incoming transaction"), tr("Date: %1\n" "Amount: %2\n" "Type: %3\n" @@ -663,8 +663,6 @@ void PIVXGUI::incomingTransaction(const QString& date, int unit, const CAmount& .arg(type) .arg(address), CClientUIInterface::MSG_INFORMATION); - - pwalletMain->fMultiSendNotify = false; } } diff --git a/src/qt/pivx/settings/forms/settingsmultisenddialog.ui b/src/qt/pivx/settings/forms/settingsmultisenddialog.ui deleted file mode 100644 index cbc59160b2722..0000000000000 --- a/src/qt/pivx/settings/forms/settingsmultisenddialog.ui +++ /dev/null @@ -1,433 +0,0 @@ - - - SettingsMultisendDialog - - - - 0 - 0 - 500 - 428 - - - - Form - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 0 - - - 30 - - - 20 - - - 30 - - - 20 - - - - - 0 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 40 - - - - - 16777215 - 40 - - - - padding-left:24px; - - - Transaction Details - - - Qt::AlignCenter - - - 7 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 24 - 24 - - - - - 24 - 24 - - - - Qt::NoFocus - - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 40 - - - - - - - - - 16777215 - 90 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 3 - - - - - - 0 - 0 - - - - - 0 - 20 - - - - - 16777215 - 20 - - - - TextLabel - - - - - - - - 0 - 50 - - - - - 16777215 - 50 - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - 3 - - - - - - 0 - 0 - - - - - 0 - 20 - - - - - 16777215 - 20 - - - - TextLabel - - - - - - - - 0 - 50 - - - - - 16777215 - 50 - - - - - - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - 5 - - - - - - 16777215 - 20 - - - - TextLabel - - - - - - - - 0 - 50 - - - - - 16777215 - 50 - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 30 - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 50 - - - - - 200 - 16777215 - - - - Qt::NoFocus - - - CANCEL - - - - - - - - 0 - 50 - - - - - 200 - 16777215 - - - - Qt::NoFocus - - - SAVE - - - - - - - - - - - - - diff --git a/src/qt/pivx/settings/forms/settingsmultisendwidget.ui b/src/qt/pivx/settings/forms/settingsmultisendwidget.ui deleted file mode 100644 index 75b3458591bba..0000000000000 --- a/src/qt/pivx/settings/forms/settingsmultisendwidget.ui +++ /dev/null @@ -1,497 +0,0 @@ - - - SettingsMultisendWidget - - - - 0 - 0 - 437 - 434 - - - - Form - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - - - 40 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 5 - - - - - TextLabel - - - - - - - TextLabel - - - true - - - - - - - - - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 120 - 30 - - - - - 120 - 30 - - - - Qt::NoFocus - - - - - - true - - - true - - - - - - - - 120 - 30 - - - - - 120 - 30 - - - - Qt::NoFocus - - - - - - true - - - true - - - true - - - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - QAbstractItemView::NoSelection - - - - - - - - 0 - 100 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Vertical - - - - 20 - 20 - - - - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 30 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 100 - 100 - - - - - 100 - 100 - - - - Qt::NoFocus - - - - - - - 100 - 100 - - - - - - - - - - - N/A - - - Qt::AlignCenter - - - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 40 - - - - - - - - 0 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - CheckBox - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - - 0 - 0 - - - - CheckBox - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 12 - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 40 - 20 - - - - - - - - - 200 - 50 - - - - Qt::NoFocus - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 20 - - - - - - - - - 200 - 50 - - - - - 200 - 50 - - - - Qt::NoFocus - - - - - - - - - - - - - - - - - - diff --git a/src/qt/pivx/settings/forms/settingswidget.ui b/src/qt/pivx/settings/forms/settingswidget.ui index 9785591b8d393..0dfdce4af62c9 100644 --- a/src/qt/pivx/settings/forms/settingswidget.ui +++ b/src/qt/pivx/settings/forms/settingswidget.ui @@ -331,34 +331,6 @@ - - - - - 0 - 50 - - - - - 16777215 - 50 - - - - Qt::NoFocus - - - Multisend - - - true - - - false - - - diff --git a/src/qt/pivx/settings/settingsmultisenddialog.cpp b/src/qt/pivx/settings/settingsmultisenddialog.cpp deleted file mode 100644 index c71c980bba56f..0000000000000 --- a/src/qt/pivx/settings/settingsmultisenddialog.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2019 The PIVX developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "qt/pivx/settings/settingsmultisenddialog.h" -#include "qt/pivx/settings/forms/ui_settingsmultisenddialog.h" -#include -#include -#include "qt/pivx/qtutils.h" - -SettingsMultisendDialog::SettingsMultisendDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::SettingsMultisendDialog) -{ - ui->setupUi(this); - - // Stylesheet - this->setStyleSheet(parent->styleSheet()); - - // Container - setCssProperty(ui->frame, "container-dialog"); - - // Text - ui->labelTitle->setText(tr("New recipient for multisend")); - setCssProperty(ui->labelTitle, "text-title-dialog"); - - // Label - ui->labelSubtitleLabel->setText(tr("Address Label (optional)")); - setCssProperty(ui->labelSubtitleLabel, "text-title2-dialog"); - - ui->lineEditLabel->setPlaceholderText(tr("Enter label to be saved with this address")); - initCssEditLine(ui->lineEditLabel, true); - - // Address - ui->labelSubtitleAddress->setText("PIVX address or contact label"); - setCssProperty(ui->labelSubtitleAddress, "text-title2-dialog"); - ui->lineEditAddress->setPlaceholderText("Enter address"); - initCssEditLine(ui->lineEditAddress, true); - ui->lineEditAddress->setValidator(new QRegExpValidator(QRegExp("^[A-Za-z0-9]+"), ui->lineEditAddress)); - - - ui->labelSubtitlePercentage->setText(tr("Percentage")); - setCssProperty(ui->labelSubtitlePercentage, "text-title2-dialog"); - ui->lineEditPercentage->setPlaceholderText("10%"); - initCssEditLine(ui->lineEditPercentage, true); - ui->lineEditPercentage->setValidator(new QIntValidator(0, 100, ui->lineEditPercentage)); - - // Buttons - setCssProperty(ui->btnEsc, "ic-close"); - setCssProperty(ui->btnCancel, "btn-dialog-cancel"); - ui->btnSave->setText("ADD"); - setCssBtnPrimary(ui->btnSave); - - connect(ui->btnEsc, &QPushButton::clicked, this, &SettingsMultisendDialog::close); - connect(ui->btnCancel, &QPushButton::clicked, this, &SettingsMultisendDialog::close); - connect(ui->btnSave, &QPushButton::clicked, [this](){ - this->isOk = true; - accept(); - }); -} - -QString SettingsMultisendDialog::getAddress(){ - return ui->lineEditAddress->text(); -} -QString SettingsMultisendDialog::getLabel(){ - return ui->lineEditLabel->text(); -} -int SettingsMultisendDialog::getPercentage(){ - QString percentage = ui->lineEditPercentage->text(); - if (percentage.isEmpty()) return 0; - return percentage.toInt(); -} - -SettingsMultisendDialog::~SettingsMultisendDialog(){ - delete ui; -} diff --git a/src/qt/pivx/settings/settingsmultisenddialog.h b/src/qt/pivx/settings/settingsmultisenddialog.h deleted file mode 100644 index d66bd854368f2..0000000000000 --- a/src/qt/pivx/settings/settingsmultisenddialog.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2019 The PIVX developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef SETTINGSMULTISENDDIALOG_H -#define SETTINGSMULTISENDDIALOG_H - -#include - -namespace Ui { -class SettingsMultisendDialog; -} - -class SettingsMultisendDialog : public QDialog -{ - Q_OBJECT - -public: - explicit SettingsMultisendDialog(QWidget *parent = nullptr); - ~SettingsMultisendDialog(); - - QString getAddress(); - QString getLabel(); - int getPercentage(); - - bool isOk = false; -private: - Ui::SettingsMultisendDialog *ui; -}; - -#endif // SETTINGSMULTISENDDIALOG_H diff --git a/src/qt/pivx/settings/settingsmultisendwidget.cpp b/src/qt/pivx/settings/settingsmultisendwidget.cpp deleted file mode 100644 index 70be1059c64a7..0000000000000 --- a/src/qt/pivx/settings/settingsmultisendwidget.cpp +++ /dev/null @@ -1,376 +0,0 @@ -// Copyright (c) 2019-2020 The PIVX developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "qt/pivx/settings/settingsmultisendwidget.h" -#include "qt/pivx/settings/forms/ui_settingsmultisendwidget.h" -#include "qt/pivx/settings/settingsmultisenddialog.h" -#include "qt/pivx/qtutils.h" -#include "addresstablemodel.h" -#include "base58.h" -#include "init.h" -#include "walletmodel.h" -#include "wallet/wallet.h" - - -#define DECORATION_SIZE 65 -#define NUM_ITEMS 3 - -MultiSendModel::MultiSendModel(QObject *parent) : QAbstractTableModel(parent) -{ - updateList(); -} - -void MultiSendModel::updateList() -{ - Q_EMIT dataChanged(index(0, 0, QModelIndex()), index((int) pwalletMain->vMultiSend.size(), 5, QModelIndex()) ); -} - -int MultiSendModel::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid()) - return 0; - return (int) pwalletMain->vMultiSend.size(); -} - -QVariant MultiSendModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - int row = index.row(); - if (role == Qt::DisplayRole || role == Qt::EditRole) { - switch (index.column()) { - case PERCENTAGE: - return pwalletMain->vMultiSend[row].second; - case ADDRESS: { - return QString::fromStdString(pwalletMain->vMultiSend[row].first); - } - } - } - return QVariant(); -} - -QModelIndex MultiSendModel::index(int row, int column, const QModelIndex& parent) const -{ - Q_UNUSED(parent); - return createIndex(row, column, nullptr); -} - -class MultiSendHolder : public FurListRow -{ -public: - MultiSendHolder(); - - explicit MultiSendHolder(bool _isLightTheme) : FurListRow(), isLightTheme(_isLightTheme) {} - - QWidget* createHolder(int pos) override - { - if (!row) { - row = new QWidget(); - QVBoxLayout *verticalLayout_2; - QFrame *frame_2; - QHBoxLayout *horizontalLayout; - QLabel *labelName; - QSpacerItem *horizontalSpacer; - QLabel *labelDate; - QLabel *lblDivisory; - - if (row->objectName().isEmpty()) - row->setObjectName(QStringLiteral("multiSendrow")); - row->resize(475, 65); - row->setStyleSheet(QStringLiteral("")); - setCssProperty(row, "container"); - verticalLayout_2 = new QVBoxLayout(row); - verticalLayout_2->setSpacing(0); - verticalLayout_2->setObjectName(QStringLiteral("verticalLayout_2")); - verticalLayout_2->setContentsMargins(20, 0, 20, 0); - frame_2 = new QFrame(row); - frame_2->setObjectName(QStringLiteral("frame_2")); - frame_2->setStyleSheet(QStringLiteral("border:none;")); - frame_2->setFrameShape(QFrame::StyledPanel); - frame_2->setFrameShadow(QFrame::Raised); - horizontalLayout = new QHBoxLayout(frame_2); - horizontalLayout->setObjectName(QStringLiteral("horizontalLayout")); - horizontalLayout->setContentsMargins(0, -1, 0, -1); - labelName = new QLabel(frame_2); - labelName->setObjectName(QStringLiteral("labelAddress")); - setCssProperty(labelName, "text-list-title1"); - horizontalLayout->addWidget(labelName); - - horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - horizontalLayout->addItem(horizontalSpacer); - - labelDate = new QLabel(frame_2); - labelDate->setObjectName(QStringLiteral("labelPercentage")); - setCssProperty(labelDate, "text-list-caption-medium"); - horizontalLayout->addWidget(labelDate); - - verticalLayout_2->addWidget(frame_2); - - lblDivisory = new QLabel(row); - lblDivisory->setObjectName(QStringLiteral("lblDivisory")); - lblDivisory->setMinimumSize(QSize(0, 1)); - lblDivisory->setMaximumSize(QSize(16777215, 1)); - lblDivisory->setStyleSheet(QStringLiteral("background-color:#bababa;")); - lblDivisory->setAlignment(Qt::AlignBottom | Qt::AlignLeading | Qt::AlignLeft); - verticalLayout_2->addWidget(lblDivisory); - } - - return row; - } - - void init(QWidget* holder,const QModelIndex &index, bool isHovered, bool isSelected) const override - { - holder->findChild("labelAddress")->setText(index.data(Qt::DisplayRole).toString()); - holder->findChild("labelPercentage")->setText( - QString::number(index.sibling(index.row(), MultiSendModel::PERCENTAGE).data(Qt::DisplayRole).toInt()) + QString("%") - ); - } - - QColor rectColor(bool isHovered, bool isSelected) override - { - return getRowColor(isLightTheme, isHovered, isSelected); - } - - ~MultiSendHolder() override {} - - bool isLightTheme; - QWidget *row = nullptr; -}; - - -SettingsMultisendWidget::SettingsMultisendWidget(PWidget *parent) : - PWidget(parent), - ui(new Ui::SettingsMultisendWidget) -{ - ui->setupUi(this); - - this->setStyleSheet(parent->styleSheet()); - delegate = new FurAbstractListItemDelegate( - DECORATION_SIZE, - new MultiSendHolder(isLightTheme()), - this - ); - - // Containers - setCssProperty(ui->left, "container"); - ui->left->setContentsMargins(10,10,10,10); - - // Title - ui->labelTitle->setText("Multisend"); - setCssTitleScreen(ui->labelTitle); - - ui->labelSubtitle1->setText(tr("MultiSend allows you to automatically send up to 100% of your stake or masternode reward to a list of other PIVX addresses after it matures.")); - setCssSubtitleScreen(ui->labelSubtitle1); - - //Button Group - ui->pushLeft->setText(tr("Active")); - setCssProperty(ui->pushLeft, "btn-check-left"); - ui->pushRight->setText(tr("Disable")); - setCssProperty(ui->pushRight, "btn-check-right"); - - setCssProperty(ui->pushImgEmpty, "img-empty-multisend"); - ui->labelEmpty->setText(tr("No active recipient yet")); - setCssProperty(ui->labelEmpty, "text-empty"); - - // CheckBox - ui->checkBoxStake->setText(tr("Send stakes")); - ui->checkBoxRewards->setText(tr("Send masternode rewards")); - - setCssProperty(ui->listView, "container"); - ui->listView->setItemDelegate(delegate); - ui->listView->setIconSize(QSize(DECORATION_SIZE, DECORATION_SIZE)); - ui->listView->setMinimumHeight(NUM_ITEMS * (DECORATION_SIZE + 2)); - ui->listView->setAttribute(Qt::WA_MacShowFocusRect, false); - ui->listView->setSelectionBehavior(QAbstractItemView::SelectRows); - - // Buttons - ui->pushButtonSave->setText(tr("ADD RECIPIENT")); - ui->pushButtonClear->setText(tr("CLEAR ALL")); - setCssBtnPrimary(ui->pushButtonSave); - setCssBtnSecondary(ui->pushButtonClear); - - connect(ui->pushButtonSave, &QPushButton::clicked, this, &SettingsMultisendWidget::onAddRecipientClicked); - connect(ui->pushButtonClear, &QPushButton::clicked, this, &SettingsMultisendWidget::clearAll); -} - -void SettingsMultisendWidget::showEvent(QShowEvent *event) -{ - if (multiSendModel) { - multiSendModel->updateList(); - updateListState(); - } -} - -void SettingsMultisendWidget::loadWalletModel() -{ - if (walletModel) { - multiSendModel = new MultiSendModel(this); - ui->listView->setModel(multiSendModel); - ui->listView->setModelColumn(MultiSendModel::ADDRESS); - - ui->pushLeft->setChecked(pwalletMain->isMultiSendEnabled()); - ui->checkBoxStake->setChecked(pwalletMain->fMultiSendStake); - ui->checkBoxRewards->setChecked(pwalletMain->fMultiSendMasternodeReward); - connect(ui->checkBoxStake, &QCheckBox::stateChanged, this, &SettingsMultisendWidget::checkBoxChanged); - connect(ui->checkBoxRewards, &QCheckBox::stateChanged, this, &SettingsMultisendWidget::checkBoxChanged); - connect(ui->pushLeft, &QPushButton::clicked, this, &SettingsMultisendWidget::activate); - connect(ui->pushRight, &QPushButton::clicked, this, &SettingsMultisendWidget::deactivate); - - updateListState(); - } -} - -void SettingsMultisendWidget::updateListState() -{ - if (multiSendModel->rowCount() > 0) { - ui->listView->setVisible(true); - ui->emptyContainer->setVisible(false); - } else { - ui->listView->setVisible(false); - ui->emptyContainer->setVisible(true); - } -} - -void SettingsMultisendWidget::clearAll() -{ - WalletModel::UnlockContext ctx(walletModel->requestUnlock()); - if (!ctx.isValid()) { - // Unlock wallet was cancelled - inform(tr("Cannot perform operation, wallet locked")); - return; - } - std::vector > vMultiSendTemp = pwalletMain->vMultiSend; - bool fRemoved = true; - pwalletMain->vMultiSend.clear(); - CWalletDB walletdb(pwalletMain->GetDBHandle()); - if (!walletdb.EraseMultiSend(vMultiSendTemp)) - fRemoved = false; - if (!walletdb.WriteMultiSend(pwalletMain->vMultiSend)) - fRemoved = false; - - checkBoxChanged(); - multiSendModel->updateList(); - updateListState(); - inform(fRemoved ? tr("Clear succeed") : tr("Clear all failed, could not locate address in wallet file")); -} - -void SettingsMultisendWidget::checkBoxChanged() -{ - pwalletMain->fMultiSendStake = ui->checkBoxStake->isChecked(); - pwalletMain->fMultiSendMasternodeReward = ui->checkBoxRewards->isChecked(); -} - -void SettingsMultisendWidget::onAddRecipientClicked() -{ - WalletModel::UnlockContext ctx(walletModel->requestUnlock()); - if (!ctx.isValid()) { - // Unlock wallet was cancelled - inform(tr("Cannot add multisend recipient, wallet locked")); - return; - } - showHideOp(true); - SettingsMultisendDialog* dialog = new SettingsMultisendDialog(window); - openDialogWithOpaqueBackgroundY(dialog, window, 3, 5); - - if (dialog->isOk) { - addMultiSend( - dialog->getAddress(), - dialog->getPercentage(), - dialog->getLabel() - ); - } - dialog->deleteLater(); -} - -void SettingsMultisendWidget::addMultiSend(QString address, int percentage, QString addressLabel) -{ - std::string strAddress = address.toStdString(); - CTxDestination destAddress = DecodeDestination(strAddress); - if (!IsValidDestination(destAddress)) { - inform(tr("The entered address: %1 is invalid.\nPlease check the address and try again.").arg(address)); - return; - } - if (percentage > 100 || percentage <= 0) { - inform(tr("Invalid percentage, please enter values from 1 to 100.")); - return; - } - - int nMultiSendPercent = percentage; - int nSumMultiSend = 0; - for (int i = 0; i < (int)pwalletMain->vMultiSend.size(); i++) - nSumMultiSend += pwalletMain->vMultiSend[i].second; - if (nSumMultiSend + nMultiSendPercent > 100) { - inform(tr("The total amount of your MultiSend vector is over 100% of your stake reward")); - return; - } - std::pair pMultiSend; - pMultiSend.first = strAddress; - pMultiSend.second = nMultiSendPercent; - pwalletMain->vMultiSend.push_back(pMultiSend); - - if (walletModel && walletModel->getAddressTableModel()) { - // update the address book with the label given or no label if none was given. - std::string userInputLabel = addressLabel.toStdString(); - walletModel->updateAddressBookLabels(destAddress, (userInputLabel.empty()) ? "(no label)" : userInputLabel, - AddressBook::AddressBookPurpose::SEND); - } - - CWalletDB walletdb(pwalletMain->GetDBHandle()); - if (!walletdb.WriteMultiSend(pwalletMain->vMultiSend)) { - inform(tr("Error saving MultiSend, failed saving properties to the database.")); - return; - } - - multiSendModel->updateList(); - updateListState(); - inform("MultiSend recipient added."); -} - -void SettingsMultisendWidget::activate() -{ - if (pwalletMain->isMultiSendEnabled()) - return; - QString strRet; - if (pwalletMain->vMultiSend.size() < 1) - strRet = tr("Unable to activate MultiSend, no available recipients"); - else if (!(ui->checkBoxStake->isChecked() || ui->checkBoxRewards->isChecked())) { - strRet = tr("Unable to activate MultiSend\nCheck one or both of the check boxes to send on stake and/or masternode rewards"); - } else if (IsValidDestinationString(pwalletMain->vMultiSend[0].first, false, Params())) { - pwalletMain->fMultiSendStake = ui->checkBoxStake->isChecked(); - pwalletMain->fMultiSendMasternodeReward = ui->checkBoxRewards->isChecked(); - - CWalletDB walletdb(pwalletMain->GetDBHandle()); - if (!walletdb.WriteMSettings(pwalletMain->fMultiSendStake, pwalletMain->fMultiSendMasternodeReward, pwalletMain->nLastMultiSendHeight)) - strRet = tr("MultiSend activated but writing settings to DB failed"); - else - strRet = tr("MultiSend activated"); - } else - strRet = tr("First multiSend address invalid"); - - inform(strRet); -} - -void SettingsMultisendWidget::deactivate() -{ - if (pwalletMain->isMultiSendEnabled()) { - QString strRet; - pwalletMain->setMultiSendDisabled(); - CWalletDB walletdb(pwalletMain->GetDBHandle()); - inform(!walletdb.WriteMSettings(false, false, pwalletMain->nLastMultiSendHeight) ? - tr("MultiSend deactivated but writing settings to DB failed") : - tr("MultiSend deactivated") - ); - } -} - -void SettingsMultisendWidget::changeTheme(bool isLightTheme, QString& theme) -{ - static_cast(this->delegate->getRowFactory())->isLightTheme = isLightTheme; -} - -SettingsMultisendWidget::~SettingsMultisendWidget() -{ - delete ui; -} diff --git a/src/qt/pivx/settings/settingsmultisendwidget.h b/src/qt/pivx/settings/settingsmultisendwidget.h deleted file mode 100644 index 82286d8a37b37..0000000000000 --- a/src/qt/pivx/settings/settingsmultisendwidget.h +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2019 The PIVX developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef SETTINGSMULTISENDWIDGET_H -#define SETTINGSMULTISENDWIDGET_H - -#include -#include -#include "qt/pivx/pwidget.h" -#include "qt/pivx/furabstractlistitemdelegate.h" - -class PIVXGUI; - -namespace Ui { -class SettingsMultisendWidget; -} - -class MultiSendModel : public QAbstractTableModel -{ - Q_OBJECT - -public: - explicit MultiSendModel(QObject *parent = nullptr); - ~MultiSendModel() override{} - - enum ColumnIndex { - ADDRESS = 0, - PERCENTAGE = 1 - }; - - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - int columnCount(const QModelIndex &parent = QModelIndex()) const override { return 2; } - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - QModelIndex index(int row, int column, const QModelIndex& parent) const override; - void updateList(); -}; - -class SettingsMultisendWidget : public PWidget -{ - Q_OBJECT - -public: - explicit SettingsMultisendWidget(PWidget *parent); - ~SettingsMultisendWidget(); - - void showEvent(QShowEvent *event) override; - void loadWalletModel() override; - void changeTheme(bool isLightTheme, QString &theme) override; - -private Q_SLOTS: - void onAddRecipientClicked(); - void clearAll(); - void checkBoxChanged(); - void activate(); - void deactivate(); - -private: - Ui::SettingsMultisendWidget *ui; - MultiSendModel* multiSendModel = nullptr; - FurAbstractListItemDelegate *delegate = nullptr; - - void addMultiSend(QString address, int percentage, QString addressLabel); - void updateListState(); -}; - -#endif // SETTINGSMULTISENDWIDGET_H diff --git a/src/qt/pivx/settings/settingswidget.cpp b/src/qt/pivx/settings/settingswidget.cpp index 62f5a6dd6e6c2..99510cd387efb 100644 --- a/src/qt/pivx/settings/settingswidget.cpp +++ b/src/qt/pivx/settings/settingswidget.cpp @@ -40,7 +40,6 @@ SettingsWidget::SettingsWidget(PIVXGUI* parent) : setCssProperty(ui->pushButtonFile, "btn-settings-check"); setCssProperty(ui->pushButtonFile2, "btn-settings-options"); - setCssProperty(ui->pushButtonFile3, "btn-settings-options"); setCssProperty(ui->pushButtonExportCsv, "btn-settings-options"); setCssProperty(ui->pushButtonConfiguration, "btn-settings-check"); @@ -63,7 +62,6 @@ SettingsWidget::SettingsWidget(PIVXGUI* parent) : options = { ui->pushButtonFile2, - ui->pushButtonFile3, ui->pushButtonExportCsv, ui->pushButtonOptions1, ui->pushButtonOptions2, @@ -76,9 +74,6 @@ SettingsWidget::SettingsWidget(PIVXGUI* parent) : ui->pushButtonTools5, }; - /* disable multisend for now */ - ui->pushButtonFile3->setVisible(false); - menus.insert(ui->pushButtonFile, ui->fileButtonsWidget); menus.insert(ui->pushButtonConfiguration, ui->configurationButtonsWidget); menus.insert(ui->pushButtonOptions, ui->optionsButtonsWidget); @@ -93,7 +88,6 @@ SettingsWidget::SettingsWidget(PIVXGUI* parent) : settingsWalletOptionsWidget = new SettingsWalletOptionsWidget(window, this); settingsMainOptionsWidget = new SettingsMainOptionsWidget(window, this); settingsDisplayOptionsWidget = new SettingsDisplayOptionsWidget(window, this); - //settingsMultisendWidget = new SettingsMultisendWidget(this); // no visible for now settingsInformationWidget = new SettingsInformationWidget(window, this); settingsConsoleWidget = new SettingsConsoleWidget(window, this); @@ -105,7 +99,6 @@ SettingsWidget::SettingsWidget(PIVXGUI* parent) : ui->stackedWidgetContainer->addWidget(settingsWalletOptionsWidget); ui->stackedWidgetContainer->addWidget(settingsMainOptionsWidget); ui->stackedWidgetContainer->addWidget(settingsDisplayOptionsWidget); - //ui->stackedWidgetContainer->addWidget(settingsMultisendWidget); ui->stackedWidgetContainer->addWidget(settingsInformationWidget); ui->stackedWidgetContainer->addWidget(settingsConsoleWidget); ui->stackedWidgetContainer->setCurrentWidget(settingsBackupWallet); @@ -113,7 +106,6 @@ SettingsWidget::SettingsWidget(PIVXGUI* parent) : // File Section connect(ui->pushButtonFile, &QPushButton::clicked, this, &SettingsWidget::onFileClicked); connect(ui->pushButtonFile2, &QPushButton::clicked, this, &SettingsWidget::onBackupWalletClicked); - connect(ui->pushButtonFile3, &QPushButton::clicked, this, &SettingsWidget::onMultisendClicked); connect(ui->pushButtonExportCsv, &QPushButton::clicked, this, &SettingsWidget::onExportCSVClicked); // Options @@ -148,9 +140,6 @@ SettingsWidget::SettingsWidget(PIVXGUI* parent) : connect(settingsExportCsvWidget, &SettingsExportCSV::message,this, &SettingsWidget::message); connect(settingsExportCsvWidget, &SettingsExportCSV::showHide, this, &SettingsWidget::showHide); connect(settingsExportCsvWidget, &SettingsExportCSV::execDialog, this, &SettingsWidget::execDialog); - // no visible for now - //connect(settingsMultisendWidget, &SettingsMultisendWidget::showHide, this, &SettingsWidget::showHide); - //connect(settingsMultisendWidget, &SettingsMultisendWidget::message, this, &SettingsWidget::message); connect(settingsMainOptionsWidget, &SettingsMainOptionsWidget::message, this, &SettingsWidget::message); connect(settingsDisplayOptionsWidget, &SettingsDisplayOptionsWidget::message, this, &SettingsWidget::message); connect(settingsWalletOptionsWidget, &SettingsWalletOptionsWidget::message, this, &SettingsWidget::message); @@ -211,7 +200,6 @@ void SettingsWidget::loadWalletModel() this->settingsExportCsvWidget->setWalletModel(this->walletModel); this->settingsSingMessageWidgets->setWalletModel(this->walletModel); this->settingsBitToolWidget->setWalletModel(this->walletModel); - //this->settingsMultisendWidget->setWalletModel(this->walletModel); no visible for now this->settingsDisplayOptionsWidget->setWalletModel(this->walletModel); this->settingsWalletOptionsWidget->setWalletModel(this->walletModel); } @@ -311,12 +299,6 @@ void SettingsWidget::onBipToolClicked() selectOption(ui->pushButtonConfiguration3); } -void SettingsWidget::onMultisendClicked() -{ - ui->stackedWidgetContainer->setCurrentWidget(settingsMultisendWidget); - selectOption(ui->pushButtonFile3); -} - void SettingsWidget::onExportCSVClicked() { ui->stackedWidgetContainer->setCurrentWidget(settingsExportCsvWidget); diff --git a/src/qt/pivx/settings/settingswidget.h b/src/qt/pivx/settings/settingswidget.h index 621e30525dcf0..6bb90ea372ebc 100644 --- a/src/qt/pivx/settings/settingswidget.h +++ b/src/qt/pivx/settings/settingswidget.h @@ -15,7 +15,6 @@ #include "qt/pivx/settings/settingswalletoptionswidget.h" #include "qt/pivx/settings/settingsmainoptionswidget.h" #include "qt/pivx/settings/settingsdisplayoptionswidget.h" -#include "qt/pivx/settings/settingsmultisendwidget.h" #include "qt/pivx/settings/settingsinformationwidget.h" #include "qt/pivx/settings/settingsconsolewidget.h" @@ -57,7 +56,6 @@ private Q_SLOTS: // Wallet Configuration void onConfigurationClicked(); void onBipToolClicked(); - void onMultisendClicked(); void onExportCSVClicked(); // Options @@ -92,7 +90,6 @@ private Q_SLOTS: SettingsWalletOptionsWidget *settingsWalletOptionsWidget{nullptr}; SettingsMainOptionsWidget *settingsMainOptionsWidget{nullptr}; SettingsDisplayOptionsWidget *settingsDisplayOptionsWidget{nullptr}; - SettingsMultisendWidget *settingsMultisendWidget{nullptr}; SettingsInformationWidget *settingsInformationWidget{nullptr}; SettingsConsoleWidget *settingsConsoleWidget{nullptr}; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5fe611aa42ecf..ece0101041703 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3918,34 +3918,6 @@ UniValue autocombinerewards(const JSONRPCRequest& request) return NullUniValue; } -UniValue printMultiSend() -{ - UniValue ret(UniValue::VARR); - UniValue act(UniValue::VOBJ); - act.pushKV("MultiSendStake Activated?", pwalletMain->fMultiSendStake); - act.pushKV("MultiSendMasternode Activated?", pwalletMain->fMultiSendMasternodeReward); - ret.push_back(act); - - if (pwalletMain->vDisabledAddresses.size() >= 1) { - UniValue disAdd(UniValue::VOBJ); - for (unsigned int i = 0; i < pwalletMain->vDisabledAddresses.size(); i++) { - disAdd.pushKV("Disabled From Sending", pwalletMain->vDisabledAddresses[i]); - } - ret.push_back(disAdd); - } - - ret.push_back("MultiSend Addresses to Send To:"); - - UniValue vMS(UniValue::VOBJ); - for (unsigned int i = 0; i < pwalletMain->vMultiSend.size(); i++) { - vMS.pushKV("Address " + std::to_string(i), pwalletMain->vMultiSend[i].first); - vMS.pushKV("Percent", pwalletMain->vMultiSend[i].second); - } - - ret.push_back(vMS); - return ret; -} - UniValue printAddresses() { std::vector vCoins; @@ -3975,170 +3947,6 @@ UniValue printAddresses() return ret; } -unsigned int sumMultiSend() -{ - unsigned int sum = 0; - for (unsigned int i = 0; i < pwalletMain->vMultiSend.size(); i++) - sum += pwalletMain->vMultiSend[i].second; - return sum; -} - -/* disable multisend -UniValue multisend(const JSONRPCRequest& request) -{ - throw std::runtime_error("Multisend is disabled in this wallet version"); - CWalletDB walletdb(pwalletMain->strWalletFile); - bool fFileBacked; - //MultiSend Commands - if (request.params.size() == 1) { - std::string strCommand = request.params[0].get_str(); - UniValue ret(UniValue::VOBJ); - if (strCommand == "print") { - return printMultiSend(); - } else if (strCommand == "printaddress" || strCommand == "printaddresses") { - return printAddresses(); - } else if (strCommand == "clear") { - LOCK(pwalletMain->cs_wallet); - { - bool erased = false; - if (pwalletMain->fFileBacked) { - if (walletdb.EraseMultiSend(pwalletMain->vMultiSend)) - erased = true; - } - - pwalletMain->vMultiSend.clear(); - pwalletMain->setMultiSendDisabled(); - - UniValue obj(UniValue::VOBJ); - obj.pushKV("Erased from database", erased); - obj.pushKV("Erased from RAM", true); - - return obj; - } - } else if (strCommand == "enablestake" || strCommand == "activatestake") { - if (pwalletMain->vMultiSend.size() < 1) - throw JSONRPCError(RPC_INVALID_REQUEST, "Unable to activate MultiSend, check MultiSend vector"); - - if (CBitcoinAddress(pwalletMain->vMultiSend[0].first).IsValid()) { - pwalletMain->fMultiSendStake = true; - if (!walletdb.WriteMSettings(true, pwalletMain->fMultiSendMasternodeReward, pwalletMain->nLastMultiSendHeight)) { - UniValue obj(UniValue::VOBJ); - obj.pushKV("error", "MultiSend activated but writing settings to DB failed"); - UniValue arr(UniValue::VARR); - arr.push_back(obj); - arr.push_back(printMultiSend()); - return arr; - } else - return printMultiSend(); - } - - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to activate MultiSend, check MultiSend vector"); - } else if (strCommand == "enablemasternode" || strCommand == "activatemasternode") { - if (pwalletMain->vMultiSend.size() < 1) - throw JSONRPCError(RPC_INVALID_REQUEST, "Unable to activate MultiSend, check MultiSend vector"); - - if (CBitcoinAddress(pwalletMain->vMultiSend[0].first).IsValid()) { - pwalletMain->fMultiSendMasternodeReward = true; - - if (!walletdb.WriteMSettings(pwalletMain->fMultiSendStake, true, pwalletMain->nLastMultiSendHeight)) { - UniValue obj(UniValue::VOBJ); - obj.pushKV("error", "MultiSend activated but writing settings to DB failed"); - UniValue arr(UniValue::VARR); - arr.push_back(obj); - arr.push_back(printMultiSend()); - return arr; - } else - return printMultiSend(); - } - - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to activate MultiSend, check MultiSend vector"); - } else if (strCommand == "disable" || strCommand == "deactivate") { - pwalletMain->setMultiSendDisabled(); - if (!walletdb.WriteMSettings(false, false, pwalletMain->nLastMultiSendHeight)) - throw JSONRPCError(RPC_DATABASE_ERROR, "MultiSend deactivated but writing settings to DB failed"); - - return printMultiSend(); - } else if (strCommand == "enableall") { - if (!walletdb.EraseMSDisabledAddresses(pwalletMain->vDisabledAddresses)) - return "failed to clear old vector from walletDB"; - else { - pwalletMain->vDisabledAddresses.clear(); - return printMultiSend(); - } - } - } - if (request.params.size() == 2 && request.params[0].get_str() == "delete") { - int del = std::stoi(request.params[1].get_str().c_str()); - if (!walletdb.EraseMultiSend(pwalletMain->vMultiSend)) - throw JSONRPCError(RPC_DATABASE_ERROR, "failed to delete old MultiSend vector from database"); - - pwalletMain->vMultiSend.erase(pwalletMain->vMultiSend.begin() + del); - if (!walletdb.WriteMultiSend(pwalletMain->vMultiSend)) - throw JSONRPCError(RPC_DATABASE_ERROR, "walletdb WriteMultiSend failed!"); - - return printMultiSend(); - } - if (request.params.size() == 2 && request.params[0].get_str() == "disable") { - std::string disAddress = request.params[1].get_str(); - if (!CBitcoinAddress(disAddress).IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "address you want to disable is not valid"); - else { - pwalletMain->vDisabledAddresses.push_back(disAddress); - if (!walletdb.EraseMSDisabledAddresses(pwalletMain->vDisabledAddresses)) - throw JSONRPCError(RPC_DATABASE_ERROR, "disabled address from sending, but failed to clear old vector from walletDB"); - - if (!walletdb.WriteMSDisabledAddresses(pwalletMain->vDisabledAddresses)) - throw JSONRPCError(RPC_DATABASE_ERROR, "disabled address from sending, but failed to store it to walletDB"); - else - return printMultiSend(); - } - } - - //if the user is entering a new MultiSend item - std::string strAddress = request.params[0].get_str(); - CBitcoinAddress address(strAddress); - if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PIV address"); - if (std::stoi(request.params[1].get_str().c_str()) < 0) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid percentage"); - if (pwalletMain->IsLocked()) - throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); - unsigned int nPercent = (unsigned int) std::stoul(request.params[1].get_str().c_str()); - - LOCK(pwalletMain->cs_wallet); - { - fFileBacked = pwalletMain->fFileBacked; - //Error if 0 is entered - if (nPercent == 0) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Sending 0% of stake is not valid"); - } - - //MultiSend can only send 100% of your stake - if (nPercent + sumMultiSend() > 100) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Failed to add to MultiSend vector, the sum of your MultiSend is greater than 100%"); - - for (unsigned int i = 0; i < pwalletMain->vMultiSend.size(); i++) { - if (pwalletMain->vMultiSend[i].first == strAddress) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Failed to add to MultiSend vector, cannot use the same address twice"); - } - - if (fFileBacked) - walletdb.EraseMultiSend(pwalletMain->vMultiSend); - - std::pair newMultiSend; - newMultiSend.first = strAddress; - newMultiSend.second = nPercent; - pwalletMain->vMultiSend.push_back(newMultiSend); - if (fFileBacked) { - if (!walletdb.WriteMultiSend(pwalletMain->vMultiSend)) - throw JSONRPCError(RPC_DATABASE_ERROR, "walletdb WriteMultiSend failed!"); - } - } - return printMultiSend(); -} -*/ - - UniValue getsaplingnotescount(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() > 1) @@ -4318,7 +4126,6 @@ static const CRPCCommand commands[] = { "wallet", "delegatorremove", &delegatorremove, true }, { "wallet", "bip38encrypt", &bip38encrypt, true }, { "wallet", "bip38decrypt", &bip38decrypt, true }, - //{ "wallet", "multisend", &multisend, false }, /** Sapling functions */ { "wallet", "getnewshieldaddress", &getnewshieldaddress, true }, diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 38727671c2715..370db86a5a350 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4071,129 +4071,6 @@ void CWallet::AutoCombineDust(CConnman* connman) } } -bool CWallet::MultiSend() -{ - return false; - /* disable multisend - LOCK2(cs_main, cs_wallet); - // Stop the old blocks from sending multisends - const CBlockIndex* tip = chainActive.Tip(); - int chainTipHeight = tip->nHeight; - if (tip->nTime < (GetAdjustedTime() - 300) || IsLocked()) { - return false; - } - - if (chainTipHeight <= nLastMultiSendHeight) { - LogPrintf("Multisend: lastmultisendheight is higher than current best height\n"); - return false; - } - - std::vector vCoins; - AvailableCoins(&vCoins); - bool stakeSent = false; - bool mnSent = false; - for (const COutput& out : vCoins) { - - //need output with precise confirm count - this is how we identify which is the output to send - if (out.tx->GetDepthInMainChain() != Params().GetConsensus().nCoinbaseMaturity + 1) - continue; - - bool isCoinStake = out.tx->IsCoinStake(); - bool isMNOutPoint = isCoinStake && (out.i == ((int)out.tx->vout.size()) - 1) && - (out.tx->vout[1].scriptPubKey != out.tx->vout[out.i].scriptPubKey); - bool sendMSonMNReward = fMultiSendMasternodeReward && isMNOutPoint; - bool sendMSOnStake = fMultiSendStake && isCoinStake && !sendMSonMNReward; //output is either mnreward or stake reward, not both - - if (!(sendMSOnStake || sendMSonMNReward)) - continue; - - CTxDestination destMyAddress; - if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, destMyAddress)) { - LogPrintf("Multisend: failed to extract destination\n"); - continue; - } - - //Disabled Addresses won't send MultiSend transactions - if (vDisabledAddresses.size() > 0) { - for (unsigned int i = 0; i < vDisabledAddresses.size(); i++) { - if (vDisabledAddresses[i] == CBitcoinAddress(destMyAddress).ToString()) { - LogPrintf("Multisend: disabled address preventing multisend\n"); - return false; - } - } - } - - // create new coin control, populate it with the selected utxo, create sending vector - CCoinControl cControl; - COutPoint outpt(out.tx->GetHash(), out.i); - cControl.Select(outpt); - cControl.destChange = destMyAddress; - - CWalletTx wtx; - CReserveKey keyChange(this); // this change address does not end up being used, because change is returned with coin control switch - CAmount nFeeRet = 0; - std::vector vecSend; - - // loop through multisend vector and add amounts and addresses to the sending vector - const isminefilter filter = ISMINE_SPENDABLE; - CAmount nAmount = 0; - for (unsigned int i = 0; i < vMultiSend.size(); i++) { - // MultiSend vector is a pair of 1)Address as a std::string 2) Percent of stake to send as an int - nAmount = ((out.tx->GetCredit(filter) - out.tx->GetDebit(filter)) * vMultiSend[i].second) / 100; - CBitcoinAddress strAddSend(vMultiSend[i].first); - CScript scriptPubKey; - scriptPubKey = GetScriptForDestination(strAddSend.Get()); - vecSend.emplace_back(scriptPubKey, nAmount, false); - } - - //get the fee amount - CWalletTx wtxdummy; - std::string strErr; - int nChangePosInOut = -1; - CreateTransaction(vecSend, wtxdummy, keyChange, nFeeRet, nChangePosInOut, strErr, &cControl, ALL_COINS, true, false, CAmount(0)); - CAmount nLastSendAmount = vecSend[vecSend.size() - 1].nAmount; - if (nLastSendAmount < nFeeRet + 500) { - LogPrintf("%s: fee of %d is too large to insert into last output\n", __func__, nFeeRet + 500); - return false; - } - vecSend[vecSend.size() - 1].nAmount = nLastSendAmount - nFeeRet - 500; - - // Create the transaction and commit it to the network - if (!CreateTransaction(vecSend, wtx, keyChange, nFeeRet, int nChangePosInOut, strErr, &cControl, ALL_COINS, true, false, CAmount(0))) { - LogPrintf("MultiSend createtransaction failed\n"); - return false; - } - - const CWallet::CommitResult& res = CommitTransaction(wtx, keyChange); - if (res.status != CWallet::CommitStatus::OK) { - LogPrintf("MultiSend transaction commit failed\n"); - return false; - } else - fMultiSendNotify = true; - - //write nLastMultiSendHeight to DB - CWalletDB walletdb(*dbw); - nLastMultiSendHeight = chainActive.Tip()->nHeight; - if (!walletdb.WriteMSettings(fMultiSendStake, fMultiSendMasternodeReward, nLastMultiSendHeight)) - LogPrintf("Failed to write MultiSend setting to DB\n"); - - LogPrintf("MultiSend successfully sent\n"); - - //set which MultiSend triggered - if (sendMSOnStake) - stakeSent = true; - else - mnSent = true; - - //stop iterating if we have sent out all the MultiSend(s) - if ((stakeSent && mnSent) || (stakeSent && !fMultiSendMasternodeReward) || (mnSent && !fMultiSendStake)) - return true; - } - - return true; - */ -} - std::string CWallet::GetWalletHelpString(bool showDebug) { std::string strUsage = HelpMessageGroup(_("Wallet options:")); @@ -4563,15 +4440,6 @@ void CWallet::SetNull() fUseCustomFee = false; nCustomFee = CWallet::minTxFee.GetFeePerK(); - //MultiSend - vMultiSend.clear(); - fMultiSendStake = false; - fMultiSendMasternodeReward = false; - fMultiSendNotify = false; - strMultiSendChangeAddress = ""; - nLastMultiSendHeight = 0; - vDisabledAddresses.clear(); - //Auto Combine Dust fCombineDust = false; nAutoCombineThreshold = 0; @@ -4581,17 +4449,6 @@ void CWallet::SetNull() m_sspk_man->nWitnessCacheNeedsUpdate = true; } -bool CWallet::isMultiSendEnabled() -{ - return fMultiSendMasternodeReward || fMultiSendStake; -} - -void CWallet::setMultiSendDisabled() -{ - fMultiSendMasternodeReward = false; - fMultiSendStake = false; -} - bool CWallet::CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index fcc354d9ccd57..44080b410aa0d 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -716,15 +716,6 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface bool fUseCustomFee; CAmount nCustomFee; - //MultiSend - std::vector > vMultiSend; - bool fMultiSendStake; - bool fMultiSendMasternodeReward; - bool fMultiSendNotify; - std::string strMultiSendChangeAddress; - int nLastMultiSendHeight; - std::vector vDisabledAddresses; - //Auto Combine Inputs bool fCombineDust; CAmount nAutoCombineThreshold; @@ -754,8 +745,6 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface CWallet(std::unique_ptr dbw_in); ~CWallet(); void SetNull(); - bool isMultiSendEnabled(); - void setMultiSendDisabled(); std::map mapWallet; @@ -1050,7 +1039,6 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface CMutableTransaction& txNew, int64_t& nTxNewTime, std::vector* availableCoins); - bool MultiSend(); void AutoCombineDust(CConnman* connman); // Shielded balances diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index d9e36e08e8afa..f8a45c5630e71 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -261,78 +261,6 @@ bool CWalletDB::WriteCustomFeeValue(const CAmount& nFee) return batch.Write(std::string(DBKeys::CUSTOM_FEE_VALUE), nFee); } -bool CWalletDB::WriteMultiSend(std::vector > vMultiSend) -{ - return false; - /* disable multisend - nWalletDBUpdateCounter++; - bool ret = true; - for (unsigned int i = 0; i < vMultiSend.size(); i++) { - std::pair pMultiSend; - pMultiSend = vMultiSend[i]; - if (!Write(std::make_pair(std::string("multisend"), i), pMultiSend, true)) - ret = false; - } - return ret; - */ -} - -bool CWalletDB::EraseMultiSend(std::vector > vMultiSend) -{ - return false; - /* disable multisend - nWalletDBUpdateCounter++; - bool ret = true; - for (unsigned int i = 0; i < vMultiSend.size(); i++) { - std::pair pMultiSend; - pMultiSend = vMultiSend[i]; - if (!Erase(std::make_pair(std::string("multisend"), i))) - ret = false; - } - return ret; - */ -} - -bool CWalletDB::WriteMSettings(bool fMultiSendStake, bool fMultiSendMasternode, int nLastMultiSendHeight) -{ - return false; - /* disable multisend - nWalletDBUpdateCounter++; - std::pair enabledMS(fMultiSendStake, fMultiSendMasternode); - std::pair, int> pSettings(enabledMS, nLastMultiSendHeight); - - return Write(std::string("msettingsv2"), pSettings, true); - */ -} - -bool CWalletDB::WriteMSDisabledAddresses(std::vector vDisabledAddresses) -{ - return false; - /* disable multisend - nWalletDBUpdateCounter++; - bool ret = true; - for (unsigned int i = 0; i < vDisabledAddresses.size(); i++) { - if (!Write(std::make_pair(std::string("mdisabled"), i), vDisabledAddresses[i])) - ret = false; - } - return ret; - */ -} - -bool CWalletDB::EraseMSDisabledAddresses(std::vector vDisabledAddresses) -{ - return false; - /* disable multisend - nWalletDBUpdateCounter++; - bool ret = true; - for (unsigned int i = 0; i < vDisabledAddresses.size(); i++) { - if (!batch.Erase(std::make_pair(std::string("mdisabled"), i))) - ret = false; - } - return ret; - */ -} - bool CWalletDB::WriteAutoCombineSettings(bool fEnable, CAmount nCombineThreshold) { nWalletDBUpdateCounter++; @@ -628,26 +556,6 @@ bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, CW ssValue >> pwallet->fUseCustomFee; } else if (strType == DBKeys::CUSTOM_FEE_VALUE) { ssValue >> pwallet->nCustomFee; - /* disable multisend - } else if (strType == "multisend") { - unsigned int i; - ssKey >> i; - std::pair pMultiSend; - ssValue >> pMultiSend; - if (CBitcoinAddress(pMultiSend.first).IsValid()) { - pwallet->vMultiSend.push_back(pMultiSend); - } - } else if (strType == "msettingsv2") { - std::pair, int> pSettings; - ssValue >> pSettings; - pwallet->fMultiSendStake = pSettings.first.first; - pwallet->fMultiSendMasternodeReward = pSettings.first.second; - pwallet->nLastMultiSendHeight = pSettings.second; - } else if (strType == "mdisabled") { - std::string strDisabledAddress; - ssValue >> strDisabledAddress; - pwallet->vDisabledAddresses.push_back(strDisabledAddress); - */ } else if (strType == DBKeys::AUTOCOMBINE) { std::pair pSettings; ssValue >> pSettings; diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h index abb18fb34b63e..ca5783756ddf3 100644 --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -146,11 +146,6 @@ class CWalletDB bool WriteStakeSplitThreshold(const CAmount& nStakeSplitThreshold); bool WriteUseCustomFee(bool fUse); bool WriteCustomFeeValue(const CAmount& nCustomFee); - bool WriteMultiSend(std::vector > vMultiSend); - bool EraseMultiSend(std::vector > vMultiSend); - bool WriteMSettings(bool fMultiSendStake, bool fMultiSendMasternode, int nLastMultiSendHeight); - bool WriteMSDisabledAddresses(std::vector vDisabledAddresses); - bool EraseMSDisabledAddresses(std::vector vDisabledAddresses); bool WriteAutoCombineSettings(bool fEnable, CAmount nCombineThreshold); bool ReadPool(int64_t nPool, CKeyPool& keypool); From 1a87c44a9bbbe792c34459cf62cd7427686fcd70 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Sat, 3 Apr 2021 02:58:55 +0200 Subject: [PATCH 10/12] [Refactoring] Add getSaplingAddressString to walletModel --- src/qt/pivx/sendconfirmdialog.cpp | 8 ++------ src/qt/pivx/splash.cpp | 6 ++---- src/qt/walletmodel.cpp | 11 +++++++++++ src/qt/walletmodel.h | 1 + 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/qt/pivx/sendconfirmdialog.cpp b/src/qt/pivx/sendconfirmdialog.cpp index 026aeac9865ef..984a9b6e6fb5d 100644 --- a/src/qt/pivx/sendconfirmdialog.cpp +++ b/src/qt/pivx/sendconfirmdialog.cpp @@ -363,12 +363,8 @@ void TxDetailDialog::onOutputsClicked() } // Obtain the noteData to get the cached amount value SaplingNoteData noteData = walletTx->mapSaplingNoteData.at(op); - Optional opAddr = - pwalletMain->GetSaplingScriptPubKeyMan()->GetOutPointAddress(*walletTx, op); - - QString labelRes = opAddr ? QString::fromStdString(Standard::EncodeDestination(*opAddr)) : ""; - labelRes = labelRes.left(18) + "..." + labelRes.right(18); - appendOutput(layoutGrid, i, labelRes, *noteData.amount, nDisplayUnit); + const QString& addrStr = model->getSaplingAddressString(walletTx, op); + appendOutput(layoutGrid, i, addrStr, *noteData.amount, nDisplayUnit); i++; } diff --git a/src/qt/pivx/splash.cpp b/src/qt/pivx/splash.cpp index eca2c3bc8c18e..149f72ff4fee7 100644 --- a/src/qt/pivx/splash.cpp +++ b/src/qt/pivx/splash.cpp @@ -97,10 +97,8 @@ void Splash::unsubscribeFromCoreSignals(){ m_handler_init_message->disconnect(); m_handler_show_progress->disconnect(); #ifdef ENABLE_WALLET - if (pwalletMain) { - m_handler_load_wallet->disconnect(); - if (m_handler_show_progress_wallet) m_handler_show_progress_wallet->disconnect(); - } + m_handler_load_wallet->disconnect(); + if (m_handler_show_progress_wallet) m_handler_show_progress_wallet->disconnect(); #endif } diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 6bc7eb8423898..a89df86b4e717 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -1002,6 +1002,17 @@ std::string WalletModel::getLabelForAddress(const CTxDestination& address) return label; } +QString WalletModel::getSaplingAddressString(const CWalletTx* wtx, const SaplingOutPoint& op) const +{ + Optional opAddr = + wallet->GetSaplingScriptPubKeyMan()->GetOutPointAddress(*wtx, op); + if (!opAddr) { + return QString(); + } + QString ret = QString::fromStdString(Standard::EncodeDestination(*opAddr)); + return ret.left(18) + "..." + ret.right(18); +} + // returns a COutPoint of 10000 PIV if found bool WalletModel::getMNCollateralCandidate(COutPoint& outPoint) { diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index e2ef22b2d78c2..92a5128dd8d8c 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -288,6 +288,7 @@ class WalletModel : public QObject bool blacklistAddressFromColdStaking(const QString &address); bool updateAddressBookPurpose(const QString &addressStr, const std::string& purpose); std::string getLabelForAddress(const CTxDestination& address); + QString getSaplingAddressString(const CWalletTx* wtx, const SaplingOutPoint& op) const; bool getKeyId(const CTxDestination& address, CKeyID& keyID); bool isMine(const CWDestination& address); From 7ec1c6582ee679fce7844983c3a9c94fafe9f24b Mon Sep 17 00:00:00 2001 From: random-zebra Date: Sat, 3 Apr 2021 03:15:04 +0200 Subject: [PATCH 11/12] [Refactoring][GUI] Remove last remaining pwalletMain calls in the GUI --- src/qt/pivx/settings/settingsbittoolwidget.cpp | 14 +++++--------- .../settings/settingssignmessagewidgets.cpp | 2 +- src/qt/walletmodel.cpp | 18 ++++++++++++++++++ src/qt/walletmodel.h | 6 ++++++ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/qt/pivx/settings/settingsbittoolwidget.cpp b/src/qt/pivx/settings/settingsbittoolwidget.cpp index 671962bf7ec65..6b537f5fb14e6 100644 --- a/src/qt/pivx/settings/settingsbittoolwidget.cpp +++ b/src/qt/pivx/settings/settingsbittoolwidget.cpp @@ -166,7 +166,7 @@ void SettingsBitToolWidget::onEncryptKeyButtonENCClicked() } CKey key; - if (!pwalletMain->GetKey(*keyID, key)) { + if (!walletModel->getKey(*keyID, key)) { ui->statusLabel_ENC->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_ENC->setText(tr("Private key for the entered address is not available.")); return; @@ -272,7 +272,7 @@ void SettingsBitToolWidget::onDecryptClicked() void SettingsBitToolWidget::importAddressFromDecKey() { // whenever a key is imported, we need to scan the whole chain - WalletRescanReserver reserver(pwalletMain); + WalletRescanReserver reserver = walletModel->getRescanReserver(); if (!reserver.reserve()) { ui->statusLabel_DEC->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_DEC->setText(tr("Wallet is currently rescanning. Abort existing rescan or wait.")); @@ -299,24 +299,20 @@ void SettingsBitToolWidget::importAddressFromDecKey() ui->statusLabel_DEC->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_DEC->setText(tr("Please wait while key is imported")); - pwalletMain->MarkDirty(); - pwalletMain->SetAddressBook(vchAddress, "", AddressBook::AddressBookPurpose::RECEIVE); + walletModel->updateAddressBookLabels(vchAddress, "", AddressBook::AddressBookPurpose::RECEIVE); // Don't throw error in case a key is already there - if (pwalletMain->HaveKey(vchAddress)) { + if (walletModel->haveKey(vchAddress)) { ui->statusLabel_DEC->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_DEC->setText(tr("Cannot import address, key already held by the wallet")); return; } - pwalletMain->mapKeyMetadata[vchAddress].nCreateTime = 1; - - if (!pwalletMain->AddKeyPubKey(key, pubkey)) { + if (!walletModel->addKeys(key, pubkey, reserver)) { ui->statusLabel_DEC->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_DEC->setText(tr("Error adding key to the wallet")); return; } - pwalletMain->ScanForWalletTransactions(chainActive.Genesis(), nullptr, reserver, true); } ui->statusLabel_DEC->setStyleSheet("QLabel { color: green; }"); diff --git a/src/qt/pivx/settings/settingssignmessagewidgets.cpp b/src/qt/pivx/settings/settingssignmessagewidgets.cpp index 671f932851767..bc3413a839991 100644 --- a/src/qt/pivx/settings/settingssignmessagewidgets.cpp +++ b/src/qt/pivx/settings/settingssignmessagewidgets.cpp @@ -181,7 +181,7 @@ void SettingsSignMessageWidgets::onSignMessageButtonSMClicked() } CKey key; - if (!pwalletMain->GetKey(*keyID, key)) { + if (!walletModel->getKey(*keyID, key)) { ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_SM->setText(tr("Private key for the entered address is not available.")); return; diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index a89df86b4e717..1ec5e9093a7a1 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -414,6 +414,24 @@ bool WalletModel::updateAddressBookLabels(const CWDestination& dest, const std:: return false; } +bool WalletModel::addKeys(const CKey& key, const CPubKey& pubkey, WalletRescanReserver& reserver) +{ + { + LOCK(wallet->cs_wallet); + wallet->mapKeyMetadata[pubkey.GetID()].nCreateTime = 1; + + if (!wallet->AddKeyPubKey(key, pubkey)) { + return false; + } + + // whenever a key is imported, we need to scan the whole chain + wallet->nTimeFirstKey = 1; // 0 would be considered 'no value' + } + CBlockIndex* pindexGenesis = WITH_LOCK(cs_main, return chainActive.Genesis(); ); + wallet->ScanForWalletTransactions(pindexGenesis, nullptr, reserver, true); + return true; +} + WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransaction* transaction, const CCoinControl* coinControl, bool fIncludeDelegations) { CAmount total = 0; diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 92a5128dd8d8c..f08946b3bf214 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -284,12 +284,18 @@ class WalletModel : public QObject //! Return a new shielded address. PairResult getNewShieldedAddress(QString& shieldedAddrRet, std::string strLabel = ""); + //! Return new wallet rescan reserver + WalletRescanReserver getRescanReserver() const { return WalletRescanReserver(wallet); } + bool whitelistAddressFromColdStaking(const QString &addressStr); bool blacklistAddressFromColdStaking(const QString &address); bool updateAddressBookPurpose(const QString &addressStr, const std::string& purpose); std::string getLabelForAddress(const CTxDestination& address); QString getSaplingAddressString(const CWalletTx* wtx, const SaplingOutPoint& op) const; bool getKeyId(const CTxDestination& address, CKeyID& keyID); + bool getKey(const CKeyID& keyID, CKey& key) const { return wallet->GetKey(keyID, key); } + bool haveKey(const CKeyID& keyID) const { return wallet->HaveKey(keyID); } + bool addKeys(const CKey& key, const CPubKey& pubkey, WalletRescanReserver& reserver); bool isMine(const CWDestination& address); bool isMine(const QString& addressStr); From 012de60777fe5cf6c639e7780e3ad3338db3cd47 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Sat, 10 Apr 2021 15:13:10 +0200 Subject: [PATCH 12/12] [Cleanup] Remove unused optionsdialog --- src/Makefile.qt.include | 4 - src/qt/CMakeLists.txt | 1 - src/qt/forms/optionsdialog.ui | 845 ---------------------------------- src/qt/optionsdialog.cpp | 346 -------------- src/qt/optionsdialog.h | 67 --- 5 files changed, 1263 deletions(-) delete mode 100644 src/qt/forms/optionsdialog.ui delete mode 100644 src/qt/optionsdialog.cpp delete mode 100644 src/qt/optionsdialog.h diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 2d1bf151b05e4..f0f4bc840bfe0 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -16,7 +16,6 @@ QT_FORMS_UI = \ qt/forms/helpmessagedialog.ui \ qt/forms/intro.ui \ qt/forms/openuridialog.ui \ - qt/forms/optionsdialog.ui \ qt/forms/rpcconsole.ui \ qt/pivx/forms/loadingdialog.ui \ qt/pivx/forms/snackbar.ui \ @@ -85,7 +84,6 @@ QT_MOC_CPP = \ qt/moc_macnotificationhandler.cpp \ qt/moc_notificator.cpp \ qt/moc_openuridialog.cpp \ - qt/moc_optionsdialog.cpp \ qt/moc_optionsmodel.cpp \ qt/moc_peertablemodel.cpp \ qt/moc_paymentserver.cpp \ @@ -191,7 +189,6 @@ BITCOIN_QT_H = \ qt/networkstyle.h \ qt/notificator.h \ qt/openuridialog.h \ - qt/optionsdialog.h \ qt/optionsmodel.h \ qt/paymentrequestplus.h \ qt/paymentserver.h \ @@ -505,7 +502,6 @@ BITCOIN_QT_BASE_CPP = \ qt/intro.cpp \ qt/networkstyle.cpp \ qt/notificator.cpp \ - qt/optionsdialog.cpp \ qt/optionsmodel.cpp \ qt/peertablemodel.cpp \ qt/platformstyle.cpp \ diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index fb24b33f374fb..ecec5dc0130c5 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -87,7 +87,6 @@ SET(QT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/intro.cpp ${CMAKE_CURRENT_SOURCE_DIR}/networkstyle.cpp ${CMAKE_CURRENT_SOURCE_DIR}/notificator.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/optionsdialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/optionsmodel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/peertablemodel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/platformstyle.cpp diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui deleted file mode 100644 index 02ba6afd61918..0000000000000 --- a/src/qt/forms/optionsdialog.ui +++ /dev/null @@ -1,845 +0,0 @@ - - - OptionsDialog - - - - 0 - 0 - 576 - 442 - - - - Options - - - true - - - - - - 0 - - - - &Main - - - - - - Automatically start PIVX after logging in to the system. - - - &Start PIVX on system login - - - - - - - - - Size of &database cache - - - Qt::PlainText - - - databaseCache - - - - - - - - - - MB - - - Qt::PlainText - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - Number of script &verification threads - - - Qt::PlainText - - - threadsScriptVerif - - - - - - - (0 = auto, <0 = leave that many cores free) - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 0 - - - - - - - Enable automatic minting of PIV units to zPIV - - - Qt::LeftToRight - - - Enable zPIV Automint - - - - - - - Enable automatic zPIV minting from specific addresses - - - Qt::LeftToRight - - - Enable Automint Addresses - - - - - - - - - - - Percentage of incoming PIV which get automatically converted to zPIV via Zerocoin Protocol (min: 10%) - - - Percentage of autominted zPIV - - - - - - - 1 - - - 100 - - - - - - - - - QLayout::SetFixedSize - - - - - - 16777215 - 16777215 - - - - Wait with automatic conversion to Zerocoin until enough PIV for this denomination is available - - - Preferred Automint zPIV Denomination - - - - - - - - 16777215 - 27 - - - - Wait with automatic conversion to Zerocoin until enough PIV for this denomination is available - - - 9 - - - 9 - - - - - - - - - - - - - W&allet - - - - - - - - Stake split threshold: - - - - - - - 1 - - - 999999 - - - - - - - - - Expert - - - - - - Whether to show coin control features or not. - - - Enable coin &control features - - - - - - - Show additional tab listing all your masternodes in first sub-tab<br/>and all masternodes on the network in second sub-tab. - - - Show Masternodes Tab - - - - - - - If you disable the spending of unconfirmed change, the change from a transaction<br/>cannot be used until that transaction has at least one confirmation.<br/>This also affects how your balance is computed. - - - &Spend unconfirmed change - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - &Network - - - - - - Automatically open the PIVX client port on the router. This only works when your router supports UPnP and it is enabled. - - - Map port using &UPnP - - - - - - - Accept connections from outside - - - Allow incoming connections - - - - - - - Connect to the PIVX network through a SOCKS5 proxy. - - - &Connect through SOCKS5 proxy (default proxy): - - - - - - - - - Proxy &IP: - - - Qt::PlainText - - - proxyIp - - - - - - - - 140 - 0 - - - - - 140 - 16777215 - - - - IP address of the proxy (e.g. IPv4: 127.0.0.1 / IPv6: ::1) - - - - - - - &Port: - - - Qt::PlainText - - - proxyPort - - - - - - - - 55 - 0 - - - - - 55 - 16777215 - - - - Port of the proxy (e.g. 9050) - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - &Window - - - - - - Show only a tray icon after minimizing the window. - - - &Minimize to the tray instead of the taskbar - - - - - - - Minimize instead of exit the application when the window is closed. When this option is enabled, the application will be closed only after selecting Quit in the menu. - - - M&inimize on close - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - &Display - - - - - - - - User Interface &language: - - - Qt::PlainText - - - lang - - - - - - - The user interface language can be set here. This setting will take effect after restarting PIVX. - - - - - - - - - - - - - - - - - - - - - Language missing or translation incomplete? Help contributing translations here: -https://www.transifex.com/pivx-project/pivx-project-translations - - - true - - - true - - - Qt::TextBrowserInteraction - - - - - - - - - User Interface Theme: - - - - - - - - - - - - - 0 - - - - - Qt::Horizontal - - - - - - - - - Unit to show amounts in: - - - Qt::PlainText - - - - - - - Choose the default subdivision unit to show in the interface and when sending coins. - - - - - - - - - - - Decimal digits - - - - - - - - - - - - - - Hide empty balances - - - Qt::LeftToRight - - - Hide empty balances - - - - - - - Hide orphan stakes in transaction lists - - - Hide orphan stakes - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - Third party URLs (e.g. a block explorer) that appear in the transactions tab as context menu items. %s in the URL is replaced by transaction hash. Multiple URLs are separated by vertical bar |. - - - Third party transaction URLs - - - - - - - Third party URLs (e.g. a block explorer) that appear in the transactions tab as context menu items. %s in the URL is replaced by transaction hash. Multiple URLs are separated by vertical bar |. - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - - Active command-line options that override above options: - - - Qt::PlainText - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - Qt::PlainText - - - true - - - - - - - - - - - - Reset all client options to default. - - - &Reset Options - - - false - - - - - - - Qt::Horizontal - - - - 40 - 48 - - - - - - - - - 200 - 0 - - - - - 75 - true - - - - - - - Qt::PlainText - - - true - - - - - - - Qt::Horizontal - - - - 40 - 48 - - - - - - - - &OK - - - false - - - true - - - - - - - &Cancel - - - false - - - - - - - - - - QValidatedLineEdit - QLineEdit -
qvalidatedlineedit.h
-
- - QValueComboBox - QComboBox -
qvaluecombobox.h
-
-
- - -
diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp deleted file mode 100644 index 3f24ef06217c9..0000000000000 --- a/src/qt/optionsdialog.cpp +++ /dev/null @@ -1,346 +0,0 @@ -// Copyright (c) 2011-2013 The Bitcoin developers -// Copyright (c) 2017-2020 The PIVX developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#if defined(HAVE_CONFIG_H) -#include "config/pivx-config.h" -#endif - -#include "optionsdialog.h" -#include "ui_optionsdialog.h" - -#include "bitcoinunits.h" -#include "guiutil.h" -#include "optionsmodel.h" - -#include "netbase.h" -#include "txdb.h" // for -dbcache defaults - -#ifdef ENABLE_WALLET -#include "wallet/wallet.h" // for CWallet::minTxFee -#endif - -#include - -#include -#include -#include -#include -#include -#include - -OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint), - ui(new Ui::OptionsDialog), - model(0), - mapper(0), - fProxyIpValid(true) -{ - ui->setupUi(this); - GUIUtil::restoreWindowGeometry("nOptionsDialogWindow", this->size(), this); - - /* Main elements init */ - ui->databaseCache->setMinimum(nMinDbCache); - ui->databaseCache->setMaximum(nMaxDbCache); - ui->threadsScriptVerif->setMinimum(-GetNumCores()); - ui->threadsScriptVerif->setMaximum(MAX_SCRIPTCHECK_THREADS); - - /* Network elements init */ -#ifndef USE_UPNP - ui->mapPortUpnp->setEnabled(false); -#endif - - ui->proxyIp->setEnabled(false); - ui->proxyPort->setEnabled(false); - ui->proxyPort->setValidator(new QIntValidator(1, 65535, this)); - - connect(ui->connectSocks, &QCheckBox::toggled, ui->proxyIp, &QWidget::setEnabled); - connect(ui->connectSocks, &QCheckBox::toggled, ui->proxyPort, &QWidget::setEnabled); - - ui->proxyIp->installEventFilter(this); - ui->proxyPort->installEventFilter(this); - -/* Window elements init */ -#ifdef Q_OS_MAC - /* remove Window tab on Mac */ - ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWindow)); -#endif - - /* remove Wallet tab in case of -disablewallet */ - if (!enableWallet) { - ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWallet)); - } - - /* Display elements init */ - - /* Number of displayed decimal digits selector */ - QString digits; - for (int index = 2; index <= 8; index++) { - digits.setNum(index); - ui->digits->addItem(digits, digits); - } - - /* Theme selector static themes */ - ui->theme->addItem(QString("Default"), QVariant("default")); - - /* Preferred Zerocoin Denominations */ - ui->preferredDenom->addItem(QString(tr("Any")), QVariant("0")); - ui->preferredDenom->addItem(QString("1"), QVariant("1")); - ui->preferredDenom->addItem(QString("5"), QVariant("5")); - ui->preferredDenom->addItem(QString("10"), QVariant("10")); - ui->preferredDenom->addItem(QString("50"), QVariant("50")); - ui->preferredDenom->addItem(QString("100"), QVariant("100")); - ui->preferredDenom->addItem(QString("500"), QVariant("500")); - ui->preferredDenom->addItem(QString("1000"), QVariant("1000")); - ui->preferredDenom->addItem(QString("5000"), QVariant("5000")); - - /* Theme selector external themes */ - fs::path pathAddr = GetDataDir() / "themes"; - QDir dir(pathAddr.string().c_str()); - dir.setFilter(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot); - QFileInfoList list = dir.entryInfoList(); - - for (int i = 0; i < list.size(); ++i) { - QFileInfo fileInfo = list.at(i); - ui->theme->addItem(fileInfo.fileName(), QVariant(fileInfo.fileName())); - } - - /* Language selector */ - QDir translations(":translations"); - ui->lang->addItem(QString("(") + tr("default") + QString(")"), QVariant("")); - for (const QString& langStr : translations.entryList()) { - QLocale locale(langStr); - - /** check if the locale name consists of 2 parts (language_country) */ - if(langStr.contains("_")) - { - /** display language strings as "native language - native country (locale name)", e.g. "Deutsch - Deutschland (de)" */ - ui->lang->addItem(locale.nativeLanguageName() + QString(" - ") + locale.nativeCountryName() + QString(" (") + langStr + QString(")"), QVariant(langStr)); - } - else - { - /** display language strings as "native language (locale name)", e.g. "Deutsch (de)" */ - ui->lang->addItem(locale.nativeLanguageName() + QString(" (") + langStr + QString(")"), QVariant(langStr)); - } - } - ui->thirdPartyTxUrls->setPlaceholderText("https://example.com/tx/%s"); - - ui->unit->setModel(new BitcoinUnits(this)); - - /* Widget-to-option mapper */ - mapper = new QDataWidgetMapper(this); - mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); - mapper->setOrientation(Qt::Vertical); - - /* setup/change UI elements when proxy IP is invalid/valid */ - connect(this, &OptionsDialog::proxyIpChecks, this, &OptionsDialog::doProxyIpChecks); -} - -OptionsDialog::~OptionsDialog() -{ - GUIUtil::saveWindowGeometry("nOptionsDialogWindow", this); - delete ui; -} - -void OptionsDialog::setModel(OptionsModel* model) -{ - this->model = model; - - if (model) { - /* check if client restart is needed and show persistent message */ - if (model->isRestartRequired()) - showRestartWarning(true); - - QString strLabel = model->getOverriddenByCommandLine(); - if (strLabel.isEmpty()) - strLabel = tr("none"); - ui->overriddenByCommandLineLabel->setText(strLabel); - - mapper->setModel(model); - setMapper(); - mapper->toFirst(); - } - - /* warn when one of the following settings changes by user action (placed here so init via mapper doesn't trigger them) */ - - /* Main */ - connect(ui->databaseCache, static_cast(&QSpinBox::valueChanged), this, &OptionsDialog::showRestartWarning); - connect(ui->threadsScriptVerif, static_cast(&QSpinBox::valueChanged), this, &OptionsDialog::showRestartWarning); - /* Wallet */ - connect(ui->spendZeroConfChange, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning); - /* Network */ - connect(ui->allowIncoming, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning); - connect(ui->connectSocks, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning); - /* Display */ - connect(ui->digits, static_cast(&QValueComboBox::valueChanged), [this]{ showRestartWarning(); }); - connect(ui->theme, static_cast(&QValueComboBox::valueChanged), [this]{ showRestartWarning(); }); - connect(ui->lang, static_cast(&QValueComboBox::valueChanged), [this]{ showRestartWarning(); }); - connect(ui->thirdPartyTxUrls, &QLineEdit::textChanged, [this]{ showRestartWarning(); }); - connect(ui->showMasternodesTab, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning); -} - -void OptionsDialog::setMapper() -{ - /* Main */ - mapper->addMapping(ui->bitcoinAtStartup, OptionsModel::StartAtStartup); - mapper->addMapping(ui->threadsScriptVerif, OptionsModel::ThreadsScriptVerif); - mapper->addMapping(ui->databaseCache, OptionsModel::DatabaseCache); - // Zeromint Enabled - mapper->addMapping(ui->checkBoxZeromintEnable, OptionsModel::ZeromintEnable); - // Zeromint Addresses - mapper->addMapping(ui->checkBoxZeromintAddresses, OptionsModel::ZeromintAddresses); - // Zerocoin mint percentage - mapper->addMapping(ui->zeromintPercentage, OptionsModel::ZeromintPercentage); - // Zerocoin preferred denomination - mapper->addMapping(ui->preferredDenom, OptionsModel::ZeromintPrefDenom); - - /* Wallet */ - mapper->addMapping(ui->spendZeroConfChange, OptionsModel::SpendZeroConfChange); - mapper->addMapping(ui->coinControlFeatures, OptionsModel::CoinControlFeatures); - - /* Network */ - mapper->addMapping(ui->mapPortUpnp, OptionsModel::MapPortUPnP); - mapper->addMapping(ui->allowIncoming, OptionsModel::Listen); - - mapper->addMapping(ui->connectSocks, OptionsModel::ProxyUse); - mapper->addMapping(ui->proxyIp, OptionsModel::ProxyIP); - mapper->addMapping(ui->proxyPort, OptionsModel::ProxyPort); - - /* Window */ -#ifndef Q_OS_MAC - mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray); - mapper->addMapping(ui->minimizeOnClose, OptionsModel::MinimizeOnClose); -#endif - - /* Display */ - mapper->addMapping(ui->digits, OptionsModel::Digits); - mapper->addMapping(ui->theme, OptionsModel::Theme); - mapper->addMapping(ui->theme, OptionsModel::Theme); - mapper->addMapping(ui->lang, OptionsModel::Language); - mapper->addMapping(ui->unit, OptionsModel::DisplayUnit); - mapper->addMapping(ui->thirdPartyTxUrls, OptionsModel::ThirdPartyTxUrls); - mapper->addMapping(ui->checkBoxHideZeroBalances, OptionsModel::HideZeroBalances); - mapper->addMapping(ui->checkBoxHideOrphans, OptionsModel::HideOrphans); - - /* Masternode Tab */ - mapper->addMapping(ui->showMasternodesTab, OptionsModel::ShowMasternodesTab); -} - -void OptionsDialog::enableOkButton() -{ - /* prevent enabling of the OK button when data modified, if there is an invalid proxy address present */ - if (fProxyIpValid) - setOkButtonState(true); -} - -void OptionsDialog::disableOkButton() -{ - setOkButtonState(false); -} - -void OptionsDialog::setOkButtonState(bool fState) -{ - ui->okButton->setEnabled(fState); -} - -void OptionsDialog::on_resetButton_clicked() -{ - if (model) { - // confirmation dialog - QMessageBox::StandardButton btnRetVal = QMessageBox::question(this, tr("Confirm options reset"), - tr("Client restart required to activate changes.") + "

" + tr("Client will be shutdown, do you want to proceed?"), - QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); - - if (btnRetVal == QMessageBox::Cancel) - return; - - /* reset all options and close GUI */ - model->Reset(); - QApplication::quit(); - } -} - -void OptionsDialog::on_okButton_clicked() -{ - mapper->submit(); - accept(); -} - -void OptionsDialog::on_cancelButton_clicked() -{ - reject(); -} - -void OptionsDialog::showRestartWarning(bool fPersistent) -{ - ui->statusLabel->setStyleSheet("QLabel { color: red; }"); - - if (fPersistent) { - ui->statusLabel->setText(tr("Client restart required to activate changes.")); - } else { - ui->statusLabel->setText(tr("This change would require a client restart.")); - // clear non-persistent status label after 10 seconds - // Todo: should perhaps be a class attribute, if we extend the use of statusLabel - QTimer::singleShot(10000, this, &OptionsDialog::clearStatusLabel); - } -} - -void OptionsDialog::clearStatusLabel() -{ - ui->statusLabel->clear(); -} - -void OptionsDialog::updateHideOrphans(bool fHide) -{ - if(ui->checkBoxHideOrphans->isChecked() != fHide) - ui->checkBoxHideOrphans->setChecked(fHide); -} - -void OptionsDialog::doProxyIpChecks(QValidatedLineEdit* pUiProxyIp, QLineEdit* pUiProxyPort) -{ - const std::string strAddrProxy = pUiProxyIp->text().toStdString(); - const int nProxyPort = pUiProxyPort->text().toInt(); - CService addrProxy(LookupNumeric(strAddrProxy.c_str(), nProxyPort)); - - // Check for a valid IPv4 / IPv6 address - if (!(fProxyIpValid = addrProxy.IsValid())) { - disableOkButton(); - pUiProxyIp->setValid(false); - ui->statusLabel->setStyleSheet("QLabel { color: red; }"); - ui->statusLabel->setText(tr("The supplied proxy address is invalid.")); - return; - } - // Check proxy port - if (!pUiProxyPort->hasAcceptableInput()) { - disableOkButton(); - ui->statusLabel->setStyleSheet("QLabel { color: red; }"); - ui->statusLabel->setText(tr("The supplied proxy port is invalid.")); - return; - } - - proxyType checkProxy = proxyType(addrProxy); - if (!checkProxy.IsValid()) { - disableOkButton(); - ui->statusLabel->setStyleSheet("QLabel { color: red; }"); - ui->statusLabel->setText(tr("The supplied proxy settings are invalid.")); - return; - } - - enableOkButton(); - ui->statusLabel->clear(); -} - -bool OptionsDialog::eventFilter(QObject* object, QEvent* event) -{ - if (event->type() == QEvent::FocusOut) { - if (object == ui->proxyIp || object == ui->proxyPort) { - Q_EMIT proxyIpChecks(ui->proxyIp, ui->proxyPort); - } - } - return QDialog::eventFilter(object, event); -} - -void OptionsDialog::setCurrentIndex(int index) -{ - ui->tabWidget->setCurrentIndex(index); -} diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h deleted file mode 100644 index 704ebe49f45cf..0000000000000 --- a/src/qt/optionsdialog.h +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2011-2013 The Bitcoin developers -// Copyright (c) 2017-2019 The PIVX developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BITCOIN_QT_OPTIONSDIALOG_H -#define BITCOIN_QT_OPTIONSDIALOG_H - -#include - -class OptionsModel; -class QValidatedLineEdit; -class QLineEdit; - -QT_BEGIN_NAMESPACE -class QDataWidgetMapper; -QT_END_NAMESPACE - -namespace Ui -{ -class OptionsDialog; -} - -/** Preferences dialog. */ -class OptionsDialog : public QDialog -{ - Q_OBJECT - -public: - explicit OptionsDialog(QWidget* parent, bool enableWallet); - ~OptionsDialog(); - - void setModel(OptionsModel* model); - void setMapper(); - void setCurrentIndex(int index); - -protected: - bool eventFilter(QObject* object, QEvent* event); - -private Q_SLOTS: - /* enable OK button */ - void enableOkButton(); - /* disable OK button */ - void disableOkButton(); - /* set OK button state (enabled / disabled) */ - void setOkButtonState(bool fState); - void on_resetButton_clicked(); - void on_okButton_clicked(); - void on_cancelButton_clicked(); - - void updateHideOrphans(bool fHide); - - void showRestartWarning(bool fPersistent = false); - void clearStatusLabel(); - void doProxyIpChecks(QValidatedLineEdit* pUiProxyIp, QLineEdit* pUiProxyPort); - -Q_SIGNALS: - void proxyIpChecks(QValidatedLineEdit* pUiProxyIp, QLineEdit* pUiProxyPort); - -private: - Ui::OptionsDialog* ui; - OptionsModel* model; - QDataWidgetMapper* mapper; - bool fProxyIpValid; -}; - -#endif // BITCOIN_QT_OPTIONSDIALOG_H