aboutsummaryrefslogtreecommitdiff
path: root/src/validation.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2017-04-25 11:29:25 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2017-06-01 11:56:06 -0700
commitcb2c7fdac2dc74368ed24ae4717ed72178956b92 (patch)
treee00cdf124e4399033b2d9354e82e1f5496144903 /src/validation.cpp
parent422634e2f5ac1ff74cd358144cecbac63007adc4 (diff)
Replace CTxInUndo with Coin
The earlier CTxInUndo class now holds the same information as the Coin class. Instead of duplicating functionality, replace CTxInUndo with a serialization adapter for Coin.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r--src/validation.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index fccef17196..dad0e1a3ee 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -1080,11 +1080,9 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txund
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);
- CTxInUndo& undo = txundo.vprevout.back();
- undo.nHeight = coins->nHeight;
- undo.fCoinBase = coins->fCoinBase;
+ txundo.vprevout.emplace_back(coins->vout[nPos], coins->nHeight, coins->fCoinBase);
+ bool ret = coins->Spend(nPos);
+ assert(ret);
}
}
// add outputs
@@ -1252,13 +1250,13 @@ enum DisconnectResult
};
/**
- * Apply the undo operation of a CTxInUndo to the given chain state.
- * @param undo The undo object.
+ * Restore the UTXO in a Coin at a given COutPoint
+ * @param undo The Coin to be restored.
* @param view The coins view to which to apply the changes.
* @param out The out point that corresponds to the tx input.
* @return A DisconnectResult as an int
*/
-int ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, const COutPoint& out)
+int ApplyTxInUndo(const Coin& undo, CCoinsViewCache& view, const COutPoint& out)
{
bool fClean = true;
@@ -1279,7 +1277,7 @@ int ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, const COutPoint&
if (coins->IsAvailable(out.n)) fClean = false; // overwriting existing output
if (coins->vout.size() < out.n+1)
coins->vout.resize(out.n+1);
- coins->vout[out.n] = undo.txout;
+ coins->vout[out.n] = undo.out;
return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN;
}
@@ -1335,7 +1333,7 @@ static DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex*
}
for (unsigned int j = tx.vin.size(); j-- > 0;) {
const COutPoint &out = tx.vin[j].prevout;
- const CTxInUndo &undo = txundo.vprevout[j];
+ const Coin &undo = txundo.vprevout[j];
int res = ApplyTxInUndo(undo, view, out);
if (res == DISCONNECT_FAILED) return DISCONNECT_FAILED;
fClean = fClean && res != DISCONNECT_UNCLEAN;