Permalink
Browse files

Modernize Transactions

  • Loading branch information...
Tranz5 committed May 4, 2014
1 parent 35ff173 commit fdf06a7ea1a9c3a56ec3adc8c60e3b6f6b3d6ea0
@@ -806,7 +806,7 @@ void CTxMemPool::queryHashes(std::vector<uint256>& vtxid)
int CMerkleTx::GetDepthInMainChain(CBlockIndex* &pindexRet) const
int CMerkleTx::GetDepthInMainChainINTERNAL(CBlockIndex* &pindexRet) const
{
if (hashBlock == 0 || nIndex == -1)
return 0;
@@ -831,6 +831,15 @@ int CMerkleTx::GetDepthInMainChain(CBlockIndex* &pindexRet) const
return pindexBest->nHeight - pindex->nHeight + 1;
}
int CMerkleTx::GetDepthInMainChain(CBlockIndex* &pindexRet) const
{
int nResult = GetDepthInMainChainINTERNAL(pindexRet);
if (nResult == 0 && !mempool.exists(GetHash()))
return -1; // Not in chain, not in mempool
return nResult;
}
int CMerkleTx::GetBlocksToMaturity() const
{
@@ -728,6 +728,8 @@ class CTransaction
/** A transaction with a merkle branch linking it to the block chain. */
class CMerkleTx : public CTransaction
{
private:
int GetDepthInMainChainINTERNAL(CBlockIndex* &pindexRet) const;
public:
uint256 hashBlock;
std::vector<uint256> vMerkleBranch;
@@ -766,9 +768,14 @@ class CMerkleTx : public CTransaction
int SetMerkleBranch(const CBlock* pblock=NULL);
// Return depth of transaction in blockchain:
// -1 : not in blockchain, and not in memory pool (conflicted transaction)
// 0 : in memory pool, waiting to be included in a block
// >=1 : this many blocks deep in the main chain
int GetDepthInMainChain(CBlockIndex* &pindexRet) const;
int GetDepthInMainChain() const { CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet); }
bool IsInMainChain() const { return GetDepthInMainChain() > 0; }
bool IsInMainChain() const { CBlockIndex *pindexRet; return GetDepthInMainChainINTERNAL(pindexRet) > 0; }
int GetBlocksToMaturity() const;
bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true);
bool AcceptToMemoryPool();
@@ -48,6 +48,7 @@
<file alias="import">res/icons/import.png</file>
<file alias="export2">res/icons/export2.png</file>
<file alias="repair">res/icons/repair.png</file>
<file alias="transaction_conflicted">res/icons/transaction_conflicted.png</file>
</qresource>
<qresource prefix="/images">
<file alias="about">res/images/about.png</file>
@@ -190,6 +190,7 @@ void OverviewPage::setWalletModel(WalletModel *model)
filter->setLimit(NUM_ITEMS);
filter->setDynamicSortFilter(true);
filter->setSortRole(Qt::EditRole);
filter->setShowInactive(false);
filter->sort(TransactionTableModel::Status, Qt::DescendingOrder);
ui->listTransactions->setModel(filter);
Binary file not shown.
@@ -21,7 +21,9 @@ QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx)
else
{
int nDepth = wtx.GetDepthInMainChain();
if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
if (nDepth < 0)
return tr("conflicted");
else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
return tr("%1/offline").arg(nDepth);
else if (nDepth < 6)
return tr("%1/unconfirmed").arg(nDepth);
@@ -1,5 +1,6 @@
#include "transactionfilterproxy.h"
#include "transactiontablemodel.h"
#include "transactionrecord.h"
#include <QDateTime>
@@ -17,7 +18,8 @@ TransactionFilterProxy::TransactionFilterProxy(QObject *parent) :
addrPrefix(),
typeFilter(ALL_TYPES),
minAmount(0),
limitRows(-1)
limitRows(-1),
showInactive(true)
{
}
@@ -30,7 +32,10 @@ bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &
QString address = index.data(TransactionTableModel::AddressRole).toString();
QString label = index.data(TransactionTableModel::LabelRole).toString();
qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
int status = index.data(TransactionTableModel::StatusRole).toInt();
if(!showInactive && (status == TransactionStatus::Conflicted || status == TransactionStatus::NotAccepted))
return false;
if(!(TYPE(type) & typeFilter))
return false;
if(datetime < dateFrom || datetime > dateTo)
@@ -73,6 +78,12 @@ void TransactionFilterProxy::setLimit(int limit)
this->limitRows = limit;
}
void TransactionFilterProxy::setShowInactive(bool showInactive)
{
this->showInactive = showInactive;
invalidateFilter();
}
int TransactionFilterProxy::rowCount(const QModelIndex &parent) const
{
if(limitRows != -1)
@@ -31,6 +31,9 @@ class TransactionFilterProxy : public QSortFilterProxyModel
/** Set maximum number of rows returned, -1 if unlimited. */
void setLimit(int limit);
/** Set whether to show conflicted transactions. */
void setShowInactive(bool showInactive);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
protected:
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const;
@@ -42,6 +45,7 @@ class TransactionFilterProxy : public QSortFilterProxyModel
quint32 typeFilter;
qint64 minAmount;
int limitRows;
bool showInactive;
signals:
@@ -170,7 +170,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
(wtx.IsCoinBase() ? 1 : 0),
wtx.nTimeReceived,
idx);
status.confirmed = wtx.IsTrusted();
status.countsForBalance = wtx.IsTrusted() && !(wtx.GetBlocksToMaturity() > 0);
status.depth = wtx.GetDepthInMainChain();
status.cur_num_blocks = nBestHeight;
@@ -187,46 +187,52 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
status.open_for = wtx.nLockTime;
}
}
else
{
if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
{
status.status = TransactionStatus::Offline;
}
else if (status.depth < NumConfirmations)
{
status.status = TransactionStatus::Unconfirmed;
}
else
{
status.status = TransactionStatus::HaveConfirmations;
}
}
// For generated transactions, determine maturity
if(type == TransactionRecord::Generated || type == TransactionRecord::StakeMint)
else if(type == TransactionRecord::Generated || type == TransactionRecord::StakeMint)
{
int64 nCredit = wtx.GetCredit(true);
if (nCredit == 0)
if (wtx.GetBlocksToMaturity() > 0)
{
status.maturity = TransactionStatus::Immature;
status.status = TransactionStatus::Immature;
if (wtx.IsInMainChain())
{
status.matures_in = wtx.GetBlocksToMaturity();
// Check if the block was requested by anyone
if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
status.maturity = TransactionStatus::MaturesWarning;
status.status = TransactionStatus::MaturesWarning;
}
else
{
status.maturity = TransactionStatus::NotAccepted;
status.status = TransactionStatus::NotAccepted;
}
}
else
{
status.maturity = TransactionStatus::Mature;
status.status = TransactionStatus::Confirmed;
}
}
else
{
if (status.depth < 0)
{
status.status = TransactionStatus::Conflicted;
}
else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
{
status.status = TransactionStatus::Offline;
}
else if (status.depth == 0)
{
status.status = TransactionStatus::Unconfirmed;
}
else if (status.depth < RecommendedNumConfirmations)
{
status.status = TransactionStatus::Confirming;
}
else
{
status.status = TransactionStatus::Confirmed;
}
}
}
@@ -14,32 +14,33 @@ class TransactionStatus
{
public:
TransactionStatus():
confirmed(false), sortKey(""), maturity(Mature),
countsForBalance(false), sortKey(""),
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 {
OpenUntilDate,
OpenUntilBlock,
Offline,
Unconfirmed,
HaveConfirmations
Confirmed, /**< Have 6 or more confirmations (normal tx) or fully mature (mined tx) **/
/// Normal (sent/received) transactions
OpenUntilDate, /**< Transaction not yet final, waiting for date */
OpenUntilBlock, /**< Transaction not yet final, waiting for block */
Offline, /**< Not sent to any other nodes **/
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;
/** @name Generated (mined) transactions
@{*/
Maturity maturity;
int matures_in;
/**@}*/
@@ -72,8 +73,8 @@ class TransactionRecord
StakeMint
};
/** Number of confirmation needed for transaction */
static const int NumConfirmations = 6;
/** Number of confirmation recommended for accepting a transaction */
static const int RecommendedNumConfirmations = 6;
TransactionRecord():
hash(), time(0), type(Other), address(""), debit(0), credit(0), idx(0)
Oops, something went wrong.

0 comments on commit fdf06a7

Please sign in to comment.