// Bitflash entry point -- starts node threads then runs GUI (or headless). #include "headers_core.h" #ifndef _WIN32 #include #endif int RunGUI(int argc, char* argv[]); // Global definitions (were in ui.cpp, now here) map mapAddressBook; bool gPoolServerRunning = false; static bool arg(int argc, char* argv[], const char* key) { for (int i=1;i 65535) fprintf(stderr, "Ignoring /port=%s: not a port number\n", strPort.c_str()); else { nListenPort = htons((unsigned short)nPort); // Or we would announce a port we never bound. addrLocalHost.port = nListenPort; } } } int main(int argc, char* argv[]) { if (arg(argc,argv,"/help") || arg(argc,argv,"-help") || arg(argc,argv,"--help") || arg(argc,argv,"/?")) { PrintUsage(); return 0; } ParseStartupArguments(argc, argv); printf("Loading block index...\n"); string strErrors; if (!LoadBlockIndex()) { fprintf(stderr,"LoadBlockIndex failed\n"); return 1; } printf("Loading wallet...\n"); if (!LoadWallet()) { fprintf(stderr,"LoadWallet failed\n"); return 1; } printf("Height=%d\n", nBestHeight); ReacceptWalletTransactions(); if (!StartNode(strErrors)) { fprintf(stderr,"StartNode: %s\n",strErrors.c_str()); return 1; } if (nMineMode == MINE_OPERATOR) { gPoolServerRunning = true; gPoolRunning = true; if (_beginthread(ThreadRPCServer, 0, NULL) == (uintptr_t)-1) printf("Error: _beginthread(ThreadRPCServer) failed\n"); } if (fGenerateBitcoins) if (_beginthread(ThreadBitcoinMiner, 0, NULL) == (uintptr_t)-1) printf("Error: _beginthread(ThreadBitcoinMiner) failed\n"); bool fHeadless = arg(argc,argv,"/nogui") || arg(argc,argv,"-nogui") || arg(argc,argv,"/daemon") || arg(argc,argv,"-daemon"); if (fHeadless) { #ifndef _WIN32 auto sig=[](int){fShutdown=true;}; signal(SIGINT,sig); signal(SIGTERM,sig); #endif printf("Running headless. Ctrl-C to stop.\n"); while (!fShutdown) Sleep(500); StopNode(); return 0; } int ret = RunGUI(argc, argv); fShutdown = true; StopNode(); return ret; }