29 static const unsigned int MAX_BLOCK_SIZE = 1000000;
31 static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/4;
33 static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 250000;
35 static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 17000;
37 static const unsigned int MAX_STANDARD_TX_SIZE = 100000;
39 static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
41 static const unsigned int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
43 static const unsigned int MAX_INV_SZ = 50000;
45 static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000;
47 static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000;
49 static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000;
51 static const unsigned int MEMPOOL_HEIGHT = 0x7FFFFFFF;
53 static const int64 DUST_SOFT_LIMIT = 100000;
55 static const int64 DUST_HARD_LIMIT = 1000;
57 static const int64 MAX_MONEY = 336000000 * COIN;
58 inline bool MoneyRange(
int64 nValue) {
return (nValue >= 0 && nValue <= MAX_MONEY); }
60 static const int COINBASE_MATURITY = 100;
62 static const unsigned int LOCKTIME_THRESHOLD = 500000000;
64 static const int MAX_SCRIPTCHECK_THREADS = 16;
66 static const int fHaveUPnP =
true;
68 static const int fHaveUPnP =
false;
112 static const uint64 nMinDiskSpace = 52428800;
151 bool VerifyDB(
int nCheckLevel,
int nCheckDepth);
236 bool IsNull()
const {
return (nFile == -1); }
271 void SetNull() { ptx = NULL; n = (
unsigned int) -1; }
272 bool IsNull()
const {
return (ptx == NULL && n == (
unsigned int) -1); }
287 void SetNull() { hash = 0; n = (
unsigned int) -1; }
288 bool IsNull()
const {
return (hash == 0 && n == (
unsigned int) -1); }
332 nSequence = std::numeric_limits<unsigned int>::max();
338 scriptSig = scriptSigIn;
339 nSequence = nSequenceIn;
342 CTxIn(
uint256 hashPrevTx,
unsigned int nOut,
CScript scriptSigIn=
CScript(),
unsigned int nSequenceIn=std::numeric_limits<unsigned int>::max())
345 scriptSig = scriptSigIn;
346 nSequence = nSequenceIn;
358 return (nSequence == std::numeric_limits<unsigned int>::max());
382 if (nSequence != std::numeric_limits<unsigned int>::max())
383 str +=
strprintf(
", nSequence=%u", nSequence);
414 scriptPubKey = scriptPubKeyIn;
426 scriptPubKey.clear();
431 return (nValue == -1);
454 if (scriptPubKey.size() < 6)
455 return "CTxOut(error)";
456 return strprintf(
"CTxOut(nValue=%"PRI64d".%08"PRI64d", scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.
ToString().substr(0,30).c_str());
512 return (vin.empty() && vout.empty());
525 if (nBlockHeight == 0)
529 if ((
int64)nLockTime < ((
int64)nLockTime < LOCKTIME_THRESHOLD ? (
int64)nBlockHeight : nBlockTime))
531 BOOST_FOREACH(
const CTxIn& txin, vin)
539 if (vin.size() != old.
vin.size())
541 for (
unsigned int i = 0; i < vin.size(); i++)
542 if (vin[i].prevout != old.
vin[i].prevout)
546 unsigned int nLowest = std::numeric_limits<unsigned int>::max();
547 for (
unsigned int i = 0; i < vin.size(); i++)
549 if (vin[i].nSequence != old.
vin[i].nSequence)
551 if (vin[i].nSequence <= nLowest)
554 nLowest = vin[i].nSequence;
556 if (old.
vin[i].nSequence < nLowest)
559 nLowest = old.
vin[i].nSequence;
568 return (vin.size() == 1 && vin[0].prevout.IsNull());
574 bool IsStandard(std::string& strReason)
const;
577 std::string strReason;
605 BOOST_FOREACH(
const CTxOut& txout, vout)
607 nValueOut += txout.
nValue;
609 throw std::runtime_error(
"CTransaction::GetValueOut() : value out of range");
627 return dPriority > COIN * 576 / 250;
652 str +=
strprintf(
"CTransaction(hash=%s, ver=%d, vin.size=%"PRIszu", vout.size=%"PRIszu", nLockTime=%u)\n",
658 for (
unsigned int i = 0; i < vin.size(); i++)
659 str +=
" " + vin[i].
ToString() +
"\n";
660 for (
unsigned int i = 0; i < vout.size(); i++)
661 str +=
" " + vout[i].
ToString() +
"\n";
679 std::vector<CScriptCheck> *pvChecks = NULL)
const;
734 CTxInUndo() : txout(), fCoinBase(false), nHeight(0), nVersion(0) {}
735 CTxInUndo(
const CTxOut &txoutIn,
bool fCoinBaseIn =
false,
unsigned int nHeightIn = 0,
int nVersionIn = 0) : txout(txoutIn), fCoinBase(fCoinBaseIn), nHeight(nHeightIn), nVersion(nVersionIn) { }
743 template<
typename Stream>
744 void Serialize(Stream &s,
int nType,
int nVersion)
const {
751 template<
typename Stream>
753 unsigned int nCode = 0;
756 fCoinBase = nCode & 1;
790 return error(
"CBlockUndo::WriteToDisk() : OpenUndoFile failed");
797 long fileOutPos = ftell(fileout);
799 return error(
"CBlockUndo::WriteToDisk() : ftell failed");
800 pos.
nPos = (
unsigned int)fileOutPos;
807 fileout << hasher.GetHash();
822 return error(
"CBlockUndo::ReadFromDisk() : OpenBlockFile failed");
828 filein >> hashChecksum;
830 catch (std::exception &e) {
831 return error(
"%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
838 if (hashChecksum != hasher.GetHash())
839 return error(
"CBlockUndo::ReadFromDisk() : checksum mismatch");
913 CCoins(
const CTransaction &tx,
int nHeightIn) : fCoinBase(tx.IsCoinBase()), vout(tx.vout), nHeight(nHeightIn), nVersion(tx.nVersion) { }
916 CCoins() : fCoinBase(false), vout(0), nHeight(0), nVersion(0) { }
920 while (vout.size() > 0 && vout.back().IsNull())
923 std::vector<CTxOut>().swap(vout);
929 std::swap(to.
nHeight, nHeight);
947 void CalcMaskSize(
unsigned int &nBytes,
unsigned int &nNonzeroBytes)
const {
948 unsigned int nLastUsedByte = 0;
949 for (
unsigned int b = 0; 2+b*8 < vout.size(); b++) {
951 for (
unsigned int i = 0; i < 8 && 2+b*8+i < vout.size(); i++) {
952 if (!vout[2+b*8+i].IsNull()) {
958 nLastUsedByte = b + 1;
962 nBytes += nLastUsedByte;
970 unsigned int nSize = 0;
971 unsigned int nMaskSize = 0, nMaskCode = 0;
972 CalcMaskSize(nMaskSize, nMaskCode);
973 bool fFirst = vout.size() > 0 && !vout[0].IsNull();
974 bool fSecond = vout.size() > 1 && !vout[1].IsNull();
975 assert(fFirst || fSecond || nMaskCode);
976 unsigned int nCode = 8*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0);
984 for (
unsigned int i = 0; i < vout.size(); i++)
985 if (!vout[i].IsNull())
992 template<
typename Stream>
993 void Serialize(Stream &s,
int nType,
int nVersion)
const {
994 unsigned int nMaskSize = 0, nMaskCode = 0;
995 CalcMaskSize(nMaskSize, nMaskCode);
996 bool fFirst = vout.size() > 0 && !vout[0].IsNull();
997 bool fSecond = vout.size() > 1 && !vout[1].IsNull();
998 assert(fFirst || fSecond || nMaskCode);
999 unsigned int nCode = 8*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0);
1005 for (
unsigned int b = 0; b<nMaskSize; b++) {
1006 unsigned char chAvail = 0;
1007 for (
unsigned int i = 0; i < 8 && 2+b*8+i < vout.size(); i++)
1008 if (!vout[2+b*8+i].IsNull())
1009 chAvail |= (1 << i);
1013 for (
unsigned int i = 0; i < vout.size(); i++) {
1014 if (!vout[i].IsNull())
1021 template<
typename Stream>
1023 unsigned int nCode = 0;
1028 fCoinBase = nCode & 1;
1029 std::vector<bool> vAvail(2,
false);
1030 vAvail[0] = nCode & 2;
1031 vAvail[1] = nCode & 4;
1032 unsigned int nMaskCode = (nCode / 8) + ((nCode & 6) != 0 ? 0 : 1);
1034 while (nMaskCode > 0) {
1035 unsigned char chAvail = 0;
1037 for (
unsigned int p = 0; p < 8; p++) {
1038 bool f = (chAvail & (1 << p)) != 0;
1039 vAvail.push_back(f);
1045 vout.assign(vAvail.size(),
CTxOut());
1046 for (
unsigned int i = 0; i < vAvail.size(); i++) {
1057 if (out.
n >= vout.size())
1059 if (vout[out.
n].IsNull())
1062 vout[out.
n].SetNull();
1064 if (vout.size() == 0) {
1076 return Spend(out, undo);
1081 return (nPos < vout.size() && !vout[nPos].IsNull());
1087 BOOST_FOREACH(
const CTxOut &out, vout)
1108 scriptPubKey(txFromIn.vout[txToIn.vin[nInIn].prevout.n].scriptPubKey),
1109 ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), nHashType(nHashTypeIn) { }
1111 bool operator()()
const;
1115 std::swap(ptxTo, check.
ptxTo);
1116 std::swap(nIn, check.
nIn);
1117 std::swap(nFlags, check.
nFlags);
1148 fMerkleVerified =
false;
1155 nVersion = this->nVersion;
1162 int SetMerkleBranch(
const CBlock* pblock=NULL);
1163 int GetDepthInMainChain(
CBlockIndex* &pindexRet)
const;
1166 int GetBlocksToMaturity()
const;
1167 bool AcceptToMemoryPool(
bool fCheckInputs=
true,
bool fLimitFree=
true);
1225 return (nTransactions+(1 << height)-1) >> height;
1229 uint256 CalcHash(
int height,
unsigned int pos,
const std::vector<uint256> &vTxid);
1232 void TraverseAndBuild(
int height,
unsigned int pos,
const std::vector<uint256> &vTxid,
const std::vector<bool> &vMatch);
1236 uint256 TraverseAndExtract(
int height,
unsigned int pos,
unsigned int &nBitsUsed,
unsigned int &nHashUsed, std::vector<uint256> &vMatch);
1244 std::vector<unsigned char> vBytes;
1248 us.
vBits.resize(vBytes.size() * 8);
1249 for (
unsigned int p = 0; p < us.
vBits.size(); p++)
1250 us.
vBits[p] = (vBytes[p / 8] & (1 << (p % 8))) != 0;
1253 vBytes.resize((vBits.size()+7)/8);
1254 for (
unsigned int p = 0; p < vBits.size(); p++)
1255 vBytes[p / 8] |= vBits[p] << (p % 8);
1261 CPartialMerkleTree(
const std::vector<uint256> &vTxid,
const std::vector<bool> &vMatch);
1267 uint256 ExtractMatches(std::vector<uint256> &vMatch);
1282 static const int CURRENT_VERSION=2;
1298 nVersion = this->nVersion;
1318 return (nBits == 0);
1328 return (
int64)nTime;
1338 std::vector<CTransaction>
vtx;
1362 CBlockHeader::SetNull();
1364 vMerkleTree.clear();
1380 block.
nTime = nTime;
1381 block.
nBits = nBits;
1388 vMerkleTree.clear();
1390 vMerkleTree.push_back(tx.
GetHash());
1392 for (
int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
1394 for (
int i = 0; i < nSize; i += 2)
1396 int i2 = std::min(i+1, nSize-1);
1397 vMerkleTree.push_back(
Hash(
BEGIN(vMerkleTree[j+i]),
END(vMerkleTree[j+i]),
1398 BEGIN(vMerkleTree[j+i2]),
END(vMerkleTree[j+i2])));
1402 return (vMerkleTree.empty() ? 0 : vMerkleTree.back());
1406 assert(vMerkleTree.size() > 0);
1407 assert(nIndex < vtx.size());
1408 return vMerkleTree[nIndex];
1413 if (vMerkleTree.empty())
1415 std::vector<uint256> vMerkleBranch;
1417 for (
int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
1419 int i = std::min(nIndex^1, nSize-1);
1420 vMerkleBranch.push_back(vMerkleTree[j+i]);
1424 return vMerkleBranch;
1431 BOOST_FOREACH(
const uint256& otherside, vMerkleBranch)
1447 return error(
"CBlock::WriteToDisk() : OpenBlockFile failed");
1454 long fileOutPos = ftell(fileout);
1456 return error(
"CBlock::WriteToDisk() : ftell failed");
1457 pos.
nPos = (
unsigned int)fileOutPos;
1475 return error(
"CBlock::ReadFromDisk() : OpenBlockFile failed");
1481 catch (std::exception &e) {
1482 return error(
"%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
1487 return error(
"CBlock::ReadFromDisk() : errors in block header");
1496 printf(
"CBlock(hash=%s, input=%s, PoW=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%"PRIszu")\n",
1497 GetHash().ToString().c_str(),
1499 GetPoWHash().ToString().c_str(),
1503 nTime, nBits, nNonce,
1505 for (
unsigned int i = 0; i < vtx.size(); i++)
1510 printf(
" vMerkleTree: ");
1511 for (
unsigned int i = 0; i < vMerkleTree.size(); i++)
1512 printf(
"%s ", vMerkleTree[i].ToString().c_str());
1580 return strprintf(
"CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast,
DateTimeStrFormat(
"%Y-%m-%d", nTimeFirst).c_str(),
DateTimeStrFormat(
"%Y-%m-%d", nTimeLast).c_str());
1585 if (nBlocks==0 || nHeightFirst > nHeightIn)
1586 nHeightFirst = nHeightIn;
1587 if (nBlocks==0 || nTimeFirst > nTimeIn)
1588 nTimeFirst = nTimeIn;
1590 if (nHeightIn > nHeightFirst)
1591 nHeightLast = nHeightIn;
1592 if (nTimeIn > nTimeLast)
1593 nTimeLast = nTimeIn;
1708 nTime = block.
nTime;
1709 nBits = block.
nBits;
1717 ret.
nPos = nDataPos;
1726 ret.
nPos = nUndoPos;
1738 block.
nTime = nTime;
1739 block.
nBits = nBits;
1751 return (
int64)nTime;
1760 return (
CBigNum(1)<<256) / (bnTarget+1);
1765 return (pnext ||
this == pindexBest);
1775 enum { nMedianTimeSpan=11 };
1779 int64 pmedian[nMedianTimeSpan];
1780 int64* pbegin = &pmedian[nMedianTimeSpan];
1781 int64* pend = &pmedian[nMedianTimeSpan];
1784 for (
int i = 0; i < nMedianTimeSpan && pindex; i++, pindex = pindex->
pprev)
1787 std::sort(pbegin, pend);
1788 return pbegin[(pend - pbegin)/2];
1794 for (
int i = 0; i < nMedianTimeSpan/2; i++)
1797 return GetBlockTime();
1798 pindex = pindex->
pnext;
1807 static bool IsSuperMajority(
int minVersion,
const CBlockIndex* pstart,
1808 unsigned int nRequired,
unsigned int nToCheck);
1812 return strprintf(
"CBlockIndex(pprev=%p, pnext=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
1813 pprev, pnext, nHeight,
1815 GetBlockHash().ToString().c_str());
1820 printf(
"%s\n", ToString().c_str());
1850 hashPrev = (pprev ? pprev->GetBlockHash() : 0);
1883 block.
nTime = nTime;
1884 block.
nBits = nBits;
1892 std::string str =
"CDiskBlockIndex(";
1894 str +=
strprintf(
"\n hashBlock=%s, hashPrev=%s)",
1895 GetBlockHash().ToString().c_str(),
1902 printf(
"%s\n", ToString().c_str());
1918 bool DoS(
int level,
bool ret =
false,
bool corruptionIn =
false) {
1919 if (mode == MODE_ERROR)
1922 mode = MODE_INVALID;
1923 corruptionPossible = corruptionIn;
1938 return mode == MODE_VALID;
1941 return mode == MODE_INVALID;
1944 return mode == MODE_ERROR;
1954 return corruptionPossible;
1985 std::map<uint256, CBlockIndex*>::iterator mi =
mapBlockIndex.find(hashBlock);
1997 if (!(nType & SER_GETHASH))
2009 return vHave.empty();
2021 for (
int i = 0; pindex && i < nStep; i++)
2022 pindex = pindex->
pprev;
2023 if (vHave.size() > 10)
2026 vHave.push_back(hashGenesisBlock);
2034 BOOST_FOREACH(
const uint256& hash, vHave)
2036 std::map<uint256, CBlockIndex*>::iterator mi =
mapBlockIndex.find(hash);
2053 BOOST_FOREACH(
const uint256& hash, vHave)
2055 std::map<uint256, CBlockIndex*>::iterator mi =
mapBlockIndex.find(hash);
2069 BOOST_FOREACH(
const uint256& hash, vHave)
2071 std::map<uint256, CBlockIndex*>::iterator mi =
mapBlockIndex.find(hash);
2107 bool remove(
const CTransaction &tx,
bool fRecursive =
false);
2110 void queryHashes(std::vector<uint256>& vtxid);
2116 return mapTx.size();
2121 return (mapTx.count(hash) != 0);
2142 CCoinsStats() : nHeight(0), hashBlock(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), hashSerialized(0), nTotalAmount(0) {}
2153 virtual bool SetCoins(
const uint256 &txid,
const CCoins &coins);
2157 virtual bool HaveCoins(
const uint256 &txid);
2166 virtual bool BatchWrite(
const std::map<uint256, CCoins> &mapCoins,
CBlockIndex *pindex);
2185 bool HaveCoins(
const uint256 &txid);
2189 bool BatchWrite(
const std::map<uint256, CCoins> &mapCoins,
CBlockIndex *pindex);
2206 bool HaveCoins(
const uint256 &txid);
2209 bool BatchWrite(
const std::map<uint256, CCoins> &mapCoins,
CBlockIndex *pindex);
2221 unsigned int GetCacheSize();
2224 std::map<uint256,CCoins>::iterator FetchCoins(
const uint256 &txid);
2237 bool HaveCoins(
const uint256 &txid);
2253 #if defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(_M_X64) || defined(__x86_64__) || defined(_M_AMD64)
2254 extern unsigned int cpuid_edx;
bool error(const char *format,...)
std::map< uint256, CBlockIndex * > mapBlockIndex
unsigned int GetSerializeSize(int nType, int nVersion) const
CCriticalSection cs_setpwalletRegistered
bool IsFinal(int nBlockHeight=0, int64 nBlockTime=0) const
bool CheckProofOfWork(uint256 hash, unsigned int nBits)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
CDiskBlockPos GetBlockPos() const
#define strprintf(format,...)
CBigNum GetBlockWork() const
CDiskBlockPos(int nFileIn, unsigned int nPosIn)
void UpdateCoins(const CTransaction &tx, CValidationState &state, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight, const uint256 &txhash)
bool IsInitialBlockDownload()
Check whether we are doing an initial block download (synchronizing from disk or network) ...
unsigned int SerReadWrite(Stream &s, const T &obj, int nType, int nVersion, CSerActionGetSerializeSize ser_action)
bool operator()(CBlockIndex *pa, CBlockIndex *pb)
int64 GetMedianTime() const
friend bool operator!=(const COutPoint &a, const COutPoint &b)
IMPLEMENT_SERIALIZE(READWRITE(VARINT(nFile));READWRITE(VARINT(nPos));) CDiskBlockPos()
bool CheckInputs(CValidationState &state, CCoinsViewCache &view, bool fScriptChecks=true, unsigned int flags=SCRIPT_VERIFY_P2SH|SCRIPT_VERIFY_STRICTENC, std::vector< CScriptCheck > *pvChecks=NULL) const
CBlockIndex * FindBlockByHeight(int nHeight)
Find a block by height in the currently-connected chain.
CBlockLocator(const std::vector< uint256 > &vHaveIn)
void Serialize(Stream &s, int nType, int nVersion) const
bool LoadExternalBlockFile(FILE *fileIn, CDiskBlockPos *dbp=NULL)
Import blocks from an external file.
void FileCommit(FILE *fileout)
void swap(CScriptCheck &check)
std::vector< CTxOut > vout
unsigned int nTransactions
bool CheckTransaction(CValidationState &state) const
CBlock(const CBlockHeader &header)
static uint64 CompressAmount(uint64 nAmount)
bool AcceptToMemoryPool(CValidationState &state, bool fCheckInputs=true, bool fLimitFree=true, bool *pfMissingInputs=NULL)
CScriptCheck(const CCoins &txFromIn, const CTransaction &txToIn, unsigned int nInIn, unsigned int nFlagsIn, int nHashTypeIn)
unsigned int GetLegacySigOpCount() const
Count ECDSA signature operations the old-fashioned (pre-0.6) way.
std::set< CWallet * > setpwalletRegistered
wrapper for CTxOut that provides a more compact serialization
unsigned int GetSerializeSize(int nType, int nVersion) const
int64 GetBlockTime() const
bool CheckDiskSpace(uint64 nAdditionalBytes=0)
Check whether enough disk space is available for an incoming block.
std::map< COutPoint, CInPoint > mapNextTx
std::set< CBlockIndex *, CBlockIndexWorkComparator > setBlockIndexValid
void Serialize(Stream &s, char a, int, int=0)
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
BloomFilter is a probabilistic filter which SPV clients provide so that we can filter the transaction...
void PrintBlockTree()
Print the loaded block tree.
std::string ToString() const
friend bool operator==(const CTxOut &a, const CTxOut &b)
std::vector< int64_t > vTxFees
bool Invalid(bool ret=false)
IMPLEMENT_SERIALIZE(READWRITE(*(CDiskBlockPos *) this);READWRITE(VARINT(nTxOffset));) CDiskTxPos(const CDiskBlockPos &blockIn
void Unserialize(Stream &s, int nType, int nVersion)
static bool AllowFree(double dPriority)
IMPLEMENT_SERIALIZE(READWRITE(prevout);READWRITE(scriptSig);READWRITE(nSequence);) bool IsFinal() const
bool AreInputsStandard(CCoinsViewCache &mapInputs) const
Check for standard transaction types.
friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b)
CTxOut(int64 nValueIn, CScript scriptPubKeyIn)
#define IMPLEMENT_SERIALIZE(statements)
bool ConnectBestBlock(CValidationState &state)
Find the best known block, and make it the tip of the block chain.
CTxIn(uint256 hashPrevTx, unsigned int nOut, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits< unsigned int >::max())
Compact serializer for scripts.
Data structure that represents a partial merkle tree.
int64 GetMinFee(unsigned int nBlockSize=1, bool fAllowFree=true, enum GetMinFee_mode mode=GMF_BLOCK) const
uint256 GetPoWHash() const
friend bool operator!=(const CTxOut &a, const CTxOut &b)
CTxOutCompressor(CTxOut &txoutIn)
unsigned long long uint64
pruned version of CTransaction: only retains metadata and unspent transaction outputs ...
int64 GetMedianTimePast() const
const std::string strMessageMagic
unsigned int GetSerializeSize(const T &obj)
unsigned int nCoinCacheSize
CBlockIndex(CBlockHeader &block)
CDiskBlockIndex(CBlockIndex *pindex)
int GetNumBlocksOfPeers()
Get the number of active peers.
void IncrementExtraNonce(CBlock *pblock, CBlockIndex *pindexPrev, unsigned int &nExtraNonce)
Modify the extranonce in a block.
Undo information for a CTxIn.
std::string ToString() const
bool VerifySignature(const CCoins &txFrom, const CTransaction &txTo, unsigned int nIn, unsigned int flags, int nHashType)
Verify a signature.
bool IsNewerThan(const CTransaction &old) const
std::string GetWarnings(std::string strFor)
Format a string that describes several potential problems detected by the core.
friend bool operator==(const COutPoint &a, const COutPoint &b)
std::string ToString() const
bool IsAvailable(unsigned int nPos) const
IMPLEMENT_SERIALIZE(READWRITE(this->nVersion);nVersion=this->nVersion;READWRITE(vin);READWRITE(vout);READWRITE(nLockTime);) void SetNull()
bool InitBlockIndex()
Initialize a new block tree database + block data on disk.
CInPoint(CTransaction *ptxIn, unsigned int nIn)
CCoins(const CTransaction &tx, int nHeightIn)
static int64 nMinTxFee
Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) ...
friend bool operator==(const CCoins &a, const CCoins &b)
uint256 BuildMerkleTree() const
int GetDepthInMainChain() const
friend bool operator!=(const CDiskBlockPos &a, const CDiskBlockPos &b)
void Serialize(Stream &s, int nType, int nVersion) const
unsigned int GetP2SHSigOpCount(CCoinsViewCache &mapInputs) const
Count ECDSA signature operations in pay-to-script-hash inputs.
uint256 SerializeHash(const T &obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
void AddBlock(unsigned int nHeightIn, uint64 nTimeIn)
CBigNum & SetCompact(unsigned int nCompact)
std::vector< uint256 > vHash
bool IsInMainChain() const
Used to relay blocks as header + vector to filtered nodes.
unsigned int CalcTreeWidth(int height)
FILE * OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly=false)
Open a block file (blk?????.dat)
CBlockIndex * InsertBlockIndex(uint256 hash)
Create a new block index entry for a given block hash.
Access to the block database (blocks/index/)
CBlockHeader GetBlockHeader() const
unsigned int GetSerializeSize(char a, int, int=0)
Abstract view on the open txout dataset.
CBlockTreeDB * pblocktree
Global variable that points to the active block tree (protected by cs_main)
An input of a transaction.
IMPLEMENT_SERIALIZE(READWRITE(VARINT(nBlocks));READWRITE(VARINT(nSize));READWRITE(VARINT(nUndoSize));READWRITE(VARINT(nHeightFirst));READWRITE(VARINT(nHeightLast));READWRITE(VARINT(nTimeFirst));READWRITE(VARINT(nTimeLast));) void SetNull()
bool ProcessBlock(CValidationState &state, CNode *pfrom, CBlock *pblock, CDiskBlockPos *dbp=NULL)
Process an incoming block.
bool VerifyDB(int nCheckLevel, int nCheckDepth)
Verify consistency of the block and coin databases.
std::vector< CTxOut > vout
bool CorruptionPossible()
CBlockIndex * GetBlockIndex()
void Unserialize(Stream &s, char &a, int, int=0)
CBlockHeader GetBlockHeader() const
CBlockIndex * pindexGenesisBlock
void CalcMaskSize(unsigned int &nBytes, unsigned int &nNonzeroBytes) const
bool IsInMainChain() const
bool DoS(int level, bool ret=false, bool corruptionIn=false)
CBlockFileInfo infoLastBlockFile
C++ wrapper for BIGNUM (OpenSSL bignum)
CBlockTemplate * CreateNewBlock(const CScript &scriptPubKeyIn)
Generate a new block, without valid proof-of-work.
std::vector< uint256 > vMerkleBranch
A CService with information about it as peer.
void RegisterWallet(CWallet *pwalletIn)
Register a wallet to receive updates from core.
std::map< uint256, CTransaction > mapTx
void scrypt_1024_1_1_256(const char *input, char *output)
std::vector< uint256 > vMerkleTree
unsigned int nHeightFirst
int64 GetValueIn(CCoinsViewCache &mapInputs) const
Amount of bitcoins coming in to this transaction Note that lightweight clients may not know anything ...
uint256 Hash(const T1 pbegin, const T1 pend)
std::vector< uint256 > vHave
An output of a transaction.
Used to marshal pointers into hashes for db storage.
std::string DateTimeStrFormat(const char *pszFormat, int64 nTime)
int64 GetValueOut() const
Amount of bitcoins spent by this transaction.
bool CheckBlock(int nHeight, const uint256 &hash)
An outpoint - a combination of a transaction hash and an index n into its vout.
unsigned int ComputeMinWork(unsigned int nBase, int64 nTime)
Calculate the minimum amount of work a received block needs, without knowing its direct parent...
std::vector< CTxInUndo > vprevout
bool Abort(const std::string &msg)
std::vector< uint256 > GetMerkleBranch(int nIndex) const
std::string ToString() const
void ThreadScriptCheck()
Run an instance of the script checking thread.
std::string ToString() const
CCriticalSection cs_LastBlockFile
void UnloadBlockIndex()
Unload database information.
std::string ToString() const
IMPLEMENT_SERIALIZE(READWRITE(FLATDATA(*this));) void SetNull()
Closure representing one script verification Note that this stores references to the spending transac...
bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, bool fAllowSlow=false)
Retrieve a transaction (from memory pool, or from disk, if possible)
CTransaction & lookup(uint256 hash)
bool WriteToDisk(CDiskBlockPos &pos)
bool HaveInputs(CCoinsViewCache &view) const
std::vector< bool > vBits
const uint256 & GetTxHash(unsigned int nIndex) const
bool LoadBlockIndex()
Load the block tree and coins database from disk.
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
COutPoint(uint256 hashIn, unsigned int nIn)
std::string ToString() const
IMPLEMENT_SERIALIZE(READWRITE(nValue);READWRITE(scriptPubKey);) void SetNull()
CMerkleTx(const CTransaction &txIn)
Capture information about block/transaction validation.
const CTransaction * ptxTo
static uint64 DecompressAmount(uint64 nAmount)
void Unserialize(Stream &s, int nType, int nVersion)
unsigned char pchMessageStart[4]
bool Spend(const COutPoint &out, CTxInUndo &undo)
A key allocated from the key pool.
CBlockTemplate * CreateNewBlockWithKey(CReserveKey &reservekey)
bool IsInvalid(int &nDoSOut)
std::vector< std::pair< unsigned int, uint256 > > vMatchedTxn
The block chain is a tree shaped structure starting with the genesis block at the root...
Undo information for a CBlock.
Serialized script, used inside transaction inputs and outputs.
CBlockLocator(const CBlockIndex *pindex)
Undo information for a CTransaction.
std::string ToString() const
std::vector< int64_t > vTxSigOps
unsigned int nTransactionsUpdated
void UnregisterWallet(CWallet *pwalletIn)
Unregister a wallet from core.
void GenerateBitcoins(bool fGenerate, CWallet *pwallet)
Run the miner threads.
bool exists(uint256 hash)
An inpoint - a combination of a transaction and an index n into its vin.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
void FormatHashBuffers(CBlock *pblock, char *pmidstate, char *pdata, char *phash1)
Do mining precalculation.
bool CheckWork(CBlock *pblock, CWallet &wallet, CReserveKey &reservekey)
Check mined block.
bool GetWalletFile(CWallet *pwallet, std::string &strWalletFileOut)
uint64 nTransactionOutputs
std::string ToString() const
bool ProcessMessages(CNode *pfrom)
Process protocol messages received from a given node.
void SyncWithWallets(const uint256 &hash, const CTransaction &tx, const CBlock *pblock=NULL, bool fUpdate=false)
Push an updated transaction to all registered wallets.
std::vector< CTransaction > vtx
friend bool operator<(const COutPoint &a, const COutPoint &b)
CDiskBlockPos GetUndoPos() const
FILE * OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly=false)
Open an undo file (rev?????.dat)
The basic transaction that is broadcasted on the network and contained in blocks. ...
CCoinsView backed by another CCoinsView.
Information about a peer.
static const int CURRENT_VERSION
bool SendMessages(CNode *pto, bool fSendTrickle)
Send queued protocol messages to be sent to a give node.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
friend bool operator==(const CTxIn &a, const CTxIn &b)
void Set(const CBlockIndex *pindex)
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits< unsigned int >::max())
CTxInUndo(const CTxOut &txoutIn, bool fCoinBaseIn=false, unsigned int nHeightIn=0, int nVersionIn=0)
std::vector< CTxUndo > vtxundo
bool ReadFromDisk(const CDiskBlockPos &pos)
bool SetBestChain(CValidationState &state, CBlockIndex *pindexNew)
Connect/disconnect blocks until pindexNew is the new tip of the active block chain.
friend bool operator!=(const CTxIn &a, const CTxIn &b)
CCoinsView that brings transactions from a memorypool into view.
static int64 nMinRelayTxFee
Fees smaller than this (in satoshi) are considered zero fee (for relaying)
CBlockLocator(uint256 hashBlock)
bool MoneyRange(int64 nValue)
bool AbortNode(const std::string &msg)
Abort with a message.
static uint256 CheckMerkleBranch(uint256 hash, const std::vector< uint256 > &vMerkleBranch, int nIndex)
uint256 GetBlockHash() const
A transaction with a merkle branch linking it to the block chain.
friend bool operator==(const CTransaction &a, const CTransaction &b)
static const CTxOut & GetOutputFor(const CTxIn &input, CCoinsViewCache &mapInputs)
std::map< uint256, CBlock * > mapOrphanBlocks
friend bool operator!=(const CCoins &a, const CCoins &b)
std::map< uint256, CCoins > cacheCoins
friend bool operator!=(const CTransaction &a, const CTransaction &b)
const uint256 * phashBlock