Scanning multiple files
This commit is contained in:
parent
9284358def
commit
4465f4c010
@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.19)
|
||||
project(btcexplorer)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
Script::Script(std::span<uint8_t> data, bool coinbase) {
|
||||
Script::Script(std::span<uint8_t> data, bool coinbase): _operations(5) {
|
||||
for(auto iter = data.begin(); iter != data.end();) {
|
||||
ScriptOperation operation;
|
||||
operation.opCode = OpCode(*iter++);
|
||||
@ -67,8 +67,8 @@ std::string Script::address() {
|
||||
|
||||
std::span<uint8_t> Script::publicKey() {
|
||||
switch (_type) {
|
||||
case P2PK: return _operations[0].input;
|
||||
case P2PKH: return _operations[2].input;
|
||||
case P2PK: return _operations[0].input.value();
|
||||
case P2PKH: return _operations[2].input.value();
|
||||
default: return {};
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,8 +154,8 @@ enum ScriptType {
|
||||
};
|
||||
|
||||
struct ScriptOperation {
|
||||
OpCode opCode;
|
||||
std::vector<uint8_t> input;
|
||||
OpCode opCode = OP_INVALIDOPCODE;
|
||||
std::optional<std::vector<uint8_t>> input = std::nullopt;
|
||||
};
|
||||
|
||||
class Script {
|
||||
|
||||
52
main.cpp
52
main.cpp
@ -3,37 +3,44 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <set>
|
||||
|
||||
#include "Models/Block.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
int main() {
|
||||
std::string path = "/Users/selim/Documents/blk00000.dat"; //"/home/selim/dl/blk00000.dat";
|
||||
std::fstream file(path);
|
||||
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();
|
||||
|
||||
PreBlockHeader header{};
|
||||
size_t index = 0;
|
||||
while (true) {
|
||||
file.read((char*)&header, sizeof(header));
|
||||
header.magic = (BlockMagic)__builtin_bswap32(header.magic);
|
||||
for (const auto & path: paths) {
|
||||
std::fstream file(path);
|
||||
std::cout << "Parsing file: " << path << std::endl;
|
||||
|
||||
if(file.eof()) {
|
||||
break;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// if(index == 171) {
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
auto stop = std::chrono::high_resolution_clock::now();
|
||||
@ -41,9 +48,6 @@ int main() {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user