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 7, 2024
1 parent d5c42aa commit 8c5f231
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Binary file modified bin/main
Binary file not shown.
15 changes: 12 additions & 3 deletions output.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
200000000000000000000000000000000000000000000000000000000000000000000000e5b7b43a00f4538e62b642589ddc5b9715585c6b6facc4b7575220412e3a4e8a64f41266ffff001f000031f8
010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff0403951a06ffffffff0277bf4025000000001976a9142c30a6aaac6d96687291475d7d52f4b469f665a688ac0000000000000000266a24aa21a9ed645ca51edf54d5cca1ec2f190d5738d86970c506b86310ce835e08c1b92715770120000000000000000000000000000000000000000000000000000000000000000000000000
2b2d727ffa881b4d782eea4b1b87ea97beebef2c37245fac7c8ee098dba0e07f
20000000000000000000000000000000000000000000000000000000000000000000000000894dc706b52c85eddb6adcc773a6e5a5c0da70991f25bb51f277fb87f114ec43fe1266ffff001f0002a42c
010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff0403951a06ffffffff028ec54025000000001976a9142c30a6aaac6d96687291475d7d52f4b469f665a688ac0000000000000000266a24aa21a9ed4abb2d1b71aafd2f2a65a9c6cd8eaa9e5085e55945de72e1b1337181cdec904c0120000000000000000000000000000000000000000000000000000000000000000000000000
cda35f49af0f4e2590a6a27bf58ab261c38dcedc20e5ecb26cabc580395d8bd4
5c5aac8345686bd466014ef256a503bc896f4186366fb000daea1f90a4143377
379c9c1070725589a0fa9626a59bfab6de21a50e600815be7d6af70edf059f3c
ec6a92468759cecaa854e9b0155d4a94e52c897fe96607d592218664d1165a11
4408e4d4f52837e9504056c8e33b7e921a10c072b520ff810fc938ad1201b652
bd2e7dfc9c1a42accac2fd14f74bbfcf89a2d61352a077aef349ebcbc98c0be5
cb2930faf9670b24e09be9a5a98e72d1b5cfd0dcecb1b1b5452eb85a1ce80ff4
6e0ae197a30f26e0de708f95e52ebb957de42ace5c08ab62092454c58e066f51
c0d67d6cb71d5cd372060a6f508017d0e90167f111a5219a0008cfa5eb37b0fa
0205c30e63e36a248faba5bdbbdde7a4185cb2bd314ae62549578575abb6da72
4ab3cc4296fee78153d60d2884323a84260157db0b83a72309272f109ad9dd32
9 changes: 4 additions & 5 deletions src/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ string getMerkleRoot(vector<string> &txns_included) {
bool start = true;

while (hashQ.size() > 1) {
if ((start || hashQ.size() == prev_size/2) && hashQ.size() % 2 == 1) {
hashQ.push(hashQ.back());
if (start || hashQ.size() == prev_size/2) {
if (hashQ.size() % 2 == 1)
hashQ.push(hashQ.back());
prev_size = hashQ.size();
}
start = false;
Expand Down Expand Up @@ -105,10 +106,8 @@ string calcNonce (string blockHeader) {
for (int i = SHA256_DIGEST_LENGTH - 1; i >= 0; i--)
hash.push_back(sha[i]);

if (hash < target) {
cout << "Hash = " << bstr2hexstr(hash, hash.length()) << endl;
if (hash < target)
return nonce;
}

// Increment nonce
int j = 3;
Expand Down
3 changes: 0 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ void mine() {
int64_t reward = 625000000;
uint32_t block_size = 80;

int count = 0;
for (auto &txn : transactions) {
bool flag = false;
for (auto &inp : txn.second["vin"]) {
Expand All @@ -59,8 +58,6 @@ void mine() {
block_size += ser_txn.size();
reward += txn.first;
}

if (++count == 4) break;
}

// Calculate TXIDs of all the transactions to be included in the block
Expand Down

0 comments on commit 8c5f231

Please sign in to comment.