Systematize style of IsTrusted single line if

pull/16766/head
Jeremy Rubin 5 years ago
parent b49dcbedf7
commit 8f174ef112

@ -2302,38 +2302,29 @@ bool CWalletTx::IsTrusted(interfaces::Chain::Lock& locked_chain) const
bool CWalletTx::IsTrusted(interfaces::Chain::Lock& locked_chain, std::set<uint256>& trusted_parents) const bool CWalletTx::IsTrusted(interfaces::Chain::Lock& locked_chain, std::set<uint256>& trusted_parents) const
{ {
// Quick answer in most cases // Quick answer in most cases
if (!locked_chain.checkFinalTx(*tx)) { if (!locked_chain.checkFinalTx(*tx)) return false;
return false;
}
int nDepth = GetDepthInMainChain(locked_chain); int nDepth = GetDepthInMainChain(locked_chain);
if (nDepth >= 1) if (nDepth >= 1) return true;
return true; if (nDepth < 0) return false;
if (nDepth < 0) // using wtx's cached debit
return false; if (!pwallet->m_spend_zero_conf_change || !IsFromMe(ISMINE_ALL)) return false;
if (!pwallet->m_spend_zero_conf_change || !IsFromMe(ISMINE_ALL)) // using wtx's cached debit
return false;
// Don't trust unconfirmed transactions from us unless they are in the mempool. // Don't trust unconfirmed transactions from us unless they are in the mempool.
if (!InMempool()) if (!InMempool()) return false;
return false;
// Trusted if all inputs are from us and are in the mempool: // Trusted if all inputs are from us and are in the mempool:
for (const CTxIn& txin : tx->vin) for (const CTxIn& txin : tx->vin)
{ {
// Transactions not sent by us: not trusted // Transactions not sent by us: not trusted
const CWalletTx* parent = pwallet->GetWalletTx(txin.prevout.hash); const CWalletTx* parent = pwallet->GetWalletTx(txin.prevout.hash);
if (parent == nullptr) if (parent == nullptr) return false;
return false;
const CTxOut& parentOut = parent->tx->vout[txin.prevout.n]; const CTxOut& parentOut = parent->tx->vout[txin.prevout.n];
// Check that this specific input being spent is trusted // Check that this specific input being spent is trusted
if (pwallet->IsMine(parentOut) != ISMINE_SPENDABLE) if (pwallet->IsMine(parentOut) != ISMINE_SPENDABLE) return false;
return false;
// If we've already trusted this parent, continue // If we've already trusted this parent, continue
if (trusted_parents.count(parent->GetHash())) if (trusted_parents.count(parent->GetHash())) continue;
continue;
// Recurse to check that the parent is also trusted // Recurse to check that the parent is also trusted
if (!parent->IsTrusted(locked_chain, trusted_parents)) if (!parent->IsTrusted(locked_chain, trusted_parents)) return false;
return false;
trusted_parents.insert(parent->GetHash()); trusted_parents.insert(parent->GetHash());
} }
return true; return true;

Loading…
Cancel
Save