Skip to content

Commit

Permalink
Decouple CCoins from CTxInUndo
Browse files Browse the repository at this point in the history
  • Loading branch information
jtimon authored and jtimon committed Dec 27, 2014
1 parent 0f2308c commit c444c62
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
22 changes: 4 additions & 18 deletions src/coins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,15 @@ void CCoins::CalcMaskSize(unsigned int &nBytes, unsigned int &nNonzeroBytes) con
nBytes += nLastUsedByte;
}

bool CCoins::Spend(const COutPoint &out, CTxInUndo &undo) {
if (out.n >= vout.size())
return false;
if (vout[out.n].IsNull())
bool CCoins::Spend(uint32_t nPos)
{
if (nPos >= vout.size() || vout[nPos].IsNull())
return false;
undo = CTxInUndo(vout[out.n]);
vout[out.n].SetNull();
vout[nPos].SetNull();
Cleanup();
if (vout.size() == 0) {
undo.nHeight = nHeight;
undo.fCoinBase = fCoinBase;
undo.nVersion = this->nVersion;
}
return true;
}

bool CCoins::Spend(int nPos) {
CTxInUndo undo;
COutPoint out(0, nPos);
return Spend(out, undo);
}


bool CCoinsView::GetCoins(const uint256 &txid, CCoins &coins) const { return false; }
bool CCoinsView::HaveCoins(const uint256 &txid) const { return false; }
uint256 CCoinsView::GetBestBlock() const { return uint256(0); }
Expand Down
6 changes: 1 addition & 5 deletions src/coins.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "compressor.h"
#include "serialize.h"
#include "uint256.h"
#include "undo.h"

#include <assert.h>
#include <stdint.h>
Expand Down Expand Up @@ -237,11 +236,8 @@ class CCoins
Cleanup();
}

//! mark an outpoint spent, and construct undo information
bool Spend(const COutPoint &out, CTxInUndo &undo);

//! mark a vout spent
bool Spend(int nPos);
bool Spend(uint32_t nPos);

//! check whether a particular output is still available
bool IsAvailable(unsigned int nPos) const {
Expand Down
17 changes: 14 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit c444c62

Please sign in to comment.