Display proof-of-work hash when one is discovered
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
diff --git a/miner.h b/miner.h
index 7639cd7..49bc07d 100644
--- a/miner.h
+++ b/miner.h
@@ -27,6 +27,21 @@ static inline uint32_t swab32(uint32_t v)
return __builtin_bswap32(v);
}
+static inline void swap256(void *dest_p, const void *src_p)
+{
+ uint32_t *dest = dest_p;
+ const uint32_t *src = src_p;
+
+ dest[0] = src[7];
+ dest[1] = src[6];
+ dest[2] = src[5];
+ dest[3] = src[4];
+ dest[4] = src[3];
+ dest[5] = src[2];
+ dest[6] = src[1];
+ dest[7] = src[0];
+}
+
extern bool opt_debug;
extern bool opt_protocol;
extern const uint32_t sha256_init_state[];
@@ -55,4 +70,6 @@ extern bool scanhash_asm32(const unsigned char *midstate,unsigned char *data,
extern int
timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y);
+extern void print_pow(const unsigned char *hash);
+
#endif /* __MINER_H__ */
diff --git a/sha256_4way.c b/sha256_4way.c
index bdc4c23..556a07a 100644
--- a/sha256_4way.c
+++ b/sha256_4way.c
@@ -123,6 +123,9 @@ unsigned int ScanHash_4WaySSE2(const unsigned char *pmidstate, unsigned char *pd
for (i = 0; i < 32/4; i++)
((unsigned int*)phash)[i] = thash[i][j];
+
+ print_pow(phash);
+
*nHashesDone = nonce;
*nNonce_p = nonce + j;
return nonce + j;
diff --git a/sha256_cryptopp.c b/sha256_cryptopp.c
index 1535b6b..4ada480 100644
--- a/sha256_cryptopp.c
+++ b/sha256_cryptopp.c
@@ -110,13 +110,7 @@ bool scanhash_cryptopp(const unsigned char *midstate, unsigned char *data,
stat_ctr++;
if (hash32[7] == 0) {
- char *hexstr;
-
- hexstr = bin2hex(hash, 32);
- fprintf(stderr,
- "DBG: found zeroes in hash:\n%s\n",
- hexstr);
- free(hexstr);
+ print_pow(hash);
*hashes_done = stat_ctr;
return true;
@@ -601,13 +595,7 @@ bool scanhash_asm32(const unsigned char *midstate, unsigned char *data,
stat_ctr++;
if (hash32[7] == 0) {
- char *hexstr;
-
- hexstr = bin2hex(hash, 32);
- fprintf(stderr,
- "DBG: found zeroes in hash:\n%s\n",
- hexstr);
- free(hexstr);
+ print_pow(hash);
*hashes_done = stat_ctr;
return true;
diff --git a/sha256_generic.c b/sha256_generic.c
index 8817d92..91fbbcf 100644
--- a/sha256_generic.c
+++ b/sha256_generic.c
@@ -256,13 +256,7 @@ bool scanhash_c(const unsigned char *midstate, unsigned char *data,
stat_ctr++;
if (hash32[7] == 0) {
- char *hexstr;
-
- hexstr = bin2hex(hash, 32);
- fprintf(stderr,
- "DBG: found zeroes in hash:\n%s\n",
- hexstr);
- free(hexstr);
+ print_pow(hash);
*hashes_done = stat_ctr;
return true;
diff --git a/sha256_via.c b/sha256_via.c
index 94576a4..011d854 100644
--- a/sha256_via.c
+++ b/sha256_via.c
@@ -57,13 +57,7 @@ bool scanhash_via(unsigned char *data_inout,
stat_ctr++;
if (hash32[7] == 0) {
- char *hexstr;
-
- hexstr = bin2hex(tmp_hash, 32);
- fprintf(stderr,
- "DBG: found zeroes in hash:\n%s\n",
- hexstr);
- free(hexstr);
+ print_pow(tmp_hash);
/* swap nonce'd data back into original storage area;
* TODO: only swap back the nonce, rather than all data
diff --git a/util.c b/util.c
index 669dd82..2a52a04 100644
--- a/util.c
+++ b/util.c
@@ -255,3 +255,14 @@ timeval_subtract (
return x->tv_sec < y->tv_sec;
}
+void print_pow(const unsigned char *hash)
+{
+ char *hexstr;
+ unsigned char hash_swap[32];
+
+ swap256(hash_swap, hash);
+ hexstr = bin2hex(hash_swap, 32);
+ fprintf(stderr, "PoW found: %s\n", hexstr);
+ free(hexstr);
+}
+