Skip to content

Commit

Permalink
Merge #552: Refactor TransactionDesc::FormatTxStatus and ` Transact…
Browse files Browse the repository at this point in the history
…ionStatus`

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 #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 #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 343f83d

Tree-SHA512: cc7333d85b7eb731aa8cdd2d8dfc707341532c93e1b5e3858e8341446cf055ba055b601f9662e8d4602726b1bedf13149c46256a60a0ce1a562f94c9986d945a
  • Loading branch information
hebasto committed Apr 15, 2022
2 parents 012d33f + 343f83d commit 7190de9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
26 changes: 12 additions & 14 deletions src/qt/transactiondesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,18 @@ using wallet::ISMINE_SPENDABLE;
using wallet::ISMINE_WATCH_ONLY;
using wallet::isminetype;

QString TransactionDesc::FormatTxStatus(const interfaces::WalletTx& wtx, const interfaces::WalletTxStatus& status, bool inMempool, int numBlocks)
QString TransactionDesc::FormatTxStatus(const interfaces::WalletTxStatus& status, bool inMempool)
{
{
int nDepth = status.depth_in_main_chain;
if (nDepth < 0) {
return tr("conflicted with a transaction with %1 confirmations").arg(-nDepth);
} else if (nDepth == 0) {
const QString abandoned{status.is_abandoned ? QLatin1String(", ") + tr("abandoned") : QString()};
return tr("0/unconfirmed, %1").arg(inMempool ? tr("in memory pool") : tr("not in memory pool")) + abandoned;
} else if (nDepth < 6) {
return tr("%1/unconfirmed").arg(nDepth);
} else {
return tr("%1 confirmations").arg(nDepth);
}
int depth = status.depth_in_main_chain;
if (depth < 0) {
return tr("conflicted with a transaction with %1 confirmations").arg(-depth);
} else if (depth == 0) {
const QString abandoned{status.is_abandoned ? QLatin1String(", ") + tr("abandoned") : QString()};
return tr("0/unconfirmed, %1").arg(inMempool ? tr("in memory pool") : tr("not in memory pool")) + abandoned;
} else if (depth < 6) {
return tr("%1/unconfirmed").arg(depth);
} else {
return tr("%1 confirmations").arg(depth);
}
}

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

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

strHTML += "<b>" + tr("Date") + ":</b> " + (nTime ? GUIUtil::dateTimeStr(nTime) : "") + "<br>";
Expand Down
2 changes: 1 addition & 1 deletion src/qt/transactiondesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TransactionDesc: public QObject
private:
TransactionDesc() {}

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

#endif // BITCOIN_QT_TRANSACTIONDESC_H
21 changes: 6 additions & 15 deletions src/qt/transactionrecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ struct WalletTxStatus;

/** UI model for transaction status. The transaction status is the part of a transaction that will change over time.
*/
class TransactionStatus
{
public:
TransactionStatus() : countsForBalance(false), sortKey(""),
matures_in(0), status(Unconfirmed), depth(0), open_for(0)
{ }

struct TransactionStatus {
enum Status {
Confirmed, /**< Have 6 or more confirmations (normal tx) or fully mature (mined tx) **/
/// Normal (sent/received) transactions
Expand All @@ -40,28 +34,25 @@ class TransactionStatus
};

/// Transaction counts towards available balance
bool countsForBalance;
bool countsForBalance{false};
/// Sorting key based on status
std::string sortKey;

/** @name Generated (mined) transactions
@{*/
int matures_in;
int matures_in{0};
/**@}*/

/** @name Reported status
@{*/
Status status;
qint64 depth;
qint64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number
of additional blocks that need to be mined before
finalization */
Status status{Unconfirmed};
qint64 depth{0};
/**@}*/

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

bool needsUpdate;
bool needsUpdate{false};
};

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

0 comments on commit 7190de9

Please sign in to comment.