Skip to content

Commit 7190de9

Browse files
committed
Merge bitcoin-core/gui#552: Refactor TransactionDesc::FormatTxStatus and TransactionStatus
343f83d qt, refactor: Use member initializers in TransactionStatus (w0xlt) 66d58ad qt, refactor: remove unused field `qint64 TransactionStatus::open_for` (w0xlt) ad6aded qt, refactor: remove unused parameters in `TransactionDesc::FormatTxStatus()` (w0xlt) 045f8d0 scripted-diff: rename nDepth -> depth (w0xlt) b1bc143 qt, refactor: remove redundant scope in `TransactionDesc::FormatTxStatus()` (w0xlt) Pull request description: This PR implements the changes suggested in bitcoin-core/gui#538 (comment) . . remove redundant scope, rename `nDepth` -> `depth`, remove unused parameters and add translator comments in `TransactionDesc::FormatTxStatus()` . Use member initializers and remove unused field `qint64 TransactionStatus::open_for` in `TransactionStatus`. Closes bitcoin-core/gui#538 ACKs for top commit: hebasto: ACK 343f83d, I have reviewed the code and it looks OK, I agree it can be merged. jarolrod: Code Review ACK bitcoin-core/gui@343f83d Tree-SHA512: cc7333d85b7eb731aa8cdd2d8dfc707341532c93e1b5e3858e8341446cf055ba055b601f9662e8d4602726b1bedf13149c46256a60a0ce1a562f94c9986d945a
2 parents 012d33f + 343f83d commit 7190de9

File tree

3 files changed

+19
-30
lines changed

3 files changed

+19
-30
lines changed

src/qt/transactiondesc.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,18 @@ using wallet::ISMINE_SPENDABLE;
3232
using wallet::ISMINE_WATCH_ONLY;
3333
using wallet::isminetype;
3434

35-
QString TransactionDesc::FormatTxStatus(const interfaces::WalletTx& wtx, const interfaces::WalletTxStatus& status, bool inMempool, int numBlocks)
35+
QString TransactionDesc::FormatTxStatus(const interfaces::WalletTxStatus& status, bool inMempool)
3636
{
37-
{
38-
int nDepth = status.depth_in_main_chain;
39-
if (nDepth < 0) {
40-
return tr("conflicted with a transaction with %1 confirmations").arg(-nDepth);
41-
} else if (nDepth == 0) {
42-
const QString abandoned{status.is_abandoned ? QLatin1String(", ") + tr("abandoned") : QString()};
43-
return tr("0/unconfirmed, %1").arg(inMempool ? tr("in memory pool") : tr("not in memory pool")) + abandoned;
44-
} else if (nDepth < 6) {
45-
return tr("%1/unconfirmed").arg(nDepth);
46-
} else {
47-
return tr("%1 confirmations").arg(nDepth);
48-
}
37+
int depth = status.depth_in_main_chain;
38+
if (depth < 0) {
39+
return tr("conflicted with a transaction with %1 confirmations").arg(-depth);
40+
} else if (depth == 0) {
41+
const QString abandoned{status.is_abandoned ? QLatin1String(", ") + tr("abandoned") : QString()};
42+
return tr("0/unconfirmed, %1").arg(inMempool ? tr("in memory pool") : tr("not in memory pool")) + abandoned;
43+
} else if (depth < 6) {
44+
return tr("%1/unconfirmed").arg(depth);
45+
} else {
46+
return tr("%1 confirmations").arg(depth);
4947
}
5048
}
5149

@@ -95,7 +93,7 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
9593
CAmount nDebit = wtx.debit;
9694
CAmount nNet = nCredit - nDebit;
9795

98-
strHTML += "<b>" + tr("Status") + ":</b> " + FormatTxStatus(wtx, status, inMempool, numBlocks);
96+
strHTML += "<b>" + tr("Status") + ":</b> " + FormatTxStatus(status, inMempool);
9997
strHTML += "<br>";
10098

10199
strHTML += "<b>" + tr("Date") + ":</b> " + (nTime ? GUIUtil::dateTimeStr(nTime) : "") + "<br>";

src/qt/transactiondesc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TransactionDesc: public QObject
2929
private:
3030
TransactionDesc() {}
3131

32-
static QString FormatTxStatus(const interfaces::WalletTx& wtx, const interfaces::WalletTxStatus& status, bool inMempool, int numBlocks);
32+
static QString FormatTxStatus(const interfaces::WalletTxStatus& status, bool inMempool);
3333
};
3434

3535
#endif // BITCOIN_QT_TRANSACTIONDESC_H

src/qt/transactionrecord.h

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ struct WalletTxStatus;
2020

2121
/** UI model for transaction status. The transaction status is the part of a transaction that will change over time.
2222
*/
23-
class TransactionStatus
24-
{
25-
public:
26-
TransactionStatus() : countsForBalance(false), sortKey(""),
27-
matures_in(0), status(Unconfirmed), depth(0), open_for(0)
28-
{ }
29-
23+
struct TransactionStatus {
3024
enum Status {
3125
Confirmed, /**< Have 6 or more confirmations (normal tx) or fully mature (mined tx) **/
3226
/// Normal (sent/received) transactions
@@ -40,28 +34,25 @@ class TransactionStatus
4034
};
4135

4236
/// Transaction counts towards available balance
43-
bool countsForBalance;
37+
bool countsForBalance{false};
4438
/// Sorting key based on status
4539
std::string sortKey;
4640

4741
/** @name Generated (mined) transactions
4842
@{*/
49-
int matures_in;
43+
int matures_in{0};
5044
/**@}*/
5145

5246
/** @name Reported status
5347
@{*/
54-
Status status;
55-
qint64 depth;
56-
qint64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number
57-
of additional blocks that need to be mined before
58-
finalization */
48+
Status status{Unconfirmed};
49+
qint64 depth{0};
5950
/**@}*/
6051

6152
/** Current block hash (to know whether cached status is still valid) */
6253
uint256 m_cur_block_hash{};
6354

64-
bool needsUpdate;
55+
bool needsUpdate{false};
6556
};
6657

6758
/** UI model for a transaction. A core transaction can be represented by multiple UI transactions if it has

0 commit comments

Comments
 (0)