You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bitcoin-cli.cpp 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include "util.h"
  6. #include "init.h"
  7. #include "bitcoinrpc.h"
  8. #include "ui_interface.h" /* for _(...) */
  9. #include <boost/filesystem/operations.hpp>
  10. //////////////////////////////////////////////////////////////////////////////
  11. //
  12. // Start
  13. //
  14. static bool AppInitRPC(int argc, char* argv[])
  15. {
  16. //
  17. // Parameters
  18. //
  19. ParseParameters(argc, argv);
  20. if (!boost::filesystem::is_directory(GetDataDir(false)))
  21. {
  22. fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
  23. return false;
  24. }
  25. ReadConfigFile(mapArgs, mapMultiArgs);
  26. if (argc<2 || mapArgs.count("-?") || mapArgs.count("--help"))
  27. {
  28. // First part of help message is specific to RPC client
  29. std::string strUsage = _("Bitcoin RPC client version") + " " + FormatFullVersion() + "\n\n" +
  30. _("Usage:") + "\n" +
  31. " bitcoin-cli [options] <command> [params] " + _("Send command to Bitcoin server") + "\n" +
  32. " bitcoin-cli [options] help " + _("List commands") + "\n" +
  33. " bitcoin-cli [options] help <command> " + _("Get help for a command") + "\n";
  34. strUsage += "\n" + HelpMessage(HMM_BITCOIN_CLI);
  35. fprintf(stdout, "%s", strUsage.c_str());
  36. return false;
  37. }
  38. return true;
  39. }
  40. int main(int argc, char* argv[])
  41. {
  42. try
  43. {
  44. if(!AppInitRPC(argc, argv))
  45. return 1;
  46. }
  47. catch (std::exception& e) {
  48. PrintExceptionContinue(&e, "AppInitRPC()");
  49. } catch (...) {
  50. PrintExceptionContinue(NULL, "AppInitRPC()");
  51. }
  52. try
  53. {
  54. if(!CommandLineRPC(argc, argv))
  55. return 1;
  56. }
  57. catch (std::exception& e) {
  58. PrintExceptionContinue(&e, "CommandLineRPC()");
  59. } catch (...) {
  60. PrintExceptionContinue(NULL, "CommandLineRPC()");
  61. }
  62. return 0;
  63. }