| 318 | } |
| 319 | |
| 320 | bool 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 | |
| 350 | bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx) |
| 351 | { |
no test coverage detected