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_passport_iteration();
38 void WaitForShutdown(boost::thread_group* threadGroup)
40 bool fShutdown = ShutdownRequested();
41 // Tell the main threads to shutdown.
44 //fprintf(stderr,"call passport iteration\n");
45 if ( ASSETCHAINS_SYMBOL[0] == 0 )
47 komodo_passport_iteration();
49 } else MilliSleep(1000);
50 fShutdown = ShutdownRequested();
54 threadGroup->interrupt_all();
55 threadGroup->join_all();
59 //////////////////////////////////////////////////////////////////////////////
63 extern int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,ASSETCHAIN_INIT;
64 extern std::string NOTARY_PUBKEY;
65 int32_t komodo_is_issuer();
66 void komodo_passport_iteration();
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_passport_iteration();
113 printf("initialized %s\n",ASSETCHAINS_SYMBOL);
114 if (!boost::filesystem::is_directory(GetDataDir(false)))
116 fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
121 ReadConfigFile(mapArgs, mapMultiArgs);
122 } catch (const missing_zcash_conf& e) {
124 (_("Before starting zcashd, you need to create a configuration file:\n"
126 "It can be completely empty! That indicates you are happy with the default\n"
127 "configuration of zcashd. But requiring a configuration file to start ensures\n"
128 "that zcashd won't accidentally compromise your privacy if there was a default\n"
129 "option you needed to change.\n"
131 "You can look at the example configuration file for suggestions of default\n"
132 "options that you may want to change. It should be in one of these locations,\n"
133 "depending on how you installed Zcash:\n") +
134 _("- Source code: %s\n"
135 "- .deb package: %s\n")).c_str(),
136 GetConfigFile().string().c_str(),
137 "contrib/DEBIAN/examples/zcash.conf",
138 "/usr/share/doc/zcash/examples/zcash.conf");
140 } catch (const std::exception& e) {
141 fprintf(stderr,"Error reading configuration file: %s\n", e.what());
144 // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
145 if (!SelectParamsFromCommandLine()) {
146 fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
151 bool fCommandLine = false;
152 for (int i = 1; i < argc; i++)
153 if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "komodo:"))
158 fprintf(stderr, "Error: There is no RPC client functionality in komodod. Use the komodo-cli utility instead.\n");
163 fDaemon = GetBoolArg("-daemon", false);
166 fprintf(stdout, "Komodo %s server starting\n",ASSETCHAINS_SYMBOL);
172 fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
175 if (pid > 0) // Parent process, pid is child process id
179 // Child process falls through to rest of initialization
181 pid_t sid = setsid();
183 fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
186 SoftSetBoolArg("-server", true);
188 fRet = AppInit2(threadGroup, scheduler);
190 catch (const std::exception& e) {
191 PrintExceptionContinue(&e, "AppInit()");
193 PrintExceptionContinue(NULL, "AppInit()");
197 threadGroup.interrupt_all();
198 // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
199 // the startup-failure cases to make sure they don't result in a hang due to some
200 // thread-blocking-waiting-for-another-thread-during-startup case
202 WaitForShutdown(&threadGroup);
209 int main(int argc, char* argv[])
213 // Connect bitcoind signal handlers
216 return (AppInit(argc, argv) ? 0 : 1);