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