2017-11-09 19:34:51 +01:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
|
|
|
|
* Copyright (C) 2009-2010 Satoshi Nakamoto
|
|
|
|
|
* Copyright (C) 2009-2013 The Bitcoin Core developers
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2014-10-18 19:53:37 +02:00
|
|
|
|
2018-01-16 10:47:52 +00:00
|
|
|
#ifndef FLOWEE_UNDO_H
|
|
|
|
|
#define FLOWEE_UNDO_H
|
2014-10-18 19:53:37 +02:00
|
|
|
|
2014-10-19 04:28:43 +02:00
|
|
|
#include "compressor.h"
|
2014-11-18 21:03:02 +00:00
|
|
|
#include "primitives/transaction.h"
|
2014-10-18 19:53:37 +02: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
|
|
|
|
|
* (coinbase or not, height, transaction version)
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
int nVersion; // if the outpoint was the last unspent: its version
|
|
|
|
|
|
|
|
|
|
CTxInUndo() : txout(), fCoinBase(false), nHeight(0), nVersion(0) {}
|
|
|
|
|
CTxInUndo(const CTxOut &txoutIn, bool fCoinBaseIn = false, unsigned int nHeightIn = 0, int nVersionIn = 0) : txout(txoutIn), fCoinBase(fCoinBaseIn), nHeight(nHeightIn), nVersion(nVersionIn) { }
|
|
|
|
|
|
|
|
|
|
unsigned int GetSerializeSize(int nType, int nVersion) const {
|
|
|
|
|
return ::GetSerializeSize(VARINT(nHeight*2+(fCoinBase ? 1 : 0)), nType, nVersion) +
|
|
|
|
|
(nHeight > 0 ? ::GetSerializeSize(VARINT(this->nVersion), nType, nVersion) : 0) +
|
|
|
|
|
::GetSerializeSize(CTxOutCompressor(REF(txout)), nType, nVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Stream>
|
|
|
|
|
void Serialize(Stream &s, int nType, int nVersion) const {
|
|
|
|
|
::Serialize(s, VARINT(nHeight*2+(fCoinBase ? 1 : 0)), nType, nVersion);
|
|
|
|
|
if (nHeight > 0)
|
|
|
|
|
::Serialize(s, VARINT(this->nVersion), nType, nVersion);
|
|
|
|
|
::Serialize(s, CTxOutCompressor(REF(txout)), nType, nVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Stream>
|
|
|
|
|
void Unserialize(Stream &s, int nType, int nVersion) {
|
|
|
|
|
unsigned int nCode = 0;
|
|
|
|
|
::Unserialize(s, VARINT(nCode), nType, nVersion);
|
|
|
|
|
nHeight = nCode / 2;
|
|
|
|
|
fCoinBase = nCode & 1;
|
|
|
|
|
if (nHeight > 0)
|
|
|
|
|
::Unserialize(s, VARINT(this->nVersion), nType, nVersion);
|
|
|
|
|
::Unserialize(s, REF(CTxOutCompressor(REF(txout))), nType, nVersion);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** Undo information for a CTransaction */
|
|
|
|
|
class CTxUndo
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
// undo information for all txins
|
|
|
|
|
std::vector<CTxInUndo> vprevout;
|
|
|
|
|
|
2017-01-19 21:40:34 +01:00
|
|
|
ADD_SERIALIZE_METHODS
|
2014-10-18 19:53:37 +02:00
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
|
|
|
READWRITE(vprevout);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-27 14:42:49 +01:00
|
|
|
/** Undo information for a CBlock */
|
|
|
|
|
class CBlockUndo
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
std::vector<CTxUndo> vtxundo; // for all but the coinbase
|
|
|
|
|
|
2017-01-19 21:40:34 +01:00
|
|
|
ADD_SERIALIZE_METHODS
|
2014-10-27 14:42:49 +01:00
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
|
|
|
READWRITE(vtxundo);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-16 10:47:52 +00:00
|
|
|
#endif
|