Anoncoin  0.9.4
P2P Digital Currency
anoncoin-cli.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2013 The Bitcoin developers
3 // Copyright (c) 2013-2014 The Anoncoin Core developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 // Many builder specific things set in the config file, don't forget to include it this way in your source files.
8 #ifdef HAVE_CONFIG_H
10 #endif
11 
12 #include "util.h"
13 #include "init.h"
14 #include "rpcclient.h"
15 #include "rpcprotocol.h"
16 #include "ui_interface.h" /* for _(...) */
17 #include "chainparams.h"
18 #include "clientversion.h"
19 
20 #include <boost/filesystem/operations.hpp>
21 
23 //
24 // Start
25 //
26 static bool AppInitRPC(int argc, char* argv[])
27 {
28  //
29  // Parameters
30  //
31  ParseParameters(argc, argv);
32  if (!boost::filesystem::is_directory(GetDataDir(false)))
33  {
34  fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
35  return false;
36  }
37  try {
39  } catch(std::exception &e) {
40  fprintf(stderr,"Error reading configuration file: %s\n", e.what());
41  return false;
42  }
43  // Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause)
45  fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
46  return false;
47  }
48 
49  if (argc<2 || mapArgs.count("-?") || mapArgs.count("--help"))
50  {
51  // First part of help message is specific to RPC client
52  std::string strUsage = _("Anoncoin Core RPC client version") + " " + FormatFullVersion() + "\n\n" +
53  _("Usage:") + "\n" +
54  " anoncoin-cli [options] <command> [params] " + _("Send command to Anoncoin Core") + "\n" +
55  " anoncoin-cli [options] help " + _("List commands") + "\n" +
56  " anoncoin-cli [options] help <command> " + _("Get help for a command") + "\n";
57 
58  strUsage += "\n" + HelpMessageCli(true);
59 
60  fprintf(stdout, "%s", strUsage.c_str());
61  return false;
62  }
63  return true;
64 }
65 
66 int main(int argc, char* argv[])
67 {
69 
70  try
71  {
72  if(!AppInitRPC(argc, argv))
73  return EXIT_FAILURE;
74  }
75  catch (std::exception& e) {
76  PrintExceptionContinue(&e, "AppInitRPC()");
77  return EXIT_FAILURE;
78  } catch (...) {
79  PrintExceptionContinue(NULL, "AppInitRPC()");
80  return EXIT_FAILURE;
81  }
82 
83  int ret = EXIT_FAILURE;
84  try
85  {
86  ret = CommandLineRPC(argc, argv);
87  }
88  catch (std::exception& e) {
89  PrintExceptionContinue(&e, "CommandLineRPC()");
90  } catch (...) {
91  PrintExceptionContinue(NULL, "CommandLineRPC()");
92  }
93  return ret;
94 }
const boost::filesystem::path & GetDataDir(bool fNetSpecific)
Definition: util.cpp:968
std::string HelpMessageCli(bool mainProgram)
Show help message for anoncoin-cli.
Definition: rpcclient.cpp:284
bool SelectParamsFromCommandLine()
Looks for -regtest or -testnet and then calls SelectParams as appropriate.
void PrintExceptionContinue(std::exception *pex, const char *pszThread)
Definition: util.cpp:928
int CommandLineRPC(int argc, char *argv[])
Definition: rpcclient.cpp:218
void ParseParameters(int argc, const char *const argv[])
Definition: util.cpp:460
std::string FormatFullVersion()
void ReadConfigFile(map< string, string > &mapSettingsRet, map< string, vector< string > > &mapMultiSettingsRet)
Definition: util.cpp:1021
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
Definition: ui_interface.h:125
void SetupEnvironment()
Definition: util.cpp:1394
map< string, vector< string > > mapMultiArgs
Definition: util.cpp:90
map< string, string > mapArgs
Definition: util.cpp:89
int main(int argc, char *argv[])