Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 646 Lines • ▼ Show 20 Lines | for (TxSpends::iterator it = range.first; it != range.second; ++it) { | ||||
copyTo->strFromAccount = copyFrom->strFromAccount; | copyTo->strFromAccount = copyFrom->strFromAccount; | ||||
// nOrderPos not copied on purpose cached members not copied on purpose. | // nOrderPos not copied on purpose cached members not copied on purpose. | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Outpoint is spent if any non-conflicted transaction, spends it: | * Outpoint is spent if any non-conflicted transaction, spends it: | ||||
*/ | */ | ||||
bool CWallet::IsSpent(const TxId &txid, uint32_t n) const { | bool CWallet::IsSpent(const COutPoint &outpoint) const { | ||||
const COutPoint outpoint(txid, n); | |||||
std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = | std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = | ||||
mapTxSpends.equal_range(outpoint); | mapTxSpends.equal_range(outpoint); | ||||
for (TxSpends::const_iterator it = range.first; it != range.second; ++it) { | for (TxSpends::const_iterator it = range.first; it != range.second; ++it) { | ||||
const TxId &wtxid = it->second; | const TxId &wtxid = it->second; | ||||
std::map<TxId, CWalletTx>::const_iterator mit = mapWallet.find(wtxid); | std::map<TxId, CWalletTx>::const_iterator mit = mapWallet.find(wtxid); | ||||
if (mit != mapWallet.end()) { | if (mit != mapWallet.end()) { | ||||
int depth = mit->second.GetDepthInMainChain(); | int depth = mit->second.GetDepthInMainChain(); | ||||
▲ Show 20 Lines • Show All 1,363 Lines • ▼ Show 20 Lines | if (IsImmatureCoinBase()) { | ||||
return Amount::zero(); | return Amount::zero(); | ||||
} | } | ||||
if (fUseCache && fAvailableCreditCached) { | if (fUseCache && fAvailableCreditCached) { | ||||
return nAvailableCreditCached; | return nAvailableCreditCached; | ||||
} | } | ||||
Amount nCredit = Amount::zero(); | Amount nCredit = Amount::zero(); | ||||
const TxId &txid = GetId(); | |||||
for (uint32_t i = 0; i < tx->vout.size(); i++) { | for (uint32_t i = 0; i < tx->vout.size(); i++) { | ||||
if (!pwallet->IsSpent(GetId(), i)) { | if (!pwallet->IsSpent(COutPoint(txid, i))) { | ||||
const CTxOut &txout = tx->vout[i]; | const CTxOut &txout = tx->vout[i]; | ||||
nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE); | nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE); | ||||
if (!MoneyRange(nCredit)) { | if (!MoneyRange(nCredit)) { | ||||
throw std::runtime_error(std::string(__func__) + | throw std::runtime_error(std::string(__func__) + | ||||
" : value out of range"); | " : value out of range"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
Show All 28 Lines | if (IsCoinBase() && GetBlocksToMaturity() > 0) { | ||||
return Amount::zero(); | return Amount::zero(); | ||||
} | } | ||||
if (fUseCache && fAvailableWatchCreditCached) { | if (fUseCache && fAvailableWatchCreditCached) { | ||||
return nAvailableWatchCreditCached; | return nAvailableWatchCreditCached; | ||||
} | } | ||||
Amount nCredit = Amount::zero(); | Amount nCredit = Amount::zero(); | ||||
const TxId &txid = GetId(); | |||||
for (uint32_t i = 0; i < tx->vout.size(); i++) { | for (uint32_t i = 0; i < tx->vout.size(); i++) { | ||||
if (!pwallet->IsSpent(GetId(), i)) { | if (!pwallet->IsSpent(COutPoint(txid, i))) { | ||||
const CTxOut &txout = tx->vout[i]; | const CTxOut &txout = tx->vout[i]; | ||||
nCredit += pwallet->GetCredit(txout, ISMINE_WATCH_ONLY); | nCredit += pwallet->GetCredit(txout, ISMINE_WATCH_ONLY); | ||||
if (!MoneyRange(nCredit)) { | if (!MoneyRange(nCredit)) { | ||||
throw std::runtime_error(std::string(__func__) + | throw std::runtime_error(std::string(__func__) + | ||||
": value out of range"); | ": value out of range"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 350 Lines • ▼ Show 20 Lines | for (const auto &entry : mapWallet) { | ||||
} | } | ||||
for (uint32_t i = 0; i < pcoin->tx->vout.size(); i++) { | for (uint32_t i = 0; i < pcoin->tx->vout.size(); i++) { | ||||
if (pcoin->tx->vout[i].nValue < nMinimumAmount || | if (pcoin->tx->vout[i].nValue < nMinimumAmount || | ||||
pcoin->tx->vout[i].nValue > nMaximumAmount) { | pcoin->tx->vout[i].nValue > nMaximumAmount) { | ||||
continue; | continue; | ||||
} | } | ||||
const COutPoint outpoint(wtxid, i); | |||||
if (coinControl && coinControl->HasSelected() && | if (coinControl && coinControl->HasSelected() && | ||||
!coinControl->fAllowOtherInputs && | !coinControl->fAllowOtherInputs && | ||||
!coinControl->IsSelected(COutPoint(entry.first, i))) { | !coinControl->IsSelected(outpoint)) { | ||||
continue; | continue; | ||||
} | } | ||||
if (IsLockedCoin(entry.first, i)) { | if (IsLockedCoin(outpoint)) { | ||||
continue; | continue; | ||||
} | } | ||||
if (IsSpent(wtxid, i)) { | if (IsSpent(outpoint)) { | ||||
continue; | continue; | ||||
} | } | ||||
isminetype mine = IsMine(pcoin->tx->vout[i]); | isminetype mine = IsMine(pcoin->tx->vout[i]); | ||||
if (mine == ISMINE_NO) { | if (mine == ISMINE_NO) { | ||||
continue; | continue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,305 Lines • ▼ Show 20 Lines | for (const auto &walletEntry : mapWallet) { | ||||
if (!IsMine(pcoin->tx->vout[i])) { | if (!IsMine(pcoin->tx->vout[i])) { | ||||
continue; | continue; | ||||
} | } | ||||
if (!ExtractDestination(pcoin->tx->vout[i].scriptPubKey, addr)) { | if (!ExtractDestination(pcoin->tx->vout[i].scriptPubKey, addr)) { | ||||
continue; | continue; | ||||
} | } | ||||
Amount n = IsSpent(walletEntry.first, i) | Amount n = IsSpent(COutPoint(walletEntry.first, i)) | ||||
? Amount::zero() | ? Amount::zero() | ||||
: pcoin->tx->vout[i].nValue; | : pcoin->tx->vout[i].nValue; | ||||
if (!balances.count(addr)) { | if (!balances.count(addr)) { | ||||
balances[addr] = Amount::zero(); | balances[addr] = Amount::zero(); | ||||
} | } | ||||
balances[addr] += n; | balances[addr] += n; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 217 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void CWallet::UnlockAllCoins() { | void CWallet::UnlockAllCoins() { | ||||
// setLockedCoins | // setLockedCoins | ||||
AssertLockHeld(cs_wallet); | AssertLockHeld(cs_wallet); | ||||
setLockedCoins.clear(); | setLockedCoins.clear(); | ||||
} | } | ||||
bool CWallet::IsLockedCoin(const TxId &txid, uint32_t n) const { | bool CWallet::IsLockedCoin(const COutPoint &outpoint) const { | ||||
// setLockedCoins | // setLockedCoins | ||||
AssertLockHeld(cs_wallet); | AssertLockHeld(cs_wallet); | ||||
COutPoint outpt(txid, n); | |||||
return setLockedCoins.count(outpt) > 0; | return setLockedCoins.count(outpoint) > 0; | ||||
} | } | ||||
void CWallet::ListLockedCoins(std::vector<COutPoint> &vOutpts) const { | void CWallet::ListLockedCoins(std::vector<COutPoint> &vOutpts) const { | ||||
// setLockedCoins | // setLockedCoins | ||||
AssertLockHeld(cs_wallet); | AssertLockHeld(cs_wallet); | ||||
for (COutPoint outpoint : setLockedCoins) { | for (COutPoint outpoint : setLockedCoins) { | ||||
vOutpts.push_back(outpoint); | vOutpts.push_back(outpoint); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 661 Lines • Show Last 20 Lines |