PRCYCoin  2.0.0.7rc1
P2P Digital Currency
undo.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2013 The Bitcoin developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_UNDO_H
7 #define BITCOIN_UNDO_H
8 
9 #include "chain.h"
10 #include "compressor.h"
11 #include "primitives/transaction.h"
12 #include "serialize.h"
13 
20 class CTxInUndo
21 {
22 public:
23  CTxOut txout; // the txout data before being spent
24  bool fCoinBase; // if the outpoint was the last unspent: whether it belonged to a coinbase
25  bool fCoinStake;
26  unsigned int nHeight; // if the outpoint was the last unspent: its height
27  int nVersion; // if the outpoint was the last unspent: its version
28 
29  CTxInUndo() : txout(), fCoinBase(false), fCoinStake(false), nHeight(0), nVersion(0) {}
30  CTxInUndo(const CTxOut& txoutIn, bool fCoinBaseIn = false, bool fCoinStakeIn = false, unsigned int nHeightIn = 0, int nVersionIn = 0) : txout(txoutIn), fCoinBase(fCoinBaseIn), fCoinStake(fCoinStakeIn), nHeight(nHeightIn), nVersion(nVersionIn) {}
31 
32  unsigned int GetSerializeSize(int nType, int nVersion) const
33  {
34  return ::GetSerializeSize(VARINT(nHeight * 4 + (fCoinBase ? 2 : 0) + (fCoinStake ? 1 : 0)), nType, nVersion) +
35  (nHeight > 0 ? ::GetSerializeSize(VARINT(this->nVersion), nType, nVersion) : 0) +
37  }
38 
39  template <typename Stream>
40  void Serialize(Stream& s, int nType, int nVersion) const
41  {
42  ::Serialize(s, VARINT(nHeight * 4 + (fCoinBase ? 2 : 0) + (fCoinStake ? 1 : 0)), nType, nVersion);
43  if (nHeight > 0)
44  ::Serialize(s, VARINT(this->nVersion), nType, nVersion);
46  }
47 
48  template <typename Stream>
49  void Unserialize(Stream& s, int nType, int nVersion)
50  {
51  unsigned int nCode = 0;
52  ::Unserialize(s, VARINT(nCode), nType, nVersion);
53  nHeight = nCode >> 2;
54  fCoinBase = nCode & 2;
55  fCoinStake = nCode & 1;
56  if (nHeight > 0)
57  ::Unserialize(s, VARINT(this->nVersion), nType, nVersion);
59  }
60 };
61 
63 class CTxUndo
64 {
65 public:
66  // undo information for all txins
67  std::vector<CTxInUndo> vprevout;
68 
70 
71  template <typename Stream, typename Operation>
72  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
73  {
75  }
76 };
77 
80 {
81 public:
82  std::vector<CTxUndo> vtxundo; // for all but the coinbase
83 
85 
86  template <typename Stream, typename Operation>
87  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
88  {
90  }
91 
92  bool WriteToDisk(CDiskBlockPos& pos, const uint256& hashBlock);
93  bool ReadFromDisk(const CDiskBlockPos& pos, const uint256& hashBlock);
94 };
95 
96 #endif // BITCOIN_UNDO_H
CTxInUndo::CTxInUndo
CTxInUndo()
Definition: undo.h:29
transaction.h
CTxUndo
Undo information for a CTransaction.
Definition: undo.h:63
CTxInUndo::nVersion
int nVersion
Definition: undo.h:27
CBlockUndo::ReadFromDisk
bool ReadFromDisk(const CDiskBlockPos &pos, const uint256 &hashBlock)
Definition: main.cpp:7200
CTxInUndo::fCoinStake
bool fCoinStake
Definition: undo.h:25
GetSerializeSize
unsigned int GetSerializeSize(char a, int, int=0)
Definition: serialize.h:194
CTxInUndo::txout
CTxOut txout
Definition: undo.h:23
CTxInUndo::nHeight
unsigned int nHeight
Definition: undo.h:26
CBlockUndo::vtxundo
std::vector< CTxUndo > vtxundo
Definition: undo.h:82
CTxInUndo::Serialize
void Serialize(Stream &s, int nType, int nVersion) const
Definition: undo.h:40
CTxUndo::ADD_SERIALIZE_METHODS
ADD_SERIALIZE_METHODS
Definition: undo.h:69
compressor.h
CTxInUndo::GetSerializeSize
unsigned int GetSerializeSize(int nType, int nVersion) const
Definition: undo.h:32
CTxOut
An output of a transaction.
Definition: transaction.h:164
VARINT
#define VARINT(obj)
Definition: serialize.h:366
CDiskBlockPos
Definition: chain.h:76
CBlockUndo::SerializationOp
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: undo.h:87
CTxInUndo::CTxInUndo
CTxInUndo(const CTxOut &txoutIn, bool fCoinBaseIn=false, bool fCoinStakeIn=false, unsigned int nHeightIn=0, int nVersionIn=0)
Definition: undo.h:30
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
chain.h
CTxOutCompressor
wrapper for CTxOut that provides a more compact serialization
Definition: compressor.h:106
READWRITE
#define READWRITE(obj)
Definition: serialize.h:164
CBlockUndo::WriteToDisk
bool WriteToDisk(CDiskBlockPos &pos, const uint256 &hashBlock)
Definition: main.cpp:7173
serialize.h
CTxInUndo::Unserialize
void Unserialize(Stream &s, int nType, int nVersion)
Definition: undo.h:49
CTxInUndo
Undo information for a CTxIn.
Definition: undo.h:20
CTxUndo::SerializationOp
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: undo.h:72
CBlockUndo::ADD_SERIALIZE_METHODS
ADD_SERIALIZE_METHODS
Definition: undo.h:84
CTxUndo::vprevout
std::vector< CTxInUndo > vprevout
Definition: undo.h:67
REF
T & REF(const T &val)
Used to bypass the rule against non-const reference to temporary where it makes sense with wrappers s...
Definition: serialize.h:34
CBlockUndo
Undo information for a CBlock.
Definition: undo.h:79
CTxInUndo::fCoinBase
bool fCoinBase
Definition: undo.h:24