Browse Source

Merge pull request #3719

f642fd9 qt: Modernize 'confirmed' terminology in shown tx status (Wladimir J. van der Laan)
0.10
Wladimir J. van der Laan 11 years ago
parent
commit
97f2bbd753
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 55
      src/qt/transactionrecord.cpp
  2. 37
      src/qt/transactionrecord.h
  3. 75
      src/qt/transactiontablemodel.cpp

55
src/qt/transactionrecord.cpp

@ -164,7 +164,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
(wtx.IsCoinBase() ? 1 : 0), (wtx.IsCoinBase() ? 1 : 0),
wtx.nTimeReceived, wtx.nTimeReceived,
idx); idx);
status.confirmed = wtx.IsTrusted(); status.countsForBalance = wtx.IsTrusted() && !(wtx.GetBlocksToMaturity() > 0);
status.depth = wtx.GetDepthInMainChain(); status.depth = wtx.GetDepthInMainChain();
status.cur_num_blocks = chainActive.Height(); status.cur_num_blocks = chainActive.Height();
@ -181,52 +181,55 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
status.open_for = wtx.nLockTime; status.open_for = wtx.nLockTime;
} }
} }
else // For generated transactions, determine maturity
else if(type == TransactionRecord::Generated)
{ {
if (status.depth < 0) if (wtx.GetBlocksToMaturity() > 0)
{ {
status.status = TransactionStatus::Conflicted; status.status = TransactionStatus::Immature;
}
else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0) if (wtx.IsInMainChain())
{ {
status.status = TransactionStatus::Offline; status.matures_in = wtx.GetBlocksToMaturity();
// Check if the block was requested by anyone
if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
status.status = TransactionStatus::MaturesWarning;
} }
else if (status.depth < NumConfirmations) else
{ {
status.status = TransactionStatus::Unconfirmed; status.status = TransactionStatus::NotAccepted;
}
} }
else else
{ {
status.status = TransactionStatus::HaveConfirmations; status.status = TransactionStatus::Confirmed;
} }
} }
else
// For generated transactions, determine maturity
if(type == TransactionRecord::Generated)
{ {
int64_t nCredit = wtx.GetCredit(true); if (status.depth < 0)
if (nCredit == 0)
{ {
status.maturity = TransactionStatus::Immature; status.status = TransactionStatus::Conflicted;
}
if (wtx.IsInMainChain()) else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
{ {
status.matures_in = wtx.GetBlocksToMaturity(); status.status = TransactionStatus::Offline;
// Check if the block was requested by anyone
if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
status.maturity = TransactionStatus::MaturesWarning;
} }
else else if (status.depth == 0)
{ {
status.maturity = TransactionStatus::NotAccepted; status.status = TransactionStatus::Unconfirmed;
} }
else if (status.depth < RecommendedNumConfirmations)
{
status.status = TransactionStatus::Confirming;
} }
else else
{ {
status.maturity = TransactionStatus::Mature; status.status = TransactionStatus::Confirmed;
} }
} }
} }
bool TransactionRecord::statusUpdateNeeded() bool TransactionRecord::statusUpdateNeeded()

37
src/qt/transactionrecord.h

@ -19,33 +19,32 @@ class TransactionStatus
{ {
public: public:
TransactionStatus(): TransactionStatus():
confirmed(false), sortKey(""), maturity(Mature), countsForBalance(false), sortKey(""),
matures_in(0), status(Offline), depth(0), open_for(0), cur_num_blocks(-1) matures_in(0), status(Offline), depth(0), open_for(0), cur_num_blocks(-1)
{ } { }
enum Maturity
{
Immature,
Mature,
MaturesWarning, /**< Transaction will likely not mature because no nodes have confirmed */
NotAccepted
};
enum Status { enum Status {
OpenUntilDate, Confirmed, /**< Have 6 or more confirmations (normal tx) or fully mature (mined tx) **/
OpenUntilBlock, /// Normal (sent/received) transactions
Offline, OpenUntilDate, /**< Transaction not yet final, waiting for date */
Unconfirmed, OpenUntilBlock, /**< Transaction not yet final, waiting for block */
HaveConfirmations, Offline, /**< Not sent to any other nodes **/
Conflicted Unconfirmed, /**< Not yet mined into a block **/
Confirming, /**< Confirmed, but waiting for the recommended number of confirmations **/
Conflicted, /**< Conflicts with other transaction or mempool **/
/// Generated (mined) transactions
Immature, /**< Mined but waiting for maturity */
MaturesWarning, /**< Transaction will likely not mature because no nodes have confirmed */
NotAccepted /**< Mined but not accepted */
}; };
bool confirmed; /// Transaction counts towards available balance
bool countsForBalance;
/// Sorting key based on status
std::string sortKey; std::string sortKey;
/** @name Generated (mined) transactions /** @name Generated (mined) transactions
@{*/ @{*/
Maturity maturity;
int matures_in; int matures_in;
/**@}*/ /**@}*/
@ -79,8 +78,8 @@ public:
SendToSelf SendToSelf
}; };
/** Number of confirmation needed for transaction */ /** Number of confirmation recommended for accepting a transaction */
static const int NumConfirmations = 6; static const int RecommendedNumConfirmations = 6;
TransactionRecord(): TransactionRecord():
hash(), time(0), type(Other), address(""), debit(0), credit(0), idx(0) hash(), time(0), type(Other), address(""), debit(0), credit(0), idx(0)

75
src/qt/transactiontablemodel.cpp

@ -285,24 +285,6 @@ QString TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) cons
{ {
QString status; QString status;
if(wtx->type == TransactionRecord::Generated)
{
switch(wtx->status.maturity)
{
case TransactionStatus::Immature:
status = tr("Immature (%1 confirmations, will be available after %2)").arg(wtx->status.depth).arg(wtx->status.depth + wtx->status.matures_in);
break;
case TransactionStatus::Mature:
status = tr("Confirmed (%1 confirmations)").arg(wtx->status.depth);
break;
case TransactionStatus::MaturesWarning:
status = tr("This block was not received by any other nodes and will probably not be accepted!");
break;
case TransactionStatus::NotAccepted:
status = tr("Generated but not accepted");
break;
}
} else {
switch(wtx->status.status) switch(wtx->status.status)
{ {
case TransactionStatus::OpenUntilBlock: case TransactionStatus::OpenUntilBlock:
@ -315,15 +297,26 @@ QString TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) cons
status = tr("Offline"); status = tr("Offline");
break; break;
case TransactionStatus::Unconfirmed: case TransactionStatus::Unconfirmed:
status = tr("Unconfirmed (%1 of %2 confirmations)").arg(wtx->status.depth).arg(TransactionRecord::NumConfirmations); status = tr("Unconfirmed");
break;
case TransactionStatus::Confirming:
status = tr("Confirming (%1 of %2 recommended confirmations)").arg(wtx->status.depth).arg(TransactionRecord::RecommendedNumConfirmations);
break; break;
case TransactionStatus::HaveConfirmations: case TransactionStatus::Confirmed:
status = tr("Confirmed (%1 confirmations)").arg(wtx->status.depth); status = tr("Confirmed (%1 confirmations)").arg(wtx->status.depth);
break; break;
case TransactionStatus::Conflicted: case TransactionStatus::Conflicted:
status = tr("Conflicted"); status = tr("Conflicted");
break; break;
} case TransactionStatus::Immature:
status = tr("Immature (%1 confirmations, will be available after %2)").arg(wtx->status.depth).arg(wtx->status.depth + wtx->status.matures_in);
break;
case TransactionStatus::MaturesWarning:
status = tr("This block was not received by any other nodes and will probably not be accepted!");
break;
case TransactionStatus::NotAccepted:
status = tr("Generated but not accepted");
break;
} }
return status; return status;
@ -441,7 +434,7 @@ QString TransactionTableModel::formatTxAmount(const TransactionRecord *wtx, bool
QString str = BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), wtx->credit + wtx->debit); QString str = BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), wtx->credit + wtx->debit);
if(showUnconfirmed) if(showUnconfirmed)
{ {
if(!wtx->status.confirmed || wtx->status.maturity != TransactionStatus::Mature) if(!wtx->status.countsForBalance)
{ {
str = QString("[") + str + QString("]"); str = QString("[") + str + QString("]");
} }
@ -451,24 +444,6 @@ QString TransactionTableModel::formatTxAmount(const TransactionRecord *wtx, bool
QVariant TransactionTableModel::txStatusDecoration(const TransactionRecord *wtx) const QVariant TransactionTableModel::txStatusDecoration(const TransactionRecord *wtx) const
{ {
if(wtx->type == TransactionRecord::Generated)
{
switch(wtx->status.maturity)
{
case TransactionStatus::Immature: {
int total = wtx->status.depth + wtx->status.matures_in;
int part = (wtx->status.depth * 4 / total) + 1;
return QIcon(QString(":/icons/transaction_%1").arg(part));
}
case TransactionStatus::Mature:
return QIcon(":/icons/transaction_confirmed");
case TransactionStatus::MaturesWarning:
case TransactionStatus::NotAccepted:
return QIcon(":/icons/transaction_0");
}
}
else
{
switch(wtx->status.status) switch(wtx->status.status)
{ {
case TransactionStatus::OpenUntilBlock: case TransactionStatus::OpenUntilBlock:
@ -477,20 +452,28 @@ QVariant TransactionTableModel::txStatusDecoration(const TransactionRecord *wtx)
case TransactionStatus::Offline: case TransactionStatus::Offline:
return QColor(192,192,192); return QColor(192,192,192);
case TransactionStatus::Unconfirmed: case TransactionStatus::Unconfirmed:
return QIcon(":/icons/transaction_0");
case TransactionStatus::Confirming:
switch(wtx->status.depth) switch(wtx->status.depth)
{ {
case 0: return QIcon(":/icons/transaction_0");
case 1: return QIcon(":/icons/transaction_1"); case 1: return QIcon(":/icons/transaction_1");
case 2: return QIcon(":/icons/transaction_2"); case 2: return QIcon(":/icons/transaction_2");
case 3: return QIcon(":/icons/transaction_3"); case 3: return QIcon(":/icons/transaction_3");
case 4: return QIcon(":/icons/transaction_4"); case 4: return QIcon(":/icons/transaction_4");
default: return QIcon(":/icons/transaction_5"); default: return QIcon(":/icons/transaction_5");
}; };
case TransactionStatus::HaveConfirmations: case TransactionStatus::Confirmed:
return QIcon(":/icons/transaction_confirmed"); return QIcon(":/icons/transaction_confirmed");
case TransactionStatus::Conflicted: case TransactionStatus::Conflicted:
return QIcon(":/icons/transaction_conflicted"); return QIcon(":/icons/transaction_conflicted");
case TransactionStatus::Immature: {
int total = wtx->status.depth + wtx->status.matures_in;
int part = (wtx->status.depth * 4 / total) + 1;
return QIcon(QString(":/icons/transaction_%1").arg(part));
} }
case TransactionStatus::MaturesWarning:
case TransactionStatus::NotAccepted:
return QIcon(":/icons/transaction_0");
} }
return QColor(0,0,0); return QColor(0,0,0);
} }
@ -557,8 +540,8 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
case Qt::TextAlignmentRole: case Qt::TextAlignmentRole:
return column_alignments[index.column()]; return column_alignments[index.column()];
case Qt::ForegroundRole: case Qt::ForegroundRole:
// Non-confirmed transactions are grey // Non-confirmed (but not immature) as transactions are grey
if(!rec->status.confirmed) if(!rec->status.countsForBalance && rec->status.status != TransactionStatus::Immature)
{ {
return COLOR_UNCONFIRMED; return COLOR_UNCONFIRMED;
} }
@ -586,9 +569,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
case TxIDRole: case TxIDRole:
return rec->getTxID(); return rec->getTxID();
case ConfirmedRole: case ConfirmedRole:
// Return True if transaction counts for balance return rec->status.countsForBalance;
return rec->status.confirmed && !(rec->type == TransactionRecord::Generated &&
rec->status.maturity != TransactionStatus::Mature);
case FormattedAmountRole: case FormattedAmountRole:
return formatTxAmount(rec, false); return formatTxAmount(rec, false);
case StatusRole: case StatusRole:

Loading…
Cancel
Save