MCPcopy Create free account
hub / github.com/ElementsProject/elements / CachedTxGetAvailableCredit

Function CachedTxGetAvailableCredit

src/wallet/receive.cpp:216–255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214}
215
216CAmountMap CachedTxGetAvailableCredit(const CWallet& wallet, const CWalletTx& wtx, bool fUseCache, const isminefilter& filter)
217{
218 // Avoid caching ismine for NO or ALL cases (could remove this check and simplify in the future).
219 bool allow_cache = (filter & ISMINE_ALL) && (filter & ISMINE_ALL) != ISMINE_ALL;
220
221 // Must wait until coinbase is safely deep enough in the chain before valuing it
222 if (wallet.IsTxImmatureCoinBase(wtx))
223 return CAmountMap();
224
225 if (fUseCache && allow_cache && wtx.m_amounts[CWalletTx::AVAILABLE_CREDIT].m_cached[filter]) {
226 return wtx.m_amounts[CWalletTx::AVAILABLE_CREDIT].m_value[filter];
227 }
228
229 bool allow_used_addresses = (filter & ISMINE_USED) || !wallet.IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE);
230 CAmountMap nCredit;
231 uint256 hashTx = wtx.GetHash();
232 CAsset pegged_asset{Params().GetConsensus().pegged_asset};
233 for (unsigned int i = 0; i < wtx.tx->vout.size(); i++)
234 {
235 if (!wallet.IsSpent(hashTx, i) && (allow_used_addresses || !wallet.IsSpentKey(hashTx, i))) {
236 if (wallet.IsMine(wtx.tx->vout[i]) & filter) {
237 CAsset asset = wtx.GetOutputAsset(wallet, i);
238 CAmount credit = std::max<CAmount>(0, wtx.GetOutputValueOut(wallet, i));
239 if (asset == pegged_asset && !MoneyRange(credit))
240 throw std::runtime_error(std::string(__func__) + ": value out of range");
241
242 nCredit[wtx.GetOutputAsset(wallet, i)] += std::max<CAmount>(0, wtx.GetOutputValueOut(wallet, i));
243 if (!MoneyRange(nCredit, pegged_asset))
244 throw std::runtime_error(std::string(__func__) + ": value out of range");
245 }
246 }
247 }
248
249 if (allow_cache) {
250 wtx.m_amounts[CWalletTx::AVAILABLE_CREDIT].Set(filter, nCredit);
251 wtx.m_is_cache_empty = false;
252 }
253
254 return nCredit;
255}
256
257void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
258 std::list<COutputEntry>& listReceived,

Callers 1

GetBalanceFunction · 0.85

Calls 12

IsTxImmatureCoinBaseMethod · 0.80
IsWalletFlagSetMethod · 0.80
IsSpentKeyMethod · 0.80
GetOutputAssetMethod · 0.80
GetOutputValueOutMethod · 0.80
ParamsClass · 0.50
MoneyRangeFunction · 0.50
GetHashMethod · 0.45
sizeMethod · 0.45
IsSpentMethod · 0.45
IsMineMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected