Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 2,245 Lines • ▼ Show 20 Lines | for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | ||||
it != mapWallet.end(); ++it) { | it != mapWallet.end(); ++it) { | ||||
const CWalletTx *pcoin = &(*it).second; | const CWalletTx *pcoin = &(*it).second; | ||||
nTotal += pcoin->GetImmatureWatchOnlyCredit(); | nTotal += pcoin->GetImmatureWatchOnlyCredit(); | ||||
} | } | ||||
return nTotal; | return nTotal; | ||||
} | } | ||||
void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlyConfirmed, | void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, | ||||
const CCoinControl *coinControl, | const CCoinControl *coinControl, | ||||
bool fIncludeZeroValue) const { | bool fIncludeZeroValue) const { | ||||
vCoins.clear(); | vCoins.clear(); | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | for (std::map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); | ||||
it != mapWallet.end(); ++it) { | it != mapWallet.end(); ++it) { | ||||
const uint256 &wtxid = it->first; | const uint256 &wtxid = it->first; | ||||
const CWalletTx *pcoin = &(*it).second; | const CWalletTx *pcoin = &(*it).second; | ||||
if (!CheckFinalTx(*pcoin)) { | if (!CheckFinalTx(*pcoin)) { | ||||
continue; | continue; | ||||
} | } | ||||
if (fOnlyConfirmed && !pcoin->IsTrusted()) { | |||||
continue; | |||||
} | |||||
if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0) { | if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0) { | ||||
continue; | continue; | ||||
} | } | ||||
int nDepth = pcoin->GetDepthInMainChain(); | int nDepth = pcoin->GetDepthInMainChain(); | ||||
if (nDepth < 0) { | if (nDepth < 0) { | ||||
continue; | continue; | ||||
} | } | ||||
// We should not consider coins which aren't at least in our mempool. | // 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 | // It's possible for these to be conflicted via ancestors which we may | ||||
// never be able to detect. | // never be able to detect. | ||||
if (nDepth == 0 && !pcoin->InMempool()) { | if (nDepth == 0 && !pcoin->InMempool()) { | ||||
continue; | continue; | ||||
} | } | ||||
bool safeTx = pcoin->IsTrusted(); | |||||
// Bitcoin-ABC: Removed check that prevents consideration of coins from | // Bitcoin-ABC: Removed check that prevents consideration of coins from | ||||
// transactions that are replacing other transactions. This check based | // transactions that are replacing other transactions. This check based | ||||
// on pcoin->mapValue.count("replaces_txid") which was not being set | // on pcoin->mapValue.count("replaces_txid") which was not being set | ||||
// anywhere. | // anywhere. | ||||
// Similarly, we should not consider coins from transactions that have | // Similarly, we should not consider coins from transactions that have | ||||
// been replaced. In the example above, we would want to prevent | // been replaced. In the example above, we would want to prevent | ||||
// creation of a transaction A' spending an output of A, because if | // creation of a transaction A' spending an output of A, because if | ||||
// transaction B were initially confirmed, conflicting with A and A', we | // transaction B were initially confirmed, conflicting with A and A', we | ||||
// wouldn't want to the user to create a transaction D intending to | // wouldn't want to the user to create a transaction D intending to | ||||
// replace A', but potentially resulting in a scenario where A, A', and | // replace A', but potentially resulting in a scenario where A, A', and | ||||
// D could all be accepted (instead of just B and D, or just A and A' | // D could all be accepted (instead of just B and D, or just A and A' | ||||
// like the user would want). | // like the user would want). | ||||
// Bitcoin-ABC: retained this check as 'replaced_by_txid' is still set | // Bitcoin-ABC: retained this check as 'replaced_by_txid' is still set | ||||
// in the wallet code. | // in the wallet code. | ||||
if (nDepth == 0 && fOnlyConfirmed && | if (nDepth == 0 && pcoin->mapValue.count("replaced_by_txid")) { | ||||
pcoin->mapValue.count("replaced_by_txid")) { | safeTx = false; | ||||
} | |||||
if (fOnlySafe && !safeTx) { | |||||
continue; | continue; | ||||
} | } | ||||
for (unsigned int i = 0; i < pcoin->tx->vout.size(); i++) { | for (unsigned int i = 0; i < pcoin->tx->vout.size(); i++) { | ||||
isminetype mine = IsMine(pcoin->tx->vout[i]); | isminetype mine = IsMine(pcoin->tx->vout[i]); | ||||
if (!(IsSpent(wtxid, i)) && mine != ISMINE_NO && | if (!(IsSpent(wtxid, i)) && mine != ISMINE_NO && | ||||
!IsLockedCoin((*it).first, i) && | !IsLockedCoin((*it).first, i) && | ||||
(pcoin->tx->vout[i].nValue > Amount(0) || fIncludeZeroValue) && | (pcoin->tx->vout[i].nValue > Amount(0) || fIncludeZeroValue) && | ||||
(!coinControl || !coinControl->HasSelected() || | (!coinControl || !coinControl->HasSelected() || | ||||
coinControl->fAllowOtherInputs || | coinControl->fAllowOtherInputs || | ||||
coinControl->IsSelected(COutPoint((*it).first, i)))) { | coinControl->IsSelected(COutPoint((*it).first, i)))) { | ||||
vCoins.push_back(COutput( | vCoins.push_back(COutput( | ||||
pcoin, i, nDepth, | pcoin, i, nDepth, | ||||
((mine & ISMINE_SPENDABLE) != ISMINE_NO) || | ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || | ||||
(coinControl && coinControl->fAllowWatchOnly && | (coinControl && coinControl->fAllowWatchOnly && | ||||
(mine & ISMINE_WATCH_SOLVABLE) != ISMINE_NO), | (mine & ISMINE_WATCH_SOLVABLE) != ISMINE_NO), | ||||
(mine & (ISMINE_SPENDABLE | ISMINE_WATCH_SOLVABLE)) != | (mine & (ISMINE_SPENDABLE | ISMINE_WATCH_SOLVABLE)) != | ||||
ISMINE_NO)); | ISMINE_NO, | ||||
safeTx)); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
static void ApproximateBestSubset( | static void ApproximateBestSubset( | ||||
std::vector<std::pair<Amount, std::pair<const CWalletTx *, unsigned int>>> | std::vector<std::pair<Amount, std::pair<const CWalletTx *, unsigned int>>> | ||||
vValue, | vValue, | ||||
▲ Show 20 Lines • Show All 2,247 Lines • Show Last 20 Lines |