aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorjtimon <jtimon@blockstream.io>2014-10-19 02:57:02 +0200
committerjtimon <jtimon@jtimon.cc>2014-12-27 15:46:09 +0100
commitc444c620c62c51d65f7de0b2a3c351e61ab1e388 (patch)
treedf3a6a164ba30069fcf9dd2a646cb593f90dad51 /src/main.cpp
parent0f2308cf7cfffe13b0206802622cad4d9e009aa1 (diff)
downloadbitcoin-c444c620c62c51d65f7de0b2a3c351e61ab1e388.tar.xz
Decouple CCoins from CTxInUndo
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 2410230ef4..3f775e3d33 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1383,9 +1383,20 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach
if (!tx.IsCoinBase()) {
txundo.vprevout.reserve(tx.vin.size());
BOOST_FOREACH(const CTxIn &txin, tx.vin) {
- txundo.vprevout.push_back(CTxInUndo());
- bool ret = inputs.ModifyCoins(txin.prevout.hash)->Spend(txin.prevout, txundo.vprevout.back());
- assert(ret);
+ CCoinsModifier coins = inputs.ModifyCoins(txin.prevout.hash);
+ unsigned nPos = txin.prevout.n;
+
+ if (nPos >= coins->vout.size() || coins->vout[nPos].IsNull())
+ assert(false);
+ // mark an outpoint spent, and construct undo information
+ txundo.vprevout.push_back(CTxInUndo(coins->vout[nPos]));
+ coins->Spend(nPos);
+ if (coins->vout.size() == 0) {
+ CTxInUndo& undo = txundo.vprevout.back();
+ undo.nHeight = coins->nHeight;
+ undo.fCoinBase = coins->fCoinBase;
+ undo.nVersion = coins->nVersion;
+ }
}
}