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,364 Lines • ▼ Show 20 Lines | Amount CWalletTx::GetAvailableCredit(bool fUseCache) const { | ||||
} | } | ||||
if (fUseCache && fAvailableCreditCached) { | if (fUseCache && fAvailableCreditCached) { | ||||
return nAvailableCreditCached; | return nAvailableCreditCached; | ||||
} | } | ||||
Amount nCredit = Amount::zero(); | Amount nCredit = Amount::zero(); | ||||
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(GetId(), i))) { | ||||
deadalnix: You could cache the txid in a local variable. | |||||
FabienAuthorUnsubmitted Done Inline ActionsThis is the only place where GetId() is called within this function, so adding a local variable is not worth it. Fabien: This is the only place where `GetId()` is called within this function, so adding a local… | |||||
deadalnixUnsubmitted Not Done Inline ActionsIt's in a loop. Unless tx->vout.size() is only called once, this is certainly called many times. deadalnix: It's in a loop. Unless `tx->vout.size()` is only called once, this is certainly called many… | |||||
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 29 Lines | Amount CWalletTx::GetAvailableWatchOnlyCredit(const bool fUseCache) const { | ||||
} | } | ||||
if (fUseCache && fAvailableWatchCreditCached) { | if (fUseCache && fAvailableWatchCreditCached) { | ||||
return nAvailableWatchCreditCached; | return nAvailableWatchCreditCached; | ||||
} | } | ||||
Amount nCredit = Amount::zero(); | Amount nCredit = Amount::zero(); | ||||
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(GetId(), i))) { | ||||
deadalnixUnsubmitted Not Done Inline Actionsdito deadalnix: dito | |||||
FabienAuthorUnsubmitted Done Inline ActionsDito :) Fabien: Dito :) | |||||
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 291 Lines • ▼ Show 20 Lines | void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, | ||||
const int nMaxDepth) const { | const int nMaxDepth) const { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
AssertLockHeld(cs_wallet); | AssertLockHeld(cs_wallet); | ||||
vCoins.clear(); | vCoins.clear(); | ||||
Amount nTotal = Amount::zero(); | Amount nTotal = Amount::zero(); | ||||
for (const auto &entry : mapWallet) { | for (const auto &entry : mapWallet) { | ||||
const TxId &wtxid = entry.first; | const TxId &wtxid = entry.first; | ||||
deadalnixUnsubmitted Not Done Inline ActionsWhy did your remove this ? deadalnix: Why did your remove this ? | |||||
FabienAuthorUnsubmitted Done Inline ActionsIt was only used by IsSpent as an alias for entry.first. Building the COutPoint from entry.first make it unused. Fabien: It was only used by `IsSpent` as an alias for `entry.first`. Building the `COutPoint` from… | |||||
deadalnixUnsubmitted Not Done Inline ActionsGiving things names is very useful. deadalnix: Giving things names is very useful. | |||||
const CWalletTx *pcoin = &entry.second; | const CWalletTx *pcoin = &entry.second; | ||||
if (!CheckFinalTx(*pcoin->tx)) { | if (!CheckFinalTx(*pcoin->tx)) { | ||||
continue; | continue; | ||||
} | } | ||||
if (pcoin->IsImmatureCoinBase()) { | if (pcoin->IsImmatureCoinBase()) { | ||||
continue; | continue; | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | for (const auto &entry : mapWallet) { | ||||
} | } | ||||
if (coinControl && coinControl->HasSelected() && | if (coinControl && coinControl->HasSelected() && | ||||
!coinControl->fAllowOtherInputs && | !coinControl->fAllowOtherInputs && | ||||
!coinControl->IsSelected(COutPoint(entry.first, i))) { | !coinControl->IsSelected(COutPoint(entry.first, i))) { | ||||
continue; | continue; | ||||
} | } | ||||
if (IsLockedCoin(entry.first, i)) { | if (IsLockedCoin(COutPoint(entry.first, i))) { | ||||
deadalnixUnsubmitted Not Done Inline ActionsBecause entry.first seems to be wtxid - unless something mutates it in between - then creating the outpoint once is preferable. deadalnix: Because entry.first seems to be wtxid - unless something mutates it in between - then creating… | |||||
continue; | continue; | ||||
} | } | ||||
if (IsSpent(wtxid, i)) { | if (IsSpent(COutPoint(wtxid, i))) { | ||||
FabienAuthorUnsubmitted Done Inline Actions-> here Fabien: -> here | |||||
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 |
You could cache the txid in a local variable.