45 lines
917 B
C++
45 lines
917 B
C++
#ifndef BTCEXPLORER_BLOCK_H
|
|
#define BTCEXPLORER_BLOCK_H
|
|
|
|
#include <cstdint>
|
|
#include <array>
|
|
#include <vector>
|
|
|
|
#include "Transaction.h"
|
|
|
|
enum BlockMagic: uint32_t {
|
|
Mainnet = 0xf9beb4d9,
|
|
Testnet3 = 0x0b110907,
|
|
Regtest = 0xfabfb5da
|
|
};
|
|
|
|
struct PreBlockHeader {
|
|
BlockMagic magic;
|
|
uint32_t blockSize;
|
|
};
|
|
|
|
struct BlockHeader {
|
|
uint32_t version;
|
|
std::array<uint8_t,32> prevBlockHeaderHash;
|
|
std::array<uint8_t,32> merkleRootHash;
|
|
uint32_t time;
|
|
uint32_t nBits;
|
|
uint32_t nOnce;
|
|
};
|
|
|
|
class Block {
|
|
private:
|
|
BlockHeader _header;
|
|
std::vector<Transaction> _transactions;
|
|
size_t _size;
|
|
|
|
public:
|
|
Block(const std::byte* pBlock, size_t size);
|
|
[[nodiscard]] uint32_t version() const;
|
|
[[nodiscard]] uint32_t time() const;
|
|
[[nodiscard]] const std::vector<Transaction>& transactions() const;
|
|
[[nodiscard]] size_t size() const;
|
|
};
|
|
|
|
#endif //BTCEXPLORER_BLOCK_H
|