Browse Source

Merge pull request #3082 from laanwj/2013_10_rpccli3

Add separate bitcoin-rpc client
0.10
Wladimir J. van der Laan 11 years ago
parent
commit
b3dd90c122
  1. 1
      .gitignore
  2. 13
      src/Makefile.am
  3. 36
      src/bitcoin-cli-res.rc
  4. 69
      src/bitcoin-cli.cpp
  5. 7
      src/bitcoind.cpp
  6. 51
      src/init.cpp
  7. 11
      src/init.h
  8. 2
      src/qt/guiutil.cpp

1
.gitignore vendored

@ -5,6 +5,7 @@ src/*.exe @@ -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

13
src/Makefile.am

@ -6,7 +6,7 @@ AM_LDFLAGS = $(PTHREAD_CFLAGS) @@ -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
@ -55,6 +55,17 @@ endif @@ -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:

36
src/bitcoin-cli-res.rc

@ -0,0 +1,36 @@ @@ -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
src/bitcoin-cli.cpp

@ -0,0 +1,69 @@ @@ -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
src/bitcoind.cpp

@ -57,12 +57,13 @@ bool AppInit(int argc, char* argv[]) @@ -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;

51
src/init.cpp

@ -171,15 +171,19 @@ bool static Bind(const CService &addr, unsigned int flags) { @@ -171,15 +171,19 @@ bool static Bind(const CService &addr, unsigned int flags) {
return true;
}
// Core-specific options shared between UI and daemon
std::string HelpMessage()
// Core-specific options shared between UI, daemon and RPC client
std::string HelpMessage(HelpMessageMode hmm)
{
string strUsage = _("Options:") + "\n";
strUsage += " -? " + _("This help message") + "\n";
strUsage += " -conf=<file> " + _("Specify configuration file (default: bitcoin.conf)") + "\n";
strUsage += " -datadir=<dir> " + _("Specify data directory") + "\n";
strUsage += " -testnet " + _("Use the test network") + "\n";
if(hmm == HMM_BITCOIND || hmm == HMM_BITCOIN_QT)
{
strUsage += " -pid=<file> " + _("Specify pid file (default: bitcoind.pid)") + "\n";
strUsage += " -gen " + _("Generate coins (default: 0)") + "\n";
strUsage += " -datadir=<dir> " + _("Specify data directory") + "\n";
strUsage += " -wallet=<file> " + _("Specify wallet file (within data directory)") + "\n";
strUsage += " -dbcache=<n> " + _("Set database cache size in megabytes (default: 25)") + "\n";
strUsage += " -timeout=<n> " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n";
@ -211,13 +215,6 @@ std::string HelpMessage() @@ -211,13 +215,6 @@ std::string HelpMessage()
#endif
#endif
strUsage += " -paytxfee=<amt> " + _("Fee per KB to add to transactions you send") + "\n";
if (fHaveGUI)
strUsage += " -server " + _("Accept command line and JSON-RPC commands") + "\n";
#if !defined(WIN32)
if (fHaveGUI)
strUsage += " -daemon " + _("Run in the background as a daemon and accept commands") + "\n";
#endif
strUsage += " -testnet " + _("Use the test network") + "\n";
strUsage += " -debug " + _("Output extra debugging information. Implies all other -debug* options") + "\n";
strUsage += " -debugnet " + _("Output extra network debugging information") + "\n";
strUsage += " -logtimestamps " + _("Prepend debug output with timestamp") + "\n";
@ -228,12 +225,37 @@ std::string HelpMessage() @@ -228,12 +225,37 @@ std::string HelpMessage()
#ifdef WIN32
strUsage += " -printtodebugger " + _("Send trace/debug info to debugger") + "\n";
#endif
}
if (hmm == HMM_BITCOIN_QT)
{
strUsage += " -server " + _("Accept command line and JSON-RPC commands") + "\n";
}
if (hmm == HMM_BITCOIND)
{
#if !defined(WIN32)
strUsage += " -daemon " + _("Run in the background as a daemon and accept commands") + "\n";
#endif
}
if (hmm == HMM_BITCOIND || hmm == HMM_BITCOIN_CLI)
{
strUsage += " -rpcconnect=<ip> " + _("Send commands to node running on <ip> (default: 127.0.0.1)") + "\n";
}
strUsage += " -rpcuser=<user> " + _("Username for JSON-RPC connections") + "\n";
strUsage += " -rpcpassword=<pw> " + _("Password for JSON-RPC connections") + "\n";
if (hmm == HMM_BITCOIND || hmm == HMM_BITCOIN_QT)
{
strUsage += " -rpcport=<port> " + _("Listen for JSON-RPC connections on <port> (default: 8332 or testnet: 18332)") + "\n";
} else {
strUsage += " -rpcport=<port> " + _("Connect to JSON-RPC on <port> (default: 8332 or testnet: 18332)") + "\n";
}
if(hmm == HMM_BITCOIND || hmm == HMM_BITCOIN_QT)
{
strUsage += " -rpcallowip=<ip> " + _("Allow JSON-RPC connections from specified IP address") + "\n";
if (!fHaveGUI)
strUsage += " -rpcconnect=<ip> " + _("Send commands to node running on <ip> (default: 127.0.0.1)") + "\n";
strUsage += " -rpcthreads=<n> " + _("Set the number of threads to service RPC calls (default: 4)") + "\n";
strUsage += " -blocknotify=<cmd> " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n";
strUsage += " -walletnotify=<cmd> " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n";
@ -253,12 +275,17 @@ std::string HelpMessage() @@ -253,12 +275,17 @@ std::string HelpMessage()
strUsage += " -blockminsize=<n> " + _("Set minimum block size in bytes (default: 0)") + "\n";
strUsage += " -blockmaxsize=<n> " + _("Set maximum block size in bytes (default: 250000)") + "\n";
strUsage += " -blockprioritysize=<n> " + _("Set maximum size of high-priority/low-fee transactions in bytes (default: 27000)") + "\n";
}
strUsage += "\n" + _("SSL options: (see the Bitcoin Wiki for SSL setup instructions)") + "\n";
strUsage += " -rpcssl " + _("Use OpenSSL (https) for JSON-RPC connections") + "\n";
if (hmm == HMM_BITCOIND || hmm == HMM_BITCOIN_QT)
{
strUsage += " -rpcsslcertificatechainfile=<file.cert> " + _("Server certificate file (default: server.cert)") + "\n";
strUsage += " -rpcsslprivatekeyfile=<file.pem> " + _("Server private key (default: server.pem)") + "\n";
strUsage += " -rpcsslciphers=<ciphers> " + _("Acceptable ciphers (default: TLSv1.2+HIGH:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!3DES:@STRENGTH)") + "\n";
strUsage += " -rpcsslciphers=<ciphers> " + _("Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)") + "\n";
}
return strUsage;
}

11
src/init.h

@ -14,6 +14,15 @@ void StartShutdown(); @@ -14,6 +14,15 @@ void StartShutdown();
bool ShutdownRequested();
void Shutdown();
bool AppInit2(boost::thread_group& threadGroup);
std::string HelpMessage();
/* The help message mode determines what help message to show */
enum HelpMessageMode
{
HMM_BITCOIND,
HMM_BITCOIN_QT,
HMM_BITCOIN_CLI
};
std::string HelpMessage(HelpMessageMode mode);
#endif

2
src/qt/guiutil.cpp

@ -527,7 +527,7 @@ HelpMessageBox::HelpMessageBox(QWidget *parent) : @@ -527,7 +527,7 @@ HelpMessageBox::HelpMessageBox(QWidget *parent) :
tr("Usage:") + "\n" +
" bitcoin-qt [" + tr("command-line options") + "] " + "\n";
coreOptions = QString::fromStdString(HelpMessage());
coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT));
uiOptions = tr("UI options") + ":\n" +
" -lang=<lang> " + tr("Set language, for example \"de_DE\" (default: system locale)") + "\n" +

Loading…
Cancel
Save