Dash Core  0.12.2.1
P2P Digital Currency
block.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core 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_PRIMITIVES_BLOCK_H
7 #define BITCOIN_PRIMITIVES_BLOCK_H
8 
10 #include "serialize.h"
11 #include "uint256.h"
12 
21 {
22 public:
23  // header
24  int32_t nVersion;
27  uint32_t nTime;
28  uint32_t nBits;
29  uint32_t nNonce;
30 
32  {
33  SetNull();
34  }
35 
37 
38  template <typename Stream, typename Operation>
39  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
40  READWRITE(this->nVersion);
41  nVersion = this->nVersion;
42  READWRITE(hashPrevBlock);
47  }
48 
49  void SetNull()
50  {
51  nVersion = 0;
54  nTime = 0;
55  nBits = 0;
56  nNonce = 0;
57  }
58 
59  bool IsNull() const
60  {
61  return (nBits == 0);
62  }
63 
64  uint256 GetHash() const;
65 
66  int64_t GetBlockTime() const
67  {
68  return (int64_t)nTime;
69  }
70 };
71 
72 
73 class CBlock : public CBlockHeader
74 {
75 public:
76  // network and disk
77  std::vector<CTransaction> vtx;
78 
79  // memory only
80  mutable CTxOut txoutMasternode; // masternode payment
81  mutable std::vector<CTxOut> voutSuperblock; // superblock payment
82  mutable bool fChecked;
83 
85  {
86  SetNull();
87  }
88 
89  CBlock(const CBlockHeader &header)
90  {
91  SetNull();
92  *((CBlockHeader*)this) = header;
93  }
94 
96 
97  template <typename Stream, typename Operation>
98  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
99  READWRITE(*(CBlockHeader*)this);
100  READWRITE(vtx);
101  }
102 
103  void SetNull()
104  {
106  vtx.clear();
108  voutSuperblock.clear();
109  fChecked = false;
110  }
111 
113  {
114  CBlockHeader block;
115  block.nVersion = nVersion;
118  block.nTime = nTime;
119  block.nBits = nBits;
120  block.nNonce = nNonce;
121  return block;
122  }
123 
124  std::string ToString() const;
125 };
126 
127 
133 {
134  std::vector<uint256> vHave;
135 
137 
138  CBlockLocator(const std::vector<uint256>& vHaveIn)
139  {
140  vHave = vHaveIn;
141  }
142 
144 
145  template <typename Stream, typename Operation>
146  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
147  if (!(nType & SER_GETHASH))
148  READWRITE(nVersion);
149  READWRITE(vHave);
150  }
151 
152  void SetNull()
153  {
154  vHave.clear();
155  }
156 
157  bool IsNull() const
158  {
159  return vHave.empty();
160  }
161 };
162 
163 #endif // BITCOIN_PRIMITIVES_BLOCK_H
void SetNull()
Definition: block.h:103
ADD_SERIALIZE_METHODS
Definition: block.h:143
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: block.h:146
void SetNull()
Definition: uint256.h:41
#define READWRITE(obj)
Definition: serialize.h:175
uint256 hashMerkleRoot
Definition: block.h:26
CTxOut txoutMasternode
Definition: block.h:80
void SetNull()
Definition: block.h:49
int64_t GetBlockTime() const
Definition: block.h:66
bool IsNull() const
Definition: block.h:157
std::vector< CTxOut > voutSuperblock
Definition: block.h:81
uint32_t nTime
Definition: block.h:27
bool fChecked
Definition: block.h:82
CBlockLocator(const std::vector< uint256 > &vHaveIn)
Definition: block.h:138
std::vector< CTransaction > vtx
Definition: block.h:77
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: block.h:98
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: block.h:39
CBlockLocator()
Definition: block.h:136
uint256 hashPrevBlock
Definition: block.h:25
ADD_SERIALIZE_METHODS
Definition: block.h:36
uint32_t nBits
Definition: block.h:28
std::string ToString() const
Definition: block.cpp:18
CBlock()
Definition: block.h:84
CBlock(const CBlockHeader &header)
Definition: block.h:89
uint32_t nNonce
Definition: block.h:29
void SetNull()
Definition: block.h:152
ADD_SERIALIZE_METHODS
Definition: block.h:95
int32_t nVersion
Definition: block.h:24
bool IsNull() const
Definition: block.h:59
CBlockHeader GetBlockHeader() const
Definition: block.h:112
CBlockHeader()
Definition: block.h:31
Definition: block.h:73
uint256 GetHash() const
Definition: block.cpp:13
std::vector< uint256 > vHave
Definition: block.h:134