BtcExplorer/main.cpp

59 lines
1.7 KiB
C++

#include <iostream>
#include <fstream>
#include <memory>
#include <vector>
#include <chrono>
#include <filesystem>
#include <set>
#include "Models/Block.h"
namespace fs = std::filesystem;
int main() {
std::string dir = "/home/selim/dl/blocks"; // "/Users/selim/Documents/blk00000.dat";
std::set<fs::path> paths;
for (const auto & entry : fs::directory_iterator(dir))
paths.insert(entry.path().string());
std::vector<Block> 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(file.eof()) {
break;
}
// if(index == 10117) {
// std::cout << "problem block" << std::endl;
// }
auto blockData = std::make_unique<std::byte[]>(header.blockSize);
file.read((char*)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<std::chrono::microseconds>(stop - start);
std::cout << "Blocks found: " << blocks.size() << std::endl;
std::cout << "Duration: " << double(duration.count())/1000000 << " seconds" << std::endl;
return 0;
}