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

Function CachedTxIsTrusted

src/wallet/receive.cpp:320–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

318}
319
320bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx, std::set<uint256>& trusted_parents)
321{
322 AssertLockHeld(wallet.cs_wallet);
323 int nDepth = wallet.GetTxDepthInMainChain(wtx);
324 if (nDepth >= 1) return true;
325 if (nDepth < 0) return false;
326 // using wtx's cached debit
327 if (!wallet.m_spend_zero_conf_change || !CachedTxIsFromMe(wallet, wtx, ISMINE_ALL)) return false;
328
329 // Don't trust unconfirmed transactions from us unless they are in the mempool.
330 if (!wtx.InMempool()) return false;
331
332 // Trusted if all inputs are from us and are in the mempool:
333 for (const CTxIn& txin : wtx.tx->vin)
334 {
335 // Transactions not sent by us: not trusted
336 const CWalletTx* parent = wallet.GetWalletTx(txin.prevout.hash);
337 if (parent == nullptr) return false;
338 const CTxOut& parentOut = parent->tx->vout[txin.prevout.n];
339 // Check that this specific input being spent is trusted
340 if (wallet.IsMine(parentOut) != ISMINE_SPENDABLE) return false;
341 // If we've already trusted this parent, continue
342 if (trusted_parents.count(parent->GetHash())) continue;
343 // Recurse to check that the parent is also trusted
344 if (!CachedTxIsTrusted(wallet, *parent, trusted_parents)) return false;
345 trusted_parents.insert(parent->GetHash());
346 }
347 return true;
348}
349
350bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx)
351{

Callers 5

spend.cppFile · 0.85
GetBalanceFunction · 0.85
GetAddressBalancesFunction · 0.85
MakeWalletTxStatusFunction · 0.85
WalletTxToJSONFunction · 0.85

Calls 8

CachedTxIsFromMeFunction · 0.85
GetTxDepthInMainChainMethod · 0.80
InMempoolMethod · 0.80
GetWalletTxMethod · 0.80
countMethod · 0.80
IsMineMethod · 0.45
GetHashMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected