Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions src/qt/transactiondesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,34 @@ QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx)
else
return tr("Open until %1").arg(GUIUtil::dateTimeStr(wtx.nLockTime));
} else {
int signatures = wtx.GetTransactionLockSignatures();
const int signatures = wtx.GetTransactionLockSignatures();
QString strUsingIX = "";
bool fConflicted;
const int nDepth = wtx.GetDepthAndMempool(fConflicted);

if (nDepth < 0 || fConflicted)
return tr("conflicted");

const bool isOffline = (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0);

if (signatures >= 0) {
if (signatures >= SWIFTTX_SIGNATURES_REQUIRED) {
int nDepth = wtx.GetDepthInMainChain();
if (nDepth < 0)
return tr("conflicted");
else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
if (isOffline)
return tr("%1/offline (verified via SwiftX)").arg(nDepth);
else if (nDepth < 6)
return tr("%1/confirmed (verified via SwiftX)").arg(nDepth);
else
return tr("%1 confirmations (verified via SwiftX)").arg(nDepth);
} else {
if (!wtx.IsTransactionLockTimedOut()) {
int nDepth = wtx.GetDepthInMainChain();
if (nDepth < 0)
return tr("conflicted");
else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
if (isOffline)
return tr("%1/offline (SwiftX verification in progress - %2 of %3 signatures)").arg(nDepth).arg(signatures).arg(SWIFTTX_SIGNATURES_TOTAL);
else if (nDepth < 6)
return tr("%1/confirmed (SwiftX verification in progress - %2 of %3 signatures )").arg(nDepth).arg(signatures).arg(SWIFTTX_SIGNATURES_TOTAL);
else
return tr("%1 confirmations (SwiftX verification in progress - %2 of %3 signatures)").arg(nDepth).arg(signatures).arg(SWIFTTX_SIGNATURES_TOTAL);
} else {
int nDepth = wtx.GetDepthInMainChain();
if (nDepth < 0)
return tr("conflicted");
else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
if (isOffline)
return tr("%1/offline (SwiftX verification failed)").arg(nDepth);
else if (nDepth < 6)
return tr("%1/confirmed (SwiftX verification failed)").arg(nDepth);
Expand All @@ -70,10 +69,7 @@ QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx)
}
}
} else {
int nDepth = wtx.GetDepthInMainChain();
if (nDepth < 0)
return tr("conflicted");
else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
if (isOffline)
return tr("%1/offline").arg(nDepth);
else if (nDepth < 6)
return tr("%1/unconfirmed").arg(nDepth);
Expand Down
12 changes: 7 additions & 5 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ void TransactionRecord::updateStatus(const CWalletTx& wtx)
wtx.nTimeReceived,
idx);
//status.countsForBalance = wtx.IsTrusted() && !(wtx.GetBlocksToMaturity() > 0);
status.depth = wtx.GetDepthInMainChain();
bool fConflicted;
status.depth = wtx.GetDepthAndMempool(fConflicted);
const bool isOffline = (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0);

//Determine the depth of the block
int nBlocksToMaturity = wtx.GetBlocksToMaturity();
Expand All @@ -374,7 +376,7 @@ void TransactionRecord::updateStatus(const CWalletTx& wtx)

if (pindex && chainActive.Contains(pindex)) {
// Check if the block was requested by anyone
if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
if (isOffline)
status.status = TransactionStatus::MaturesWarning;
} else {
status.status = TransactionStatus::NotAccepted;
Expand All @@ -384,9 +386,9 @@ void TransactionRecord::updateStatus(const CWalletTx& wtx)
status.matures_in = 0;
}
} else {
if (status.depth < 0) {
if (status.depth < 0 || fConflicted) {
status.status = TransactionStatus::Conflicted;
} else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0) {
} else if (isOffline) {
status.status = TransactionStatus::Offline;
} else if (status.depth == 0) {
status.status = TransactionStatus::Unconfirmed;
Expand Down Expand Up @@ -438,4 +440,4 @@ std::string TransactionRecord::statusToString(){
default:
return "No status";
}
}
}
10 changes: 6 additions & 4 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,9 @@ void WalletModel::getOutputs(const std::vector<COutPoint>& vOutpoints, std::vect
LOCK2(cs_main, wallet->cs_wallet);
for (const COutPoint& outpoint : vOutpoints) {
if (!wallet->mapWallet.count(outpoint.hash)) continue;
int nDepth = wallet->mapWallet[outpoint.hash].GetDepthInMainChain();
if (nDepth < 0) continue;
bool fConflicted;
const int nDepth = wallet->mapWallet[outpoint.hash].GetDepthAndMempool(fConflicted);
if (nDepth < 0 || fConflicted) continue;
COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, nDepth, true);
vOutputs.push_back(out);
}
Expand All @@ -889,8 +890,9 @@ void WalletModel::listCoins(std::map<QString, std::vector<COutput> >& mapCoins)
// add locked coins
for (const COutPoint& outpoint : vLockedCoins) {
if (!wallet->mapWallet.count(outpoint.hash)) continue;
int nDepth = wallet->mapWallet[outpoint.hash].GetDepthInMainChain();
if (nDepth < 0) continue;
bool fConflicted;
int nDepth = wallet->mapWallet[outpoint.hash].GetDepthAndMempool(fConflicted);
if (nDepth < 0 || fConflicted) continue;
COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, nDepth, true);
if (outpoint.n < out.tx->vout.size() && wallet->IsMine(out.tx->vout[outpoint.n]) == ISMINE_SPENDABLE)
vCoins.push_back(out);
Expand Down
24 changes: 16 additions & 8 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,13 +667,16 @@ CAmount GetAccountBalance(CWalletDB& walletdb, const std::string& strAccount, in
// Tally wallet transactions
for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) {
const CWalletTx& wtx = (*it).second;
if (!IsFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
bool fConflicted;
int depth = wtx.GetDepthAndMempool(fConflicted);

if (!IsFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || depth < 0 || fConflicted)
continue;

CAmount nReceived, nSent, nFee;
wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter);

if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
if (nReceived != 0 && depth >= nMinDepth)
nBalance += nReceived;
nBalance -= nSent + nFee;
}
Expand Down Expand Up @@ -741,15 +744,18 @@ UniValue getbalance(const UniValue& params, bool fHelp)
CAmount nBalance = 0;
for (std::map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) {
const CWalletTx& wtx = (*it).second;
if (!IsFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
bool fConflicted;
int depth = wtx.GetDepthAndMempool(fConflicted);

if (!IsFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || depth < 0 || fConflicted)
continue;

CAmount allFee;
std::string strSentAccount;
std::list<COutputEntry> listReceived;
std::list<COutputEntry> listSent;
wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter);
if (wtx.GetDepthInMainChain() >= nMinDepth) {
if (depth >= nMinDepth) {
for (const COutputEntry& r : listReceived)
nBalance += r.amount;
}
Expand Down Expand Up @@ -1276,7 +1282,8 @@ void ListTransactions(const CWalletTx& wtx, const std::string& strAccount, int n
}

// Received
if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) {
int depth = wtx.GetDepthInMainChain();
if (listReceived.size() > 0 && depth >= nMinDepth) {
for (const COutputEntry& r : listReceived) {
std::string account;
if (pwalletMain->mapAddressBook.count(r.destination))
Expand All @@ -1288,7 +1295,7 @@ void ListTransactions(const CWalletTx& wtx, const std::string& strAccount, int n
entry.push_back(Pair("account", account));
MaybePushAddress(entry, r.destination);
if (wtx.IsCoinBase()) {
if (wtx.GetDepthInMainChain() < 1)
if (depth < 1)
entry.push_back(Pair("category", "orphan"));
else if (wtx.GetBlocksToMaturity() > 0)
entry.push_back(Pair("category", "immature"));
Expand Down Expand Up @@ -1497,8 +1504,9 @@ UniValue listaccounts(const UniValue& params, bool fHelp)
std::string strSentAccount;
std::list<COutputEntry> listReceived;
std::list<COutputEntry> listSent;
int nDepth = wtx.GetDepthInMainChain();
if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0)
bool fConflicted;
int nDepth = wtx.GetDepthAndMempool(fConflicted);
if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0 || fConflicted)
continue;
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly);
mapAccountBalances[strSentAccount] -= nFee;
Expand Down
19 changes: 12 additions & 7 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ bool CWalletTx::InMempool() const
void CWalletTx::RelayWalletTransaction(std::string strCommand)
{
LOCK(cs_main);
if (!IsCoinBase()) {
if (!IsCoinBase() && !IsCoinStake()) {
if (GetDepthInMainChain() == 0 && !isAbandoned()) {
uint256 hash = GetHash();
LogPrintf("Relaying wtx %s\n", hash.ToString());
Expand Down Expand Up @@ -1851,11 +1851,6 @@ void CWallet::AvailableCoins(
if (nDepth == 0 && !pcoin->InMempool())
continue;

// We should not consider coins which aren't at least in our mempool
// It's possible for these to be conflicted via ancestors which we may never be able to detect
if (nDepth == 0 && !pcoin->InMempool())
continue;

for (unsigned int i = 0; i < pcoin->vout.size(); i++) {
bool found = false;
if (nCoinType == ONLY_DENOMINATED) {
Expand Down Expand Up @@ -3031,7 +3026,10 @@ std::map<CTxDestination, CAmount> CWallet::GetAddressBalances()
if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0)
continue;

int nDepth = pcoin->GetDepthInMainChain();
bool fConflicted;
int nDepth = pcoin->GetDepthAndMempool(fConflicted);
if (fConflicted)
continue;
if (nDepth < (pcoin->IsFromMe(ISMINE_ALL) ? 0 : 1))
continue;

Expand Down Expand Up @@ -5562,6 +5560,13 @@ bool CWalletTx::IsTrusted() const
return true;
}

int CWalletTx::GetDepthAndMempool(bool& fConflicted, bool enableIX) const
{
int ret = GetDepthInMainChain(enableIX);
fConflicted = (ret == 0 && !InMempool()); // not in chain nor in mempool
return ret;
}

void CWalletTx::MarkDirty()
{
fCreditCached = false;
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,8 @@ class CWalletTx : public CMerkleTx

void BindWallet(CWallet* pwalletIn);

int GetDepthAndMempool(bool& fConflicted, bool enableIX = true) const;

//! filter decides which addresses will count towards the debit
CAmount GetDebit(const isminefilter& filter) const;
CAmount GetCredit(const isminefilter& filter) const;
Expand Down