#include #include #include #include #include #include #include #include "Models/Block.h" #include "Models/VarInt.h" namespace fs = std::filesystem; void processBlock(std::byte* data, size_t size) { VarInt txCount(data + sizeof(BlockHeader)); auto pTxData = data + sizeof(BlockHeader) + txCount.size(); } int main() { std::string dir = "/home/selim/dl/bitcoin/blocks"; //"/home/selim/dl/blocks"; // "/Users/selim/Documents/blk00000.dat"; std::set paths; for (const auto & entry : fs::directory_iterator(dir)) { if(entry.path().filename().string().starts_with("blk")) { paths.insert(entry.path().string()); } } constexpr size_t blockBufferSize = 10*1024*1024; auto blockData = std::make_unique(blockBufferSize); std::vector blocks; auto start = std::chrono::high_resolution_clock::now(); size_t index = 0; for (const auto & path: paths) { std::fstream file(path); std::cout << "Parsing file: " << path << std::endl; PreBlockHeader header{}; while (true) { file.read((char*)&header, sizeof(header)); header.magic = (BlockMagic)__builtin_bswap32(header.magic); if(header.blockSize > blockBufferSize) { std::cout << "Insufficient block buffer size. Exiting" << std::endl; return 0; } if(file.eof()) { break; } file.read((char*)blockData.get(), header.blockSize); processBlock(blockData.get(), header.blockSize); //Block block(blockData.get(), header.blockSize); //blocks.emplace_back(blockData.get(), header.blockSize); //std::cout << "Parsed new block " << index++ << " with size: " << header.blockSize << std::endl; } } auto stop = std::chrono::high_resolution_clock::now(); auto duration = duration_cast(stop - start); std::cout << "Blocks found: " << blocks.size() << std::endl; std::cout << "Duration: " << double(duration.count())/1000000 << " seconds" << std::endl; return 0; }