Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

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) {
40  READWRITE(this->nVersion);
46  }
47 
48  void SetNull()
49  {
50  nVersion = 0;
53  nTime = 0;
54  nBits = 0;
55  nNonce = 0;
56  }
57 
58  bool IsNull() const
59  {
60  return (nBits == 0);
61  }
62 
63  uint256 GetHash() const;
64 
65  int64_t GetBlockTime() const
66  {
67  return (int64_t)nTime;
68  }
69 };
70 
71 
72 class CBlock : public CBlockHeader
73 {
74 public:
75  // network and disk
76  std::vector<CTransactionRef> vtx;
77 
78  // memory only
79  mutable bool fChecked;
80 
82  {
83  SetNull();
84  }
85 
86  CBlock(const CBlockHeader &header)
87  {
88  SetNull();
89  *((CBlockHeader*)this) = header;
90  }
91 
93 
94  template <typename Stream, typename Operation>
95  inline void SerializationOp(Stream& s, Operation ser_action) {
96  READWRITE(*(CBlockHeader*)this);
97  READWRITE(vtx);
98  }
99 
100  void SetNull()
101  {
103  vtx.clear();
104  fChecked = false;
105  }
106 
108  {
109  CBlockHeader block;
110  block.nVersion = nVersion;
113  block.nTime = nTime;
114  block.nBits = nBits;
115  block.nNonce = nNonce;
116  return block;
117  }
118 
119  std::string ToString() const;
120 };
121 
122 
128 {
129  std::vector<uint256> vHave;
130 
132 
133  explicit CBlockLocator(const std::vector<uint256>& vHaveIn) : vHave(vHaveIn) {}
134 
136 
137  template <typename Stream, typename Operation>
138  inline void SerializationOp(Stream& s, Operation ser_action) {
139  int nVersion = s.GetVersion();
140  if (!(s.GetType() & SER_GETHASH))
141  READWRITE(nVersion);
142  READWRITE(vHave);
143  }
144 
145  void SetNull()
146  {
147  vHave.clear();
148  }
149 
150  bool IsNull() const
151  {
152  return vHave.empty();
153  }
154 };
155 
156 #endif // BITCOIN_PRIMITIVES_BLOCK_H
uint32_t nNonce
Definition: block.h:29
CBlockHeader()
Definition: block.h:31
CBlockLocator()
Definition: block.h:131
CBlockHeader GetBlockHeader() const
Definition: block.h:107
void SetNull()
Definition: uint256.h:41
Describes a place in the block chain to another node such that if the other node doesn&#39;t have the sam...
Definition: block.h:127
#define READWRITE(obj)
Definition: serialize.h:165
Definition: block.h:72
CBlock(const CBlockHeader &header)
Definition: block.h:86
void SerializationOp(Stream &s, Operation ser_action)
Definition: block.h:95
std::string ToString() const
Definition: block.cpp:22
ADD_SERIALIZE_METHODS
Definition: block.h:92
bool IsNull() const
Definition: block.h:150
CBlock()
Definition: block.h:81
uint32_t nTime
Definition: block.h:27
void SetNull()
Definition: block.h:145
uint256 hashMerkleRoot
Definition: block.h:26
void SerializationOp(Stream &s, Operation ser_action)
Definition: block.h:138
uint256 hashPrevBlock
Definition: block.h:25
ADD_SERIALIZE_METHODS
Definition: block.h:36
void SetNull()
Definition: block.h:48
std::vector< uint256 > vHave
Definition: block.h:129
int64_t GetBlockTime() const
Definition: block.h:65
CBlockLocator(const std::vector< uint256 > &vHaveIn)
Definition: block.h:133
uint256 GetHash() const
Definition: block.cpp:14
256-bit opaque blob.
Definition: uint256.h:123
std::vector< CTransactionRef > vtx
Definition: block.h:76
void SerializationOp(Stream &s, Operation ser_action)
Definition: block.h:39
void SetNull()
Definition: block.h:100
bool IsNull() const
Definition: block.h:58
bool fChecked
Definition: block.h:79
int32_t nVersion
Definition: block.h:24
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:20
uint32_t nBits
Definition: block.h:28
ADD_SERIALIZE_METHODS
Definition: block.h:135
Released under the MIT license