Skip to content

Commit

Permalink
Merge CCoinsViewCache's GetOutputFor and AccessCoin
Browse files Browse the repository at this point in the history
They're doing the same thing now.
  • Loading branch information
sipa authored and xanimo committed Jul 15, 2024
1 parent 893733a commit d944b0c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
9 changes: 1 addition & 8 deletions src/coins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,14 @@ unsigned int CCoinsViewCache::GetCacheSize() const {
return cacheCoins.size();
}

const CTxOut &CCoinsViewCache::GetOutputFor(const CTxIn& input) const
{
const Coin& coin = AccessCoin(input.prevout);
assert(!coin.IsPruned());
return coin.out;
}

CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const
{
if (tx.IsCoinBase())
return 0;

CAmount nResult = 0;
for (unsigned int i = 0; i < tx.vin.size(); i++)
nResult += GetOutputFor(tx.vin[i]).nValue;
nResult += AccessCoin(tx.vin[i].prevout).out.nValue;

return nResult;
}
Expand Down
2 changes: 0 additions & 2 deletions src/coins.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ class CCoinsViewCache : public CCoinsViewBacked
*/
double GetPriority(const CTransaction &tx, int nHeight, CAmount &inChainInputValue) const;

const CTxOut &GetOutputFor(const CTxIn& input) const;

private:
CCoinsMap::iterator FetchCoins(const COutPoint &outpoint) const;

Expand Down
4 changes: 2 additions & 2 deletions src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
unsigned int nSigOps = 0;
for (unsigned int i = 0; i < tx.vin.size(); i++)
{
const CTxOut &prevout = inputs.GetOutputFor(tx.vin[i]);
const CTxOut &prevout = inputs.AccessCoin(tx.vin[i].prevout).out;
if (prevout.scriptPubKey.IsPayToScriptHash())
nSigOps += prevout.scriptPubKey.GetSigOpCount(tx.vin[i].scriptSig);
}
Expand All @@ -146,7 +146,7 @@ int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& i

for (unsigned int i = 0; i < tx.vin.size(); i++)
{
const CTxOut &prevout = inputs.GetOutputFor(tx.vin[i]);
const CTxOut &prevout = inputs.AccessCoin(tx.vin[i].prevout).out;
nSigOps += CountWitnessSigOps(tx.vin[i].scriptSig, prevout.scriptPubKey, &tx.vin[i].scriptWitness, flags);
}
return nSigOps;
Expand Down
4 changes: 2 additions & 2 deletions src/policy/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)

for (unsigned int i = 0; i < tx.vin.size(); i++)
{
const CTxOut& prev = mapInputs.GetOutputFor(tx.vin[i]);
const CTxOut& prev = mapInputs.AccessCoin(tx.vin[i].prevout).out;

std::vector<std::vector<unsigned char> > vSolutions;
txnouttype whichType;
Expand Down Expand Up @@ -167,7 +167,7 @@ bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
if (tx.vin[i].scriptWitness.IsNull())
continue;

const CTxOut &prev = mapInputs.GetOutputFor(tx.vin[i]);
const CTxOut &prev = mapInputs.AccessCoin(tx.vin[i].prevout).out;

// get the scriptPubKey corresponding to this input:
CScript prevScript = prev.scriptPubKey;
Expand Down

0 comments on commit d944b0c

Please sign in to comment.