1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2013 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #include "clientversion.h"
11 #include "scheduler.h"
13 #include "httpserver.h"
15 #include "rpcserver.h"
17 #include <boost/algorithm/string/predicate.hpp>
18 #include <boost/filesystem.hpp>
19 #include <boost/thread.hpp>
28 /* Introduction text for doxygen: */
30 /*! \mainpage Developer documentation
32 * \section intro_sec Introduction
34 * This is the developer documentation of the reference client for an experimental new digital currency called Bitcoin (https://www.bitcoin.org/),
35 * which enables instant payments to anyone, anywhere in the world. Bitcoin uses peer-to-peer technology to operate
36 * with no central authority: managing transactions and issuing money are carried out collectively by the network.
38 * The software is a community-driven open source project, released under the MIT license.
41 * Use the buttons <code>Namespaces</code>, <code>Classes</code> or <code>Files</code> at the top of the page to start navigating the code.
45 #define KOMODO_ASSETCHAIN_MAXLEN 65
46 extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
47 void komodo_passport_iteration();
49 void WaitForShutdown(boost::thread_group* threadGroup)
51 bool fShutdown = ShutdownRequested();
52 // Tell the main threads to shutdown.
55 //fprintf(stderr,"call passport iteration\n");
56 if ( ASSETCHAINS_SYMBOL[0] == 0 )
58 komodo_passport_iteration();
60 } else MilliSleep(1000);
61 fShutdown = ShutdownRequested();
65 Interrupt(*threadGroup);
66 threadGroup->join_all();
70 //////////////////////////////////////////////////////////////////////////////
74 extern int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,ASSETCHAIN_INIT;
75 extern std::string NOTARY_PUBKEY;
76 int32_t komodo_is_issuer();
77 void komodo_passport_iteration();
79 bool AppInit(int argc, char* argv[])
81 boost::thread_group threadGroup;
89 // If Qt is used, parameters/komodo.conf are parsed in qt/bitcoin.cpp's main()
90 ParseParameters(argc, argv);
92 // Process help and version before taking care about datadir
93 if (mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help") || mapArgs.count("-version"))
95 std::string strUsage = _("Komodo Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n" + PrivacyInfo();
97 if (mapArgs.count("-version"))
99 strUsage += LicenseInfo();
103 strUsage += "\n" + _("Usage:") + "\n" +
104 " komodod [options] " + _("Start Komodo Daemon") + "\n";
106 strUsage += "\n" + HelpMessage(HMM_BITCOIND);
109 fprintf(stdout, "%s", strUsage.c_str());
115 void komodo_args(char *argv0);
116 komodo_args(argv[0]);
117 fprintf(stderr,"call komodo_args.(%s) NOTARY_PUBKEY.(%s)\n",argv[0],NOTARY_PUBKEY.c_str());
118 while ( ASSETCHAIN_INIT == 0 )
120 //if ( komodo_is_issuer() != 0 )
121 // komodo_passport_iteration();
123 boost::this_thread::sleep_for(boost::chrono::seconds(1));
128 printf("initialized %s\n",ASSETCHAINS_SYMBOL);
129 if (!boost::filesystem::is_directory(GetDataDir(false)))
131 fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
136 ReadConfigFile(mapArgs, mapMultiArgs);
137 } catch (const missing_zcash_conf& e) {
139 (_("Before starting zcashd, you need to create a configuration file:\n"
141 "It can be completely empty! That indicates you are happy with the default\n"
142 "configuration of zcashd. But requiring a configuration file to start ensures\n"
143 "that zcashd won't accidentally compromise your privacy if there was a default\n"
144 "option you needed to change.\n"
146 "You can look at the example configuration file for suggestions of default\n"
147 "options that you may want to change. It should be in one of these locations,\n"
148 "depending on how you installed Zcash:\n") +
149 _("- Source code: %s\n"
150 "- .deb package: %s\n")).c_str(),
151 GetConfigFile().string().c_str(),
152 "contrib/debian/examples/zcash.conf",
153 "/usr/share/doc/zcash/examples/zcash.conf");
155 } catch (const std::exception& e) {
156 fprintf(stderr,"Error reading configuration file: %s\n", e.what());
159 // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
160 if (!SelectParamsFromCommandLine()) {
161 fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
166 bool fCommandLine = false;
167 for (int i = 1; i < argc; i++)
168 if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "komodo:"))
173 fprintf(stderr, "Error: There is no RPC client functionality in komodod. Use the komodo-cli utility instead.\n");
178 fDaemon = GetBoolArg("-daemon", false);
181 fprintf(stdout, "Komodo %s server starting\n",ASSETCHAINS_SYMBOL);
187 fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
190 if (pid > 0) // Parent process, pid is child process id
194 // Child process falls through to rest of initialization
196 pid_t sid = setsid();
198 fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
201 SoftSetBoolArg("-server", true);
203 fRet = AppInit2(threadGroup, scheduler);
205 catch (const std::exception& e) {
206 PrintExceptionContinue(&e, "AppInit()");
208 PrintExceptionContinue(NULL, "AppInit()");
212 Interrupt(threadGroup);
213 // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
214 // the startup-failure cases to make sure they don't result in a hang due to some
215 // thread-blocking-waiting-for-another-thread-during-startup case
217 WaitForShutdown(&threadGroup);
224 int main(int argc, char* argv[])
228 // Connect bitcoind signal handlers
231 return (AppInit(argc, argv) ? 0 : 1);