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"
7 #include "rpc/server.h"
11 #include "scheduler.h"
13 #include "httpserver.h"
16 #include <boost/algorithm/string/predicate.hpp>
17 #include <boost/filesystem.hpp>
18 #include <boost/thread.hpp>
27 /* Introduction text for doxygen: */
29 /*! \mainpage Developer documentation
31 * \section intro_sec Introduction
33 * This is the developer documentation of the reference client for an experimental new digital currency called Bitcoin (https://www.bitcoin.org/),
34 * which enables instant payments to anyone, anywhere in the world. Bitcoin uses peer-to-peer technology to operate
35 * with no central authority: managing transactions and issuing money are carried out collectively by the network.
37 * The software is a community-driven open source project, released under the MIT license.
40 * Use the buttons <code>Namespaces</code>, <code>Classes</code> or <code>Files</code> at the top of the page to start navigating the code.
44 #define KOMODO_ASSETCHAIN_MAXLEN 65
45 extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
46 void komodo_passport_iteration();
47 uint64_t komodo_interestsum();
48 int32_t komodo_longestchain();
50 void WaitForShutdown(boost::thread_group* threadGroup)
52 bool fShutdown = ShutdownRequested();
53 // Tell the main threads to shutdown.
56 //fprintf(stderr,"call passport iteration\n");
57 if ( ASSETCHAINS_SYMBOL[0] == 0 )
59 komodo_passport_iteration();
65 komodo_longestchain();
68 fShutdown = ShutdownRequested();
72 Interrupt(*threadGroup);
73 threadGroup->join_all();
77 //////////////////////////////////////////////////////////////////////////////
81 extern int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,ASSETCHAIN_INIT;
82 extern std::string NOTARY_PUBKEY;
83 int32_t komodo_is_issuer();
84 void komodo_passport_iteration();
86 bool AppInit(int argc, char* argv[])
88 boost::thread_group threadGroup;
96 // If Qt is used, parameters/komodo.conf are parsed in qt/bitcoin.cpp's main()
97 ParseParameters(argc, argv);
99 // Process help and version before taking care about datadir
100 if (mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help") || mapArgs.count("-version"))
102 std::string strUsage = _("Komodo Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n" + PrivacyInfo();
104 if (mapArgs.count("-version"))
106 strUsage += LicenseInfo();
110 strUsage += "\n" + _("Usage:") + "\n" +
111 " komodod [options] " + _("Start Komodo Daemon") + "\n";
113 strUsage += "\n" + HelpMessage(HMM_BITCOIND);
116 fprintf(stdout, "%s", strUsage.c_str());
122 void komodo_args(char *argv0);
123 komodo_args(argv[0]);
124 fprintf(stderr,"call komodo_args.(%s) NOTARY_PUBKEY.(%s)\n",argv[0],NOTARY_PUBKEY.c_str());
125 while ( ASSETCHAIN_INIT == 0 )
127 //if ( komodo_is_issuer() != 0 )
128 // komodo_passport_iteration();
130 boost::this_thread::sleep_for(boost::chrono::seconds(1));
135 printf("initialized %s at %u\n",ASSETCHAINS_SYMBOL,(uint32_t)time(NULL));
136 if (!boost::filesystem::is_directory(GetDataDir(false)))
138 fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
143 ReadConfigFile(mapArgs, mapMultiArgs);
144 } catch (const missing_zcash_conf& e) {
146 (_("Before starting komodod, you need to create a configuration file:\n"
148 "It can be completely empty! That indicates you are happy with the default\n"
149 "configuration of komodod. But requiring a configuration file to start ensures\n"
150 "that komodod won't accidentally compromise your privacy if there was a default\n"
151 "option you needed to change.\n"
153 "You can look at the example configuration file for suggestions of default\n"
154 "options that you may want to change. It should be in one of these locations,\n"
155 "depending on how you installed Komodo:\n") +
156 _("- Source code: %s\n"
157 "- .deb package: %s\n")).c_str(),
158 GetConfigFile().string().c_str(),
159 "contrib/debian/examples/komodo.conf",
160 "/usr/share/doc/komodo/examples/komodo.conf");
162 } catch (const std::exception& e) {
163 fprintf(stderr,"Error reading configuration file: %s\n", e.what());
166 // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
167 if (!SelectParamsFromCommandLine()) {
168 fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
173 bool fCommandLine = false;
174 for (int i = 1; i < argc; i++)
175 if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "komodo:"))
180 fprintf(stderr, "Error: There is no RPC client functionality in komodod. Use the komodo-cli utility instead.\n");
185 fDaemon = GetBoolArg("-daemon", false);
188 fprintf(stdout, "Komodo %s server starting\n",ASSETCHAINS_SYMBOL);
194 fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
197 if (pid > 0) // Parent process, pid is child process id
201 // Child process falls through to rest of initialization
203 pid_t sid = setsid();
205 fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
208 SoftSetBoolArg("-server", true);
210 fRet = AppInit2(threadGroup, scheduler);
212 catch (const std::exception& e) {
213 PrintExceptionContinue(&e, "AppInit()");
215 PrintExceptionContinue(NULL, "AppInit()");
219 Interrupt(threadGroup);
220 // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
221 // the startup-failure cases to make sure they don't result in a hang due to some
222 // thread-blocking-waiting-for-another-thread-during-startup case
224 WaitForShutdown(&threadGroup);
231 int main(int argc, char* argv[])
235 // Connect bitcoind signal handlers
238 return (AppInit(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE);