diff options
-rw-r--r-- | bitcoin-qt.pro | 3 | ||||
-rw-r--r-- | doc/release-notes.txt | 1 | ||||
-rw-r--r-- | src/db.cpp | 5 | ||||
-rw-r--r-- | src/init.cpp | 2 | ||||
-rw-r--r-- | src/irc.cpp | 21 | ||||
-rw-r--r-- | src/main.h | 2 | ||||
-rw-r--r-- | src/makefile.linux-mingw | 5 | ||||
-rw-r--r-- | src/makefile.mingw | 5 | ||||
-rw-r--r-- | src/qt/rpcconsole.cpp | 126 | ||||
-rw-r--r-- | src/rpcmining.cpp | 4 | ||||
-rw-r--r-- | src/rpcwallet.cpp | 3 | ||||
-rw-r--r-- | src/wallet.cpp | 8 | ||||
-rw-r--r-- | src/wallet.h | 7 |
13 files changed, 148 insertions, 44 deletions
diff --git a/bitcoin-qt.pro b/bitcoin-qt.pro index bf0c87e7e3..7c122dee34 100644 --- a/bitcoin-qt.pro +++ b/bitcoin-qt.pro @@ -176,7 +176,8 @@ HEADERS += src/qt/bitcoingui.h \ src/allocators.h \ src/ui_interface.h \ src/qt/rpcconsole.h \ - src/version.h + src/version.h \ + src/netbase.h SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \ src/qt/transactiontablemodel.cpp \ diff --git a/doc/release-notes.txt b/doc/release-notes.txt index 5374847b51..babc56ff81 100644 --- a/doc/release-notes.txt +++ b/doc/release-notes.txt @@ -43,6 +43,7 @@ JSON-RPC API * Rework gettransaction, getblock calls. 'gettransaction' responds for non-wallet TXs now. * Remove deprecated RPC 'getblocknumber' +* Remove superceded RPC 'getmemorypool' (see BIP 22, above) * New blockchain checkpoint at block 193,000 * listtransactions output now displays "smart" times for transactions, and 'blocktime' and 'timereceived' fields were added diff --git a/src/db.cpp b/src/db.cpp index 5671993d37..015e7ec2de 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -195,10 +195,7 @@ CDB::CDB(const char *pszFile, const char* pszMode) : { delete pdb; pdb = NULL; - { - LOCK(bitdb.cs_db); - --bitdb.mapFileUseCount[strFile]; - } + --bitdb.mapFileUseCount[strFile]; strFile = ""; throw runtime_error(strprintf("CDB() : can't open database file %s, error %d", pszFile, ret)); } diff --git a/src/init.cpp b/src/init.cpp index f578df6bf4..0a28312af5 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -225,7 +225,7 @@ std::string HelpMessage() " -datadir=<dir> " + _("Specify data directory") + "\n" + " -dbcache=<n> " + _("Set database cache size in megabytes (default: 25)") + "\n" + " -dblogsize=<n> " + _("Set database disk log size in megabytes (default: 100)") + "\n" + - " -timeout=<n> " + _("Specify connection timeout (in milliseconds)") + "\n" + + " -timeout=<n> " + _("Specify connection timeout in milliseconds (default: 5000))") + "\n" + " -proxy=<ip:port> " + _("Connect through socks proxy") + "\n" + " -socks=<n> " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n" + " -tor=<ip:port> " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\n" diff --git a/src/irc.cpp b/src/irc.cpp index 50c6a5b4db..6991e6ee7e 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -207,16 +207,22 @@ void ThreadIRCSeed(void* parg) void ThreadIRCSeed2(void* parg) { - /* Don't advertise on IRC if we don't allow incoming connections */ - if (mapArgs.count("-connect") || fNoListen) + // Don't connect to IRC if we won't use IPv4 connections. + if (IsLimited(NET_IPV4)) return; + // ... or if we won't make outbound connections and won't accept inbound ones. + if (mapArgs.count("-connect") && fNoListen) + return; + + // ... or if IRC is not enabled. if (!GetBoolArg("-irc", false)) return; printf("ThreadIRCSeed started\n"); int nErrorWait = 10; int nRetryWait = 10; + int nNameRetry = 0; while (!fShutdown) { @@ -251,7 +257,9 @@ void ThreadIRCSeed2(void* parg) CNetAddr addrIPv4("1.2.3.4"); // arbitrary IPv4 address to make GetLocal prefer IPv4 addresses CService addrLocal; string strMyName; - if (GetLocal(addrLocal, &addrIPv4)) + // Don't use our IP as our nick if we're not listening + // or if it keeps failing because the nick is already in use. + if (!fNoListen && GetLocal(addrLocal, &addrIPv4) && nNameRetry<3) strMyName = EncodeAddress(GetLocalAddress(&addrConnect)); if (strMyName == "") strMyName = strprintf("x%u", GetRand(1000000000)); @@ -267,6 +275,7 @@ void ThreadIRCSeed2(void* parg) if (nRet == 2) { printf("IRC name already in use\n"); + nNameRetry++; Wait(10); continue; } @@ -276,6 +285,7 @@ void ThreadIRCSeed2(void* parg) else return; } + nNameRetry = 0; Sleep(500); // Get our external IP from the IRC server and re-nick before joining the channel @@ -283,7 +293,8 @@ void ThreadIRCSeed2(void* parg) if (GetIPFromIRC(hSocket, strMyName, addrFromIRC)) { printf("GetIPFromIRC() returned %s\n", addrFromIRC.ToString().c_str()); - if (addrFromIRC.IsRoutable()) + // Don't use our IP as our nick if we're not listening + if (!fNoListen && addrFromIRC.IsRoutable()) { // IRC lets you to re-nick AddLocal(addrFromIRC, LOCAL_IRC); @@ -291,7 +302,7 @@ void ThreadIRCSeed2(void* parg) Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str()); } } - + if (fTestNet) { Send(hSocket, "JOIN #bitcoinTEST3\r"); Send(hSocket, "WHO #bitcoinTEST3\r"); diff --git a/src/main.h b/src/main.h index dc9f9ee74a..b8057a295e 100644 --- a/src/main.h +++ b/src/main.h @@ -1174,7 +1174,7 @@ public: std::string ToString() const { - return strprintf("CBlockIndex(nprev=%08x, pnext=%08x, nFile=%d, nBlockPos=%-6d nHeight=%d, merkle=%s, hashBlock=%s)", + return strprintf("CBlockIndex(pprev=%08x, pnext=%08x, nFile=%d, nBlockPos=%-6d nHeight=%d, merkle=%s, hashBlock=%s)", pprev, pnext, nFile, nBlockPos, nHeight, hashMerkleRoot.ToString().substr(0,10).c_str(), GetBlockHash().ToString().substr(0,20).c_str()); diff --git a/src/makefile.linux-mingw b/src/makefile.linux-mingw index 625ed67847..828ddfe588 100644 --- a/src/makefile.linux-mingw +++ b/src/makefile.linux-mingw @@ -33,6 +33,7 @@ LIBS= \ DEFS=-D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB -DBOOST_SPIRIT_THREADSAFE DEBUGFLAGS=-g CFLAGS=-O2 -w -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS) +LDFLAGS=-Wl,--dynamicbase -Wl,--nxcompat TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data) @@ -93,7 +94,7 @@ obj/%.o: %.cpp $(HEADERS) i586-mingw32msvc-g++ -c $(CFLAGS) -o $@ $< bitcoind.exe: $(OBJS:obj/%=obj/%) - i586-mingw32msvc-g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) + i586-mingw32msvc-g++ $(CFLAGS) $(LDFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp)) @@ -101,7 +102,7 @@ obj-test/%.o: test/%.cpp $(HEADERS) i586-mingw32msvc-g++ -c $(TESTDEFS) $(CFLAGS) -o $@ $< test_bitcoin.exe: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%)) - i586-mingw32msvc-g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ -lboost_unit_test_framework-mt-s $(LIBS) + i586-mingw32msvc-g++ $(CFLAGS) $(LDFLAGS) -o $@ $(LIBPATHS) $^ -lboost_unit_test_framework-mt-s $(LIBS) clean: diff --git a/src/makefile.mingw b/src/makefile.mingw index 9b3d36f355..5d46797766 100644 --- a/src/makefile.mingw +++ b/src/makefile.mingw @@ -28,6 +28,7 @@ LIBS= \ DEFS=-DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB -DBOOST_SPIRIT_THREADSAFE DEBUGFLAGS=-g CFLAGS=-mthreads -O2 -w -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS) +LDFLAGS=-Wl,--dynamicbase -Wl,--nxcompat TESTDEFS = -DTEST_DATA_DIR=$(abspath test/data) @@ -85,7 +86,7 @@ obj/%.o: %.cpp $(HEADERS) g++ -c $(CFLAGS) -o $@ $< bitcoind.exe: $(OBJS:obj/%=obj/%) - g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) + g++ $(CFLAGS) $(LDFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp)) @@ -93,7 +94,7 @@ obj-test/%.o: test/%.cpp $(HEADERS) g++ -c $(TESTDEFS) $(CFLAGS) -o $@ $< test_bitcoin.exe: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%)) - g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ -lboost_unit_test_framework $(LIBS) + g++ $(CFLAGS) $(LDFLAGS) -o $@ $(LIBPATHS) $^ -lboost_unit_test_framework $(LIBS) clean: -del /Q bitcoind test_bitcoin diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 08f936e719..7d5b6fed53 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -13,7 +13,6 @@ #include <QUrl> #include <QScrollBar> -#include <boost/tokenizer.hpp> #include <openssl/crypto.h> // TODO: make it possible to filter out categories (esp debug messages when implemented) @@ -54,34 +53,108 @@ void RPCExecutor::start() // Nothing to do } -void RPCExecutor::request(const QString &command) +/** + * Split shell command line into a list of arguments. Aims to emulate \c bash and friends. + * + * - Arguments are delimited with whitespace + * - Extra whitespace at the beginning and end and between arguments will be ignored + * - Text can be "double" or 'single' quoted + * - The backslash \c \ is used as escape character + * - Outside quotes, any character can be escaped + * - Within double quotes, only escape \c " and backslashes before a \c " or another backslash + * - Within single quotes, no escaping is possible and no special interpretation takes place + * + * @param[out] args Parsed arguments will be appended to this list + * @param[in] strCommand Command line to split + */ +bool parseCommandLine(std::vector<std::string> &args, const std::string &strCommand) { - // Parse shell-like command line into separate arguments - std::string strMethod; - std::vector<std::string> strParams; - try { - boost::escaped_list_separator<char> els('\\',' ','\"'); - std::string strCommand = command.toStdString(); - boost::tokenizer<boost::escaped_list_separator<char> > tok(strCommand, els); - - int n = 0; - for(boost::tokenizer<boost::escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end();++beg,++n) + enum CmdParseState + { + STATE_EATING_SPACES, + STATE_ARGUMENT, + STATE_SINGLEQUOTED, + STATE_DOUBLEQUOTED, + STATE_ESCAPE_OUTER, + STATE_ESCAPE_DOUBLEQUOTED + } state = STATE_EATING_SPACES; + std::string curarg; + foreach(char ch, strCommand) + { + switch(state) { - if(n == 0) // First parameter is the command - strMethod = *beg; - else - strParams.push_back(*beg); + case STATE_ARGUMENT: // In or after argument + case STATE_EATING_SPACES: // Handle runs of whitespace + switch(ch) + { + case '"': state = STATE_DOUBLEQUOTED; break; + case '\'': state = STATE_SINGLEQUOTED; break; + case '\\': state = STATE_ESCAPE_OUTER; break; + case ' ': case '\n': case '\t': + if(state == STATE_ARGUMENT) // Space ends argument + { + args.push_back(curarg); + curarg.clear(); + } + state = STATE_EATING_SPACES; + break; + default: curarg += ch; state = STATE_ARGUMENT; + } + break; + case STATE_SINGLEQUOTED: // Single-quoted string + switch(ch) + { + case '\'': state = STATE_ARGUMENT; break; + default: curarg += ch; + } + break; + case STATE_DOUBLEQUOTED: // Double-quoted string + switch(ch) + { + case '"': state = STATE_ARGUMENT; break; + case '\\': state = STATE_ESCAPE_DOUBLEQUOTED; break; + default: curarg += ch; + } + break; + case STATE_ESCAPE_OUTER: // '\' outside quotes + curarg += ch; state = STATE_ARGUMENT; + break; + case STATE_ESCAPE_DOUBLEQUOTED: // '\' in double-quoted text + if(ch != '"' && ch != '\\') curarg += '\\'; // keep '\' for everything but the quote and '\' itself + curarg += ch; state = STATE_DOUBLEQUOTED; + break; } } - catch(boost::escaped_list_error &e) + switch(state) // final state { - emit reply(RPCConsole::CMD_ERROR, QString("Parse error")); - return; + case STATE_EATING_SPACES: + return true; + case STATE_ARGUMENT: + args.push_back(curarg); + return true; + default: // ERROR to end in one of the other states + return false; } +} - try { +void RPCExecutor::request(const QString &command) +{ + std::vector<std::string> args; + if(!parseCommandLine(args, command.toStdString())) + { + emit reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \"")); + return; + } + if(args.empty()) + return; // Nothing to do + try + { std::string strPrint; - json_spirit::Value result = tableRPC.execute(strMethod, RPCConvertValues(strMethod, strParams)); + // Convert argument list to JSON objects in method-dependent way, + // and pass it along with the method name to the dispatcher. + json_spirit::Value result = tableRPC.execute( + args[0], + RPCConvertValues(args[0], std::vector<std::string>(args.begin() + 1, args.end()))); // Format result reply if (result.type() == json_spirit::null_type) @@ -95,7 +168,16 @@ void RPCExecutor::request(const QString &command) } catch (json_spirit::Object& objError) { - emit reply(RPCConsole::CMD_ERROR, QString::fromStdString(write_string(json_spirit::Value(objError), false))); + try // Nice formatting for standard-format error + { + int code = find_value(objError, "code").get_int(); + std::string message = find_value(objError, "message").get_str(); + emit reply(RPCConsole::CMD_ERROR, QString::fromStdString(message) + " (code " + QString::number(code) + ")"); + } + catch(std::runtime_error &) // raised when converting to invalid type, i.e. missing code or message + { // Show raw JSON object + emit reply(RPCConsole::CMD_ERROR, QString::fromStdString(write_string(json_spirit::Value(objError), false))); + } } catch (std::exception& e) { diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index d2cb31f51d..2954b9ee57 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -225,6 +225,10 @@ Value getblocktemplate(const Array& params, bool fHelp) const Value& modeval = find_value(oparam, "mode"); if (modeval.type() == str_type) strMode = modeval.get_str(); + else if (modeval.type() == null_type) + { + /* Do nothing */ + } else throw JSONRPCError(-8, "Invalid mode"); } diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index b82b4f9991..929dde9c15 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -1006,7 +1006,8 @@ Value listtransactions(const Array& params, bool fHelp) Array ret; - CWallet::TxItems txOrdered = pwalletMain->OrderedTxItems(strAccount); + std::list<CAccountingEntry> acentries; + CWallet::TxItems txOrdered = pwalletMain->OrderedTxItems(acentries, strAccount); // iterate backwards until we have nCount items to return: for (CWallet::TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) diff --git a/src/wallet.cpp b/src/wallet.cpp index f2c21129be..2f312d809e 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -291,8 +291,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) return true; } -CWallet::TxItems -CWallet::OrderedTxItems(std::string strAccount) +CWallet::TxItems CWallet::OrderedTxItems(std::list<CAccountingEntry>& acentries, std::string strAccount) { CWalletDB walletdb(strWalletFile); @@ -306,7 +305,7 @@ CWallet::OrderedTxItems(std::string strAccount) CWalletTx* wtx = &((*it).second); txOrdered.insert(make_pair(wtx->nOrderPos, TxPair(wtx, (CAccountingEntry*)0))); } - list<CAccountingEntry> acentries; + acentries.clear(); walletdb.ListAccountCreditDebit(strAccount, acentries); BOOST_FOREACH(CAccountingEntry& entry, acentries) { @@ -375,7 +374,8 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) { // Tolerate times up to the last timestamp in the wallet not more than 5 minutes into the future int64 latestTolerated = latestNow + 300; - TxItems txOrdered = OrderedTxItems(); + std::list<CAccountingEntry> acentries; + TxItems txOrdered = OrderedTxItems(acentries); for (TxItems::reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it) { CWalletTx *const pwtx = (*it).second.first; diff --git a/src/wallet.h b/src/wallet.h index 44f8a17d37..7fd33629fe 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -146,7 +146,12 @@ public: typedef std::pair<CWalletTx*, CAccountingEntry*> TxPair; typedef std::multimap<int64, TxPair > TxItems; - TxItems OrderedTxItems(std::string strAccount = ""); + + /** Get the wallet's activity log + @return multimap of ordered transactions and accounting entries + @warning Returned pointers are *only* valid within the scope of passed acentries + */ + TxItems OrderedTxItems(std::list<CAccountingEntry>& acentries, std::string strAccount = ""); void MarkDirty(); bool AddToWallet(const CWalletTx& wtxIn); |