Skip to content

Commit

Permalink
Add separate bitcoin-rpc client
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
laanwj committed Oct 21, 2013
1 parent cc7562b commit 2a03a39
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ src/*.exe
src/*/*.exe
src/bitcoin
src/bitcoind
src/bitcoin-cli
src/test/test_bitcoin
src/qt/test/test_bitcoin-qt

Expand Down
13 changes: 12 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ AM_LDFLAGS = $(PTHREAD_CFLAGS)

noinst_LIBRARIES = libbitcoin.a

bin_PROGRAMS = bitcoind
bin_PROGRAMS = bitcoind bitcoin-cli

SUBDIRS = . $(BUILD_QT) $(BUILD_TEST)
DIST_SUBDIRS = . qt test
Expand Down Expand Up @@ -55,6 +55,17 @@ endif
AM_CPPFLAGS += $(BDB_CPPFLAGS)
bitcoind_LDADD += $(BDB_LIBS)

# bitcoin-cli binary #
bitcoin_cli_LDADD = libbitcoin.a leveldb/libleveldb.a leveldb/libmemenv.a \
$(BOOST_LIBS)
bitcoin_cli_SOURCES = bitcoin-cli.cpp
#

if TARGET_WINDOWS
bitcoin_cli_SOURCES += bitcoin-cli-res.rc
endif
bitcoin_cli_LDADD += $(BDB_LIBS)

leveldb/libleveldb.a: leveldb/libmemenv.a

leveldb/%.a:
Expand Down
36 changes: 36 additions & 0 deletions src/bitcoin-cli-res.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <windows.h> // needed for VERSIONINFO
#include "clientversion.h" // holds the needed client version information

#define VER_PRODUCTVERSION CLIENT_VERSION_MAJOR,CLIENT_VERSION_MINOR,CLIENT_VERSION_REVISION,CLIENT_VERSION_BUILD
#define VER_PRODUCTVERSION_STR STRINGIZE(CLIENT_VERSION_MAJOR) "." STRINGIZE(CLIENT_VERSION_MINOR) "." STRINGIZE(CLIENT_VERSION_REVISION) "." STRINGIZE(CLIENT_VERSION_BUILD)
#define VER_FILEVERSION VER_PRODUCTVERSION
#define VER_FILEVERSION_STR VER_PRODUCTVERSION_STR
#define COPYRIGHT_STR "2009-" STRINGIZE(COPYRIGHT_YEAR) " The Bitcoin developers"

VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
PRODUCTVERSION VER_PRODUCTVERSION
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904E4" // U.S. English - multilingual (hex)
BEGIN
VALUE "CompanyName", "Bitcoin"
VALUE "FileDescription", "Bitcoin-cli (OSS RPC client for Bitcoin)"
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", "bitcoin-cli"
VALUE "LegalCopyright", COPYRIGHT_STR
VALUE "LegalTrademarks1", "Distributed under the MIT/X11 software license, see the accompanying file COPYING or http://www.opensource.org/licenses/mit-license.php."
VALUE "OriginalFilename", "bitcoin-cli.exe"
VALUE "ProductName", "Bitcoin-cli"
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
END
END

BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0, 1252 // language neutral - multilingual (decimal)
END
END
69 changes: 69 additions & 0 deletions src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 4 additions & 3 deletions src/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ bool AppInit(int argc, char* argv[])
// First part of help message is specific to bitcoind / RPC client
std::string strUsage = _("Bitcoin version") + " " + FormatFullVersion() + "\n\n" +
_("Usage:") + "\n" +
" bitcoind [options] " + "\n" +
" bitcoind [options] <command> [params] " + _("Send command to -server or bitcoind") + "\n" +
" bitcoind [options] " + _("Start Bitcoin server") + "\n" +
_("Usage (deprecated, use bitcoin-cli):") + "\n" +
" bitcoind [options] <command> [params] " + _("Send command to Bitcoin server") + "\n" +
" bitcoind [options] help " + _("List commands") + "\n" +
" bitcoind [options] help <command> " + _("Get help for a command") + "\n";

strUsage += "\n" + HelpMessage();
strUsage += "\n" + HelpMessage(HMM_BITCOIND);

fprintf(stdout, "%s", strUsage.c_str());
return false;
Expand Down
Loading

0 comments on commit 2a03a39

Please sign in to comment.