lbrycrd/src/undo.h

88 lines
3.1 KiB
C
Raw Normal View History

2014-10-18 19:53:37 +02:00
// Copyright (c) 2009-2010 Satoshi Nakamoto
2020-02-27 09:55:47 -07:00
// Copyright (c) 2009-2014 The Bitcoin Core developers
2014-10-18 19:53:37 +02:00
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2014-11-03 16:16:40 +01:00
#ifndef BITCOIN_UNDO_H
#define BITCOIN_UNDO_H
2014-10-18 19:53:37 +02:00
#include <compressor.h>
#include <primitives/transaction.h>
#include <serialize.h>
2014-10-18 19:53:37 +02:00
/** Undo information for a CTxIn
*
2020-02-27 09:55:47 -07:00
* Contains the prevout's CTxOut being spent, and if this was the
* last output of the affected transaction, its metadata as well
* (coinbase or not, height, transaction version)
2014-10-18 19:53:37 +02:00
*/
2020-02-27 09:55:47 -07:00
class CTxInUndo
2014-10-18 19:53:37 +02:00
{
2020-02-27 09:55:47 -07:00
uint32_t nDeprecated1 = 0; // if the outpoint was the last unspent: its version
bool fDeprecated2 = false; // whether the outpoint was the last unspent
public:
2020-02-27 09:55:47 -07:00
CTxOut out; // the out data before being spent
bool fCoinBase; // if the outpoint was the last unspent: whether it belonged to a coinbase
uint32_t nHeight; // if the outpoint was the last unspent: its height
uint32_t nClaimValidHeight; // If the outpoint was a claim or support, the height at which the claim or support should be inserted into the trie
bool fIsClaim; // if the outpoint was a claim or support
uint32_t nClaimOriginalHeight; // If we are a claim, we need to track the original insertion height for that claim
2014-10-18 19:53:37 +02:00
2020-02-27 09:55:47 -07:00
CTxInUndo() : out(), fCoinBase(false), nHeight(0), nClaimValidHeight(0), fIsClaim(false), nClaimOriginalHeight(0) {}
CTxInUndo(const CTxOut &txoutIn, bool fCoinBaseIn = false, uint32_t nHeightIn = 0) :
out(txoutIn), fCoinBase(fCoinBaseIn), nHeight(nHeightIn), nClaimValidHeight(0), fIsClaim(false), nClaimOriginalHeight(0) {}
2020-02-27 09:55:47 -07:00
ADD_SERIALIZE_METHODS;
2020-02-27 09:55:47 -07:00
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
if (ser_action.ForRead()) {
uint32_t nCode = 0;
READWRITE(VARINT(nCode)); // VARINT in this method is for legacy compatibility
nHeight = nCode >> 2U;
fCoinBase = nCode & 2U;
fDeprecated2 = nCode & 1U;
} else {
uint32_t nCode = (nHeight << 2U) | (fCoinBase ? 2U : 0U) | (fDeprecated2 ? 1U: 0U);
READWRITE(VARINT(nCode));
}
2020-02-27 09:55:47 -07:00
if (fDeprecated2)
READWRITE(VARINT(nDeprecated1));
READWRITE(REF(CTxOutCompressor(REF(out))));
READWRITE(VARINT(nClaimValidHeight));
READWRITE(fIsClaim);
READWRITE(VARINT(nClaimOriginalHeight));
2014-10-18 19:53:37 +02:00
}
};
/** Undo information for a CTransaction */
class CTxUndo
{
public:
// undo information for all txins
2020-02-27 09:55:47 -07:00
std::vector<CTxInUndo> vprevout;
2014-10-18 19:53:37 +02:00
2020-02-27 09:55:47 -07:00
ADD_SERIALIZE_METHODS;
2020-02-27 09:55:47 -07:00
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(vprevout);
2014-10-18 19:53:37 +02: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>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(vtxundo);
}
};
2014-11-03 16:16:40 +01:00
#endif // BITCOIN_UNDO_H