Skip to content

Commit 8436547

Browse files
committed
Follow Bitcoin PRs:
- gui: Avoid Wallet::GetBalance in WalletModel::pollBalanceChanged bitcoin#18160 - gui: Drop PeerTableModel dependency to ClientModel bitcoin#18060 - gui: Break trivial circular dependencies bitcoin#18036 - gui: Improve "Hide" button tool-tip message bitcoin#17360 - gui: Shortcut to close ModalOverlay bitcoin#17998 - gui: Remove warning "unused variable 'wallet_model'" bitcoin#17939 - refactor: Use PACKAGE_NAME in GUI modal overlay and bitcoin-wallet bitcoin#17923 - gui: remove OpenSSL PRNG seeding (Windows, Qt only) bitcoin#17151 - refactor: Remove unused defines in qt/bitcoinunits.h bitcoin#17869
1 parent 2018e96 commit 8436547

17 files changed

+40
-81
lines changed

src/bitcoin-wallet.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ static bool WalletAppInit(int argc, char* argv[])
4343
}
4444
if (argc < 2 || HelpRequested(gArgs)) {
4545
std::string usage = strprintf("%s litecoinz-wallet version", PACKAGE_NAME) + " " + FormatFullVersion() + "\n\n" +
46-
"wallet-tool is an offline tool for creating and interacting with LitecoinZ Core wallet files.\n" +
47-
"By default wallet-tool will act on wallets in the default mainnet wallet directory in the datadir.\n" +
46+
"litecoinz-bitcoin-wallet is an offline tool for creating and interacting with " PACKAGE_NAME " wallet files.\n" +
47+
"By default litecoinz-wallet will act on wallets in the default mainnet wallet directory in the datadir.\n" +
4848
"To change the target wallet, use the -datadir, -wallet and -testnet/-regtest arguments.\n\n" +
4949
"Usage:\n" +
5050
" litecoinz-wallet [options] <command>\n\n" +

src/interfaces/wallet.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -502,16 +502,17 @@ class WalletImpl : public Wallet
502502

503503
return result;
504504
}
505-
bool tryGetBalances(WalletBalances& balances, int& num_blocks) override
505+
bool tryGetBalances(WalletBalances& balances, int& num_blocks, bool force, int cached_num_blocks) override
506506
{
507507
auto locked_chain = m_wallet->chain().lock(true /* try_lock */);
508508
if (!locked_chain) return false;
509+
num_blocks = locked_chain->getHeight().get_value_or(-1);
510+
if (!force && num_blocks == cached_num_blocks) return false;
509511
TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
510512
if (!locked_wallet) {
511513
return false;
512514
}
513515
balances = getBalances();
514-
num_blocks = locked_chain->getHeight().get_value_or(-1);
515516
return true;
516517
}
517518
CAmount getBalance() override { return m_wallet->GetBalance().m_mine_trusted; }

src/interfaces/wallet.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,11 @@ class Wallet
230230
//! Get shielded balance.
231231
virtual CAmount getShieldedBalance() = 0;
232232

233-
//! Get balances if possible without blocking.
234-
virtual bool tryGetBalances(WalletBalances& balances, int& num_blocks) = 0;
233+
//! Get balances if possible without waiting for chain and wallet locks.
234+
virtual bool tryGetBalances(WalletBalances& balances,
235+
int& num_blocks,
236+
bool force,
237+
int cached_num_blocks) = 0;
235238

236239
//! Get balance.
237240
virtual CAmount getBalance() = 0;

src/qt/bantablemodel.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
#include <qt/bantablemodel.h>
66

7-
#include <qt/clientmodel.h>
8-
97
#include <interfaces/node.h>
108
#include <sync.h>
119
#include <util/time.h>
1210

1311
#include <utility>
1412

15-
#include <QDebug>
13+
#include <QDateTime>
1614
#include <QList>
15+
#include <QModelIndex>
16+
#include <QVariant>
1717

1818
bool BannedNodeLessThan::operator()(const CCombinedBan& left, const CCombinedBan& right) const
1919
{
@@ -80,10 +80,9 @@ class BanTablePriv
8080
}
8181
};
8282

83-
BanTableModel::BanTableModel(interfaces::Node& node, ClientModel *parent) :
83+
BanTableModel::BanTableModel(interfaces::Node& node, QObject* parent) :
8484
QAbstractTableModel(parent),
85-
m_node(node),
86-
clientModel(parent)
85+
m_node(node)
8786
{
8887
columns << tr("IP/Netmask") << tr("Banned Until");
8988
priv.reset(new BanTablePriv());

src/qt/bantablemodel.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <QAbstractTableModel>
1313
#include <QStringList>
1414

15-
class ClientModel;
1615
class BanTablePriv;
1716

1817
namespace interfaces {
@@ -45,7 +44,7 @@ class BanTableModel : public QAbstractTableModel
4544
Q_OBJECT
4645

4746
public:
48-
explicit BanTableModel(interfaces::Node& node, ClientModel *parent = nullptr);
47+
explicit BanTableModel(interfaces::Node& node, QObject* parent);
4948
~BanTableModel();
5049
void startAutoRefresh();
5150
void stopAutoRefresh();
@@ -72,7 +71,6 @@ public Q_SLOTS:
7271

7372
private:
7473
interfaces::Node& m_node;
75-
ClientModel *clientModel;
7674
QStringList columns;
7775
std::unique_ptr<BanTablePriv> priv;
7876
};

src/qt/bitcoinunits.h

-19
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,6 @@
1313
// U+2009 THIN SPACE = UTF-8 E2 80 89
1414
#define REAL_THIN_SP_CP 0x2009
1515
#define REAL_THIN_SP_UTF8 "\xE2\x80\x89"
16-
#define REAL_THIN_SP_HTML "&thinsp;"
17-
18-
// U+200A HAIR SPACE = UTF-8 E2 80 8A
19-
#define HAIR_SP_CP 0x200A
20-
#define HAIR_SP_UTF8 "\xE2\x80\x8A"
21-
#define HAIR_SP_HTML "&#8202;"
22-
23-
// U+2006 SIX-PER-EM SPACE = UTF-8 E2 80 86
24-
#define SIXPEREM_SP_CP 0x2006
25-
#define SIXPEREM_SP_UTF8 "\xE2\x80\x86"
26-
#define SIXPEREM_SP_HTML "&#8198;"
27-
28-
// U+2007 FIGURE SPACE = UTF-8 E2 80 87
29-
#define FIGURE_SP_CP 0x2007
30-
#define FIGURE_SP_UTF8 "\xE2\x80\x87"
31-
#define FIGURE_SP_HTML "&#8199;"
3216

3317
// QMessageBox seems to have a bug whereby it doesn't display thin/hair spaces
3418
// correctly. Workaround is to display a space in a small font. If you
@@ -116,9 +100,6 @@ class BitcoinUnits: public QAbstractListModel
116100
{
117101
text.remove(' ');
118102
text.remove(QChar(THIN_SP_CP));
119-
#if (THIN_SP_CP != REAL_THIN_SP_CP)
120-
text.remove(QChar(REAL_THIN_SP_CP));
121-
#endif
122103
return text;
123104
}
124105

src/qt/forms/modaloverlay.ui

+3
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ QLabel { color: rgb(40,40,40); }</string>
398398
<property name="text">
399399
<string>Hide</string>
400400
</property>
401+
<property name="shortcut">
402+
<string>Esc</string>
403+
</property>
401404
<property name="focusPolicy">
402405
<enum>Qt::StrongFocus</enum>
403406
</property>

src/qt/forms/sendcoinsdialog.ui

+1-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@
797797
<item>
798798
<widget class="QPushButton" name="buttonMinimizeFee">
799799
<property name="toolTip">
800-
<string>collapse fee-settings</string>
800+
<string>Hide transaction fee settings</string>
801801
</property>
802802
<property name="text">
803803
<string>Hide</string>

src/qt/modaloverlay.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ verificationPauseActive(false)
3535
setVisible(false);
3636
if (!enable_wallet) {
3737
ui->infoText->setVisible(false);
38-
ui->infoTextStrong->setText(tr("LitecoinZ Core is currently syncing. It will download headers and blocks from peers and validate them until reaching the tip of the block chain."));
38+
ui->infoTextStrong->setText(tr("%1 is currently syncing. It will download headers and blocks from peers and validate them until reaching the tip of the block chain.").arg(PACKAGE_NAME));
3939
}
4040

4141
animation.setTargetObject(this);

src/qt/peertablemodel.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <qt/peertablemodel.h>
66

7-
#include <qt/clientmodel.h>
87
#include <qt/guiconstants.h>
98
#include <qt/guiutil.h>
109

@@ -101,10 +100,9 @@ class PeerTablePriv
101100
}
102101
};
103102

104-
PeerTableModel::PeerTableModel(interfaces::Node& node, ClientModel *parent) :
103+
PeerTableModel::PeerTableModel(interfaces::Node& node, QObject* parent) :
105104
QAbstractTableModel(parent),
106105
m_node(node),
107-
clientModel(parent),
108106
timer(nullptr)
109107
{
110108
columns << tr("NodeId") << tr("Node/Service") << tr("Ping") << tr("Sent") << tr("Received") << tr("User Agent");

src/qt/peertablemodel.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <QAbstractTableModel>
1414
#include <QStringList>
1515

16-
class ClientModel;
1716
class PeerTablePriv;
1817

1918
namespace interfaces {
@@ -51,7 +50,7 @@ class PeerTableModel : public QAbstractTableModel
5150
Q_OBJECT
5251

5352
public:
54-
explicit PeerTableModel(interfaces::Node& node, ClientModel *parent = nullptr);
53+
explicit PeerTableModel(interfaces::Node& node, QObject* parent);
5554
~PeerTableModel();
5655
const CNodeCombinedStats *getNodeStats(int idx);
5756
int getRowByNodeId(NodeId nodeid);
@@ -83,7 +82,6 @@ public Q_SLOTS:
8382

8483
private:
8584
interfaces::Node& m_node;
86-
ClientModel *clientModel;
8785
QStringList columns;
8886
std::unique_ptr<PeerTablePriv> priv;
8987
QTimer *timer;

src/qt/rpcconsole.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -907,12 +907,8 @@ void RPCConsole::on_lineEdit_returnPressed()
907907

908908
cmdBeforeBrowsing = QString();
909909

910-
WalletModel* wallet_model{nullptr};
911910
#ifdef ENABLE_WALLET
912-
const int wallet_index = ui->WalletSelector->currentIndex();
913-
if (wallet_index > 0) {
914-
wallet_model = ui->WalletSelector->itemData(wallet_index).value<WalletModel*>();
915-
}
911+
WalletModel* wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();
916912

917913
if (m_last_wallet_model != wallet_model) {
918914
if (wallet_model) {

src/qt/utilitydialog.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <qt/forms/ui_helpmessagedialog.h>
1212

13-
#include <qt/bitcoingui.h>
1413
#include <qt/guiutil.h>
1514

1615
#include <clientversion.h>
@@ -22,9 +21,10 @@
2221

2322
#include <QCloseEvent>
2423
#include <QLabel>
24+
#include <QMainWindow>
2525
#include <QRegExp>
26-
#include <QTextTable>
2726
#include <QTextCursor>
27+
#include <QTextTable>
2828
#include <QVBoxLayout>
2929

3030
/** "Help message" or "About" dialog box */
@@ -149,10 +149,9 @@ ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
149149
GUIUtil::handleCloseWindowShortcut(this);
150150
}
151151

152-
QWidget *ShutdownWindow::showShutdownWindow(BitcoinGUI *window)
152+
QWidget* ShutdownWindow::showShutdownWindow(QMainWindow* window)
153153
{
154-
if (!window)
155-
return nullptr;
154+
assert(window != nullptr);
156155

157156
// Show a simple window indicating shutdown status
158157
QWidget *shutdownWindow = new ShutdownWindow();

src/qt/utilitydialog.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
#define BITCOIN_QT_UTILITYDIALOG_H
77

88
#include <QDialog>
9-
#include <QObject>
9+
#include <QWidget>
1010

11-
class BitcoinGUI;
11+
QT_BEGIN_NAMESPACE
12+
class QMainWindow;
13+
QT_END_NAMESPACE
1214

1315
namespace interfaces {
1416
class Node;
@@ -46,7 +48,7 @@ class ShutdownWindow : public QWidget
4648

4749
public:
4850
explicit ShutdownWindow(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::Widget);
49-
static QWidget *showShutdownWindow(BitcoinGUI *window);
51+
static QWidget* showShutdownWindow(QMainWindow* window);
5052

5153
protected:
5254
void closeEvent(QCloseEvent *event);

src/qt/walletmodel.cpp

+7-10
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,18 @@ void WalletModel::pollBalanceChanged()
7878
// rescan.
7979
interfaces::WalletBalances new_balances;
8080
int numBlocks = -1;
81-
if (!m_wallet->tryGetBalances(new_balances, numBlocks)) {
81+
if (!m_wallet->tryGetBalances(new_balances, numBlocks, fForceCheckBalanceChanged, cachedNumBlocks)) {
8282
return;
8383
}
8484

85-
if(fForceCheckBalanceChanged || numBlocks != cachedNumBlocks)
86-
{
87-
fForceCheckBalanceChanged = false;
85+
fForceCheckBalanceChanged = false;
8886

89-
// Balance and number of transactions might have changed
90-
cachedNumBlocks = numBlocks;
87+
// Balance and number of transactions might have changed
88+
cachedNumBlocks = numBlocks;
9189

92-
checkBalanceChanged(new_balances);
93-
if(transactionTableModel)
94-
transactionTableModel->updateConfirmations();
95-
}
90+
checkBalanceChanged(new_balances);
91+
if(transactionTableModel)
92+
transactionTableModel->updateConfirmations();
9693
}
9794

9895
void WalletModel::checkBalanceChanged(const interfaces::WalletBalances& new_balances)

src/qt/winshutdownmonitor.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66

77
#if defined(Q_OS_WIN)
88
#include <shutdown.h>
9-
#include <util/system.h>
109

1110
#include <windows.h>
1211

1312
#include <QDebug>
1413

15-
#include <openssl/rand.h>
16-
1714
// If we don't want a message to be processed by Qt, return true and set result to
1815
// the value that the window procedure should return. Otherwise return false.
1916
bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pnResult)
@@ -22,16 +19,6 @@ bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType, void *pM
2219

2320
MSG *pMsg = static_cast<MSG *>(pMessage);
2421

25-
// Seed OpenSSL PRNG with Windows event data (e.g. mouse movements and other user interactions)
26-
if (RAND_event(pMsg->message, pMsg->wParam, pMsg->lParam) == 0) {
27-
// Warn only once as this is performance-critical
28-
static bool warned = false;
29-
if (!warned) {
30-
LogPrintf("%s: OpenSSL RAND_event() failed to seed OpenSSL PRNG with enough data.\n", __func__);
31-
warned = true;
32-
}
33-
}
34-
3522
switch(pMsg->message)
3623
{
3724
case WM_QUERYENDSESSION:

test/lint/lint-circular-dependencies.sh

-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
1313
"index/txindex -> validation -> index/txindex"
1414
"policy/fees -> txmempool -> policy/fees"
1515
"qt/addresstablemodel -> qt/walletmodel -> qt/addresstablemodel"
16-
"qt/bantablemodel -> qt/clientmodel -> qt/bantablemodel"
17-
"qt/bitcoingui -> qt/utilitydialog -> qt/bitcoingui"
1816
"qt/bitcoingui -> qt/walletframe -> qt/bitcoingui"
19-
"qt/clientmodel -> qt/peertablemodel -> qt/clientmodel"
2017
"qt/recentrequeststablemodel -> qt/walletmodel -> qt/recentrequeststablemodel"
2118
"qt/sendcoinsdialog -> qt/walletmodel -> qt/sendcoinsdialog"
2219
"qt/transactiontablemodel -> qt/walletmodel -> qt/transactiontablemodel"

0 commit comments

Comments
 (0)