mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-11 15:48:05 +00:00
Decouple CCoins from CTxInUndo
This commit is contained in:
parent
0f2308cf7c
commit
c444c620c6
@ -31,29 +31,15 @@ void CCoins::CalcMaskSize(unsigned int &nBytes, unsigned int &nNonzeroBytes) con
|
|||||||
nBytes += nLastUsedByte;
|
nBytes += nLastUsedByte;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCoins::Spend(const COutPoint &out, CTxInUndo &undo) {
|
bool CCoins::Spend(uint32_t nPos)
|
||||||
if (out.n >= vout.size())
|
{
|
||||||
|
if (nPos >= vout.size() || vout[nPos].IsNull())
|
||||||
return false;
|
return false;
|
||||||
if (vout[out.n].IsNull())
|
vout[nPos].SetNull();
|
||||||
return false;
|
|
||||||
undo = CTxInUndo(vout[out.n]);
|
|
||||||
vout[out.n].SetNull();
|
|
||||||
Cleanup();
|
Cleanup();
|
||||||
if (vout.size() == 0) {
|
|
||||||
undo.nHeight = nHeight;
|
|
||||||
undo.fCoinBase = fCoinBase;
|
|
||||||
undo.nVersion = this->nVersion;
|
|
||||||
}
|
|
||||||
return true;
|
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::GetCoins(const uint256 &txid, CCoins &coins) const { return false; }
|
||||||
bool CCoinsView::HaveCoins(const uint256 &txid) const { return false; }
|
bool CCoinsView::HaveCoins(const uint256 &txid) const { return false; }
|
||||||
uint256 CCoinsView::GetBestBlock() const { return uint256(0); }
|
uint256 CCoinsView::GetBestBlock() const { return uint256(0); }
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include "compressor.h"
|
#include "compressor.h"
|
||||||
#include "serialize.h"
|
#include "serialize.h"
|
||||||
#include "uint256.h"
|
#include "uint256.h"
|
||||||
#include "undo.h"
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -237,11 +236,8 @@ public:
|
|||||||
Cleanup();
|
Cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! mark an outpoint spent, and construct undo information
|
|
||||||
bool Spend(const COutPoint &out, CTxInUndo &undo);
|
|
||||||
|
|
||||||
//! mark a vout spent
|
//! mark a vout spent
|
||||||
bool Spend(int nPos);
|
bool Spend(uint32_t nPos);
|
||||||
|
|
||||||
//! check whether a particular output is still available
|
//! check whether a particular output is still available
|
||||||
bool IsAvailable(unsigned int nPos) const {
|
bool IsAvailable(unsigned int nPos) const {
|
||||||
|
17
src/main.cpp
17
src/main.cpp
@ -1383,9 +1383,20 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach
|
|||||||
if (!tx.IsCoinBase()) {
|
if (!tx.IsCoinBase()) {
|
||||||
txundo.vprevout.reserve(tx.vin.size());
|
txundo.vprevout.reserve(tx.vin.size());
|
||||||
BOOST_FOREACH(const CTxIn &txin, tx.vin) {
|
BOOST_FOREACH(const CTxIn &txin, tx.vin) {
|
||||||
txundo.vprevout.push_back(CTxInUndo());
|
CCoinsModifier coins = inputs.ModifyCoins(txin.prevout.hash);
|
||||||
bool ret = inputs.ModifyCoins(txin.prevout.hash)->Spend(txin.prevout, txundo.vprevout.back());
|
unsigned nPos = txin.prevout.n;
|
||||||
assert(ret);
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user