Handle "conflicted" transactions properly
Extend CMerkleTx::GetDepthInMainChain with the concept of a "conflicted" transaction-- a transaction generated by the wallet that is not in the main chain or in the mempool, and, therefore, will likely never be confirmed. GetDepthInMainChain() now returns -1 for conflicted transactions (0 for unconfirmed-but-in-the-mempool, and >1 for confirmed). This makes getbalance, getbalance '*', and listunspent all agree when there are mutated transactions in the wallet. Before: listunspent: one 49BTC output getbalance: 96 BTC (change counted twice) getbalance '*': 46 BTC (spends counted twice) After: all agree, 49 BTC available to spend.
This commit is contained in:
10
src/wallet.h
10
src/wallet.h
@@ -700,8 +700,11 @@ public:
|
||||
// Quick answer in most cases
|
||||
if (!IsFinalTx(*this))
|
||||
return false;
|
||||
if (GetDepthInMainChain() >= 1)
|
||||
int nDepth = GetDepthInMainChain();
|
||||
if (nDepth >= 1)
|
||||
return true;
|
||||
if (nDepth < 0)
|
||||
return false;
|
||||
if (!bSpendZeroConfChange || !IsFromMe()) // using wtx's cached debit
|
||||
return false;
|
||||
|
||||
@@ -717,8 +720,11 @@ public:
|
||||
|
||||
if (!IsFinalTx(*ptx))
|
||||
return false;
|
||||
if (ptx->GetDepthInMainChain() >= 1)
|
||||
int nPDepth = ptx->GetDepthInMainChain();
|
||||
if (nPDepth >= 1)
|
||||
continue;
|
||||
if (nPDepth < 0)
|
||||
return false;
|
||||
if (!pwallet->IsFromMe(*ptx))
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user