refactor: Get rid of Wallet::IsWalletFlagSet method

Replace by privateKeysDisabled method to avoid need for GUI to reference
internal wallet flags.

Also remove adjacent WalletModel canGetAddresses wrapper that serves no purpose
and make Wallet::canGetAddresses non-const so it can be implemented by IPC
classes in #10102.
This commit is contained in:
Russell Yanofsky 2017-12-05 15:57:12 -05:00
parent 5bf45fe2a9
commit 77e4b06572
8 changed files with 24 additions and 36 deletions

View File

@ -463,8 +463,8 @@ public:
} }
unsigned int getConfirmTarget() override { return m_wallet->m_confirm_target; } unsigned int getConfirmTarget() override { return m_wallet->m_confirm_target; }
bool hdEnabled() override { return m_wallet->IsHDEnabled(); } bool hdEnabled() override { return m_wallet->IsHDEnabled(); }
bool canGetAddresses() const override { return m_wallet->CanGetAddresses(); } bool canGetAddresses() override { return m_wallet->CanGetAddresses(); }
bool IsWalletFlagSet(uint64_t flag) override { return m_wallet->IsWalletFlagSet(flag); } bool privateKeysDisabled() override { return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); }
OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; } OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; }
OutputType getDefaultChangeType() override { return m_wallet->m_default_change_type; } OutputType getDefaultChangeType() override { return m_wallet->m_default_change_type; }
CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; } CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; }

View File

@ -247,10 +247,10 @@ public:
virtual bool hdEnabled() = 0; virtual bool hdEnabled() = 0;
// Return whether the wallet is blank. // Return whether the wallet is blank.
virtual bool canGetAddresses() const = 0; virtual bool canGetAddresses() = 0;
// check if a certain wallet flag is set. // Return whether private keys enabled.
virtual bool IsWalletFlagSet(uint64_t flag) = 0; virtual bool privateKeysDisabled() = 0;
// Get default address type. // Get default address type.
virtual OutputType getDefaultAddressType() = 0; virtual OutputType getDefaultAddressType() = 0;

View File

@ -1258,7 +1258,7 @@ void BitcoinGUI::updateWalletStatus()
} }
WalletModel * const walletModel = walletView->getWalletModel(); WalletModel * const walletModel = walletView->getWalletModel();
setEncryptionStatus(walletModel->getEncryptionStatus()); setEncryptionStatus(walletModel->getEncryptionStatus());
setHDStatus(walletModel->privateKeysDisabled(), walletModel->wallet().hdEnabled()); setHDStatus(walletModel->wallet().privateKeysDisabled(), walletModel->wallet().hdEnabled());
} }
#endif // ENABLE_WALLET #endif // ENABLE_WALLET

View File

@ -161,7 +161,7 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances)
{ {
int unit = walletModel->getOptionsModel()->getDisplayUnit(); int unit = walletModel->getOptionsModel()->getDisplayUnit();
m_balances = balances; m_balances = balances;
if (walletModel->privateKeysDisabled()) { if (walletModel->wallet().privateKeysDisabled()) {
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance, false, BitcoinUnits::separatorAlways)); ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance, false, BitcoinUnits::separatorAlways));
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_watch_only_balance, false, BitcoinUnits::separatorAlways)); ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_watch_only_balance, false, BitcoinUnits::separatorAlways));
ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways)); ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
@ -184,7 +184,7 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances)
// for symmetry reasons also show immature label when the watch-only one is shown // for symmetry reasons also show immature label when the watch-only one is shown
ui->labelImmature->setVisible(showImmature || showWatchOnlyImmature); ui->labelImmature->setVisible(showImmature || showWatchOnlyImmature);
ui->labelImmatureText->setVisible(showImmature || showWatchOnlyImmature); ui->labelImmatureText->setVisible(showImmature || showWatchOnlyImmature);
ui->labelWatchImmature->setVisible(!walletModel->privateKeysDisabled() && showWatchOnlyImmature); // show watch-only immature balance ui->labelWatchImmature->setVisible(!walletModel->wallet().privateKeysDisabled() && showWatchOnlyImmature); // show watch-only immature balance
} }
// show/hide watch-only labels // show/hide watch-only labels
@ -236,9 +236,9 @@ void OverviewPage::setWalletModel(WalletModel *model)
connect(model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &OverviewPage::updateDisplayUnit); connect(model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &OverviewPage::updateDisplayUnit);
updateWatchOnlyLabels(wallet.haveWatchOnly() && !model->privateKeysDisabled()); updateWatchOnlyLabels(wallet.haveWatchOnly() && !model->wallet().privateKeysDisabled());
connect(model, &WalletModel::notifyWatchonlyChanged, [this](bool showWatchOnly) { connect(model, &WalletModel::notifyWatchonlyChanged, [this](bool showWatchOnly) {
updateWatchOnlyLabels(showWatchOnly && !walletModel->privateKeysDisabled()); updateWatchOnlyLabels(showWatchOnly && !walletModel->wallet().privateKeysDisabled());
}); });
} }

View File

@ -99,11 +99,11 @@ void ReceiveCoinsDialog::setModel(WalletModel *_model)
} }
// Set the button to be enabled or disabled based on whether the wallet can give out new addresses. // Set the button to be enabled or disabled based on whether the wallet can give out new addresses.
ui->receiveButton->setEnabled(model->canGetAddresses()); ui->receiveButton->setEnabled(model->wallet().canGetAddresses());
// Enable/disable the receive button if the wallet is now able/unable to give out new addresses. // Enable/disable the receive button if the wallet is now able/unable to give out new addresses.
connect(model, &WalletModel::canGetAddressesChanged, [this] { connect(model, &WalletModel::canGetAddressesChanged, [this] {
ui->receiveButton->setEnabled(model->canGetAddresses()); ui->receiveButton->setEnabled(model->wallet().canGetAddresses());
}); });
} }
} }

View File

@ -187,7 +187,7 @@ void SendCoinsDialog::setModel(WalletModel *_model)
// set default rbf checkbox state // set default rbf checkbox state
ui->optInRBF->setCheckState(Qt::Checked); ui->optInRBF->setCheckState(Qt::Checked);
if (model->privateKeysDisabled()) { if (model->wallet().privateKeysDisabled()) {
ui->sendButton->setText(tr("Cr&eate Unsigned")); ui->sendButton->setText(tr("Cr&eate Unsigned"));
ui->sendButton->setToolTip(tr("Creates a Partially Signed Bitcoin Transaction (PSBT) for use with e.g. an offline %1 wallet, or a PSBT-compatible hardware wallet.").arg(PACKAGE_NAME)); ui->sendButton->setToolTip(tr("Creates a Partially Signed Bitcoin Transaction (PSBT) for use with e.g. an offline %1 wallet, or a PSBT-compatible hardware wallet.").arg(PACKAGE_NAME));
} }
@ -312,14 +312,14 @@ void SendCoinsDialog::on_sendButton_clicked()
} }
QString questionString; QString questionString;
if (model->privateKeysDisabled()) { if (model->wallet().privateKeysDisabled()) {
questionString.append(tr("Do you want to draft this transaction?")); questionString.append(tr("Do you want to draft this transaction?"));
} else { } else {
questionString.append(tr("Are you sure you want to send?")); questionString.append(tr("Are you sure you want to send?"));
} }
questionString.append("<br /><span style='font-size:10pt;'>"); questionString.append("<br /><span style='font-size:10pt;'>");
if (model->privateKeysDisabled()) { if (model->wallet().privateKeysDisabled()) {
questionString.append(tr("Please, review your transaction proposal. This will produce a Partially Signed Bitcoin Transaction (PSBT) which you can copy and then sign with e.g. an offline %1 wallet, or a PSBT-compatible hardware wallet.").arg(PACKAGE_NAME)); questionString.append(tr("Please, review your transaction proposal. This will produce a Partially Signed Bitcoin Transaction (PSBT) which you can copy and then sign with e.g. an offline %1 wallet, or a PSBT-compatible hardware wallet.").arg(PACKAGE_NAME));
} else { } else {
questionString.append(tr("Please, review your transaction.")); questionString.append(tr("Please, review your transaction."));
@ -374,8 +374,8 @@ void SendCoinsDialog::on_sendButton_clicked()
} else { } else {
questionString = questionString.arg("<br /><br />" + formatted.at(0)); questionString = questionString.arg("<br /><br />" + formatted.at(0));
} }
const QString confirmation = model->privateKeysDisabled() ? tr("Confirm transaction proposal") : tr("Confirm send coins"); const QString confirmation = model->wallet().privateKeysDisabled() ? tr("Confirm transaction proposal") : tr("Confirm send coins");
const QString confirmButtonText = model->privateKeysDisabled() ? tr("Copy PSBT to clipboard") : tr("Send"); const QString confirmButtonText = model->wallet().privateKeysDisabled() ? tr("Copy PSBT to clipboard") : tr("Send");
SendConfirmationDialog confirmationDialog(confirmation, questionString, informative_text, detailed_text, SEND_CONFIRM_DELAY, confirmButtonText, this); SendConfirmationDialog confirmationDialog(confirmation, questionString, informative_text, detailed_text, SEND_CONFIRM_DELAY, confirmButtonText, this);
confirmationDialog.exec(); confirmationDialog.exec();
QMessageBox::StandardButton retval = static_cast<QMessageBox::StandardButton>(confirmationDialog.result()); QMessageBox::StandardButton retval = static_cast<QMessageBox::StandardButton>(confirmationDialog.result());
@ -387,7 +387,7 @@ void SendCoinsDialog::on_sendButton_clicked()
} }
bool send_failure = false; bool send_failure = false;
if (model->privateKeysDisabled()) { if (model->wallet().privateKeysDisabled()) {
CMutableTransaction mtx = CMutableTransaction{*(currentTransaction.getWtx())}; CMutableTransaction mtx = CMutableTransaction{*(currentTransaction.getWtx())};
PartiallySignedTransaction psbtx(mtx); PartiallySignedTransaction psbtx(mtx);
bool complete = false; bool complete = false;
@ -562,7 +562,7 @@ void SendCoinsDialog::setBalance(const interfaces::WalletBalances& balances)
if(model && model->getOptionsModel()) if(model && model->getOptionsModel())
{ {
CAmount balance = balances.balance; CAmount balance = balances.balance;
if (model->privateKeysDisabled()) { if (model->wallet().privateKeysDisabled()) {
balance = balances.watch_only_balance; balance = balances.watch_only_balance;
ui->labelBalanceName->setText(tr("Watch-only balance:")); ui->labelBalanceName->setText(tr("Watch-only balance:"));
} }
@ -652,7 +652,7 @@ void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry)
} }
// Include watch-only for wallets without private key // Include watch-only for wallets without private key
coin_control.fAllowWatchOnly = model->privateKeysDisabled(); coin_control.fAllowWatchOnly = model->wallet().privateKeysDisabled();
// Calculate available amount to send. // Calculate available amount to send.
CAmount amount = model->wallet().getAvailableBalance(coin_control); CAmount amount = model->wallet().getAvailableBalance(coin_control);
@ -707,7 +707,7 @@ void SendCoinsDialog::updateCoinControlState(CCoinControl& ctrl)
ctrl.m_confirm_target = getConfTargetForIndex(ui->confTargetSelector->currentIndex()); ctrl.m_confirm_target = getConfTargetForIndex(ui->confTargetSelector->currentIndex());
ctrl.m_signal_bip125_rbf = ui->optInRBF->isChecked(); ctrl.m_signal_bip125_rbf = ui->optInRBF->isChecked();
// Include watch-only for wallets without private key // Include watch-only for wallets without private key
ctrl.fAllowWatchOnly = model->privateKeysDisabled(); ctrl.fAllowWatchOnly = model->wallet().privateKeysDisabled();
} }
void SendCoinsDialog::updateSmartFeeLabel() void SendCoinsDialog::updateSmartFeeLabel()

View File

@ -23,7 +23,7 @@
#include <ui_interface.h> #include <ui_interface.h>
#include <util/system.h> // for GetBoolArg #include <util/system.h> // for GetBoolArg
#include <wallet/coincontrol.h> #include <wallet/coincontrol.h>
#include <wallet/wallet.h> #include <wallet/wallet.h> // for CRecipient
#include <stdint.h> #include <stdint.h>
@ -184,7 +184,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
std::string strFailReason; std::string strFailReason;
auto& newTx = transaction.getWtx(); auto& newTx = transaction.getWtx();
newTx = m_wallet->createTransaction(vecSend, coinControl, !privateKeysDisabled() /* sign */, nChangePosRet, nFeeRequired, strFailReason); newTx = m_wallet->createTransaction(vecSend, coinControl, !wallet().privateKeysDisabled() /* sign */, nChangePosRet, nFeeRequired, strFailReason);
transaction.setTransactionFee(nFeeRequired); transaction.setTransactionFee(nFeeRequired);
if (fSubtractFeeFromAmount && newTx) if (fSubtractFeeFromAmount && newTx)
transaction.reassignAmounts(nChangePosRet); transaction.reassignAmounts(nChangePosRet);
@ -488,7 +488,7 @@ bool WalletModel::bumpFee(uint256 hash, uint256& new_hash)
return false; return false;
} }
const bool create_psbt = privateKeysDisabled(); const bool create_psbt = m_wallet->privateKeysDisabled();
// allow a user based fee verification // allow a user based fee verification
QString questionString = create_psbt ? tr("Do you want to draft a transaction with fee increase?") : tr("Do you want to increase the fee?"); QString questionString = create_psbt ? tr("Do you want to draft a transaction with fee increase?") : tr("Do you want to increase the fee?");
@ -558,16 +558,6 @@ bool WalletModel::isWalletEnabled()
return !gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET); return !gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET);
} }
bool WalletModel::privateKeysDisabled() const
{
return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
}
bool WalletModel::canGetAddresses() const
{
return m_wallet->canGetAddresses();
}
QString WalletModel::getWalletName() const QString WalletModel::getWalletName() const
{ {
return QString::fromStdString(m_wallet->getWalletName()); return QString::fromStdString(m_wallet->getWalletName());

View File

@ -140,8 +140,6 @@ public:
bool bumpFee(uint256 hash, uint256& new_hash); bool bumpFee(uint256 hash, uint256& new_hash);
static bool isWalletEnabled(); static bool isWalletEnabled();
bool privateKeysDisabled() const;
bool canGetAddresses() const;
interfaces::Node& node() const { return m_node; } interfaces::Node& node() const { return m_node; }
interfaces::Wallet& wallet() const { return *m_wallet; } interfaces::Wallet& wallet() const { return *m_wallet; }