|
10 | 10 | #include "net.h"
|
11 | 11 | #include "wallet.h"
|
12 | 12 |
|
13 |
| -#ifdef ENABLE_WALLET |
14 |
| -// These globals are only used by the built-in miner |
15 |
| -double dHashesPerSec = 0.0; |
16 |
| -int64_t nHPSTimerStart = 0; |
17 |
| -#endif |
18 |
| - |
19 | 13 | //////////////////////////////////////////////////////////////////////////////
|
20 | 14 | //
|
21 | 15 | // BitcoinMiner
|
@@ -57,41 +51,6 @@ void SHA256Transform(void* pstate, void* pinput, const void* pinit)
|
57 | 51 | ((uint32_t*)pstate)[i] = ctx.h[i];
|
58 | 52 | }
|
59 | 53 |
|
60 |
| -// |
61 |
| -// ScanHash scans nonces looking for a hash with at least some zero bits. |
62 |
| -// It operates on big endian data. Caller does the byte reversing. |
63 |
| -// All input buffers are 16-byte aligned. nNonce is usually preserved |
64 |
| -// between calls, but periodically or if nNonce is 0xffff0000 or above, |
65 |
| -// the block is rebuilt and nNonce starts over at zero. |
66 |
| -// |
67 |
| -unsigned int static ScanHash_CryptoPP(char* pmidstate, char* pdata, char* phash1, char* phash, unsigned int& nHashesDone) |
68 |
| -{ |
69 |
| - unsigned int& nNonce = *(unsigned int*)(pdata + 12); |
70 |
| - for (;;) |
71 |
| - { |
72 |
| - // Crypto++ SHA256 |
73 |
| - // Hash pdata using pmidstate as the starting state into |
74 |
| - // pre-formatted buffer phash1, then hash phash1 into phash |
75 |
| - nNonce++; |
76 |
| - SHA256Transform(phash1, pdata, pmidstate); |
77 |
| - SHA256Transform(phash, phash1, pSHA256InitState); |
78 |
| - |
79 |
| - // Return the nonce if the hash has at least some zero bits, |
80 |
| - // caller will check if it has enough to reach the target |
81 |
| - if (((unsigned short*)phash)[14] == 0) |
82 |
| - return nNonce; |
83 |
| - |
84 |
| - // If nothing found after trying for a while, return -1 |
85 |
| - if ((nNonce & 0xffff) == 0) |
86 |
| - { |
87 |
| - nHashesDone = 0xffff+1; |
88 |
| - return (unsigned int) -1; |
89 |
| - } |
90 |
| - if ((nNonce & 0xfff) == 0) |
91 |
| - boost::this_thread::interruption_point(); |
92 |
| - } |
93 |
| -} |
94 |
| - |
95 | 54 | // Some explaining would be appreciated
|
96 | 55 | class COrphan
|
97 | 56 | {
|
@@ -384,18 +343,6 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
384 | 343 | return pblocktemplate.release();
|
385 | 344 | }
|
386 | 345 |
|
387 |
| -#ifdef ENABLE_WALLET |
388 |
| -CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) |
389 |
| -{ |
390 |
| - CPubKey pubkey; |
391 |
| - if (!reservekey.GetReservedKey(pubkey)) |
392 |
| - return NULL; |
393 |
| - |
394 |
| - CScript scriptPubKey = CScript() << pubkey << OP_CHECKSIG; |
395 |
| - return CreateNewBlock(scriptPubKey); |
396 |
| -} |
397 |
| -#endif |
398 |
| - |
399 | 346 | void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
|
400 | 347 | {
|
401 | 348 | // Update nExtraNonce
|
@@ -460,6 +407,58 @@ void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash
|
460 | 407 | }
|
461 | 408 |
|
462 | 409 | #ifdef ENABLE_WALLET
|
| 410 | +////////////////////////////////////////////////////////////////////////////// |
| 411 | +// |
| 412 | +// Internal miner |
| 413 | +// |
| 414 | +double dHashesPerSec = 0.0; |
| 415 | +int64_t nHPSTimerStart = 0; |
| 416 | + |
| 417 | +// |
| 418 | +// ScanHash scans nonces looking for a hash with at least some zero bits. |
| 419 | +// It operates on big endian data. Caller does the byte reversing. |
| 420 | +// All input buffers are 16-byte aligned. nNonce is usually preserved |
| 421 | +// between calls, but periodically or if nNonce is 0xffff0000 or above, |
| 422 | +// the block is rebuilt and nNonce starts over at zero. |
| 423 | +// |
| 424 | +unsigned int static ScanHash_CryptoPP(char* pmidstate, char* pdata, char* phash1, char* phash, unsigned int& nHashesDone) |
| 425 | +{ |
| 426 | + unsigned int& nNonce = *(unsigned int*)(pdata + 12); |
| 427 | + for (;;) |
| 428 | + { |
| 429 | + // Crypto++ SHA256 |
| 430 | + // Hash pdata using pmidstate as the starting state into |
| 431 | + // pre-formatted buffer phash1, then hash phash1 into phash |
| 432 | + nNonce++; |
| 433 | + SHA256Transform(phash1, pdata, pmidstate); |
| 434 | + SHA256Transform(phash, phash1, pSHA256InitState); |
| 435 | + |
| 436 | + // Return the nonce if the hash has at least some zero bits, |
| 437 | + // caller will check if it has enough to reach the target |
| 438 | + if (((unsigned short*)phash)[14] == 0) |
| 439 | + return nNonce; |
| 440 | + |
| 441 | + // If nothing found after trying for a while, return -1 |
| 442 | + if ((nNonce & 0xffff) == 0) |
| 443 | + { |
| 444 | + nHashesDone = 0xffff+1; |
| 445 | + return (unsigned int) -1; |
| 446 | + } |
| 447 | + if ((nNonce & 0xfff) == 0) |
| 448 | + boost::this_thread::interruption_point(); |
| 449 | + } |
| 450 | +} |
| 451 | + |
| 452 | +CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) |
| 453 | +{ |
| 454 | + CPubKey pubkey; |
| 455 | + if (!reservekey.GetReservedKey(pubkey)) |
| 456 | + return NULL; |
| 457 | + |
| 458 | + CScript scriptPubKey = CScript() << pubkey << OP_CHECKSIG; |
| 459 | + return CreateNewBlock(scriptPubKey); |
| 460 | +} |
| 461 | + |
463 | 462 | bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
|
464 | 463 | {
|
465 | 464 | uint256 hash = pblock->GetHash();
|
|
0 commit comments