mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Cleanup code using forward declarations.
Use misc methods of avoiding unnecesary header includes. Replace int typedefs with int##_t from stdint.h. Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h. Normalize QT_VERSION ifs where possible. Resolve some indirect dependencies as direct ones. Remove extern declarations from .cpp files.
This commit is contained in:
83
src/main.h
83
src/main.h
@@ -2,6 +2,7 @@
|
||||
// Copyright (c) 2009-2013 The Bitcoin developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_MAIN_H
|
||||
#define BITCOIN_MAIN_H
|
||||
|
||||
@@ -9,22 +10,27 @@
|
||||
#include "bitcoin-config.h"
|
||||
#endif
|
||||
|
||||
#include "core.h"
|
||||
#include "bignum.h"
|
||||
#include "sync.h"
|
||||
#include "txmempool.h"
|
||||
#include "chainparams.h"
|
||||
#include "core.h"
|
||||
#include "net.h"
|
||||
#include "script.h"
|
||||
#include "sync.h"
|
||||
#include "txmempool.h"
|
||||
#include "uint256.h"
|
||||
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
class CBlock;
|
||||
class CBlockIndex;
|
||||
class CBloomFilter;
|
||||
class CInv;
|
||||
class CKeyItem;
|
||||
class CNode;
|
||||
class CReserveKey;
|
||||
class CWallet;
|
||||
|
||||
/** The maximum allowed size for a serialized block, in bytes (network rule) */
|
||||
static const unsigned int MAX_BLOCK_SIZE = 1000000;
|
||||
@@ -45,8 +51,8 @@ static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
|
||||
/** Fake height value used in CCoins to signify they are only in the memory pool (since 0.8) */
|
||||
static const unsigned int MEMPOOL_HEIGHT = 0x7FFFFFFF;
|
||||
/** No amount larger than this (in satoshi) is valid */
|
||||
static const int64 MAX_MONEY = 21000000 * COIN;
|
||||
inline bool MoneyRange(int64 nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
|
||||
static const int64_t MAX_MONEY = 21000000 * COIN;
|
||||
inline bool MoneyRange(int64_t nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
|
||||
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
|
||||
static const int COINBASE_MATURITY = 100;
|
||||
/** Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp. */
|
||||
@@ -72,10 +78,10 @@ extern CScript COINBASE_FLAGS;
|
||||
extern CCriticalSection cs_main;
|
||||
extern CTxMemPool mempool;
|
||||
extern std::map<uint256, CBlockIndex*> mapBlockIndex;
|
||||
extern uint64 nLastBlockTx;
|
||||
extern uint64 nLastBlockSize;
|
||||
extern uint64_t nLastBlockTx;
|
||||
extern uint64_t nLastBlockSize;
|
||||
extern const std::string strMessageMagic;
|
||||
extern int64 nTimeBestReceived;
|
||||
extern int64_t nTimeBestReceived;
|
||||
extern bool fImporting;
|
||||
extern bool fReindex;
|
||||
extern bool fBenchmark;
|
||||
@@ -85,17 +91,15 @@ extern unsigned int nCoinCacheSize;
|
||||
extern bool fHaveGUI;
|
||||
|
||||
// Settings
|
||||
extern int64 nTransactionFee;
|
||||
extern int64_t nTransactionFee;
|
||||
|
||||
// Minimum disk space required - used in CheckDiskSpace()
|
||||
static const uint64 nMinDiskSpace = 52428800;
|
||||
static const uint64_t nMinDiskSpace = 52428800;
|
||||
|
||||
|
||||
class CReserveKey;
|
||||
class CCoinsDB;
|
||||
class CBlockTreeDB;
|
||||
struct CDiskBlockPos;
|
||||
class CCoins;
|
||||
class CTxUndo;
|
||||
class CCoinsView;
|
||||
class CCoinsViewCache;
|
||||
@@ -124,7 +128,7 @@ void PushGetBlocks(CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd);
|
||||
/** Process an incoming block */
|
||||
bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp = NULL);
|
||||
/** Check whether enough disk space is available for an incoming block */
|
||||
bool CheckDiskSpace(uint64 nAdditionalBytes = 0);
|
||||
bool CheckDiskSpace(uint64_t nAdditionalBytes = 0);
|
||||
/** Open a block file (blk?????.dat) */
|
||||
FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false);
|
||||
/** Open an undo file (rev?????.dat) */
|
||||
@@ -150,7 +154,7 @@ void ThreadScriptCheck();
|
||||
/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */
|
||||
bool CheckProofOfWork(uint256 hash, unsigned int nBits);
|
||||
/** Calculate the minimum amount of work a received block needs, without knowing its direct parent */
|
||||
unsigned int ComputeMinWork(unsigned int nBase, int64 nTime);
|
||||
unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime);
|
||||
/** Get the number of active peers */
|
||||
int GetNumBlocksOfPeers();
|
||||
/** Check whether we are doing an initial block download (synchronizing from disk or network) */
|
||||
@@ -163,7 +167,7 @@ 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);
|
||||
int64 GetBlockValue(int nHeight, int64 nFees);
|
||||
int64_t GetBlockValue(int nHeight, int64_t nFees);
|
||||
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock);
|
||||
|
||||
void UpdateTime(CBlockHeader& block, const CBlockIndex* pindexPrev);
|
||||
@@ -247,7 +251,7 @@ enum GetMinFee_mode
|
||||
GMF_SEND,
|
||||
};
|
||||
|
||||
int64 GetMinFee(const CTransaction& tx, bool fAllowFree, enum GetMinFee_mode mode);
|
||||
int64_t GetMinFee(const CTransaction& tx, bool fAllowFree, enum GetMinFee_mode mode);
|
||||
|
||||
//
|
||||
// Check transaction inputs, and make sure any
|
||||
@@ -307,12 +311,12 @@ bool CheckTransaction(const CTransaction& tx, CValidationState& state);
|
||||
*/
|
||||
bool IsStandardTx(const CTransaction& tx, std::string& reason);
|
||||
|
||||
bool IsFinalTx(const CTransaction &tx, int nBlockHeight = 0, int64 nBlockTime = 0);
|
||||
bool IsFinalTx(const CTransaction &tx, int nBlockHeight = 0, int64_t nBlockTime = 0);
|
||||
|
||||
/** Amount of bitcoins spent by the transaction.
|
||||
@return sum of all outputs (note: does not include fees)
|
||||
*/
|
||||
int64 GetValueOut(const CTransaction& tx);
|
||||
int64_t GetValueOut(const CTransaction& tx);
|
||||
|
||||
/** Undo information for a CBlock */
|
||||
class CBlockUndo
|
||||
@@ -600,8 +604,8 @@ public:
|
||||
unsigned int nUndoSize; // number of used bytes in the undo file
|
||||
unsigned int nHeightFirst; // lowest height of block in file
|
||||
unsigned int nHeightLast; // highest height of block in file
|
||||
uint64 nTimeFirst; // earliest time of block in file
|
||||
uint64 nTimeLast; // latest time of block in file
|
||||
uint64_t nTimeFirst; // earliest time of block in file
|
||||
uint64_t nTimeLast; // latest time of block in file
|
||||
|
||||
IMPLEMENT_SERIALIZE(
|
||||
READWRITE(VARINT(nBlocks));
|
||||
@@ -632,7 +636,7 @@ public:
|
||||
}
|
||||
|
||||
// update statistics (does not update nSize)
|
||||
void AddBlock(unsigned int nHeightIn, uint64 nTimeIn) {
|
||||
void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn) {
|
||||
if (nBlocks==0 || nHeightFirst > nHeightIn)
|
||||
nHeightFirst = nHeightIn;
|
||||
if (nBlocks==0 || nTimeFirst > nTimeIn)
|
||||
@@ -786,9 +790,9 @@ public:
|
||||
return *phashBlock;
|
||||
}
|
||||
|
||||
int64 GetBlockTime() const
|
||||
int64_t GetBlockTime() const
|
||||
{
|
||||
return (int64)nTime;
|
||||
return (int64_t)nTime;
|
||||
}
|
||||
|
||||
CBigNum GetBlockWork() const
|
||||
@@ -807,11 +811,11 @@ public:
|
||||
|
||||
enum { nMedianTimeSpan=11 };
|
||||
|
||||
int64 GetMedianTimePast() const
|
||||
int64_t GetMedianTimePast() const
|
||||
{
|
||||
int64 pmedian[nMedianTimeSpan];
|
||||
int64* pbegin = &pmedian[nMedianTimeSpan];
|
||||
int64* pend = &pmedian[nMedianTimeSpan];
|
||||
int64_t pmedian[nMedianTimeSpan];
|
||||
int64_t* pbegin = &pmedian[nMedianTimeSpan];
|
||||
int64_t* pend = &pmedian[nMedianTimeSpan];
|
||||
|
||||
const CBlockIndex* pindex = this;
|
||||
for (int i = 0; i < nMedianTimeSpan && pindex; i++, pindex = pindex->pprev)
|
||||
@@ -821,7 +825,7 @@ public:
|
||||
return pbegin[(pend - pbegin)/2];
|
||||
}
|
||||
|
||||
int64 GetMedianTime() const;
|
||||
int64_t GetMedianTime() const;
|
||||
|
||||
/**
|
||||
* Returns true if there are nRequired or more blocks of minVersion or above
|
||||
@@ -1035,11 +1039,11 @@ struct CCoinsStats
|
||||
{
|
||||
int nHeight;
|
||||
uint256 hashBlock;
|
||||
uint64 nTransactions;
|
||||
uint64 nTransactionOutputs;
|
||||
uint64 nSerializedSize;
|
||||
uint64_t nTransactions;
|
||||
uint64_t nTransactionOutputs;
|
||||
uint64_t nSerializedSize;
|
||||
uint256 hashSerialized;
|
||||
int64 nTotalAmount;
|
||||
int64_t nTotalAmount;
|
||||
|
||||
CCoinsStats() : nHeight(0), hashBlock(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), hashSerialized(0), nTotalAmount(0) {}
|
||||
};
|
||||
@@ -1130,7 +1134,8 @@ public:
|
||||
@return Sum of value of all inputs (scriptSigs)
|
||||
@see CTransaction::FetchInputs
|
||||
*/
|
||||
int64 GetValueIn(const CTransaction& tx);
|
||||
int64_t GetValueIn(const CTransaction& tx);
|
||||
|
||||
|
||||
// Check whether all prevouts of the transaction are present in the UTXO set represented by this view
|
||||
bool HaveInputs(const CTransaction& tx);
|
||||
|
||||
Reference in New Issue
Block a user