Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
primitives
block.h
Go to the documentation of this file.
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-present 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
#include <util/time.h>
13
14
#include <cstdint>
15
#include <string>
16
#include <utility>
17
#include <vector>
18
26
class
CBlockHeader
27
{
28
public
:
29
// header
30
int32_t
nVersion
;
31
uint256
hashPrevBlock
;
32
uint256
hashMerkleRoot
;
33
uint32_t
nTime
;
34
uint32_t
nBits
;
35
uint32_t
nNonce
;
36
37
CBlockHeader
()
38
{
39
SetNull
();
40
}
41
42
SERIALIZE_METHODS
(
CBlockHeader
, obj) {
READWRITE
(obj.nVersion, obj.hashPrevBlock, obj.hashMerkleRoot, obj.nTime, obj.nBits, obj.nNonce); }
43
44
void
SetNull
()
45
{
46
nVersion
= 0;
47
hashPrevBlock
.SetNull();
48
hashMerkleRoot
.SetNull();
49
nTime
= 0;
50
nBits
= 0;
51
nNonce
= 0;
52
}
53
54
bool
IsNull
()
const
55
{
56
return
(
nBits
== 0);
57
}
58
59
uint256
GetHash
()
const
;
60
61
NodeSeconds
Time
()
const
62
{
63
return
NodeSeconds
{std::chrono::seconds{
nTime
}};
64
}
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<CTransactionRef>
vtx
;
78
79
// Memory-only flags for caching expensive checks
80
mutable
bool
fChecked
;
// CheckBlock()
81
mutable
bool
m_checked_witness_commitment
{
false
};
// CheckWitnessCommitment()
82
mutable
bool
m_checked_merkle_root
{
false
};
// CheckMerkleRoot()
83
84
CBlock
()
85
{
86
SetNull
();
87
}
88
89
CBlock
(
const
CBlockHeader
&header)
90
{
91
SetNull
();
92
*(
static_cast<
CBlockHeader
*
>
(
this
)) = header;
93
}
94
95
SERIALIZE_METHODS
(
CBlock
, obj)
96
{
97
READWRITE
(
AsBase<CBlockHeader>
(obj), obj.vtx);
98
}
99
100
void
SetNull
()
101
{
102
CBlockHeader::SetNull
();
103
vtx
.clear();
104
fChecked
=
false
;
105
m_checked_witness_commitment
=
false
;
106
m_checked_merkle_root
=
false
;
107
}
108
109
std::string
ToString
()
const
;
110
};
111
116
struct
CBlockLocator
117
{
125
static
constexpr
int
DUMMY_VERSION
= 70016;
126
127
std::vector<uint256>
vHave
;
128
129
CBlockLocator
() =
default
;
130
131
explicit
CBlockLocator
(std::vector<uint256>&& have) :
vHave
(
std
::move(have)) {}
132
133
SERIALIZE_METHODS
(
CBlockLocator
, obj)
134
{
135
int
nVersion =
DUMMY_VERSION
;
136
READWRITE
(nVersion);
137
READWRITE
(obj.vHave);
138
}
139
140
void
SetNull
()
141
{
142
vHave
.clear();
143
}
144
145
bool
IsNull
()
const
146
{
147
return
vHave
.empty();
148
}
149
};
150
151
#endif
// BITCOIN_PRIMITIVES_BLOCK_H
CBlockHeader::Time
NodeSeconds Time() const
Definition
block.h:61
CBlockHeader::nNonce
uint32_t nNonce
Definition
block.h:35
CBlockHeader::SERIALIZE_METHODS
SERIALIZE_METHODS(CBlockHeader, obj)
Definition
block.h:42
CBlockHeader::nBits
uint32_t nBits
Definition
block.h:34
CBlockHeader::CBlockHeader
CBlockHeader()
Definition
block.h:37
CBlockHeader::nTime
uint32_t nTime
Definition
block.h:33
CBlockHeader::GetBlockTime
int64_t GetBlockTime() const
Definition
block.h:66
CBlockHeader::nVersion
int32_t nVersion
Definition
block.h:30
CBlockHeader::hashPrevBlock
uint256 hashPrevBlock
Definition
block.h:31
CBlockHeader::SetNull
void SetNull()
Definition
block.h:44
CBlockHeader::hashMerkleRoot
uint256 hashMerkleRoot
Definition
block.h:32
CBlockHeader::GetHash
uint256 GetHash() const
Definition
block.cpp:15
CBlockHeader::IsNull
bool IsNull() const
Definition
block.h:54
CBlock::SetNull
void SetNull()
Definition
block.h:100
CBlock::ToString
std::string ToString() const
Definition
block.cpp:20
CBlock::m_checked_merkle_root
bool m_checked_merkle_root
Definition
block.h:82
CBlock::vtx
std::vector< CTransactionRef > vtx
Definition
block.h:77
CBlock::SERIALIZE_METHODS
SERIALIZE_METHODS(CBlock, obj)
Definition
block.h:95
CBlock::m_checked_witness_commitment
bool m_checked_witness_commitment
Definition
block.h:81
CBlock::CBlock
CBlock()
Definition
block.h:84
CBlock::CBlock
CBlock(const CBlockHeader &header)
Definition
block.h:89
CBlock::fChecked
bool fChecked
Definition
block.h:80
uint256
256-bit opaque blob.
Definition
uint256.h:195
std
Definition
common.h:29
transaction.h
serialize.h
AsBase
Out & AsBase(In &x)
Convert any argument to a reference to X, maintaining constness.
Definition
serialize.h:133
READWRITE
#define READWRITE(...)
Definition
serialize.h:145
CBlockLocator::SERIALIZE_METHODS
SERIALIZE_METHODS(CBlockLocator, obj)
Definition
block.h:133
CBlockLocator::vHave
std::vector< uint256 > vHave
Definition
block.h:127
CBlockLocator::IsNull
bool IsNull() const
Definition
block.h:145
CBlockLocator::CBlockLocator
CBlockLocator(std::vector< uint256 > &&have)
Definition
block.h:131
CBlockLocator::DUMMY_VERSION
static constexpr int DUMMY_VERSION
Historically CBlockLocator's version field has been written to network streams as the negotiated prot...
Definition
block.h:125
CBlockLocator::CBlockLocator
CBlockLocator()=default
CBlockLocator::SetNull
void SetNull()
Definition
block.h:140
uint256.h
NodeSeconds
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds
Definition
time.h:25
Generated on
for Bitcoin Core by
1.17.0