Master Core  v0.0.9 - 49a5c0d97abf09ef2911ddfe8d9551df59f9efd3-dirty
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
bitcoin-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 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "util.h"
7 #include "init.h"
8 #include "rpcclient.h"
9 #include "rpcprotocol.h"
10 #include "ui_interface.h" /* for _(...) */
11 #include "chainparams.h"
12 
13 #include <boost/filesystem/operations.hpp>
14 
16 //
17 // Start
18 //
19 static bool AppInitRPC(int argc, char* argv[])
20 {
21  //
22  // Parameters
23  //
24  ParseParameters(argc, argv);
25  if (!boost::filesystem::is_directory(GetDataDir(false)))
26  {
27  fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
28  return false;
29  }
30  try {
32  } catch(std::exception &e) {
33  fprintf(stderr,"Error reading configuration file: %s\n", e.what());
34  return false;
35  }
36  // Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause)
38  fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
39  return false;
40  }
41 
42  if (argc<2 || mapArgs.count("-?") || mapArgs.count("--help"))
43  {
44  // First part of help message is specific to RPC client
45  std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n\n" +
46  _("Usage:") + "\n" +
47  " bitcoin-cli [options] <command> [params] " + _("Send command to Bitcoin Core") + "\n" +
48  " bitcoin-cli [options] help " + _("List commands") + "\n" +
49  " bitcoin-cli [options] help <command> " + _("Get help for a command") + "\n";
50 
51  strUsage += "\n" + HelpMessageCli(true);
52 
53  fprintf(stdout, "%s", strUsage.c_str());
54  return false;
55  }
56  return true;
57 }
58 
59 int main(int argc, char* argv[])
60 {
62 
63  try
64  {
65  if(!AppInitRPC(argc, argv))
66  return abs(RPC_MISC_ERROR);
67  }
68  catch (std::exception& e) {
69  PrintExceptionContinue(&e, "AppInitRPC()");
70  return abs(RPC_MISC_ERROR);
71  } catch (...) {
72  PrintExceptionContinue(NULL, "AppInitRPC()");
73  return abs(RPC_MISC_ERROR);
74  }
75 
76  int ret = abs(RPC_MISC_ERROR);
77  try
78  {
79  ret = CommandLineRPC(argc, argv);
80  }
81  catch (std::exception& e) {
82  PrintExceptionContinue(&e, "CommandLineRPC()");
83  } catch (...) {
84  PrintExceptionContinue(NULL, "CommandLineRPC()");
85  }
86  return ret;
87 }
const boost::filesystem::path & GetDataDir(bool fNetSpecific)
Definition: util.cpp:973
std::string HelpMessageCli(bool mainProgram)
Show help message for bitcoin-cli.
Definition: rpcclient.cpp:276
static bool AppInitRPC(int argc, char *argv[])
Definition: bitcoin-cli.cpp:19
bool SelectParamsFromCommandLine()
Looks for -regtest or -testnet and then calls SelectParams as appropriate.
void PrintExceptionContinue(std::exception *pex, const char *pszThread)
Definition: util.cpp:933
int main(int argc, char *argv[])
Definition: bitcoin-cli.cpp:59
int CommandLineRPC(int argc, char *argv[])
Definition: rpcclient.cpp:210
void ParseParameters(int argc, const char *const argv[])
Definition: util.cpp:460
void ReadConfigFile(map< string, string > &mapSettingsRet, map< string, vector< string > > &mapMultiSettingsRet)
Definition: util.cpp:1019
string FormatFullVersion()
Definition: util.cpp:1325
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
Definition: ui_interface.h:105
void SetupEnvironment()
Definition: util.cpp:1412
map< string, vector< string > > mapMultiArgs
Definition: util.cpp:90
map< string, string > mapArgs
Definition: util.cpp:89