Changeset View
Changeset View
Standalone View
Standalone View
src/primitives/block.h
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_PRIMITIVES_BLOCK_H | #ifndef BITCOIN_PRIMITIVES_BLOCK_H | ||||
#define BITCOIN_PRIMITIVES_BLOCK_H | #define BITCOIN_PRIMITIVES_BLOCK_H | ||||
#include <primitives/blockhash.h> | |||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <uint256.h> | #include <uint256.h> | ||||
/** | /** | ||||
* Nodes collect new transactions into a block, hash them into a hash tree, and | * Nodes collect new transactions into a block, hash them into a hash tree, and | ||||
* scan through nonce values to make the block's hash satisfy proof-of-work | * scan through nonce values to make the block's hash satisfy proof-of-work | ||||
* requirements. When they solve the proof-of-work, they broadcast the block to | * requirements. When they solve the proof-of-work, they broadcast the block to | ||||
* everyone and the block is added to the block chain. The first transaction in | * everyone and the block is added to the block chain. The first transaction in | ||||
* the block is a special one that creates a new coin owned by the creator of | * the block is a special one that creates a new coin owned by the creator of | ||||
* the block. | * the block. | ||||
*/ | */ | ||||
class CBlockHeader { | class CBlockHeader { | ||||
public: | public: | ||||
// header | // header | ||||
int32_t nVersion; | int32_t nVersion; | ||||
uint256 hashPrevBlock; | BlockHash hashPrevBlock; | ||||
uint256 hashMerkleRoot; | uint256 hashMerkleRoot; | ||||
uint32_t nTime; | uint32_t nTime; | ||||
uint32_t nBits; | uint32_t nBits; | ||||
uint32_t nNonce; | uint32_t nNonce; | ||||
CBlockHeader() { SetNull(); } | CBlockHeader() { SetNull(); } | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(this->nVersion); | READWRITE(this->nVersion); | ||||
READWRITE(hashPrevBlock); | READWRITE(hashPrevBlock); | ||||
READWRITE(hashMerkleRoot); | READWRITE(hashMerkleRoot); | ||||
READWRITE(nTime); | READWRITE(nTime); | ||||
READWRITE(nBits); | READWRITE(nBits); | ||||
READWRITE(nNonce); | READWRITE(nNonce); | ||||
} | } | ||||
void SetNull() { | void SetNull() { | ||||
nVersion = 0; | nVersion = 0; | ||||
hashPrevBlock.SetNull(); | hashPrevBlock = BlockHash(); | ||||
hashMerkleRoot.SetNull(); | hashMerkleRoot.SetNull(); | ||||
nTime = 0; | nTime = 0; | ||||
nBits = 0; | nBits = 0; | ||||
nNonce = 0; | nNonce = 0; | ||||
} | } | ||||
bool IsNull() const { return (nBits == 0); } | bool IsNull() const { return (nBits == 0); } | ||||
uint256 GetHash() const; | BlockHash GetHash() const; | ||||
int64_t GetBlockTime() const { return (int64_t)nTime; } | int64_t GetBlockTime() const { return (int64_t)nTime; } | ||||
}; | }; | ||||
class CBlock : public CBlockHeader { | class CBlock : public CBlockHeader { | ||||
public: | public: | ||||
// network and disk | // network and disk | ||||
std::vector<CTransactionRef> vtx; | std::vector<CTransactionRef> vtx; | ||||
Show All 37 Lines | |||||
}; | }; | ||||
/** | /** | ||||
* Describes a place in the block chain to another node such that if the other | * Describes a place in the block chain to another node such that if the other | ||||
* node doesn't have the same branch, it can find a recent common trunk. The | * node doesn't have the same branch, it can find a recent common trunk. The | ||||
* further back it is, the further before the fork it may be. | * further back it is, the further before the fork it may be. | ||||
*/ | */ | ||||
struct CBlockLocator { | struct CBlockLocator { | ||||
std::vector<uint256> vHave; | std::vector<BlockHash> vHave; | ||||
CBlockLocator() {} | CBlockLocator() {} | ||||
explicit CBlockLocator(const std::vector<uint256> &vHaveIn) | explicit CBlockLocator(const std::vector<BlockHash> &vHaveIn) | ||||
: vHave(vHaveIn) {} | : vHave(vHaveIn) {} | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
int nVersion = s.GetVersion(); | int nVersion = s.GetVersion(); | ||||
if (!(s.GetType() & SER_GETHASH)) { | if (!(s.GetType() & SER_GETHASH)) { | ||||
Show All 11 Lines |