PPCoin: Remove genesis block tool
[novacoin.git] / src / init.cpp
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Copyright (c) 2011-2012 The PPCoin developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #include "db.h"
7 #include "walletdb.h"
8 #include "bitcoinrpc.h"
9 #include "net.h"
10 #include "init.h"
11 #include "util.h"
12 #include "ui_interface.h"
13 #include "checkpoints.h"
14 #include <boost/filesystem.hpp>
15 #include <boost/filesystem/fstream.hpp>
16 #include <boost/filesystem/convenience.hpp>
17 #include <boost/interprocess/sync/file_lock.hpp>
18
19 #ifndef WIN32
20 #include <signal.h>
21 #endif
22
23 using namespace std;
24 using namespace boost;
25
26 CWallet* pwalletMain;
27
28 //////////////////////////////////////////////////////////////////////////////
29 //
30 // Shutdown
31 //
32
33 void ExitTimeout(void* parg)
34 {
35 #ifdef WIN32
36     Sleep(5000);
37     ExitProcess(0);
38 #endif
39 }
40
41 void StartShutdown()
42 {
43 #ifdef QT_GUI
44     // ensure we leave the Qt main loop for a clean GUI exit (Shutdown() is called in bitcoin.cpp afterwards)
45     QueueShutdown();
46 #else
47     // Without UI, Shutdown() can simply be started in a new thread
48     CreateThread(Shutdown, NULL);
49 #endif
50 }
51
52 void Shutdown(void* parg)
53 {
54     static CCriticalSection cs_Shutdown;
55     static bool fTaken;
56     bool fFirstThread = false;
57     {
58         TRY_LOCK(cs_Shutdown, lockShutdown);
59         if (lockShutdown)
60         {
61             fFirstThread = !fTaken;
62             fTaken = true;
63         }
64     }
65     static bool fExit;
66     if (fFirstThread)
67     {
68         fShutdown = true;
69         nTransactionsUpdated++;
70         DBFlush(false);
71         StopNode();
72         DBFlush(true);
73         boost::filesystem::remove(GetPidFile());
74         UnregisterWallet(pwalletMain);
75         delete pwalletMain;
76         CreateThread(ExitTimeout, NULL);
77         Sleep(50);
78         printf("PPCoin exiting\n\n");
79         fExit = true;
80 #ifndef QT_GUI
81         // ensure non UI client get's exited here, but let Bitcoin-Qt reach return 0; in bitcoin.cpp
82         exit(0);
83 #endif
84     }
85     else
86     {
87         while (!fExit)
88             Sleep(500);
89         Sleep(100);
90         ExitThread(0);
91     }
92 }
93
94 void HandleSIGTERM(int)
95 {
96     fRequestShutdown = true;
97 }
98
99
100
101
102
103
104 //////////////////////////////////////////////////////////////////////////////
105 //
106 // Start
107 //
108 #if !defined(QT_GUI)
109 int main(int argc, char* argv[])
110 {
111     bool fRet = false;
112     fRet = AppInit(argc, argv);
113
114     if (fRet && fDaemon)
115         return 0;
116
117     return 1;
118 }
119 #endif
120
121 bool AppInit(int argc, char* argv[])
122 {
123     bool fRet = false;
124     try
125     {
126         fRet = AppInit2(argc, argv);
127     }
128     catch (std::exception& e) {
129         PrintException(&e, "AppInit()");
130     } catch (...) {
131         PrintException(NULL, "AppInit()");
132     }
133     if (!fRet)
134         Shutdown(NULL);
135     return fRet;
136 }
137
138 bool AppInit2(int argc, char* argv[])
139 {
140 #ifdef _MSC_VER
141     // Turn off microsoft heap dump noise
142     _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
143     _CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0));
144 #endif
145 #if _MSC_VER >= 1400
146     // Disable confusing "helpful" text message on abort, ctrl-c
147     _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
148 #endif
149 #ifndef WIN32
150     umask(077);
151 #endif
152 #ifndef WIN32
153     // Clean shutdown on SIGTERM
154     struct sigaction sa;
155     sa.sa_handler = HandleSIGTERM;
156     sigemptyset(&sa.sa_mask);
157     sa.sa_flags = 0;
158     sigaction(SIGTERM, &sa, NULL);
159     sigaction(SIGINT, &sa, NULL);
160     sigaction(SIGHUP, &sa, NULL);
161 #endif
162
163     //
164     // Parameters
165     //
166     // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
167 #if !defined(QT_GUI)
168     ParseParameters(argc, argv);
169     if (!boost::filesystem::is_directory(GetDataDir(false)))
170     {
171         fprintf(stderr, "Error: Specified directory does not exist\n");
172         Shutdown(NULL);
173     }
174     ReadConfigFile(mapArgs, mapMultiArgs);
175 #endif
176
177     if (mapArgs.count("-?") || mapArgs.count("--help"))
178     {
179         string strUsage = string() +
180           _("PPCoin version") + " " + FormatFullVersion() + "\n\n" +
181           _("Usage:") + "\t\t\t\t\t\t\t\t\t\t\n" +
182             "  ppcoind [options]                   \t  " + "\n" +
183             "  ppcoind [options] <command> [params]\t  " + _("Send command to -server or ppcoind") + "\n" +
184             "  ppcoind [options] help              \t\t  " + _("List commands") + "\n" +
185             "  ppcoind [options] help <command>    \t\t  " + _("Get help for a command") + "\n" +
186           _("Options:") + "\n" +
187             "  -conf=<file>     \t\t  " + _("Specify configuration file (default: ppcoin.conf)") + "\n" +
188             "  -pid=<file>      \t\t  " + _("Specify pid file (default: ppcoind.pid)") + "\n" +
189             "  -gen             \t\t  " + _("Generate coins") + "\n" +
190             "  -gen=0           \t\t  " + _("Don't generate coins") + "\n" +
191             "  -min             \t\t  " + _("Start minimized") + "\n" +
192             "  -splash          \t\t  " + _("Show splash screen on startup (default: 1)") + "\n" +
193             "  -datadir=<dir>   \t\t  " + _("Specify data directory") + "\n" +
194             "  -dbcache=<n>     \t\t  " + _("Set database cache size in megabytes (default: 25)") + "\n" +
195             "  -dblogsize=<n>   \t\t  " + _("Set database disk log size in megabytes (default: 100)") + "\n" +
196             "  -timeout=<n>     \t  "   + _("Specify connection timeout (in milliseconds)") + "\n" +
197             "  -proxy=<ip:port> \t  "   + _("Connect through socks4 proxy") + "\n" +
198             "  -dns             \t  "   + _("Allow DNS lookups for addnode and connect") + "\n" +
199             "  -port=<port>     \t\t  " + _("Listen for connections on <port> (default: 9901 or testnet: 9903)") + "\n" +
200             "  -maxconnections=<n>\t  " + _("Maintain at most <n> connections to peers (default: 125)") + "\n" +
201             "  -addnode=<ip>    \t  "   + _("Add a node to connect to and attempt to keep the connection open") + "\n" +
202             "  -connect=<ip>    \t\t  " + _("Connect only to the specified node") + "\n" +
203             "  -listen          \t  "   + _("Accept connections from outside (default: 1)") + "\n" +
204 #ifdef QT_GUI
205             "  -lang=<lang>     \t\t  " + _("Set language, for example \"de_DE\" (default: system locale)") + "\n" +
206 #endif
207             "  -dnsseed         \t  "   + _("Find peers using DNS lookup (default: 1)") + "\n" +
208             "  -banscore=<n>    \t  "   + _("Threshold for disconnecting misbehaving peers (default: 100)") + "\n" +
209             "  -bantime=<n>     \t  "   + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n" +
210             "  -maxreceivebuffer=<n>\t  " + _("Maximum per-connection receive buffer, <n>*1000 bytes (default: 10000)") + "\n" +
211             "  -maxsendbuffer=<n>\t  "   + _("Maximum per-connection send buffer, <n>*1000 bytes (default: 10000)") + "\n" +
212 #ifdef USE_UPNP
213 #if USE_UPNP
214             "  -upnp            \t  "   + _("Use Universal Plug and Play to map the listening port (default: 1)") + "\n" +
215 #else
216             "  -upnp            \t  "   + _("Use Universal Plug and Play to map the listening port (default: 0)") + "\n" +
217 #endif
218             "  -detachdb        \t  "   + _("Detach block and address databases. Increases shutdown time (default: 0)") + "\n" +
219 #endif
220             "  -paytxfee=<amt>  \t  "   + _("Fee per KB to add to transactions you send") + "\n" +
221 #ifdef QT_GUI
222             "  -server          \t\t  " + _("Accept command line and JSON-RPC commands") + "\n" +
223 #endif
224 #if !defined(WIN32) && !defined(QT_GUI)
225             "  -daemon          \t\t  " + _("Run in the background as a daemon and accept commands") + "\n" +
226 #endif
227             "  -testnet         \t\t  " + _("Use the test network") + "\n" +
228             "  -debug           \t\t  " + _("Output extra debugging information") + "\n" +
229             "  -logtimestamps   \t  "   + _("Prepend debug output with timestamp") + "\n" +
230             "  -printtoconsole  \t  "   + _("Send trace/debug info to console instead of debug.log file") + "\n" +
231 #ifdef WIN32
232             "  -printtodebugger \t  "   + _("Send trace/debug info to debugger") + "\n" +
233 #endif
234             "  -rpcuser=<user>  \t  "   + _("Username for JSON-RPC connections") + "\n" +
235             "  -rpcpassword=<pw>\t  "   + _("Password for JSON-RPC connections") + "\n" +
236             "  -rpcport=<port>  \t\t  " + _("Listen for JSON-RPC connections on <port> (default: 9902)") + "\n" +
237             "  -rpcallowip=<ip> \t\t  " + _("Allow JSON-RPC connections from specified IP address") + "\n" +
238             "  -rpcconnect=<ip> \t  "   + _("Send commands to node running on <ip> (default: 127.0.0.1)") + "\n" +
239             "  -blocknotify=<cmd> "     + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n" +
240             "  -upgradewallet   \t  "   + _("Upgrade wallet to latest format") + "\n" +
241             "  -keypool=<n>     \t  "   + _("Set key pool size to <n> (default: 100)") + "\n" +
242             "  -rescan          \t  "   + _("Rescan the block chain for missing wallet transactions") + "\n" +
243             "  -checkblocks=<n> \t\t  " + _("How many blocks to check at startup (default: 2500, 0 = all)") + "\n" +
244             "  -checklevel=<n>  \t\t  " + _("How thorough the block verification is (0-6, default: 1)") + "\n";
245
246         strUsage += string() +
247             _("\nSSL options: (see the Bitcoin Wiki for SSL setup instructions)") + "\n" +
248             "  -rpcssl                                \t  " + _("Use OpenSSL (https) for JSON-RPC connections") + "\n" +
249             "  -rpcsslcertificatechainfile=<file.cert>\t  " + _("Server certificate file (default: server.cert)") + "\n" +
250             "  -rpcsslprivatekeyfile=<file.pem>       \t  " + _("Server private key (default: server.pem)") + "\n" +
251             "  -rpcsslciphers=<ciphers>               \t  " + _("Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)") + "\n";
252
253         strUsage += string() +
254             "  -?               \t\t  " + _("This help message") + "\n";
255
256         // Remove tabs
257         strUsage.erase(std::remove(strUsage.begin(), strUsage.end(), '\t'), strUsage.end());
258 #if defined(QT_GUI) && defined(WIN32)
259         // On windows, show a message box, as there is no stderr
260         ThreadSafeMessageBox(strUsage, _("Usage"), wxOK | wxMODAL);
261 #else
262         fprintf(stderr, "%s", strUsage.c_str());
263 #endif
264         return false;
265     }
266
267     fTestNet = GetBoolArg("-testnet");
268     if (fTestNet)
269     {
270         SoftSetBoolArg("-irc", true);
271     }
272
273     fDebug = GetBoolArg("-debug");
274     fDetachDB = GetBoolArg("-detachdb", false);
275
276 #if !defined(WIN32) && !defined(QT_GUI)
277     fDaemon = GetBoolArg("-daemon");
278 #else
279     fDaemon = false;
280 #endif
281
282     if (fDaemon)
283         fServer = true;
284     else
285         fServer = GetBoolArg("-server");
286
287     /* force fServer when running without GUI */
288 #if !defined(QT_GUI)
289     fServer = true;
290 #endif
291     fPrintToConsole = GetBoolArg("-printtoconsole");
292     fPrintToDebugger = GetBoolArg("-printtodebugger");
293     fLogTimestamps = GetBoolArg("-logtimestamps");
294
295 #ifndef QT_GUI
296     for (int i = 1; i < argc; i++)
297         if (!IsSwitchChar(argv[i][0]) && !(strlen(argv[i]) > 7 && strncasecmp(argv[i], "bitcoin:", 8) == 0))
298             fCommandLine = true;
299
300     if (fCommandLine)
301     {
302         int ret = CommandLineRPC(argc, argv);
303         exit(ret);
304     }
305 #endif
306
307 #if !defined(WIN32) && !defined(QT_GUI)
308     if (fDaemon)
309     {
310         // Daemonize
311         pid_t pid = fork();
312         if (pid < 0)
313         {
314             fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
315             return false;
316         }
317         if (pid > 0)
318         {
319             CreatePidFile(GetPidFile(), pid);
320             return true;
321         }
322
323         pid_t sid = setsid();
324         if (sid < 0)
325             fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
326     }
327 #endif
328
329     if (!fDebug)
330         ShrinkDebugFile();
331     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
332     printf("PPCoin version %s (%s)\n", FormatFullVersion().c_str(), CLIENT_DATE.c_str());
333     printf("Default data directory %s\n", GetDefaultDataDir().string().c_str());
334
335     if (GetBoolArg("-loadblockindextest"))
336     {
337         CTxDB txdb("r");
338         txdb.LoadBlockIndex();
339         PrintBlockTree();
340         return false;
341     }
342
343     // Make sure only a single bitcoin process is using the data directory.
344     boost::filesystem::path pathLockFile = GetDataDir() / ".lock";
345     FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist.
346     if (file) fclose(file);
347     static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
348     if (!lock.try_lock())
349     {
350         ThreadSafeMessageBox(strprintf(_("Cannot obtain a lock on data directory %s.  PPCoin is probably already running."), GetDataDir().string().c_str()), _("PPCoin"), wxOK|wxMODAL);
351         return false;
352     }
353
354     std::ostringstream strErrors;
355     //
356     // Load data files
357     //
358     if (fDaemon)
359         fprintf(stdout, "ppcoin server starting\n");
360     int64 nStart;
361
362     InitMessage(_("Loading addresses..."));
363     printf("Loading addresses...\n");
364     nStart = GetTimeMillis();
365     if (!LoadAddresses())
366         strErrors << _("Error loading addr.dat") << "\n";
367     printf(" addresses   %15"PRI64d"ms\n", GetTimeMillis() - nStart);
368
369     InitMessage(_("Loading block index..."));
370     printf("Loading block index...\n");
371     nStart = GetTimeMillis();
372     if (!LoadBlockIndex())
373         strErrors << _("Error loading blkindex.dat") << "\n";
374
375     // as LoadBlockIndex can take several minutes, it's possible the user
376     // requested to kill bitcoin-qt during the last operation. If so, exit.
377     // As the program has not fully started yet, Shutdown() is possibly overkill.
378     if (fRequestShutdown)
379     {
380         printf("Shutdown requested. Exiting.\n");
381         return false;
382     }
383     printf(" block index %15"PRI64d"ms\n", GetTimeMillis() - nStart);
384
385     InitMessage(_("Loading wallet..."));
386     printf("Loading wallet...\n");
387     nStart = GetTimeMillis();
388     bool fFirstRun;
389     pwalletMain = new CWallet("wallet.dat");
390     int nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun);
391     if (nLoadWalletRet != DB_LOAD_OK)
392     {
393         if (nLoadWalletRet == DB_CORRUPT)
394             strErrors << _("Error loading wallet.dat: Wallet corrupted") << "\n";
395         else if (nLoadWalletRet == DB_TOO_NEW)
396             strErrors << _("Error loading wallet.dat: Wallet requires newer version of PPCoin") << "\n";
397         else if (nLoadWalletRet == DB_NEED_REWRITE)
398         {
399             strErrors << _("Wallet needed to be rewritten: restart PPCoin to complete") << "\n";
400             printf("%s", strErrors.str().c_str());
401             ThreadSafeMessageBox(strErrors.str(), _("PPCoin"), wxOK | wxICON_ERROR | wxMODAL);
402             return false;
403         }
404         else
405             strErrors << _("Error loading wallet.dat") << "\n";
406     }
407
408     if (GetBoolArg("-upgradewallet", fFirstRun))
409     {
410         int nMaxVersion = GetArg("-upgradewallet", 0);
411         if (nMaxVersion == 0) // the -walletupgrade without argument case
412         {
413             printf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
414             nMaxVersion = CLIENT_VERSION;
415             pwalletMain->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
416         }
417         else
418             printf("Allowing wallet upgrade up to %i\n", nMaxVersion);
419         if (nMaxVersion < pwalletMain->GetVersion())
420             strErrors << _("Cannot downgrade wallet") << "\n";
421         pwalletMain->SetMaxVersion(nMaxVersion);
422     }
423
424     if (fFirstRun)
425     {
426         // Create new keyUser and set as default key
427         RandAddSeedPerfmon();
428
429         std::vector<unsigned char> newDefaultKey;
430         if (!pwalletMain->GetKeyFromPool(newDefaultKey, false))
431             strErrors << _("Cannot initialize keypool") << "\n";
432         pwalletMain->SetDefaultKey(newDefaultKey);
433         if (!pwalletMain->SetAddressBookName(CBitcoinAddress(pwalletMain->vchDefaultKey), ""))
434             strErrors << _("Cannot write default address") << "\n";
435     }
436
437     printf("%s", strErrors.str().c_str());
438     printf(" wallet      %15"PRI64d"ms\n", GetTimeMillis() - nStart);
439
440     RegisterWallet(pwalletMain);
441
442     CBlockIndex *pindexRescan = pindexBest;
443     if (GetBoolArg("-rescan"))
444         pindexRescan = pindexGenesisBlock;
445     else
446     {
447         CWalletDB walletdb("wallet.dat");
448         CBlockLocator locator;
449         if (walletdb.ReadBestBlock(locator))
450             pindexRescan = locator.GetBlockIndex();
451     }
452     if (pindexBest != pindexRescan)
453     {
454         InitMessage(_("Rescanning..."));
455         printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight);
456         nStart = GetTimeMillis();
457         pwalletMain->ScanForWalletTransactions(pindexRescan, true);
458         printf(" rescan      %15"PRI64d"ms\n", GetTimeMillis() - nStart);
459     }
460
461     InitMessage(_("Done loading"));
462     printf("Done loading\n");
463
464     //// debug print
465     printf("mapBlockIndex.size() = %d\n",   mapBlockIndex.size());
466     printf("nBestHeight = %d\n",            nBestHeight);
467     printf("setKeyPool.size() = %d\n",      pwalletMain->setKeyPool.size());
468     printf("mapWallet.size() = %d\n",       pwalletMain->mapWallet.size());
469     printf("mapAddressBook.size() = %d\n",  pwalletMain->mapAddressBook.size());
470
471     if (!strErrors.str().empty())
472     {
473         ThreadSafeMessageBox(strErrors.str(), _("PPCoin"), wxOK | wxICON_ERROR | wxMODAL);
474         return false;
475     }
476
477     // Add wallet transactions that aren't already in a block to mapTransactions
478     pwalletMain->ReacceptWalletTransactions();
479
480     // Note: Bitcoin-QT stores several settings in the wallet, so we want
481     // to load the wallet BEFORE parsing command-line arguments, so
482     // the command-line/bitcoin.conf settings override GUI setting.
483
484     //
485     // Parameters
486     //
487     if (GetBoolArg("-printblockindex") || GetBoolArg("-printblocktree"))
488     {
489         PrintBlockTree();
490         return false;
491     }
492
493     if (mapArgs.count("-timeout"))
494     {
495         int nNewTimeout = GetArg("-timeout", 5000);
496         if (nNewTimeout > 0 && nNewTimeout < 600000)
497             nConnectTimeout = nNewTimeout;
498     }
499
500     if (mapArgs.count("-printblock"))
501     {
502         string strMatch = mapArgs["-printblock"];
503         int nFound = 0;
504         for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)
505         {
506             uint256 hash = (*mi).first;
507             if (strncmp(hash.ToString().c_str(), strMatch.c_str(), strMatch.size()) == 0)
508             {
509                 CBlockIndex* pindex = (*mi).second;
510                 CBlock block;
511                 block.ReadFromDisk(pindex);
512                 block.BuildMerkleTree();
513                 block.print();
514                 printf("\n");
515                 nFound++;
516             }
517         }
518         if (nFound == 0)
519             printf("No blocks matching %s were found\n", strMatch.c_str());
520         return false;
521     }
522
523     if (mapArgs.count("-proxy"))
524     {
525         fUseProxy = true;
526         addrProxy = CService(mapArgs["-proxy"], 9050);
527         if (!addrProxy.IsValid())
528         {
529             ThreadSafeMessageBox(_("Invalid -proxy address"), _("PPCcoin"), wxOK | wxMODAL);
530             return false;
531         }
532     }
533
534     bool fTor = (fUseProxy && addrProxy.GetPort() == 9050);
535     if (fTor)
536     {
537         // Use SoftSetBoolArg here so user can override any of these if they wish.
538         // Note: the GetBoolArg() calls for all of these must happen later.
539         SoftSetBoolArg("-listen", false);
540         SoftSetBoolArg("-irc", false);
541         SoftSetBoolArg("-dnsseed", false);
542         SoftSetBoolArg("-upnp", false);
543         SoftSetBoolArg("-dns", false);
544     }
545
546     fAllowDNS = GetBoolArg("-dns");
547     fNoListen = !GetBoolArg("-listen", true);
548
549     // Continue to put "/P2SH/" in the coinbase to monitor
550     // BIP16 support.
551     // This can be removed eventually...
552     const char* pszP2SH = "/P2SH/";
553     COINBASE_FLAGS << std::vector<unsigned char>(pszP2SH, pszP2SH+strlen(pszP2SH));
554
555     if (!fNoListen)
556     {
557         std::string strError;
558         if (!BindListenPort(strError))
559         {
560             ThreadSafeMessageBox(strError, _("PPCoin"), wxOK | wxMODAL);
561             return false;
562         }
563     }
564
565     if (mapArgs.count("-addnode"))
566     {
567         BOOST_FOREACH(string strAddr, mapMultiArgs["-addnode"])
568         {
569             CAddress addr(CService(strAddr, GetDefaultPort(), fAllowDNS));
570             addr.nTime = 0; // so it won't relay unless successfully connected
571             if (addr.IsValid())
572                 addrman.Add(addr, CNetAddr("127.0.0.1"));
573         }
574     }
575
576     if (mapArgs.count("-paytxfee"))
577     {
578         if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee) || nTransactionFee < MIN_TX_FEE)
579         {
580             ThreadSafeMessageBox(_("Invalid amount for -paytxfee=<amount>"), _("PPCoin"), wxOK | wxMODAL);
581             return false;
582         }
583         if (nTransactionFee > 0.25 * COIN)
584             ThreadSafeMessageBox(_("Warning: -paytxfee is set very high.  This is the transaction fee you will pay if you send a transaction."), _("PPCoin"), wxOK | wxICON_EXCLAMATION | wxMODAL);
585     }
586
587     if (mapArgs.count("-reservebalance")) // ppcoin: reserve balance amount
588     {
589         int64 nReserveBalance = 0;
590         if (!ParseMoney(mapArgs["-reservebalance"], nReserveBalance))
591         {
592             ThreadSafeMessageBox(_("Invalid amount for -reservebalance=<amount>"), _("PPCoin"), wxOK | wxMODAL);
593             return false;
594         }
595     }
596
597     if (mapArgs.count("-checkpointkey")) // ppcoin: checkpoint master priv key
598     {
599         if (!Checkpoints::SetCheckpointPrivKey(GetArg("-checkpointkey", "")))
600             ThreadSafeMessageBox(_("Unable to sign checkpoint, wrong checkpointkey?\n"), _("PPCoin"), wxOK | wxMODAL);
601     }
602
603     //
604     // Start the node
605     //
606     if (!CheckDiskSpace())
607         return false;
608
609     RandAddSeedPerfmon();
610
611     if (!CreateThread(StartNode, NULL))
612         ThreadSafeMessageBox(_("Error: CreateThread(StartNode) failed"), _("PPCoin"), wxOK | wxMODAL);
613
614     if (fServer)
615         CreateThread(ThreadRPCServer, NULL);
616
617 #ifdef QT_GUI
618     if (GetStartOnSystemStartup())
619         SetStartOnSystemStartup(true); // Remove startup links
620 #endif
621
622 #if !defined(QT_GUI)
623     while (1)
624         Sleep(5000);
625 #endif
626
627     return true;
628 }
629