BtcExplorer/main.cpp

47 lines
1.3 KiB
C++

#include <iostream>
#include <fstream>
#include <memory>
#include <vector>
#include <chrono>
#include "Models/Block.h"
int main() {
std::string path = "/home/selim/dl/blk00000.dat";
std::fstream file(path);
std::vector<Block> blocks;
auto start = std::chrono::high_resolution_clock::now();
PreBlockHeader header{};
size_t index = 0;
while (true) {
file.read((char*)&header, sizeof(header));
header.magic = (BlockMagic)__builtin_bswap32(header.magic);
if(file.eof()) {
break;
}
auto blockData = std::make_unique<std::byte[]>(header.blockSize);
file.read((char*)blockData.get(), header.blockSize);
blocks.emplace_back(blockData.get(), header.blockSize);
std::cout << "Parsed new block " << index++ << " with size: " << header.blockSize << std::endl;
break;
}
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;
// for(size_t i = 0; i < 100; ++i) {
// std::cout << "version: " << blocks[i].time() << std::endl;
// }
return 0;
}