experimental-genesis 1
experimental-genesis 2
experimental-genesis 3
experimental-genesis 4
experimental-genesis 5
experimental-genesis 6
experimental-genesis 7
experimental-genesis 8
experimental-genesis 9
experimental-genesis 10
experimental-genesis 11
experimental-genesis 12
experimental-genesis 13
experimental-genesis 14
experimental-genesis 15
experimental-genesis 16
experimental-genesis 17
experimental-genesis 18
experimental-genesis 19
experimental-genesis 20
experimental-genesis 21
experimental-genesis 22
experimental-genesis 23
experimental-genesis 24
experimental-genesis 25
experimental-genesis 26
experimental-genesis 27
experimental-genesis 28
experimental-genesis 29
experimental-genesis 30
experimental-genesis 31
experimental-genesis 32
experimental-genesis 33
experimental-genesis 34
experimental-genesis 35
experimental-genesis 36 #ifndef BITCOIN_MAIN_H
experimental-genesis 37 #define BITCOIN_MAIN_H
experimental-genesis 38
experimental-genesis 39 #include "bignum.h"
experimental-genesis 40 #include "net.h"
experimental-genesis 41 #include "key.h"
experimental-genesis 42 #include "script.h"
experimental-genesis 43 #include "db.h"
experimental-genesis 44
experimental-genesis 45 #include <list>
experimental-genesis 46
experimental-genesis 47 class CBlock;
experimental-genesis 48 class CBlockIndex;
experimental-genesis 49 class CWalletTx;
experimental-genesis 50 class CWallet;
experimental-genesis 51 class CKeyItem;
experimental-genesis 52 class CReserveKey;
experimental-genesis 53 class CWalletDB;
experimental-genesis 54
experimental-genesis 55 class CAddress;
experimental-genesis 56 class CInv;
experimental-genesis 57 class CRequestTracker;
experimental-genesis 58 class CNode;
experimental-genesis 59 class CBlockIndex;
experimental-genesis 60
experimental-genesis 61 static const unsigned int MAX_BLOCK_SIZE = 1000000;
experimental-genesis 62 static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2;
experimental-genesis 63 static const int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
experimental-genesis 64 static const int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
experimental-genesis 65 static const int64 COIN = 100000000;
experimental-genesis 66 static const int64 CENT = 1000000;
experimental-genesis 67 static const int64 MIN_TX_FEE = 50000;
experimental-genesis 68 static const int64 MIN_RELAY_TX_FEE = 10000;
experimental-genesis 69 static const int64 MAX_MONEY = 21000000 * COIN;
experimental-genesis 70 inline bool MoneyRange(int64 nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
experimental-genesis 71 static const int COINBASE_MATURITY = 100;
experimental-genesis 72
experimental-genesis 73 static const int LOCKTIME_THRESHOLD = 500000000;
experimental-genesis 74 #ifdef USE_UPNP
experimental-genesis 75 static const int fHaveUPnP = true;
experimental-genesis 76 #else
experimental-genesis 77 static const int fHaveUPnP = false;
experimental-genesis 78 #endif
experimental-genesis 79
experimental-genesis 80
experimental-genesis 81
experimental-genesis 82
experimental-genesis 83
experimental-genesis 84
experimental-genesis 85 extern CCriticalSection cs_main;
experimental-genesis 86 extern std::map<uint256, CBlockIndex*> mapBlockIndex;
experimental-genesis 87 extern uint256 hashGenesisBlock;
experimental-genesis 88 extern CBlockIndex* pindexGenesisBlock;
experimental-genesis 89 extern int nBestHeight;
experimental-genesis 90 extern CBigNum bnBestChainWork;
experimental-genesis 91 extern CBigNum bnBestInvalidWork;
experimental-genesis 92 extern uint256 hashBestChain;
experimental-genesis 93 extern CBlockIndex* pindexBest;
experimental-genesis 94 extern unsigned int nTransactionsUpdated;
experimental-genesis 95 extern double dHashesPerSec;
experimental-genesis 96 extern int64 nHPSTimerStart;
experimental-genesis 97 extern int64 nTimeBestReceived;
experimental-genesis 98 extern CCriticalSection cs_setpwalletRegistered;
experimental-genesis 99 extern std::set<CWallet*> setpwalletRegistered;
experimental-genesis 100
experimental-genesis 101
experimental-genesis 102 extern int fGenerateBitcoins;
experimental-genesis 103 extern int64 nTransactionFee;
experimental-genesis 104 extern int fLimitProcessors;
experimental-genesis 105 extern int nLimitProcessors;
experimental-genesis 106 extern int fMinimizeToTray;
experimental-genesis 107 extern int fMinimizeOnClose;
experimental-genesis 108 extern int fUseUPnP;
experimental-genesis 109
experimental-genesis 110
experimental-genesis 111
experimental-genesis 112
experimental-genesis 113
experimental-genesis 114 class CReserveKey;
experimental-genesis 115 class CTxDB;
experimental-genesis 116 class CTxIndex;
experimental-genesis 117
experimental-genesis 118 void RegisterWallet(CWallet* pwalletIn);
experimental-genesis 119 void UnregisterWallet(CWallet* pwalletIn);
experimental-genesis 120 bool ProcessBlock(CNode* pfrom, CBlock* pblock);
experimental-genesis 121 bool CheckDiskSpace(uint64 nAdditionalBytes=0);
experimental-genesis 122 FILE* OpenBlockFile(unsigned int nFile, unsigned int nBlockPos, const char* pszMode="rb");
experimental-genesis 123 FILE* AppendBlockFile(unsigned int& nFileRet);
experimental-genesis 124 bool LoadBlockIndex(bool fAllowNew=true);
experimental-genesis 125 void PrintBlockTree();
experimental-genesis 126 bool ProcessMessages(CNode* pfrom);
experimental-genesis 127 bool SendMessages(CNode* pto, bool fSendTrickle);
experimental-genesis 128 void GenerateBitcoins(bool fGenerate, CWallet* pwallet);
experimental-genesis 129 CBlock* CreateNewBlock(CReserveKey& reservekey);
experimental-genesis 130 void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
experimental-genesis 131 void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash1);
experimental-genesis 132 bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey);
experimental-genesis 133 bool CheckProofOfWork(uint256 hash, unsigned int nBits);
experimental-genesis 134 unsigned int ComputeMinWork(unsigned int nBase, int64 nTime);
experimental-genesis 135 int GetNumBlocksOfPeers();
experimental-genesis 136 bool IsInitialBlockDownload();
experimental-genesis 137 std::string GetWarnings(std::string strFor);
experimental-genesis 138
experimental-genesis 139
experimental-genesis 140
experimental-genesis 141
experimental-genesis 142
experimental-genesis 143
experimental-genesis 144
experimental-genesis 145
experimental-genesis 146
experimental-genesis 147
experimental-genesis 148
experimental-genesis 149
experimental-genesis 150 bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut);
experimental-genesis 151
experimental-genesis 152 template<typename T>
experimental-genesis 153 bool WriteSetting(const std::string& strKey, const T& value)
experimental-genesis 154 {
experimental-genesis 155 bool fOk = false;
experimental-genesis 156 BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
experimental-genesis 157 {
experimental-genesis 158 std::string strWalletFile;
experimental-genesis 159 if (!GetWalletFile(pwallet, strWalletFile))
experimental-genesis 160 continue;
experimental-genesis 161 fOk |= CWalletDB(strWalletFile).WriteSetting(strKey, value);
experimental-genesis 162 }
experimental-genesis 163 return fOk;
experimental-genesis 164 }
experimental-genesis 165
experimental-genesis 166
experimental-genesis 167 class CDiskTxPos
experimental-genesis 168 {
experimental-genesis 169 public:
experimental-genesis 170 unsigned int nFile;
experimental-genesis 171 unsigned int nBlockPos;
experimental-genesis 172 unsigned int nTxPos;
experimental-genesis 173
experimental-genesis 174 CDiskTxPos()
experimental-genesis 175 {
experimental-genesis 176 SetNull();
experimental-genesis 177 }
experimental-genesis 178
experimental-genesis 179 CDiskTxPos(unsigned int nFileIn, unsigned int nBlockPosIn, unsigned int nTxPosIn)
experimental-genesis 180 {
experimental-genesis 181 nFile = nFileIn;
experimental-genesis 182 nBlockPos = nBlockPosIn;
experimental-genesis 183 nTxPos = nTxPosIn;
experimental-genesis 184 }
experimental-genesis 185
experimental-genesis 186 IMPLEMENT_SERIALIZE( READWRITE(FLATDATA(*this)); )
experimental-genesis 187 void SetNull() { nFile = -1; nBlockPos = 0; nTxPos = 0; }
experimental-genesis 188 bool IsNull() const { return (nFile == -1); }
experimental-genesis 189
experimental-genesis 190 friend bool operator==(const CDiskTxPos& a, const CDiskTxPos& b)
experimental-genesis 191 {
experimental-genesis 192 return (a.nFile == b.nFile &&
experimental-genesis 193 a.nBlockPos == b.nBlockPos &&
experimental-genesis 194 a.nTxPos == b.nTxPos);
experimental-genesis 195 }
experimental-genesis 196
experimental-genesis 197 friend bool operator!=(const CDiskTxPos& a, const CDiskTxPos& b)
experimental-genesis 198 {
experimental-genesis 199 return !(a == b);
experimental-genesis 200 }
experimental-genesis 201
experimental-genesis 202 std::string ToString() const
experimental-genesis 203 {
experimental-genesis 204 if (IsNull())
experimental-genesis 205 return strprintf("null");
experimental-genesis 206 else
experimental-genesis 207 return strprintf("(nFile=%d, nBlockPos=%d, nTxPos=%d)", nFile, nBlockPos, nTxPos);
experimental-genesis 208 }
experimental-genesis 209
experimental-genesis 210 void print() const
experimental-genesis 211 {
experimental-genesis 212 printf("%s", ToString().c_str());
experimental-genesis 213 }
experimental-genesis 214 };
experimental-genesis 215
experimental-genesis 216
experimental-genesis 217
experimental-genesis 218
experimental-genesis 219 class CInPoint
experimental-genesis 220 {
experimental-genesis 221 public:
experimental-genesis 222 CTransaction* ptx;
experimental-genesis 223 unsigned int n;
experimental-genesis 224
experimental-genesis 225 CInPoint() { SetNull(); }
experimental-genesis 226 CInPoint(CTransaction* ptxIn, unsigned int nIn) { ptx = ptxIn; n = nIn; }
experimental-genesis 227 void SetNull() { ptx = NULL; n = -1; }
experimental-genesis 228 bool IsNull() const { return (ptx == NULL && n == -1); }
experimental-genesis 229 };
experimental-genesis 230
experimental-genesis 231
experimental-genesis 232
experimental-genesis 233
experimental-genesis 234 class COutPoint
experimental-genesis 235 {
experimental-genesis 236 public:
experimental-genesis 237 uint256 hash;
experimental-genesis 238 unsigned int n;
experimental-genesis 239
experimental-genesis 240 COutPoint() { SetNull(); }
experimental-genesis 241 COutPoint(uint256 hashIn, unsigned int nIn) { hash = hashIn; n = nIn; }
experimental-genesis 242 IMPLEMENT_SERIALIZE( READWRITE(FLATDATA(*this)); )
experimental-genesis 243 void SetNull() { hash = 0; n = -1; }
experimental-genesis 244 bool IsNull() const { return (hash == 0 && n == -1); }
experimental-genesis 245
experimental-genesis 246 friend bool operator<(const COutPoint& a, const COutPoint& b)
experimental-genesis 247 {
experimental-genesis 248 return (a.hash < b.hash || (a.hash == b.hash && a.n < b.n));
experimental-genesis 249 }
experimental-genesis 250
experimental-genesis 251 friend bool operator==(const COutPoint& a, const COutPoint& b)
experimental-genesis 252 {
experimental-genesis 253 return (a.hash == b.hash && a.n == b.n);
experimental-genesis 254 }
experimental-genesis 255
experimental-genesis 256 friend bool operator!=(const COutPoint& a, const COutPoint& b)
experimental-genesis 257 {
experimental-genesis 258 return !(a == b);
experimental-genesis 259 }
experimental-genesis 260
experimental-genesis 261 std::string ToString() const
experimental-genesis 262 {
experimental-genesis 263 return strprintf("COutPoint(%s, %d)", hash.ToString().substr(0,10).c_str(), n);
experimental-genesis 264 }
experimental-genesis 265
experimental-genesis 266 void print() const
experimental-genesis 267 {
experimental-genesis 268 printf("%s\n", ToString().c_str());
experimental-genesis 269 }
experimental-genesis 270 };
experimental-genesis 271
experimental-genesis 272
experimental-genesis 273
experimental-genesis 274
experimental-genesis 275
experimental-genesis 276
experimental-genesis 277
experimental-genesis 278
experimental-genesis 279
experimental-genesis 280 class CTxIn
experimental-genesis 281 {
experimental-genesis 282 public:
experimental-genesis 283 COutPoint prevout;
experimental-genesis 284 CScript scriptSig;
experimental-genesis 285 unsigned int nSequence;
experimental-genesis 286
experimental-genesis 287 CTxIn()
experimental-genesis 288 {
experimental-genesis 289 nSequence = UINT_MAX;
experimental-genesis 290 }
experimental-genesis 291
experimental-genesis 292 explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=UINT_MAX)
experimental-genesis 293 {
experimental-genesis 294 prevout = prevoutIn;
experimental-genesis 295 scriptSig = scriptSigIn;
experimental-genesis 296 nSequence = nSequenceIn;
experimental-genesis 297 }
experimental-genesis 298
experimental-genesis 299 CTxIn(uint256 hashPrevTx, unsigned int nOut, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=UINT_MAX)
experimental-genesis 300 {
experimental-genesis 301 prevout = COutPoint(hashPrevTx, nOut);
experimental-genesis 302 scriptSig = scriptSigIn;
experimental-genesis 303 nSequence = nSequenceIn;
experimental-genesis 304 }
experimental-genesis 305
experimental-genesis 306 IMPLEMENT_SERIALIZE
experimental-genesis 307 (
experimental-genesis 308 READWRITE(prevout);
experimental-genesis 309 READWRITE(scriptSig);
experimental-genesis 310 READWRITE(nSequence);
experimental-genesis 311 )
experimental-genesis 312
experimental-genesis 313 bool IsFinal() const
experimental-genesis 314 {
experimental-genesis 315 return (nSequence == UINT_MAX);
experimental-genesis 316 }
experimental-genesis 317
experimental-genesis 318 friend bool operator==(const CTxIn& a, const CTxIn& b)
experimental-genesis 319 {
experimental-genesis 320 return (a.prevout == b.prevout &&
experimental-genesis 321 a.scriptSig == b.scriptSig &&
experimental-genesis 322 a.nSequence == b.nSequence);
experimental-genesis 323 }
experimental-genesis 324
experimental-genesis 325 friend bool operator!=(const CTxIn& a, const CTxIn& b)
experimental-genesis 326 {
experimental-genesis 327 return !(a == b);
experimental-genesis 328 }
experimental-genesis 329
experimental-genesis 330 std::string ToString() const
experimental-genesis 331 {
experimental-genesis 332 std::string str;
experimental-genesis 333 str += strprintf("CTxIn(");
experimental-genesis 334 str += prevout.ToString();
experimental-genesis 335 if (prevout.IsNull())
experimental-genesis 336 str += strprintf(", coinbase %s", HexStr(scriptSig).c_str());
experimental-genesis 337 else
experimental-genesis 338 str += strprintf(", scriptSig=%s", scriptSig.ToString().substr(0,24).c_str());
experimental-genesis 339 if (nSequence != UINT_MAX)
experimental-genesis 340 str += strprintf(", nSequence=%u", nSequence);
experimental-genesis 341 str += ")";
experimental-genesis 342 return str;
experimental-genesis 343 }
experimental-genesis 344
experimental-genesis 345 void print() const
experimental-genesis 346 {
experimental-genesis 347 printf("%s\n", ToString().c_str());
experimental-genesis 348 }
experimental-genesis 349 };
experimental-genesis 350
experimental-genesis 351
experimental-genesis 352
experimental-genesis 353
experimental-genesis 354
experimental-genesis 355
experimental-genesis 356
experimental-genesis 357
experimental-genesis 358 class CTxOut
experimental-genesis 359 {
experimental-genesis 360 public:
experimental-genesis 361 int64 nValue;
experimental-genesis 362 CScript scriptPubKey;
experimental-genesis 363
experimental-genesis 364 CTxOut()
experimental-genesis 365 {
experimental-genesis 366 SetNull();
experimental-genesis 367 }
experimental-genesis 368
experimental-genesis 369 CTxOut(int64 nValueIn, CScript scriptPubKeyIn)
experimental-genesis 370 {
experimental-genesis 371 nValue = nValueIn;
experimental-genesis 372 scriptPubKey = scriptPubKeyIn;
experimental-genesis 373 }
experimental-genesis 374
experimental-genesis 375 IMPLEMENT_SERIALIZE
experimental-genesis 376 (
experimental-genesis 377 READWRITE(nValue);
experimental-genesis 378 READWRITE(scriptPubKey);
experimental-genesis 379 )
experimental-genesis 380
experimental-genesis 381 void SetNull()
experimental-genesis 382 {
experimental-genesis 383 nValue = -1;
experimental-genesis 384 scriptPubKey.clear();
experimental-genesis 385 }
experimental-genesis 386
experimental-genesis 387 bool IsNull()
experimental-genesis 388 {
experimental-genesis 389 return (nValue == -1);
experimental-genesis 390 }
experimental-genesis 391
experimental-genesis 392 uint256 GetHash() const
experimental-genesis 393 {
experimental-genesis 394 return SerializeHash(*this);
experimental-genesis 395 }
experimental-genesis 396
experimental-genesis 397 friend bool operator==(const CTxOut& a, const CTxOut& b)
experimental-genesis 398 {
experimental-genesis 399 return (a.nValue == b.nValue &&
experimental-genesis 400 a.scriptPubKey == b.scriptPubKey);
experimental-genesis 401 }
experimental-genesis 402
experimental-genesis 403 friend bool operator!=(const CTxOut& a, const CTxOut& b)
experimental-genesis 404 {
experimental-genesis 405 return !(a == b);
experimental-genesis 406 }
experimental-genesis 407
experimental-genesis 408 std::string ToString() const
experimental-genesis 409 {
experimental-genesis 410 if (scriptPubKey.size() < 6)
experimental-genesis 411 return "CTxOut(error)";
experimental-genesis 412 return strprintf("CTxOut(nValue=%"PRI64d".%08"PRI64d", scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30).c_str());
experimental-genesis 413 }
experimental-genesis 414
experimental-genesis 415 void print() const
experimental-genesis 416 {
experimental-genesis 417 printf("%s\n", ToString().c_str());
experimental-genesis 418 }
experimental-genesis 419 };
experimental-genesis 420
experimental-genesis 421
experimental-genesis 422
experimental-genesis 423
experimental-genesis 424
experimental-genesis 425
experimental-genesis 426
experimental-genesis 427
experimental-genesis 428 class CTransaction
experimental-genesis 429 {
experimental-genesis 430 public:
experimental-genesis 431 int nVersion;
experimental-genesis 432 std::vector<CTxIn> vin;
experimental-genesis 433 std::vector<CTxOut> vout;
experimental-genesis 434 unsigned int nLockTime;
experimental-genesis 435
experimental-genesis 436
experimental-genesis 437 mutable int nDoS;
experimental-genesis 438 bool DoS(int nDoSIn, bool fIn) const { nDoS += nDoSIn; return fIn; }
experimental-genesis 439
experimental-genesis 440 CTransaction()
experimental-genesis 441 {
experimental-genesis 442 SetNull();
experimental-genesis 443 }
experimental-genesis 444
experimental-genesis 445 IMPLEMENT_SERIALIZE
experimental-genesis 446 (
experimental-genesis 447 READWRITE(this->nVersion);
experimental-genesis 448 nVersion = this->nVersion;
experimental-genesis 449 READWRITE(vin);
experimental-genesis 450 READWRITE(vout);
experimental-genesis 451 READWRITE(nLockTime);
experimental-genesis 452 )
experimental-genesis 453
experimental-genesis 454 void SetNull()
experimental-genesis 455 {
experimental-genesis 456 nVersion = 1;
experimental-genesis 457 vin.clear();
experimental-genesis 458 vout.clear();
experimental-genesis 459 nLockTime = 0;
experimental-genesis 460 nDoS = 0;
experimental-genesis 461 }
experimental-genesis 462
experimental-genesis 463 bool IsNull() const
experimental-genesis 464 {
experimental-genesis 465 return (vin.empty() && vout.empty());
experimental-genesis 466 }
experimental-genesis 467
experimental-genesis 468 uint256 GetHash() const
experimental-genesis 469 {
experimental-genesis 470 return SerializeHash(*this);
experimental-genesis 471 }
experimental-genesis 472
experimental-genesis 473 bool IsFinal(int nBlockHeight=0, int64 nBlockTime=0) const
experimental-genesis 474 {
experimental-genesis 475
experimental-genesis 476 if (nLockTime == 0)
experimental-genesis 477 return true;
experimental-genesis 478 if (nBlockHeight == 0)
experimental-genesis 479 nBlockHeight = nBestHeight;
experimental-genesis 480 if (nBlockTime == 0)
experimental-genesis 481 nBlockTime = GetAdjustedTime();
experimental-genesis 482 if ((int64)nLockTime < (nLockTime < LOCKTIME_THRESHOLD ? (int64)nBlockHeight : nBlockTime))
experimental-genesis 483 return true;
experimental-genesis 484 BOOST_FOREACH(const CTxIn& txin, vin)
experimental-genesis 485 if (!txin.IsFinal())
experimental-genesis 486 return false;
experimental-genesis 487 return true;
experimental-genesis 488 }
experimental-genesis 489
experimental-genesis 490 bool IsNewerThan(const CTransaction& old) const
experimental-genesis 491 {
experimental-genesis 492 if (vin.size() != old.vin.size())
experimental-genesis 493 return false;
experimental-genesis 494 for (int i = 0; i < vin.size(); i++)
experimental-genesis 495 if (vin[i].prevout != old.vin[i].prevout)
experimental-genesis 496 return false;
experimental-genesis 497
experimental-genesis 498 bool fNewer = false;
experimental-genesis 499 unsigned int nLowest = UINT_MAX;
experimental-genesis 500 for (int i = 0; i < vin.size(); i++)
experimental-genesis 501 {
experimental-genesis 502 if (vin[i].nSequence != old.vin[i].nSequence)
experimental-genesis 503 {
experimental-genesis 504 if (vin[i].nSequence <= nLowest)
experimental-genesis 505 {
experimental-genesis 506 fNewer = false;
experimental-genesis 507 nLowest = vin[i].nSequence;
experimental-genesis 508 }
experimental-genesis 509 if (old.vin[i].nSequence < nLowest)
experimental-genesis 510 {
experimental-genesis 511 fNewer = true;
experimental-genesis 512 nLowest = old.vin[i].nSequence;
experimental-genesis 513 }
experimental-genesis 514 }
experimental-genesis 515 }
experimental-genesis 516 return fNewer;
experimental-genesis 517 }
experimental-genesis 518
experimental-genesis 519 bool IsCoinBase() const
experimental-genesis 520 {
experimental-genesis 521 return (vin.size() == 1 && vin[0].prevout.IsNull());
experimental-genesis 522 }
experimental-genesis 523
experimental-genesis 524 int GetSigOpCount() const
experimental-genesis 525 {
experimental-genesis 526 int n = 0;
experimental-genesis 527 BOOST_FOREACH(const CTxIn& txin, vin)
experimental-genesis 528 n += txin.scriptSig.GetSigOpCount();
experimental-genesis 529 BOOST_FOREACH(const CTxOut& txout, vout)
experimental-genesis 530 n += txout.scriptPubKey.GetSigOpCount();
experimental-genesis 531 return n;
experimental-genesis 532 }
experimental-genesis 533
experimental-genesis 534 bool IsStandard() const
experimental-genesis 535 {
experimental-genesis 536 BOOST_FOREACH(const CTxIn& txin, vin)
experimental-genesis 537 if (!txin.scriptSig.IsPushOnly())
experimental-genesis 538 return error("nonstandard txin: %s", txin.scriptSig.ToString().c_str());
experimental-genesis 539 BOOST_FOREACH(const CTxOut& txout, vout)
experimental-genesis 540 if (!::IsStandard(txout.scriptPubKey))
experimental-genesis 541 return error("nonstandard txout: %s", txout.scriptPubKey.ToString().c_str());
experimental-genesis 542 return true;
experimental-genesis 543 }
experimental-genesis 544
experimental-genesis 545 int64 GetValueOut() const
experimental-genesis 546 {
experimental-genesis 547 int64 nValueOut = 0;
experimental-genesis 548 BOOST_FOREACH(const CTxOut& txout, vout)
experimental-genesis 549 {
experimental-genesis 550 nValueOut += txout.nValue;
experimental-genesis 551 if (!MoneyRange(txout.nValue) || !MoneyRange(nValueOut))
experimental-genesis 552 throw std::runtime_error("CTransaction::GetValueOut() : value out of range");
experimental-genesis 553 }
experimental-genesis 554 return nValueOut;
experimental-genesis 555 }
experimental-genesis 556
experimental-genesis 557 static bool AllowFree(double dPriority)
experimental-genesis 558 {
experimental-genesis 559
experimental-genesis 560
experimental-genesis 561 return dPriority > COIN * 144 / 250;
experimental-genesis 562 }
experimental-genesis 563
experimental-genesis 564 int64 GetMinFee(unsigned int nBlockSize=1, bool fAllowFree=true, bool fForRelay=false) const
experimental-genesis 565 {
experimental-genesis 566
experimental-genesis 567 int64 nBaseFee = fForRelay ? MIN_RELAY_TX_FEE : MIN_TX_FEE;
experimental-genesis 568
experimental-genesis 569 unsigned int nBytes = ::GetSerializeSize(*this, SER_NETWORK);
experimental-genesis 570 unsigned int nNewBlockSize = nBlockSize + nBytes;
experimental-genesis 571 int64 nMinFee = (1 + (int64)nBytes / 1000) * nBaseFee;
experimental-genesis 572
experimental-genesis 573 if (fAllowFree)
experimental-genesis 574 {
experimental-genesis 575 if (nBlockSize == 1)
experimental-genesis 576 {
experimental-genesis 577
experimental-genesis 578
experimental-genesis 579 if (nBytes < 10000)
experimental-genesis 580 nMinFee = 0;
experimental-genesis 581 }
experimental-genesis 582 else
experimental-genesis 583 {
experimental-genesis 584
experimental-genesis 585 if (nNewBlockSize < 27000)
experimental-genesis 586 nMinFee = 0;
experimental-genesis 587 }
experimental-genesis 588 }
experimental-genesis 589
experimental-genesis 590
experimental-genesis 591 if (nMinFee < nBaseFee)
experimental-genesis 592 BOOST_FOREACH(const CTxOut& txout, vout)
experimental-genesis 593 if (txout.nValue < CENT)
experimental-genesis 594 nMinFee = nBaseFee;
experimental-genesis 595
experimental-genesis 596
experimental-genesis 597 if (nBlockSize != 1 && nNewBlockSize >= MAX_BLOCK_SIZE_GEN/2)
experimental-genesis 598 {
experimental-genesis 599 if (nNewBlockSize >= MAX_BLOCK_SIZE_GEN)
experimental-genesis 600 return MAX_MONEY;
experimental-genesis 601 nMinFee *= MAX_BLOCK_SIZE_GEN / (MAX_BLOCK_SIZE_GEN - nNewBlockSize);
experimental-genesis 602 }
experimental-genesis 603
experimental-genesis 604 if (!MoneyRange(nMinFee))
experimental-genesis 605 nMinFee = MAX_MONEY;
experimental-genesis 606 return nMinFee;
experimental-genesis 607 }
experimental-genesis 608
experimental-genesis 609
experimental-genesis 610 bool ReadFromDisk(CDiskTxPos pos, FILE** pfileRet=NULL)
experimental-genesis 611 {
experimental-genesis 612 CAutoFile filein = OpenBlockFile(pos.nFile, 0, pfileRet ? "rb+" : "rb");
experimental-genesis 613 if (!filein)
experimental-genesis 614 return error("CTransaction::ReadFromDisk() : OpenBlockFile failed");
experimental-genesis 615
experimental-genesis 616
experimental-genesis 617 if (fseek(filein, pos.nTxPos, SEEK_SET) != 0)
experimental-genesis 618 return error("CTransaction::ReadFromDisk() : fseek failed");
experimental-genesis 619 filein >> *this;
experimental-genesis 620
experimental-genesis 621
experimental-genesis 622 if (pfileRet)
experimental-genesis 623 {
experimental-genesis 624 if (fseek(filein, pos.nTxPos, SEEK_SET) != 0)
experimental-genesis 625 return error("CTransaction::ReadFromDisk() : second fseek failed");
experimental-genesis 626 *pfileRet = filein.release();
experimental-genesis 627 }
experimental-genesis 628 return true;
experimental-genesis 629 }
experimental-genesis 630
experimental-genesis 631 friend bool operator==(const CTransaction& a, const CTransaction& b)
experimental-genesis 632 {
experimental-genesis 633 return (a.nVersion == b.nVersion &&
experimental-genesis 634 a.vin == b.vin &&
experimental-genesis 635 a.vout == b.vout &&
experimental-genesis 636 a.nLockTime == b.nLockTime);
experimental-genesis 637 }
experimental-genesis 638
experimental-genesis 639 friend bool operator!=(const CTransaction& a, const CTransaction& b)
experimental-genesis 640 {
experimental-genesis 641 return !(a == b);
experimental-genesis 642 }
experimental-genesis 643
experimental-genesis 644
experimental-genesis 645 std::string ToString() const
experimental-genesis 646 {
experimental-genesis 647 std::string str;
experimental-genesis 648 str += strprintf("CTransaction(hash=%s, ver=%d, vin.size=%d, vout.size=%d, nLockTime=%d)\n",
experimental-genesis 649 GetHash().ToString().substr(0,10).c_str(),
experimental-genesis 650 nVersion,
experimental-genesis 651 vin.size(),
experimental-genesis 652 vout.size(),
experimental-genesis 653 nLockTime);
experimental-genesis 654 for (int i = 0; i < vin.size(); i++)
experimental-genesis 655 str += " " + vin[i].ToString() + "\n";
experimental-genesis 656 for (int i = 0; i < vout.size(); i++)
experimental-genesis 657 str += " " + vout[i].ToString() + "\n";
experimental-genesis 658 return str;
experimental-genesis 659 }
experimental-genesis 660
experimental-genesis 661 void print() const
experimental-genesis 662 {
experimental-genesis 663 printf("%s", ToString().c_str());
experimental-genesis 664 }
experimental-genesis 665
experimental-genesis 666
experimental-genesis 667 bool ReadFromDisk(CTxDB& txdb, COutPoint prevout, CTxIndex& txindexRet);
experimental-genesis 668 bool ReadFromDisk(CTxDB& txdb, COutPoint prevout);
experimental-genesis 669 bool ReadFromDisk(COutPoint prevout);
experimental-genesis 670 bool DisconnectInputs(CTxDB& txdb);
experimental-genesis 671 bool ConnectInputs(CTxDB& txdb, std::map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx,
experimental-genesis 672 CBlockIndex* pindexBlock, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee,
experimental-genesis 673 bool& fInvalid);
experimental-genesis 674 bool ClientConnectInputs();
experimental-genesis 675 bool CheckTransaction() const;
experimental-genesis 676 bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL);
experimental-genesis 677 bool AcceptToMemoryPool(bool fCheckInputs=true, bool* pfMissingInputs=NULL);
experimental-genesis 678 protected:
experimental-genesis 679 bool AddToMemoryPoolUnchecked();
experimental-genesis 680 public:
experimental-genesis 681 bool RemoveFromMemoryPool();
experimental-genesis 682 };
experimental-genesis 683
experimental-genesis 684
experimental-genesis 685
experimental-genesis 686
experimental-genesis 687
experimental-genesis 688
experimental-genesis 689
experimental-genesis 690
experimental-genesis 691 class CMerkleTx : public CTransaction
experimental-genesis 692 {
experimental-genesis 693 public:
experimental-genesis 694 uint256 hashBlock;
experimental-genesis 695 std::vector<uint256> vMerkleBranch;
experimental-genesis 696 int nIndex;
experimental-genesis 697
experimental-genesis 698
experimental-genesis 699 mutable char fMerkleVerified;
experimental-genesis 700
experimental-genesis 701
experimental-genesis 702 CMerkleTx()
experimental-genesis 703 {
experimental-genesis 704 Init();
experimental-genesis 705 }
experimental-genesis 706
experimental-genesis 707 CMerkleTx(const CTransaction& txIn) : CTransaction(txIn)
experimental-genesis 708 {
experimental-genesis 709 Init();
experimental-genesis 710 }
experimental-genesis 711
experimental-genesis 712 void Init()
experimental-genesis 713 {
experimental-genesis 714 hashBlock = 0;
experimental-genesis 715 nIndex = -1;
experimental-genesis 716 fMerkleVerified = false;
experimental-genesis 717 }
experimental-genesis 718
experimental-genesis 719
experimental-genesis 720 IMPLEMENT_SERIALIZE
experimental-genesis 721 (
experimental-genesis 722 nSerSize += SerReadWrite(s, *(CTransaction*)this, nType, nVersion, ser_action);
experimental-genesis 723 nVersion = this->nVersion;
experimental-genesis 724 READWRITE(hashBlock);
experimental-genesis 725 READWRITE(vMerkleBranch);
experimental-genesis 726 READWRITE(nIndex);
experimental-genesis 727 )
experimental-genesis 728
experimental-genesis 729
experimental-genesis 730 int SetMerkleBranch(const CBlock* pblock=NULL);
experimental-genesis 731 int GetDepthInMainChain(int& nHeightRet) const;
experimental-genesis 732 int GetDepthInMainChain() const { int nHeight; return GetDepthInMainChain(nHeight); }
experimental-genesis 733 bool IsInMainChain() const { return GetDepthInMainChain() > 0; }
experimental-genesis 734 int GetBlocksToMaturity() const;
experimental-genesis 735 bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true);
experimental-genesis 736 bool AcceptToMemoryPool();
experimental-genesis 737 };
experimental-genesis 738
experimental-genesis 739
experimental-genesis 740
experimental-genesis 741
experimental-genesis 742
experimental-genesis 743
experimental-genesis 744
experimental-genesis 745
experimental-genesis 746
experimental-genesis 747 class CTxIndex
experimental-genesis 748 {
experimental-genesis 749 public:
experimental-genesis 750 CDiskTxPos pos;
experimental-genesis 751 std::vector<CDiskTxPos> vSpent;
experimental-genesis 752
experimental-genesis 753 CTxIndex()
experimental-genesis 754 {
experimental-genesis 755 SetNull();
experimental-genesis 756 }
experimental-genesis 757
experimental-genesis 758 CTxIndex(const CDiskTxPos& posIn, unsigned int nOutputs)
experimental-genesis 759 {
experimental-genesis 760 pos = posIn;
experimental-genesis 761 vSpent.resize(nOutputs);
experimental-genesis 762 }
experimental-genesis 763
experimental-genesis 764 IMPLEMENT_SERIALIZE
experimental-genesis 765 (
experimental-genesis 766 if (!(nType & SER_GETHASH))
experimental-genesis 767 READWRITE(nVersion);
experimental-genesis 768 READWRITE(pos);
experimental-genesis 769 READWRITE(vSpent);
experimental-genesis 770 )
experimental-genesis 771
experimental-genesis 772 void SetNull()
experimental-genesis 773 {
experimental-genesis 774 pos.SetNull();
experimental-genesis 775 vSpent.clear();
experimental-genesis 776 }
experimental-genesis 777
experimental-genesis 778 bool IsNull()
experimental-genesis 779 {
experimental-genesis 780 return pos.IsNull();
experimental-genesis 781 }
experimental-genesis 782
experimental-genesis 783 friend bool operator==(const CTxIndex& a, const CTxIndex& b)
experimental-genesis 784 {
experimental-genesis 785 return (a.pos == b.pos &&
experimental-genesis 786 a.vSpent == b.vSpent);
experimental-genesis 787 }
experimental-genesis 788
experimental-genesis 789 friend bool operator!=(const CTxIndex& a, const CTxIndex& b)
experimental-genesis 790 {
experimental-genesis 791 return !(a == b);
experimental-genesis 792 }
experimental-genesis 793 int GetDepthInMainChain() const;
experimental-genesis 794 };
experimental-genesis 795
experimental-genesis 796
experimental-genesis 797
experimental-genesis 798
experimental-genesis 799
experimental-genesis 800
experimental-genesis 801
experimental-genesis 802
experimental-genesis 803
experimental-genesis 804
experimental-genesis 805
experimental-genesis 806
experimental-genesis 807
experimental-genesis 808
experimental-genesis 809
experimental-genesis 810
experimental-genesis 811 class CBlock
experimental-genesis 812 {
experimental-genesis 813 public:
experimental-genesis 814
experimental-genesis 815 int nVersion;
experimental-genesis 816 uint256 hashPrevBlock;
experimental-genesis 817 uint256 hashMerkleRoot;
experimental-genesis 818 unsigned int nTime;
experimental-genesis 819 unsigned int nBits;
experimental-genesis 820 unsigned int nNonce;
experimental-genesis 821
experimental-genesis 822
experimental-genesis 823 std::vector<CTransaction> vtx;
experimental-genesis 824
experimental-genesis 825
experimental-genesis 826 mutable std::vector<uint256> vMerkleTree;
experimental-genesis 827
experimental-genesis 828
experimental-genesis 829 mutable int nDoS;
experimental-genesis 830 bool DoS(int nDoSIn, bool fIn) const { nDoS += nDoSIn; return fIn; }
experimental-genesis 831
experimental-genesis 832 CBlock()
experimental-genesis 833 {
experimental-genesis 834 SetNull();
experimental-genesis 835 }
experimental-genesis 836
experimental-genesis 837 IMPLEMENT_SERIALIZE
experimental-genesis 838 (
experimental-genesis 839 READWRITE(this->nVersion);
experimental-genesis 840 nVersion = this->nVersion;
experimental-genesis 841 READWRITE(hashPrevBlock);
experimental-genesis 842 READWRITE(hashMerkleRoot);
experimental-genesis 843 READWRITE(nTime);
experimental-genesis 844 READWRITE(nBits);
experimental-genesis 845 READWRITE(nNonce);
experimental-genesis 846
experimental-genesis 847
experimental-genesis 848 if (!(nType & (SER_GETHASH|SER_BLOCKHEADERONLY)))
experimental-genesis 849 READWRITE(vtx);
experimental-genesis 850 else if (fRead)
experimental-genesis 851 const_cast<CBlock*>(this)->vtx.clear();
experimental-genesis 852 )
experimental-genesis 853
experimental-genesis 854 void SetNull()
experimental-genesis 855 {
experimental-genesis 856 nVersion = 1;
experimental-genesis 857 hashPrevBlock = 0;
experimental-genesis 858 hashMerkleRoot = 0;
experimental-genesis 859 nTime = 0;
experimental-genesis 860 nBits = 0;
experimental-genesis 861 nNonce = 0;
experimental-genesis 862 vtx.clear();
experimental-genesis 863 vMerkleTree.clear();
experimental-genesis 864 nDoS = 0;
experimental-genesis 865 }
experimental-genesis 866
experimental-genesis 867 bool IsNull() const
experimental-genesis 868 {
experimental-genesis 869 return (nBits == 0);
experimental-genesis 870 }
experimental-genesis 871
experimental-genesis 872 uint256 GetHash() const
experimental-genesis 873 {
experimental-genesis 874 return Hash(BEGIN(nVersion), END(nNonce));
experimental-genesis 875 }
experimental-genesis 876
experimental-genesis 877 int64 GetBlockTime() const
experimental-genesis 878 {
experimental-genesis 879 return (int64)nTime;
experimental-genesis 880 }
experimental-genesis 881
experimental-genesis 882 int GetSigOpCount() const
experimental-genesis 883 {
experimental-genesis 884 int n = 0;
experimental-genesis 885 BOOST_FOREACH(const CTransaction& tx, vtx)
experimental-genesis 886 n += tx.GetSigOpCount();
experimental-genesis 887 return n;
experimental-genesis 888 }
experimental-genesis 889
experimental-genesis 890
experimental-genesis 891 uint256 BuildMerkleTree() const
experimental-genesis 892 {
experimental-genesis 893 vMerkleTree.clear();
experimental-genesis 894 BOOST_FOREACH(const CTransaction& tx, vtx)
experimental-genesis 895 vMerkleTree.push_back(tx.GetHash());
experimental-genesis 896 int j = 0;
experimental-genesis 897 for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
experimental-genesis 898 {
experimental-genesis 899 for (int i = 0; i < nSize; i += 2)
experimental-genesis 900 {
experimental-genesis 901 int i2 = std::min(i+1, nSize-1);
experimental-genesis 902 vMerkleTree.push_back(Hash(BEGIN(vMerkleTree[j+i]), END(vMerkleTree[j+i]),
experimental-genesis 903 BEGIN(vMerkleTree[j+i2]), END(vMerkleTree[j+i2])));
experimental-genesis 904 }
experimental-genesis 905 j += nSize;
experimental-genesis 906 }
experimental-genesis 907 return (vMerkleTree.empty() ? 0 : vMerkleTree.back());
experimental-genesis 908 }
experimental-genesis 909
experimental-genesis 910 std::vector<uint256> GetMerkleBranch(int nIndex) const
experimental-genesis 911 {
experimental-genesis 912 if (vMerkleTree.empty())
experimental-genesis 913 BuildMerkleTree();
experimental-genesis 914 std::vector<uint256> vMerkleBranch;
experimental-genesis 915 int j = 0;
experimental-genesis 916 for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
experimental-genesis 917 {
experimental-genesis 918 int i = std::min(nIndex^1, nSize-1);
experimental-genesis 919 vMerkleBranch.push_back(vMerkleTree[j+i]);
experimental-genesis 920 nIndex >>= 1;
experimental-genesis 921 j += nSize;
experimental-genesis 922 }
experimental-genesis 923 return vMerkleBranch;
experimental-genesis 924 }
experimental-genesis 925
experimental-genesis 926 static uint256 CheckMerkleBranch(uint256 hash, const std::vector<uint256>& vMerkleBranch, int nIndex)
experimental-genesis 927 {
experimental-genesis 928 if (nIndex == -1)
experimental-genesis 929 return 0;
experimental-genesis 930 BOOST_FOREACH(const uint256& otherside, vMerkleBranch)
experimental-genesis 931 {
experimental-genesis 932 if (nIndex & 1)
experimental-genesis 933 hash = Hash(BEGIN(otherside), END(otherside), BEGIN(hash), END(hash));
experimental-genesis 934 else
experimental-genesis 935 hash = Hash(BEGIN(hash), END(hash), BEGIN(otherside), END(otherside));
experimental-genesis 936 nIndex >>= 1;
experimental-genesis 937 }
experimental-genesis 938 return hash;
experimental-genesis 939 }
experimental-genesis 940
experimental-genesis 941
experimental-genesis 942 bool WriteToDisk(unsigned int& nFileRet, unsigned int& nBlockPosRet)
experimental-genesis 943 {
experimental-genesis 944
experimental-genesis 945 CAutoFile fileout = AppendBlockFile(nFileRet);
experimental-genesis 946 if (!fileout)
experimental-genesis 947 return error("CBlock::WriteToDisk() : AppendBlockFile failed");
experimental-genesis 948
experimental-genesis 949
experimental-genesis 950 unsigned int nSize = fileout.GetSerializeSize(*this);
experimental-genesis 951 fileout << FLATDATA(pchMessageStart) << nSize;
experimental-genesis 952
experimental-genesis 953
experimental-genesis 954 nBlockPosRet = ftell(fileout);
experimental-genesis 955 if (nBlockPosRet == -1)
experimental-genesis 956 return error("CBlock::WriteToDisk() : ftell failed");
experimental-genesis 957 fileout << *this;
experimental-genesis 958
experimental-genesis 959
experimental-genesis 960 fflush(fileout);
experimental-genesis 961 if (!IsInitialBlockDownload() || (nBestHeight+1) % 500 == 0)
experimental-genesis 962 {
experimental-genesis 963 #ifdef WIN32
experimental-genesis 964 _commit(_fileno(fileout));
experimental-genesis 965 #else
experimental-genesis 966 fsync(fileno(fileout));
experimental-genesis 967 #endif
experimental-genesis 968 }
experimental-genesis 969
experimental-genesis 970 return true;
experimental-genesis 971 }
experimental-genesis 972
experimental-genesis 973 bool ReadFromDisk(unsigned int nFile, unsigned int nBlockPos, bool fReadTransactions=true)
experimental-genesis 974 {
experimental-genesis 975 SetNull();
experimental-genesis 976
experimental-genesis 977
experimental-genesis 978 CAutoFile filein = OpenBlockFile(nFile, nBlockPos, "rb");
experimental-genesis 979 if (!filein)
experimental-genesis 980 return error("CBlock::ReadFromDisk() : OpenBlockFile failed");
experimental-genesis 981 if (!fReadTransactions)
experimental-genesis 982 filein.nType |= SER_BLOCKHEADERONLY;
experimental-genesis 983
experimental-genesis 984
experimental-genesis 985 filein >> *this;
experimental-genesis 986
experimental-genesis 987
experimental-genesis 988 if (!CheckProofOfWork(GetHash(), nBits))
experimental-genesis 989 return error("CBlock::ReadFromDisk() : errors in block header");
experimental-genesis 990
experimental-genesis 991 return true;
experimental-genesis 992 }
experimental-genesis 993
experimental-genesis 994
experimental-genesis 995
experimental-genesis 996 void print() const
experimental-genesis 997 {
experimental-genesis 998 printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%d)\n",
experimental-genesis 999 GetHash().ToString().substr(0,20).c_str(),
experimental-genesis 1000 nVersion,
experimental-genesis 1001 hashPrevBlock.ToString().substr(0,20).c_str(),
experimental-genesis 1002 hashMerkleRoot.ToString().substr(0,10).c_str(),
experimental-genesis 1003 nTime, nBits, nNonce,
experimental-genesis 1004 vtx.size());
experimental-genesis 1005 for (int i = 0; i < vtx.size(); i++)
experimental-genesis 1006 {
experimental-genesis 1007 printf(" ");
experimental-genesis 1008 vtx[i].print();
experimental-genesis 1009 }
experimental-genesis 1010 printf(" vMerkleTree: ");
experimental-genesis 1011 for (int i = 0; i < vMerkleTree.size(); i++)
experimental-genesis 1012 printf("%s ", vMerkleTree[i].ToString().substr(0,10).c_str());
experimental-genesis 1013 printf("\n");
experimental-genesis 1014 }
experimental-genesis 1015
experimental-genesis 1016
experimental-genesis 1017 bool DisconnectBlock(CTxDB& txdb, CBlockIndex* pindex);
experimental-genesis 1018 bool ConnectBlock(CTxDB& txdb, CBlockIndex* pindex);
experimental-genesis 1019 bool ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions=true);
experimental-genesis 1020 bool SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew);
experimental-genesis 1021 bool AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos);
experimental-genesis 1022 bool CheckBlock() const;
experimental-genesis 1023 bool AcceptBlock();
experimental-genesis 1024 };
experimental-genesis 1025
experimental-genesis 1026
experimental-genesis 1027
experimental-genesis 1028
experimental-genesis 1029
experimental-genesis 1030
experimental-genesis 1031
experimental-genesis 1032
experimental-genesis 1033
experimental-genesis 1034
experimental-genesis 1035
experimental-genesis 1036
experimental-genesis 1037
experimental-genesis 1038
experimental-genesis 1039 class CBlockIndex
experimental-genesis 1040 {
experimental-genesis 1041 public:
experimental-genesis 1042 const uint256* phashBlock;
experimental-genesis 1043 CBlockIndex* pprev;
experimental-genesis 1044 CBlockIndex* pnext;
experimental-genesis 1045 unsigned int nFile;
experimental-genesis 1046 unsigned int nBlockPos;
experimental-genesis 1047 int nHeight;
experimental-genesis 1048 CBigNum bnChainWork;
experimental-genesis 1049
experimental-genesis 1050
experimental-genesis 1051 int nVersion;
experimental-genesis 1052 uint256 hashMerkleRoot;
experimental-genesis 1053 unsigned int nTime;
experimental-genesis 1054 unsigned int nBits;
experimental-genesis 1055 unsigned int nNonce;
experimental-genesis 1056
experimental-genesis 1057
experimental-genesis 1058 CBlockIndex()
experimental-genesis 1059 {
experimental-genesis 1060 phashBlock = NULL;
experimental-genesis 1061 pprev = NULL;
experimental-genesis 1062 pnext = NULL;
experimental-genesis 1063 nFile = 0;
experimental-genesis 1064 nBlockPos = 0;
experimental-genesis 1065 nHeight = 0;
experimental-genesis 1066 bnChainWork = 0;
experimental-genesis 1067
experimental-genesis 1068 nVersion = 0;
experimental-genesis 1069 hashMerkleRoot = 0;
experimental-genesis 1070 nTime = 0;
experimental-genesis 1071 nBits = 0;
experimental-genesis 1072 nNonce = 0;
experimental-genesis 1073 }
experimental-genesis 1074
experimental-genesis 1075 CBlockIndex(unsigned int nFileIn, unsigned int nBlockPosIn, CBlock& block)
experimental-genesis 1076 {
experimental-genesis 1077 phashBlock = NULL;
experimental-genesis 1078 pprev = NULL;
experimental-genesis 1079 pnext = NULL;
experimental-genesis 1080 nFile = nFileIn;
experimental-genesis 1081 nBlockPos = nBlockPosIn;
experimental-genesis 1082 nHeight = 0;
experimental-genesis 1083 bnChainWork = 0;
experimental-genesis 1084
experimental-genesis 1085 nVersion = block.nVersion;
experimental-genesis 1086 hashMerkleRoot = block.hashMerkleRoot;
experimental-genesis 1087 nTime = block.nTime;
experimental-genesis 1088 nBits = block.nBits;
experimental-genesis 1089 nNonce = block.nNonce;
experimental-genesis 1090 }
experimental-genesis 1091
experimental-genesis 1092 CBlock GetBlockHeader() const
experimental-genesis 1093 {
experimental-genesis 1094 CBlock block;
experimental-genesis 1095 block.nVersion = nVersion;
experimental-genesis 1096 if (pprev)
experimental-genesis 1097 block.hashPrevBlock = pprev->GetBlockHash();
experimental-genesis 1098 block.hashMerkleRoot = hashMerkleRoot;
experimental-genesis 1099 block.nTime = nTime;
experimental-genesis 1100 block.nBits = nBits;
experimental-genesis 1101 block.nNonce = nNonce;
experimental-genesis 1102 return block;
experimental-genesis 1103 }
experimental-genesis 1104
experimental-genesis 1105 uint256 GetBlockHash() const
experimental-genesis 1106 {
experimental-genesis 1107 return *phashBlock;
experimental-genesis 1108 }
experimental-genesis 1109
experimental-genesis 1110 int64 GetBlockTime() const
experimental-genesis 1111 {
experimental-genesis 1112 return (int64)nTime;
experimental-genesis 1113 }
experimental-genesis 1114
experimental-genesis 1115 CBigNum GetBlockWork() const
experimental-genesis 1116 {
experimental-genesis 1117 CBigNum bnTarget;
experimental-genesis 1118 bnTarget.SetCompact(nBits);
experimental-genesis 1119 if (bnTarget <= 0)
experimental-genesis 1120 return 0;
experimental-genesis 1121 return (CBigNum(1)<<256) / (bnTarget+1);
experimental-genesis 1122 }
experimental-genesis 1123
experimental-genesis 1124 bool IsInMainChain() const
experimental-genesis 1125 {
experimental-genesis 1126 return (pnext || this == pindexBest);
experimental-genesis 1127 }
experimental-genesis 1128
experimental-genesis 1129 bool CheckIndex() const
experimental-genesis 1130 {
experimental-genesis 1131 return CheckProofOfWork(GetBlockHash(), nBits);
experimental-genesis 1132 }
experimental-genesis 1133
experimental-genesis 1134 bool EraseBlockFromDisk()
experimental-genesis 1135 {
experimental-genesis 1136
experimental-genesis 1137 CAutoFile fileout = OpenBlockFile(nFile, nBlockPos, "rb+");
experimental-genesis 1138 if (!fileout)
experimental-genesis 1139 return false;
experimental-genesis 1140
experimental-genesis 1141
experimental-genesis 1142 CBlock block;
experimental-genesis 1143 block.SetNull();
experimental-genesis 1144 fileout << block;
experimental-genesis 1145
experimental-genesis 1146 return true;
experimental-genesis 1147 }
experimental-genesis 1148
experimental-genesis 1149 enum { nMedianTimeSpan=11 };
experimental-genesis 1150
experimental-genesis 1151 int64 GetMedianTimePast() const
experimental-genesis 1152 {
experimental-genesis 1153 int64 pmedian[nMedianTimeSpan];
experimental-genesis 1154 int64* pbegin = &pmedian[nMedianTimeSpan];
experimental-genesis 1155 int64* pend = &pmedian[nMedianTimeSpan];
experimental-genesis 1156
experimental-genesis 1157 const CBlockIndex* pindex = this;
experimental-genesis 1158 for (int i = 0; i < nMedianTimeSpan && pindex; i++, pindex = pindex->pprev)
experimental-genesis 1159 *(--pbegin) = pindex->GetBlockTime();
experimental-genesis 1160
experimental-genesis 1161 std::sort(pbegin, pend);
experimental-genesis 1162 return pbegin[(pend - pbegin)/2];
experimental-genesis 1163 }
experimental-genesis 1164
experimental-genesis 1165 int64 GetMedianTime() const
experimental-genesis 1166 {
experimental-genesis 1167 const CBlockIndex* pindex = this;
experimental-genesis 1168 for (int i = 0; i < nMedianTimeSpan/2; i++)
experimental-genesis 1169 {
experimental-genesis 1170 if (!pindex->pnext)
experimental-genesis 1171 return GetBlockTime();
experimental-genesis 1172 pindex = pindex->pnext;
experimental-genesis 1173 }
experimental-genesis 1174 return pindex->GetMedianTimePast();
experimental-genesis 1175 }
experimental-genesis 1176
experimental-genesis 1177
experimental-genesis 1178
experimental-genesis 1179 std::string ToString() const
experimental-genesis 1180 {
experimental-genesis 1181 return strprintf("CBlockIndex(nprev=%08x, pnext=%08x, nFile=%d, nBlockPos=%-6d nHeight=%d, merkle=%s, hashBlock=%s)",
experimental-genesis 1182 pprev, pnext, nFile, nBlockPos, nHeight,
experimental-genesis 1183 hashMerkleRoot.ToString().substr(0,10).c_str(),
experimental-genesis 1184 GetBlockHash().ToString().substr(0,20).c_str());
experimental-genesis 1185 }
experimental-genesis 1186
experimental-genesis 1187 void print() const
experimental-genesis 1188 {
experimental-genesis 1189 printf("%s\n", ToString().c_str());
experimental-genesis 1190 }
experimental-genesis 1191 };
experimental-genesis 1192
experimental-genesis 1193
experimental-genesis 1194
experimental-genesis 1195
experimental-genesis 1196
experimental-genesis 1197
experimental-genesis 1198 class CDiskBlockIndex : public CBlockIndex
experimental-genesis 1199 {
experimental-genesis 1200 public:
experimental-genesis 1201 uint256 hashPrev;
experimental-genesis 1202 uint256 hashNext;
experimental-genesis 1203
experimental-genesis 1204 CDiskBlockIndex()
experimental-genesis 1205 {
experimental-genesis 1206 hashPrev = 0;
experimental-genesis 1207 hashNext = 0;
experimental-genesis 1208 }
experimental-genesis 1209
experimental-genesis 1210 explicit CDiskBlockIndex(CBlockIndex* pindex) : CBlockIndex(*pindex)
experimental-genesis 1211 {
experimental-genesis 1212 hashPrev = (pprev ? pprev->GetBlockHash() : 0);
experimental-genesis 1213 hashNext = (pnext ? pnext->GetBlockHash() : 0);
experimental-genesis 1214 }
experimental-genesis 1215
experimental-genesis 1216 IMPLEMENT_SERIALIZE
experimental-genesis 1217 (
experimental-genesis 1218 if (!(nType & SER_GETHASH))
experimental-genesis 1219 READWRITE(nVersion);
experimental-genesis 1220
experimental-genesis 1221 READWRITE(hashNext);
experimental-genesis 1222 READWRITE(nFile);
experimental-genesis 1223 READWRITE(nBlockPos);
experimental-genesis 1224 READWRITE(nHeight);
experimental-genesis 1225
experimental-genesis 1226
experimental-genesis 1227 READWRITE(this->nVersion);
experimental-genesis 1228 READWRITE(hashPrev);
experimental-genesis 1229 READWRITE(hashMerkleRoot);
experimental-genesis 1230 READWRITE(nTime);
experimental-genesis 1231 READWRITE(nBits);
experimental-genesis 1232 READWRITE(nNonce);
experimental-genesis 1233 )
experimental-genesis 1234
experimental-genesis 1235 uint256 GetBlockHash() const
experimental-genesis 1236 {
experimental-genesis 1237 CBlock block;
experimental-genesis 1238 block.nVersion = nVersion;
experimental-genesis 1239 block.hashPrevBlock = hashPrev;
experimental-genesis 1240 block.hashMerkleRoot = hashMerkleRoot;
experimental-genesis 1241 block.nTime = nTime;
experimental-genesis 1242 block.nBits = nBits;
experimental-genesis 1243 block.nNonce = nNonce;
experimental-genesis 1244 return block.GetHash();
experimental-genesis 1245 }
experimental-genesis 1246
experimental-genesis 1247
experimental-genesis 1248 std::string ToString() const
experimental-genesis 1249 {
experimental-genesis 1250 std::string str = "CDiskBlockIndex(";
experimental-genesis 1251 str += CBlockIndex::ToString();
experimental-genesis 1252 str += strprintf("\n hashBlock=%s, hashPrev=%s, hashNext=%s)",
experimental-genesis 1253 GetBlockHash().ToString().c_str(),
experimental-genesis 1254 hashPrev.ToString().substr(0,20).c_str(),
experimental-genesis 1255 hashNext.ToString().substr(0,20).c_str());
experimental-genesis 1256 return str;
experimental-genesis 1257 }
experimental-genesis 1258
experimental-genesis 1259 void print() const
experimental-genesis 1260 {
experimental-genesis 1261 printf("%s\n", ToString().c_str());
experimental-genesis 1262 }
experimental-genesis 1263 };
experimental-genesis 1264
experimental-genesis 1265
experimental-genesis 1266
experimental-genesis 1267
experimental-genesis 1268
experimental-genesis 1269
experimental-genesis 1270
experimental-genesis 1271
experimental-genesis 1272
experimental-genesis 1273
experimental-genesis 1274
experimental-genesis 1275
experimental-genesis 1276
experimental-genesis 1277 class CBlockLocator
experimental-genesis 1278 {
experimental-genesis 1279 protected:
experimental-genesis 1280 std::vector<uint256> vHave;
experimental-genesis 1281 public:
experimental-genesis 1282
experimental-genesis 1283 CBlockLocator()
experimental-genesis 1284 {
experimental-genesis 1285 }
experimental-genesis 1286
experimental-genesis 1287 explicit CBlockLocator(const CBlockIndex* pindex)
experimental-genesis 1288 {
experimental-genesis 1289 Set(pindex);
experimental-genesis 1290 }
experimental-genesis 1291
experimental-genesis 1292 explicit CBlockLocator(uint256 hashBlock)
experimental-genesis 1293 {
experimental-genesis 1294 std::map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock);
experimental-genesis 1295 if (mi != mapBlockIndex.end())
experimental-genesis 1296 Set((*mi).second);
experimental-genesis 1297 }
experimental-genesis 1298
experimental-genesis 1299 IMPLEMENT_SERIALIZE
experimental-genesis 1300 (
experimental-genesis 1301 if (!(nType & SER_GETHASH))
experimental-genesis 1302 READWRITE(nVersion);
experimental-genesis 1303 READWRITE(vHave);
experimental-genesis 1304 )
experimental-genesis 1305
experimental-genesis 1306 void SetNull()
experimental-genesis 1307 {
experimental-genesis 1308 vHave.clear();
experimental-genesis 1309 }
experimental-genesis 1310
experimental-genesis 1311 bool IsNull()
experimental-genesis 1312 {
experimental-genesis 1313 return vHave.empty();
experimental-genesis 1314 }
experimental-genesis 1315
experimental-genesis 1316 void Set(const CBlockIndex* pindex)
experimental-genesis 1317 {
experimental-genesis 1318 vHave.clear();
experimental-genesis 1319 int nStep = 1;
experimental-genesis 1320 while (pindex)
experimental-genesis 1321 {
experimental-genesis 1322 vHave.push_back(pindex->GetBlockHash());
experimental-genesis 1323
experimental-genesis 1324
experimental-genesis 1325 for (int i = 0; pindex && i < nStep; i++)
experimental-genesis 1326 pindex = pindex->pprev;
experimental-genesis 1327 if (vHave.size() > 10)
experimental-genesis 1328 nStep *= 2;
experimental-genesis 1329 }
experimental-genesis 1330 vHave.push_back(hashGenesisBlock);
experimental-genesis 1331 }
experimental-genesis 1332
experimental-genesis 1333 int GetDistanceBack()
experimental-genesis 1334 {
experimental-genesis 1335
experimental-genesis 1336 int nDistance = 0;
experimental-genesis 1337 int nStep = 1;
experimental-genesis 1338 BOOST_FOREACH(const uint256& hash, vHave)
experimental-genesis 1339 {
experimental-genesis 1340 std::map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash);
experimental-genesis 1341 if (mi != mapBlockIndex.end())
experimental-genesis 1342 {
experimental-genesis 1343 CBlockIndex* pindex = (*mi).second;
experimental-genesis 1344 if (pindex->IsInMainChain())
experimental-genesis 1345 return nDistance;
experimental-genesis 1346 }
experimental-genesis 1347 nDistance += nStep;
experimental-genesis 1348 if (nDistance > 10)
experimental-genesis 1349 nStep *= 2;
experimental-genesis 1350 }
experimental-genesis 1351 return nDistance;
experimental-genesis 1352 }
experimental-genesis 1353
experimental-genesis 1354 CBlockIndex* GetBlockIndex()
experimental-genesis 1355 {
experimental-genesis 1356
experimental-genesis 1357 BOOST_FOREACH(const uint256& hash, vHave)
experimental-genesis 1358 {
experimental-genesis 1359 std::map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash);
experimental-genesis 1360 if (mi != mapBlockIndex.end())
experimental-genesis 1361 {
experimental-genesis 1362 CBlockIndex* pindex = (*mi).second;
experimental-genesis 1363 if (pindex->IsInMainChain())
experimental-genesis 1364 return pindex;
experimental-genesis 1365 }
experimental-genesis 1366 }
experimental-genesis 1367 return pindexGenesisBlock;
experimental-genesis 1368 }
experimental-genesis 1369
experimental-genesis 1370 uint256 GetBlockHash()
experimental-genesis 1371 {
experimental-genesis 1372
experimental-genesis 1373 BOOST_FOREACH(const uint256& hash, vHave)
experimental-genesis 1374 {
experimental-genesis 1375 std::map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash);
experimental-genesis 1376 if (mi != mapBlockIndex.end())
experimental-genesis 1377 {
experimental-genesis 1378 CBlockIndex* pindex = (*mi).second;
experimental-genesis 1379 if (pindex->IsInMainChain())
experimental-genesis 1380 return hash;
experimental-genesis 1381 }
experimental-genesis 1382 }
experimental-genesis 1383 return hashGenesisBlock;
experimental-genesis 1384 }
experimental-genesis 1385
experimental-genesis 1386 int GetHeight()
experimental-genesis 1387 {
experimental-genesis 1388 CBlockIndex* pindex = GetBlockIndex();
experimental-genesis 1389 if (!pindex)
experimental-genesis 1390 return 0;
experimental-genesis 1391 return pindex->nHeight;
experimental-genesis 1392 }
experimental-genesis 1393 };
experimental-genesis 1394
experimental-genesis 1395
experimental-genesis 1396
experimental-genesis 1397
experimental-genesis 1398
experimental-genesis 1399
experimental-genesis 1400
experimental-genesis 1401
experimental-genesis 1402
experimental-genesis 1403
experimental-genesis 1404
experimental-genesis 1405
experimental-genesis 1406
experimental-genesis 1407
experimental-genesis 1408
experimental-genesis 1409
experimental-genesis 1410 class CUnsignedAlert
experimental-genesis 1411 {
experimental-genesis 1412 public:
experimental-genesis 1413 int nVersion;
experimental-genesis 1414 int64 nRelayUntil;
experimental-genesis 1415 int64 nExpiration;
experimental-genesis 1416 int nID;
experimental-genesis 1417 int nCancel;
experimental-genesis 1418 std::set<int> setCancel;
experimental-genesis 1419 int nMinVer;
experimental-genesis 1420 int nMaxVer;
experimental-genesis 1421 std::set<std::string> setSubVer;
experimental-genesis 1422 int nPriority;
experimental-genesis 1423
experimental-genesis 1424
experimental-genesis 1425 std::string strComment;
experimental-genesis 1426 std::string strStatusBar;
experimental-genesis 1427 std::string strReserved;
experimental-genesis 1428
experimental-genesis 1429 IMPLEMENT_SERIALIZE
experimental-genesis 1430 (
experimental-genesis 1431 READWRITE(this->nVersion);
experimental-genesis 1432 nVersion = this->nVersion;
experimental-genesis 1433 READWRITE(nRelayUntil);
experimental-genesis 1434 READWRITE(nExpiration);
experimental-genesis 1435 READWRITE(nID);
experimental-genesis 1436 READWRITE(nCancel);
experimental-genesis 1437 READWRITE(setCancel);
experimental-genesis 1438 READWRITE(nMinVer);
experimental-genesis 1439 READWRITE(nMaxVer);
experimental-genesis 1440 READWRITE(setSubVer);
experimental-genesis 1441 READWRITE(nPriority);
experimental-genesis 1442
experimental-genesis 1443 READWRITE(strComment);
experimental-genesis 1444 READWRITE(strStatusBar);
experimental-genesis 1445 READWRITE(strReserved);
experimental-genesis 1446 )
experimental-genesis 1447
experimental-genesis 1448 void SetNull()
experimental-genesis 1449 {
experimental-genesis 1450 nVersion = 1;
experimental-genesis 1451 nRelayUntil = 0;
experimental-genesis 1452 nExpiration = 0;
experimental-genesis 1453 nID = 0;
experimental-genesis 1454 nCancel = 0;
experimental-genesis 1455 setCancel.clear();
experimental-genesis 1456 nMinVer = 0;
experimental-genesis 1457 nMaxVer = 0;
experimental-genesis 1458 setSubVer.clear();
experimental-genesis 1459 nPriority = 0;
experimental-genesis 1460
experimental-genesis 1461 strComment.clear();
experimental-genesis 1462 strStatusBar.clear();
experimental-genesis 1463 strReserved.clear();
experimental-genesis 1464 }
experimental-genesis 1465
experimental-genesis 1466 std::string ToString() const
experimental-genesis 1467 {
experimental-genesis 1468 std::string strSetCancel;
experimental-genesis 1469 BOOST_FOREACH(int n, setCancel)
experimental-genesis 1470 strSetCancel += strprintf("%d ", n);
experimental-genesis 1471 std::string strSetSubVer;
experimental-genesis 1472 BOOST_FOREACH(std::string str, setSubVer)
experimental-genesis 1473 strSetSubVer += "\"" + str + "\" ";
experimental-genesis 1474 return strprintf(
experimental-genesis 1475 "CAlert(\n"
experimental-genesis 1476 " nVersion = %d\n"
experimental-genesis 1477 " nRelayUntil = %"PRI64d"\n"
experimental-genesis 1478 " nExpiration = %"PRI64d"\n"
experimental-genesis 1479 " nID = %d\n"
experimental-genesis 1480 " nCancel = %d\n"
experimental-genesis 1481 " setCancel = %s\n"
experimental-genesis 1482 " nMinVer = %d\n"
experimental-genesis 1483 " nMaxVer = %d\n"
experimental-genesis 1484 " setSubVer = %s\n"
experimental-genesis 1485 " nPriority = %d\n"
experimental-genesis 1486 " strComment = \"%s\"\n"
experimental-genesis 1487 " strStatusBar = \"%s\"\n"
experimental-genesis 1488 ")\n",
experimental-genesis 1489 nVersion,
experimental-genesis 1490 nRelayUntil,
experimental-genesis 1491 nExpiration,
experimental-genesis 1492 nID,
experimental-genesis 1493 nCancel,
experimental-genesis 1494 strSetCancel.c_str(),
experimental-genesis 1495 nMinVer,
experimental-genesis 1496 nMaxVer,
experimental-genesis 1497 strSetSubVer.c_str(),
experimental-genesis 1498 nPriority,
experimental-genesis 1499 strComment.c_str(),
experimental-genesis 1500 strStatusBar.c_str());
experimental-genesis 1501 }
experimental-genesis 1502
experimental-genesis 1503 void print() const
experimental-genesis 1504 {
experimental-genesis 1505 printf("%s", ToString().c_str());
experimental-genesis 1506 }
experimental-genesis 1507 };
experimental-genesis 1508
experimental-genesis 1509 class CAlert : public CUnsignedAlert
experimental-genesis 1510 {
experimental-genesis 1511 public:
experimental-genesis 1512 std::vector<unsigned char> vchMsg;
experimental-genesis 1513 std::vector<unsigned char> vchSig;
experimental-genesis 1514
experimental-genesis 1515 CAlert()
experimental-genesis 1516 {
experimental-genesis 1517 SetNull();
experimental-genesis 1518 }
experimental-genesis 1519
experimental-genesis 1520 IMPLEMENT_SERIALIZE
experimental-genesis 1521 (
experimental-genesis 1522 READWRITE(vchMsg);
experimental-genesis 1523 READWRITE(vchSig);
experimental-genesis 1524 )
experimental-genesis 1525
experimental-genesis 1526 void SetNull()
experimental-genesis 1527 {
experimental-genesis 1528 CUnsignedAlert::SetNull();
experimental-genesis 1529 vchMsg.clear();
experimental-genesis 1530 vchSig.clear();
experimental-genesis 1531 }
experimental-genesis 1532
experimental-genesis 1533 bool IsNull() const
experimental-genesis 1534 {
experimental-genesis 1535 return (nExpiration == 0);
experimental-genesis 1536 }
experimental-genesis 1537
experimental-genesis 1538 uint256 GetHash() const
experimental-genesis 1539 {
experimental-genesis 1540 return SerializeHash(*this);
experimental-genesis 1541 }
experimental-genesis 1542
experimental-genesis 1543 bool IsInEffect() const
experimental-genesis 1544 {
experimental-genesis 1545 return (GetAdjustedTime() < nExpiration);
experimental-genesis 1546 }
experimental-genesis 1547
experimental-genesis 1548 bool Cancels(const CAlert& alert) const
experimental-genesis 1549 {
experimental-genesis 1550 if (!IsInEffect())
experimental-genesis 1551 return false;
experimental-genesis 1552 return (alert.nID <= nCancel || setCancel.count(alert.nID));
experimental-genesis 1553 }
experimental-genesis 1554
experimental-genesis 1555 bool AppliesTo(int nVersion, std::string strSubVerIn) const
experimental-genesis 1556 {
experimental-genesis 1557 return (IsInEffect() &&
experimental-genesis 1558 nMinVer <= nVersion && nVersion <= nMaxVer &&
experimental-genesis 1559 (setSubVer.empty() || setSubVer.count(strSubVerIn)));
experimental-genesis 1560 }
experimental-genesis 1561
experimental-genesis 1562 bool AppliesToMe() const
experimental-genesis 1563 {
experimental-genesis 1564 return AppliesTo(VERSION, ::pszSubVer);
experimental-genesis 1565 }
experimental-genesis 1566
experimental-genesis 1567 bool RelayTo(CNode* pnode) const
experimental-genesis 1568 {
experimental-genesis 1569 if (!IsInEffect())
experimental-genesis 1570 return false;
experimental-genesis 1571
experimental-genesis 1572 if (pnode->setKnown.insert(GetHash()).second)
experimental-genesis 1573 {
experimental-genesis 1574 if (AppliesTo(pnode->nVersion, pnode->strSubVer) ||
experimental-genesis 1575 AppliesToMe() ||
experimental-genesis 1576 GetAdjustedTime() < nRelayUntil)
experimental-genesis 1577 {
experimental-genesis 1578 pnode->PushMessage("alert", *this);
experimental-genesis 1579 return true;
experimental-genesis 1580 }
experimental-genesis 1581 }
experimental-genesis 1582 return false;
experimental-genesis 1583 }
experimental-genesis 1584
experimental-genesis 1585 bool CheckSignature()
experimental-genesis 1586 {
experimental-genesis 1587 CKey key;
experimental-genesis 1588 if (!key.SetPubKey(ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284")))
experimental-genesis 1589 return error("CAlert::CheckSignature() : SetPubKey failed");
experimental-genesis 1590 if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
experimental-genesis 1591 return error("CAlert::CheckSignature() : verify signature failed");
experimental-genesis 1592
experimental-genesis 1593
experimental-genesis 1594 CDataStream sMsg(vchMsg);
experimental-genesis 1595 sMsg >> *(CUnsignedAlert*)this;
experimental-genesis 1596 return true;
experimental-genesis 1597 }
experimental-genesis 1598
experimental-genesis 1599 bool ProcessAlert();
experimental-genesis 1600 };
experimental-genesis 1601
experimental-genesis 1602 #endif