aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEric Lombrozo <elombrozo@gmail.com>2013-01-08 14:58:06 -0800
committerEric Lombrozo <elombrozo@gmail.com>2013-06-05 23:15:20 -0700
commitaabdf9e899e9024927c26c194ad38142495f80bf (patch)
tree736c1df9b5cd042539083b5326b5a684c30a27bb /src
parent48343a0a506398e22349c791717500a20bfff511 (diff)
Moved UpdateTime out of CBlockHeader and moved CBlockHeader into core.
Diffstat (limited to 'src')
-rw-r--r--src/core.h61
-rw-r--r--src/main.cpp10
-rw-r--r--src/main.h66
-rw-r--r--src/rpcmining.cpp4
4 files changed, 71 insertions, 70 deletions
diff --git a/src/core.h b/src/core.h
index c86e1f499d..cba3ab233f 100644
--- a/src/core.h
+++ b/src/core.h
@@ -672,4 +672,65 @@ public:
};
+/** Nodes collect new transactions into a block, hash them into a hash tree,
+ * and scan through nonce values to make the block's hash satisfy proof-of-work
+ * requirements. When they solve the proof-of-work, they broadcast the block
+ * to everyone and the block is added to the block chain. The first transaction
+ * in the block is a special one that creates a new coin owned by the creator
+ * of the block.
+ */
+class CBlockHeader
+{
+public:
+ // header
+ static const int CURRENT_VERSION=2;
+ int nVersion;
+ uint256 hashPrevBlock;
+ uint256 hashMerkleRoot;
+ unsigned int nTime;
+ unsigned int nBits;
+ unsigned int nNonce;
+
+ CBlockHeader()
+ {
+ SetNull();
+ }
+
+ IMPLEMENT_SERIALIZE
+ (
+ READWRITE(this->nVersion);
+ nVersion = this->nVersion;
+ READWRITE(hashPrevBlock);
+ READWRITE(hashMerkleRoot);
+ READWRITE(nTime);
+ READWRITE(nBits);
+ READWRITE(nNonce);
+ )
+
+ void SetNull()
+ {
+ nVersion = CBlockHeader::CURRENT_VERSION;
+ hashPrevBlock = 0;
+ hashMerkleRoot = 0;
+ nTime = 0;
+ nBits = 0;
+ nNonce = 0;
+ }
+
+ bool IsNull() const
+ {
+ return (nBits == 0);
+ }
+
+ uint256 GetHash() const
+ {
+ return Hash(BEGIN(nVersion), END(nNonce));
+ }
+
+ int64 GetBlockTime() const
+ {
+ return (int64)nTime;
+ }
+};
+
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 28b32101d3..bd40476d4c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1300,13 +1300,13 @@ bool ConnectBestBlock(CValidationState &state) {
} while(true);
}
-void CBlockHeader::UpdateTime(const CBlockIndex* pindexPrev)
+void UpdateTime(CBlockHeader& block, const CBlockIndex* pindexPrev)
{
- nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
+ block.nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
// Updating time can change work required on testnet:
if (fTestNet)
- nBits = GetNextWorkRequired(pindexPrev, this);
+ block.nBits = GetNextWorkRequired(pindexPrev, &block);
}
@@ -4366,7 +4366,7 @@ CBlockTemplate* CreateNewBlock(CReserveKey& reservekey)
// Fill in header
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
- pblock->UpdateTime(pindexPrev);
+ UpdateTime(*pblock, pindexPrev);
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock);
pblock->nNonce = 0;
pblock->vtx[0].vin[0].scriptSig = CScript() << OP_0 << OP_0;
@@ -4606,7 +4606,7 @@ void static BitcoinMiner(CWallet *pwallet)
break;
// Update nTime every few seconds
- pblock->UpdateTime(pindexPrev);
+ UpdateTime(*pblock, pindexPrev);
nBlockTime = ByteReverse(pblock->nTime);
if (fTestNet)
{
diff --git a/src/main.h b/src/main.h
index 1279e62ca8..f4e80c85ce 100644
--- a/src/main.h
+++ b/src/main.h
@@ -180,6 +180,9 @@ bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, b
bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew);
/** Find the best known block, and make it the tip of the block chain */
bool ConnectBestBlock(CValidationState &state);
+
+void UpdateTime(CBlockHeader& block, const CBlockIndex* pindexPrev);
+
/** Create a new block index entry for a given block hash */
CBlockIndex * InsertBlockIndex(uint256 hash);
/** Verify a signature */
@@ -576,69 +579,6 @@ public:
};
-/** Nodes collect new transactions into a block, hash them into a hash tree,
- * and scan through nonce values to make the block's hash satisfy proof-of-work
- * requirements. When they solve the proof-of-work, they broadcast the block
- * to everyone and the block is added to the block chain. The first transaction
- * in the block is a special one that creates a new coin owned by the creator
- * of the block.
- */
-class CBlockHeader
-{
-public:
- // header
- static const int CURRENT_VERSION=2;
- int nVersion;
- uint256 hashPrevBlock;
- uint256 hashMerkleRoot;
- unsigned int nTime;
- unsigned int nBits;
- unsigned int nNonce;
-
- CBlockHeader()
- {
- SetNull();
- }
-
- IMPLEMENT_SERIALIZE
- (
- READWRITE(this->nVersion);
- nVersion = this->nVersion;
- READWRITE(hashPrevBlock);
- READWRITE(hashMerkleRoot);
- READWRITE(nTime);
- READWRITE(nBits);
- READWRITE(nNonce);
- )
-
- void SetNull()
- {
- nVersion = CBlockHeader::CURRENT_VERSION;
- hashPrevBlock = 0;
- hashMerkleRoot = 0;
- nTime = 0;
- nBits = 0;
- nNonce = 0;
- }
-
- bool IsNull() const
- {
- return (nBits == 0);
- }
-
- uint256 GetHash() const
- {
- return Hash(BEGIN(nVersion), END(nNonce));
- }
-
- int64 GetBlockTime() const
- {
- return (int64)nTime;
- }
-
- void UpdateTime(const CBlockIndex* pindexPrev);
-};
-
class CBlock : public CBlockHeader
{
public:
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp
index d2cac68706..6f8ac7a112 100644
--- a/src/rpcmining.cpp
+++ b/src/rpcmining.cpp
@@ -159,7 +159,7 @@ Value getwork(const Array& params, bool fHelp)
CBlock* pblock = &pblocktemplate->block; // pointer for convenience
// Update nTime
- pblock->UpdateTime(pindexPrev);
+ UpdateTime(*pblock, pindexPrev);
pblock->nNonce = 0;
// Update nExtraNonce
@@ -289,7 +289,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
CBlock* pblock = &pblocktemplate->block; // pointer for convenience
// Update nTime
- pblock->UpdateTime(pindexPrev);
+ UpdateTime(*pblock, pindexPrev);
pblock->nNonce = 0;
Array transactions;