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