aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoin-cli.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2013-10-11 23:09:59 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2013-10-21 09:22:48 +0200
commit2a03a39020da5ae38f05c38a5bf92c023acdeb90 (patch)
tree0428ba46a5f377dadddf0c570b908043f1fcbeb5 /src/bitcoin-cli.cpp
parentcc7562b7d2dc4eae6e3ab930a2a37cd3c00aac5d (diff)
Add separate bitcoin-rpc client
This adds an executable `bitcoin-rpc` that only serves as a Bitcoin RPC client. The commit does not remove RPC functionality from the `bitcoind` yet, this functionality should be deprecated but is left for a later version to give users some time to switch.
Diffstat (limited to 'src/bitcoin-cli.cpp')
-rw-r--r--src/bitcoin-cli.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
new file mode 100644
index 0000000000..bb30c748bb
--- /dev/null
+++ b/src/bitcoin-cli.cpp
@@ -0,0 +1,69 @@
+// Copyright (c) 2009-2010 Satoshi Nakamoto
+// Copyright (c) 2009-2013 The Bitcoin developers
+// Distributed under the MIT/X11 software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include "util.h"
+#include "init.h"
+#include "bitcoinrpc.h"
+#include "ui_interface.h" /* for _(...) */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// Start
+//
+static bool AppInitRPC(int argc, char* argv[])
+{
+ //
+ // Parameters
+ //
+ ParseParameters(argc, argv);
+ if (!boost::filesystem::is_directory(GetDataDir(false)))
+ {
+ fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
+ return false;
+ }
+ ReadConfigFile(mapArgs, mapMultiArgs);
+
+ if (argc<2 || mapArgs.count("-?") || mapArgs.count("--help"))
+ {
+ // First part of help message is specific to RPC client
+ std::string strUsage = _("Bitcoin RPC client version") + " " + FormatFullVersion() + "\n\n" +
+ _("Usage:") + "\n" +
+ " bitcoin-cli [options] <command> [params] " + _("Send command to Bitcoin server") + "\n" +
+ " bitcoin-cli [options] help " + _("List commands") + "\n" +
+ " bitcoin-cli [options] help <command> " + _("Get help for a command") + "\n";
+
+ strUsage += "\n" + HelpMessage(HMM_BITCOIN_CLI);
+
+ fprintf(stdout, "%s", strUsage.c_str());
+ return false;
+ }
+ return true;
+}
+
+int main(int argc, char* argv[])
+{
+ try
+ {
+ if(!AppInitRPC(argc, argv))
+ return 1;
+ }
+ catch (std::exception& e) {
+ PrintExceptionContinue(&e, "AppInitRPC()");
+ } catch (...) {
+ PrintExceptionContinue(NULL, "AppInitRPC()");
+ }
+
+ try
+ {
+ if(!CommandLineRPC(argc, argv))
+ return 1;
+ }
+ catch (std::exception& e) {
+ PrintExceptionContinue(&e, "CommandLineRPC()");
+ } catch (...) {
+ PrintExceptionContinue(NULL, "CommandLineRPC()");
+ }
+ return 0;
+}