2014-10-18 14:53:37 -03:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2016-12-31 15:01:21 -03:00
|
|
|
// Copyright (c) 2009-2016 The Bitcoin Core developers
|
2014-10-18 14:53:37 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2014-11-03 12:16:40 -03:00
|
|
|
#ifndef BITCOIN_UNDO_H
|
|
|
|
#define BITCOIN_UNDO_H
|
2014-10-18 14:53:37 -03:00
|
|
|
|
2014-10-18 23:28:43 -03:00
|
|
|
#include "compressor.h"
|
2014-11-18 18:03:02 -03:00
|
|
|
#include "primitives/transaction.h"
|
2014-10-18 14:53:37 -03:00
|
|
|
#include "serialize.h"
|
|
|
|
|
|
|
|
/** Undo information for a CTxIn
|
|
|
|
*
|
|
|
|
* Contains the prevout's CTxOut being spent, and if this was the
|
|
|
|
* last output of the affected transaction, its metadata as well
|
2017-04-25 15:29:18 -03:00
|
|
|
* (coinbase or not, height). Earlier versions also stored the transaction
|
|
|
|
* version.
|
2014-10-18 14:53:37 -03:00
|
|
|
*/
|
|
|
|
class CTxInUndo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CTxOut txout; // the txout data before being spent
|
|
|
|
bool fCoinBase; // if the outpoint was the last unspent: whether it belonged to a coinbase
|
|
|
|
unsigned int nHeight; // if the outpoint was the last unspent: its height
|
|
|
|
|
2017-04-25 15:29:18 -03:00
|
|
|
CTxInUndo() : txout(), fCoinBase(false), nHeight(0) {}
|
|
|
|
CTxInUndo(const CTxOut &txoutIn, bool fCoinBaseIn = false, unsigned int nHeightIn = 0) : txout(txoutIn), fCoinBase(fCoinBaseIn), nHeight(nHeightIn) { }
|
2014-10-18 14:53:37 -03:00
|
|
|
|
|
|
|
template<typename Stream>
|
2016-10-28 20:29:17 -03:00
|
|
|
void Serialize(Stream &s) const {
|
|
|
|
::Serialize(s, VARINT(nHeight*2+(fCoinBase ? 1 : 0)));
|
2017-04-25 15:29:18 -03:00
|
|
|
if (nHeight > 0) {
|
|
|
|
int nVersionDummy = 0;
|
|
|
|
::Serialize(s, VARINT(nVersionDummy));
|
|
|
|
}
|
2016-10-28 20:29:17 -03:00
|
|
|
::Serialize(s, CTxOutCompressor(REF(txout)));
|
2014-10-18 14:53:37 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Stream>
|
2016-10-28 20:29:17 -03:00
|
|
|
void Unserialize(Stream &s) {
|
2014-10-18 14:53:37 -03:00
|
|
|
unsigned int nCode = 0;
|
2016-10-28 20:29:17 -03:00
|
|
|
::Unserialize(s, VARINT(nCode));
|
2014-10-18 14:53:37 -03:00
|
|
|
nHeight = nCode / 2;
|
|
|
|
fCoinBase = nCode & 1;
|
2017-04-25 15:29:18 -03:00
|
|
|
if (nHeight > 0) {
|
|
|
|
int nVersionDummy;
|
|
|
|
::Unserialize(s, VARINT(nVersionDummy));
|
|
|
|
}
|
2016-10-28 20:29:17 -03:00
|
|
|
::Unserialize(s, REF(CTxOutCompressor(REF(txout))));
|
2014-10-18 14:53:37 -03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Undo information for a CTransaction */
|
|
|
|
class CTxUndo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// undo information for all txins
|
|
|
|
std::vector<CTxInUndo> vprevout;
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
2016-10-28 20:29:17 -03:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
2014-10-18 14:53:37 -03:00
|
|
|
READWRITE(vprevout);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-27 10:42:49 -03:00
|
|
|
/** Undo information for a CBlock */
|
|
|
|
class CBlockUndo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::vector<CTxUndo> vtxundo; // for all but the coinbase
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
2016-10-28 20:29:17 -03:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
2014-10-27 10:42:49 -03:00
|
|
|
READWRITE(vtxundo);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-11-03 12:16:40 -03:00
|
|
|
#endif // BITCOIN_UNDO_H
|