Skip to content

Commit 9b5d7aa

Browse files
committed
qt: update address warnings when wallet is encrypted
1 parent eeaed3f commit 9b5d7aa

File tree

12 files changed

+40
-37
lines changed

12 files changed

+40
-37
lines changed

src/interfaces/wallet.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,7 @@ class Wallet
291291
virtual std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn) = 0;
292292

293293
//! Register handler for address book changed messages.
294-
using AddressBookChangedFn = std::function<void(const CTxDestination& address,
295-
const std::string& label,
296-
bool is_mine,
297-
const std::string& purpose,
298-
ChangeType status)>;
294+
using AddressBookChangedFn = std::function<void(const CTxDestination& address, const std::string& label, bool is_mine, const std::string& purpose, ChangeType status, bool is_active)>;
299295
virtual std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn) = 0;
300296

301297
//! Register handler for transaction changed messages.

src/qt/addresstablemodel.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class AddressTablePriv
109109
std::sort(cachedAddressTable.begin(), cachedAddressTable.end(), AddressTableEntryLessThan());
110110
}
111111

112-
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
112+
void updateEntry(const QString& address, const QString& label, bool isMine, const QString& purpose, int status, bool isActive)
113113
{
114114
// Find address / label in model
115115
QList<AddressTableEntry>::iterator lower = std::lower_bound(
@@ -130,7 +130,7 @@ class AddressTablePriv
130130
break;
131131
}
132132
parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
133-
cachedAddressTable.insert(lowerIndex, AddressTableEntry(newEntryType, label, address, /*TODO:*/ false));
133+
cachedAddressTable.insert(lowerIndex, AddressTableEntry(newEntryType, label, address, isActive));
134134
parent->endInsertRows();
135135
break;
136136
case CT_UPDATED:
@@ -357,11 +357,10 @@ QModelIndex AddressTableModel::index(int row, int column, const QModelIndex &par
357357
}
358358
}
359359

360-
void AddressTableModel::updateEntry(const QString &address,
361-
const QString &label, bool isMine, const QString &purpose, int status)
360+
void AddressTableModel::updateEntry(const QString& address, const QString& label, bool isMine, const QString& purpose, int status, bool isActive)
362361
{
363362
// Update address book model from Bitcoin core
364-
priv->updateEntry(address, label, isMine, purpose, status);
363+
priv->updateEntry(address, label, isMine, purpose, status, isActive);
365364
}
366365

367366
QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type)

src/qt/addresstablemodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class AddressTableModel : public QAbstractTableModel
101101
public Q_SLOTS:
102102
/* Update address list from core.
103103
*/
104-
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status);
104+
void updateEntry(const QString& address, const QString& label, bool isMine, const QString& purpose, int status, bool isActive);
105105

106106
friend class AddressTablePriv;
107107
};

src/qt/bitcoingui.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,9 @@ void BitcoinGUI::updateWalletStatus()
14181418
WalletModel * const walletModel = walletView->getWalletModel();
14191419
setEncryptionStatus(walletModel->getEncryptionStatus());
14201420
setHDStatus(walletModel->wallet().privateKeysDisabled(), walletModel->wallet().hdEnabled());
1421+
1422+
// Refresh requests table and address book to show warnings on old unencrypted keys
1423+
walletView->refreshAddressTables();
14211424
}
14221425
#endif // ENABLE_WALLET
14231426

src/qt/signverifymessagedialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void SignVerifyMessageDialog::on_addressBookButton_SM_clicked()
9090
{
9191
if (model && model->getAddressTableModel())
9292
{
93-
model->refresh(platformStyle, /*pk_hash_only=*/true);
93+
model->RefreshAddressTableModel(platformStyle, /*pk_hash_only=*/true);
9494
AddressBookPage dlg(platformStyle, AddressBookPage::ForSelection, AddressBookPage::ReceivingTab, this);
9595
dlg.setModel(model->getAddressTableModel());
9696
if (dlg.exec())

src/qt/walletmodel.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,10 @@ void WalletModel::updateTransaction()
137137
fForceCheckBalanceChanged = true;
138138
}
139139

140-
void WalletModel::updateAddressBook(const QString &address, const QString &label,
141-
bool isMine, const QString &purpose, int status)
140+
void WalletModel::updateAddressBook(const QString& address, const QString& label, bool isMine, const QString& purpose, int status, bool isActive)
142141
{
143142
if(addressTableModel)
144-
addressTableModel->updateEntry(address, label, isMine, purpose, status);
143+
addressTableModel->updateEntry(address, label, isMine, purpose, status, isActive);
145144
}
146145

147146
void WalletModel::updateWatchOnlyFlag(bool fHaveWatchonly)
@@ -375,21 +374,14 @@ static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel)
375374
assert(invoked);
376375
}
377376

378-
static void NotifyAddressBookChanged(WalletModel *walletmodel,
379-
const CTxDestination &address, const std::string &label, bool isMine,
380-
const std::string &purpose, ChangeType status)
377+
static void NotifyAddressBookChanged(WalletModel* walletmodel, const CTxDestination& address, const std::string& label, bool isMine, const std::string& purpose, ChangeType status, bool isActive)
381378
{
382379
QString strAddress = QString::fromStdString(EncodeDestination(address));
383380
QString strLabel = QString::fromStdString(label);
384381
QString strPurpose = QString::fromStdString(purpose);
385382

386-
qDebug() << "NotifyAddressBookChanged: " + strAddress + " " + strLabel + " isMine=" + QString::number(isMine) + " purpose=" + strPurpose + " status=" + QString::number(status);
387-
bool invoked = QMetaObject::invokeMethod(walletmodel, "updateAddressBook",
388-
Q_ARG(QString, strAddress),
389-
Q_ARG(QString, strLabel),
390-
Q_ARG(bool, isMine),
391-
Q_ARG(QString, strPurpose),
392-
Q_ARG(int, status));
383+
qDebug() << "NotifyAddressBookChanged: " + strAddress + " " + strLabel + " isMine=" + QString::number(isMine) + " purpose=" + strPurpose + " status=" + QString::number(status) + " isActive=" + QString::number(isActive);
384+
bool invoked = QMetaObject::invokeMethod(walletmodel, "updateAddressBook", Q_ARG(QString, strAddress), Q_ARG(QString, strLabel), Q_ARG(bool, isMine), Q_ARG(QString, strPurpose), Q_ARG(int, status), Q_ARG(bool, isActive));
393385
assert(invoked);
394386
}
395387

@@ -428,7 +420,7 @@ void WalletModel::subscribeToCoreSignals()
428420
// Connect signals to wallet
429421
m_handler_unload = m_wallet->handleUnload(std::bind(&NotifyUnload, this));
430422
m_handler_status_changed = m_wallet->handleStatusChanged(std::bind(&NotifyKeyStoreStatusChanged, this));
431-
m_handler_address_book_changed = m_wallet->handleAddressBookChanged(std::bind(NotifyAddressBookChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5));
423+
m_handler_address_book_changed = m_wallet->handleAddressBookChanged(std::bind(NotifyAddressBookChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6));
432424
m_handler_transaction_changed = m_wallet->handleTransactionChanged(std::bind(NotifyTransactionChanged, this, std::placeholders::_1, std::placeholders::_2));
433425
m_handler_show_progress = m_wallet->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2));
434426
m_handler_watch_only_changed = m_wallet->handleWatchOnlyChanged(std::bind(NotifyWatchonlyChanged, this, std::placeholders::_1));
@@ -601,11 +593,16 @@ bool WalletModel::isMultiwallet() const
601593
return m_node.walletLoader().getWallets().size() > 1;
602594
}
603595

604-
void WalletModel::refresh(const PlatformStyle* platformStyle, bool pk_hash_only)
596+
void WalletModel::RefreshAddressTableModel(const PlatformStyle* platformStyle, bool pk_hash_only)
605597
{
606598
addressTableModel = new AddressTableModel(platformStyle, this, pk_hash_only);
607599
}
608600

601+
void WalletModel::RefreshRecentRequestsTableModel(const PlatformStyle* platformStyle)
602+
{
603+
recentRequestsTableModel = new RecentRequestsTableModel(platformStyle, this);
604+
}
605+
609606
uint256 WalletModel::getLastBlockProcessed() const
610607
{
611608
return m_client_model ? m_client_model->getBestBlockHash() : uint256{};

src/qt/walletmodel.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ class WalletModel : public QObject
149149

150150
bool isMultiwallet() const;
151151

152-
void refresh(const PlatformStyle* platformStyle, bool pk_hash_only = false);
152+
void RefreshAddressTableModel(const PlatformStyle* platformStyle, bool pk_hash_only = false);
153+
void RefreshRecentRequestsTableModel(const PlatformStyle* platformStyle);
153154

154155
uint256 getLastBlockProcessed() const;
155156

@@ -236,7 +237,7 @@ public Q_SLOTS:
236237
/* New transaction, or transaction changed status */
237238
void updateTransaction();
238239
/* New, updated or removed address book entry */
239-
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status);
240+
void updateAddressBook(const QString& address, const QString& label, bool isMine, const QString& purpose, int status, bool isActive);
240241
/* Watch-only added */
241242
void updateWatchOnlyFlag(bool fHaveWatchonly);
242243
/* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */

src/qt/walletview.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ void WalletView::showOutOfSyncWarning(bool fShow)
200200
overviewPage->showOutOfSyncWarning(fShow);
201201
}
202202

203+
void WalletView::refreshAddressTables()
204+
{
205+
walletModel->RefreshRecentRequestsTableModel(platformStyle);
206+
receiveCoinsPage->setModel(walletModel);
207+
walletModel->RefreshAddressTableModel(platformStyle);
208+
usedReceivingAddressesPage->setModel(walletModel->getAddressTableModel());
209+
}
210+
203211
void WalletView::encryptWallet()
204212
{
205213
auto dlg = new AskPassphraseDialog(AskPassphraseDialog::Encrypt, this);

src/qt/walletview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class WalletView : public QStackedWidget
4848
bool handlePaymentRequest(const SendCoinsRecipient& recipient);
4949

5050
void showOutOfSyncWarning(bool fShow);
51+
void refreshAddressTables();
5152

5253
private:
5354
ClientModel* clientModel{nullptr};

src/wallet/interfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ class WalletImpl : public Wallet
502502
{
503503
return MakeSignalHandler(m_wallet->NotifyAddressBookChanged.connect(
504504
[fn](const CTxDestination& address, const std::string& label, bool is_mine,
505-
const std::string& purpose, ChangeType status) { fn(address, label, is_mine, purpose, status); }));
505+
const std::string& purpose, ChangeType status, bool is_active) { fn(address, label, is_mine, purpose, status, is_active); }));
506506
}
507507
std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) override
508508
{

0 commit comments

Comments
 (0)