From 119e552f7ccd49c0137a3c6b4f94018a84d69620 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 26 Apr 2017 16:09:27 -0700 Subject: [PATCH] Merge CCoinsViewCache's GetOutputFor and AccessCoin They're doing the same thing now. --- src/coins.cpp | 9 +-------- src/coins.h | 2 -- src/consensus/tx_verify.cpp | 4 ++-- src/policy/policy.cpp | 4 ++-- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 09fd2b13d..59bcdce9c 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -213,13 +213,6 @@ 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()) @@ -227,7 +220,7 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const 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; } diff --git a/src/coins.h b/src/coins.h index 43da9a3c6..1203c3fad 100644 --- a/src/coins.h +++ b/src/coins.h @@ -272,8 +272,6 @@ public: //! Check whether all prevouts of the transaction are present in the UTXO set represented by this view bool HaveInputs(const CTransaction& tx) const; - const CTxOut &GetOutputFor(const CTxIn& input) const; - private: CCoinsMap::iterator FetchCoins(const COutPoint &outpoint) const; diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp index 9a6f3c9cd..1195a1561 100644 --- a/src/consensus/tx_verify.cpp +++ b/src/consensus/tx_verify.cpp @@ -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); } @@ -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; diff --git a/src/policy/policy.cpp b/src/policy/policy.cpp index f4fffd657..14d58e744 100644 --- a/src/policy/policy.cpp +++ b/src/policy/policy.cpp @@ -165,7 +165,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 > vSolutions; txnouttype whichType; @@ -204,7 +204,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;