Skip to content

Commit b3214ce

Browse files
committed
qt, refactor: Convert uint256 to Txid in the GUI
Switch all instances of a transaction from a uint256 to the Txid type.
1 parent efac285 commit b3214ce

11 files changed

+33
-24
lines changed

src/interfaces/wallet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <support/allocators/secure.h>
1515
#include <util/fs.h>
1616
#include <util/result.h>
17+
#include <util/transaction_identifier.h>
1718
#include <util/ui_change_type.h>
1819

1920
#include <cstdint>
@@ -300,7 +301,7 @@ class Wallet
300301
virtual std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn) = 0;
301302

302303
//! Register handler for transaction changed messages.
303-
using TransactionChangedFn = std::function<void(const uint256& txid, ChangeType status)>;
304+
using TransactionChangedFn = std::function<void(const Txid& txid, ChangeType status)>;
304305
virtual std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) = 0;
305306

306307
//! Register handler for watchonly changed messages.

src/qt/sendcoinsdialog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <qt/clientmodel.h>
99
#include <qt/walletmodel.h>
10+
#include <util/transaction_identifier.h>
1011

1112
#include <QDialog>
1213
#include <QMessageBox>
@@ -61,7 +62,7 @@ public Q_SLOTS:
6162
void setBalance(const interfaces::WalletBalances& balances);
6263

6364
Q_SIGNALS:
64-
void coinsSent(const uint256& txid);
65+
void coinsSent(const Txid& txid);
6566

6667
private:
6768
Ui::SendCoinsDialog *ui;

src/qt/transactionrecord.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
3737
CAmount nCredit = wtx.credit;
3838
CAmount nDebit = wtx.debit;
3939
CAmount nNet = nCredit - nDebit;
40-
uint256 hash = wtx.tx->GetHash();
40+
Txid hash = wtx.tx->GetHash();
4141
std::map<std::string, std::string> mapValue = wtx.value_map;
4242

4343
bool involvesWatchAddress = false;

src/qt/transactionrecord.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <consensus/amount.h>
99
#include <uint256.h>
10+
#include <util/transaction_identifier.h>
1011

1112
#include <QList>
1213
#include <QString>
@@ -79,13 +80,13 @@ class TransactionRecord
7980
{
8081
}
8182

82-
TransactionRecord(uint256 _hash, qint64 _time):
83+
TransactionRecord(Txid _hash, qint64 _time):
8384
hash(_hash), time(_time), type(Other), debit(0),
8485
credit(0), idx(0)
8586
{
8687
}
8788

88-
TransactionRecord(uint256 _hash, qint64 _time,
89+
TransactionRecord(Txid _hash, qint64 _time,
8990
Type _type, const std::string &_address,
9091
const CAmount& _debit, const CAmount& _credit):
9192
hash(_hash), time(_time), type(_type), address(_address), debit(_debit), credit(_credit),
@@ -100,7 +101,7 @@ class TransactionRecord
100101

101102
/** @name Immutable transaction attributes
102103
@{*/
103-
uint256 hash;
104+
Txid hash;
104105
qint64 time;
105106
Type type;
106107
std::string address;

src/qt/transactiontablemodel.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ struct TxLessThan
4949
{
5050
return a.hash < b.hash;
5151
}
52-
bool operator()(const TransactionRecord &a, const uint256 &b) const
52+
bool operator()(const TransactionRecord &a, const Txid &b) const
5353
{
5454
return a.hash < b;
5555
}
56-
bool operator()(const uint256 &a, const TransactionRecord &b) const
56+
bool operator()(const Txid &a, const TransactionRecord &b) const
5757
{
5858
return a < b.hash;
5959
}
@@ -64,7 +64,7 @@ struct TransactionNotification
6464
{
6565
public:
6666
TransactionNotification() = default;
67-
TransactionNotification(uint256 _hash, ChangeType _status, bool _showTransaction):
67+
TransactionNotification(Txid _hash, ChangeType _status, bool _showTransaction):
6868
hash(_hash), status(_status), showTransaction(_showTransaction) {}
6969

7070
void invoke(QObject *ttm)
@@ -78,7 +78,7 @@ struct TransactionNotification
7878
assert(invoked);
7979
}
8080
private:
81-
uint256 hash;
81+
Txid hash;
8282
ChangeType status;
8383
bool showTransaction;
8484
};
@@ -103,7 +103,7 @@ class TransactionTablePriv
103103
bool m_loading = false;
104104
std::vector< TransactionNotification > vQueueNotifications;
105105

106-
void NotifyTransactionChanged(const uint256 &hash, ChangeType status);
106+
void NotifyTransactionChanged(const Txid& hash, ChangeType status);
107107
void DispatchNotifications();
108108

109109
/* Query entire wallet anew from core.
@@ -127,7 +127,7 @@ class TransactionTablePriv
127127
128128
Call with transaction that was added, removed or changed.
129129
*/
130-
void updateWallet(interfaces::Wallet& wallet, const uint256 &hash, int status, bool showTransaction)
130+
void updateWallet(interfaces::Wallet& wallet, const Txid& hash, int status, bool showTransaction)
131131
{
132132
qDebug() << "TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.ToString()) + " " + QString::number(status);
133133

@@ -699,7 +699,7 @@ void TransactionTableModel::updateDisplayUnit()
699699
Q_EMIT dataChanged(index(0, Amount), index(priv->size()-1, Amount));
700700
}
701701

702-
void TransactionTablePriv::NotifyTransactionChanged(const uint256 &hash, ChangeType status)
702+
void TransactionTablePriv::NotifyTransactionChanged(const Txid& hash, ChangeType status)
703703
{
704704
// Find transaction in wallet
705705
// Determine whether to show transaction or not (determine this here so that no relocking is needed in GUI thread)

src/qt/transactionview.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
193193
// Double-clicking on a transaction on the transaction history page shows details
194194
connect(this, &TransactionView::doubleClicked, this, &TransactionView::showDetails);
195195
// Highlight transaction after fee bump
196-
connect(this, &TransactionView::bumpedFee, [this](const uint256& txid) {
196+
connect(this, &TransactionView::bumpedFee, [this](const Txid& txid) {
197197
focusTransaction(txid);
198198
});
199199
}
@@ -434,7 +434,7 @@ void TransactionView::bumpFee([[maybe_unused]] bool checked)
434434
Txid hash = Txid::FromHex(hashQStr.toStdString()).value();
435435

436436
// Bump tx fee over the walletModel
437-
uint256 newHash;
437+
Txid newHash;
438438
if (model->bumpFee(hash, newHash)) {
439439
// Update the table
440440
transactionView->selectionModel()->clearSelection();
@@ -602,7 +602,7 @@ void TransactionView::focusTransaction(const QModelIndex &idx)
602602
transactionView->setFocus();
603603
}
604604

605-
void TransactionView::focusTransaction(const uint256& txid)
605+
void TransactionView::focusTransaction(const Txid& txid)
606606
{
607607
if (!transactionProxyModel)
608608
return;

src/qt/transactionview.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <qt/guiutil.h>
99

1010
#include <uint256.h>
11+
#include <util/transaction_identifier.h>
1112

1213
#include <QWidget>
1314
#include <QKeyEvent>
@@ -115,7 +116,7 @@ private Q_SLOTS:
115116
/** Fired when a message should be reported to the user */
116117
void message(const QString &title, const QString &message, unsigned int style);
117118

118-
void bumpedFee(const uint256& txid);
119+
void bumpedFee(const Txid& txid);
119120

120121
public Q_SLOTS:
121122
void chooseDate(int idx);
@@ -126,7 +127,7 @@ public Q_SLOTS:
126127
void exportClicked();
127128
void closeOpenedDialogs();
128129
void focusTransaction(const QModelIndex&);
129-
void focusTransaction(const uint256& txid);
130+
void focusTransaction(const Txid& txid);
130131
};
131132

132133
#endif // BITCOIN_QT_TRANSACTIONVIEW_H

src/qt/walletmodel.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ static void NotifyAddressBookChanged(WalletModel *walletmodel,
388388
assert(invoked);
389389
}
390390

391-
static void NotifyTransactionChanged(WalletModel *walletmodel, const uint256 &hash, ChangeType status)
391+
static void NotifyTransactionChanged(WalletModel *walletmodel, const Txid& hash, ChangeType status)
392392
{
393393
Q_UNUSED(hash);
394394
Q_UNUSED(status);
@@ -479,7 +479,7 @@ WalletModel::UnlockContext::~UnlockContext()
479479
}
480480
}
481481

482-
bool WalletModel::bumpFee(uint256 hash, uint256& new_hash)
482+
bool WalletModel::bumpFee(Txid hash, Txid& new_hash)
483483
{
484484
CCoinControl coin_control;
485485
coin_control.m_signal_bip125_rbf = true;
@@ -561,11 +561,15 @@ bool WalletModel::bumpFee(uint256 hash, uint256& new_hash)
561561
return false;
562562
}
563563
// commit the bumped transaction
564-
if(!m_wallet->commitBumpTransaction(hash, std::move(mtx), errors, new_hash)) {
564+
// Temporary uint256 variable needed for commitBumpTransaction out parameter.
565+
uint256 bumped_txid_result;
566+
if(!m_wallet->commitBumpTransaction(hash, std::move(mtx), errors, bumped_txid_result)) {
565567
QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Could not commit transaction") + "<br />(" +
566568
QString::fromStdString(errors[0].translated)+")");
567569
return false;
568570
}
571+
// Assign the received txid back to the new_hash.
572+
new_hash = Txid::FromUint256(bumped_txid_result);
569573
return true;
570574
}
571575

src/qt/walletmodel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <interfaces/wallet.h>
1313
#include <support/allocators/secure.h>
14+
#include <util/transaction_identifier.h>
1415

1516
#include <vector>
1617

@@ -129,7 +130,7 @@ class WalletModel : public QObject
129130

130131
UnlockContext requestUnlock();
131132

132-
bool bumpFee(uint256 hash, uint256& new_hash);
133+
bool bumpFee(Txid hash, Txid& new_hash);
133134
void displayAddress(std::string sAddress) const;
134135

135136
static bool isWalletEnabled();

src/qt/walletview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ WalletView::WalletView(WalletModel* wallet_model, const PlatformStyle* _platform
8282

8383
connect(sendCoinsPage, &SendCoinsDialog::coinsSent, this, &WalletView::coinsSent);
8484
// Highlight transaction after send
85-
connect(sendCoinsPage, &SendCoinsDialog::coinsSent, transactionView, qOverload<const uint256&>(&TransactionView::focusTransaction));
85+
connect(sendCoinsPage, &SendCoinsDialog::coinsSent, transactionView, qOverload<const Txid&>(&TransactionView::focusTransaction));
8686

8787
// Clicking on "Export" allows to export the transaction list
8888
connect(exportButton, &QPushButton::clicked, transactionView, &TransactionView::exportClicked);

0 commit comments

Comments
 (0)