Skip to content

Commit 77e4b06

Browse files
committed
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.
1 parent 5bf45fe commit 77e4b06

File tree

8 files changed

+24
-36
lines changed

8 files changed

+24
-36
lines changed

src/interfaces/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ class WalletImpl : public Wallet
463463
}
464464
unsigned int getConfirmTarget() override { return m_wallet->m_confirm_target; }
465465
bool hdEnabled() override { return m_wallet->IsHDEnabled(); }
466-
bool canGetAddresses() const override { return m_wallet->CanGetAddresses(); }
467-
bool IsWalletFlagSet(uint64_t flag) override { return m_wallet->IsWalletFlagSet(flag); }
466+
bool canGetAddresses() override { return m_wallet->CanGetAddresses(); }
467+
bool privateKeysDisabled() override { return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); }
468468
OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; }
469469
OutputType getDefaultChangeType() override { return m_wallet->m_default_change_type; }
470470
CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; }

src/interfaces/wallet.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@ class Wallet
247247
virtual bool hdEnabled() = 0;
248248

249249
// Return whether the wallet is blank.
250-
virtual bool canGetAddresses() const = 0;
250+
virtual bool canGetAddresses() = 0;
251251

252-
// check if a certain wallet flag is set.
253-
virtual bool IsWalletFlagSet(uint64_t flag) = 0;
252+
// Return whether private keys enabled.
253+
virtual bool privateKeysDisabled() = 0;
254254

255255
// Get default address type.
256256
virtual OutputType getDefaultAddressType() = 0;

src/qt/bitcoingui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ void BitcoinGUI::updateWalletStatus()
12581258
}
12591259
WalletModel * const walletModel = walletView->getWalletModel();
12601260
setEncryptionStatus(walletModel->getEncryptionStatus());
1261-
setHDStatus(walletModel->privateKeysDisabled(), walletModel->wallet().hdEnabled());
1261+
setHDStatus(walletModel->wallet().privateKeysDisabled(), walletModel->wallet().hdEnabled());
12621262
}
12631263
#endif // ENABLE_WALLET
12641264

src/qt/overviewpage.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances)
161161
{
162162
int unit = walletModel->getOptionsModel()->getDisplayUnit();
163163
m_balances = balances;
164-
if (walletModel->privateKeysDisabled()) {
164+
if (walletModel->wallet().privateKeysDisabled()) {
165165
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance, false, BitcoinUnits::separatorAlways));
166166
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_watch_only_balance, false, BitcoinUnits::separatorAlways));
167167
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)
184184
// for symmetry reasons also show immature label when the watch-only one is shown
185185
ui->labelImmature->setVisible(showImmature || showWatchOnlyImmature);
186186
ui->labelImmatureText->setVisible(showImmature || showWatchOnlyImmature);
187-
ui->labelWatchImmature->setVisible(!walletModel->privateKeysDisabled() && showWatchOnlyImmature); // show watch-only immature balance
187+
ui->labelWatchImmature->setVisible(!walletModel->wallet().privateKeysDisabled() && showWatchOnlyImmature); // show watch-only immature balance
188188
}
189189

190190
// show/hide watch-only labels
@@ -236,9 +236,9 @@ void OverviewPage::setWalletModel(WalletModel *model)
236236

237237
connect(model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &OverviewPage::updateDisplayUnit);
238238

239-
updateWatchOnlyLabels(wallet.haveWatchOnly() && !model->privateKeysDisabled());
239+
updateWatchOnlyLabels(wallet.haveWatchOnly() && !model->wallet().privateKeysDisabled());
240240
connect(model, &WalletModel::notifyWatchonlyChanged, [this](bool showWatchOnly) {
241-
updateWatchOnlyLabels(showWatchOnly && !walletModel->privateKeysDisabled());
241+
updateWatchOnlyLabels(showWatchOnly && !walletModel->wallet().privateKeysDisabled());
242242
});
243243
}
244244

src/qt/receivecoinsdialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ void ReceiveCoinsDialog::setModel(WalletModel *_model)
9999
}
100100

101101
// Set the button to be enabled or disabled based on whether the wallet can give out new addresses.
102-
ui->receiveButton->setEnabled(model->canGetAddresses());
102+
ui->receiveButton->setEnabled(model->wallet().canGetAddresses());
103103

104104
// Enable/disable the receive button if the wallet is now able/unable to give out new addresses.
105105
connect(model, &WalletModel::canGetAddressesChanged, [this] {
106-
ui->receiveButton->setEnabled(model->canGetAddresses());
106+
ui->receiveButton->setEnabled(model->wallet().canGetAddresses());
107107
});
108108
}
109109
}

src/qt/sendcoinsdialog.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void SendCoinsDialog::setModel(WalletModel *_model)
187187
// set default rbf checkbox state
188188
ui->optInRBF->setCheckState(Qt::Checked);
189189

190-
if (model->privateKeysDisabled()) {
190+
if (model->wallet().privateKeysDisabled()) {
191191
ui->sendButton->setText(tr("Cr&eate Unsigned"));
192192
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));
193193
}
@@ -312,14 +312,14 @@ void SendCoinsDialog::on_sendButton_clicked()
312312
}
313313

314314
QString questionString;
315-
if (model->privateKeysDisabled()) {
315+
if (model->wallet().privateKeysDisabled()) {
316316
questionString.append(tr("Do you want to draft this transaction?"));
317317
} else {
318318
questionString.append(tr("Are you sure you want to send?"));
319319
}
320320

321321
questionString.append("<br /><span style='font-size:10pt;'>");
322-
if (model->privateKeysDisabled()) {
322+
if (model->wallet().privateKeysDisabled()) {
323323
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));
324324
} else {
325325
questionString.append(tr("Please, review your transaction."));
@@ -374,8 +374,8 @@ void SendCoinsDialog::on_sendButton_clicked()
374374
} else {
375375
questionString = questionString.arg("<br /><br />" + formatted.at(0));
376376
}
377-
const QString confirmation = model->privateKeysDisabled() ? tr("Confirm transaction proposal") : tr("Confirm send coins");
378-
const QString confirmButtonText = model->privateKeysDisabled() ? tr("Copy PSBT to clipboard") : tr("Send");
377+
const QString confirmation = model->wallet().privateKeysDisabled() ? tr("Confirm transaction proposal") : tr("Confirm send coins");
378+
const QString confirmButtonText = model->wallet().privateKeysDisabled() ? tr("Copy PSBT to clipboard") : tr("Send");
379379
SendConfirmationDialog confirmationDialog(confirmation, questionString, informative_text, detailed_text, SEND_CONFIRM_DELAY, confirmButtonText, this);
380380
confirmationDialog.exec();
381381
QMessageBox::StandardButton retval = static_cast<QMessageBox::StandardButton>(confirmationDialog.result());
@@ -387,7 +387,7 @@ void SendCoinsDialog::on_sendButton_clicked()
387387
}
388388

389389
bool send_failure = false;
390-
if (model->privateKeysDisabled()) {
390+
if (model->wallet().privateKeysDisabled()) {
391391
CMutableTransaction mtx = CMutableTransaction{*(currentTransaction.getWtx())};
392392
PartiallySignedTransaction psbtx(mtx);
393393
bool complete = false;
@@ -562,7 +562,7 @@ void SendCoinsDialog::setBalance(const interfaces::WalletBalances& balances)
562562
if(model && model->getOptionsModel())
563563
{
564564
CAmount balance = balances.balance;
565-
if (model->privateKeysDisabled()) {
565+
if (model->wallet().privateKeysDisabled()) {
566566
balance = balances.watch_only_balance;
567567
ui->labelBalanceName->setText(tr("Watch-only balance:"));
568568
}
@@ -652,7 +652,7 @@ void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry)
652652
}
653653

654654
// Include watch-only for wallets without private key
655-
coin_control.fAllowWatchOnly = model->privateKeysDisabled();
655+
coin_control.fAllowWatchOnly = model->wallet().privateKeysDisabled();
656656

657657
// Calculate available amount to send.
658658
CAmount amount = model->wallet().getAvailableBalance(coin_control);
@@ -707,7 +707,7 @@ void SendCoinsDialog::updateCoinControlState(CCoinControl& ctrl)
707707
ctrl.m_confirm_target = getConfTargetForIndex(ui->confTargetSelector->currentIndex());
708708
ctrl.m_signal_bip125_rbf = ui->optInRBF->isChecked();
709709
// Include watch-only for wallets without private key
710-
ctrl.fAllowWatchOnly = model->privateKeysDisabled();
710+
ctrl.fAllowWatchOnly = model->wallet().privateKeysDisabled();
711711
}
712712

713713
void SendCoinsDialog::updateSmartFeeLabel()

src/qt/walletmodel.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <ui_interface.h>
2424
#include <util/system.h> // for GetBoolArg
2525
#include <wallet/coincontrol.h>
26-
#include <wallet/wallet.h>
26+
#include <wallet/wallet.h> // for CRecipient
2727

2828
#include <stdint.h>
2929

@@ -184,7 +184,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
184184
std::string strFailReason;
185185

186186
auto& newTx = transaction.getWtx();
187-
newTx = m_wallet->createTransaction(vecSend, coinControl, !privateKeysDisabled() /* sign */, nChangePosRet, nFeeRequired, strFailReason);
187+
newTx = m_wallet->createTransaction(vecSend, coinControl, !wallet().privateKeysDisabled() /* sign */, nChangePosRet, nFeeRequired, strFailReason);
188188
transaction.setTransactionFee(nFeeRequired);
189189
if (fSubtractFeeFromAmount && newTx)
190190
transaction.reassignAmounts(nChangePosRet);
@@ -488,7 +488,7 @@ bool WalletModel::bumpFee(uint256 hash, uint256& new_hash)
488488
return false;
489489
}
490490

491-
const bool create_psbt = privateKeysDisabled();
491+
const bool create_psbt = m_wallet->privateKeysDisabled();
492492

493493
// allow a user based fee verification
494494
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()
558558
return !gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET);
559559
}
560560

561-
bool WalletModel::privateKeysDisabled() const
562-
{
563-
return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
564-
}
565-
566-
bool WalletModel::canGetAddresses() const
567-
{
568-
return m_wallet->canGetAddresses();
569-
}
570-
571561
QString WalletModel::getWalletName() const
572562
{
573563
return QString::fromStdString(m_wallet->getWalletName());

src/qt/walletmodel.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ class WalletModel : public QObject
140140
bool bumpFee(uint256 hash, uint256& new_hash);
141141

142142
static bool isWalletEnabled();
143-
bool privateKeysDisabled() const;
144-
bool canGetAddresses() const;
145143

146144
interfaces::Node& node() const { return m_node; }
147145
interfaces::Wallet& wallet() const { return *m_wallet; }

0 commit comments

Comments
 (0)