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"
14 #include <boost/algorithm/string/predicate.hpp>
15 #include <boost/filesystem.hpp>
16 #include <boost/thread.hpp>
18 /* Introduction text for doxygen: */
20 /*! \mainpage Developer documentation
22 * \section intro_sec Introduction
24 * This is the developer documentation of the reference client for an experimental new digital currency called Bitcoin (https://www.bitcoin.org/),
25 * which enables instant payments to anyone, anywhere in the world. Bitcoin uses peer-to-peer technology to operate
26 * with no central authority: managing transactions and issuing money are carried out collectively by the network.
28 * The software is a community-driven open source project, released under the MIT license.
31 * Use the buttons <code>Namespaces</code>, <code>Classes</code> or <code>Files</code> at the top of the page to start navigating the code.
35 extern char ASSETCHAINS_SYMBOL[16];
36 void komodo_gateway_iteration(char *symbol);
37 void komodo_iteration(char *symbol);
38 int32_t komodo_is_issuer();
40 void WaitForShutdown(boost::thread_group* threadGroup)
42 bool fShutdown = ShutdownRequested();
43 // Tell the main threads to shutdown.
47 if ( komodo_is_issuer() != 0 )
48 komodo_gateway_iteration(ASSETCHAINS_SYMBOL);
49 else komodo_iteration((char *)"EUR");
51 fShutdown = ShutdownRequested();
55 threadGroup->interrupt_all();
56 threadGroup->join_all();
60 //////////////////////////////////////////////////////////////////////////////
64 extern int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,ASSETCHAIN_INIT;
65 extern std::string NOTARY_PUBKEY;
66 int32_t komodo_is_issuer();
68 bool AppInit(int argc, char* argv[])
70 boost::thread_group threadGroup;
78 // If Qt is used, parameters/komodo.conf are parsed in qt/bitcoin.cpp's main()
79 ParseParameters(argc, argv);
81 // Process help and version before taking care about datadir
82 if (mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help") || mapArgs.count("-version"))
84 std::string strUsage = _("Komodo Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n";
86 if (mapArgs.count("-version"))
88 strUsage += LicenseInfo();
92 strUsage += "\n" + _("Usage:") + "\n" +
93 " komodod [options] " + _("Start Komodo Daemon") + "\n";
95 strUsage += "\n" + HelpMessage(HMM_BITCOIND);
98 fprintf(stdout, "%s", strUsage.c_str());
106 fprintf(stderr,"call komodo_args NOTARY_PUBKEY.(%s)\n",NOTARY_PUBKEY.c_str());
107 while ( ASSETCHAIN_INIT == 0 )
109 if ( komodo_is_issuer() != 0 )
110 komodo_gateway_iteration(ASSETCHAINS_SYMBOL);
113 if (!boost::filesystem::is_directory(GetDataDir(false)))
115 fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
120 ReadConfigFile(mapArgs, mapMultiArgs);
121 } catch (const std::exception& e) {
122 fprintf(stderr,"Error reading configuration file: %s\n", e.what());
125 // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
126 if (!SelectParamsFromCommandLine()) {
127 fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
132 bool fCommandLine = false;
133 for (int i = 1; i < argc; i++)
134 if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "komodo:"))
139 fprintf(stderr, "Error: There is no RPC client functionality in komodod. Use the komodo-cli utility instead.\n");
144 fDaemon = GetBoolArg("-daemon", false);
147 extern char ASSETCHAINS_SYMBOL[16];
148 fprintf(stdout, "Komodo %s server starting\n",ASSETCHAINS_SYMBOL);
154 fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
157 if (pid > 0) // Parent process, pid is child process id
161 // Child process falls through to rest of initialization
163 pid_t sid = setsid();
165 fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
168 SoftSetBoolArg("-server", true);
170 fRet = AppInit2(threadGroup, scheduler);
172 catch (const std::exception& e) {
173 PrintExceptionContinue(&e, "AppInit()");
175 PrintExceptionContinue(NULL, "AppInit()");
180 threadGroup.interrupt_all();
181 // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
182 // the startup-failure cases to make sure they don't result in a hang due to some
183 // thread-blocking-waiting-for-another-thread-during-startup case
185 WaitForShutdown(&threadGroup);
192 int main(int argc, char* argv[])
196 // Connect bitcoind signal handlers
199 return (AppInit(argc, argv) ? 0 : 1);