Skip to content

Commit

Permalink
Mining only p2pkh txns
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushj05 committed Apr 8, 2024
1 parent 5c494a0 commit 6a42e0c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
Binary file modified bin/main
Binary file not shown.
2 changes: 1 addition & 1 deletion output.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2000000000000000000000000000000000000000000000000000000000000000000000008a1965d728a82573d51ae1a46dc45779cdfc73b15509e368dfd80b744033d0e3e4ff1266ffff001f0000f933
2000000000000000000000000000000000000000000000000000000000000000000000008a1965d728a82573d51ae1a46dc45779cdfc73b15509e368dfd80b744033d0e3180c1466ffff001f00002c68
010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff0403951a06ffffffff028ae14025000000001976a9142c30a6aaac6d96687291475d7d52f4b469f665a688ac0000000000000000266a24aa21a9ed67d1e6b1485ccdb1fe1976fb41cc05e6ca5d98b60e808f1b11be06de903e017b0120000000000000000000000000000000000000000000000000000000000000000000000000
567fbbe1ef215719e95dc88075e34b9210168d0ac28fe33e96e999626c6bd690
59e09faf72796071cef91de471f2b1e50945b798ee76085efc08aad6834b9265
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void mine() {
for (auto &txn : transactions) {
bool flag = false;
for (auto &inp : txn.second["vin"]) {
if (inp["prevout"]["scriptpubkey_type"] != "p2pkh" && inp["prevout"]["scriptpubkey_type"] != "v1_p2tr"){
if (inp["prevout"]["scriptpubkey_type"] != "p2pkh"){
flag = true;
break;
}
Expand Down
45 changes: 45 additions & 0 deletions src/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <iostream>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <jsoncpp/json/json.h>
Expand Down Expand Up @@ -118,6 +119,50 @@ string int2compact (uint64_t num) {
return comp;
}

string get_wTXID (Json::Value txn) {
string ser_txn = "";

ser_txn += int2bin(txn["version"].asUInt());
ser_txn += int2compact(txn["vin"].size());

for (auto &inp : txn["vin"]) {
// outpoint
string txid = hexstr2bstr(inp["txid"].asString());
reverse(txid.begin(), txid.end());
ser_txn += txid;
ser_txn += int2bin(inp["vout"].asUInt());

ser_txn += int2compact(inp["scriptsig"].asString().length()/2);
ser_txn += hexstr2bstr(inp["scriptsig"].asString());

ser_txn += int2bin(inp["sequence"].asUInt());
}

ser_txn += int2compact(txn["vout"].size());

for (auto &out : txn["vout"]) {
ser_txn += int2bin(out["value"].asInt64(), IS_INT64_T);
ser_txn += int2compact(out["scriptpubkey"].asString().length()/2);
ser_txn += hexstr2bstr(out["scriptpubkey"].asString());
}

for (auto &inp : txn["vin"]) {
// string_view k = "witness";
// if (inp.find(k.begin(), k.end()) == k.end())
// continue;
if (inp["witness"].empty())
continue;

ser_txn += int2compact(inp["witness"].size());
for (auto &wit : inp["witness"])
ser_txn += int2compact(wit.asString().length()/2) + hexstr2bstr(wit.asString());
}

ser_txn += int2bin(txn["locktime"].asUInt());

return ser_txn;
}

string serialize_txn (Json::Value txn, bool isCleared = false) {
string ser_txn = "";

Expand Down

0 comments on commit 6a42e0c

Please sign in to comment.