diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0cba2e6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "iostream": "cpp" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..05054c5 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: g++ build active file", + "command": "/usr/bin/g++", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/mine b/mine index 084fa46..bf3fa62 100755 Binary files a/mine and b/mine differ diff --git a/mine.cpp b/mine.cpp index 507626f..f08d5a6 100644 --- a/mine.cpp +++ b/mine.cpp @@ -2,66 +2,93 @@ #include #include #include -using namespace std; +#include +using json = nlohmann::json; struct Output { - int Amount; - string ScriptPubKey; -} + int amount; + std::string scriptPubKey; + std::string scriptPubKeyAsm; + std::string scriptPubKeyType; + std::string scriptPubKeyAddress; +}; struct Input { - string txId; + std::string txId; int vOut; - string scriptSig; - string sequence; - vector witness; - vector prevout; - string scriptSigAsm; + std::string scriptSig; + int sequence; + std::vector witness; + Output prevout; + std::string scriptSigAsm; bool isCoinbase; -} +}; struct Txn { int version; int locktime; - vector vin; - vector vout; + std::vector vin; + std::vector vout; + +}; + +void from_json(const json& j, Output& p) { + j.at("scriptpubkey").get_to(p.scriptPubKey); + j.at("scriptpubkey_asm").get_to(p.scriptPubKeyAsm); + j.at("scriptpubkey_type").get_to(p.scriptPubKeyType); + j.at("scriptpubkey_address").get_to(p.scriptPubKeyAddress); + j.at("value").get_to(p.amount); +} +void from_json(const json& j, Input& p) { + j.at("txid").get_to(p.txId); + j.at("vout").get_to(p.vOut); + j.at("prevout").get_to(p.prevout); + j.at("scriptsig").get_to(p.scriptSig); + j.at("scriptsig_asm").get_to(p.scriptSigAsm); + j.at("witness").get_to(p.witness); + j.at("is_coinbase").get_to(p.isCoinbase); + j.at("sequence").get_to(p.sequence); } -string serialise(string content) { - string serialised; - int sz = content.size(); - return serialised; +void from_json(const json& j, Txn& p) { + j.at("version").get_to(p.version); + j.at("locktime").get_to(p.locktime); + j.at("vin").get_to(p.vin); + j.at("vout").get_to(p.vout); +} + +std::string serialise(Txn t) { + std::string serialised; + return t.vin[0].scriptSig; } int main() { - freopen("output.txt","w",stdout); + freopen("output.txt","w",stdout); + std::ifstream myfile("txns.txt"); + std::string filename; + std::vector txns; - ifstream myfile; - myfile.open("txns.txt"); - string filename; - vector txns; + while (myfile.good()) { + getline(myfile,filename); + txns.push_back(filename); + } - while (myfile.good()) { - getline(myfile,filename); - txns.push_back(filename); - } + myfile.close(); + + for (std::string txn: txns) {//man this outer loop is running approx 8000 times! + std::string path = "mempool/" + txn; + myfile.open(path); + json data = json::parse(myfile); + Txn t; + from_json(data , t); + std::cout< -void from_json(const json& j, T (&t)[N]) { - if (j.size()!=N) { - throw std::runtime_error("size!"); - } - size_t index=0; - for (auto& item : j) { - from_json(item, t[index++]); - } -} +// template +// void from_json(const json& j, T (&t)[N]) { +// if (j.size()!=N) { +// throw std::runtime_error("size!"); +// } +// size_t index=0; +// for (auto& item : j) { +// from_json(item, t[index++]); +// } +// } int main() { std::ifstream f("test.json"); json data = json::parse(f); @@ -33,4 +33,15 @@ int main() { from_json(data, my_array); std::cout<