diff --git a/.gitignore b/.gitignore index ba6842aca..da0437835 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/src/Makefile.am b/src/Makefile.am index 49249fedc..14d1dd03a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 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: diff --git a/src/bitcoin-cli-res.rc b/src/bitcoin-cli-res.rc new file mode 100644 index 000000000..337897753 --- /dev/null +++ b/src/bitcoin-cli-res.rc @@ -0,0 +1,36 @@ +#include // 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 diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp new file mode 100644 index 000000000..bb30c748b --- /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] [params] " + _("Send command to Bitcoin server") + "\n" + + " bitcoin-cli [options] help " + _("List commands") + "\n" + + " bitcoin-cli [options] help " + _("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; +} diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 1b40a868a..fbacbd2e2 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -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] [params] " + _("Send command to -server or bitcoind") + "\n" + + " bitcoind [options] " + _("Start Bitcoin server") + "\n" + + _("Usage (deprecated, use bitcoin-cli):") + "\n" + + " bitcoind [options] [params] " + _("Send command to Bitcoin server") + "\n" + " bitcoind [options] help " + _("List commands") + "\n" + " bitcoind [options] help " + _("Get help for a command") + "\n"; - strUsage += "\n" + HelpMessage(); + strUsage += "\n" + HelpMessage(HMM_BITCOIND); fprintf(stdout, "%s", strUsage.c_str()); return false; diff --git a/src/init.cpp b/src/init.cpp index daa12d899..6493679d2 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -171,94 +171,121 @@ 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= " + _("Specify configuration file (default: bitcoin.conf)") + "\n"; - strUsage += " -pid= " + _("Specify pid file (default: bitcoind.pid)") + "\n"; - strUsage += " -gen " + _("Generate coins (default: 0)") + "\n"; strUsage += " -datadir= " + _("Specify data directory") + "\n"; - strUsage += " -wallet= " + _("Specify wallet file (within data directory)") + "\n"; - strUsage += " -dbcache= " + _("Set database cache size in megabytes (default: 25)") + "\n"; - strUsage += " -timeout= " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n"; - strUsage += " -proxy= " + _("Connect through socks proxy") + "\n"; - strUsage += " -socks= " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n"; - strUsage += " -onion= " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\n"; - strUsage += " -dns " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n"; - strUsage += " -port= " + _("Listen for connections on (default: 8333 or testnet: 18333)") + "\n"; - strUsage += " -maxconnections= " + _("Maintain at most connections to peers (default: 125)") + "\n"; - strUsage += " -addnode= " + _("Add a node to connect to and attempt to keep the connection open") + "\n"; - strUsage += " -connect= " + _("Connect only to the specified node(s)") + "\n"; - strUsage += " -seednode= " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n"; - strUsage += " -externalip= " + _("Specify your own public address") + "\n"; - strUsage += " -onlynet= " + _("Only connect to nodes in network (IPv4, IPv6 or Tor)") + "\n"; - strUsage += " -discover " + _("Discover own IP address (default: 1 when listening and no -externalip)") + "\n"; - strUsage += " -checkpoints " + _("Only accept block chain matching built-in checkpoints (default: 1)") + "\n"; - strUsage += " -listen " + _("Accept connections from outside (default: 1 if no -proxy or -connect)") + "\n"; - strUsage += " -bind= " + _("Bind to given address and always listen on it. Use [host]:port notation for IPv6") + "\n"; - strUsage += " -dnsseed " + _("Find peers using DNS lookup (default: 1 unless -connect)") + "\n"; - strUsage += " -banscore= " + _("Threshold for disconnecting misbehaving peers (default: 100)") + "\n"; - strUsage += " -bantime= " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n"; - strUsage += " -maxreceivebuffer= " + _("Maximum per-connection receive buffer, *1000 bytes (default: 5000)") + "\n"; - strUsage += " -maxsendbuffer= " + _("Maximum per-connection send buffer, *1000 bytes (default: 1000)") + "\n"; + strUsage += " -testnet " + _("Use the test network") + "\n"; + + if(hmm == HMM_BITCOIND || hmm == HMM_BITCOIN_QT) + { + strUsage += " -pid= " + _("Specify pid file (default: bitcoind.pid)") + "\n"; + strUsage += " -gen " + _("Generate coins (default: 0)") + "\n"; + strUsage += " -wallet= " + _("Specify wallet file (within data directory)") + "\n"; + strUsage += " -dbcache= " + _("Set database cache size in megabytes (default: 25)") + "\n"; + strUsage += " -timeout= " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n"; + strUsage += " -proxy= " + _("Connect through socks proxy") + "\n"; + strUsage += " -socks= " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n"; + strUsage += " -onion= " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\n"; + strUsage += " -dns " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n"; + strUsage += " -port= " + _("Listen for connections on (default: 8333 or testnet: 18333)") + "\n"; + strUsage += " -maxconnections= " + _("Maintain at most connections to peers (default: 125)") + "\n"; + strUsage += " -addnode= " + _("Add a node to connect to and attempt to keep the connection open") + "\n"; + strUsage += " -connect= " + _("Connect only to the specified node(s)") + "\n"; + strUsage += " -seednode= " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n"; + strUsage += " -externalip= " + _("Specify your own public address") + "\n"; + strUsage += " -onlynet= " + _("Only connect to nodes in network (IPv4, IPv6 or Tor)") + "\n"; + strUsage += " -discover " + _("Discover own IP address (default: 1 when listening and no -externalip)") + "\n"; + strUsage += " -checkpoints " + _("Only accept block chain matching built-in checkpoints (default: 1)") + "\n"; + strUsage += " -listen " + _("Accept connections from outside (default: 1 if no -proxy or -connect)") + "\n"; + strUsage += " -bind= " + _("Bind to given address and always listen on it. Use [host]:port notation for IPv6") + "\n"; + strUsage += " -dnsseed " + _("Find peers using DNS lookup (default: 1 unless -connect)") + "\n"; + strUsage += " -banscore= " + _("Threshold for disconnecting misbehaving peers (default: 100)") + "\n"; + strUsage += " -bantime= " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n"; + strUsage += " -maxreceivebuffer= " + _("Maximum per-connection receive buffer, *1000 bytes (default: 5000)") + "\n"; + strUsage += " -maxsendbuffer= " + _("Maximum per-connection send buffer, *1000 bytes (default: 1000)") + "\n"; #ifdef USE_UPNP #if USE_UPNP - strUsage += " -upnp " + _("Use UPnP to map the listening port (default: 1 when listening)") + "\n"; + strUsage += " -upnp " + _("Use UPnP to map the listening port (default: 1 when listening)") + "\n"; #else - strUsage += " -upnp " + _("Use UPnP to map the listening port (default: 0)") + "\n"; + strUsage += " -upnp " + _("Use UPnP to map the listening port (default: 0)") + "\n"; #endif #endif - strUsage += " -paytxfee= " + _("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"; - strUsage += " -shrinkdebugfile " + _("Shrink debug.log file on client startup (default: 1 when no -debug)") + "\n"; - strUsage += " -printtoconsole " + _("Send trace/debug info to console instead of debug.log file") + "\n"; - strUsage += " -regtest " + _("Enter regression test mode, which uses a special chain in which blocks can be " + strUsage += " -paytxfee= " + _("Fee per KB to add to transactions you send") + "\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"; + strUsage += " -shrinkdebugfile " + _("Shrink debug.log file on client startup (default: 1 when no -debug)") + "\n"; + strUsage += " -printtoconsole " + _("Send trace/debug info to console instead of debug.log file") + "\n"; + strUsage += " -regtest " + _("Enter regression test mode, which uses a special chain in which blocks can be " "solved instantly. This is intended for regression testing tools and app development.") + "\n"; #ifdef WIN32 - strUsage += " -printtodebugger " + _("Send trace/debug info to debugger") + "\n"; + 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= " + _("Send commands to node running on (default: 127.0.0.1)") + "\n"; + } + strUsage += " -rpcuser= " + _("Username for JSON-RPC connections") + "\n"; strUsage += " -rpcpassword= " + _("Password for JSON-RPC connections") + "\n"; - strUsage += " -rpcport= " + _("Listen for JSON-RPC connections on (default: 8332 or testnet: 18332)") + "\n"; - strUsage += " -rpcallowip= " + _("Allow JSON-RPC connections from specified IP address") + "\n"; - if (!fHaveGUI) - strUsage += " -rpcconnect= " + _("Send commands to node running on (default: 127.0.0.1)") + "\n"; - strUsage += " -rpcthreads= " + _("Set the number of threads to service RPC calls (default: 4)") + "\n"; - strUsage += " -blocknotify= " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n"; - strUsage += " -walletnotify= " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n"; - strUsage += " -alertnotify= " + _("Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)") + "\n"; - strUsage += " -upgradewallet " + _("Upgrade wallet to latest format") + "\n"; - strUsage += " -keypool= " + _("Set key pool size to (default: 100)") + "\n"; - strUsage += " -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n"; - strUsage += " -salvagewallet " + _("Attempt to recover private keys from a corrupt wallet.dat") + "\n"; - strUsage += " -checkblocks= " + _("How many blocks to check at startup (default: 288, 0 = all)") + "\n"; - strUsage += " -checklevel= " + _("How thorough the block verification is (0-4, default: 3)") + "\n"; - strUsage += " -txindex " + _("Maintain a full transaction index (default: 0)") + "\n"; - strUsage += " -loadblock= " + _("Imports blocks from external blk000??.dat file") + "\n"; - strUsage += " -reindex " + _("Rebuild block chain index from current blk000??.dat files") + "\n"; - strUsage += " -par= " + _("Set the number of script verification threads (up to 16, 0 = auto, <0 = leave that many cores free, default: 0)") + "\n"; + if (hmm == HMM_BITCOIND || hmm == HMM_BITCOIN_QT) + { + strUsage += " -rpcport= " + _("Listen for JSON-RPC connections on (default: 8332 or testnet: 18332)") + "\n"; + } else { + strUsage += " -rpcport= " + _("Connect to JSON-RPC on (default: 8332 or testnet: 18332)") + "\n"; + } - strUsage += "\n" + _("Block creation options:") + "\n"; - strUsage += " -blockminsize= " + _("Set minimum block size in bytes (default: 0)") + "\n"; - strUsage += " -blockmaxsize= " + _("Set maximum block size in bytes (default: 250000)") + "\n"; - strUsage += " -blockprioritysize= " + _("Set maximum size of high-priority/low-fee transactions in bytes (default: 27000)") + "\n"; + if(hmm == HMM_BITCOIND || hmm == HMM_BITCOIN_QT) + { + strUsage += " -rpcallowip= " + _("Allow JSON-RPC connections from specified IP address") + "\n"; + strUsage += " -rpcthreads= " + _("Set the number of threads to service RPC calls (default: 4)") + "\n"; + strUsage += " -blocknotify= " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n"; + strUsage += " -walletnotify= " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n"; + strUsage += " -alertnotify= " + _("Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)") + "\n"; + strUsage += " -upgradewallet " + _("Upgrade wallet to latest format") + "\n"; + strUsage += " -keypool= " + _("Set key pool size to (default: 100)") + "\n"; + strUsage += " -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n"; + strUsage += " -salvagewallet " + _("Attempt to recover private keys from a corrupt wallet.dat") + "\n"; + strUsage += " -checkblocks= " + _("How many blocks to check at startup (default: 288, 0 = all)") + "\n"; + strUsage += " -checklevel= " + _("How thorough the block verification is (0-4, default: 3)") + "\n"; + strUsage += " -txindex " + _("Maintain a full transaction index (default: 0)") + "\n"; + strUsage += " -loadblock= " + _("Imports blocks from external blk000??.dat file") + "\n"; + strUsage += " -reindex " + _("Rebuild block chain index from current blk000??.dat files") + "\n"; + strUsage += " -par= " + _("Set the number of script verification threads (up to 16, 0 = auto, <0 = leave that many cores free, default: 0)") + "\n"; + + strUsage += "\n" + _("Block creation options:") + "\n"; + strUsage += " -blockminsize= " + _("Set minimum block size in bytes (default: 0)") + "\n"; + strUsage += " -blockmaxsize= " + _("Set maximum block size in bytes (default: 250000)") + "\n"; + strUsage += " -blockprioritysize= " + _("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"; - strUsage += " -rpcsslcertificatechainfile= " + _("Server certificate file (default: server.cert)") + "\n"; - strUsage += " -rpcsslprivatekeyfile= " + _("Server private key (default: server.pem)") + "\n"; - strUsage += " -rpcsslciphers= " + _("Acceptable ciphers (default: TLSv1.2+HIGH:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!3DES:@STRENGTH)") + "\n"; + if (hmm == HMM_BITCOIND || hmm == HMM_BITCOIN_QT) + { + strUsage += " -rpcsslcertificatechainfile= " + _("Server certificate file (default: server.cert)") + "\n"; + strUsage += " -rpcsslprivatekeyfile= " + _("Server private key (default: server.pem)") + "\n"; + strUsage += " -rpcsslciphers= " + _("Acceptable ciphers (default: TLSv1.2+HIGH:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!3DES:@STRENGTH)") + "\n"; + strUsage += " -rpcsslciphers= " + _("Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)") + "\n"; + } return strUsage; } diff --git a/src/init.h b/src/init.h index e5a2a6929..785a6cdba 100644 --- a/src/init.h +++ b/src/init.h @@ -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 diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index c951b21b8..b65348548 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -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= " + tr("Set language, for example \"de_DE\" (default: system locale)") + "\n" +