aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am6
-rw-r--r--src/Makefile.qt.include19
-rw-r--r--src/alert.cpp1
-rw-r--r--src/base58.cpp9
-rw-r--r--src/bitcoin-cli.cpp185
-rw-r--r--src/bitcoind.cpp33
-rw-r--r--src/chainparams.cpp56
-rw-r--r--src/chainparams.h77
-rw-r--r--src/compat/glibc_sanity.cpp61
-rw-r--r--src/compat/glibcxx_sanity.cpp61
-rw-r--r--src/compat/sanity.h7
-rw-r--r--src/init.cpp53
-rw-r--r--src/init.h3
-rw-r--r--src/key.cpp12
-rw-r--r--src/key.h3
-rw-r--r--src/main.cpp284
-rw-r--r--src/main.h18
-rw-r--r--src/miner.cpp44
-rw-r--r--src/miner.h3
-rw-r--r--src/net.cpp43
-rw-r--r--src/net.h21
-rw-r--r--src/protocol.cpp1
-rw-r--r--src/protocol.h3
-rw-r--r--src/qt/bitcoin.cpp5
-rw-r--r--src/qt/bitcoin.qrc73
-rw-r--r--src/qt/bitcoin_locale.qrc75
-rw-r--r--src/qt/bitcoingui.cpp5
-rw-r--r--src/qt/clientmodel.cpp8
-rw-r--r--src/qt/clientmodel.h2
-rw-r--r--src/qt/coincontroldialog.cpp24
-rw-r--r--src/qt/forms/aboutdialog.ui192
-rw-r--r--src/qt/forms/coincontroldialog.ui2
-rw-r--r--src/qt/forms/helpmessagedialog.ui7
-rw-r--r--src/qt/forms/optionsdialog.ui10
-rw-r--r--src/qt/forms/rpcconsole.ui4
-rw-r--r--src/qt/forms/sendcoinsdialog.ui2
-rw-r--r--src/qt/optionsdialog.cpp2
-rw-r--r--src/qt/optionsmodel.cpp13
-rw-r--r--src/qt/optionsmodel.h1
-rw-r--r--src/qt/paymentrequestplus.cpp1
-rw-r--r--src/qt/paymentrequestplus.h2
-rw-r--r--src/qt/paymentserver.cpp4
-rw-r--r--src/qt/rpcconsole.cpp6
-rw-r--r--src/qt/sendcoinsdialog.cpp4
-rw-r--r--src/qt/transactiondesc.cpp2
-rw-r--r--src/qt/utilitydialog.cpp116
-rw-r--r--src/qt/utilitydialog.h25
-rw-r--r--src/qt/walletmodel.cpp2
-rw-r--r--src/rpcblockchain.cpp24
-rw-r--r--src/rpcclient.cpp175
-rw-r--r--src/rpcclient.h10
-rw-r--r--src/rpcmining.cpp8
-rw-r--r--src/rpcmisc.cpp2
-rw-r--r--src/rpcserver.cpp17
-rw-r--r--src/script.cpp4
-rw-r--r--src/script.h11
-rw-r--r--src/test/util_tests.cpp11
-rw-r--r--src/util.cpp77
-rw-r--r--src/util.h14
-rw-r--r--src/version.cpp2
-rw-r--r--src/wallet.cpp16
-rw-r--r--src/wallet.h2
62 files changed, 1013 insertions, 950 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 3016be47b9..e1542203f8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -85,7 +85,8 @@ BITCOIN_CORE_H = \
util.h \
version.h \
walletdb.h \
- wallet.h
+ wallet.h \
+ compat/sanity.h
JSON_H = \
json/json_spirit.h \
@@ -154,6 +155,8 @@ libbitcoin_common_a_SOURCES = \
sync.cpp \
util.cpp \
version.cpp \
+ compat/glibc_sanity.cpp \
+ compat/glibcxx_sanity.cpp \
$(BITCOIN_CORE_H)
if GLIBC_BACK_COMPAT
@@ -171,7 +174,6 @@ nodist_libbitcoin_common_a_SOURCES = $(srcdir)/obj/build.h
# bitcoind binary #
bitcoind_LDADD = \
libbitcoin_server.a \
- libbitcoin_cli.a \
libbitcoin_common.a \
$(LIBLEVELDB) \
$(LIBMEMENV)
diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include
index 749b976c44..647434e1ef 100644
--- a/src/Makefile.qt.include
+++ b/src/Makefile.qt.include
@@ -76,7 +76,6 @@ QT_TS = \
qt/locale/bitcoin_zh_TW.ts
QT_FORMS_UI = \
- qt/forms/aboutdialog.ui \
qt/forms/addressbookpage.ui \
qt/forms/askpassphrasedialog.ui \
qt/forms/coincontroldialog.ui \
@@ -152,6 +151,8 @@ QT_MOC = \
QT_QRC_CPP = qt/qrc_bitcoin.cpp
QT_QRC = qt/bitcoin.qrc
+QT_QRC_LOCALE_CPP = qt/qrc_bitcoin_locale.cpp
+QT_QRC_LOCALE = qt/bitcoin_locale.qrc
PROTOBUF_CC = qt/paymentrequest.pb.cc
PROTOBUF_H = qt/paymentrequest.pb.h
@@ -321,10 +322,10 @@ qt_libbitcoinqt_a_CPPFLAGS = $(BITCOIN_INCLUDES) $(BITCOIN_QT_INCLUDES) \
$(QT_INCLUDES) $(QT_DBUS_INCLUDES) $(PROTOBUF_CFLAGS) $(QR_CFLAGS)
qt_libbitcoinqt_a_SOURCES = $(BITCOIN_QT_CPP) $(BITCOIN_QT_H) $(QT_FORMS_UI) \
- $(QT_QRC) $(QT_TS) $(PROTOBUF_PROTO) $(RES_ICONS) $(RES_IMAGES) $(RES_MOVIES)
+ $(QT_QRC) $(QT_QRC_LOCALE) $(QT_TS) $(PROTOBUF_PROTO) $(RES_ICONS) $(RES_IMAGES) $(RES_MOVIES)
nodist_qt_libbitcoinqt_a_SOURCES = $(QT_MOC_CPP) $(QT_MOC) $(PROTOBUF_CC) \
- $(PROTOBUF_H) $(QT_QRC_CPP)
+ $(PROTOBUF_H) $(QT_QRC_CPP) $(QT_QRC_LOCALE_CPP)
# forms/foo.h -> forms/ui_foo.h
QT_FORMS_H=$(join $(dir $(QT_FORMS_UI)),$(addprefix ui_, $(notdir $(QT_FORMS_UI:.ui=.h))))
@@ -371,10 +372,16 @@ translate: qt/bitcoinstrings.cpp $(QT_FORMS_UI) $(QT_FORMS_UI) $(BITCOIN_QT_CPP)
@test -n $(LUPDATE) || echo "lupdate is required for updating translations"
$(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(LUPDATE) $^ -locations relative -no-obsolete -ts qt/locale/bitcoin_en.ts
-$(QT_QRC_CPP): $(QT_QRC) $(QT_QM) $(QT_FORMS_H) $(RES_ICONS) $(RES_IMAGES) $(RES_MOVIES) $(PROTOBUF_H)
+$(QT_QRC_LOCALE_CPP): $(QT_QRC_LOCALE) $(QT_QM)
@test -f $(RCC)
- $(AM_V_GEN) cd $(srcdir); QT_SELECT=$(QT_SELECT) $(RCC) -name bitcoin $< | \
- $(SED) -e '/^\*\*.*Created:/d' -e '/^\*\*.*by:/d' > $(abs_builddir)/$@
+ @test -f $(@D)/$(<F) || cp -f $< $(@D)
+ $(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(RCC) -name bitcoin_locale $(@D)/$(<F) | \
+ $(SED) -e '/^\*\*.*Created:/d' -e '/^\*\*.*by:/d' > $@
+
+$(QT_QRC_CPP): $(QT_QRC) $(QT_FORMS_H) $(RES_ICONS) $(RES_IMAGES) $(RES_MOVIES) $(PROTOBUF_H)
+ @test -f $(RCC)
+ $(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(RCC) -name bitcoin $< | \
+ $(SED) -e '/^\*\*.*Created:/d' -e '/^\*\*.*by:/d' > $@
CLEAN_QT = $(nodist_qt_libbitcoinqt_a_SOURCES) $(QT_QM) $(QT_FORMS_H) qt/*.gcda qt/*.gcno
diff --git a/src/alert.cpp b/src/alert.cpp
index 99164d63e5..638f0d7a1c 100644
--- a/src/alert.cpp
+++ b/src/alert.cpp
@@ -5,6 +5,7 @@
#include "alert.h"
+#include "chainparams.h"
#include "key.h"
#include "net.h"
#include "ui_interface.h"
diff --git a/src/base58.cpp b/src/base58.cpp
index 5975703887..1bd64684e5 100644
--- a/src/base58.cpp
+++ b/src/base58.cpp
@@ -114,9 +114,8 @@ std::string EncodeBase58Check(const std::vector<unsigned char>& vchIn) {
}
bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRet) {
- if (!DecodeBase58(psz, vchRet))
- return false;
- if (vchRet.size() < 4)
+ if (!DecodeBase58(psz, vchRet) ||
+ (vchRet.size() < 4))
{
vchRet.clear();
return false;
@@ -154,8 +153,8 @@ void CBase58Data::SetData(const std::vector<unsigned char> &vchVersionIn, const
bool CBase58Data::SetString(const char* psz, unsigned int nVersionBytes) {
std::vector<unsigned char> vchTemp;
- DecodeBase58Check(psz, vchTemp);
- if (vchTemp.size() < nVersionBytes) {
+ bool rc58 = DecodeBase58Check(psz, vchTemp);
+ if ((!rc58) || (vchTemp.size() < nVersionBytes)) {
vchData.clear();
vchVersion.clear();
return false;
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index ce9e7a4027..40b45415c4 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -12,6 +12,33 @@
#include <boost/filesystem/operations.hpp>
+using namespace std;
+using namespace boost;
+using namespace boost::asio;
+using namespace json_spirit;
+
+std::string HelpMessageCli()
+{
+ string strUsage;
+ 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";
+ 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";
+ strUsage += " -rpcconnect=<ip> " + _("Send commands to node running on <ip> (default: 127.0.0.1)") + "\n";
+ strUsage += " -rpcport=<port> " + _("Connect to JSON-RPC on <port> (default: 8332 or testnet: 18332)") + "\n";
+ strUsage += " -rpcwait " + _("Wait for RPC server to start") + "\n";
+ strUsage += " -rpcuser=<user> " + _("Username for JSON-RPC connections") + "\n";
+ strUsage += " -rpcpassword=<pw> " + _("Password for JSON-RPC connections") + "\n";
+
+ strUsage += "\n" + _("SSL options: (see the Bitcoin Wiki for SSL setup instructions)") + "\n";
+ strUsage += " -rpcssl " + _("Use OpenSSL (https) for JSON-RPC connections") + "\n";
+
+ return strUsage;
+}
+
//////////////////////////////////////////////////////////////////////////////
//
// Start
@@ -33,22 +60,24 @@ static bool AppInitRPC(int argc, char* argv[])
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
return false;
}
- // Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause)
+ // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
if (!SelectParamsFromCommandLine()) {
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
return false;
}
- if (argc<2 || mapArgs.count("-?") || mapArgs.count("--help"))
+ if (argc<2 || mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
{
- // First part of help message is specific to RPC client
- std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n\n" +
- _("Usage:") + "\n" +
- " bitcoin-cli [options] <command> [params] " + _("Send command to Bitcoin Core") + "\n" +
- " bitcoin-cli [options] help " + _("List commands") + "\n" +
- " bitcoin-cli [options] help <command> " + _("Get help for a command") + "\n";
+ std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n";
+ if (!mapArgs.count("-version"))
+ {
+ strUsage += "\n" + _("Usage:") + "\n" +
+ " bitcoin-cli [options] <command> [params] " + _("Send command to Bitcoin Core") + "\n" +
+ " bitcoin-cli [options] help " + _("List commands") + "\n" +
+ " bitcoin-cli [options] help <command> " + _("Get help for a command") + "\n";
- strUsage += "\n" + HelpMessageCli(true);
+ strUsage += "\n" + HelpMessageCli();
+ }
fprintf(stdout, "%s", strUsage.c_str());
return false;
@@ -56,6 +85,136 @@ static bool AppInitRPC(int argc, char* argv[])
return true;
}
+Object CallRPC(const string& strMethod, const Array& params)
+{
+ if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "")
+ throw runtime_error(strprintf(
+ _("You must set rpcpassword=<password> in the configuration file:\n%s\n"
+ "If the file does not exist, create it with owner-readable-only file permissions."),
+ GetConfigFile().string().c_str()));
+
+ // Connect to localhost
+ bool fUseSSL = GetBoolArg("-rpcssl", false);
+ asio::io_service io_service;
+ ssl::context context(io_service, ssl::context::sslv23);
+ context.set_options(ssl::context::no_sslv2);
+ asio::ssl::stream<asio::ip::tcp::socket> sslStream(io_service, context);
+ SSLIOStreamDevice<asio::ip::tcp> d(sslStream, fUseSSL);
+ iostreams::stream< SSLIOStreamDevice<asio::ip::tcp> > stream(d);
+
+ bool fWait = GetBoolArg("-rpcwait", false); // -rpcwait means try until server has started
+ do {
+ bool fConnected = d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(Params().RPCPort())));
+ if (fConnected) break;
+ if (fWait)
+ MilliSleep(1000);
+ else
+ throw runtime_error("couldn't connect to server");
+ } while (fWait);
+
+ // HTTP basic authentication
+ string strUserPass64 = EncodeBase64(mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]);
+ map<string, string> mapRequestHeaders;
+ mapRequestHeaders["Authorization"] = string("Basic ") + strUserPass64;
+
+ // Send request
+ string strRequest = JSONRPCRequest(strMethod, params, 1);
+ string strPost = HTTPPost(strRequest, mapRequestHeaders);
+ stream << strPost << std::flush;
+
+ // Receive HTTP reply status
+ int nProto = 0;
+ int nStatus = ReadHTTPStatus(stream, nProto);
+
+ // Receive HTTP reply message headers and body
+ map<string, string> mapHeaders;
+ string strReply;
+ ReadHTTPMessage(stream, mapHeaders, strReply, nProto);
+
+ if (nStatus == HTTP_UNAUTHORIZED)
+ throw runtime_error("incorrect rpcuser or rpcpassword (authorization failed)");
+ else if (nStatus >= 400 && nStatus != HTTP_BAD_REQUEST && nStatus != HTTP_NOT_FOUND && nStatus != HTTP_INTERNAL_SERVER_ERROR)
+ throw runtime_error(strprintf("server returned HTTP error %d", nStatus));
+ else if (strReply.empty())
+ throw runtime_error("no response from server");
+
+ // Parse reply
+ Value valReply;
+ if (!read_string(strReply, valReply))
+ throw runtime_error("couldn't parse reply from server");
+ const Object& reply = valReply.get_obj();
+ if (reply.empty())
+ throw runtime_error("expected reply to have result, error and id properties");
+
+ return reply;
+}
+
+int CommandLineRPC(int argc, char *argv[])
+{
+ string strPrint;
+ int nRet = 0;
+ try
+ {
+ // Skip switches
+ while (argc > 1 && IsSwitchChar(argv[1][0]))
+ {
+ argc--;
+ argv++;
+ }
+
+ // Method
+ if (argc < 2)
+ throw runtime_error("too few parameters");
+ string strMethod = argv[1];
+
+ // Parameters default to strings
+ std::vector<std::string> strParams(&argv[2], &argv[argc]);
+ Array params = RPCConvertValues(strMethod, strParams);
+
+ // Execute
+ Object reply = CallRPC(strMethod, params);
+
+ // Parse reply
+ const Value& result = find_value(reply, "result");
+ const Value& error = find_value(reply, "error");
+
+ if (error.type() != null_type)
+ {
+ // Error
+ strPrint = "error: " + write_string(error, false);
+ int code = find_value(error.get_obj(), "code").get_int();
+ nRet = abs(code);
+ }
+ else
+ {
+ // Result
+ if (result.type() == null_type)
+ strPrint = "";
+ else if (result.type() == str_type)
+ strPrint = result.get_str();
+ else
+ strPrint = write_string(result, true);
+ }
+ }
+ catch (boost::thread_interrupted) {
+ throw;
+ }
+ catch (std::exception& e) {
+ strPrint = string("error: ") + e.what();
+ nRet = EXIT_FAILURE;
+ }
+ catch (...) {
+ PrintExceptionContinue(NULL, "CommandLineRPC()");
+ throw;
+ }
+
+ if (strPrint != "")
+ {
+ fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str());
+ }
+ return nRet;
+}
+
int main(int argc, char* argv[])
{
SetupEnvironment();
@@ -63,17 +222,17 @@ int main(int argc, char* argv[])
try
{
if(!AppInitRPC(argc, argv))
- return abs(RPC_MISC_ERROR);
+ return EXIT_FAILURE;
}
catch (std::exception& e) {
PrintExceptionContinue(&e, "AppInitRPC()");
- return abs(RPC_MISC_ERROR);
+ return EXIT_FAILURE;
} catch (...) {
PrintExceptionContinue(NULL, "AppInitRPC()");
- return abs(RPC_MISC_ERROR);
+ return EXIT_FAILURE;
}
- int ret = abs(RPC_MISC_ERROR);
+ int ret = EXIT_FAILURE;
try
{
ret = CommandLineRPC(argc, argv);
diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp
index 9b535c2e6b..880955481b 100644
--- a/src/bitcoind.cpp
+++ b/src/bitcoind.cpp
@@ -4,7 +4,6 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "rpcserver.h"
-#include "rpcclient.h"
#include "init.h"
#include "main.h"
#include "noui.h"
@@ -77,25 +76,27 @@ bool AppInit(int argc, char* argv[])
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
return false;
}
- // Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause)
+ // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
if (!SelectParamsFromCommandLine()) {
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
return false;
}
- if (mapArgs.count("-?") || mapArgs.count("--help"))
+ if (mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
{
- // First part of help message is specific to bitcoind / RPC client
- std::string strUsage = _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n\n" +
- _("Usage:") + "\n" +
- " bitcoind [options] " + _("Start Bitcoin Core Daemon") + "\n" +
- _("Usage (deprecated, use bitcoin-cli):") + "\n" +
- " bitcoind [options] <command> [params] " + _("Send command to Bitcoin Core") + "\n" +
- " bitcoind [options] help " + _("List commands") + "\n" +
- " bitcoind [options] help <command> " + _("Get help for a command") + "\n";
-
- strUsage += "\n" + HelpMessage(HMM_BITCOIND);
- strUsage += "\n" + HelpMessageCli(false);
+ std::string strUsage = _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n";
+
+ if (mapArgs.count("-version"))
+ {
+ strUsage += LicenseInfo();
+ }
+ else
+ {
+ strUsage += "\n" + _("Usage:") + "\n" +
+ " bitcoind [options] " + _("Start Bitcoin Core Daemon") + "\n";
+
+ strUsage += "\n" + HelpMessage(HMM_BITCOIND);
+ }
fprintf(stdout, "%s", strUsage.c_str());
return false;
@@ -109,8 +110,8 @@ bool AppInit(int argc, char* argv[])
if (fCommandLine)
{
- int ret = CommandLineRPC(argc, argv);
- exit(ret);
+ fprintf(stderr, "Error: There is no RPC client functionality in bitcoind anymore. Use the bitcoin-cli utility instead.\n");
+ exit(1);
}
#ifndef WIN32
fDaemon = GetBoolArg("-daemon", false);
diff --git a/src/chainparams.cpp b/src/chainparams.cpp
index f5cf846a01..31eac62d48 100644
--- a/src/chainparams.cpp
+++ b/src/chainparams.cpp
@@ -6,12 +6,11 @@
#include "chainparams.h"
#include "assert.h"
-#include "core.h"
-#include "protocol.h"
#include "util.h"
#include <boost/assign/list_of.hpp>
+using namespace std;
using namespace boost::assign;
//
@@ -100,6 +99,8 @@ unsigned int pnSeed[] =
class CMainParams : public CChainParams {
public:
CMainParams() {
+ networkID = CChainParams::MAIN;
+ strNetworkID = "main";
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
@@ -112,6 +113,10 @@ public:
nRPCPort = 8332;
bnProofOfWorkLimit = ~uint256(0) >> 32;
nSubsidyHalvingInterval = 210000;
+ nEnforceBlockUpgradeMajority = 750;
+ nRejectBlockOutdatedMajority = 950;
+ nToCheckBlockUpgradeMajority = 1000;
+ nMinerThreads = 0;
// Build the genesis block. Note that the output of the genesis coinbase cannot
// be spent as it did not originally exist in the database.
@@ -167,27 +172,25 @@ public:
addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek;
vFixedSeeds.push_back(addr);
}
- }
-
- virtual const CBlock& GenesisBlock() const { return genesis; }
- virtual Network NetworkID() const { return CChainParams::MAIN; }
- virtual const vector<CAddress>& FixedSeeds() const {
- return vFixedSeeds;
+ fRequireRPCPassword = true;
+ fMiningRequiresPeers = true;
+ fDefaultCheckMemPool = false;
+ fAllowMinDifficultyBlocks = false;
+ fRequireStandard = true;
+ fMineBlocksOnDemand = false;
}
-protected:
- CBlock genesis;
- vector<CAddress> vFixedSeeds;
};
static CMainParams mainParams;
-
//
// Testnet (v3)
//
class CTestNetParams : public CMainParams {
public:
CTestNetParams() {
+ networkID = CChainParams::TESTNET;
+ strNetworkID = "test";
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
@@ -198,6 +201,9 @@ public:
vAlertPubKey = ParseHex("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a");
nDefaultPort = 18333;
nRPCPort = 18332;
+ nEnforceBlockUpgradeMajority = 51;
+ nRejectBlockOutdatedMajority = 75;
+ nToCheckBlockUpgradeMajority = 100;
strDataDir = "testnet3";
// Modify the testnet genesis block so the timestamp is valid for a later start.
@@ -208,6 +214,7 @@ public:
vFixedSeeds.clear();
vSeeds.clear();
+ vSeeds.push_back(CDNSSeedData("alexykot.me", "testnet-seed.alexykot.me"));
vSeeds.push_back(CDNSSeedData("bitcoin.petertodd.org", "testnet-seed.bitcoin.petertodd.org"));
vSeeds.push_back(CDNSSeedData("bluematt.me", "testnet-seed.bluematt.me"));
@@ -216,23 +223,34 @@ public:
base58Prefixes[SECRET_KEY] = list_of(239);
base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x35)(0x87)(0xCF);
base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x35)(0x83)(0x94);
+
+ fRequireRPCPassword = true;
+ fMiningRequiresPeers = true;
+ fDefaultCheckMemPool = false;
+ fAllowMinDifficultyBlocks = true;
+ fRequireStandard = false;
+ fMineBlocksOnDemand = false;
}
- virtual Network NetworkID() const { return CChainParams::TESTNET; }
};
static CTestNetParams testNetParams;
-
//
// Regression test
//
class CRegTestParams : public CTestNetParams {
public:
CRegTestParams() {
+ networkID = CChainParams::REGTEST;
+ strNetworkID = "regtest";
pchMessageStart[0] = 0xfa;
pchMessageStart[1] = 0xbf;
pchMessageStart[2] = 0xb5;
pchMessageStart[3] = 0xda;
nSubsidyHalvingInterval = 150;
+ nEnforceBlockUpgradeMajority = 750;
+ nRejectBlockOutdatedMajority = 950;
+ nToCheckBlockUpgradeMajority = 1000;
+ nMinerThreads = 1;
bnProofOfWorkLimit = ~uint256(0) >> 1;
genesis.nTime = 1296688602;
genesis.nBits = 0x207fffff;
@@ -243,10 +261,14 @@ public:
assert(hashGenesisBlock == uint256("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
vSeeds.clear(); // Regtest mode doesn't have any DNS seeds.
- }
- virtual bool RequireRPCPassword() const { return false; }
- virtual Network NetworkID() const { return CChainParams::REGTEST; }
+ fRequireRPCPassword = false;
+ fMiningRequiresPeers = false;
+ fDefaultCheckMemPool = true;
+ fAllowMinDifficultyBlocks = true;
+ fRequireStandard = false;
+ fMineBlocksOnDemand = true;
+ }
};
static CRegTestParams regTestParams;
diff --git a/src/chainparams.h b/src/chainparams.h
index 5600b904cc..c0a6ebda6b 100644
--- a/src/chainparams.h
+++ b/src/chainparams.h
@@ -6,21 +6,17 @@
#ifndef BITCOIN_CHAIN_PARAMS_H
#define BITCOIN_CHAIN_PARAMS_H
+#include "core.h"
+#include "protocol.h"
#include "uint256.h"
#include <vector>
-using namespace std;
-
-#define MESSAGE_START_SIZE 4
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
-class CAddress;
-class CBlock;
-
struct CDNSSeedData {
- string name, host;
- CDNSSeedData(const string &strName, const string &strHost) : name(strName), host(strHost) {}
+ std::string name, host;
+ CDNSSeedData(const std::string &strName, const std::string &strHost) : name(strName), host(strHost) {}
};
/**
@@ -53,17 +49,37 @@ public:
const uint256& HashGenesisBlock() const { return hashGenesisBlock; }
const MessageStartChars& MessageStart() const { return pchMessageStart; }
- const vector<unsigned char>& AlertKey() const { return vAlertPubKey; }
+ const std::vector<unsigned char>& AlertKey() const { return vAlertPubKey; }
int GetDefaultPort() const { return nDefaultPort; }
const uint256& ProofOfWorkLimit() const { return bnProofOfWorkLimit; }
int SubsidyHalvingInterval() const { return nSubsidyHalvingInterval; }
- virtual const CBlock& GenesisBlock() const = 0;
- virtual bool RequireRPCPassword() const { return true; }
- const string& DataDir() const { return strDataDir; }
- virtual Network NetworkID() const = 0;
- const vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
- const std::vector<unsigned char> &Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
- virtual const vector<CAddress>& FixedSeeds() const = 0;
+ /* Used to check majorities for block version upgrade */
+ int EnforceBlockUpgradeMajority() const { return nEnforceBlockUpgradeMajority; }
+ int RejectBlockOutdatedMajority() const { return nRejectBlockOutdatedMajority; }
+ int ToCheckBlockUpgradeMajority() const { return nToCheckBlockUpgradeMajority; }
+
+ /* Used if GenerateBitcoins is called with a negative number of threads */
+ int DefaultMinerThreads() const { return nMinerThreads; }
+ const CBlock& GenesisBlock() const { return genesis; }
+ bool RequireRPCPassword() const { return fRequireRPCPassword; }
+ /* Make miner wait to have peers to avoid wasting work */
+ bool MiningRequiresPeers() const { return fMiningRequiresPeers; }
+ /* Default value for -checkmempool argument */
+ bool DefaultCheckMemPool() const { return fDefaultCheckMemPool; }
+ /* Allow mining of a min-difficulty block */
+ bool AllowMinDifficultyBlocks() const { return fAllowMinDifficultyBlocks; }
+ /* Make standard checks */
+ bool RequireStandard() const { return fRequireStandard; }
+ const std::string& DataDir() const { return strDataDir; }
+ /* Make miner stop after a block is found. In RPC, don't return
+ * until nGenProcLimit blocks are generated */
+ bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
+ Network NetworkID() const { return networkID; }
+ /* Return the BIP70 network string (main, test or regtest) */
+ std::string NetworkIDString() const { return strNetworkID; }
+ const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
+ const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
+ const std::vector<CAddress>& FixedSeeds() const { return vFixedSeeds; }
int RPCPort() const { return nRPCPort; }
protected:
CChainParams() {}
@@ -71,14 +87,28 @@ protected:
uint256 hashGenesisBlock;
MessageStartChars pchMessageStart;
// Raw pub key bytes for the broadcast alert signing key.
- vector<unsigned char> vAlertPubKey;
+ std::vector<unsigned char> vAlertPubKey;
int nDefaultPort;
int nRPCPort;
uint256 bnProofOfWorkLimit;
int nSubsidyHalvingInterval;
- string strDataDir;
- vector<CDNSSeedData> vSeeds;
+ int nEnforceBlockUpgradeMajority;
+ int nRejectBlockOutdatedMajority;
+ int nToCheckBlockUpgradeMajority;
+ std::string strDataDir;
+ int nMinerThreads;
+ std::vector<CDNSSeedData> vSeeds;
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
+ Network networkID;
+ std::string strNetworkID;
+ CBlock genesis;
+ std::vector<CAddress> vFixedSeeds;
+ bool fRequireRPCPassword;
+ bool fMiningRequiresPeers;
+ bool fDefaultCheckMemPool;
+ bool fAllowMinDifficultyBlocks;
+ bool fRequireStandard;
+ bool fMineBlocksOnDemand;
};
/**
@@ -96,13 +126,4 @@ void SelectParams(CChainParams::Network network);
*/
bool SelectParamsFromCommandLine();
-inline bool TestNet() {
- // Note: it's deliberate that this returns "false" for regression test mode.
- return Params().NetworkID() == CChainParams::TESTNET;
-}
-
-inline bool RegTest() {
- return Params().NetworkID() == CChainParams::REGTEST;
-}
-
#endif
diff --git a/src/compat/glibc_sanity.cpp b/src/compat/glibc_sanity.cpp
new file mode 100644
index 0000000000..1f64df9e33
--- /dev/null
+++ b/src/compat/glibc_sanity.cpp
@@ -0,0 +1,61 @@
+#include "bitcoin-config.h"
+
+#include <cstddef>
+#if defined(HAVE_SYS_SELECT_H)
+#include <sys/select.h>
+#endif
+
+extern "C" void* memcpy(void* a, const void* b, size_t c);
+void* memcpy_int(void* a, const void* b, size_t c)
+{
+ return memcpy(a,b,c);
+}
+
+namespace {
+// trigger: Use the memcpy_int wrapper which calls our internal memcpy.
+// A direct call to memcpy may be optimized away by the compiler.
+// test: Fill an array with a sequence of integers. memcpy to a new empty array.
+// Verify that the arrays are equal. Use an odd size to decrease the odds of
+// the call being optimized away.
+template <unsigned int T>
+bool sanity_test_memcpy()
+{
+ unsigned int memcpy_test[T];
+ unsigned int memcpy_verify[T] = {};
+ for (unsigned int i = 0; i != T; ++i)
+ memcpy_test[i] = i;
+
+ memcpy_int(memcpy_verify,memcpy_test,sizeof(memcpy_test));
+
+ for (unsigned int i = 0; i != T; ++i)
+ {
+ if(memcpy_verify[i] != i)
+ return false;
+ }
+ return true;
+}
+
+#if defined(HAVE_SYS_SELECT_H)
+// trigger: Call FD_SET to trigger __fdelt_chk. FORTIFY_SOURCE must be defined
+// as >0 and optimizations must be set to at least -O2.
+// test: Add a file descriptor to an empty fd_set. Verify that it has been
+// correctly added.
+bool sanity_test_fdelt()
+{
+ fd_set fds;
+ FD_ZERO(&fds);
+ FD_SET(0, &fds);
+ return FD_ISSET(0,&fds);
+}
+#endif
+
+} // anon namespace
+
+bool glibc_sanity_test()
+{
+#if defined(HAVE_SYS_SELECT_H)
+ if (!sanity_test_fdelt())
+ return false;
+#endif
+ return sanity_test_memcpy<1025>();
+}
diff --git a/src/compat/glibcxx_sanity.cpp b/src/compat/glibcxx_sanity.cpp
new file mode 100644
index 0000000000..2ff70948fd
--- /dev/null
+++ b/src/compat/glibcxx_sanity.cpp
@@ -0,0 +1,61 @@
+#include <locale>
+#include <list>
+#include <stdexcept>
+
+namespace{
+
+// trigger: use ctype<char>::widen to trigger ctype<char>::_M_widen_init().
+// test: convert a char from narrow to wide and back. Verify that the result
+// matches the original.
+bool sanity_test_widen(char testchar)
+{
+ const std::ctype<char>& test(std::use_facet< std::ctype<char> >(std::locale()));
+ return test.narrow(test.widen(testchar),'b') == testchar;
+}
+
+// trigger: use list::push_back and list::pop_back to trigger _M_hook and
+// _M_unhook.
+// test: Push a sequence of integers into a list. Pop them off and verify that
+// they match the original sequence.
+bool sanity_test_list(unsigned int size)
+{
+ std::list<unsigned int> test;
+ for (unsigned int i = 0; i != size; ++i)
+ test.push_back(i+1);
+
+ if (test.size() != size)
+ return false;
+
+ while (!test.empty())
+ {
+ if(test.back() != test.size())
+ return false;
+ test.pop_back();
+ }
+ return true;
+}
+
+} // anon namespace
+
+// trigger: string::at(x) on an empty string to trigger __throw_out_of_range_fmt.
+// test: force std::string to throw an out_of_range exception. Verify that
+// it's caught correctly.
+bool sanity_test_range_fmt()
+{
+ std::string test;
+ try
+ {
+ test.at(1);
+ }
+ catch (const std::out_of_range&)
+ {
+ return true;
+ }
+ catch (...){}
+ return false;
+}
+
+bool glibcxx_sanity_test()
+{
+ return sanity_test_widen('a') && sanity_test_list(100) && sanity_test_range_fmt();
+}
diff --git a/src/compat/sanity.h b/src/compat/sanity.h
new file mode 100644
index 0000000000..a221f69dfc
--- /dev/null
+++ b/src/compat/sanity.h
@@ -0,0 +1,7 @@
+#ifndef BITCON_COMPAT_SANITY_H
+#define BITCON_COMPAT_SANITY_H
+
+bool glibc_sanity_test();
+bool glibcxx_sanity_test();
+
+#endif
diff --git a/src/init.cpp b/src/init.cpp
index aca5e0c9aa..6eab273526 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -11,6 +11,7 @@
#include "addrman.h"
#include "checkpoints.h"
+#include "key.h"
#include "main.h"
#include "miner.h"
#include "net.h"
@@ -30,6 +31,7 @@
#ifndef WIN32
#include <signal.h>
#endif
+#include "compat/sanity.h"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
@@ -194,9 +196,9 @@ bool static Bind(const CService &addr, unsigned int flags) {
return true;
}
-// Core-specific options shared between UI, daemon and RPC client
-std::string HelpMessage(HelpMessageMode hmm)
+std::string HelpMessage(HelpMessageMode mode)
{
+ // When adding new options to the categories, please keep and ensure alphabetical ordering.
string strUsage = _("Options:") + "\n";
strUsage += " -? " + _("This help message") + "\n";
strUsage += " -alertnotify=<cmd> " + _("Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)") + "\n";
@@ -204,7 +206,7 @@ std::string HelpMessage(HelpMessageMode hmm)
strUsage += " -checkblocks=<n> " + _("How many blocks to check at startup (default: 288, 0 = all)") + "\n";
strUsage += " -checklevel=<n> " + _("How thorough the block verification of -checkblocks is (0-4, default: 3)") + "\n";
strUsage += " -conf=<file> " + _("Specify configuration file (default: bitcoin.conf)") + "\n";
- if (hmm == HMM_BITCOIND)
+ if (mode == HMM_BITCOIND)
{
#if !defined(WIN32)
strUsage += " -daemon " + _("Run in the background as a daemon and accept commands") + "\n";
@@ -273,12 +275,13 @@ std::string HelpMessage(HelpMessageMode hmm)
strUsage += " -dropmessagestest=<n> " + _("Randomly drop 1 of every <n> network messages") + "\n";
strUsage += " -fuzzmessagestest=<n> " + _("Randomly fuzz 1 of every <n> network messages") + "\n";
strUsage += " -flushwallet " + _("Run a thread to flush wallet periodically (default: 1)") + "\n";
+ strUsage += " -stopafterblockimport " + _("Stop running after importing blocks from disk (default: 0)") + "\n";
}
strUsage += " -debug=<category> " + _("Output debugging information (default: 0, supplying <category> is optional)") + "\n";
strUsage += " " + _("If <category> is not supplied, output all debugging information.") + "\n";
strUsage += " " + _("<category> can be:");
strUsage += " addrman, alert, coindb, db, lock, rand, rpc, selectcoins, mempool, net"; // Don't translate these and qt below
- if (hmm == HMM_BITCOIN_QT)
+ if (mode == HMM_BITCOIN_QT)
strUsage += ", qt";
strUsage += ".\n";
strUsage += " -gen " + _("Generate coins (default: 0)") + "\n";
@@ -329,6 +332,18 @@ std::string HelpMessage(HelpMessageMode hmm)
return strUsage;
}
+std::string LicenseInfo()
+{
+ return FormatParagraph(strprintf(_("Copyright (C) 2009-%i The Bitcoin Core Developers"), COPYRIGHT_YEAR)) + "\n" +
+ "\n" +
+ FormatParagraph(_("This is experimental software.")) + "\n" +
+ "\n" +
+ FormatParagraph(_("Distributed under the MIT/X11 software license, see the accompanying file COPYING or <http://www.opensource.org/licenses/mit-license.php>.")) + "\n" +
+ "\n" +
+ FormatParagraph(_("This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit <https://www.openssl.org/> and cryptographic software written by Eric Young and UPnP software written by Thomas Bernard.")) +
+ "\n";
+}
+
struct CImportingNow
{
CImportingNow() {
@@ -392,6 +407,28 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
LogPrintf("Warning: Could not open blocks file %s\n", path.string());
}
}
+
+ if (GetBoolArg("-stopafterblockimport", false)) {
+ LogPrintf("Stopping after block import\n");
+ StartShutdown();
+ }
+}
+
+/** Sanity checks
+ * Ensure that Bitcoin is running in a usable environment with all
+ * necessary library support.
+ */
+bool InitSanityCheck(void)
+{
+ if(!ECC_InitSanityCheck()) {
+ InitError("OpenSSL appears to lack support for elliptic curve cryptography. For more "
+ "information, visit https://en.bitcoin.it/wiki/OpenSSL_and_EC_Libraries");
+ return false;
+ }
+ if (!glibc_sanity_test() || !glibcxx_sanity_test())
+ return false;
+
+ return true;
}
/** Initialize bitcoin.
@@ -526,7 +563,8 @@ bool AppInit2(boost::thread_group& threadGroup)
InitWarning(_("Warning: Deprecated argument -debugnet ignored, use -debug=net"));
fBenchmark = GetBoolArg("-benchmark", false);
- mempool.setSanityCheck(GetBoolArg("-checkmempool", RegTest()));
+ // Checkmempool defaults to true in regtest mode
+ mempool.setSanityCheck(GetBoolArg("-checkmempool", Params().DefaultCheckMemPool()));
Checkpoints::fEnabled = GetBoolArg("-checkpoints", true);
// -par=0 means autodetect, but nScriptCheckThreads==0 means no concurrency
@@ -597,6 +635,9 @@ bool AppInit2(boost::thread_group& threadGroup)
std::string strWalletFile = GetArg("-wallet", "wallet.dat");
#endif
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
+ // Sanity check
+ if (!InitSanityCheck())
+ return InitError(_("Initialization sanity check failed. Bitcoin Core is shutting down."));
std::string strDataDir = GetDataDir().string();
#ifdef ENABLE_WALLET
@@ -744,7 +785,7 @@ bool AppInit2(boost::thread_group& threadGroup)
}
// see Step 2: parameter interactions for more information about these
- fListen = GetBoolArg("-listen", true);
+ fListen = GetBoolArg("-listen", DEFAULT_LISTEN);
fDiscover = GetBoolArg("-discover", true);
fNameLookup = GetBoolArg("-dns", true);
diff --git a/src/init.h b/src/init.h
index 4a967bea37..52daa47616 100644
--- a/src/init.h
+++ b/src/init.h
@@ -28,6 +28,9 @@ enum HelpMessageMode
HMM_BITCOIN_QT
};
+/** Help for options shared between UI and daemon (for -help) */
std::string HelpMessage(HelpMessageMode mode);
+/** Returns licensing information (for -version) */
+std::string LicenseInfo();
#endif
diff --git a/src/key.cpp b/src/key.cpp
index aa24f0a622..4747beffb4 100644
--- a/src/key.cpp
+++ b/src/key.cpp
@@ -631,3 +631,15 @@ bool CExtPubKey::Derive(CExtPubKey &out, unsigned int nChild) const {
out.nChild = nChild;
return pubkey.Derive(out.pubkey, out.vchChainCode, nChild, vchChainCode);
}
+
+bool ECC_InitSanityCheck() {
+ EC_KEY *pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
+ if(pkey == NULL)
+ return false;
+ EC_KEY_free(pkey);
+
+ // TODO Is there more EC functionality that could be missing?
+ return true;
+}
+
+
diff --git a/src/key.h b/src/key.h
index 983775fd23..11dc65de8c 100644
--- a/src/key.h
+++ b/src/key.h
@@ -306,4 +306,7 @@ struct CExtKey {
void SetMaster(const unsigned char *seed, unsigned int nSeedLen);
};
+/** Check that required EC support is available at runtime */
+bool ECC_InitSanityCheck(void);
+
#endif
diff --git a/src/main.cpp b/src/main.cpp
index cf8c436ded..006ec7cabc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -40,7 +40,6 @@ CTxMemPool mempool;
map<uint256, CBlockIndex*> mapBlockIndex;
CChain chainActive;
-CChain chainMostWork;
int64_t nTimeBestReceived = 0;
int nScriptCheckThreads = 0;
bool fImporting = false;
@@ -398,6 +397,12 @@ CBlockIndex *CChain::FindFork(const CBlockLocator &locator) const {
return Genesis();
}
+CBlockIndex *CChain::FindFork(CBlockIndex *pindex) const {
+ while (pindex && !Contains(pindex))
+ pindex = pindex->pprev;
+ return pindex;
+}
+
CCoinsViewCache *pcoinsTip = NULL;
CBlockTreeDB *pblocktree = NULL;
@@ -823,7 +828,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
// Rather not work on nonstandard transactions (unless -testnet/-regtest)
string reason;
- if (Params().NetworkID() == CChainParams::MAIN && !IsStandardTx(tx, reason))
+ if (Params().RequireStandard() && !IsStandardTx(tx, reason))
return state.DoS(0,
error("AcceptToMemoryPool : nonstandard transaction: %s", reason),
REJECT_NONSTANDARD, reason);
@@ -887,7 +892,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
}
// Check for non-standard pay-to-script-hash in inputs
- if (Params().NetworkID() == CChainParams::MAIN && !AreInputsStandard(tx, view))
+ if (Params().RequireStandard() && !AreInputsStandard(tx, view))
return error("AcceptToMemoryPool: : nonstandard transaction input");
// Note: if you modify this code to accept non-standard transactions, then
@@ -1202,7 +1207,7 @@ unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime)
const uint256 &bnLimit = Params().ProofOfWorkLimit();
// Testnet has min-difficulty blocks
// after nTargetSpacing*2 time between blocks:
- if (TestNet() && nTime > nTargetSpacing*2)
+ if (Params().AllowMinDifficultyBlocks() && nTime > nTargetSpacing*2)
return bnLimit.GetCompact();
uint256 bnResult;
@@ -1230,7 +1235,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
// Only change once per interval
if ((pindexLast->nHeight+1) % nInterval != 0)
{
- if (TestNet())
+ if (Params().AllowMinDifficultyBlocks())
{
// Special difficulty rule for testnet:
// If the new block's timestamp is more than 2* 10 minutes
@@ -1460,7 +1465,7 @@ void UpdateTime(CBlockHeader& block, const CBlockIndex* pindexPrev)
block.nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
// Updating time can change work required on testnet:
- if (TestNet())
+ if (Params().AllowMinDifficultyBlocks())
block.nBits = GetNextWorkRequired(pindexPrev, &block);
}
@@ -1890,6 +1895,11 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
for (unsigned int i = 0; i < block.vtx.size(); i++)
g_signals.SyncTransaction(block.GetTxHash(i), block.vtx[i], &block);
+ // Watch for changes to the previous coinbase transaction.
+ static uint256 hashPrevBestCoinBase;
+ g_signals.UpdatedTransaction(hashPrevBestCoinBase);
+ hashPrevBestCoinBase = block.GetTxHash(0);
+
return true;
}
@@ -1975,7 +1985,7 @@ bool static DisconnectTip(CValidationState &state) {
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
// ignore validation errors in resurrected transactions
list<CTransaction> removed;
- CValidationState stateDummy;
+ CValidationState stateDummy;
if (!tx.IsCoinBase())
if (!AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL))
mempool.remove(tx, removed, true);
@@ -2035,23 +2045,17 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew) {
return true;
}
-// Make chainMostWork correspond to the chain with the most work in it, that isn't
+// Return the tip of the chain with the most work in it, that isn't
// known to be invalid (it's however far from certain to be valid).
-void static FindMostWorkChain() {
- CBlockIndex *pindexNew = NULL;
-
- // In case the current best is invalid, do not consider it.
- while (chainMostWork.Tip() && (chainMostWork.Tip()->nStatus & BLOCK_FAILED_MASK)) {
- setBlockIndexValid.erase(chainMostWork.Tip());
- chainMostWork.SetTip(chainMostWork.Tip()->pprev);
- }
-
+static CBlockIndex* FindMostWorkChain() {
do {
+ CBlockIndex *pindexNew = NULL;
+
// Find the best candidate header.
{
std::set<CBlockIndex*, CBlockIndexWorkComparator>::reverse_iterator it = setBlockIndexValid.rbegin();
if (it == setBlockIndexValid.rend())
- return;
+ return NULL;
pindexNew = *it;
}
@@ -2075,70 +2079,111 @@ void static FindMostWorkChain() {
}
pindexTest = pindexTest->pprev;
}
- if (fInvalidAncestor)
- continue;
-
- break;
+ if (!fInvalidAncestor)
+ return pindexNew;
} while(true);
-
- // Check whether it's actually an improvement.
- if (chainMostWork.Tip() && !CBlockIndexWorkComparator()(chainMostWork.Tip(), pindexNew))
- return;
-
- // We have a new best.
- chainMostWork.SetTip(pindexNew);
}
-// Try to activate to the most-work chain (thereby connecting it).
-bool ActivateBestChain(CValidationState &state) {
- LOCK(cs_main);
+// Try to make some progress towards making pindexMostWork the active block.
+static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMostWork) {
+ AssertLockHeld(cs_main);
+ bool fInvalidFound = false;
CBlockIndex *pindexOldTip = chainActive.Tip();
- bool fComplete = false;
- while (!fComplete) {
- FindMostWorkChain();
- fComplete = true;
+ CBlockIndex *pindexFork = chainActive.FindFork(pindexMostWork);
- // Check whether we have something to do.
- if (chainMostWork.Tip() == NULL) break;
+ // Disconnect active blocks which are no longer in the best chain.
+ while (chainActive.Tip() && chainActive.Tip() != pindexFork) {
+ if (!DisconnectTip(state))
+ return false;
+ }
- // Disconnect active blocks which are no longer in the best chain.
- while (chainActive.Tip() && !chainMostWork.Contains(chainActive.Tip())) {
- if (!DisconnectTip(state))
- return false;
- }
+ // Build list of new blocks to connect.
+ std::vector<CBlockIndex*> vpindexToConnect;
+ vpindexToConnect.reserve(pindexMostWork->nHeight - (pindexFork ? pindexFork->nHeight : -1));
+ while (pindexMostWork && pindexMostWork != pindexFork) {
+ vpindexToConnect.push_back(pindexMostWork);
+ pindexMostWork = pindexMostWork->pprev;
+ }
- // Connect new blocks.
- while (!chainActive.Contains(chainMostWork.Tip())) {
- CBlockIndex *pindexConnect = chainMostWork[chainActive.Height() + 1];
- if (!ConnectTip(state, pindexConnect)) {
- if (state.IsInvalid()) {
- // The block violates a consensus rule.
- if (!state.CorruptionPossible())
- InvalidChainFound(chainMostWork.Tip());
- fComplete = false;
- state = CValidationState();
- break;
- } else {
- // A system error occurred (disk space, database error, ...).
- return false;
- }
+ // Connect new blocks.
+ BOOST_REVERSE_FOREACH(CBlockIndex *pindexConnect, vpindexToConnect) {
+ if (!ConnectTip(state, pindexConnect)) {
+ if (state.IsInvalid()) {
+ // The block violates a consensus rule.
+ if (!state.CorruptionPossible())
+ InvalidChainFound(vpindexToConnect.back());
+ state = CValidationState();
+ fInvalidFound = true;
+ break;
+ } else {
+ // A system error occurred (disk space, database error, ...).
+ return false;
+ }
+ } else {
+ if (!pindexOldTip || chainActive.Tip()->nChainWork > pindexOldTip->nChainWork) {
+ // We're in a better position than we were. Return temporarily to release the lock.
+ break;
}
}
}
- if (chainActive.Tip() != pindexOldTip) {
- std::string strCmd = GetArg("-blocknotify", "");
- if (!IsInitialBlockDownload() && !strCmd.empty())
+ // Callbacks/notifications for a new best chain.
+ if (fInvalidFound)
+ CheckForkWarningConditionsOnNewFork(vpindexToConnect.back());
+ else
+ CheckForkWarningConditions();
+
+ if (!pblocktree->Flush())
+ return state.Abort(_("Failed to sync block index"));
+
+ return true;
+}
+
+bool ActivateBestChain(CValidationState &state) {
+ CBlockIndex *pindexNewTip = NULL;
+ CBlockIndex *pindexMostWork = NULL;
+ do {
+ boost::this_thread::interruption_point();
+
+ bool fInitialDownload;
{
- boost::replace_all(strCmd, "%s", chainActive.Tip()->GetBlockHash().GetHex());
- boost::thread t(runCommand, strCmd); // thread runs free
+ LOCK(cs_main);
+ pindexMostWork = FindMostWorkChain();
+
+ // Whether we have anything to do at all.
+ if (pindexMostWork == NULL || pindexMostWork == chainActive.Tip())
+ return true;
+
+ if (!ActivateBestChainStep(state, pindexMostWork))
+ return false;
+
+ pindexNewTip = chainActive.Tip();
+ fInitialDownload = IsInitialBlockDownload();
}
- }
+ // When we reach this point, we switched to a new tip (stored in pindexNewTip).
+
+ // Notifications/callbacks that can run without cs_main
+ if (!fInitialDownload) {
+ uint256 hashNewTip = pindexNewTip->GetBlockHash();
+ // Relay inventory, but don't relay old inventory during initial block download.
+ int nBlockEstimate = Checkpoints::GetTotalBlocksEstimate();
+ LOCK(cs_vNodes);
+ BOOST_FOREACH(CNode* pnode, vNodes)
+ if (chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate))
+ pnode->PushInventory(CInv(MSG_BLOCK, hashNewTip));
+
+ std::string strCmd = GetArg("-blocknotify", "");
+ if (!strCmd.empty()) {
+ boost::replace_all(strCmd, "%s", hashNewTip.GetHex());
+ boost::thread t(runCommand, strCmd); // thread runs free
+ }
+ }
+ uiInterface.NotifyBlocksChanged();
+ } while(pindexMostWork != chainActive.Tip());
return true;
}
-
CBlockIndex* AddToBlockIndex(CBlockHeader& block)
{
// Check for duplicate
@@ -2168,7 +2213,6 @@ CBlockIndex* AddToBlockIndex(CBlockHeader& block)
return pindexNew;
}
-
// Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS).
bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBlockIndex *pindexNew, const CDiskBlockPos& pos)
{
@@ -2198,30 +2242,9 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindexNew)))
return state.Abort(_("Failed to write block index"));
- // New best?
- if (!ActivateBestChain(state))
- return false;
-
- LOCK(cs_main);
- if (pindexNew == chainActive.Tip())
- {
- // Clear fork warning if its no longer applicable
- CheckForkWarningConditions();
- // Notify UI to display prev block's coinbase if it was ours
- static uint256 hashPrevBestCoinBase;
- g_signals.UpdatedTransaction(hashPrevBestCoinBase);
- hashPrevBestCoinBase = block.GetTxHash(0);
- } else
- CheckForkWarningConditionsOnNewFork(pindexNew);
-
- if (!pblocktree->Flush())
- return state.Abort(_("Failed to sync block index"));
-
- uiInterface.NotifyBlocksChanged();
return true;
}
-
bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false)
{
bool fUpdatedLast = false;
@@ -2316,7 +2339,6 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne
return true;
}
-
bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW)
{
// Check proof of work matches claimed amount
@@ -2457,14 +2479,11 @@ bool AcceptBlockHeader(CBlockHeader& block, CValidationState& state, CBlockIndex
return state.DoS(100, error("AcceptBlock() : forked chain older than last checkpoint (height %d)", nHeight));
// Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded:
- if (block.nVersion < 2)
+ if (block.nVersion < 2 &&
+ CBlockIndex::IsSuperMajority(2, pindexPrev, Params().RejectBlockOutdatedMajority()))
{
- if ((!TestNet() && CBlockIndex::IsSuperMajority(2, pindexPrev, 950, 1000)) ||
- (TestNet() && CBlockIndex::IsSuperMajority(2, pindexPrev, 75, 100)))
- {
- return state.Invalid(error("AcceptBlock() : rejected nVersion=1 block"),
- REJECT_OBSOLETE, "bad-version");
- }
+ return state.Invalid(error("AcceptBlock() : rejected nVersion=1 block"),
+ REJECT_OBSOLETE, "bad-version");
}
}
@@ -2494,7 +2513,6 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
}
int nHeight = pindex->nHeight;
- uint256 hash = pindex->GetBlockHash();
// Check that all transactions are finalized
BOOST_FOREACH(const CTransaction& tx, block.vtx)
@@ -2505,19 +2523,15 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
}
// Enforce block.nVersion=2 rule that the coinbase starts with serialized block height
- if (block.nVersion >= 2)
+ // if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet):
+ if (block.nVersion >= 2 &&
+ CBlockIndex::IsSuperMajority(2, pindex->pprev, Params().EnforceBlockUpgradeMajority()))
{
- // if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet):
- if ((!TestNet() && CBlockIndex::IsSuperMajority(2, pindex->pprev, 750, 1000)) ||
- (TestNet() && CBlockIndex::IsSuperMajority(2, pindex->pprev, 51, 100)))
- {
- CScript expect = CScript() << nHeight;
- if (block.vtx[0].vin[0].scriptSig.size() < expect.size() ||
- !std::equal(expect.begin(), expect.end(), block.vtx[0].vin[0].scriptSig.begin())) {
- pindex->nStatus |= BLOCK_FAILED_VALID;
- return state.DoS(100, error("AcceptBlock() : block height mismatch in coinbase"),
- REJECT_INVALID, "bad-cb-height");
- }
+ CScript expect = CScript() << nHeight;
+ if (block.vtx[0].vin[0].scriptSig.size() < expect.size() ||
+ !std::equal(expect.begin(), expect.end(), block.vtx[0].vin[0].scriptSig.begin())) {
+ pindex->nStatus |= BLOCK_FAILED_VALID;
+ return state.DoS(100, error("AcceptBlock() : block height mismatch in coinbase"), REJECT_INVALID, "bad-cb-height");
}
}
@@ -2538,21 +2552,12 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
return state.Abort(_("System error: ") + e.what());
}
- // Relay inventory, but don't relay old inventory during initial block download
- int nBlockEstimate = Checkpoints::GetTotalBlocksEstimate();
- if (chainActive.Tip()->GetBlockHash() == hash)
- {
- LOCK(cs_vNodes);
- BOOST_FOREACH(CNode* pnode, vNodes)
- if (chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate))
- pnode->PushInventory(CInv(MSG_BLOCK, hash));
- }
-
return true;
}
-bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired, unsigned int nToCheck)
+bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired)
{
+ unsigned int nToCheck = Params().ToCheckBlockUpgradeMajority();
unsigned int nFound = 0;
for (unsigned int i = 0; i < nToCheck && nFound < nRequired && pstart != NULL; i++)
{
@@ -2577,10 +2582,11 @@ void PushGetBlocks(CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd)
bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp)
{
- AssertLockHeld(cs_main);
-
// Check for duplicate
uint256 hash = pblock->GetHash();
+
+ {
+ LOCK(cs_main);
if (mapBlockIndex.count(hash))
return state.Invalid(error("ProcessBlock() : already have block %d %s", mapBlockIndex[hash]->nHeight, hash.ToString()), 0, "duplicate");
if (mapOrphanBlocks.count(hash))
@@ -2649,7 +2655,11 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
mapOrphanBlocksByPrev.erase(hashPrev);
}
- LogPrintf("ProcessBlock: ACCEPTED\n");
+ }
+
+ if (!ActivateBestChain(state))
+ return error("ProcessBlock() : ActivateBestChain failed");
+
return true;
}
@@ -3085,6 +3095,8 @@ bool InitBlockIndex() {
CBlockIndex *pindex = AddToBlockIndex(block);
if (!ReceivedBlockTransactions(block, state, pindex, blockPos))
return error("LoadBlockIndex() : genesis block not accepted");
+ if (!ActivateBestChain(state))
+ return error("LoadBlockIndex() : genesis block cannot be activated");
} catch(std::runtime_error &e) {
return error("LoadBlockIndex() : failed to initialize block database: %s", e.what());
}
@@ -3214,7 +3226,6 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
// process block
if (nBlockPos >= nStartByte) {
- LOCK(cs_main);
if (dbp)
dbp->nPos = nBlockPos;
CValidationState state;
@@ -3903,10 +3914,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
CInv inv(MSG_BLOCK, block.GetHash());
pfrom->AddInventoryKnown(inv);
- LOCK(cs_main);
- // Remember who we got this block from.
- mapBlockSource[inv.hash] = pfrom->GetId();
- MarkBlockAsReceived(inv.hash, pfrom->GetId());
+ {
+ LOCK(cs_main);
+ // Remember who we got this block from.
+ mapBlockSource[inv.hash] = pfrom->GetId();
+ MarkBlockAsReceived(inv.hash, pfrom->GetId());
+ }
CValidationState state;
ProcessBlock(state, pfrom, &block);
@@ -4280,8 +4293,8 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
// RPC ping request by user
pingSend = true;
}
- if (pto->nLastSend && GetTime() - pto->nLastSend > 30 * 60 && pto->vSendMsg.empty()) {
- // Ping automatically sent as a keepalive
+ if (pto->nPingNonceSent == 0 && pto->nPingUsecStart + PING_INTERVAL * 1000000 < GetTimeMicros()) {
+ // Ping automatically sent as a latency probe & keepalive.
pingSend = true;
}
if (pingSend) {
@@ -4289,15 +4302,14 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
while (nonce == 0) {
RAND_bytes((unsigned char*)&nonce, sizeof(nonce));
}
- pto->nPingNonceSent = nonce;
pto->fPingQueued = false;
+ pto->nPingUsecStart = GetTimeMicros();
if (pto->nVersion > BIP0031_VERSION) {
- // Take timestamp as close as possible before transmitting ping
- pto->nPingUsecStart = GetTimeMicros();
+ pto->nPingNonceSent = nonce;
pto->PushMessage("ping", nonce);
} else {
- // Peer is too old to support ping command with nonce, pong will never arrive, disable timing
- pto->nPingUsecStart = 0;
+ // Peer is too old to support ping command with nonce, pong will never arrive.
+ pto->nPingNonceSent = 0;
pto->PushMessage("ping");
}
}
@@ -4439,8 +4451,8 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
// in flight for over two minutes, since we first had a chance to
// process an incoming block.
int64_t nNow = GetTimeMicros();
- if (!pto->fDisconnect && state.nBlocksInFlight &&
- state.nLastBlockReceive < state.nLastBlockProcess - BLOCK_DOWNLOAD_TIMEOUT*1000000 &&
+ if (!pto->fDisconnect && state.nBlocksInFlight &&
+ state.nLastBlockReceive < state.nLastBlockProcess - BLOCK_DOWNLOAD_TIMEOUT*1000000 &&
state.vBlocksInFlight.front().nTime < state.nLastBlockProcess - 2*BLOCK_DOWNLOAD_TIMEOUT*1000000) {
LogPrintf("Peer %s is stalling block download, disconnecting\n", state.name.c_str());
pto->fDisconnect = true;
diff --git a/src/main.h b/src/main.h
index 23c8660376..5a0aedcde1 100644
--- a/src/main.h
+++ b/src/main.h
@@ -66,12 +66,6 @@ static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 128;
/** Timeout in seconds before considering a block download peer unresponsive. */
static const unsigned int BLOCK_DOWNLOAD_TIMEOUT = 60;
-#ifdef USE_UPNP
-static const int fHaveUPnP = true;
-#else
-static const int fHaveUPnP = false;
-#endif
-
/** "reject" message codes **/
static const unsigned char REJECT_MALFORMED = 0x01;
static const unsigned char REJECT_INVALID = 0x10;
@@ -841,10 +835,11 @@ public:
/**
* Returns true if there are nRequired or more blocks of minVersion or above
- * in the last nToCheck blocks, starting at pstart and going backwards.
+ * in the last Params().ToCheckBlockUpgradeMajority() blocks, starting at pstart
+ * and going backwards.
*/
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart,
- unsigned int nRequired, unsigned int nToCheck);
+ unsigned int nRequired);
std::string ToString() const
{
@@ -1018,7 +1013,6 @@ public:
/** RAII wrapper for VerifyDB: Verify consistency of the block and coin databases */
class CVerifyDB {
public:
-
CVerifyDB();
~CVerifyDB();
bool VerifyDB(int nCheckLevel, int nCheckDepth);
@@ -1079,14 +1073,14 @@ public:
/** Find the last common block between this chain and a locator. */
CBlockIndex *FindFork(const CBlockLocator &locator) const;
+
+ /** Find the last common block between this chain and a block index entry. */
+ CBlockIndex *FindFork(CBlockIndex *pindex) const;
};
/** The currently-connected chain of blocks. */
extern CChain chainActive;
-/** The currently best known chain of headers (some of which may be invalid). */
-extern CChain chainMostWork;
-
/** Global variable that points to the active CCoinsView (protected by cs_main) */
extern CCoinsViewCache *pcoinsTip;
diff --git a/src/miner.cpp b/src/miner.cpp
index ddd277a9bb..87779efbbd 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -11,6 +11,8 @@
#ifdef ENABLE_WALLET
#include "wallet.h"
#endif
+
+using namespace std;
//////////////////////////////////////////////////////////////////////////////
//
// BitcoinMiner
@@ -484,22 +486,22 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
LOCK(cs_main);
if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash())
return error("BitcoinMiner : generated block is stale");
+ }
- // Remove key from key pool
- reservekey.KeepKey();
-
- // Track how many getdata requests this block gets
- {
- LOCK(wallet.cs_wallet);
- wallet.mapRequestCount[pblock->GetHash()] = 0;
- }
+ // Remove key from key pool
+ reservekey.KeepKey();
- // Process this block the same as if we had received it from another node
- CValidationState state;
- if (!ProcessBlock(state, NULL, pblock))
- return error("BitcoinMiner : ProcessBlock, block not accepted");
+ // Track how many getdata requests this block gets
+ {
+ LOCK(wallet.cs_wallet);
+ wallet.mapRequestCount[pblock->GetHash()] = 0;
}
+ // Process this block the same as if we had received it from another node
+ CValidationState state;
+ if (!ProcessBlock(state, NULL, pblock))
+ return error("BitcoinMiner : ProcessBlock, block not accepted");
+
return true;
}
@@ -514,7 +516,7 @@ void static BitcoinMiner(CWallet *pwallet)
unsigned int nExtraNonce = 0;
try { while (true) {
- if (Params().NetworkID() != CChainParams::REGTEST) {
+ if (Params().MiningRequiresPeers()) {
// Busy-wait for the network to come online so we don't waste time mining
// on an obsolete chain. In regtest mode we expect to fly solo.
while (vNodes.empty())
@@ -582,9 +584,8 @@ void static BitcoinMiner(CWallet *pwallet)
CheckWork(pblock, *pwallet, reservekey);
SetThreadPriority(THREAD_PRIORITY_LOWEST);
- // In regression test mode, stop mining after a block is found. This
- // allows developers to controllably generate a block on demand.
- if (Params().NetworkID() == CChainParams::REGTEST)
+ // In regression test mode, stop mining after a block is found.
+ if (Params().MineBlocksOnDemand())
throw boost::thread_interrupted();
break;
@@ -622,7 +623,8 @@ void static BitcoinMiner(CWallet *pwallet)
// Check for stop or if block needs to be rebuilt
boost::this_thread::interruption_point();
- if (vNodes.empty() && Params().NetworkID() != CChainParams::REGTEST)
+ // Regtest mode doesn't require peers
+ if (vNodes.empty() && Params().MiningRequiresPeers())
break;
if (nBlockNonce >= 0xffff0000)
break;
@@ -634,7 +636,7 @@ void static BitcoinMiner(CWallet *pwallet)
// Update nTime every few seconds
UpdateTime(*pblock, pindexPrev);
nBlockTime = ByteReverse(pblock->nTime);
- if (TestNet())
+ if (Params().AllowMinDifficultyBlocks())
{
// Changing pblock->nTime can change work required on testnet:
nBlockBits = ByteReverse(pblock->nBits);
@@ -654,8 +656,9 @@ void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
static boost::thread_group* minerThreads = NULL;
if (nThreads < 0) {
- if (Params().NetworkID() == CChainParams::REGTEST)
- nThreads = 1;
+ // In regtest threads defaults to 1
+ if (Params().DefaultMinerThreads())
+ nThreads = Params().DefaultMinerThreads();
else
nThreads = boost::thread::hardware_concurrency();
}
@@ -676,4 +679,3 @@ void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
}
#endif
-
diff --git a/src/miner.h b/src/miner.h
index 26151f6cd5..dcd61d8fd9 100644
--- a/src/miner.h
+++ b/src/miner.h
@@ -10,11 +10,12 @@
class CBlock;
class CBlockIndex;
-struct CBlockTemplate;
class CReserveKey;
class CScript;
class CWallet;
+struct CBlockTemplate;
+
/** Run the miner threads */
void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads);
/** Generate a new block, without valid proof-of-work */
diff --git a/src/net.cpp b/src/net.cpp
index 479f77c469..757a06aaed 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -469,11 +469,10 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
}
}
-
/// debug print
LogPrint("net", "trying connection %s lastseen=%.1fhrs\n",
pszDest ? pszDest : addrConnect.ToString(),
- pszDest ? 0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0);
+ pszDest ? 0.0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0);
// Connect
SOCKET hSocket;
@@ -505,10 +504,8 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
pnode->nTimeConnected = GetTime();
return pnode;
}
- else
- {
- return NULL;
- }
+
+ return NULL;
}
void CNode::CloseSocketDisconnect()
@@ -535,7 +532,6 @@ void CNode::Cleanup()
{
}
-
void CNode::PushVersion()
{
int nBestHeight = g_signals.GetHeight().get_value_or(0);
@@ -1028,23 +1024,27 @@ void ThreadSocketHandler()
//
// Inactivity checking
//
- if (pnode->vSendMsg.empty())
- pnode->nLastSendEmpty = GetTime();
- if (GetTime() - pnode->nTimeConnected > 60)
+ int64_t nTime = GetTime();
+ if (nTime - pnode->nTimeConnected > 60)
{
if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
{
LogPrint("net", "socket no message in first 60 seconds, %d %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0);
pnode->fDisconnect = true;
}
- else if (GetTime() - pnode->nLastSend > 90*60 && GetTime() - pnode->nLastSendEmpty > 90*60)
+ else if (nTime - pnode->nLastSend > TIMEOUT_INTERVAL)
{
- LogPrintf("socket not sending\n");
+ LogPrintf("socket sending timeout: %is\n", nTime - pnode->nLastSend);
pnode->fDisconnect = true;
}
- else if (GetTime() - pnode->nLastRecv > 90*60)
+ else if (nTime - pnode->nLastRecv > (pnode->nVersion > BIP0031_VERSION ? TIMEOUT_INTERVAL : 90*60))
{
- LogPrintf("socket inactivity timeout\n");
+ LogPrintf("socket receive timeout: %is\n", nTime - pnode->nLastRecv);
+ pnode->fDisconnect = true;
+ }
+ else if (pnode->nPingNonceSent && pnode->nPingUsecStart + TIMEOUT_INTERVAL * 1000000 < GetTimeMicros())
+ {
+ LogPrintf("ping timeout: %fs\n", 0.000001 * (GetTimeMicros() - pnode->nPingUsecStart));
pnode->fDisconnect = true;
}
}
@@ -1425,21 +1425,21 @@ void ThreadOpenAddedConnections()
}
// if successful, this moves the passed grant to the constructed node
-bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound, const char *strDest, bool fOneShot)
+bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound, const char *pszDest, bool fOneShot)
{
//
// Initiate outbound network connection
//
boost::this_thread::interruption_point();
- if (!strDest)
+ if (!pszDest) {
if (IsLocal(addrConnect) ||
FindNode((CNetAddr)addrConnect) || CNode::IsBanned(addrConnect) ||
FindNode(addrConnect.ToStringIPPort().c_str()))
return false;
- if (strDest && FindNode(strDest))
+ } else if (FindNode(pszDest))
return false;
- CNode* pnode = ConnectNode(addrConnect, strDest);
+ CNode* pnode = ConnectNode(addrConnect, pszDest);
boost::this_thread::interruption_point();
if (!pnode)
@@ -1575,7 +1575,7 @@ bool BindListenPort(const CService &addrBind, string& strError)
socklen_t len = sizeof(sockaddr);
if (!addrBind.GetSockAddr((struct sockaddr*)&sockaddr, &len))
{
- strError = strprintf("Error: bind address family for %s not supported", addrBind.ToString());
+ strError = strprintf("Error: Bind address family for %s not supported", addrBind.ToString());
LogPrintf("%s\n", strError);
return false;
}
@@ -1769,9 +1769,8 @@ bool StopNode()
class CNetCleanup
{
public:
- CNetCleanup()
- {
- }
+ CNetCleanup() {}
+
~CNetCleanup()
{
// Close sockets
diff --git a/src/net.h b/src/net.h
index bc14069132..14d578a72a 100644
--- a/src/net.h
+++ b/src/net.h
@@ -28,6 +28,7 @@
#include <boost/signals2/signal.hpp>
#include <openssl/rand.h>
+
class CAddrMan;
class CBlockIndex;
class CNode;
@@ -36,8 +37,14 @@ namespace boost {
class thread_group;
}
+/** Time between pings automatically sent out for latency probing and keepalive (in seconds). */
+static const int PING_INTERVAL = 2 * 60;
+/** Time after which to disconnect, after waiting for a ping response (or inactivity). */
+static const int TIMEOUT_INTERVAL = 20 * 60;
/** The maximum number of entries in an 'inv' protocol message */
static const unsigned int MAX_INV_SZ = 50000;
+/** -listen default */
+static const bool DEFAULT_LISTEN = true;
/** -upnp default */
#ifdef USE_UPNP
static const bool DEFAULT_UPNP = USE_UPNP;
@@ -54,11 +61,11 @@ bool GetMyExternalIP(CNetAddr& ipRet);
void AddressCurrentlyConnected(const CService& addr);
CNode* FindNode(const CNetAddr& ip);
CNode* FindNode(const CService& ip);
-CNode* ConnectNode(CAddress addrConnect, const char *strDest = NULL);
+CNode* ConnectNode(CAddress addrConnect, const char *pszDest = NULL);
bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false);
void MapPort(bool fUseUPnP);
unsigned short GetListenPort();
-bool BindListenPort(const CService &bindAddr, std::string& strError=REF(std::string()));
+bool BindListenPort(const CService &bindAddr, std::string& strError);
void StartNode(boost::thread_group& threadGroup);
bool StopNode();
void SocketSendData(CNode *pnode);
@@ -130,7 +137,7 @@ struct LocalServiceInfo {
};
extern CCriticalSection cs_mapLocalHost;
-extern map<CNetAddr, LocalServiceInfo> mapLocalHost;
+extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost;
class CNodeStats
{
@@ -217,7 +224,6 @@ public:
int64_t nLastSend;
int64_t nLastRecv;
- int64_t nLastSendEmpty;
int64_t nTimeConnected;
CAddress addr;
std::string addrName;
@@ -273,10 +279,14 @@ public:
CCriticalSection cs_inventory;
std::multimap<int64_t, CInv> mapAskFor;
- // Ping time measurement
+ // Ping time measurement:
+ // The pong reply we're expecting, or 0 if no pong expected.
uint64_t nPingNonceSent;
+ // Time (in usec) the last ping was sent, or 0 if no ping was ever sent.
int64_t nPingUsecStart;
+ // Last measured round-trip time.
int64_t nPingUsecTime;
+ // Whether a ping is requested.
bool fPingQueued;
CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn = "", bool fInboundIn=false) : ssSend(SER_NETWORK, INIT_PROTO_VERSION), setAddrKnown(5000)
@@ -288,7 +298,6 @@ public:
nLastRecv = 0;
nSendBytes = 0;
nRecvBytes = 0;
- nLastSendEmpty = GetTime();
nTimeConnected = GetTime();
addr = addrIn;
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
diff --git a/src/protocol.cpp b/src/protocol.cpp
index c77a92f020..87b2f23873 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -5,6 +5,7 @@
#include "protocol.h"
+#include "chainparams.h"
#include "util.h"
#ifndef WIN32
diff --git a/src/protocol.h b/src/protocol.h
index e6f105fe5c..6de5d05a72 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -10,7 +10,6 @@
#ifndef __INCLUDED_PROTOCOL_H__
#define __INCLUDED_PROTOCOL_H__
-#include "chainparams.h"
#include "netbase.h"
#include "serialize.h"
#include "uint256.h"
@@ -19,6 +18,8 @@
#include <stdint.h>
#include <string>
+#define MESSAGE_START_SIZE 4
+
/** Message header.
* (4) message start.
* (12) command.
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 45d7a52889..387f6ede4b 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -475,6 +475,7 @@ int main(int argc, char *argv[])
#endif
Q_INIT_RESOURCE(bitcoin);
+ Q_INIT_RESOURCE(bitcoin_locale);
BitcoinApplication app(argc, argv);
#if QT_VERSION > 0x050100
// Generate high-dpi pixmaps
@@ -502,9 +503,9 @@ int main(int argc, char *argv[])
// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
// but before showing splash screen.
- if (mapArgs.count("-?") || mapArgs.count("--help"))
+ if (mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
{
- HelpMessageDialog help(NULL);
+ HelpMessageDialog help(NULL, mapArgs.count("-version"));
help.showOrPrint();
return 1;
}
diff --git a/src/qt/bitcoin.qrc b/src/qt/bitcoin.qrc
index e1c739b022..f38200c7f7 100644
--- a/src/qt/bitcoin.qrc
+++ b/src/qt/bitcoin.qrc
@@ -84,77 +84,4 @@
<file alias="spinner-033">res/movies/spinner-033.png</file>
<file alias="spinner-034">res/movies/spinner-034.png</file>
</qresource>
- <qresource prefix="/translations">
- <file alias="ach">locale/bitcoin_ach.qm</file>
- <file alias="af_ZA">locale/bitcoin_af_ZA.qm</file>
- <file alias="ar">locale/bitcoin_ar.qm</file>
- <file alias="be_BY">locale/bitcoin_be_BY.qm</file>
- <file alias="bg">locale/bitcoin_bg.qm</file>
- <file alias="bs">locale/bitcoin_bs.qm</file>
- <file alias="ca_ES">locale/bitcoin_ca_ES.qm</file>
- <file alias="ca">locale/bitcoin_ca.qm</file>
- <file alias="ca@valencia">locale/bitcoin_ca@valencia.qm</file>
- <file alias="cmn">locale/bitcoin_cmn.qm</file>
- <file alias="cs">locale/bitcoin_cs.qm</file>
- <file alias="cy">locale/bitcoin_cy.qm</file>
- <file alias="da">locale/bitcoin_da.qm</file>
- <file alias="de">locale/bitcoin_de.qm</file>
- <file alias="el_GR">locale/bitcoin_el_GR.qm</file>
- <file alias="en">locale/bitcoin_en.qm</file>
- <file alias="eo">locale/bitcoin_eo.qm</file>
- <file alias="es_CL">locale/bitcoin_es_CL.qm</file>
- <file alias="es_DO">locale/bitcoin_es_DO.qm</file>
- <file alias="es_MX">locale/bitcoin_es_MX.qm</file>
- <file alias="es">locale/bitcoin_es.qm</file>
- <file alias="es_UY">locale/bitcoin_es_UY.qm</file>
- <file alias="et">locale/bitcoin_et.qm</file>
- <file alias="eu_ES">locale/bitcoin_eu_ES.qm</file>
- <file alias="fa_IR">locale/bitcoin_fa_IR.qm</file>
- <file alias="fa">locale/bitcoin_fa.qm</file>
- <file alias="fi">locale/bitcoin_fi.qm</file>
- <file alias="fr_CA">locale/bitcoin_fr_CA.qm</file>
- <file alias="fr">locale/bitcoin_fr.qm</file>
- <file alias="gl">locale/bitcoin_gl.qm</file>
- <file alias="gu_IN">locale/bitcoin_gu_IN.qm</file>
- <file alias="he">locale/bitcoin_he.qm</file>
- <file alias="hi_IN">locale/bitcoin_hi_IN.qm</file>
- <file alias="hr">locale/bitcoin_hr.qm</file>
- <file alias="hu">locale/bitcoin_hu.qm</file>
- <file alias="id_ID">locale/bitcoin_id_ID.qm</file>
- <file alias="it">locale/bitcoin_it.qm</file>
- <file alias="ja">locale/bitcoin_ja.qm</file>
- <file alias="ka">locale/bitcoin_ka.qm</file>
- <file alias="kk_KZ">locale/bitcoin_kk_KZ.qm</file>
- <file alias="ko_KR">locale/bitcoin_ko_KR.qm</file>
- <file alias="ky">locale/bitcoin_ky.qm</file>
- <file alias="la">locale/bitcoin_la.qm</file>
- <file alias="lt">locale/bitcoin_lt.qm</file>
- <file alias="lv_LV">locale/bitcoin_lv_LV.qm</file>
- <file alias="mn">locale/bitcoin_mn.qm</file>
- <file alias="ms_MY">locale/bitcoin_ms_MY.qm</file>
- <file alias="nb">locale/bitcoin_nb.qm</file>
- <file alias="nl">locale/bitcoin_nl.qm</file>
- <file alias="pam">locale/bitcoin_pam.qm</file>
- <file alias="pl">locale/bitcoin_pl.qm</file>
- <file alias="pt_BR">locale/bitcoin_pt_BR.qm</file>
- <file alias="pt_PT">locale/bitcoin_pt_PT.qm</file>
- <file alias="ro_RO">locale/bitcoin_ro_RO.qm</file>
- <file alias="ru">locale/bitcoin_ru.qm</file>
- <file alias="sah">locale/bitcoin_sah.qm</file>
- <file alias="sk">locale/bitcoin_sk.qm</file>
- <file alias="sl_SI">locale/bitcoin_sl_SI.qm</file>
- <file alias="sq">locale/bitcoin_sq.qm</file>
- <file alias="sr">locale/bitcoin_sr.qm</file>
- <file alias="sv">locale/bitcoin_sv.qm</file>
- <file alias="th_TH">locale/bitcoin_th_TH.qm</file>
- <file alias="tr">locale/bitcoin_tr.qm</file>
- <file alias="uk">locale/bitcoin_uk.qm</file>
- <file alias="ur_PK">locale/bitcoin_ur_PK.qm</file>
- <file alias="uz@Cyrl">locale/bitcoin_uz@Cyrl.qm</file>
- <file alias="vi">locale/bitcoin_vi.qm</file>
- <file alias="vi_VN">locale/bitcoin_vi_VN.qm</file>
- <file alias="zh_CN">locale/bitcoin_zh_CN.qm</file>
- <file alias="zh_HK">locale/bitcoin_zh_HK.qm</file>
- <file alias="zh_TW">locale/bitcoin_zh_TW.qm</file>
- </qresource>
</RCC>
diff --git a/src/qt/bitcoin_locale.qrc b/src/qt/bitcoin_locale.qrc
new file mode 100644
index 0000000000..b70a107397
--- /dev/null
+++ b/src/qt/bitcoin_locale.qrc
@@ -0,0 +1,75 @@
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource prefix="/translations">
+ <file alias="ach">locale/bitcoin_ach.qm</file>
+ <file alias="af_ZA">locale/bitcoin_af_ZA.qm</file>
+ <file alias="ar">locale/bitcoin_ar.qm</file>
+ <file alias="be_BY">locale/bitcoin_be_BY.qm</file>
+ <file alias="bg">locale/bitcoin_bg.qm</file>
+ <file alias="bs">locale/bitcoin_bs.qm</file>
+ <file alias="ca_ES">locale/bitcoin_ca_ES.qm</file>
+ <file alias="ca">locale/bitcoin_ca.qm</file>
+ <file alias="ca@valencia">locale/bitcoin_ca@valencia.qm</file>
+ <file alias="cmn">locale/bitcoin_cmn.qm</file>
+ <file alias="cs">locale/bitcoin_cs.qm</file>
+ <file alias="cy">locale/bitcoin_cy.qm</file>
+ <file alias="da">locale/bitcoin_da.qm</file>
+ <file alias="de">locale/bitcoin_de.qm</file>
+ <file alias="el_GR">locale/bitcoin_el_GR.qm</file>
+ <file alias="en">locale/bitcoin_en.qm</file>
+ <file alias="eo">locale/bitcoin_eo.qm</file>
+ <file alias="es_CL">locale/bitcoin_es_CL.qm</file>
+ <file alias="es_DO">locale/bitcoin_es_DO.qm</file>
+ <file alias="es_MX">locale/bitcoin_es_MX.qm</file>
+ <file alias="es">locale/bitcoin_es.qm</file>
+ <file alias="es_UY">locale/bitcoin_es_UY.qm</file>
+ <file alias="et">locale/bitcoin_et.qm</file>
+ <file alias="eu_ES">locale/bitcoin_eu_ES.qm</file>
+ <file alias="fa_IR">locale/bitcoin_fa_IR.qm</file>
+ <file alias="fa">locale/bitcoin_fa.qm</file>
+ <file alias="fi">locale/bitcoin_fi.qm</file>
+ <file alias="fr_CA">locale/bitcoin_fr_CA.qm</file>
+ <file alias="fr">locale/bitcoin_fr.qm</file>
+ <file alias="gl">locale/bitcoin_gl.qm</file>
+ <file alias="gu_IN">locale/bitcoin_gu_IN.qm</file>
+ <file alias="he">locale/bitcoin_he.qm</file>
+ <file alias="hi_IN">locale/bitcoin_hi_IN.qm</file>
+ <file alias="hr">locale/bitcoin_hr.qm</file>
+ <file alias="hu">locale/bitcoin_hu.qm</file>
+ <file alias="id_ID">locale/bitcoin_id_ID.qm</file>
+ <file alias="it">locale/bitcoin_it.qm</file>
+ <file alias="ja">locale/bitcoin_ja.qm</file>
+ <file alias="ka">locale/bitcoin_ka.qm</file>
+ <file alias="kk_KZ">locale/bitcoin_kk_KZ.qm</file>
+ <file alias="ko_KR">locale/bitcoin_ko_KR.qm</file>
+ <file alias="ky">locale/bitcoin_ky.qm</file>
+ <file alias="la">locale/bitcoin_la.qm</file>
+ <file alias="lt">locale/bitcoin_lt.qm</file>
+ <file alias="lv_LV">locale/bitcoin_lv_LV.qm</file>
+ <file alias="mn">locale/bitcoin_mn.qm</file>
+ <file alias="ms_MY">locale/bitcoin_ms_MY.qm</file>
+ <file alias="nb">locale/bitcoin_nb.qm</file>
+ <file alias="nl">locale/bitcoin_nl.qm</file>
+ <file alias="pam">locale/bitcoin_pam.qm</file>
+ <file alias="pl">locale/bitcoin_pl.qm</file>
+ <file alias="pt_BR">locale/bitcoin_pt_BR.qm</file>
+ <file alias="pt_PT">locale/bitcoin_pt_PT.qm</file>
+ <file alias="ro_RO">locale/bitcoin_ro_RO.qm</file>
+ <file alias="ru">locale/bitcoin_ru.qm</file>
+ <file alias="sah">locale/bitcoin_sah.qm</file>
+ <file alias="sk">locale/bitcoin_sk.qm</file>
+ <file alias="sl_SI">locale/bitcoin_sl_SI.qm</file>
+ <file alias="sq">locale/bitcoin_sq.qm</file>
+ <file alias="sr">locale/bitcoin_sr.qm</file>
+ <file alias="sv">locale/bitcoin_sv.qm</file>
+ <file alias="th_TH">locale/bitcoin_th_TH.qm</file>
+ <file alias="tr">locale/bitcoin_tr.qm</file>
+ <file alias="uk">locale/bitcoin_uk.qm</file>
+ <file alias="ur_PK">locale/bitcoin_ur_PK.qm</file>
+ <file alias="uz@Cyrl">locale/bitcoin_uz@Cyrl.qm</file>
+ <file alias="vi">locale/bitcoin_vi.qm</file>
+ <file alias="vi_VN">locale/bitcoin_vi_VN.qm</file>
+ <file alias="zh_CN">locale/bitcoin_zh_CN.qm</file>
+ <file alias="zh_HK">locale/bitcoin_zh_HK.qm</file>
+ <file alias="zh_TW">locale/bitcoin_zh_TW.qm</file>
+ </qresource>
+</RCC>
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index 3469f990ac..30f5ec8939 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -549,14 +549,13 @@ void BitcoinGUI::aboutClicked()
if(!clientModel)
return;
- AboutDialog dlg(this);
- dlg.setModel(clientModel);
+ HelpMessageDialog dlg(this, true);
dlg.exec();
}
void BitcoinGUI::showHelpMessageClicked()
{
- HelpMessageDialog *help = new HelpMessageDialog(this);
+ HelpMessageDialog *help = new HelpMessageDialog(this, false);
help->setAttribute(Qt::WA_DeleteOnClose);
help->show();
}
diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp
index 403b03378f..9c9565be67 100644
--- a/src/qt/clientmodel.cpp
+++ b/src/qt/clientmodel.cpp
@@ -142,14 +142,6 @@ void ClientModel::updateAlert(const QString &hash, int status)
emit alertsChanged(getStatusBarWarnings());
}
-QString ClientModel::getNetworkName() const
-{
- QString netname(QString::fromStdString(Params().DataDir()));
- if(netname.isEmpty())
- netname = "main";
- return netname;
-}
-
bool ClientModel::inInitialBlockDownload() const
{
return IsInitialBlockDownload();
diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h
index 9c9a35b654..c7bd60bd41 100644
--- a/src/qt/clientmodel.h
+++ b/src/qt/clientmodel.h
@@ -56,8 +56,6 @@ public:
double getVerificationProgress() const;
QDateTime getLastBlockDate() const;
- //! Return network (main, testnet3, regtest)
- QString getNetworkName() const;
//! Return true if core is doing initial block download
bool inInitialBlockDownload() const;
//! Return true if core is importing blocks
diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp
index e27f1bff97..42d6da7d37 100644
--- a/src/qt/coincontroldialog.cpp
+++ b/src/qt/coincontroldialog.cpp
@@ -71,7 +71,7 @@ CoinControlDialog::CoinControlDialog(QWidget *parent) :
QAction *clipboardAfterFeeAction = new QAction(tr("Copy after fee"), this);
QAction *clipboardBytesAction = new QAction(tr("Copy bytes"), this);
QAction *clipboardPriorityAction = new QAction(tr("Copy priority"), this);
- QAction *clipboardLowOutputAction = new QAction(tr("Copy low output"), this);
+ QAction *clipboardLowOutputAction = new QAction(tr("Copy dust"), this);
QAction *clipboardChangeAction = new QAction(tr("Copy change"), this);
connect(clipboardQuantityAction, SIGNAL(triggered()), this, SLOT(clipboardQuantity()));
@@ -309,7 +309,7 @@ void CoinControlDialog::clipboardPriority()
GUIUtil::setClipboard(ui->labelCoinControlPriority->text());
}
-// copy label "Low output" to clipboard
+// copy label "Dust" to clipboard
void CoinControlDialog::clipboardLowOutput()
{
GUIUtil::setClipboard(ui->labelCoinControlLowOutput->text());
@@ -439,7 +439,6 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
// nPayAmount
qint64 nPayAmount = 0;
- bool fLowOutput = false;
bool fDust = false;
CTransaction txDummy;
foreach(const qint64 &amount, CoinControlDialog::payAmounts)
@@ -448,9 +447,6 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
if (amount > 0)
{
- if (amount < CENT)
- fLowOutput = true;
-
CTxOut txout(amount, (CScript)vector<unsigned char>(24, 0));
txDummy.vout.push_back(txout);
if (txout.IsDust(CTransaction::minRelayTxFee))
@@ -571,7 +567,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
QLabel *l7 = dialog->findChild<QLabel *>("labelCoinControlLowOutput");
QLabel *l8 = dialog->findChild<QLabel *>("labelCoinControlChange");
- // enable/disable "low output" and "change"
+ // enable/disable "dust" and "change"
dialog->findChild<QLabel *>("labelCoinControlLowOutputText")->setEnabled(nPayAmount > 0);
dialog->findChild<QLabel *>("labelCoinControlLowOutput") ->setEnabled(nPayAmount > 0);
dialog->findChild<QLabel *>("labelCoinControlChangeText") ->setEnabled(nPayAmount > 0);
@@ -584,14 +580,13 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
l4->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nAfterFee)); // After Fee
l5->setText(((nBytes > 0) ? "~" : "") + QString::number(nBytes)); // Bytes
l6->setText(sPriorityLabel); // Priority
- l7->setText((fLowOutput ? (fDust ? tr("Dust") : tr("yes")) : tr("no"))); // Low Output / Dust
+ l7->setText(fDust ? tr("yes") : tr("no")); // Dust
l8->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nChange)); // Change
// turn labels "red"
l5->setStyleSheet((nBytes >= 1000) ? "color:red;" : ""); // Bytes >= 1000
l6->setStyleSheet((dPriority > 0 && !AllowFree(dPriority)) ? "color:red;" : ""); // Priority < "medium"
- l7->setStyleSheet((fLowOutput) ? "color:red;" : ""); // Low Output = "yes"
- l8->setStyleSheet((nChange > 0 && nChange < CENT) ? "color:red;" : ""); // Change < 0.01BTC
+ l7->setStyleSheet((fDust) ? "color:red;" : ""); // Dust = "yes"
// tool tips
QString toolTip1 = tr("This label turns red, if the transaction size is greater than 1000 bytes.") + "<br /><br />";
@@ -602,21 +597,14 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
toolTip2 += tr("This label turns red, if the priority is smaller than \"medium\".") + "<br /><br />";
toolTip2 += tr("This means a fee of at least %1 per kB is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CTransaction::minTxFee.GetFeePerK()));
- QString toolTip3 = tr("This label turns red, if any recipient receives an amount smaller than %1.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CENT)) + "<br /><br />";
- toolTip3 += tr("This means a fee of at least %1 is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CTransaction::minTxFee.GetFeePerK())) + "<br /><br />";
- toolTip3 += tr("Amounts below 0.546 times the minimum relay fee are shown as dust.");
-
- QString toolTip4 = tr("This label turns red, if the change is smaller than %1.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CENT)) + "<br /><br />";
- toolTip4 += tr("This means a fee of at least %1 is required.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CTransaction::minTxFee.GetFeePerK()));
+ QString toolTip3 = tr("This label turns red, if any recipient receives an amount smaller than %1.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CTransaction::minRelayTxFee.GetFee(546)));
l5->setToolTip(toolTip1);
l6->setToolTip(toolTip2);
l7->setToolTip(toolTip3);
- l8->setToolTip(toolTip4);
dialog->findChild<QLabel *>("labelCoinControlBytesText") ->setToolTip(l5->toolTip());
dialog->findChild<QLabel *>("labelCoinControlPriorityText") ->setToolTip(l6->toolTip());
dialog->findChild<QLabel *>("labelCoinControlLowOutputText")->setToolTip(l7->toolTip());
- dialog->findChild<QLabel *>("labelCoinControlChangeText") ->setToolTip(l8->toolTip());
// Insufficient funds
QLabel *label = dialog->findChild<QLabel *>("labelCoinControlInsuffFunds");
diff --git a/src/qt/forms/aboutdialog.ui b/src/qt/forms/aboutdialog.ui
deleted file mode 100644
index fec63f737a..0000000000
--- a/src/qt/forms/aboutdialog.ui
+++ /dev/null
@@ -1,192 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>AboutDialog</class>
- <widget class="QDialog" name="AboutDialog">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>593</width>
- <height>319</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>About Bitcoin Core</string>
- </property>
- <layout class="QHBoxLayout" name="horizontalLayout_2">
- <item>
- <widget class="QLabel" name="label_4">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Ignored">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="pixmap">
- <pixmap resource="../bitcoin.qrc">:/images/about</pixmap>
- </property>
- </widget>
- </item>
- <item>
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <spacer name="verticalSpacer_2">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QLabel" name="label">
- <property name="cursor">
- <cursorShape>IBeamCursor</cursorShape>
- </property>
- <property name="text">
- <string>&lt;b&gt;Bitcoin Core&lt;/b&gt; version</string>
- </property>
- <property name="textInteractionFlags">
- <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="versionLabel">
- <property name="cursor">
- <cursorShape>IBeamCursor</cursorShape>
- </property>
- <property name="text">
- <string notr="true">0.3.666-beta</string>
- </property>
- <property name="textInteractionFlags">
- <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QLabel" name="copyrightLabel">
- <property name="cursor">
- <cursorShape>IBeamCursor</cursorShape>
- </property>
- <property name="text">
- <string notr="true">Copyright &amp;copy; 2009-YYYY The Bitcoin Core developers</string>
- </property>
- <property name="textFormat">
- <enum>Qt::RichText</enum>
- </property>
- <property name="textInteractionFlags">
- <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="label_2">
- <property name="cursor">
- <cursorShape>IBeamCursor</cursorShape>
- </property>
- <property name="text">
- <string>
-This is experimental software.
-
-Distributed under the MIT/X11 software license, see the accompanying file COPYING or &lt;a href=&quot;http://www.opensource.org/licenses/mit-license.php&quot;&gt;http://www.opensource.org/licenses/mit-license.php&lt;/a&gt;.
-
-This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (&lt;a href=&quot;https://www.openssl.org/&quot;&gt;https://www.openssl.org/&lt;/a&gt;) and cryptographic software written by Eric Young (&lt;a href=&quot;mailto:eay@cryptsoft.com&quot;&gt;eay@cryptsoft.com&lt;/a&gt;) and UPnP software written by Thomas Bernard.</string>
- </property>
- <property name="textFormat">
- <enum>Qt::RichText</enum>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- <property name="textInteractionFlags">
- <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Ok</set>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- <resources>
- <include location="../bitcoin.qrc"/>
- </resources>
- <connections>
- <connection>
- <sender>buttonBox</sender>
- <signal>accepted()</signal>
- <receiver>AboutDialog</receiver>
- <slot>accept()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>20</x>
- <y>20</y>
- </hint>
- <hint type="destinationlabel">
- <x>20</x>
- <y>20</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>buttonBox</sender>
- <signal>rejected()</signal>
- <receiver>AboutDialog</receiver>
- <slot>reject()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>20</x>
- <y>20</y>
- </hint>
- <hint type="destinationlabel">
- <x>20</x>
- <y>20</y>
- </hint>
- </hints>
- </connection>
- </connections>
-</ui>
diff --git a/src/qt/forms/coincontroldialog.ui b/src/qt/forms/coincontroldialog.ui
index cd1c0ffa18..67ea3a9d8c 100644
--- a/src/qt/forms/coincontroldialog.ui
+++ b/src/qt/forms/coincontroldialog.ui
@@ -225,7 +225,7 @@
</font>
</property>
<property name="text">
- <string>Low Output:</string>
+ <string>Dust:</string>
</property>
</widget>
</item>
diff --git a/src/qt/forms/helpmessagedialog.ui b/src/qt/forms/helpmessagedialog.ui
index f68fea7e64..d8ab27c238 100644
--- a/src/qt/forms/helpmessagedialog.ui
+++ b/src/qt/forms/helpmessagedialog.ui
@@ -16,7 +16,7 @@
</font>
</property>
<property name="windowTitle">
- <string>Bitcoin Core - Command-line options</string>
+ <string notr="true">Bitcoin Core - Command-line options</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
@@ -54,11 +54,6 @@
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="helpMessageLabel">
- <property name="font">
- <font>
- <family>Terminal</family>
- </font>
- </property>
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
</property>
diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui
index 0103842e02..0c5b8895aa 100644
--- a/src/qt/forms/optionsdialog.ui
+++ b/src/qt/forms/optionsdialog.ui
@@ -243,6 +243,16 @@
</widget>
</item>
<item>
+ <widget class="QCheckBox" name="allowIncoming">
+ <property name="toolTip">
+ <string>Accept connections from outside</string>
+ </property>
+ <property name="text">
+ <string>Allow incoming connections</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QCheckBox" name="connectSocks">
<property name="toolTip">
<string>Connect to the Bitcoin network through a SOCKS proxy.</string>
diff --git a/src/qt/forms/rpcconsole.ui b/src/qt/forms/rpcconsole.ui
index 1e574e8527..7158b65c2d 100644
--- a/src/qt/forms/rpcconsole.ui
+++ b/src/qt/forms/rpcconsole.ui
@@ -559,7 +559,7 @@
<item>
<widget class="QLabel" name="label_16">
<property name="text">
- <string>In:</string>
+ <string>Received</string>
</property>
</widget>
</item>
@@ -639,7 +639,7 @@
<item>
<widget class="QLabel" name="label_17">
<property name="text">
- <string>Out:</string>
+ <string>Sent</string>
</property>
</widget>
</item>
diff --git a/src/qt/forms/sendcoinsdialog.ui b/src/qt/forms/sendcoinsdialog.ui
index 4cb1670c79..a631b04670 100644
--- a/src/qt/forms/sendcoinsdialog.ui
+++ b/src/qt/forms/sendcoinsdialog.ui
@@ -417,7 +417,7 @@
</font>
</property>
<property name="text">
- <string>Low Output:</string>
+ <string>Dust:</string>
</property>
</widget>
</item>
diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp
index 1cbf5f8810..abfd4123e0 100644
--- a/src/qt/optionsdialog.cpp
+++ b/src/qt/optionsdialog.cpp
@@ -151,6 +151,7 @@ void OptionsDialog::setModel(OptionsModel *model)
/* Wallet */
connect(ui->spendZeroConfChange, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
/* Network */
+ connect(ui->allowIncoming, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
connect(ui->connectSocks, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
/* Display */
connect(ui->lang, SIGNAL(valueChanged()), this, SLOT(showRestartWarning()));
@@ -171,6 +172,7 @@ void OptionsDialog::setMapper()
/* Network */
mapper->addMapping(ui->mapPortUpnp, OptionsModel::MapPortUPnP);
+ mapper->addMapping(ui->allowIncoming, OptionsModel::Listen);
mapper->addMapping(ui->connectSocks, OptionsModel::ProxyUse);
mapper->addMapping(ui->proxyIp, OptionsModel::ProxyIP);
diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp
index f3a5f37bb3..4dafd9d2af 100644
--- a/src/qt/optionsmodel.cpp
+++ b/src/qt/optionsmodel.cpp
@@ -110,6 +110,11 @@ void OptionsModel::Init()
if (!SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()))
addOverriddenOption("-upnp");
+ if (!settings.contains("fListen"))
+ settings.setValue("fListen", DEFAULT_LISTEN);
+ if (!SoftSetBoolArg("-listen", settings.value("fListen").toBool()))
+ addOverriddenOption("-listen");
+
if (!settings.contains("fUseProxy"))
settings.setValue("fUseProxy", false);
if (!settings.contains("addrProxy"))
@@ -214,6 +219,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
return settings.value("nDatabaseCache");
case ThreadsScriptVerif:
return settings.value("nThreadsScriptVerif");
+ case Listen:
+ return settings.value("fListen");
default:
return QVariant();
}
@@ -339,6 +346,12 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
setRestartRequired(true);
}
break;
+ case Listen:
+ if (settings.value("fListen") != value) {
+ settings.setValue("fListen", value);
+ setRestartRequired(true);
+ }
+ break;
default:
break;
}
diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h
index f05e3e92de..2596682d07 100644
--- a/src/qt/optionsmodel.h
+++ b/src/qt/optionsmodel.h
@@ -42,6 +42,7 @@ public:
ThreadsScriptVerif, // int
DatabaseCache, // int
SpendZeroConfChange, // bool
+ Listen, // bool
OptionIDRowCount,
};
diff --git a/src/qt/paymentrequestplus.cpp b/src/qt/paymentrequestplus.cpp
index e369734a98..464f995eb6 100644
--- a/src/qt/paymentrequestplus.cpp
+++ b/src/qt/paymentrequestplus.cpp
@@ -17,6 +17,7 @@
#include <QDebug>
#include <QSslCertificate>
+using namespace std;
class SSLVerifyError : public std::runtime_error
{
diff --git a/src/qt/paymentrequestplus.h b/src/qt/paymentrequestplus.h
index 8c126b1fad..3c4861a4d4 100644
--- a/src/qt/paymentrequestplus.h
+++ b/src/qt/paymentrequestplus.h
@@ -24,7 +24,7 @@ public:
PaymentRequestPlus() { }
bool parse(const QByteArray& data);
- bool SerializeToString(string* output) const;
+ bool SerializeToString(std::string* output) const;
bool IsInitialized() const;
QString getPKIType() const;
diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp
index 6165731d22..49923a1afc 100644
--- a/src/qt/paymentserver.cpp
+++ b/src/qt/paymentserver.cpp
@@ -44,6 +44,7 @@
#include <QUrlQuery>
#endif
+using namespace std;
using namespace boost;
const int BITCOIN_IPC_CONNECT_TIMEOUT = 1000; // milliseconds
@@ -499,8 +500,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoins
const payments::PaymentDetails& details = request.getDetails();
// Payment request network matches client network?
- if ((details.network() == "main" && TestNet()) ||
- (details.network() == "test" && !TestNet()))
+ if (details.network() != Params().NetworkIDString())
{
emit message(tr("Payment request rejected"), tr("Payment request network doesn't match client network."),
CClientUIInterface::MSG_ERROR);
diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp
index 0d3e11f4ac..f7491f4a42 100644
--- a/src/qt/rpcconsole.cpp
+++ b/src/qt/rpcconsole.cpp
@@ -316,7 +316,7 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->buildDate->setText(model->formatBuildDate());
ui->startupTime->setText(model->formatClientStartupTime());
- ui->networkName->setText(model->getNetworkName());
+ ui->networkName->setText(QString::fromStdString(Params().NetworkIDString()));
}
}
@@ -415,8 +415,8 @@ void RPCConsole::on_lineEdit_returnPressed()
{
message(CMD_REQUEST, cmd);
emit cmdRequest(cmd);
- // Truncate history from current position
- history.erase(history.begin() + historyPtr, history.end());
+ // Remove command, if already in history
+ history.removeOne(cmd);
// Append command to history
history.append(cmd);
// Enforce maximum history size
diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp
index 23b8ef83e2..b7d74d7039 100644
--- a/src/qt/sendcoinsdialog.cpp
+++ b/src/qt/sendcoinsdialog.cpp
@@ -53,7 +53,7 @@ SendCoinsDialog::SendCoinsDialog(QWidget *parent) :
QAction *clipboardAfterFeeAction = new QAction(tr("Copy after fee"), this);
QAction *clipboardBytesAction = new QAction(tr("Copy bytes"), this);
QAction *clipboardPriorityAction = new QAction(tr("Copy priority"), this);
- QAction *clipboardLowOutputAction = new QAction(tr("Copy low output"), this);
+ QAction *clipboardLowOutputAction = new QAction(tr("Copy dust"), this);
QAction *clipboardChangeAction = new QAction(tr("Copy change"), this);
connect(clipboardQuantityAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardQuantity()));
connect(clipboardAmountAction, SIGNAL(triggered()), this, SLOT(coinControlClipboardAmount()));
@@ -478,7 +478,7 @@ void SendCoinsDialog::coinControlClipboardPriority()
GUIUtil::setClipboard(ui->labelCoinControlPriority->text());
}
-// Coin Control: copy label "Low output" to clipboard
+// Coin Control: copy label "Dust" to clipboard
void SendCoinsDialog::coinControlClipboardLowOutput()
{
GUIUtil::setClipboard(ui->labelCoinControlLowOutput->text());
diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp
index 0cfcb048c8..61da3373fd 100644
--- a/src/qt/transactiondesc.cpp
+++ b/src/qt/transactiondesc.cpp
@@ -18,6 +18,8 @@
#include <stdint.h>
#include <string>
+using namespace std;
+
QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx)
{
AssertLockHeld(cs_main);
diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp
index 01b710e876..eb647d0170 100644
--- a/src/qt/utilitydialog.cpp
+++ b/src/qt/utilitydialog.cpp
@@ -4,7 +4,6 @@
#include "utilitydialog.h"
-#include "ui_aboutdialog.h"
#include "ui_helpmessagedialog.h"
#include "bitcoingui.h"
@@ -16,72 +15,64 @@
#include "util.h"
#include <QLabel>
+#include <QRegExp>
#include <QVBoxLayout>
-/** "About" dialog box */
-AboutDialog::AboutDialog(QWidget *parent) :
+/** "Help message" or "About" dialog box */
+HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
QDialog(parent),
- ui(new Ui::AboutDialog)
+ ui(new Ui::HelpMessageDialog)
{
ui->setupUi(this);
+ GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), this);
- // Set current copyright year
- ui->copyrightLabel->setText(tr("Copyright") + QString(" &copy; 2009-%1 ").arg(COPYRIGHT_YEAR) + tr("The Bitcoin Core developers"));
-}
-
-void AboutDialog::setModel(ClientModel *model)
-{
- if(model)
- {
- QString version = model->formatFullVersion();
- /* On x86 add a bit specifier to the version so that users can distinguish between
- * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious.
- */
+ QString version = tr("Bitcoin Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
+ /* On x86 add a bit specifier to the version so that users can distinguish between
+ * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious.
+ */
#if defined(__x86_64__)
- version += " " + tr("(%1-bit)").arg(64);
+ version += " " + tr("(%1-bit)").arg(64);
#elif defined(__i386__ )
- version += " " + tr("(%1-bit)").arg(32);
+ version += " " + tr("(%1-bit)").arg(32);
#endif
- ui->versionLabel->setText(version);
- }
-}
-
-AboutDialog::~AboutDialog()
-{
- delete ui;
-}
-
-void AboutDialog::on_buttonBox_accepted()
-{
- close();
-}
-
-/** "Help message" dialog box */
-HelpMessageDialog::HelpMessageDialog(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::HelpMessageDialog)
-{
- ui->setupUi(this);
- GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), this);
-
- header = tr("Bitcoin Core") + " " + tr("version") + " " +
- QString::fromStdString(FormatFullVersion()) + "\n\n" +
- tr("Usage:") + "\n" +
- " bitcoin-qt [" + tr("command-line options") + "] " + "\n";
-
- coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT));
-
- uiOptions = tr("UI options") + ":\n" +
- " -choosedatadir " + tr("Choose data directory on startup (default: 0)") + "\n" +
- " -lang=<lang> " + tr("Set language, for example \"de_DE\" (default: system locale)") + "\n" +
- " -min " + tr("Start minimized") + "\n" +
- " -rootcertificates=<file> " + tr("Set SSL root certificates for payment request (default: -system-)") + "\n" +
- " -splash " + tr("Show splash screen on startup (default: 1)");
- ui->helpMessageLabel->setFont(GUIUtil::bitcoinAddressFont());
-
- // Set help message text
- ui->helpMessageLabel->setText(header + "\n" + coreOptions + "\n" + uiOptions);
+ if (about)
+ {
+ setWindowTitle(tr("About Bitcoin Core"));
+
+ /// HTML-format the license message from the core
+ QString licenseInfo = QString::fromStdString(LicenseInfo());
+ QString licenseInfoHTML = licenseInfo;
+ // Make URLs clickable
+ QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
+ uri.setMinimal(true); // use non-greedy matching
+ licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
+ // Replace newlines with HTML breaks
+ licenseInfoHTML.replace("\n\n", "<br><br>");
+
+ ui->helpMessageLabel->setTextFormat(Qt::RichText);
+ ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ text = version + "\n" + licenseInfo;
+ ui->helpMessageLabel->setText(version + "<br><br>" + licenseInfoHTML);
+ ui->helpMessageLabel->setWordWrap(true);
+ } else {
+ setWindowTitle(tr("Command-line options"));
+ QString header = tr("Usage:") + "\n" +
+ " bitcoin-qt [" + tr("command-line options") + "] " + "\n";
+
+ QString coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT));
+
+ QString uiOptions = tr("UI options") + ":\n" +
+ " -choosedatadir " + tr("Choose data directory on startup (default: 0)") + "\n" +
+ " -lang=<lang> " + tr("Set language, for example \"de_DE\" (default: system locale)") + "\n" +
+ " -min " + tr("Start minimized") + "\n" +
+ " -rootcertificates=<file> " + tr("Set SSL root certificates for payment request (default: -system-)") + "\n" +
+ " -splash " + tr("Show splash screen on startup (default: 1)");
+
+ ui->helpMessageLabel->setFont(GUIUtil::bitcoinAddressFont());
+ text = version + "\n" + header + "\n" + coreOptions + "\n" + uiOptions;
+ ui->helpMessageLabel->setText(text);
+ }
}
HelpMessageDialog::~HelpMessageDialog()
@@ -93,18 +84,17 @@ HelpMessageDialog::~HelpMessageDialog()
void HelpMessageDialog::printToConsole()
{
// On other operating systems, the expected action is to print the message to the console.
- QString strUsage = header + "\n" + coreOptions + "\n" + uiOptions + "\n";
- fprintf(stdout, "%s", strUsage.toStdString().c_str());
+ fprintf(stdout, "%s\n", qPrintable(text));
}
void HelpMessageDialog::showOrPrint()
{
#if defined(WIN32)
- // On Windows, show a message box, as there is no stderr/stdout in windowed applications
- exec();
+ // On Windows, show a message box, as there is no stderr/stdout in windowed applications
+ exec();
#else
- // On other operating systems, print help text to console
- printToConsole();
+ // On other operating systems, print help text to console
+ printToConsole();
#endif
}
diff --git a/src/qt/utilitydialog.h b/src/qt/utilitydialog.h
index 874daf6a7f..154bb70b8b 100644
--- a/src/qt/utilitydialog.h
+++ b/src/qt/utilitydialog.h
@@ -12,35 +12,16 @@ class BitcoinGUI;
class ClientModel;
namespace Ui {
- class AboutDialog;
class HelpMessageDialog;
}
-/** "About" dialog box */
-class AboutDialog : public QDialog
-{
- Q_OBJECT
-
-public:
- explicit AboutDialog(QWidget *parent);
- ~AboutDialog();
-
- void setModel(ClientModel *model);
-
-private:
- Ui::AboutDialog *ui;
-
-private slots:
- void on_buttonBox_accepted();
-};
-
/** "Help message" dialog box */
class HelpMessageDialog : public QDialog
{
Q_OBJECT
public:
- explicit HelpMessageDialog(QWidget *parent);
+ explicit HelpMessageDialog(QWidget *parent, bool about);
~HelpMessageDialog();
void printToConsole();
@@ -48,9 +29,7 @@ public:
private:
Ui::HelpMessageDialog *ui;
- QString header;
- QString coreOptions;
- QString uiOptions;
+ QString text;
private slots:
void on_okButton_accepted();
diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
index 87ff3db584..2f633a26c8 100644
--- a/src/qt/walletmodel.cpp
+++ b/src/qt/walletmodel.cpp
@@ -24,6 +24,8 @@
#include <QSet>
#include <QTimer>
+using namespace std;
+
WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent) :
QObject(parent), wallet(wallet), optionsModel(optionsModel), addressTableModel(0),
transactionTableModel(0),
diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp
index ff5057b526..580c6bd5ba 100644
--- a/src/rpcblockchain.cpp
+++ b/src/rpcblockchain.cpp
@@ -3,10 +3,10 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include "rpcserver.h"
+#include "checkpoints.h"
#include "main.h"
+#include "rpcserver.h"
#include "sync.h"
-#include "checkpoints.h"
#include <stdint.h>
@@ -438,7 +438,7 @@ Value getblockchaininfo(const Array& params, bool fHelp)
"Returns an object containing various state info regarding block chain processing.\n"
"\nResult:\n"
"{\n"
- " \"chain\": \"xxxx\", (string) current chain (main, testnet3, regtest)\n"
+ " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n"
" \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
" \"bestblockhash\": \"...\", (string) the hash of the currently best block\n"
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
@@ -450,18 +450,12 @@ Value getblockchaininfo(const Array& params, bool fHelp)
+ HelpExampleRpc("getblockchaininfo", "")
);
- proxyType proxy;
- GetProxy(NET_IPV4, proxy);
-
Object obj;
- std::string chain = Params().DataDir();
- if(chain.empty())
- chain = "main";
- obj.push_back(Pair("chain", chain));
- obj.push_back(Pair("blocks", (int)chainActive.Height()));
- obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()));
- obj.push_back(Pair("difficulty", (double)GetDifficulty()));
- obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(chainActive.Tip())));
- obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
+ obj.push_back(Pair("chain", Params().NetworkIDString()));
+ obj.push_back(Pair("blocks", (int)chainActive.Height()));
+ obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()));
+ obj.push_back(Pair("difficulty", (double)GetDifficulty()));
+ obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(chainActive.Tip())));
+ obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
return obj;
}
diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp
index b89a95ad11..3a06e33016 100644
--- a/src/rpcclient.cpp
+++ b/src/rpcclient.cpp
@@ -12,86 +12,9 @@
#include <stdint.h>
-#include <boost/algorithm/string.hpp>
-#include <boost/asio.hpp>
-#include <boost/asio/ssl.hpp>
-#include <boost/bind.hpp>
-#include <boost/filesystem.hpp>
-#include <boost/foreach.hpp>
-#include <boost/iostreams/concepts.hpp>
-#include <boost/iostreams/stream.hpp>
-#include <boost/shared_ptr.hpp>
-#include "json/json_spirit_writer_template.h"
-
using namespace std;
-using namespace boost;
-using namespace boost::asio;
using namespace json_spirit;
-Object CallRPC(const string& strMethod, const Array& params)
-{
- if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "")
- throw runtime_error(strprintf(
- _("You must set rpcpassword=<password> in the configuration file:\n%s\n"
- "If the file does not exist, create it with owner-readable-only file permissions."),
- GetConfigFile().string().c_str()));
-
- // Connect to localhost
- bool fUseSSL = GetBoolArg("-rpcssl", false);
- asio::io_service io_service;
- ssl::context context(io_service, ssl::context::sslv23);
- context.set_options(ssl::context::no_sslv2);
- asio::ssl::stream<asio::ip::tcp::socket> sslStream(io_service, context);
- SSLIOStreamDevice<asio::ip::tcp> d(sslStream, fUseSSL);
- iostreams::stream< SSLIOStreamDevice<asio::ip::tcp> > stream(d);
-
- bool fWait = GetBoolArg("-rpcwait", false); // -rpcwait means try until server has started
- do {
- bool fConnected = d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(Params().RPCPort())));
- if (fConnected) break;
- if (fWait)
- MilliSleep(1000);
- else
- throw runtime_error("couldn't connect to server");
- } while (fWait);
-
- // HTTP basic authentication
- string strUserPass64 = EncodeBase64(mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]);
- map<string, string> mapRequestHeaders;
- mapRequestHeaders["Authorization"] = string("Basic ") + strUserPass64;
-
- // Send request
- string strRequest = JSONRPCRequest(strMethod, params, 1);
- string strPost = HTTPPost(strRequest, mapRequestHeaders);
- stream << strPost << std::flush;
-
- // Receive HTTP reply status
- int nProto = 0;
- int nStatus = ReadHTTPStatus(stream, nProto);
-
- // Receive HTTP reply message headers and body
- map<string, string> mapHeaders;
- string strReply;
- ReadHTTPMessage(stream, mapHeaders, strReply, nProto);
-
- if (nStatus == HTTP_UNAUTHORIZED)
- throw runtime_error("incorrect rpcuser or rpcpassword (authorization failed)");
- else if (nStatus >= 400 && nStatus != HTTP_BAD_REQUEST && nStatus != HTTP_NOT_FOUND && nStatus != HTTP_INTERNAL_SERVER_ERROR)
- throw runtime_error(strprintf("server returned HTTP error %d", nStatus));
- else if (strReply.empty())
- throw runtime_error("no response from server");
-
- // Parse reply
- Value valReply;
- if (!read_string(strReply, valReply))
- throw runtime_error("couldn't parse reply from server");
- const Object& reply = valReply.get_obj();
- if (reply.empty())
- throw runtime_error("expected reply to have result, error and id properties");
-
- return reply;
-}
-
template<typename T>
void ConvertTo(Value& value, bool fAllowNull=false)
{
@@ -182,101 +105,3 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
return params;
}
-int CommandLineRPC(int argc, char *argv[])
-{
- string strPrint;
- int nRet = 0;
- try
- {
- // Skip switches
- while (argc > 1 && IsSwitchChar(argv[1][0]))
- {
- argc--;
- argv++;
- }
-
- // Method
- if (argc < 2)
- throw runtime_error("too few parameters");
- string strMethod = argv[1];
-
- // Parameters default to strings
- std::vector<std::string> strParams(&argv[2], &argv[argc]);
- Array params = RPCConvertValues(strMethod, strParams);
-
- // Execute
- Object reply = CallRPC(strMethod, params);
-
- // Parse reply
- const Value& result = find_value(reply, "result");
- const Value& error = find_value(reply, "error");
-
- if (error.type() != null_type)
- {
- // Error
- strPrint = "error: " + write_string(error, false);
- int code = find_value(error.get_obj(), "code").get_int();
- nRet = abs(code);
- }
- else
- {
- // Result
- if (result.type() == null_type)
- strPrint = "";
- else if (result.type() == str_type)
- strPrint = result.get_str();
- else
- strPrint = write_string(result, true);
- }
- }
- catch (boost::thread_interrupted) {
- throw;
- }
- catch (std::exception& e) {
- strPrint = string("error: ") + e.what();
- nRet = abs(RPC_MISC_ERROR);
- }
- catch (...) {
- PrintExceptionContinue(NULL, "CommandLineRPC()");
- throw;
- }
-
- if (strPrint != "")
- {
- fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str());
- }
- return nRet;
-}
-
-std::string HelpMessageCli(bool mainProgram)
-{
- string strUsage;
- if(mainProgram)
- {
- 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";
- 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";
- } else {
- strUsage += _("RPC client options:") + "\n";
- }
-
- strUsage += " -rpcconnect=<ip> " + _("Send commands to node running on <ip> (default: 127.0.0.1)") + "\n";
- strUsage += " -rpcport=<port> " + _("Connect to JSON-RPC on <port> (default: 8332 or testnet: 18332)") + "\n";
- strUsage += " -rpcwait " + _("Wait for RPC server to start") + "\n";
-
- if(mainProgram)
- {
- strUsage += " -rpcuser=<user> " + _("Username for JSON-RPC connections") + "\n";
- strUsage += " -rpcpassword=<pw> " + _("Password for JSON-RPC connections") + "\n";
-
- strUsage += "\n" + _("SSL options: (see the Bitcoin Wiki for SSL setup instructions)") + "\n";
- strUsage += " -rpcssl " + _("Use OpenSSL (https) for JSON-RPC connections") + "\n";
- }
-
- return strUsage;
-}
-
diff --git a/src/rpcclient.h b/src/rpcclient.h
index e101d22ec5..840890e34b 100644
--- a/src/rpcclient.h
+++ b/src/rpcclient.h
@@ -10,16 +10,6 @@
#include "json/json_spirit_utils.h"
#include "json/json_spirit_writer_template.h"
-int CommandLineRPC(int argc, char *argv[]);
-
json_spirit::Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams);
-/** Show help message for bitcoin-cli.
- * The mainProgram argument is used to determine whether to show this message as main program
- * (and include some common options) or as sub-header of another help message.
- *
- * @note the argument can be removed once bitcoin-cli functionality is removed from bitcoind
- */
-std::string HelpMessageCli(bool mainProgram);
-
#endif
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp
index dd148c6af1..57a51c0fde 100644
--- a/src/rpcmining.cpp
+++ b/src/rpcmining.cpp
@@ -13,9 +13,11 @@
#include "db.h"
#include "wallet.h"
#endif
+
#include <stdint.h>
#include <boost/assign/list_of.hpp>
+
#include "json/json_spirit_utils.h"
#include "json/json_spirit_value.h"
@@ -175,7 +177,7 @@ Value setgenerate(const Array& params, bool fHelp)
}
// -regtest mode: don't return until nGenProcLimit blocks are generated
- if (fGenerate && Params().NetworkID() == CChainParams::REGTEST)
+ if (fGenerate && Params().MineBlocksOnDemand())
{
int nHeightStart = 0;
int nHeightEnd = 0;
@@ -251,6 +253,7 @@ Value getmininginfo(const Array& params, bool fHelp)
" \"hashespersec\": n (numeric) The hashes per second of the generation, or 0 if no generation.\n"
" \"pooledtx\": n (numeric) The size of the mem pool\n"
" \"testnet\": true|false (boolean) If using testnet or not\n"
+ " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getmininginfo", "")
@@ -266,7 +269,8 @@ Value getmininginfo(const Array& params, bool fHelp)
obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1)));
obj.push_back(Pair("networkhashps", getnetworkhashps(params, false)));
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
- obj.push_back(Pair("testnet", TestNet()));
+ obj.push_back(Pair("testnet", Params().NetworkID() == CChainParams::TESTNET));
+ obj.push_back(Pair("chain", Params().NetworkIDString()));
#ifdef ENABLE_WALLET
obj.push_back(Pair("generate", getgenerate(params, false)));
obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp
index 9802445fcb..5181aa23d8 100644
--- a/src/rpcmisc.cpp
+++ b/src/rpcmisc.cpp
@@ -73,7 +73,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("connections", (int)vNodes.size()));
obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string())));
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
- obj.push_back(Pair("testnet", TestNet()));
+ obj.push_back(Pair("testnet", Params().NetworkID() == CChainParams::TESTNET));
#ifdef ENABLE_WALLET
if (pwalletMain) {
obj.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime()));
diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp
index 72a7fe83ef..56b5f2de0b 100644
--- a/src/rpcserver.cpp
+++ b/src/rpcserver.cpp
@@ -254,7 +254,7 @@ static const CRPCCommand vRPCCommands[] =
{ "getblocktemplate", &getblocktemplate, true, false, false },
{ "getmininginfo", &getmininginfo, true, false, false },
{ "getnetworkhashps", &getnetworkhashps, true, false, false },
- { "submitblock", &submitblock, false, false, false },
+ { "submitblock", &submitblock, false, true, false },
/* Raw transactions */
{ "createrawtransaction", &createrawtransaction, false, false, false },
@@ -642,7 +642,6 @@ void StartRPCThreads()
LogPrintf("Binding RPC on address %s port %i (IPv4+IPv6 bind any: %i)\n", bindAddress.to_string(), endpoint.port(), bBindAny);
boost::system::error_code v6_only_error;
boost::shared_ptr<ip::tcp::acceptor> acceptor(new ip::tcp::acceptor(*rpc_io_service));
- rpc_acceptors.push_back(acceptor);
try {
acceptor->open(endpoint.protocol());
@@ -658,6 +657,7 @@ void StartRPCThreads()
RPCListen(acceptor, *rpc_ssl_context, fUseSSL);
fListening = true;
+ rpc_acceptors.push_back(acceptor);
// If dual IPv6/IPv4 bind succesful, skip binding to IPv4 separately
if(bBindAny && bindAddress == asio::ip::address_v6::any() && !v6_only_error)
break;
@@ -700,11 +700,20 @@ void StopRPCThreads()
// First, cancel all timers and acceptors
// This is not done automatically by ->stop(), and in some cases the destructor of
// asio::io_service can hang if this is skipped.
+ boost::system::error_code ec;
BOOST_FOREACH(const boost::shared_ptr<ip::tcp::acceptor> &acceptor, rpc_acceptors)
- acceptor->cancel();
+ {
+ acceptor->cancel(ec);
+ if (ec)
+ LogPrintf("%s: Warning: %s when cancelling acceptor", __func__, ec.message());
+ }
rpc_acceptors.clear();
BOOST_FOREACH(const PAIRTYPE(std::string, boost::shared_ptr<deadline_timer>) &timer, deadlineTimers)
- timer.second->cancel();
+ {
+ timer.second->cancel(ec);
+ if (ec)
+ LogPrintf("%s: Warning: %s when cancelling timer", __func__, ec.message());
+ }
deadlineTimers.clear();
rpc_io_service->stop();
diff --git a/src/script.cpp b/src/script.cpp
index 381e84d0b7..11cdfef950 100644
--- a/src/script.cpp
+++ b/src/script.cpp
@@ -838,10 +838,6 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
valtype& vchSig = stacktop(-2);
valtype& vchPubKey = stacktop(-1);
- ////// debug print
- //PrintHex(vchSig.begin(), vchSig.end(), "sig: %s\n");
- //PrintHex(vchPubKey.begin(), vchPubKey.end(), "pubkey: %s\n");
-
// Subset of script starting at the most recent codeseparator
CScript scriptCode(pbegincodehash, pend);
diff --git a/src/script.h b/src/script.h
index aed2b7a6ad..a282e7dc04 100644
--- a/src/script.h
+++ b/src/script.h
@@ -691,12 +691,6 @@ public:
void SetDestination(const CTxDestination& address);
void SetMultisig(int nRequired, const std::vector<CPubKey>& keys);
-
- void PrintHex() const
- {
- LogPrintf("CScript(%s)\n", HexStr(begin(), end(), true).c_str());
- }
-
std::string ToString() const
{
std::string str;
@@ -720,11 +714,6 @@ public:
return str;
}
- void print() const
- {
- LogPrintf("%s\n", ToString());
- }
-
CScriptID GetID() const
{
return CScriptID(Hash160(*this));
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
index 0e53a57593..0b071361d8 100644
--- a/src/test/util_tests.cpp
+++ b/src/test/util_tests.cpp
@@ -351,4 +351,15 @@ BOOST_AUTO_TEST_CASE(test_ParseInt32)
BOOST_CHECK(!ParseInt32("32482348723847471234", NULL));
}
+BOOST_AUTO_TEST_CASE(test_FormatParagraph)
+{
+ BOOST_CHECK_EQUAL(FormatParagraph("", 79, 0), "");
+ BOOST_CHECK_EQUAL(FormatParagraph("test", 79, 0), "test");
+ BOOST_CHECK_EQUAL(FormatParagraph(" test", 79, 0), "test");
+ BOOST_CHECK_EQUAL(FormatParagraph("test test", 79, 0), "test test");
+ BOOST_CHECK_EQUAL(FormatParagraph("test test", 4, 0), "test\ntest");
+ BOOST_CHECK_EQUAL(FormatParagraph("testerde test ", 4, 0), "testerde\ntest");
+ BOOST_CHECK_EQUAL(FormatParagraph("test test", 4, 4), "test\n test");
+}
+
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/util.cpp b/src/util.cpp
index d106b03230..30590912ff 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -460,6 +460,7 @@ void ParseParameters(int argc, const char* const argv[])
{
mapArgs.clear();
mapMultiArgs.clear();
+
for (int i = 1; i < argc; i++)
{
std::string str(argv[i]);
@@ -475,9 +476,15 @@ void ParseParameters(int argc, const char* const argv[])
if (boost::algorithm::starts_with(str, "/"))
str = "-" + str.substr(1);
#endif
+
if (str[0] != '-')
break;
+ // Interpret --foo as -foo.
+ // If both --foo and -foo are set, the last takes effect.
+ if (str.length() > 1 && str[1] == '-')
+ str = str.substr(1);
+
mapArgs[str] = strValue;
mapMultiArgs[str].push_back(strValue);
}
@@ -485,19 +492,8 @@ void ParseParameters(int argc, const char* const argv[])
// New 0.6 features:
BOOST_FOREACH(const PAIRTYPE(string,string)& entry, mapArgs)
{
- string name = entry.first;
-
- // interpret --foo as -foo (as long as both are not set)
- if (name.find("--") == 0)
- {
- std::string singleDash(name.begin()+1, name.end());
- if (mapArgs.count(singleDash) == 0)
- mapArgs[singleDash] = entry.second;
- name = singleDash;
- }
-
// interpret -nofoo as -foo=0 (and -nofoo=0 as -foo=1) as long as -foo not set
- InterpretNegativeSetting(name, mapArgs);
+ InterpretNegativeSetting(entry.first, mapArgs);
}
}
@@ -962,13 +958,15 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)
void ClearDatadirCache()
{
std::fill(&pathCached[0], &pathCached[CChainParams::MAX_NETWORK_TYPES+1],
- boost::filesystem::path());
+ boost::filesystem::path());
}
boost::filesystem::path GetConfigFile()
{
boost::filesystem::path pathConfigFile(GetArg("-conf", "bitcoin.conf"));
- if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir(false) / pathConfigFile;
+ if (!pathConfigFile.is_complete())
+ pathConfigFile = GetDataDir(false) / pathConfigFile;
+
return pathConfigFile;
}
@@ -1028,9 +1026,9 @@ bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
#endif /* WIN32 */
}
-
-// Ignores exceptions thrown by boost's create_directory if the requested directory exists.
-// Specifically handles case where path p exists, but it wasn't possible for the user to write to the parent directory.
+// Ignores exceptions thrown by Boost's create_directory if the requested directory exists.
+// Specifically handles case where path p exists, but it wasn't possible for the user to
+// write to the parent directory.
bool TryCreateDirectory(const boost::filesystem::path& p)
{
try
@@ -1381,19 +1379,19 @@ bool ParseInt32(const std::string& str, int32_t *out)
void SetupEnvironment()
{
- #ifndef WIN32
+#ifndef WIN32
try
{
- #if BOOST_FILESYSTEM_VERSION == 3
+#if BOOST_FILESYSTEM_VERSION == 3
boost::filesystem::path::codecvt(); // Raises runtime error if current locale is invalid
- #else // boost filesystem v2
+#else // boost filesystem v2
std::locale(); // Raises runtime error if current locale is invalid
- #endif
+#endif
} catch(std::runtime_error &e)
{
setenv("LC_ALL", "C", 1); // Force C locale
}
- #endif
+#endif
}
std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime)
@@ -1405,3 +1403,38 @@ std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime)
ss << boost::posix_time::from_time_t(nTime);
return ss.str();
}
+
+std::string FormatParagraph(const std::string in, size_t width, size_t indent)
+{
+ std::stringstream out;
+ size_t col = 0;
+ size_t ptr = 0;
+ while(ptr < in.size())
+ {
+ // Find beginning of next word
+ ptr = in.find_first_not_of(' ', ptr);
+ if (ptr == std::string::npos)
+ break;
+ // Find end of next word
+ size_t endword = in.find_first_of(' ', ptr);
+ if (endword == std::string::npos)
+ endword = in.size();
+ // Add newline and indentation if this wraps over the allowed width
+ if (col > 0)
+ {
+ if ((col + endword - ptr) > width)
+ {
+ out << '\n';
+ for(size_t i=0; i<indent; ++i)
+ out << ' ';
+ col = 0;
+ } else
+ out << ' ';
+ }
+ // Append word
+ out << in.substr(ptr, endword - ptr);
+ col += endword - ptr;
+ ptr = endword;
+ }
+ return out.str();
+}
diff --git a/src/util.h b/src/util.h
index b09f9bb15e..da1810a3d3 100644
--- a/src/util.h
+++ b/src/util.h
@@ -286,16 +286,10 @@ inline std::string HexStr(const T& vch, bool fSpaces=false)
return HexStr(vch.begin(), vch.end(), fSpaces);
}
-template<typename T>
-void PrintHex(const T pbegin, const T pend, const char* pszFormat="%s", bool fSpaces=true)
-{
- LogPrintf(pszFormat, HexStr(pbegin, pend, fSpaces).c_str());
-}
-
-inline void PrintHex(const std::vector<unsigned char>& vch, const char* pszFormat="%s", bool fSpaces=true)
-{
- LogPrintf(pszFormat, HexStr(vch, fSpaces).c_str());
-}
+/** Format a paragraph of text to a fixed width, adding spaces for
+ * indentation to any added line.
+ */
+std::string FormatParagraph(const std::string in, size_t width=79, size_t indent=0);
inline int64_t GetPerformanceCounter()
{
diff --git a/src/version.cpp b/src/version.cpp
index 51e34aa9c9..d86caa3ac2 100644
--- a/src/version.cpp
+++ b/src/version.cpp
@@ -12,7 +12,7 @@
const std::string CLIENT_NAME("Satoshi");
// Client version number
-#define CLIENT_VERSION_SUFFIX "-beta"
+#define CLIENT_VERSION_SUFFIX ""
// The following part of the code determines the CLIENT_BUILD variable.
diff --git a/src/wallet.cpp b/src/wallet.cpp
index ef0b442e1a..400c966a95 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -128,6 +128,22 @@ bool CWallet::AddCScript(const CScript& redeemScript)
return CWalletDB(strWalletFile).WriteCScript(Hash160(redeemScript), redeemScript);
}
+bool CWallet::LoadCScript(const CScript& redeemScript)
+{
+ /* A sanity check was added in pull #3843 to avoid adding redeemScripts
+ * that never can be redeemed. However, old wallets may still contain
+ * these. Do not add them to the wallet and warn. */
+ if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)
+ {
+ std::string strAddr = CBitcoinAddress(redeemScript.GetID()).ToString();
+ LogPrintf("%s: Warning: This wallet contains a redeemScript of size %i which exceeds maximum size %i thus can never be redeemed. Do not use address %s.\n",
+ __func__, redeemScript.size(), MAX_SCRIPT_ELEMENT_SIZE, strAddr);
+ return true;
+ }
+
+ return CCryptoKeyStore::AddCScript(redeemScript);
+}
+
bool CWallet::Unlock(const SecureString& strWalletPassphrase)
{
CCrypter crypter;
diff --git a/src/wallet.h b/src/wallet.h
index 274c31157c..7df656fc25 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -211,7 +211,7 @@ public:
// Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
bool AddCScript(const CScript& redeemScript);
- bool LoadCScript(const CScript& redeemScript) { return CCryptoKeyStore::AddCScript(redeemScript); }
+ bool LoadCScript(const CScript& redeemScript);
/// Adds a destination data tuple to the store, and saves it to disk
bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value);