raw
experimental-genesis    1 //  /****************************\
experimental-genesis 2 // * EXPERIMENTAL BRANCH. *
experimental-genesis 3 // * FOR LABORATORY USE ONLY. *
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 // Copyright (c) 2009-2010 Satoshi Nakamoto
experimental-genesis 33 // Copyright (c) 2009-2012 The Bitcoin developers
experimental-genesis 34 // Distributed under the MIT/X11 software license, see the accompanying
experimental-genesis 35 // file license.txt or http://www.opensource.org/licenses/mit-license.php.
experimental-genesis 36 #include "headers.h"
experimental-genesis 37 #include "db.h"
experimental-genesis 38 #include "bitcoinrpc.h"
experimental-genesis 39 #include "net.h"
experimental-genesis 40 #include "init.h"
experimental-genesis 41 #include "strlcpy.h"
experimental-genesis 42 #include <boost/filesystem.hpp>
experimental-genesis 43 #include <boost/filesystem/fstream.hpp>
experimental-genesis 44 #include <boost/interprocess/sync/file_lock.hpp>
experimental-genesis 45
experimental-genesis 46 #if defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED)
experimental-genesis 47 #define _BITCOIN_QT_PLUGINS_INCLUDED
experimental-genesis 48 #define __INSURE__
experimental-genesis 49 #include <QtPlugin>
experimental-genesis 50 Q_IMPORT_PLUGIN(qcncodecs)
experimental-genesis 51 Q_IMPORT_PLUGIN(qjpcodecs)
experimental-genesis 52 Q_IMPORT_PLUGIN(qtwcodecs)
experimental-genesis 53 Q_IMPORT_PLUGIN(qkrcodecs)
experimental-genesis 54 Q_IMPORT_PLUGIN(qtaccessiblewidgets)
experimental-genesis 55 #endif
experimental-genesis 56
experimental-genesis 57 using namespace std;
experimental-genesis 58 using namespace boost;
experimental-genesis 59
experimental-genesis 60 CWallet* pwalletMain;
experimental-genesis 61
experimental-genesis 62 //////////////////////////////////////////////////////////////////////////////
experimental-genesis 63 //
experimental-genesis 64 // Shutdown
experimental-genesis 65 //
experimental-genesis 66
experimental-genesis 67 void ExitTimeout(void* parg)
experimental-genesis 68 {
experimental-genesis 69 #ifdef WIN32
experimental-genesis 70 Sleep(5000);
experimental-genesis 71 ExitProcess(0);
experimental-genesis 72 #endif
experimental-genesis 73 }
experimental-genesis 74
experimental-genesis 75 void Shutdown(void* parg)
experimental-genesis 76 {
experimental-genesis 77 static CCriticalSection cs_Shutdown;
experimental-genesis 78 static bool fTaken;
experimental-genesis 79 bool fFirstThread = false;
experimental-genesis 80 TRY_CRITICAL_BLOCK(cs_Shutdown)
experimental-genesis 81 {
experimental-genesis 82 fFirstThread = !fTaken;
experimental-genesis 83 fTaken = true;
experimental-genesis 84 }
experimental-genesis 85 static bool fExit;
experimental-genesis 86 if (fFirstThread)
experimental-genesis 87 {
experimental-genesis 88 fShutdown = true;
experimental-genesis 89 nTransactionsUpdated++;
experimental-genesis 90 DBFlush(false);
experimental-genesis 91 StopNode();
experimental-genesis 92 DBFlush(true);
experimental-genesis 93 boost::filesystem::remove(GetPidFile());
experimental-genesis 94 UnregisterWallet(pwalletMain);
experimental-genesis 95 delete pwalletMain;
experimental-genesis 96 CreateThread(ExitTimeout, NULL);
experimental-genesis 97 Sleep(50);
experimental-genesis 98 printf("Bitcoin exiting\n\n");
experimental-genesis 99 fExit = true;
experimental-genesis 100 exit(0);
experimental-genesis 101 }
experimental-genesis 102 else
experimental-genesis 103 {
experimental-genesis 104 while (!fExit)
experimental-genesis 105 Sleep(500);
experimental-genesis 106 Sleep(100);
experimental-genesis 107 ExitThread(0);
experimental-genesis 108 }
experimental-genesis 109 }
experimental-genesis 110
experimental-genesis 111 void HandleSIGTERM(int)
experimental-genesis 112 {
experimental-genesis 113 fRequestShutdown = true;
experimental-genesis 114 }
experimental-genesis 115
experimental-genesis 116
experimental-genesis 117
experimental-genesis 118
experimental-genesis 119
experimental-genesis 120
experimental-genesis 121 //////////////////////////////////////////////////////////////////////////////
experimental-genesis 122 //
experimental-genesis 123 // Start
experimental-genesis 124 //
experimental-genesis 125 #if !defined(QT_GUI)
experimental-genesis 126 int main(int argc, char* argv[])
experimental-genesis 127 {
experimental-genesis 128 bool fRet = false;
experimental-genesis 129 fRet = AppInit(argc, argv);
experimental-genesis 130
experimental-genesis 131 if (fRet && fDaemon)
experimental-genesis 132 return 0;
experimental-genesis 133
experimental-genesis 134 return 1;
experimental-genesis 135 }
experimental-genesis 136 #endif
experimental-genesis 137
experimental-genesis 138 bool AppInit(int argc, char* argv[])
experimental-genesis 139 {
experimental-genesis 140 bool fRet = false;
experimental-genesis 141 try
experimental-genesis 142 {
experimental-genesis 143 fRet = AppInit2(argc, argv);
experimental-genesis 144 }
experimental-genesis 145 catch (std::exception& e) {
experimental-genesis 146 PrintException(&e, "AppInit()");
experimental-genesis 147 } catch (...) {
experimental-genesis 148 PrintException(NULL, "AppInit()");
experimental-genesis 149 }
experimental-genesis 150 if (!fRet)
experimental-genesis 151 Shutdown(NULL);
experimental-genesis 152 return fRet;
experimental-genesis 153 }
experimental-genesis 154
experimental-genesis 155 bool AppInit2(int argc, char* argv[])
experimental-genesis 156 {
experimental-genesis 157 #ifdef _MSC_VER
experimental-genesis 158 // Turn off microsoft heap dump noise
experimental-genesis 159 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
experimental-genesis 160 _CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0));
experimental-genesis 161 #endif
experimental-genesis 162 #if _MSC_VER >= 1400
experimental-genesis 163 // Disable confusing "helpful" text message on abort, ctrl-c
experimental-genesis 164 _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
experimental-genesis 165 #endif
experimental-genesis 166 #ifndef WIN32
experimental-genesis 167 umask(077);
experimental-genesis 168 #endif
experimental-genesis 169 #ifndef WIN32
experimental-genesis 170 // Clean shutdown on SIGTERM
experimental-genesis 171 struct sigaction sa;
experimental-genesis 172 sa.sa_handler = HandleSIGTERM;
experimental-genesis 173 sigemptyset(&sa.sa_mask);
experimental-genesis 174 sa.sa_flags = 0;
experimental-genesis 175 sigaction(SIGTERM, &sa, NULL);
experimental-genesis 176 sigaction(SIGINT, &sa, NULL);
experimental-genesis 177 sigaction(SIGHUP, &sa, NULL);
experimental-genesis 178 #endif
experimental-genesis 179
experimental-genesis 180 //
experimental-genesis 181 // Parameters
experimental-genesis 182 //
experimental-genesis 183 ParseParameters(argc, argv);
experimental-genesis 184
experimental-genesis 185 if (mapArgs.count("-datadir"))
experimental-genesis 186 {
experimental-genesis 187 if (filesystem::is_directory(filesystem::system_complete(mapArgs["-datadir"])))
experimental-genesis 188 {
experimental-genesis 189 filesystem::path pathDataDir = filesystem::system_complete(mapArgs["-datadir"]);
experimental-genesis 190 strlcpy(pszSetDataDir, pathDataDir.string().c_str(), sizeof(pszSetDataDir));
experimental-genesis 191 }
experimental-genesis 192 else
experimental-genesis 193 {
experimental-genesis 194 fprintf(stderr, "Error: Specified directory does not exist\n");
experimental-genesis 195 Shutdown(NULL);
experimental-genesis 196 }
experimental-genesis 197 }
experimental-genesis 198
experimental-genesis 199
experimental-genesis 200 ReadConfigFile(mapArgs, mapMultiArgs); // Must be done after processing datadir
experimental-genesis 201
experimental-genesis 202 if (mapArgs.count("-?") || mapArgs.count("--help"))
experimental-genesis 203 {
experimental-genesis 204 string strUsage = string() +
experimental-genesis 205 _("Bitcoin version") + " " + FormatFullVersion() + "\n\n" +
experimental-genesis 206 _("Usage:") + "\t\t\t\t\t\t\t\t\t\t\n" +
experimental-genesis 207 " bitcoind [options] \t " + "\n" +
experimental-genesis 208 " bitcoind [options] <command> [params]\t " + _("Send command to -server or bitcoind\n") +
experimental-genesis 209 " bitcoind [options] help \t\t " + _("List commands\n") +
experimental-genesis 210 " bitcoind [options] help <command> \t\t " + _("Get help for a command\n") +
experimental-genesis 211 _("Options:\n") +
experimental-genesis 212 " -conf=<file> \t\t " + _("Specify configuration file (default: bitcoin.conf)\n") +
experimental-genesis 213 " -pid=<file> \t\t " + _("Specify pid file (default: bitcoind.pid)\n") +
experimental-genesis 214 " -gen \t\t " + _("Generate coins\n") +
experimental-genesis 215 " -gen=0 \t\t " + _("Don't generate coins\n") +
experimental-genesis 216 " -min \t\t " + _("Start minimized\n") +
experimental-genesis 217 " -datadir=<dir> \t\t " + _("Specify data directory\n") +
experimental-genesis 218 " -timeout=<n> \t " + _("Specify connection timeout (in milliseconds)\n") +
experimental-genesis 219 " -proxy=<ip:port> \t " + _("Connect through socks4 proxy\n") +
experimental-genesis 220 " -dns \t " + _("Allow DNS lookups for addnode and connect\n") +
experimental-genesis 221 " -port=<port> \t\t " + _("Listen for connections on <port> (default: 8333 or testnet: 18333)\n") +
experimental-genesis 222 " -maxconnections=<n>\t " + _("Maintain at most <n> connections to peers (default: 125)\n") +
experimental-genesis 223 " -addnode=<ip> \t " + _("Add a node to connect to\n") +
experimental-genesis 224 " -connect=<ip> \t\t " + _("Connect only to the specified node\n") +
experimental-genesis 225 " -noirc \t " + _("Don't find peers using internet relay chat\n") +
experimental-genesis 226 " -nolisten \t " + _("Don't accept connections from outside\n") +
experimental-genesis 227 " -nodnsseed \t " + _("Don't bootstrap list of peers using DNS\n") +
experimental-genesis 228 " -banscore=<n> \t " + _("Threshold for disconnecting misbehaving peers (default: 100)\n") +
experimental-genesis 229 " -bantime=<n> \t " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)\n") +
experimental-genesis 230 " -maxreceivebuffer=<n>\t " + _("Maximum per-connection receive buffer, <n>*1000 bytes (default: 10000)\n") +
experimental-genesis 231 " -maxsendbuffer=<n>\t " + _("Maximum per-connection send buffer, <n>*1000 bytes (default: 10000)\n") +
experimental-genesis 232 #ifdef USE_UPNP
experimental-genesis 233 #if USE_UPNP
experimental-genesis 234 " -noupnp \t " + _("Don't attempt to use UPnP to map the listening port\n") +
experimental-genesis 235 #else
experimental-genesis 236 " -upnp \t " + _("Attempt to use UPnP to map the listening port\n") +
experimental-genesis 237 #endif
experimental-genesis 238 #endif
experimental-genesis 239 " -paytxfee=<amt> \t " + _("Fee per kB to add to transactions you send\n") +
experimental-genesis 240 #ifdef QT_GUI
experimental-genesis 241 " -server \t\t " + _("Accept command line and JSON-RPC commands\n") +
experimental-genesis 242 #endif
experimental-genesis 243 #if !defined(WIN32) && !defined(QT_GUI)
experimental-genesis 244 " -daemon \t\t " + _("Run in the background as a daemon and accept commands\n") +
experimental-genesis 245 #endif
experimental-genesis 246 " -testnet \t\t " + _("Use the test network\n") +
experimental-genesis 247 " -debug \t\t " + _("Output extra debugging information\n") +
experimental-genesis 248 " -logtimestamps \t " + _("Prepend debug output with timestamp\n") +
experimental-genesis 249 " -printtoconsole \t " + _("Send trace/debug info to console instead of debug.log file\n") +
experimental-genesis 250 #ifdef WIN32
experimental-genesis 251 " -printtodebugger \t " + _("Send trace/debug info to debugger\n") +
experimental-genesis 252 #endif
experimental-genesis 253 " -rpcuser=<user> \t " + _("Username for JSON-RPC connections\n") +
experimental-genesis 254 " -rpcpassword=<pw>\t " + _("Password for JSON-RPC connections\n") +
experimental-genesis 255 " -rpcport=<port> \t\t " + _("Listen for JSON-RPC connections on <port> (default: 8332)\n") +
experimental-genesis 256 " -rpcallowip=<ip> \t\t " + _("Allow JSON-RPC connections from specified IP address\n") +
experimental-genesis 257 " -rpcconnect=<ip> \t " + _("Send commands to node running on <ip> (default: 127.0.0.1)\n") +
experimental-genesis 258 " -keypool=<n> \t " + _("Set key pool size to <n> (default: 100)\n") +
experimental-genesis 259 " -rescan \t " + _("Rescan the block chain for missing wallet transactions\n");
experimental-genesis 260
experimental-genesis 261 #ifdef USE_SSL
experimental-genesis 262 strUsage += string() +
experimental-genesis 263 _("\nSSL options: (see the Bitcoin Wiki for SSL setup instructions)\n") +
experimental-genesis 264 " -rpcssl \t " + _("Use OpenSSL (https) for JSON-RPC connections\n") +
experimental-genesis 265 " -rpcsslcertificatechainfile=<file.cert>\t " + _("Server certificate file (default: server.cert)\n") +
experimental-genesis 266 " -rpcsslprivatekeyfile=<file.pem> \t " + _("Server private key (default: server.pem)\n") +
experimental-genesis 267 " -rpcsslciphers=<ciphers> \t " + _("Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)\n");
experimental-genesis 268 #endif
experimental-genesis 269
experimental-genesis 270 strUsage += string() +
experimental-genesis 271 " -? \t\t " + _("This help message\n");
experimental-genesis 272
experimental-genesis 273 // Remove tabs
experimental-genesis 274 strUsage.erase(std::remove(strUsage.begin(), strUsage.end(), '\t'), strUsage.end());
experimental-genesis 275 #if defined(QT_GUI) && defined(WIN32)
experimental-genesis 276 // On windows, show a message box, as there is no stderr
experimental-genesis 277 wxMessageBox(strUsage, "Usage");
experimental-genesis 278 #else
experimental-genesis 279 fprintf(stderr, "%s", strUsage.c_str());
experimental-genesis 280 #endif
experimental-genesis 281 return false;
experimental-genesis 282 }
experimental-genesis 283
experimental-genesis 284 fTestNet = GetBoolArg("-testnet");
experimental-genesis 285 fDebug = GetBoolArg("-debug");
experimental-genesis 286
experimental-genesis 287 #if !defined(WIN32) && !defined(QT_GUI)
experimental-genesis 288 fDaemon = GetBoolArg("-daemon");
experimental-genesis 289 #else
experimental-genesis 290 fDaemon = false;
experimental-genesis 291 #endif
experimental-genesis 292
experimental-genesis 293 if (fDaemon)
experimental-genesis 294 fServer = true;
experimental-genesis 295 else
experimental-genesis 296 fServer = GetBoolArg("-server");
experimental-genesis 297
experimental-genesis 298 /* force fServer when running without GUI */
experimental-genesis 299 #if !defined(QT_GUI)
experimental-genesis 300 fServer = true;
experimental-genesis 301 #endif
experimental-genesis 302 fPrintToConsole = GetBoolArg("-printtoconsole");
experimental-genesis 303 fPrintToDebugger = GetBoolArg("-printtodebugger");
experimental-genesis 304 fLogTimestamps = GetBoolArg("-logtimestamps");
experimental-genesis 305
experimental-genesis 306 #ifndef QT_GUI
experimental-genesis 307 for (int i = 1; i < argc; i++)
experimental-genesis 308 if (!IsSwitchChar(argv[i][0]))
experimental-genesis 309 fCommandLine = true;
experimental-genesis 310
experimental-genesis 311 if (fCommandLine)
experimental-genesis 312 {
experimental-genesis 313 int ret = CommandLineRPC(argc, argv);
experimental-genesis 314 exit(ret);
experimental-genesis 315 }
experimental-genesis 316 #endif
experimental-genesis 317
experimental-genesis 318 #if !defined(WIN32) && !defined(QT_GUI)
experimental-genesis 319 if (fDaemon)
experimental-genesis 320 {
experimental-genesis 321 // Daemonize
experimental-genesis 322 pid_t pid = fork();
experimental-genesis 323 if (pid < 0)
experimental-genesis 324 {
experimental-genesis 325 fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
experimental-genesis 326 return false;
experimental-genesis 327 }
experimental-genesis 328 if (pid > 0)
experimental-genesis 329 {
experimental-genesis 330 CreatePidFile(GetPidFile(), pid);
experimental-genesis 331 return true;
experimental-genesis 332 }
experimental-genesis 333
experimental-genesis 334 pid_t sid = setsid();
experimental-genesis 335 if (sid < 0)
experimental-genesis 336 fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
experimental-genesis 337 }
experimental-genesis 338 #endif
experimental-genesis 339
experimental-genesis 340 if (!fDebug && !pszSetDataDir[0])
experimental-genesis 341 ShrinkDebugFile();
experimental-genesis 342 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
experimental-genesis 343 printf("Bitcoin version %s\n", FormatFullVersion().c_str());
experimental-genesis 344 printf("Default data directory %s\n", GetDefaultDataDir().c_str());
experimental-genesis 345
experimental-genesis 346 if (GetBoolArg("-loadblockindextest"))
experimental-genesis 347 {
experimental-genesis 348 CTxDB txdb("r");
experimental-genesis 349 txdb.LoadBlockIndex();
experimental-genesis 350 PrintBlockTree();
experimental-genesis 351 return false;
experimental-genesis 352 }
experimental-genesis 353
experimental-genesis 354 // Make sure only a single bitcoin process is using the data directory.
experimental-genesis 355 string strLockFile = GetDataDir() + "/.lock";
experimental-genesis 356 FILE* file = fopen(strLockFile.c_str(), "a"); // empty lock file; created if it doesn't exist.
experimental-genesis 357 if (file) fclose(file);
experimental-genesis 358 static boost::interprocess::file_lock lock(strLockFile.c_str());
experimental-genesis 359 if (!lock.try_lock())
experimental-genesis 360 {
experimental-genesis 361 wxMessageBox(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin is probably already running."), GetDataDir().c_str()), "Bitcoin");
experimental-genesis 362 return false;
experimental-genesis 363 }
experimental-genesis 364
experimental-genesis 365 string strErrors;
experimental-genesis 366
experimental-genesis 367 //
experimental-genesis 368 // Load data files
experimental-genesis 369 //
experimental-genesis 370 if (fDaemon)
experimental-genesis 371 fprintf(stdout, "bitcoin server starting\n");
experimental-genesis 372 strErrors = "";
experimental-genesis 373 int64 nStart;
experimental-genesis 374
experimental-genesis 375 InitMessage(_("Loading addresses..."));
experimental-genesis 376 printf("Loading addresses...\n");
experimental-genesis 377 nStart = GetTimeMillis();
experimental-genesis 378 if (!LoadAddresses())
experimental-genesis 379 strErrors += _("Error loading addr.dat \n");
experimental-genesis 380 printf(" addresses %15"PRI64d"ms\n", GetTimeMillis() - nStart);
experimental-genesis 381
experimental-genesis 382 InitMessage(_("Loading block index..."));
experimental-genesis 383 printf("Loading block index...\n");
experimental-genesis 384 nStart = GetTimeMillis();
experimental-genesis 385 if (!LoadBlockIndex())
experimental-genesis 386 strErrors += _("Error loading blkindex.dat \n");
experimental-genesis 387 printf(" block index %15"PRI64d"ms\n", GetTimeMillis() - nStart);
experimental-genesis 388
experimental-genesis 389 InitMessage(_("Loading wallet..."));
experimental-genesis 390 printf("Loading wallet...\n");
experimental-genesis 391 nStart = GetTimeMillis();
experimental-genesis 392 bool fFirstRun;
experimental-genesis 393 pwalletMain = new CWallet("wallet.dat");
experimental-genesis 394 int nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun);
experimental-genesis 395 if (nLoadWalletRet != DB_LOAD_OK)
experimental-genesis 396 {
experimental-genesis 397 if (nLoadWalletRet == DB_CORRUPT)
experimental-genesis 398 strErrors += _("Error loading wallet.dat: Wallet corrupted \n");
experimental-genesis 399 else if (nLoadWalletRet == DB_TOO_NEW)
experimental-genesis 400 strErrors += _("Error loading wallet.dat: Wallet requires newer version of Bitcoin \n");
experimental-genesis 401 else if (nLoadWalletRet == DB_NEED_REWRITE)
experimental-genesis 402 {
experimental-genesis 403 strErrors += _("Wallet needed to be rewritten: restart Bitcoin to complete \n");
experimental-genesis 404 wxMessageBox(strErrors, "Bitcoin", wxOK | wxICON_ERROR);
experimental-genesis 405 return false;
experimental-genesis 406 }
experimental-genesis 407 else
experimental-genesis 408 strErrors += _("Error loading wallet.dat \n");
experimental-genesis 409 }
experimental-genesis 410 printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart);
experimental-genesis 411
experimental-genesis 412 RegisterWallet(pwalletMain);
experimental-genesis 413
experimental-genesis 414 CBlockIndex *pindexRescan = pindexBest;
experimental-genesis 415 if (GetBoolArg("-rescan"))
experimental-genesis 416 pindexRescan = pindexGenesisBlock;
experimental-genesis 417 else
experimental-genesis 418 {
experimental-genesis 419 CWalletDB walletdb("wallet.dat");
experimental-genesis 420 CBlockLocator locator;
experimental-genesis 421 if (walletdb.ReadBestBlock(locator))
experimental-genesis 422 pindexRescan = locator.GetBlockIndex();
experimental-genesis 423 }
experimental-genesis 424 if (pindexBest != pindexRescan)
experimental-genesis 425 {
experimental-genesis 426 InitMessage(_("Rescanning..."));
experimental-genesis 427 printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight);
experimental-genesis 428 nStart = GetTimeMillis();
experimental-genesis 429 pwalletMain->ScanForWalletTransactions(pindexRescan, true);
experimental-genesis 430 printf(" rescan %15"PRI64d"ms\n", GetTimeMillis() - nStart);
experimental-genesis 431 }
experimental-genesis 432
experimental-genesis 433 InitMessage(_("Done loading"));
experimental-genesis 434 printf("Done loading\n");
experimental-genesis 435
experimental-genesis 436 //// debug print
experimental-genesis 437 printf("mapBlockIndex.size() = %d\n", mapBlockIndex.size());
experimental-genesis 438 printf("nBestHeight = %d\n", nBestHeight);
experimental-genesis 439 printf("setKeyPool.size() = %d\n", pwalletMain->setKeyPool.size());
experimental-genesis 440 printf("mapWallet.size() = %d\n", pwalletMain->mapWallet.size());
experimental-genesis 441 printf("mapAddressBook.size() = %d\n", pwalletMain->mapAddressBook.size());
experimental-genesis 442
experimental-genesis 443 if (!strErrors.empty())
experimental-genesis 444 {
experimental-genesis 445 wxMessageBox(strErrors, "Bitcoin", wxOK | wxICON_ERROR);
experimental-genesis 446 return false;
experimental-genesis 447 }
experimental-genesis 448
experimental-genesis 449 // Add wallet transactions that aren't already in a block to mapTransactions
experimental-genesis 450 pwalletMain->ReacceptWalletTransactions();
experimental-genesis 451
experimental-genesis 452 // Note: Bitcoin-QT stores several settings in the wallet, so we want
experimental-genesis 453 // to load the wallet BEFORE parsing command-line arguments, so
experimental-genesis 454 // the command-line/bitcoin.conf settings override GUI setting.
experimental-genesis 455
experimental-genesis 456 //
experimental-genesis 457 // Parameters
experimental-genesis 458 //
experimental-genesis 459 if (GetBoolArg("-printblockindex") || GetBoolArg("-printblocktree"))
experimental-genesis 460 {
experimental-genesis 461 PrintBlockTree();
experimental-genesis 462 return false;
experimental-genesis 463 }
experimental-genesis 464
experimental-genesis 465 if (mapArgs.count("-timeout"))
experimental-genesis 466 {
experimental-genesis 467 int nNewTimeout = GetArg("-timeout", 5000);
experimental-genesis 468 if (nNewTimeout > 0 && nNewTimeout < 600000)
experimental-genesis 469 nConnectTimeout = nNewTimeout;
experimental-genesis 470 }
experimental-genesis 471
experimental-genesis 472 if (mapArgs.count("-printblock"))
experimental-genesis 473 {
experimental-genesis 474 string strMatch = mapArgs["-printblock"];
experimental-genesis 475 int nFound = 0;
experimental-genesis 476 for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)
experimental-genesis 477 {
experimental-genesis 478 uint256 hash = (*mi).first;
experimental-genesis 479 if (strncmp(hash.ToString().c_str(), strMatch.c_str(), strMatch.size()) == 0)
experimental-genesis 480 {
experimental-genesis 481 CBlockIndex* pindex = (*mi).second;
experimental-genesis 482 CBlock block;
experimental-genesis 483 block.ReadFromDisk(pindex);
experimental-genesis 484 block.BuildMerkleTree();
experimental-genesis 485 block.print();
experimental-genesis 486 printf("\n");
experimental-genesis 487 nFound++;
experimental-genesis 488 }
experimental-genesis 489 }
experimental-genesis 490 if (nFound == 0)
experimental-genesis 491 printf("No blocks matching %s were found\n", strMatch.c_str());
experimental-genesis 492 return false;
experimental-genesis 493 }
experimental-genesis 494
experimental-genesis 495 fGenerateBitcoins = GetBoolArg("-gen");
experimental-genesis 496
experimental-genesis 497 if (mapArgs.count("-proxy"))
experimental-genesis 498 {
experimental-genesis 499 fUseProxy = true;
experimental-genesis 500 addrProxy = CAddress(mapArgs["-proxy"]);
experimental-genesis 501 if (!addrProxy.IsValid())
experimental-genesis 502 {
experimental-genesis 503 wxMessageBox(_("Invalid -proxy address"), "Bitcoin");
experimental-genesis 504 return false;
experimental-genesis 505 }
experimental-genesis 506 }
experimental-genesis 507
experimental-genesis 508 bool fTor = (fUseProxy && addrProxy.port == htons(9050));
experimental-genesis 509 if (fTor)
experimental-genesis 510 {
experimental-genesis 511 // Use SoftSetArg here so user can override any of these if they wish.
experimental-genesis 512 // Note: the GetBoolArg() calls for all of these must happen later.
experimental-genesis 513 SoftSetArg("-nolisten", true);
experimental-genesis 514 SoftSetArg("-noirc", true);
experimental-genesis 515 SoftSetArg("-nodnsseed", true);
experimental-genesis 516 SoftSetArg("-noupnp", true);
experimental-genesis 517 SoftSetArg("-upnp", false);
experimental-genesis 518 SoftSetArg("-dns", false);
experimental-genesis 519 }
experimental-genesis 520
experimental-genesis 521 fAllowDNS = GetBoolArg("-dns");
experimental-genesis 522 fNoListen = GetBoolArg("-nolisten");
experimental-genesis 523
experimental-genesis 524 // Command-line args override in-wallet settings:
experimental-genesis 525 if (mapArgs.count("-upnp"))
experimental-genesis 526 fUseUPnP = GetBoolArg("-upnp");
experimental-genesis 527 else if (mapArgs.count("-noupnp"))
experimental-genesis 528 fUseUPnP = !GetBoolArg("-noupnp");
experimental-genesis 529
experimental-genesis 530 if (!fNoListen)
experimental-genesis 531 {
experimental-genesis 532 if (!BindListenPort(strErrors))
experimental-genesis 533 {
experimental-genesis 534 wxMessageBox(strErrors, "Bitcoin");
experimental-genesis 535 return false;
experimental-genesis 536 }
experimental-genesis 537 }
experimental-genesis 538
experimental-genesis 539 if (mapArgs.count("-addnode"))
experimental-genesis 540 {
experimental-genesis 541 BOOST_FOREACH(string strAddr, mapMultiArgs["-addnode"])
experimental-genesis 542 {
experimental-genesis 543 CAddress addr(strAddr, fAllowDNS);
experimental-genesis 544 addr.nTime = 0; // so it won't relay unless successfully connected
experimental-genesis 545 if (addr.IsValid())
experimental-genesis 546 AddAddress(addr);
experimental-genesis 547 }
experimental-genesis 548 }
experimental-genesis 549
experimental-genesis 550 if (mapArgs.count("-paytxfee"))
experimental-genesis 551 {
experimental-genesis 552 if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee))
experimental-genesis 553 {
experimental-genesis 554 wxMessageBox(_("Invalid amount for -paytxfee=<amount>"), "Bitcoin");
experimental-genesis 555 return false;
experimental-genesis 556 }
experimental-genesis 557 if (nTransactionFee > 0.25 * COIN)
experimental-genesis 558 wxMessageBox(_("Warning: -paytxfee is set very high. This is the transaction fee you will pay if you send a transaction."), "Bitcoin", wxOK | wxICON_EXCLAMATION);
experimental-genesis 559 }
experimental-genesis 560
experimental-genesis 561 //
experimental-genesis 562 // Start the node
experimental-genesis 563 //
experimental-genesis 564 if (!CheckDiskSpace())
experimental-genesis 565 return false;
experimental-genesis 566
experimental-genesis 567 RandAddSeedPerfmon();
experimental-genesis 568
experimental-genesis 569 if (!CreateThread(StartNode, NULL))
experimental-genesis 570 wxMessageBox(_("Error: CreateThread(StartNode) failed"), "Bitcoin");
experimental-genesis 571
experimental-genesis 572 if (fServer)
experimental-genesis 573 CreateThread(ThreadRPCServer, NULL);
experimental-genesis 574
experimental-genesis 575 #if !defined(QT_GUI)
experimental-genesis 576 while (1)
experimental-genesis 577 Sleep(5000);
experimental-genesis 578 #endif
experimental-genesis 579
experimental-genesis 580 return true;
experimental-genesis 581 }