refactor: Rely on returned value of GetCoin instead of parameter

Also removed the unused coin parameter of GetCoin.

Co-authored-by: Andrew Toth <andrewstoth@gmail.com>
This commit is contained in:
Lőrinc
2024-09-07 23:12:35 +02:00
parent 46dfbf169b
commit 4feaa28728
16 changed files with 85 additions and 113 deletions

View File

@@ -180,18 +180,14 @@ std::optional<std::vector<int>> CalculatePrevHeights(
std::vector<int> prev_heights;
prev_heights.resize(tx.vin.size());
for (size_t i = 0; i < tx.vin.size(); ++i) {
const CTxIn& txin = tx.vin[i];
Coin coin;
if (!coins.GetCoin(txin.prevout, coin)) {
if (auto coin{coins.GetCoin(tx.vin[i].prevout)}) {
prev_heights[i] = coin->nHeight == MEMPOOL_HEIGHT
? tip.nHeight + 1 // Assume all mempool transaction confirm in the next block.
: coin->nHeight;
} else {
LogPrintf("ERROR: %s: Missing input %d in transaction \'%s\'\n", __func__, i, tx.GetHash().GetHex());
return std::nullopt;
}
if (coin.nHeight == MEMPOOL_HEIGHT) {
// Assume all mempool transaction confirm in the next block.
prev_heights[i] = tip.nHeight + 1;
} else {
prev_heights[i] = coin.nHeight;
}
}
return prev_heights;
}