Skip to content

Commit

Permalink
Mining only p2wpkh txns
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushj05 committed Apr 8, 2024
1 parent b95e7af commit 559bac2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
Binary file modified bin/main
Binary file not shown.
6 changes: 3 additions & 3 deletions output.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
2000000000000000000000000000000000000000000000000000000000000000000000002523173839330bc5f136f4b5b17784604d27227645f2831feb5a0e64e195f0ac7f0c1466ffff001f0001086d
010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff0403951a06ffffffff02a4de4125000000001976a9142c30a6aaac6d96687291475d7d52f4b469f665a688ac0000000000000000266a24aa21a9ed026385796235b3225e7b4417be377244371535b3717e332e1c0bbc5db2457c710120000000000000000000000000000000000000000000000000000000000000000000000000
3bbb1bd963829caaf4ad2351db98a8cc39f18cafbd8ffbf3803627e3d64c7148
20000000000000000000000000000000000000000000000000000000000000000000000047c7da17888a6de293e9a2ea4da7cff57533df2ad9cc1c483f8f8d992802c9792f101466ffff001f0004a0e2
010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff0403951a06ffffffff02a4de4125000000001976a9142c30a6aaac6d96687291475d7d52f4b469f665a688ac0000000000000000266a24aa21a9ed52885e31e3822e0d515b45917847c59ba4b9dfc2a9311c962a7209c86e1aa14e0120000000000000000000000000000000000000000000000000000000000000000000000000
84158f8f7c0edd7c195ea322cfd70a9a835d40c8e71bd12f9385fcc91f6d9241
e6d870ecd3e78026506da94b80411048053758e2f8f248061b553bfe15e76392
d683f4a8105bdbc816b5afb478845ebcddb8af1a3b24fdebbb1ec7b3e3fe0ddd
e5c0a41f3cd0a84ffb9453018fa0fb4f97b730bb6c59ff330739f171810e75eb
Expand Down
15 changes: 5 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void mine() {

vector<string> blockTxns;
vector<string> blockTxnIds;
vector<string> wTXIDs;
int64_t reward = 625000000;
uint32_t block_size = 80;

Expand All @@ -55,23 +56,17 @@ void mine() {

if (block_size + ser_txn.size() < 1024*1024 && verify_txn(txn.second) >= 0) {
blockTxns.push_back(ser_txn);
wTXIDs.push_back(hash256(get_wTXID(txn.second)));
block_size += ser_txn.size();
reward += txn.first;
}
}

// Calculate TXIDs of all the transactions to be included in the block
for (string txn : blockTxns) {
char sha[SHA256_DIGEST_LENGTH];
SHA256((unsigned char*) txn.c_str(), txn.length(), (unsigned char*) sha);
SHA256((unsigned char*) sha, SHA256_DIGEST_LENGTH, (unsigned char*) sha);
string txid = "";
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
txid.push_back(sha[i]);
blockTxnIds.push_back(txid);
}
for (string txn : blockTxns)
blockTxnIds.push_back(hash256(txn));

vector<string> wTXIDs = blockTxnIds;

wTXIDs.push_back(string(32, 0));
string wTXID_commitment = hash256(getMerkleRoot(wTXIDs) + string(32, 0));
string coinbaseTxn = genCoinbaseTxn(reward, wTXID_commitment);
Expand Down
5 changes: 1 addition & 4 deletions src/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ string get_wTXID (Json::Value txn) {
}

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

ser_txn += int2compact(inp["witness"].size());
Expand Down

0 comments on commit 559bac2

Please sign in to comment.