Bitcoin Core
21.99.0
P2P Digital Currency
src
primitives
block.h
Go to the documentation of this file.
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-2020 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
9
#include <
primitives/transaction.h
>
10
#include <
serialize.h
>
11
#include <
uint256.h
>
12
20
class
CBlockHeader
21
{
22
public
:
23
// header
24
int32_t
nVersion
;
25
uint256
hashPrevBlock
;
26
uint256
hashMerkleRoot
;
27
uint32_t
nTime
;
28
uint32_t
nBits
;
29
uint32_t
nNonce
;
30
31
CBlockHeader
()
32
{
33
SetNull
();
34
}
35
36
SERIALIZE_METHODS
(
CBlockHeader
, obj) {
READWRITE
(obj.nVersion, obj.hashPrevBlock, obj.hashMerkleRoot, obj.nTime, obj.nBits, obj.nNonce); }
37
38
void
SetNull
()
39
{
40
nVersion
= 0;
41
hashPrevBlock
.
SetNull
();
42
hashMerkleRoot
.
SetNull
();
43
nTime
= 0;
44
nBits
= 0;
45
nNonce
= 0;
46
}
47
48
bool
IsNull
()
const
49
{
50
return
(
nBits
== 0);
51
}
52
53
uint256
GetHash
()
const
;
54
55
int64_t
GetBlockTime
()
const
56
{
57
return
(int64_t)
nTime
;
58
}
59
};
60
61
62
class
CBlock
:
public
CBlockHeader
63
{
64
public
:
65
// network and disk
66
std::vector<CTransactionRef>
vtx
;
67
68
// memory only
69
mutable
bool
fChecked
;
70
71
CBlock
()
72
{
73
SetNull
();
74
}
75
76
CBlock
(
const
CBlockHeader
&header)
77
{
78
SetNull
();
79
*(
static_cast<
CBlockHeader
*
>
(
this
)) = header;
80
}
81
82
SERIALIZE_METHODS
(
CBlock
, obj)
83
{
84
READWRITEAS
(
CBlockHeader
, obj);
85
READWRITE
(obj.vtx);
86
}
87
88
void
SetNull
()
89
{
90
CBlockHeader::SetNull
();
91
vtx
.clear();
92
fChecked
=
false
;
93
}
94
95
CBlockHeader
GetBlockHeader
()
const
96
{
97
CBlockHeader
block;
98
block.
nVersion
=
nVersion
;
99
block.
hashPrevBlock
=
hashPrevBlock
;
100
block.
hashMerkleRoot
=
hashMerkleRoot
;
101
block.
nTime
=
nTime
;
102
block.
nBits
=
nBits
;
103
block.
nNonce
=
nNonce
;
104
return
block;
105
}
106
107
std::string
ToString
()
const
;
108
};
109
114
struct
CBlockLocator
115
{
116
std::vector<uint256>
vHave
;
117
118
CBlockLocator
() {}
119
120
explicit
CBlockLocator
(
const
std::vector<uint256>& vHaveIn) :
vHave
(vHaveIn) {}
121
122
SERIALIZE_METHODS
(
CBlockLocator
, obj)
123
{
124
int
nVersion = s.GetVersion();
125
if
(!(s.GetType() &
SER_GETHASH
))
126
READWRITE
(nVersion);
127
READWRITE
(obj.vHave);
128
}
129
130
void
SetNull
()
131
{
132
vHave
.clear();
133
}
134
135
bool
IsNull
()
const
136
{
137
return
vHave
.empty();
138
}
139
};
140
141
#endif // BITCOIN_PRIMITIVES_BLOCK_H
CBlockLocator::CBlockLocator
CBlockLocator()
Definition:
block.h:118
CBlockHeader::hashMerkleRoot
uint256 hashMerkleRoot
Definition:
block.h:26
CBlockHeader::CBlockHeader
CBlockHeader()
Definition:
block.h:31
CBlockHeader::IsNull
bool IsNull() const
Definition:
block.h:48
CBlockHeader::nBits
uint32_t nBits
Definition:
block.h:28
CBlockHeader
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition:
block.h:20
transaction.h
CBlockHeader::nVersion
int32_t nVersion
Definition:
block.h:24
uint256.h
CBlockLocator::IsNull
bool IsNull() const
Definition:
block.h:135
base_blob::SetNull
void SetNull()
Definition:
uint256.h:39
CBlockLocator::SERIALIZE_METHODS
SERIALIZE_METHODS(CBlockLocator, obj)
Definition:
block.h:122
CBlockLocator::SetNull
void SetNull()
Definition:
block.h:130
READWRITEAS
#define READWRITEAS(type, obj)
Definition:
serialize.h:176
CBlockHeader::GetHash
uint256 GetHash() const
Definition:
block.cpp:11
CBlockHeader::nNonce
uint32_t nNonce
Definition:
block.h:29
CBlock::fChecked
bool fChecked
Definition:
block.h:69
CBlock::SERIALIZE_METHODS
SERIALIZE_METHODS(CBlock, obj)
Definition:
block.h:82
CBlockHeader::GetBlockTime
int64_t GetBlockTime() const
Definition:
block.h:55
CBlock::CBlock
CBlock()
Definition:
block.h:71
CBlockHeader::SERIALIZE_METHODS
SERIALIZE_METHODS(CBlockHeader, obj)
Definition:
block.h:36
CBlock::CBlock
CBlock(const CBlockHeader &header)
Definition:
block.h:76
CBlockHeader::nTime
uint32_t nTime
Definition:
block.h:27
uint256
256-bit opaque blob.
Definition:
uint256.h:124
READWRITE
#define READWRITE(...)
Definition:
serialize.h:175
CBlockLocator::CBlockLocator
CBlockLocator(const std::vector< uint256 > &vHaveIn)
Definition:
block.h:120
CBlockHeader::SetNull
void SetNull()
Definition:
block.h:38
CBlockHeader::hashPrevBlock
uint256 hashPrevBlock
Definition:
block.h:25
CBlock
Definition:
block.h:62
CBlock::vtx
std::vector< CTransactionRef > vtx
Definition:
block.h:66
CBlockLocator::vHave
std::vector< uint256 > vHave
Definition:
block.h:116
serialize.h
CBlock::ToString
std::string ToString() const
Definition:
block.cpp:16
CBlock::SetNull
void SetNull()
Definition:
block.h:88
CBlockLocator
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition:
block.h:114
SER_GETHASH
@ SER_GETHASH
Definition:
serialize.h:168
CBlock::GetBlockHeader
CBlockHeader GetBlockHeader() const
Definition:
block.h:95
Generated on Mon Apr 19 2021 20:03:41 for Bitcoin Core by
1.8.17