aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/debian/bitcoin-qt.desktop4
-rw-r--r--contrib/debian/changelog7
-rw-r--r--qa/rpc-tests/util.sh6
-rwxr-xr-xqa/rpc-tests/wallet.sh25
-rw-r--r--src/Makefile.am1
-rw-r--r--src/addrman.cpp8
-rw-r--r--src/chainparams.cpp1
-rw-r--r--src/init.cpp21
-rw-r--r--src/main.cpp3
-rw-r--r--src/main.h3
-rw-r--r--src/miner.cpp3
-rw-r--r--src/net.cpp1
-rw-r--r--src/qt/bitcoin.cpp10
-rw-r--r--src/qt/bitcoingui.cpp10
-rw-r--r--src/qt/clientmodel.cpp7
-rw-r--r--src/qt/clientmodel.h4
-rw-r--r--src/qt/coincontroldialog.cpp12
-rw-r--r--src/qt/forms/rpcconsole.ui24
-rw-r--r--src/qt/optionsmodel.cpp1
-rw-r--r--src/qt/rpcconsole.cpp2
-rw-r--r--src/qt/sendcoinsdialog.cpp57
-rw-r--r--src/qt/sendcoinsentry.cpp7
-rw-r--r--src/qt/splashscreen.cpp7
-rw-r--r--src/qt/splashscreen.h2
-rw-r--r--src/rpcblockchain.cpp24
-rw-r--r--src/rpcdump.cpp2
-rw-r--r--src/rpcmining.cpp10
-rw-r--r--src/rpcmisc.cpp326
-rw-r--r--src/rpcnet.cpp62
-rw-r--r--src/rpcserver.cpp9
-rw-r--r--src/rpcserver.h1
-rw-r--r--src/rpcwallet.cpp268
-rw-r--r--src/test/Makefile.am2
-rw-r--r--src/test/miner_tests.cpp1
-rw-r--r--src/test/test_bitcoin.cpp4
-rw-r--r--src/test/uint160_tests.cpp20
-rw-r--r--src/test/uint256_tests.cpp634
-rw-r--r--src/txdb.cpp12
-rw-r--r--src/ui_interface.h2
-rw-r--r--src/uint256.h157
-rw-r--r--src/util.cpp27
-rw-r--r--src/util.h2
-rw-r--r--src/wallet.cpp2
-rw-r--r--src/wallet.h3
44 files changed, 1151 insertions, 643 deletions
diff --git a/contrib/debian/bitcoin-qt.desktop b/contrib/debian/bitcoin-qt.desktop
index 82bc80a734..61e1aca6ad 100644
--- a/contrib/debian/bitcoin-qt.desktop
+++ b/contrib/debian/bitcoin-qt.desktop
@@ -4,9 +4,9 @@ Name=Bitcoin
Comment=Bitcoin P2P Cryptocurrency
Comment[fr]=Bitcoin, monnaie virtuelle cryptographique pair à pair
Comment[tr]=Bitcoin, eşten eşe kriptografik sanal para birimi
-Exec=/usr/bin/bitcoin-qt %u
+Exec=bitcoin-qt %u
Terminal=false
Type=Application
-Icon=/usr/share/pixmaps/bitcoin128.png
+Icon=bitcoin128
MimeType=x-scheme-handler/bitcoin;
Categories=Office;Finance;
diff --git a/contrib/debian/changelog b/contrib/debian/changelog
index bd6b42dc51..95b9ad31a3 100644
--- a/contrib/debian/changelog
+++ b/contrib/debian/changelog
@@ -1,3 +1,10 @@
+bitcoin (0.8.6-precise1) precise; urgency=medium
+
+ * New upstream release.
+ * Make .desktop paths non-fixed (suggested by prusnak@github)
+
+ -- Matt Corallo <matt@bluematt.me> Fri, 13 Dec 2013 13:31:00 -0400
+
bitcoin (0.8.5-precise1) precise; urgency=medium
* New upstream release.
diff --git a/qa/rpc-tests/util.sh b/qa/rpc-tests/util.sh
index dc2a319970..e4e3953748 100644
--- a/qa/rpc-tests/util.sh
+++ b/qa/rpc-tests/util.sh
@@ -82,3 +82,9 @@ function CreateTxn1 {
function SendRawTxn {
$CLI $1 sendrawtransaction $2
}
+
+# Use: GetBlocks <datadir>
+# returns number of blocks from getinfo
+function GetBlocks {
+ ExtractKey blocks "$( $CLI $1 getinfo )"
+}
diff --git a/qa/rpc-tests/wallet.sh b/qa/rpc-tests/wallet.sh
index dd511782d0..118809a265 100755
--- a/qa/rpc-tests/wallet.sh
+++ b/qa/rpc-tests/wallet.sh
@@ -37,12 +37,27 @@ B3PID=$!
trap "kill -9 $B1PID $B2PID $B3PID; rm -rf $D" EXIT
+# Wait until all three nodes are at the same block number
+function WaitBlocks {
+ while :
+ do
+ sleep 1
+ BLOCKS1=$( GetBlocks $B1ARGS )
+ BLOCKS2=$( GetBlocks $B2ARGS )
+ BLOCKS3=$( GetBlocks $B3ARGS )
+ if (( $BLOCKS1 == $BLOCKS2 && $BLOCKS2 == $BLOCKS3 ))
+ then
+ break
+ fi
+ done
+}
+
# 1 block, 50 XBT each == 50 XBT
$CLI $B1ARGS setgenerate true 1
-sleep 1 # sleep is necessary to let block broadcast
+WaitBlocks
# 101 blocks, 1 mature == 50 XBT
$CLI $B2ARGS setgenerate true 101
-sleep 1
+WaitBlocks
CheckBalance $B1ARGS 50
CheckBalance $B2ARGS 50
@@ -56,11 +71,11 @@ Send $B1ARGS $B3ARGS 10
# Have B1 mine a new block, and mature it
# to recover transaction fees
$CLI $B1ARGS setgenerate true 1
-sleep 1
+WaitBlocks
# Have B2 mine 100 blocks so B1's block is mature:
$CLI $B2ARGS setgenerate true 100
-sleep 1
+WaitBlocks
# B1 should end up with 100 XBT in block rewards plus fees,
# minus the 21 XBT sent to B3:
@@ -77,7 +92,7 @@ RAWTXID2=$(SendRawTxn $B2ARGS $RAW2)
# Have B2 mine a block to confirm transactions:
$CLI $B2ARGS setgenerate true 1
-sleep 1 # allow time for block to be relayed
+WaitBlocks
# Check balances after confirmation
CheckBalance $B1ARGS 0
diff --git a/src/Makefile.am b/src/Makefile.am
index 62dd63abef..5ce1c8e1b6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -53,6 +53,7 @@ libbitcoin_server_a_SOURCES = \
noui.cpp \
rpcblockchain.cpp \
rpcmining.cpp \
+ rpcmisc.cpp \
rpcnet.cpp \
rpcrawtransaction.cpp \
txdb.cpp \
diff --git a/src/addrman.cpp b/src/addrman.cpp
index 815da07c9b..46b4a94938 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -14,12 +14,12 @@ int CAddrInfo::GetTriedBucket(const std::vector<unsigned char> &nKey) const
CDataStream ss1(SER_GETHASH, 0);
std::vector<unsigned char> vchKey = GetKey();
ss1 << nKey << vchKey;
- uint64_t hash1 = Hash(ss1.begin(), ss1.end()).Get64();
+ uint64_t hash1 = Hash(ss1.begin(), ss1.end()).GetLow64();
CDataStream ss2(SER_GETHASH, 0);
std::vector<unsigned char> vchGroupKey = GetGroup();
ss2 << nKey << vchGroupKey << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP);
- uint64_t hash2 = Hash(ss2.begin(), ss2.end()).Get64();
+ uint64_t hash2 = Hash(ss2.begin(), ss2.end()).GetLow64();
return hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
}
@@ -29,11 +29,11 @@ int CAddrInfo::GetNewBucket(const std::vector<unsigned char> &nKey, const CNetAd
std::vector<unsigned char> vchGroupKey = GetGroup();
std::vector<unsigned char> vchSourceGroupKey = src.GetGroup();
ss1 << nKey << vchGroupKey << vchSourceGroupKey;
- uint64_t hash1 = Hash(ss1.begin(), ss1.end()).Get64();
+ uint64_t hash1 = Hash(ss1.begin(), ss1.end()).GetLow64();
CDataStream ss2(SER_GETHASH, 0);
ss2 << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP);
- uint64_t hash2 = Hash(ss2.begin(), ss2.end()).Get64();
+ uint64_t hash2 = Hash(ss2.begin(), ss2.end()).GetLow64();
return hash2 % ADDRMAN_NEW_BUCKET_COUNT;
}
diff --git a/src/chainparams.cpp b/src/chainparams.cpp
index 14da3860ad..d3d6b98d80 100644
--- a/src/chainparams.cpp
+++ b/src/chainparams.cpp
@@ -143,6 +143,7 @@ public:
vSeeds.push_back(CDNSSeedData("bitcoin.sipa.be", "seed.bitcoin.sipa.be"));
vSeeds.push_back(CDNSSeedData("bluematt.me", "dnsseed.bluematt.me"));
vSeeds.push_back(CDNSSeedData("dashjr.org", "dnsseed.bitcoin.dashjr.org"));
+ vSeeds.push_back(CDNSSeedData("bitcoinstats.com", "seed.bitcoinstats.com"));
vSeeds.push_back(CDNSSeedData("xf2.org", "bitseed.xf2.org"));
base58Prefixes[PUBKEY_ADDRESS] = list_of(0);
diff --git a/src/init.cpp b/src/init.cpp
index 22ee0cfc08..6b100ce148 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -10,7 +10,6 @@
#include "init.h"
#include "addrman.h"
-#include "db.h"
#include "checkpoints.h"
#include "main.h"
#include "miner.h"
@@ -20,6 +19,7 @@
#include "ui_interface.h"
#include "util.h"
#ifdef ENABLE_WALLET
+#include "db.h"
#include "wallet.h"
#include "walletdb.h"
#endif
@@ -164,13 +164,13 @@ void HandleSIGHUP(int)
bool static InitError(const std::string &str)
{
- uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR);
+ uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR | CClientUIInterface::NOSHOWGUI);
return false;
}
bool static InitWarning(const std::string &str)
{
- uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_WARNING);
+ uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_WARNING | CClientUIInterface::NOSHOWGUI);
return true;
}
@@ -226,8 +226,8 @@ std::string HelpMessage(HelpMessageMode hmm)
#endif
#endif
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 += " " + _("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)
{
@@ -240,12 +240,8 @@ std::string HelpMessage(HelpMessageMode hmm)
strUsage += " -logtimestamps " + _("Prepend debug output with timestamp (default: 1)") + "\n";
strUsage += " -shrinkdebugfile " + _("Shrink debug.log file on client startup (default: 1 when no -debug)") + "\n";
strUsage += " -printtoconsole " + _("Send trace/debug info to console instead of debug.log file") + "\n";
- strUsage += " -regtest " + _("Enter regression test mode, which uses a special chain in which blocks can be "
- "solved instantly. This is intended for regression testing tools and app development.") + "\n";
-#ifdef WIN32
- strUsage += " -printtodebugger " + _("Send trace/debug info to debugger") + "\n";
-#endif
-
+ strUsage += " -regtest " + _("Enter regression test mode, which uses a special chain in which blocks can be solved instantly.") + "\n";
+ strUsage += " " + _("This is intended for regression testing tools and app development.") + "\n";
if (hmm == HMM_BITCOIN_QT)
{
strUsage += " -server " + _("Accept command line and JSON-RPC commands") + "\n";
@@ -493,7 +489,6 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
fServer = GetBoolArg("-server", false);
fPrintToConsole = GetBoolArg("-printtoconsole", false);
- fPrintToDebugger = GetBoolArg("-printtodebugger", false);
fLogTimestamps = GetBoolArg("-logtimestamps", true);
#ifdef ENABLE_WALLET
bool fDisableWallet = GetBoolArg("-disablewallet", false);
@@ -535,6 +530,7 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
return InitError(strprintf(_("Invalid amount for -minrelaytxfee=<amount>: '%s'"), mapArgs["-minrelaytxfee"].c_str()));
}
+#ifdef ENABLE_WALLET
if (mapArgs.count("-paytxfee"))
{
if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee))
@@ -543,7 +539,6 @@ bool AppInit2(boost::thread_group& threadGroup, bool fForceServer)
InitWarning(_("Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction."));
}
-#ifdef ENABLE_WALLET
strWalletFile = GetArg("-wallet", "wallet.dat");
#endif
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
diff --git a/src/main.cpp b/src/main.cpp
index 174c993453..017a0768d5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -67,9 +67,6 @@ CScript COINBASE_FLAGS;
const string strMessageMagic = "Bitcoin Signed Message:\n";
-// Settings
-int64_t nTransactionFee = 0;
-
// Internal stuff
namespace {
struct CBlockIndexWorkComparator
diff --git a/src/main.h b/src/main.h
index fd5e352cb6..f3f9acb639 100644
--- a/src/main.h
+++ b/src/main.h
@@ -96,9 +96,6 @@ extern bool fTxIndex;
extern unsigned int nCoinCacheSize;
extern bool fHaveGUI;
-// Settings
-extern int64_t nTransactionFee;
-
// Minimum disk space required - used in CheckDiskSpace()
static const uint64_t nMinDiskSpace = 52428800;
diff --git a/src/miner.cpp b/src/miner.cpp
index edfbbf5736..21a9fa256b 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -8,8 +8,9 @@
#include "core.h"
#include "main.h"
#include "net.h"
+#ifdef ENABLE_WALLET
#include "wallet.h"
-
+#endif
//////////////////////////////////////////////////////////////////////////////
//
// BitcoinMiner
diff --git a/src/net.cpp b/src/net.cpp
index 6ae749c657..ab39be60b5 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -12,7 +12,6 @@
#include "addrman.h"
#include "chainparams.h"
#include "core.h"
-#include "db.h"
#include "ui_interface.h"
#ifdef WIN32
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index b74452d4c6..657b42d16a 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -17,6 +17,7 @@
#include "main.h"
#include "ui_interface.h"
#include "util.h"
+#include "wallet.h"
#include <stdint.h>
@@ -197,9 +198,10 @@ int main(int argc, char *argv[])
// Application identification (must be set before OptionsModel is initialized,
// as it is used to locate QSettings)
+ bool isaTestNet = TestNet() || RegTest();
QApplication::setOrganizationName("Bitcoin");
QApplication::setOrganizationDomain("bitcoin.org");
- if (TestNet()) // Separate UI settings for testnet
+ if (isaTestNet) // Separate UI settings for testnets
QApplication::setApplicationName("Bitcoin-Qt-testnet");
else
QApplication::setApplicationName("Bitcoin-Qt");
@@ -230,7 +232,7 @@ int main(int argc, char *argv[])
PaymentServer* paymentServer = new PaymentServer(&app);
// User language is set up: pick a data directory
- Intro::pickDataDirectory(TestNet());
+ Intro::pickDataDirectory(isaTestNet);
// Install global event filter that makes sure that long tooltips can be word-wrapped
app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app));
@@ -258,7 +260,7 @@ int main(int argc, char *argv[])
return 1;
}
- SplashScreen splash(QPixmap(), 0);
+ SplashScreen splash(QPixmap(), 0, isaTestNet);
if (GetBoolArg("-splash", true) && !GetBoolArg("-min", false))
{
splash.show();
@@ -280,7 +282,7 @@ int main(int argc, char *argv[])
boost::thread_group threadGroup;
- BitcoinGUI window(TestNet(), 0);
+ BitcoinGUI window(isaTestNet, 0);
guiref = &window;
QTimer* pollShutdownTimer = new QTimer(guiref);
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index 2c40310de0..6be5a64015 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -215,6 +215,8 @@ void BitcoinGUI::createActions(bool fIsTestnet)
historyAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_4));
tabGroup->addAction(historyAction);
+ // These showNormalIfMinimized are needed because Send Coins and Receive Coins
+ // can be triggered from the tray menu, and need to show the GUI to be useful.
connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage()));
connect(sendCoinsAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
@@ -331,6 +333,7 @@ void BitcoinGUI::createToolBars()
toolbar->addAction(sendCoinsAction);
toolbar->addAction(receiveCoinsAction);
toolbar->addAction(historyAction);
+ overviewAction->setChecked(true);
}
void BitcoinGUI::setClientModel(ClientModel *clientModel)
@@ -681,8 +684,11 @@ void BitcoinGUI::message(const QString &title, const QString &message, unsigned
if (!(buttons = (QMessageBox::StandardButton)(style & CClientUIInterface::BTN_MASK)))
buttons = QMessageBox::Ok;
- // Ensure we get users attention
- showNormalIfMinimized();
+ // Ensure we get users attention, but only if main window is visible
+ // as we don't want to pop up the main window for messages that happen before
+ // initialization is finished.
+ if(!(style & CClientUIInterface::NOSHOWGUI))
+ showNormalIfMinimized();
QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons, this);
int r = mBox.exec();
if (ret != NULL)
diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp
index c64e411bca..f273b9ea46 100644
--- a/src/qt/clientmodel.cpp
+++ b/src/qt/clientmodel.cpp
@@ -123,9 +123,12 @@ void ClientModel::updateAlert(const QString &hash, int status)
emit alertsChanged(getStatusBarWarnings());
}
-bool ClientModel::isTestNet() const
+QString ClientModel::getNetworkName() const
{
- return TestNet();
+ QString netname(QString::fromStdString(Params().DataDir()));
+ if(netname.isEmpty())
+ netname = "main";
+ return netname;
}
bool ClientModel::inInitialBlockDownload() const
diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h
index 05e8412528..ca735f14ce 100644
--- a/src/qt/clientmodel.h
+++ b/src/qt/clientmodel.h
@@ -46,8 +46,8 @@ public:
double getVerificationProgress() const;
QDateTime getLastBlockDate() const;
- //! Return true if client connected to testnet
- bool isTestNet() 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 b4e6aeb1dd..e1a9140f45 100644
--- a/src/qt/coincontroldialog.cpp
+++ b/src/qt/coincontroldialog.cpp
@@ -449,7 +449,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
}
}
- QString sPriorityLabel = "";
+ QString sPriorityLabel = tr("none");
int64_t nAmount = 0;
int64_t nPayFee = 0;
int64_t nAfterFee = 0;
@@ -593,10 +593,10 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
l8->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, nChange)); // Change
// turn labels "red"
- l5->setStyleSheet((nBytes >= 1000) ? "color:red;" : ""); // Bytes >= 1000
- l6->setStyleSheet((!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
+ 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
// tool tips
QString toolTip1 = tr("This label turns red, if the transaction size is greater than 1000 bytes.") + "<br /><br />";
@@ -604,7 +604,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
toolTip1 += tr("Can vary +/- 1 byte per input.");
QString toolTip2 = tr("Transactions with higher priority are more likely to get included into a block.") + "<br /><br />";
- toolTip2 += tr("This label turns red, if the priority is smaller than \"medium\"") + "<br /><br />";
+ 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::nMinTxFee));
QString toolTip3 = tr("This label turns red, if any recipient receives an amount smaller than %1.").arg(BitcoinUnits::formatWithUnit(nDisplayUnit, CENT)) + "<br /><br />";
diff --git a/src/qt/forms/rpcconsole.ui b/src/qt/forms/rpcconsole.ui
index 83e51b275e..69504f3159 100644
--- a/src/qt/forms/rpcconsole.ui
+++ b/src/qt/forms/rpcconsole.ui
@@ -172,14 +172,14 @@
</widget>
</item>
<item row="7" column="0">
- <widget class="QLabel" name="label_7">
+ <widget class="QLabel" name="label_8">
<property name="text">
- <string>Number of connections</string>
+ <string>Name</string>
</property>
</widget>
</item>
<item row="7" column="1">
- <widget class="QLabel" name="numberOfConnections">
+ <widget class="QLabel" name="networkName">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
</property>
@@ -195,19 +195,25 @@
</widget>
</item>
<item row="8" column="0">
- <widget class="QLabel" name="label_8">
+ <widget class="QLabel" name="label_7">
<property name="text">
- <string>On testnet</string>
+ <string>Number of connections</string>
</property>
</widget>
</item>
<item row="8" column="1">
- <widget class="QCheckBox" name="isTestNet">
- <property name="enabled">
- <bool>false</bool>
+ <widget class="QLabel" name="numberOfConnections">
+ <property name="cursor">
+ <cursorShape>IBeamCursor</cursorShape>
</property>
<property name="text">
- <string/>
+ <string>N/A</string>
+ </property>
+ <property name="textFormat">
+ <enum>Qt::PlainText</enum>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp
index 15a873d2bd..363f432d62 100644
--- a/src/qt/optionsmodel.cpp
+++ b/src/qt/optionsmodel.cpp
@@ -14,6 +14,7 @@
#include "init.h"
#include "main.h"
#include "net.h"
+#include "wallet.h"
#include "walletdb.h"
#include <QSettings>
diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp
index d43cdc7e5f..a8470572dd 100644
--- a/src/qt/rpcconsole.cpp
+++ b/src/qt/rpcconsole.cpp
@@ -284,7 +284,7 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->buildDate->setText(model->formatBuildDate());
ui->startupTime->setText(model->formatClientStartupTime());
- ui->isTestNet->setChecked(model->isTestNet());
+ ui->networkName->setText(model->getNetworkName());
}
}
diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp
index 4bf5c3c479..92be835c56 100644
--- a/src/qt/sendcoinsdialog.cpp
+++ b/src/qt/sendcoinsdialog.cpp
@@ -546,44 +546,45 @@ void SendCoinsDialog::coinControlChangeChecked(int state)
// Coin Control: custom change address changed
void SendCoinsDialog::coinControlChangeEdited(const QString& text)
{
- if (model)
+ if (model && model->getAddressTableModel())
{
- CoinControlDialog::coinControl->destChange = CBitcoinAddress(text.toStdString()).Get();
+ // Default to no change address until verified
+ CoinControlDialog::coinControl->destChange = CNoDestination();
+ ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}");
+
+ CBitcoinAddress addr = CBitcoinAddress(text.toStdString());
- // label for the change address
- ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:black;}");
- if (text.isEmpty())
+ if (text.isEmpty()) // Nothing entered
+ {
ui->labelCoinControlChangeLabel->setText("");
- else if (!CBitcoinAddress(text.toStdString()).IsValid())
+ }
+ else if (!addr.IsValid()) // Invalid address
{
- // invalid change address
- CoinControlDialog::coinControl->destChange = CNoDestination();
-
ui->lineEditCoinControlChange->setValid(false);
- ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}");
ui->labelCoinControlChangeLabel->setText(tr("Warning: Invalid Bitcoin address"));
}
- else
+ else // Valid address
{
- QString associatedLabel = model->getAddressTableModel()->labelForAddress(text);
- if (!associatedLabel.isEmpty())
- ui->labelCoinControlChangeLabel->setText(associatedLabel);
- else
+ CPubKey pubkey;
+ CKeyID keyid;
+ addr.GetKeyID(keyid);
+ if (!model->getPubKey(keyid, pubkey)) // Unknown change address
{
- CPubKey pubkey;
- CKeyID keyid;
- CBitcoinAddress(text.toStdString()).GetKeyID(keyid);
- if (model->getPubKey(keyid, pubkey))
- ui->labelCoinControlChangeLabel->setText(tr("(no label)"));
+ ui->lineEditCoinControlChange->setValid(false);
+ ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address"));
+ }
+ else // Known change address
+ {
+ ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:black;}");
+
+ // Query label
+ QString associatedLabel = model->getAddressTableModel()->labelForAddress(text);
+ if (!associatedLabel.isEmpty())
+ ui->labelCoinControlChangeLabel->setText(associatedLabel);
else
- {
- // unknown change address
- CoinControlDialog::coinControl->destChange = CNoDestination();
-
- ui->lineEditCoinControlChange->setValid(false);
- ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}");
- ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address"));
- }
+ ui->labelCoinControlChangeLabel->setText(tr("(no label)"));
+
+ CoinControlDialog::coinControl->destChange = addr.Get();
}
}
}
diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp
index 4d28f68861..3f5d0cda3a 100644
--- a/src/qt/sendcoinsentry.cpp
+++ b/src/qt/sendcoinsentry.cpp
@@ -155,11 +155,12 @@ SendCoinsRecipient SendCoinsEntry::getValue()
QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
{
QWidget::setTabOrder(prev, ui->payTo);
- QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
+ QWidget::setTabOrder(ui->payTo, ui->addAsLabel);
+ QWidget *w = ui->payAmount->setupTabChain(ui->addAsLabel);
+ QWidget::setTabOrder(w, ui->addressBookButton);
QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
- QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
- return ui->payAmount->setupTabChain(ui->addAsLabel);
+ return ui->deleteButton;
}
void SendCoinsEntry::setValue(const SendCoinsRecipient &value)
diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp
index 4528c3477c..6fb834c045 100644
--- a/src/qt/splashscreen.cpp
+++ b/src/qt/splashscreen.cpp
@@ -4,14 +4,13 @@
#include "splashscreen.h"
-#include "chainparams.h"
#include "clientversion.h"
#include "util.h"
#include <QApplication>
#include <QPainter>
-SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) :
+SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTestNet) :
QSplashScreen(pixmap, f)
{
// set reference point, paddings
@@ -32,7 +31,7 @@ SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) :
// load the bitmap for writing some text over it
QPixmap newPixmap;
- if(TestNet()) {
+ if(isTestNet) {
newPixmap = QPixmap(":/images/splash_testnet");
}
else {
@@ -72,7 +71,7 @@ SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) :
pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace,copyrightText);
// draw testnet string if testnet is on
- if(TestNet()) {
+ if(isTestNet) {
QFont boldFont = QFont(font, 10*fontFactor);
boldFont.setWeight(QFont::Bold);
pixPaint.setFont(boldFont);
diff --git a/src/qt/splashscreen.h b/src/qt/splashscreen.h
index ddf040593d..070e376c95 100644
--- a/src/qt/splashscreen.h
+++ b/src/qt/splashscreen.h
@@ -14,7 +14,7 @@ class SplashScreen : public QSplashScreen
Q_OBJECT
public:
- explicit SplashScreen(const QPixmap &pixmap = QPixmap(), Qt::WindowFlags f = 0);
+ explicit SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTestNet);
};
#endif // SPLASHSCREEN_H
diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp
index 34ae6e0543..661deffb19 100644
--- a/src/rpcblockchain.cpp
+++ b/src/rpcblockchain.cpp
@@ -127,30 +127,6 @@ Value getdifficulty(const Array& params, bool fHelp)
}
-Value settxfee(const Array& params, bool fHelp)
-{
- if (fHelp || params.size() < 1 || params.size() > 1)
- throw runtime_error(
- "settxfee amount\n"
- "\nSet the transaction fee. 'amount' is a real and is rounded to the nearest 0.00000001\n"
- "\nArguments:\n"
- "1. amount (numeric, required) The transaction fee in btc rounded to the nearest 0.00000001\n"
- "\nResult\n"
- "true|false (boolean) Returns true if successful\n"
- "\nExamples:\n"
- + HelpExampleCli("settxfee", "0.00001")
- + HelpExampleRpc("settxfee", "0.00001")
- );
-
- // Amount
- int64_t nAmount = 0;
- if (params[0].get_real() != 0.0)
- nAmount = AmountFromValue(params[0]); // rejects 0.0 amounts
-
- nTransactionFee = nAmount;
- return true;
-}
-
Value getrawmempool(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp
index 92f4c2c6dd..c801b284cb 100644
--- a/src/rpcdump.cpp
+++ b/src/rpcdump.cpp
@@ -86,6 +86,8 @@ Value importprivkey(const Array& params, bool fHelp)
+ HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false")
);
+ EnsureWalletIsUnlocked();
+
string strSecret = params[0].get_str();
string strLabel = "";
if (params.size() > 1)
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp
index b81433120e..564f0401f1 100644
--- a/src/rpcmining.cpp
+++ b/src/rpcmining.cpp
@@ -5,13 +5,14 @@
#include "rpcserver.h"
#include "chainparams.h"
-#include "db.h"
#include "init.h"
#include "net.h"
#include "main.h"
#include "miner.h"
+#ifdef ENABLE_WALLET
+#include "db.h"
#include "wallet.h"
-
+#endif
#include <stdint.h>
#include "json/json_spirit_utils.h"
@@ -54,7 +55,10 @@ void ShutdownRPCMining()
// or from the last difficulty change if 'lookup' is nonpositive.
// If 'height' is nonnegative, compute the estimate at the time when a given block was found.
Value GetNetworkHashPS(int lookup, int height) {
- CBlockIndex *pb = chainActive[height];
+ CBlockIndex *pb = chainActive.Tip();
+
+ if (height >= 0 && height < chainActive.Height())
+ pb = chainActive[height];
if (pb == NULL || !pb->nHeight)
return 0;
diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp
new file mode 100644
index 0000000000..c61cc4192b
--- /dev/null
+++ b/src/rpcmisc.cpp
@@ -0,0 +1,326 @@
+// Copyright (c) 2010 Satoshi Nakamoto
+// Copyright (c) 2009-2013 The Bitcoin developers
+// Distributed under the MIT/X11 software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include "base58.h"
+#include "rpcserver.h"
+#include "init.h"
+#include "main.h"
+#include "net.h"
+#include "netbase.h"
+#include "util.h"
+#ifdef ENABLE_WALLET
+#include "wallet.h"
+#include "walletdb.h"
+#endif
+
+#include <stdint.h>
+
+#include <boost/assign/list_of.hpp>
+#include "json/json_spirit_utils.h"
+#include "json/json_spirit_value.h"
+
+using namespace std;
+using namespace boost;
+using namespace boost::assign;
+using namespace json_spirit;
+
+Value getinfo(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 0)
+ throw runtime_error(
+ "getinfo\n"
+ "Returns an object containing various state info.\n"
+ "\nResult:\n"
+ "{\n"
+ " \"version\": xxxxx, (numeric) the server version\n"
+ " \"protocolversion\": xxxxx, (numeric) the protocol version\n"
+ " \"walletversion\": xxxxx, (numeric) the wallet version\n"
+ " \"balance\": xxxxxxx, (numeric) the total bitcoin balance of the wallet\n"
+ " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
+ " \"timeoffset\": xxxxx, (numeric) the time offset\n"
+ " \"connections\": xxxxx, (numeric) the number of connections\n"
+ " \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n"
+ " \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
+ " \"testnet\": true|false, (boolean) if the server is using testnet or not\n"
+ " \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n"
+ " \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
+ " \"paytxfee\": x.xxxx, (numeric) the transaction fee set in btc\n"
+ " \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n"
+ " \"errors\": \"...\" (string) any error messages\n"
+ "}\n"
+ "\nExamples:\n"
+ + HelpExampleCli("getinfo", "")
+ + HelpExampleRpc("getinfo", "")
+ );
+
+ proxyType proxy;
+ GetProxy(NET_IPV4, proxy);
+
+ Object obj;
+ obj.push_back(Pair("version", (int)CLIENT_VERSION));
+ obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION));
+#ifdef ENABLE_WALLET
+ if (pwalletMain) {
+ obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
+ obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
+ }
+#endif
+ obj.push_back(Pair("blocks", (int)chainActive.Height()));
+ obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset()));
+ 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()));
+#ifdef ENABLE_WALLET
+ if (pwalletMain) {
+ obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime()));
+ obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize()));
+ }
+ obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
+ if (pwalletMain && pwalletMain->IsCrypted())
+ obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
+#endif
+ obj.push_back(Pair("errors", GetWarnings("statusbar")));
+ return obj;
+}
+
+#ifdef ENABLE_WALLET
+class DescribeAddressVisitor : public boost::static_visitor<Object>
+{
+public:
+ Object operator()(const CNoDestination &dest) const { return Object(); }
+
+ Object operator()(const CKeyID &keyID) const {
+ Object obj;
+ CPubKey vchPubKey;
+ pwalletMain->GetPubKey(keyID, vchPubKey);
+ obj.push_back(Pair("isscript", false));
+ obj.push_back(Pair("pubkey", HexStr(vchPubKey)));
+ obj.push_back(Pair("iscompressed", vchPubKey.IsCompressed()));
+ return obj;
+ }
+
+ Object operator()(const CScriptID &scriptID) const {
+ Object obj;
+ obj.push_back(Pair("isscript", true));
+ CScript subscript;
+ pwalletMain->GetCScript(scriptID, subscript);
+ std::vector<CTxDestination> addresses;
+ txnouttype whichType;
+ int nRequired;
+ ExtractDestinations(subscript, whichType, addresses, nRequired);
+ obj.push_back(Pair("script", GetTxnOutputType(whichType)));
+ obj.push_back(Pair("hex", HexStr(subscript.begin(), subscript.end())));
+ Array a;
+ BOOST_FOREACH(const CTxDestination& addr, addresses)
+ a.push_back(CBitcoinAddress(addr).ToString());
+ obj.push_back(Pair("addresses", a));
+ if (whichType == TX_MULTISIG)
+ obj.push_back(Pair("sigsrequired", nRequired));
+ return obj;
+ }
+};
+#endif
+
+Value validateaddress(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 1)
+ throw runtime_error(
+ "validateaddress \"bitcoinaddress\"\n"
+ "\nReturn information about the given bitcoin address.\n"
+ "\nArguments:\n"
+ "1. \"bitcoinaddress\" (string, required) The bitcoin address to validate\n"
+ "\nResult:\n"
+ "{\n"
+ " \"isvalid\" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.\n"
+ " \"address\" : \"bitcoinaddress\", (string) The bitcoin address validated\n"
+ " \"ismine\" : true|false, (boolean) If the address is yours or not\n"
+ " \"isscript\" : true|false, (boolean) If the key is a script\n"
+ " \"pubkey\" : \"publickeyhex\", (string) The hex value of the raw public key\n"
+ " \"iscompressed\" : true|false, (boolean) If the address is compressed\n"
+ " \"account\" : \"account\" (string) The account associated with the address, \"\" is the default account\n"
+ "}\n"
+ "\nExamples:\n"
+ + HelpExampleCli("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
+ + HelpExampleRpc("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
+ );
+
+ CBitcoinAddress address(params[0].get_str());
+ bool isValid = address.IsValid();
+
+ Object ret;
+ ret.push_back(Pair("isvalid", isValid));
+ if (isValid)
+ {
+ CTxDestination dest = address.Get();
+ string currentAddress = address.ToString();
+ ret.push_back(Pair("address", currentAddress));
+#ifdef ENABLE_WALLET
+ bool fMine = pwalletMain ? IsMine(*pwalletMain, dest) : false;
+ ret.push_back(Pair("ismine", fMine));
+ if (fMine) {
+ Object detail = boost::apply_visitor(DescribeAddressVisitor(), dest);
+ ret.insert(ret.end(), detail.begin(), detail.end());
+ }
+ if (pwalletMain && pwalletMain->mapAddressBook.count(dest))
+ ret.push_back(Pair("account", pwalletMain->mapAddressBook[dest].name));
+#endif
+ }
+ return ret;
+}
+
+//
+// Used by addmultisigaddress / createmultisig:
+//
+CScript _createmultisig(const Array& params)
+{
+ int nRequired = params[0].get_int();
+ const Array& keys = params[1].get_array();
+
+ // Gather public keys
+ if (nRequired < 1)
+ throw runtime_error("a multisignature address must require at least one key to redeem");
+ if ((int)keys.size() < nRequired)
+ throw runtime_error(
+ strprintf("not enough keys supplied "
+ "(got %"PRIszu" keys, but need at least %d to redeem)", keys.size(), nRequired));
+ std::vector<CPubKey> pubkeys;
+ pubkeys.resize(keys.size());
+ for (unsigned int i = 0; i < keys.size(); i++)
+ {
+ const std::string& ks = keys[i].get_str();
+#ifdef ENABLE_WALLET
+ // Case 1: Bitcoin address and we have full public key:
+ CBitcoinAddress address(ks);
+ if (pwalletMain && address.IsValid())
+ {
+ CKeyID keyID;
+ if (!address.GetKeyID(keyID))
+ throw runtime_error(
+ strprintf("%s does not refer to a key",ks.c_str()));
+ CPubKey vchPubKey;
+ if (!pwalletMain->GetPubKey(keyID, vchPubKey))
+ throw runtime_error(
+ strprintf("no full public key for address %s",ks.c_str()));
+ if (!vchPubKey.IsFullyValid())
+ throw runtime_error(" Invalid public key: "+ks);
+ pubkeys[i] = vchPubKey;
+ }
+
+ // Case 2: hex public key
+ else
+#endif
+ if (IsHex(ks))
+ {
+ CPubKey vchPubKey(ParseHex(ks));
+ if (!vchPubKey.IsFullyValid())
+ throw runtime_error(" Invalid public key: "+ks);
+ pubkeys[i] = vchPubKey;
+ }
+ else
+ {
+ throw runtime_error(" Invalid public key: "+ks);
+ }
+ }
+ CScript result;
+ result.SetMultisig(nRequired, pubkeys);
+ return result;
+}
+
+Value createmultisig(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() < 2 || params.size() > 2)
+ {
+ string msg = "createmultisig nrequired [\"key\",...]\n"
+ "\nCreates a multi-signature address with n signature of m keys required.\n"
+ "It returns a json object with the address and redeemScript.\n"
+
+ "\nArguments:\n"
+ "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n"
+ "2. \"keys\" (string, required) A json array of keys which are bitcoin addresses or hex-encoded public keys\n"
+ " [\n"
+ " \"key\" (string) bitcoin address or hex-encoded public key\n"
+ " ,...\n"
+ " ]\n"
+
+ "\nResult:\n"
+ "{\n"
+ " \"address\":\"multisigaddress\", (string) The value of the new multisig address.\n"
+ " \"redeemScript\":\"script\" (string) The string value of the hex-encoded redemption script.\n"
+ "}\n"
+
+ "\nExamples:\n"
+ "\nCreate a multisig address from 2 addresses\n"
+ + HelpExampleCli("createmultisig", "2 \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") +
+ "\nAs a json rpc call\n"
+ + HelpExampleRpc("icreatemultisig", "2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"")
+ ;
+ throw runtime_error(msg);
+ }
+
+ // Construct using pay-to-script-hash:
+ CScript inner = _createmultisig(params);
+ CScriptID innerID = inner.GetID();
+ CBitcoinAddress address(innerID);
+
+ Object result;
+ result.push_back(Pair("address", address.ToString()));
+ result.push_back(Pair("redeemScript", HexStr(inner.begin(), inner.end())));
+
+ return result;
+}
+
+Value verifymessage(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 3)
+ throw runtime_error(
+ "verifymessage \"bitcoinaddress\" \"signature\" \"message\"\n"
+ "\nVerify a signed message\n"
+ "\nArguments:\n"
+ "1. \"bitcoinaddress\" (string, required) The bitcoin address to use for the signature.\n"
+ "2. \"signature\" (string, required) The signature provided by the signer in base 64 encoding (see signmessage).\n"
+ "3. \"message\" (string, required) The message that was signed.\n"
+ "\nResult:\n"
+ "true|false (boolean) If the signature is verified or not.\n"
+ "\nExamples:\n"
+ "\nUnlock the wallet for 30 seconds\n"
+ + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
+ "\nCreate the signature\n"
+ + HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"my message\"") +
+ "\nVerify the signature\n"
+ + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"signature\" \"my message\"") +
+ "\nAs json rpc\n"
+ + HelpExampleRpc("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\", \"signature\", \"my message\"")
+ );
+
+ string strAddress = params[0].get_str();
+ string strSign = params[1].get_str();
+ string strMessage = params[2].get_str();
+
+ CBitcoinAddress addr(strAddress);
+ if (!addr.IsValid())
+ throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
+
+ CKeyID keyID;
+ if (!addr.GetKeyID(keyID))
+ throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
+
+ bool fInvalid = false;
+ vector<unsigned char> vchSig = DecodeBase64(strSign.c_str(), &fInvalid);
+
+ if (fInvalid)
+ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");
+
+ CHashWriter ss(SER_GETHASH, 0);
+ ss << strMessageMagic;
+ ss << strMessage;
+
+ CPubKey pubkey;
+ if (!pubkey.RecoverCompact(ss.GetHash(), vchSig))
+ return false;
+
+ return (pubkey.GetID() == keyID);
+}
+
diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp
index fd72fe6386..06ae7070c3 100644
--- a/src/rpcnet.cpp
+++ b/src/rpcnet.cpp
@@ -338,65 +338,3 @@ Value getnettotals(const Array& params, bool fHelp)
obj.push_back(Pair("timemillis", static_cast<boost::int64_t>(GetTimeMillis())));
return obj;
}
-
-Value getinfo(const Array& params, bool fHelp)
-{
- if (fHelp || params.size() != 0)
- throw runtime_error(
- "getinfo\n"
- "Returns an object containing various state info.\n"
- "\nResult:\n"
- "{\n"
- " \"version\": xxxxx, (numeric) the server version\n"
- " \"protocolversion\": xxxxx, (numeric) the protocol version\n"
- " \"walletversion\": xxxxx, (numeric) the wallet version\n"
- " \"balance\": xxxxxxx, (numeric) the total bitcoin balance of the wallet\n"
- " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
- " \"timeoffset\": xxxxx, (numeric) the time offset\n"
- " \"connections\": xxxxx, (numeric) the number of connections\n"
- " \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n"
- " \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
- " \"testnet\": true|false, (boolean) if the server is using testnet or not\n"
- " \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n"
- " \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n"
- " \"paytxfee\": x.xxxx, (numeric) the transaction fee set in btc\n"
- " \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n"
- " \"errors\": \"...\" (string) any error messages\n"
- "}\n"
- "\nExamples:\n"
- + HelpExampleCli("getinfo", "")
- + HelpExampleRpc("getinfo", "")
- );
-
- proxyType proxy;
- GetProxy(NET_IPV4, proxy);
-
- Object obj;
- obj.push_back(Pair("version", (int)CLIENT_VERSION));
- obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION));
-#ifdef ENABLE_WALLET
- if (pwalletMain) {
- obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
- obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
- }
-#endif
- obj.push_back(Pair("blocks", (int)chainActive.Height()));
- obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset()));
- 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()));
-#ifdef ENABLE_WALLET
- if (pwalletMain) {
- obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime()));
- obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize()));
- }
-#endif
- obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
-#ifdef ENABLE_WALLET
- if (pwalletMain && pwalletMain->IsCrypted())
- obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
-#endif
- obj.push_back(Pair("errors", GetWarnings("statusbar")));
- return obj;
-}
diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp
index c95f450c82..9f2100a8d7 100644
--- a/src/rpcserver.cpp
+++ b/src/rpcserver.cpp
@@ -237,7 +237,6 @@ static const CRPCCommand vRPCCommands[] =
{ "getrawmempool", &getrawmempool, true, false, false },
{ "getblock", &getblock, false, false, false },
{ "getblockhash", &getblockhash, false, false, false },
- { "settxfee", &settxfee, false, false, true },
{ "getrawtransaction", &getrawtransaction, false, false, false },
{ "createrawtransaction", &createrawtransaction, false, false, false },
{ "decoderawtransaction", &decoderawtransaction, false, false, false },
@@ -253,6 +252,9 @@ static const CRPCCommand vRPCCommands[] =
{ "getmininginfo", &getmininginfo, true, false, false },
{ "getblocktemplate", &getblocktemplate, true, false, false },
{ "submitblock", &submitblock, false, false, false },
+ { "validateaddress", &validateaddress, true, false, false },
+ { "createmultisig", &createmultisig, true, true , false },
+ { "verifymessage", &verifymessage, false, false, false },
#ifdef ENABLE_WALLET
/* Wallet */
@@ -273,18 +275,16 @@ static const CRPCCommand vRPCCommands[] =
{ "walletpassphrasechange", &walletpassphrasechange, false, false, true },
{ "walletlock", &walletlock, true, false, true },
{ "encryptwallet", &encryptwallet, false, false, true },
- { "validateaddress", &validateaddress, true, false, false },
{ "getbalance", &getbalance, false, false, true },
+ { "getunconfirmedbalance", &getunconfirmedbalance, false, false, true },
{ "move", &movecmd, false, false, true },
{ "sendfrom", &sendfrom, false, false, true },
{ "sendmany", &sendmany, false, false, true },
{ "addmultisigaddress", &addmultisigaddress, false, false, true },
- { "createmultisig", &createmultisig, true, true , false },
{ "gettransaction", &gettransaction, false, false, true },
{ "listtransactions", &listtransactions, false, false, true },
{ "listaddressgroupings", &listaddressgroupings, false, false, true },
{ "signmessage", &signmessage, false, false, true },
- { "verifymessage", &verifymessage, false, false, false },
{ "listaccounts", &listaccounts, false, false, true },
{ "listsinceblock", &listsinceblock, false, false, true },
{ "dumpprivkey", &dumpprivkey, true, false, true },
@@ -294,6 +294,7 @@ static const CRPCCommand vRPCCommands[] =
{ "listunspent", &listunspent, false, false, true },
{ "lockunspent", &lockunspent, false, false, true },
{ "listlockunspent", &listlockunspent, false, false, true },
+ { "settxfee", &settxfee, false, false, true },
/* Wallet-enabled mining */
{ "getgenerate", &getgenerate, true, false, false },
diff --git a/src/rpcserver.h b/src/rpcserver.h
index 4d29e90c09..9087be9e88 100644
--- a/src/rpcserver.h
+++ b/src/rpcserver.h
@@ -135,6 +135,7 @@ extern json_spirit::Value verifymessage(const json_spirit::Array& params, bool f
extern json_spirit::Value getreceivedbyaddress(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getreceivedbyaccount(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getbalance(const json_spirit::Array& params, bool fHelp);
+extern json_spirit::Value getunconfirmedbalance(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value movecmd(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value sendfrom(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value sendmany(const json_spirit::Array& params, bool fHelp);
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp
index 82fa9d88c5..8ad5c9c51d 100644
--- a/src/rpcwallet.cpp
+++ b/src/rpcwallet.cpp
@@ -441,59 +441,6 @@ Value signmessage(const Array& params, bool fHelp)
return EncodeBase64(&vchSig[0], vchSig.size());
}
-Value verifymessage(const Array& params, bool fHelp)
-{
- if (fHelp || params.size() != 3)
- throw runtime_error(
- "verifymessage \"bitcoinaddress\" \"signature\" \"message\"\n"
- "\nVerify a signed message\n"
- "\nArguments:\n"
- "1. \"bitcoinaddress\" (string, required) The bitcoin address to use for the signature.\n"
- "2. \"signature\" (string, required) The signature provided by the signer in base 64 encoding (see signmessage).\n"
- "3. \"message\" (string, required) The message that was signed.\n"
- "\nResult:\n"
- "true|false (boolean) If the signature is verified or not.\n"
- "\nExamples:\n"
- "\nUnlock the wallet for 30 seconds\n"
- + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
- "\nCreate the signature\n"
- + HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"my message\"") +
- "\nVerify the signature\n"
- + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"signature\" \"my message\"") +
- "\nAs json rpc\n"
- + HelpExampleRpc("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\", \"signature\", \"my message\"")
- );
-
- string strAddress = params[0].get_str();
- string strSign = params[1].get_str();
- string strMessage = params[2].get_str();
-
- CBitcoinAddress addr(strAddress);
- if (!addr.IsValid())
- throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
-
- CKeyID keyID;
- if (!addr.GetKeyID(keyID))
- throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
-
- bool fInvalid = false;
- vector<unsigned char> vchSig = DecodeBase64(strSign.c_str(), &fInvalid);
-
- if (fInvalid)
- throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");
-
- CHashWriter ss(SER_GETHASH, 0);
- ss << strMessageMagic;
- ss << strMessage;
-
- CPubKey pubkey;
- if (!pubkey.RecoverCompact(ss.GetHash(), vchSig))
- return false;
-
- return (pubkey.GetID() == keyID);
-}
-
-
Value getreceivedbyaddress(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
@@ -699,6 +646,15 @@ Value getbalance(const Array& params, bool fHelp)
return ValueFromAmount(nBalance);
}
+Value getunconfirmedbalance(const Array &params, bool fHelp)
+{
+ if (fHelp || params.size() > 0)
+ throw runtime_error(
+ "getunconfirmedbalance\n"
+ "Returns the server's total unconfirmed balance\n");
+ return ValueFromAmount(pwalletMain->GetUnconfirmedBalance());
+}
+
Value movecmd(const Array& params, bool fHelp)
{
@@ -907,61 +863,8 @@ Value sendmany(const Array& params, bool fHelp)
return wtx.GetHash().GetHex();
}
-//
-// Used by addmultisigaddress / createmultisig:
-//
-static CScript _createmultisig(const Array& params)
-{
- int nRequired = params[0].get_int();
- const Array& keys = params[1].get_array();
-
- // Gather public keys
- if (nRequired < 1)
- throw runtime_error("a multisignature address must require at least one key to redeem");
- if ((int)keys.size() < nRequired)
- throw runtime_error(
- strprintf("not enough keys supplied "
- "(got %"PRIszu" keys, but need at least %d to redeem)", keys.size(), nRequired));
- std::vector<CPubKey> pubkeys;
- pubkeys.resize(keys.size());
- for (unsigned int i = 0; i < keys.size(); i++)
- {
- const std::string& ks = keys[i].get_str();
-
- // Case 1: Bitcoin address and we have full public key:
- CBitcoinAddress address(ks);
- if (pwalletMain && address.IsValid())
- {
- CKeyID keyID;
- if (!address.GetKeyID(keyID))
- throw runtime_error(
- strprintf("%s does not refer to a key",ks.c_str()));
- CPubKey vchPubKey;
- if (!pwalletMain->GetPubKey(keyID, vchPubKey))
- throw runtime_error(
- strprintf("no full public key for address %s",ks.c_str()));
- if (!vchPubKey.IsFullyValid())
- throw runtime_error(" Invalid public key: "+ks);
- pubkeys[i] = vchPubKey;
- }
-
- // Case 2: hex public key
- else if (IsHex(ks))
- {
- CPubKey vchPubKey(ParseHex(ks));
- if (!vchPubKey.IsFullyValid())
- throw runtime_error(" Invalid public key: "+ks);
- pubkeys[i] = vchPubKey;
- }
- else
- {
- throw runtime_error(" Invalid public key: "+ks);
- }
- }
- CScript result;
- result.SetMultisig(nRequired, pubkeys);
- return result;
-}
+// Defined in rpcmisc.cpp
+extern CScript _createmultisig(const Array& params);
Value addmultisigaddress(const Array& params, bool fHelp)
{
@@ -1006,49 +909,6 @@ Value addmultisigaddress(const Array& params, bool fHelp)
return CBitcoinAddress(innerID).ToString();
}
-Value createmultisig(const Array& params, bool fHelp)
-{
- if (fHelp || params.size() < 2 || params.size() > 2)
- {
- string msg = "createmultisig nrequired [\"key\",...]\n"
- "\nCreates a multi-signature address with n signature of m keys required.\n"
- "It returns a json object with the address and redeemScript.\n"
-
- "\nArguments:\n"
- "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n"
- "2. \"keys\" (string, required) A json array of keys which are bitcoin addresses or hex-encoded public keys\n"
- " [\n"
- " \"key\" (string) bitcoin address or hex-encoded public key\n"
- " ,...\n"
- " ]\n"
-
- "\nResult:\n"
- "{\n"
- " \"address\":\"multisigaddress\", (string) The value of the new multisig address.\n"
- " \"redeemScript\":\"script\" (string) The string value of the hex-encoded redemption script.\n"
- "}\n"
-
- "\nExamples:\n"
- "\nCreate a multisig address from 2 addresses\n"
- + HelpExampleCli("createmultisig", "2 \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") +
- "\nAs a json rpc call\n"
- + HelpExampleRpc("icreatemultisig", "2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"")
- ;
- throw runtime_error(msg);
- }
-
- // Construct using pay-to-script-hash:
- CScript inner = _createmultisig(params);
- CScriptID innerID = inner.GetID();
- CBitcoinAddress address(innerID);
-
- Object result;
- result.push_back(Pair("address", address.ToString()));
- result.push_back(Pair("redeemScript", HexStr(inner.begin(), inner.end())));
-
- return result;
-}
-
struct tallyitem
{
@@ -1862,87 +1722,6 @@ Value encryptwallet(const Array& params, bool fHelp)
return "wallet encrypted; Bitcoin server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup.";
}
-class DescribeAddressVisitor : public boost::static_visitor<Object>
-{
-public:
- Object operator()(const CNoDestination &dest) const { return Object(); }
-
- Object operator()(const CKeyID &keyID) const {
- Object obj;
- CPubKey vchPubKey;
- pwalletMain->GetPubKey(keyID, vchPubKey);
- obj.push_back(Pair("isscript", false));
- obj.push_back(Pair("pubkey", HexStr(vchPubKey)));
- obj.push_back(Pair("iscompressed", vchPubKey.IsCompressed()));
- return obj;
- }
-
- Object operator()(const CScriptID &scriptID) const {
- Object obj;
- obj.push_back(Pair("isscript", true));
- CScript subscript;
- pwalletMain->GetCScript(scriptID, subscript);
- std::vector<CTxDestination> addresses;
- txnouttype whichType;
- int nRequired;
- ExtractDestinations(subscript, whichType, addresses, nRequired);
- obj.push_back(Pair("script", GetTxnOutputType(whichType)));
- obj.push_back(Pair("hex", HexStr(subscript.begin(), subscript.end())));
- Array a;
- BOOST_FOREACH(const CTxDestination& addr, addresses)
- a.push_back(CBitcoinAddress(addr).ToString());
- obj.push_back(Pair("addresses", a));
- if (whichType == TX_MULTISIG)
- obj.push_back(Pair("sigsrequired", nRequired));
- return obj;
- }
-};
-
-Value validateaddress(const Array& params, bool fHelp)
-{
- if (fHelp || params.size() != 1)
- throw runtime_error(
- "validateaddress \"bitcoinaddress\"\n"
- "\nReturn information about the given bitcoin address.\n"
- "\nArguments:\n"
- "1. \"bitcoinaddress\" (string, required) The bitcoin address to validate\n"
- "\nResult:\n"
- "{\n"
- " \"isvalid\" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.\n"
- " \"address\" : \"bitcoinaddress\", (string) The bitcoin address validated\n"
- " \"ismine\" : true|false, (boolean) If the address is yours or not\n"
- " \"isscript\" : true|false, (boolean) If the key is a script\n"
- " \"pubkey\" : \"publickeyhex\", (string) The hex value of the raw public key\n"
- " \"iscompressed\" : true|false, (boolean) If the address is compressed\n"
- " \"account\" : \"account\" (string) The account associated with the address, \"\" is the default account\n"
- "}\n"
- "\nExamples:\n"
- + HelpExampleCli("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
- + HelpExampleRpc("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"")
- );
-
- CBitcoinAddress address(params[0].get_str());
- bool isValid = address.IsValid();
-
- Object ret;
- ret.push_back(Pair("isvalid", isValid));
- if (isValid)
- {
- CTxDestination dest = address.Get();
- string currentAddress = address.ToString();
- ret.push_back(Pair("address", currentAddress));
- bool fMine = pwalletMain ? IsMine(*pwalletMain, dest) : false;
- ret.push_back(Pair("ismine", fMine));
- if (fMine) {
- Object detail = boost::apply_visitor(DescribeAddressVisitor(), dest);
- ret.insert(ret.end(), detail.begin(), detail.end());
- }
- if (pwalletMain && pwalletMain->mapAddressBook.count(dest))
- ret.push_back(Pair("account", pwalletMain->mapAddressBook[dest].name));
- }
- return ret;
-}
-
Value lockunspent(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
@@ -2066,3 +1845,28 @@ Value listlockunspent(const Array& params, bool fHelp)
return ret;
}
+Value settxfee(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() < 1 || params.size() > 1)
+ throw runtime_error(
+ "settxfee amount\n"
+ "\nSet the transaction fee. 'amount' is a real and is rounded to the nearest 0.00000001\n"
+ "\nArguments:\n"
+ "1. amount (numeric, required) The transaction fee in btc rounded to the nearest 0.00000001\n"
+ "\nResult\n"
+ "true|false (boolean) Returns true if successful\n"
+ "\nExamples:\n"
+ + HelpExampleCli("settxfee", "0.00001")
+ + HelpExampleRpc("settxfee", "0.00001")
+ );
+
+ // Amount
+ int64_t nAmount = 0;
+ if (params[0].get_real() != 0.0)
+ nAmount = AmountFromValue(params[0]); // rejects 0.0 amounts
+
+ nTransactionFee = nAmount;
+ return true;
+}
+
+
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
index ccc8da1690..384616e897 100644
--- a/src/test/Makefile.am
+++ b/src/test/Makefile.am
@@ -34,7 +34,7 @@ test_bitcoin_SOURCES = alert_tests.cpp \
key_tests.cpp miner_tests.cpp mruset_tests.cpp multisig_tests.cpp \
netbase_tests.cpp pmt_tests.cpp rpc_tests.cpp script_P2SH_tests.cpp \
script_tests.cpp serialize_tests.cpp sigopcount_tests.cpp test_bitcoin.cpp \
- transaction_tests.cpp uint160_tests.cpp uint256_tests.cpp util_tests.cpp \
+ transaction_tests.cpp uint256_tests.cpp util_tests.cpp \
sighash_tests.cpp $(JSON_TEST_FILES) $(RAW_TEST_FILES)
if ENABLE_WALLET
diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp
index ea6abb7e9a..8e3091d555 100644
--- a/src/test/miner_tests.cpp
+++ b/src/test/miner_tests.cpp
@@ -4,7 +4,6 @@
#include "miner.h"
#include "uint256.h"
#include "util.h"
-#include "wallet.h"
#include <boost/test/unit_test.hpp>
diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp
index a4592fe803..96d0712403 100644
--- a/src/test/test_bitcoin.cpp
+++ b/src/test/test_bitcoin.cpp
@@ -2,12 +2,12 @@
-#include "db.h"
#include "main.h"
#include "txdb.h"
#include "ui_interface.h"
#include "util.h"
#ifdef ENABLE_WALLET
+#include "db.h"
#include "wallet.h"
#endif
@@ -26,7 +26,7 @@ struct TestingSetup {
boost::thread_group threadGroup;
TestingSetup() {
- fPrintToDebugger = true; // don't want to write to debug.log file
+ fPrintToDebugLog = false; // don't want to write to debug.log file
noui_connect();
#ifdef ENABLE_WALLET
bitdb.MakeMock();
diff --git a/src/test/uint160_tests.cpp b/src/test/uint160_tests.cpp
deleted file mode 100644
index 87418fabec..0000000000
--- a/src/test/uint160_tests.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "uint256.h"
-
-#include <stdint.h>
-
-#include <boost/test/unit_test.hpp>
-
-BOOST_AUTO_TEST_SUITE(uint160_tests)
-
-BOOST_AUTO_TEST_CASE(uint160_equality)
-{
- uint160 num1 = 10;
- uint160 num2 = 11;
- BOOST_CHECK(num1+1 == num2);
-
- uint64_t num3 = 10;
- BOOST_CHECK(num1 == num3);
- BOOST_CHECK(num1+num2 == num3+num2);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/uint256_tests.cpp b/src/test/uint256_tests.cpp
index 188635dcbd..368484fdff 100644
--- a/src/test/uint256_tests.cpp
+++ b/src/test/uint256_tests.cpp
@@ -1,29 +1,633 @@
+#include <boost/test/unit_test.hpp>
+#include <stdint.h>
+#include <sstream>
+#include <iomanip>
+#include <limits>
+#include <cmath>
#include "uint256.h"
#include <string>
+#include "version.h"
-#include <stdint.h>
+BOOST_AUTO_TEST_SUITE(uint256_tests)
+
+const unsigned char R1Array[] =
+ "\x9c\x52\x4a\xdb\xcf\x56\x11\x12\x2b\x29\x12\x5e\x5d\x35\xd2\xd2"
+ "\x22\x81\xaa\xb5\x33\xf0\x08\x32\xd5\x56\xb1\xf9\xea\xe5\x1d\x7d";
+const char R1ArrayHex[] = "7D1DE5EAF9B156D53208F033B5AA8122D2d2355d5e12292b121156cfdb4a529c";
+const double R1Ldouble = 0.4887374590559308955; // R1L equals roughly R1Ldouble * 2^256
+const double R1Sdouble = 0.7096329412477836074;
+const uint256 R1L = uint256(std::vector<unsigned char>(R1Array,R1Array+32));
+const uint160 R1S = uint160(std::vector<unsigned char>(R1Array,R1Array+20));
+const uint64_t R1LLow64 = 0x121156cfdb4a529cULL;
-#include <boost/test/unit_test.hpp>
+const unsigned char R2Array[] =
+ "\x70\x32\x1d\x7c\x47\xa5\x6b\x40\x26\x7e\x0a\xc3\xa6\x9c\xb6\xbf"
+ "\x13\x30\x47\xa3\x19\x2d\xda\x71\x49\x13\x72\xf0\xb4\xca\x81\xd7";
+const uint256 R2L = uint256(std::vector<unsigned char>(R2Array,R2Array+32));
+const uint160 R2S = uint160(std::vector<unsigned char>(R2Array,R2Array+20));
-BOOST_AUTO_TEST_SUITE(uint256_tests)
+const char R1LplusR2L[] = "549FB09FEA236A1EA3E31D4D58F1B1369288D204211CA751527CFC175767850C";
+
+const unsigned char ZeroArray[] =
+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
+const uint256 ZeroL = uint256(std::vector<unsigned char>(ZeroArray,ZeroArray+32));
+const uint160 ZeroS = uint160(std::vector<unsigned char>(ZeroArray,ZeroArray+20));
+
+const unsigned char OneArray[] =
+ "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
+const uint256 OneL = uint256(std::vector<unsigned char>(OneArray,OneArray+32));
+const uint160 OneS = uint160(std::vector<unsigned char>(OneArray,OneArray+20));
+
+const unsigned char MaxArray[] =
+ "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
+ "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
+const uint256 MaxL = uint256(std::vector<unsigned char>(MaxArray,MaxArray+32));
+const uint160 MaxS = uint160(std::vector<unsigned char>(MaxArray,MaxArray+20));
+
+const uint256 HalfL = (OneL << 255);
+const uint160 HalfS = (OneS << 159);
+std::string ArrayToString(const unsigned char A[], unsigned int width)
+{
+ std::stringstream Stream;
+ Stream << std::hex;
+ for (unsigned int i = 0; i < width; ++i)
+ {
+ Stream<<std::setw(2)<<std::setfill('0')<<(unsigned int)A[width-i-1];
+ }
+ return Stream.str();
+}
-BOOST_AUTO_TEST_CASE(uint256_equality)
+BOOST_AUTO_TEST_CASE( basics ) // constructors, equality, inequality
{
- uint256 num1 = 10;
- uint256 num2 = 11;
- BOOST_CHECK(num1+1 == num2);
+ BOOST_CHECK(1 == 0+1);
+ // constructor uint256(vector<char>):
+ BOOST_CHECK(R1L.ToString() == ArrayToString(R1Array,32));
+ BOOST_CHECK(R1S.ToString() == ArrayToString(R1Array,20));
+ BOOST_CHECK(R2L.ToString() == ArrayToString(R2Array,32));
+ BOOST_CHECK(R2S.ToString() == ArrayToString(R2Array,20));
+ BOOST_CHECK(ZeroL.ToString() == ArrayToString(ZeroArray,32));
+ BOOST_CHECK(ZeroS.ToString() == ArrayToString(ZeroArray,20));
+ BOOST_CHECK(OneL.ToString() == ArrayToString(OneArray,32));
+ BOOST_CHECK(OneS.ToString() == ArrayToString(OneArray,20));
+ BOOST_CHECK(MaxL.ToString() == ArrayToString(MaxArray,32));
+ BOOST_CHECK(MaxS.ToString() == ArrayToString(MaxArray,20));
+ BOOST_CHECK(OneL.ToString() != ArrayToString(ZeroArray,32));
+ BOOST_CHECK(OneS.ToString() != ArrayToString(ZeroArray,20));
+
+ // == and !=
+ BOOST_CHECK(R1L != R2L && R1S != R2S);
+ BOOST_CHECK(ZeroL != OneL && ZeroS != OneS);
+ BOOST_CHECK(OneL != ZeroL && OneS != ZeroS);
+ BOOST_CHECK(MaxL != ZeroL && MaxS != ZeroS);
+ BOOST_CHECK(~MaxL == ZeroL && ~MaxS == ZeroS);
+ BOOST_CHECK( ((R1L ^ R2L) ^ R1L) == R2L);
+ BOOST_CHECK( ((R1S ^ R2S) ^ R1S) == R2S);
+
+ uint64_t Tmp64 = 0xc4dab720d9c7acaaULL;
+ for (unsigned int i = 0; i < 256; ++i)
+ {
+ BOOST_CHECK(ZeroL != (OneL << i));
+ BOOST_CHECK((OneL << i) != ZeroL);
+ BOOST_CHECK(R1L != (R1L ^ (OneL << i)));
+ BOOST_CHECK(((uint256(Tmp64) ^ (OneL << i) ) != Tmp64 ));
+ }
+ BOOST_CHECK(ZeroL == (OneL << 256));
+
+ for (unsigned int i = 0; i < 160; ++i)
+ {
+ BOOST_CHECK(ZeroS != (OneS << i));
+ BOOST_CHECK((OneS << i) != ZeroS);
+ BOOST_CHECK(R1S != (R1S ^ (OneS << i)));
+ BOOST_CHECK(((uint160(Tmp64) ^ (OneS << i) ) != Tmp64 ));
+ }
+ BOOST_CHECK(ZeroS == (OneS << 256));
+
+ // String Constructor and Copy Constructor
+ BOOST_CHECK(uint256("0x"+R1L.ToString()) == R1L);
+ BOOST_CHECK(uint256("0x"+R2L.ToString()) == R2L);
+ BOOST_CHECK(uint256("0x"+ZeroL.ToString()) == ZeroL);
+ BOOST_CHECK(uint256("0x"+OneL.ToString()) == OneL);
+ BOOST_CHECK(uint256("0x"+MaxL.ToString()) == MaxL);
+ BOOST_CHECK(uint256(R1L.ToString()) == R1L);
+ BOOST_CHECK(uint256(" 0x"+R1L.ToString()+" ") == R1L);
+ BOOST_CHECK(uint256("") == ZeroL);
+ BOOST_CHECK(R1L == uint256(R1ArrayHex));
+ BOOST_CHECK(uint256(R1L) == R1L);
+ BOOST_CHECK((uint256(R1L^R2L)^R2L) == R1L);
+ BOOST_CHECK(uint256(ZeroL) == ZeroL);
+ BOOST_CHECK(uint256(OneL) == OneL);
+
+ BOOST_CHECK(uint160("0x"+R1S.ToString()) == R1S);
+ BOOST_CHECK(uint160("0x"+R2S.ToString()) == R2S);
+ BOOST_CHECK(uint160("0x"+ZeroS.ToString()) == ZeroS);
+ BOOST_CHECK(uint160("0x"+OneS.ToString()) == OneS);
+ BOOST_CHECK(uint160("0x"+MaxS.ToString()) == MaxS);
+ BOOST_CHECK(uint160(R1S.ToString()) == R1S);
+ BOOST_CHECK(uint160(" 0x"+R1S.ToString()+" ") == R1S);
+ BOOST_CHECK(uint160("") == ZeroS);
+ BOOST_CHECK(R1S == uint160(R1ArrayHex));
+
+ BOOST_CHECK(uint160(R1S) == R1S);
+ BOOST_CHECK((uint160(R1S^R2S)^R2S) == R1S);
+ BOOST_CHECK(uint160(ZeroS) == ZeroS);
+ BOOST_CHECK(uint160(OneS) == OneS);
+
+ // uint64_t constructor
+ BOOST_CHECK( (R1L & uint256("0xffffffffffffffff")) == uint256(R1LLow64));
+ BOOST_CHECK(ZeroL == uint256(0));
+ BOOST_CHECK(OneL == uint256(1));
+ BOOST_CHECK(uint256("0xffffffffffffffff") = uint256(0xffffffffffffffffULL));
+ BOOST_CHECK( (R1S & uint160("0xffffffffffffffff")) == uint160(R1LLow64));
+ BOOST_CHECK(ZeroS == uint160(0));
+ BOOST_CHECK(OneS == uint160(1));
+ BOOST_CHECK(uint160("0xffffffffffffffff") = uint160(0xffffffffffffffffULL));
+
+ // Assignment (from base_uint)
+ uint256 tmpL = ~ZeroL; BOOST_CHECK(tmpL == ~ZeroL);
+ tmpL = ~OneL; BOOST_CHECK(tmpL == ~OneL);
+ tmpL = ~R1L; BOOST_CHECK(tmpL == ~R1L);
+ tmpL = ~R2L; BOOST_CHECK(tmpL == ~R2L);
+ tmpL = ~MaxL; BOOST_CHECK(tmpL == ~MaxL);
+ uint160 tmpS = ~ZeroS; BOOST_CHECK(tmpS == ~ZeroS);
+ tmpS = ~OneS; BOOST_CHECK(tmpS == ~OneS);
+ tmpS = ~R1S; BOOST_CHECK(tmpS == ~R1S);
+ tmpS = ~R2S; BOOST_CHECK(tmpS == ~R2S);
+ tmpS = ~MaxS; BOOST_CHECK(tmpS == ~MaxS);
- uint64_t num3 = 10;
- BOOST_CHECK(num1 == num3);
- BOOST_CHECK(num1+num2 == num3+num2);
+ // Wrong length must give 0
+ BOOST_CHECK(uint256(std::vector<unsigned char>(OneArray,OneArray+31)) == 0);
+ BOOST_CHECK(uint256(std::vector<unsigned char>(OneArray,OneArray+20)) == 0);
+ BOOST_CHECK(uint160(std::vector<unsigned char>(OneArray,OneArray+32)) == 0);
+ BOOST_CHECK(uint160(std::vector<unsigned char>(OneArray,OneArray+19)) == 0);
}
-BOOST_AUTO_TEST_CASE(uint256_hex)
+void shiftArrayRight(unsigned char* to, const unsigned char* from, unsigned int arrayLength, unsigned int bitsToShift)
{
- std::string hexStr = "d35583ed493a5eee756931353144f558e6a9ab3ad6024a63ced7f10daf7faad9";
- uint256 num1;
- num1.SetHex(hexStr);
- BOOST_CHECK(num1.GetHex() == hexStr);
+ for (unsigned int T=0; T < arrayLength; ++T)
+ {
+ unsigned int F = (T+bitsToShift/8);
+ if (F < arrayLength)
+ to[T] = from[F] >> (bitsToShift%8);
+ else
+ to[T] = 0;
+ if (F + 1 < arrayLength)
+ to[T] |= from[(F+1)] << (8-bitsToShift%8);
+ }
+}
+
+void shiftArrayLeft(unsigned char* to, const unsigned char* from, unsigned int arrayLength, unsigned int bitsToShift)
+{
+ for (unsigned int T=0; T < arrayLength; ++T)
+ {
+ if (T >= bitsToShift/8)
+ {
+ unsigned int F = T-bitsToShift/8;
+ to[T] = from[F] << (bitsToShift%8);
+ if (T >= bitsToShift/8+1)
+ to[T] |= from[F-1] >> (8-bitsToShift%8);
+ }
+ else {
+ to[T] = 0;
+ }
+ }
+}
+
+BOOST_AUTO_TEST_CASE( shifts ) { // "<<" ">>" "<<=" ">>="
+ unsigned char TmpArray[32];
+ uint256 TmpL;
+ for (unsigned int i = 0; i < 256; ++i)
+ {
+ shiftArrayLeft(TmpArray, OneArray, 32, i);
+ BOOST_CHECK(uint256(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (OneL << i));
+ TmpL = OneL; TmpL <<= i;
+ BOOST_CHECK(TmpL == (OneL << i));
+ BOOST_CHECK((HalfL >> (255-i)) == (OneL << i));
+ TmpL = HalfL; TmpL >>= (255-i);
+ BOOST_CHECK(TmpL == (OneL << i));
+
+ shiftArrayLeft(TmpArray, R1Array, 32, i);
+ BOOST_CHECK(uint256(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (R1L << i));
+ TmpL = R1L; TmpL <<= i;
+ BOOST_CHECK(TmpL == (R1L << i));
+
+ shiftArrayRight(TmpArray, R1Array, 32, i);
+ BOOST_CHECK(uint256(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (R1L >> i));
+ TmpL = R1L; TmpL >>= i;
+ BOOST_CHECK(TmpL == (R1L >> i));
+
+ shiftArrayLeft(TmpArray, MaxArray, 32, i);
+ BOOST_CHECK(uint256(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (MaxL << i));
+ TmpL = MaxL; TmpL <<= i;
+ BOOST_CHECK(TmpL == (MaxL << i));
+
+ shiftArrayRight(TmpArray, MaxArray, 32, i);
+ BOOST_CHECK(uint256(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (MaxL >> i));
+ TmpL = MaxL; TmpL >>= i;
+ BOOST_CHECK(TmpL == (MaxL >> i));
+ }
+ uint256 c1L = uint256(0x0123456789abcdefULL);
+ uint256 c2L = c1L << 128;
+ for (unsigned int i = 0; i < 128; ++i) {
+ BOOST_CHECK((c1L << i) == (c2L >> (128-i)));
+ }
+ for (unsigned int i = 128; i < 256; ++i) {
+ BOOST_CHECK((c1L << i) == (c2L << (i-128)));
+ }
+
+ uint160 TmpS;
+ for (unsigned int i = 0; i < 160; ++i)
+ {
+ shiftArrayLeft(TmpArray, OneArray, 20, i);
+ BOOST_CHECK(uint160(std::vector<unsigned char>(TmpArray,TmpArray+20)) == (OneS << i));
+ TmpS = OneS; TmpS <<= i;
+ BOOST_CHECK(TmpS == (OneS << i));
+ BOOST_CHECK((HalfS >> (159-i)) == (OneS << i));
+ TmpS = HalfS; TmpS >>= (159-i);
+ BOOST_CHECK(TmpS == (OneS << i));
+
+ shiftArrayLeft(TmpArray, R1Array, 20, i);
+ BOOST_CHECK(uint160(std::vector<unsigned char>(TmpArray,TmpArray+20)) == (R1S << i));
+ TmpS = R1S; TmpS <<= i;
+ BOOST_CHECK(TmpS == (R1S << i));
+
+ shiftArrayRight(TmpArray, R1Array, 20, i);
+ BOOST_CHECK(uint160(std::vector<unsigned char>(TmpArray,TmpArray+20)) == (R1S >> i));
+ TmpS = R1S; TmpS >>= i;
+ BOOST_CHECK(TmpS == (R1S >> i));
+
+ shiftArrayLeft(TmpArray, MaxArray, 20, i);
+ BOOST_CHECK(uint160(std::vector<unsigned char>(TmpArray,TmpArray+20)) == (MaxS << i));
+ TmpS = MaxS; TmpS <<= i;
+ BOOST_CHECK(TmpS == (MaxS << i));
+
+ shiftArrayRight(TmpArray, MaxArray, 20, i);
+ BOOST_CHECK(uint160(std::vector<unsigned char>(TmpArray,TmpArray+20)) == (MaxS >> i));
+ TmpS = MaxS; TmpS >>= i;
+ BOOST_CHECK(TmpS == (MaxS >> i));
+ }
+ uint160 c1S = uint160(0x0123456789abcdefULL);
+ uint160 c2S = c1S << 80;
+ for (unsigned int i = 0; i < 80; ++i) {
+ BOOST_CHECK((c1S << i) == (c2S >> (80-i)));
+ }
+ for (unsigned int i = 80; i < 160; ++i) {
+ BOOST_CHECK((c1S << i) == (c2S << (i-80)));
+ }
+}
+
+BOOST_AUTO_TEST_CASE( unaryOperators ) // ! ~ -
+{
+ BOOST_CHECK(!ZeroL); BOOST_CHECK(!ZeroS);
+ BOOST_CHECK(!(!OneL));BOOST_CHECK(!(!OneS));
+ for (unsigned int i = 0; i < 256; ++i)
+ BOOST_CHECK(!(!(OneL<<i)));
+ for (unsigned int i = 0; i < 160; ++i)
+ BOOST_CHECK(!(!(OneS<<i)));
+ BOOST_CHECK(!(!R1L));BOOST_CHECK(!(!R1S));
+ BOOST_CHECK(!(!R2S));BOOST_CHECK(!(!R2S));
+ BOOST_CHECK(!(!MaxL));BOOST_CHECK(!(!MaxS));
+
+ BOOST_CHECK(~ZeroL == MaxL); BOOST_CHECK(~ZeroS == MaxS);
+
+ unsigned char TmpArray[32];
+ for (unsigned int i = 0; i < 32; ++i) { TmpArray[i] = ~R1Array[i]; }
+ BOOST_CHECK(uint256(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (~R1L));
+ BOOST_CHECK(uint160(std::vector<unsigned char>(TmpArray,TmpArray+20)) == (~R1S));
+
+ BOOST_CHECK(-ZeroL == ZeroL); BOOST_CHECK(-ZeroS == ZeroS);
+ BOOST_CHECK(-R1L == (~R1L)+1);
+ BOOST_CHECK(-R1S == (~R1S)+1);
+ for (unsigned int i = 0; i < 256; ++i)
+ BOOST_CHECK(-(OneL<<i) == (MaxL << i));
+ for (unsigned int i = 0; i < 160; ++i)
+ BOOST_CHECK(-(OneS<<i) == (MaxS << i));
+}
+
+
+// Check if doing _A_ _OP_ _B_ results in the same as applying _OP_ onto each
+// element of Aarray and Barray, and then converting the result into a uint256.
+#define CHECKBITWISEOPERATOR(_A_,_B_,_OP_) \
+ for (unsigned int i = 0; i < 32; ++i) { TmpArray[i] = _A_##Array[i] _OP_ _B_##Array[i]; } \
+ BOOST_CHECK(uint256(std::vector<unsigned char>(TmpArray,TmpArray+32)) == (_A_##L _OP_ _B_##L)); \
+ for (unsigned int i = 0; i < 20; ++i) { TmpArray[i] = _A_##Array[i] _OP_ _B_##Array[i]; } \
+ BOOST_CHECK(uint160(std::vector<unsigned char>(TmpArray,TmpArray+20)) == (_A_##S _OP_ _B_##S));
+
+#define CHECKASSIGNMENTOPERATOR(_A_,_B_,_OP_) \
+ TmpL = _A_##L; TmpL _OP_##= _B_##L; BOOST_CHECK(TmpL == (_A_##L _OP_ _B_##L)); \
+ TmpS = _A_##S; TmpS _OP_##= _B_##S; BOOST_CHECK(TmpS == (_A_##S _OP_ _B_##S));
+
+BOOST_AUTO_TEST_CASE( bitwiseOperators )
+{
+ unsigned char TmpArray[32];
+
+ CHECKBITWISEOPERATOR(R1,R2,|)
+ CHECKBITWISEOPERATOR(R1,R2,^)
+ CHECKBITWISEOPERATOR(R1,R2,&)
+ CHECKBITWISEOPERATOR(R1,Zero,|)
+ CHECKBITWISEOPERATOR(R1,Zero,^)
+ CHECKBITWISEOPERATOR(R1,Zero,&)
+ CHECKBITWISEOPERATOR(R1,Max,|)
+ CHECKBITWISEOPERATOR(R1,Max,^)
+ CHECKBITWISEOPERATOR(R1,Max,&)
+ CHECKBITWISEOPERATOR(Zero,R1,|)
+ CHECKBITWISEOPERATOR(Zero,R1,^)
+ CHECKBITWISEOPERATOR(Zero,R1,&)
+ CHECKBITWISEOPERATOR(Max,R1,|)
+ CHECKBITWISEOPERATOR(Max,R1,^)
+ CHECKBITWISEOPERATOR(Max,R1,&)
+
+ uint256 TmpL;
+ uint160 TmpS;
+ CHECKASSIGNMENTOPERATOR(R1,R2,|)
+ CHECKASSIGNMENTOPERATOR(R1,R2,^)
+ CHECKASSIGNMENTOPERATOR(R1,R2,&)
+ CHECKASSIGNMENTOPERATOR(R1,Zero,|)
+ CHECKASSIGNMENTOPERATOR(R1,Zero,^)
+ CHECKASSIGNMENTOPERATOR(R1,Zero,&)
+ CHECKASSIGNMENTOPERATOR(R1,Max,|)
+ CHECKASSIGNMENTOPERATOR(R1,Max,^)
+ CHECKASSIGNMENTOPERATOR(R1,Max,&)
+ CHECKASSIGNMENTOPERATOR(Zero,R1,|)
+ CHECKASSIGNMENTOPERATOR(Zero,R1,^)
+ CHECKASSIGNMENTOPERATOR(Zero,R1,&)
+ CHECKASSIGNMENTOPERATOR(Max,R1,|)
+ CHECKASSIGNMENTOPERATOR(Max,R1,^)
+ CHECKASSIGNMENTOPERATOR(Max,R1,&)
+
+ uint64_t Tmp64 = 0xe1db685c9a0b47a2ULL;
+ TmpL = R1L; TmpL |= Tmp64; BOOST_CHECK(TmpL == (R1L | uint256(Tmp64)));
+ TmpS = R1S; TmpS |= Tmp64; BOOST_CHECK(TmpS == (R1S | uint160(Tmp64)));
+ TmpL = R1L; TmpL |= 0; BOOST_CHECK(TmpL == R1L);
+ TmpS = R1S; TmpS |= 0; BOOST_CHECK(TmpS == R1S);
+ TmpL ^= 0; BOOST_CHECK(TmpL == R1L);
+ TmpS ^= 0; BOOST_CHECK(TmpS == R1S);
+ TmpL ^= Tmp64; BOOST_CHECK(TmpL == (R1L ^ uint256(Tmp64)));
+ TmpS ^= Tmp64; BOOST_CHECK(TmpS == (R1S ^ uint160(Tmp64)));
+}
+
+BOOST_AUTO_TEST_CASE( comparison ) // <= >= < >
+{
+ uint256 TmpL;
+ for (unsigned int i = 0; i < 256; ++i) {
+ TmpL= OneL<< i;
+ BOOST_CHECK( TmpL >= ZeroL && TmpL > ZeroL && ZeroL < TmpL && ZeroL <= TmpL);
+ BOOST_CHECK( TmpL >= 0 && TmpL > 0 && 0 < TmpL && 0 <= TmpL);
+ TmpL |= R1L;
+ BOOST_CHECK( TmpL >= R1L ); BOOST_CHECK( (TmpL == R1L) != (TmpL > R1L)); BOOST_CHECK( (TmpL == R1L) || !( TmpL <= R1L));
+ BOOST_CHECK( R1L <= TmpL ); BOOST_CHECK( (R1L == TmpL) != (R1L < TmpL)); BOOST_CHECK( (TmpL == R1L) || !( R1L >= TmpL));
+ BOOST_CHECK(! (TmpL < R1L)); BOOST_CHECK(! (R1L > TmpL));
+ }
+ uint160 TmpS;
+ for (unsigned int i = 0; i < 160; ++i) {
+ TmpS= OneS<< i;
+ BOOST_CHECK( TmpS >= ZeroS && TmpS > ZeroS && ZeroS < TmpS && ZeroS <= TmpS);
+ BOOST_CHECK( TmpS >= 0 && TmpS > 0 && 0 < TmpS && 0 <= TmpS);
+ TmpS |= R1S;
+ BOOST_CHECK( TmpS >= R1S ); BOOST_CHECK( (TmpS == R1S) != (TmpS > R1S)); BOOST_CHECK( (TmpS == R1S) || !( TmpS <= R1S));
+ BOOST_CHECK( R1S <= TmpS ); BOOST_CHECK( (R1S == TmpS) != (R1S < TmpS)); BOOST_CHECK( (TmpS == R1S) || !( R1S >= TmpS));
+ BOOST_CHECK(! (TmpS < R1S)); BOOST_CHECK(! (R1S > TmpS));
+ }
+}
+
+BOOST_AUTO_TEST_CASE( plusMinus )
+{
+ uint256 TmpL = 0;
+ BOOST_CHECK(R1L+R2L == uint256(R1LplusR2L));
+ TmpL += R1L;
+ BOOST_CHECK(TmpL == R1L);
+ TmpL += R2L;
+ BOOST_CHECK(TmpL == R1L + R2L);
+ BOOST_CHECK(OneL+MaxL == ZeroL);
+ BOOST_CHECK(MaxL+OneL == ZeroL);
+ for (unsigned int i = 1; i < 256; ++i) {
+ BOOST_CHECK( (MaxL >> i) + OneL == (HalfL >> (i-1)) );
+ BOOST_CHECK( OneL + (MaxL >> i) == (HalfL >> (i-1)) );
+ TmpL = (MaxL>>i); TmpL += OneL;
+ BOOST_CHECK( TmpL == (HalfL >> (i-1)) );
+ TmpL = (MaxL>>i); TmpL += 1;
+ BOOST_CHECK( TmpL == (HalfL >> (i-1)) );
+ TmpL = (MaxL>>i);
+ BOOST_CHECK( TmpL++ == (MaxL>>i) );
+ BOOST_CHECK( TmpL == (HalfL >> (i-1)));
+ }
+ BOOST_CHECK(uint256(0xbedc77e27940a7ULL) + 0xee8d836fce66fbULL == uint256(0xbedc77e27940a7ULL + 0xee8d836fce66fbULL));
+ TmpL = uint256(0xbedc77e27940a7ULL); TmpL += 0xee8d836fce66fbULL;
+ BOOST_CHECK(TmpL == uint256(0xbedc77e27940a7ULL+0xee8d836fce66fbULL));
+ TmpL -= 0xee8d836fce66fbULL; BOOST_CHECK(TmpL == 0xbedc77e27940a7ULL);
+ TmpL = R1L;
+ BOOST_CHECK(++TmpL == R1L+1);
+
+ BOOST_CHECK(R1L -(-R2L) == R1L+R2L);
+ BOOST_CHECK(R1L -(-OneL) == R1L+OneL);
+ BOOST_CHECK(R1L - OneL == R1L+(-OneL));
+ for (unsigned int i = 1; i < 256; ++i) {
+ BOOST_CHECK((MaxL>>i) - (-OneL) == (HalfL >> (i-1)));
+ BOOST_CHECK((HalfL >> (i-1)) - OneL == (MaxL>>i));
+ TmpL = (HalfL >> (i-1));
+ BOOST_CHECK(TmpL-- == (HalfL >> (i-1)));
+ BOOST_CHECK(TmpL == (MaxL >> i));
+ TmpL = (HalfL >> (i-1));
+ BOOST_CHECK(--TmpL == (MaxL >> i));
+ }
+ TmpL = R1L;
+ BOOST_CHECK(--TmpL == R1L-1);
+
+ // 160-bit; copy-pasted
+ uint160 TmpS = 0;
+ BOOST_CHECK(R1S+R2S == uint160(R1LplusR2L));
+ TmpS += R1S;
+ BOOST_CHECK(TmpS == R1S);
+ TmpS += R2S;
+ BOOST_CHECK(TmpS == R1S + R2S);
+ BOOST_CHECK(OneS+MaxS == ZeroS);
+ BOOST_CHECK(MaxS+OneS == ZeroS);
+ for (unsigned int i = 1; i < 160; ++i) {
+ BOOST_CHECK( (MaxS >> i) + OneS == (HalfS >> (i-1)) );
+ BOOST_CHECK( OneS + (MaxS >> i) == (HalfS >> (i-1)) );
+ TmpS = (MaxS>>i); TmpS += OneS;
+ BOOST_CHECK( TmpS == (HalfS >> (i-1)) );
+ TmpS = (MaxS>>i); TmpS += 1;
+ BOOST_CHECK( TmpS == (HalfS >> (i-1)) );
+ TmpS = (MaxS>>i);
+ BOOST_CHECK( TmpS++ == (MaxS>>i) );
+ BOOST_CHECK( TmpS == (HalfS >> (i-1)));
+ }
+ BOOST_CHECK(uint160(0xbedc77e27940a7ULL) + 0xee8d836fce66fbULL == uint160(0xbedc77e27940a7ULL + 0xee8d836fce66fbULL));
+ TmpS = uint160(0xbedc77e27940a7ULL); TmpS += 0xee8d836fce66fbULL;
+ BOOST_CHECK(TmpS == uint160(0xbedc77e27940a7ULL+0xee8d836fce66fbULL));
+ TmpS -= 0xee8d836fce66fbULL; BOOST_CHECK(TmpS == 0xbedc77e27940a7ULL);
+ TmpS = R1S;
+ BOOST_CHECK(++TmpS == R1S+1);
+
+ BOOST_CHECK(R1S -(-R2S) == R1S+R2S);
+ BOOST_CHECK(R1S -(-OneS) == R1S+OneS);
+ BOOST_CHECK(R1S - OneS == R1S+(-OneS));
+ for (unsigned int i = 1; i < 160; ++i) {
+ BOOST_CHECK((MaxS>>i) - (-OneS) == (HalfS >> (i-1)));
+ BOOST_CHECK((HalfS >> (i-1)) - OneS == (MaxS>>i));
+ TmpS = (HalfS >> (i-1));
+ BOOST_CHECK(TmpS-- == (HalfS >> (i-1)));
+ BOOST_CHECK(TmpS == (MaxS >> i));
+ TmpS = (HalfS >> (i-1));
+ BOOST_CHECK(--TmpS == (MaxS >> i));
+ }
+ TmpS = R1S;
+ BOOST_CHECK(--TmpS == R1S-1);
+
+}
+
+bool almostEqual(double d1, double d2)
+{
+ return fabs(d1-d2) <= 4*fabs(d1)*std::numeric_limits<double>::epsilon();
+}
+
+BOOST_AUTO_TEST_CASE( methods ) // GetHex SetHex begin() end() size() GetLow64 GetSerializeSize, Serialize, Unserialize
+{
+ BOOST_CHECK(R1L.GetHex() == R1L.ToString());
+ BOOST_CHECK(R2L.GetHex() == R2L.ToString());
+ BOOST_CHECK(OneL.GetHex() == OneL.ToString());
+ BOOST_CHECK(MaxL.GetHex() == MaxL.ToString());
+ uint256 TmpL(R1L);
+ BOOST_CHECK(TmpL == R1L);
+ TmpL.SetHex(R2L.ToString()); BOOST_CHECK(TmpL == R2L);
+ TmpL.SetHex(ZeroL.ToString()); BOOST_CHECK(TmpL == 0);
+ TmpL.SetHex(HalfL.ToString()); BOOST_CHECK(TmpL == HalfL);
+
+ TmpL.SetHex(R1L.ToString());
+ BOOST_CHECK(memcmp(R1L.begin(), R1Array, 32)==0);
+ BOOST_CHECK(memcmp(TmpL.begin(), R1Array, 32)==0);
+ BOOST_CHECK(memcmp(R2L.begin(), R2Array, 32)==0);
+ BOOST_CHECK(memcmp(ZeroL.begin(), ZeroArray, 32)==0);
+ BOOST_CHECK(memcmp(OneL.begin(), OneArray, 32)==0);
+ BOOST_CHECK(R1L.size() == 32);
+ BOOST_CHECK(R2L.size() == 32);
+ BOOST_CHECK(ZeroL.size() == 32);
+ BOOST_CHECK(MaxL.size() == 32);
+ BOOST_CHECK(R1L.begin() + 32 == R1L.end());
+ BOOST_CHECK(R2L.begin() + 32 == R2L.end());
+ BOOST_CHECK(OneL.begin() + 32 == OneL.end());
+ BOOST_CHECK(MaxL.begin() + 32 == MaxL.end());
+ BOOST_CHECK(TmpL.begin() + 32 == TmpL.end());
+ BOOST_CHECK(R1L.GetLow64() == R1LLow64);
+ BOOST_CHECK(HalfL.GetLow64() ==0x0000000000000000ULL);
+ BOOST_CHECK(OneL.GetLow64() ==0x0000000000000001ULL);
+ BOOST_CHECK(R1L.GetSerializeSize(0,PROTOCOL_VERSION) == 32);
+ BOOST_CHECK(ZeroL.GetSerializeSize(0,PROTOCOL_VERSION) == 32);
+
+ std::stringstream ss;
+ R1L.Serialize(ss,0,PROTOCOL_VERSION);
+ BOOST_CHECK(ss.str() == std::string(R1Array,R1Array+32));
+ TmpL.Unserialize(ss,0,PROTOCOL_VERSION);
+ BOOST_CHECK(R1L == TmpL);
+ ss.str("");
+ ZeroL.Serialize(ss,0,PROTOCOL_VERSION);
+ BOOST_CHECK(ss.str() == std::string(ZeroArray,ZeroArray+32));
+ TmpL.Unserialize(ss,0,PROTOCOL_VERSION);
+ BOOST_CHECK(ZeroL == TmpL);
+ ss.str("");
+ MaxL.Serialize(ss,0,PROTOCOL_VERSION);
+ BOOST_CHECK(ss.str() == std::string(MaxArray,MaxArray+32));
+ TmpL.Unserialize(ss,0,PROTOCOL_VERSION);
+ BOOST_CHECK(MaxL == TmpL);
+ ss.str("");
+
+ BOOST_CHECK(R1S.GetHex() == R1S.ToString());
+ BOOST_CHECK(R2S.GetHex() == R2S.ToString());
+ BOOST_CHECK(OneS.GetHex() == OneS.ToString());
+ BOOST_CHECK(MaxS.GetHex() == MaxS.ToString());
+ uint160 TmpS(R1S);
+ BOOST_CHECK(TmpS == R1S);
+ TmpS.SetHex(R2S.ToString()); BOOST_CHECK(TmpS == R2S);
+ TmpS.SetHex(ZeroS.ToString()); BOOST_CHECK(TmpS == 0);
+ TmpS.SetHex(HalfS.ToString()); BOOST_CHECK(TmpS == HalfS);
+
+ TmpS.SetHex(R1S.ToString());
+ BOOST_CHECK(memcmp(R1S.begin(), R1Array, 20)==0);
+ BOOST_CHECK(memcmp(TmpS.begin(), R1Array, 20)==0);
+ BOOST_CHECK(memcmp(R2S.begin(), R2Array, 20)==0);
+ BOOST_CHECK(memcmp(ZeroS.begin(), ZeroArray, 20)==0);
+ BOOST_CHECK(memcmp(OneS.begin(), OneArray, 20)==0);
+ BOOST_CHECK(R1S.size() == 20);
+ BOOST_CHECK(R2S.size() == 20);
+ BOOST_CHECK(ZeroS.size() == 20);
+ BOOST_CHECK(MaxS.size() == 20);
+ BOOST_CHECK(R1S.begin() + 20 == R1S.end());
+ BOOST_CHECK(R2S.begin() + 20 == R2S.end());
+ BOOST_CHECK(OneS.begin() + 20 == OneS.end());
+ BOOST_CHECK(MaxS.begin() + 20 == MaxS.end());
+ BOOST_CHECK(TmpS.begin() + 20 == TmpS.end());
+ BOOST_CHECK(R1S.GetLow64() == R1LLow64);
+ BOOST_CHECK(HalfS.GetLow64() ==0x0000000000000000ULL);
+ BOOST_CHECK(OneS.GetLow64() ==0x0000000000000001ULL);
+ BOOST_CHECK(R1S.GetSerializeSize(0,PROTOCOL_VERSION) == 20);
+ BOOST_CHECK(ZeroS.GetSerializeSize(0,PROTOCOL_VERSION) == 20);
+
+ R1S.Serialize(ss,0,PROTOCOL_VERSION);
+ BOOST_CHECK(ss.str() == std::string(R1Array,R1Array+20));
+ TmpS.Unserialize(ss,0,PROTOCOL_VERSION);
+ BOOST_CHECK(R1S == TmpS);
+ ss.str("");
+ ZeroS.Serialize(ss,0,PROTOCOL_VERSION);
+ BOOST_CHECK(ss.str() == std::string(ZeroArray,ZeroArray+20));
+ TmpS.Unserialize(ss,0,PROTOCOL_VERSION);
+ BOOST_CHECK(ZeroS == TmpS);
+ ss.str("");
+ MaxS.Serialize(ss,0,PROTOCOL_VERSION);
+ BOOST_CHECK(ss.str() == std::string(MaxArray,MaxArray+20));
+ TmpS.Unserialize(ss,0,PROTOCOL_VERSION);
+ BOOST_CHECK(MaxS == TmpS);
+ ss.str("");
+
+ for (unsigned int i = 0; i < 255; ++i)
+ {
+ BOOST_CHECK((OneL << i).getdouble() == ldexp(1.0,i));
+ if (i < 160) BOOST_CHECK((OneS << i).getdouble() == ldexp(1.0,i));
+ }
+ BOOST_CHECK(ZeroL.getdouble() == 0.0);
+ BOOST_CHECK(ZeroS.getdouble() == 0.0);
+ for (int i = 256; i > 53; --i)
+ BOOST_CHECK(almostEqual((R1L>>(256-i)).getdouble(), ldexp(R1Ldouble,i)));
+ for (int i = 160; i > 53; --i)
+ BOOST_CHECK(almostEqual((R1S>>(160-i)).getdouble(), ldexp(R1Sdouble,i)));
+ uint64_t R1L64part = (R1L>>192).GetLow64();
+ uint64_t R1S64part = (R1S>>96).GetLow64();
+ for (int i = 53; i > 0; --i) // doubles can store all integers in {0,...,2^54-1} exactly
+ {
+ BOOST_CHECK((R1L>>(256-i)).getdouble() == (double)(R1L64part >> (64-i)));
+ BOOST_CHECK((R1S>>(160-i)).getdouble() == (double)(R1S64part >> (64-i)));
+ }
+}
+
+BOOST_AUTO_TEST_CASE( getmaxcoverage ) // some more tests just to get 100% coverage
+{
+ // ~R1L give a base_uint<256>
+ BOOST_CHECK((~~R1L >> 10) == (R1L >> 10)); BOOST_CHECK((~~R1S >> 10) == (R1S >> 10));
+ BOOST_CHECK((~~R1L << 10) == (R1L << 10)); BOOST_CHECK((~~R1S << 10) == (R1S << 10));
+ BOOST_CHECK(!(~~R1L < R1L)); BOOST_CHECK(!(~~R1S < R1S));
+ BOOST_CHECK(~~R1L <= R1L); BOOST_CHECK(~~R1S <= R1S);
+ BOOST_CHECK(!(~~R1L > R1L)); BOOST_CHECK(!(~~R1S > R1S));
+ BOOST_CHECK(~~R1L >= R1L); BOOST_CHECK(~~R1S >= R1S);
+ BOOST_CHECK(!(R1L < ~~R1L)); BOOST_CHECK(!(R1S < ~~R1S));
+ BOOST_CHECK(R1L <= ~~R1L); BOOST_CHECK(R1S <= ~~R1S);
+ BOOST_CHECK(!(R1L > ~~R1L)); BOOST_CHECK(!(R1S > ~~R1S));
+ BOOST_CHECK(R1L >= ~~R1L); BOOST_CHECK(R1S >= ~~R1S);
+
+ BOOST_CHECK(~~R1L + R2L == R1L + ~~R2L);
+ BOOST_CHECK(~~R1S + R2S == R1S + ~~R2S);
+ BOOST_CHECK(~~R1L - R2L == R1L - ~~R2L);
+ BOOST_CHECK(~~R1S - R2S == R1S - ~~R2S);
+ BOOST_CHECK(~R1L != R1L); BOOST_CHECK(R1L != ~R1L);
+ BOOST_CHECK(~R1S != R1S); BOOST_CHECK(R1S != ~R1S);
+ unsigned char TmpArray[32];
+ CHECKBITWISEOPERATOR(~R1,R2,|)
+ CHECKBITWISEOPERATOR(~R1,R2,^)
+ CHECKBITWISEOPERATOR(~R1,R2,&)
+ CHECKBITWISEOPERATOR(R1,~R2,|)
+ CHECKBITWISEOPERATOR(R1,~R2,^)
+ CHECKBITWISEOPERATOR(R1,~R2,&)
}
BOOST_AUTO_TEST_SUITE_END()
+
diff --git a/src/txdb.cpp b/src/txdb.cpp
index 99deb31404..6ed0d18785 100644
--- a/src/txdb.cpp
+++ b/src/txdb.cpp
@@ -26,8 +26,8 @@ void static BatchWriteHashBestChain(CLevelDBBatch &batch, const uint256 &hash) {
CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool fMemory, bool fWipe) : db(GetDataDir() / "chainstate", nCacheSize, fMemory, fWipe) {
}
-bool CCoinsViewDB::GetCoins(const uint256 &txid, CCoins &coins) {
- return db.Read(make_pair('c', txid), coins);
+bool CCoinsViewDB::GetCoins(const uint256 &txid, CCoins &coins) {
+ return db.Read(make_pair('c', txid), coins);
}
bool CCoinsViewDB::SetCoins(const uint256 &txid, const CCoins &coins) {
@@ -37,7 +37,7 @@ bool CCoinsViewDB::SetCoins(const uint256 &txid, const CCoins &coins) {
}
bool CCoinsViewDB::HaveCoins(const uint256 &txid) {
- return db.Exists(make_pair('c', txid));
+ return db.Exists(make_pair('c', txid));
}
uint256 CCoinsViewDB::GetBestBlock() {
@@ -131,7 +131,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) {
ssKey >> txhash;
ss << txhash;
ss << VARINT(coins.nVersion);
- ss << (coins.fCoinBase ? 'c' : 'n');
+ ss << (coins.fCoinBase ? 'c' : 'n');
ss << VARINT(coins.nHeight);
stats.nTransactions++;
for (unsigned int i=0; i<coins.vout.size(); i++) {
@@ -148,7 +148,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) {
}
pcursor->Next();
} catch (std::exception &e) {
- return error("%s() : deserialize error", __PRETTY_FUNCTION__);
+ return error("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
}
}
delete pcursor;
@@ -226,7 +226,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
break; // if shutdown requested or finished loading block index
}
} catch (std::exception &e) {
- return error("%s() : deserialize error", __PRETTY_FUNCTION__);
+ return error("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
}
}
delete pcursor;
diff --git a/src/ui_interface.h b/src/ui_interface.h
index a14ed67814..677d097fa4 100644
--- a/src/ui_interface.h
+++ b/src/ui_interface.h
@@ -62,6 +62,8 @@ public:
/** Force blocking, modal message box dialog (not just OS notification) */
MODAL = 0x10000000U,
+ /** Don't bring GUI to foreground. Use for messages during initialization */
+ NOSHOWGUI = 0x20000000U,
/** Predefined combinations for certain default usage cases */
MSG_INFORMATION = ICON_INFORMATION,
diff --git a/src/uint256.h b/src/uint256.h
index 7dbb3f83bb..ba903bc8fc 100644
--- a/src/uint256.h
+++ b/src/uint256.h
@@ -19,9 +19,6 @@ inline signed char HexDigit(char c)
return p_util_hexdigit[(unsigned char)c];
}
-inline int Testuint256AdHoc(std::vector<std::string> vArg);
-
-
/** Base class without constructors for uint256 and uint160.
* This makes the compiler let you use it in a union.
*/
@@ -203,7 +200,7 @@ public:
{
// prefix operator
int i = 0;
- while (--pn[i] == -1 && i < WIDTH-1)
+ while (--pn[i] == (uint32_t)-1 && i < WIDTH-1)
i++;
return *this;
}
@@ -370,9 +367,10 @@ public:
return sizeof(pn);
}
- uint64_t Get64(int n=0) const
+ uint64_t GetLow64() const
{
- return pn[2*n] | (uint64_t)pn[2*n+1] << 32;
+ assert(WIDTH >= 2);
+ return pn[0] | (uint64_t)pn[1] << 32;
}
// unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const
@@ -398,7 +396,6 @@ public:
friend class uint160;
friend class uint256;
- friend inline int Testuint256AdHoc(std::vector<std::string> vArg);
};
typedef base_uint<160> base_uint160;
@@ -525,9 +522,6 @@ inline const uint160 operator-(const uint160& a, const uint160& b) { r
-
-
-
//////////////////////////////////////////////////////////////////////////////
//
// uint256
@@ -638,147 +632,4 @@ inline const uint256 operator|(const uint256& a, const uint256& b) { return
inline const uint256 operator+(const uint256& a, const uint256& b) { return (base_uint256)a + (base_uint256)b; }
inline const uint256 operator-(const uint256& a, const uint256& b) { return (base_uint256)a - (base_uint256)b; }
-
-
-
-
-
-
-
-
-
-#ifdef TEST_UINT256
-
-inline int Testuint256AdHoc(std::vector<std::string> vArg)
-{
- uint256 g(0);
-
-
- LogPrintf("%s\n", g.ToString().c_str());
- g--; LogPrintf("g--\n");
- LogPrintf("%s\n", g.ToString().c_str());
- g--; LogPrintf("g--\n");
- LogPrintf("%s\n", g.ToString().c_str());
- g++; LogPrintf("g++\n");
- LogPrintf("%s\n", g.ToString().c_str());
- g++; LogPrintf("g++\n");
- LogPrintf("%s\n", g.ToString().c_str());
- g++; LogPrintf("g++\n");
- LogPrintf("%s\n", g.ToString().c_str());
- g++; LogPrintf("g++\n");
- LogPrintf("%s\n", g.ToString().c_str());
-
-
-
- uint256 a(7);
- LogPrintf("a=7\n");
- LogPrintf("%s\n", a.ToString().c_str());
-
- uint256 b;
- LogPrintf("b undefined\n");
- LogPrintf("%s\n", b.ToString().c_str());
- int c = 3;
-
- a = c;
- a.pn[3] = 15;
- LogPrintf("%s\n", a.ToString().c_str());
- uint256 k(c);
-
- a = 5;
- a.pn[3] = 15;
- LogPrintf("%s\n", a.ToString().c_str());
- b = 1;
- b <<= 52;
-
- a |= b;
-
- a ^= 0x500;
-
- LogPrintf("a %s\n", a.ToString().c_str());
-
- a = a | b | (uint256)0x1000;
-
-
- LogPrintf("a %s\n", a.ToString().c_str());
- LogPrintf("b %s\n", b.ToString().c_str());
-
- a = 0xfffffffe;
- a.pn[4] = 9;
-
- LogPrintf("%s\n", a.ToString().c_str());
- a++;
- LogPrintf("%s\n", a.ToString().c_str());
- a++;
- LogPrintf("%s\n", a.ToString().c_str());
- a++;
- LogPrintf("%s\n", a.ToString().c_str());
- a++;
- LogPrintf("%s\n", a.ToString().c_str());
-
- a--;
- LogPrintf("%s\n", a.ToString().c_str());
- a--;
- LogPrintf("%s\n", a.ToString().c_str());
- a--;
- LogPrintf("%s\n", a.ToString().c_str());
- uint256 d = a--;
- LogPrintf("%s\n", d.ToString().c_str());
- LogPrintf("%s\n", a.ToString().c_str());
- a--;
- LogPrintf("%s\n", a.ToString().c_str());
- a--;
- LogPrintf("%s\n", a.ToString().c_str());
-
- d = a;
-
- LogPrintf("%s\n", d.ToString().c_str());
- for (int i = uint256::WIDTH-1; i >= 0; i--) LogPrintf("%08x", d.pn[i]); LogPrintf("\n");
-
- uint256 neg = d;
- neg = ~neg;
- LogPrintf("%s\n", neg.ToString().c_str());
-
-
- uint256 e = uint256("0xABCDEF123abcdef12345678909832180000011111111");
- LogPrintf("\n");
- LogPrintf("%s\n", e.ToString().c_str());
-
-
- LogPrintf("\n");
- uint256 x1 = uint256("0xABCDEF123abcdef12345678909832180000011111111");
- uint256 x2;
- LogPrintf("%s\n", x1.ToString().c_str());
- for (int i = 0; i < 270; i += 4)
- {
- x2 = x1 << i;
- LogPrintf("%s\n", x2.ToString().c_str());
- }
-
- LogPrintf("\n");
- LogPrintf("%s\n", x1.ToString().c_str());
- for (int i = 0; i < 270; i += 4)
- {
- x2 = x1;
- x2 >>= i;
- LogPrintf("%s\n", x2.ToString().c_str());
- }
-
-
- for (int i = 0; i < 100; i++)
- {
- uint256 k = (~uint256(0) >> i);
- LogPrintf("%s\n", k.ToString().c_str());
- }
-
- for (int i = 0; i < 100; i++)
- {
- uint256 k = (~uint256(0) << i);
- LogPrintf("%s\n", k.ToString().c_str());
- }
-
- return (0);
-}
-
-#endif
-
#endif
diff --git a/src/util.cpp b/src/util.cpp
index bedf59767b..280798f2fb 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -88,7 +88,7 @@ map<string, string> mapArgs;
map<string, vector<string> > mapMultiArgs;
bool fDebug = false;
bool fPrintToConsole = false;
-bool fPrintToDebugger = false;
+bool fPrintToDebugLog = true;
bool fDaemon = false;
bool fServer = false;
string strMiscWarning;
@@ -270,7 +270,7 @@ int LogPrint(const char* category, const char* pszFormat, ...)
ret += vprintf(pszFormat, arg_ptr);
va_end(arg_ptr);
}
- else if (!fPrintToDebugger)
+ else if (fPrintToDebugLog)
{
static bool fStartedNewLine = true;
boost::call_once(&DebugPrintInit, debugPrintInitFlag);
@@ -302,29 +302,6 @@ int LogPrint(const char* category, const char* pszFormat, ...)
va_end(arg_ptr);
}
-#ifdef WIN32
- if (fPrintToDebugger)
- {
- // accumulate and output a line at a time
- static std::string buffer;
-
- boost::mutex::scoped_lock scoped_lock(*mutexDebugLog);
-
- va_list arg_ptr;
- va_start(arg_ptr, pszFormat);
- buffer += vstrprintf(pszFormat, arg_ptr);
- va_end(arg_ptr);
-
- int line_start = 0, line_end;
- while((line_end = buffer.find('\n', line_start)) != -1)
- {
- OutputDebugStringA(buffer.substr(line_start, line_end - line_start).c_str());
- line_start = line_end + 1;
- ret += line_end-line_start;
- }
- buffer.erase(0, line_start);
- }
-#endif
return ret;
}
diff --git a/src/util.h b/src/util.h
index 9c7f185f13..3922872e06 100644
--- a/src/util.h
+++ b/src/util.h
@@ -120,7 +120,7 @@ extern std::map<std::string, std::string> mapArgs;
extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
extern bool fDebug;
extern bool fPrintToConsole;
-extern bool fPrintToDebugger;
+extern bool fPrintToDebugLog;
extern bool fDaemon;
extern bool fServer;
extern std::string strMiscWarning;
diff --git a/src/wallet.cpp b/src/wallet.cpp
index cfaa0d6b9f..9065ba8483 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -16,6 +16,8 @@
using namespace std;
+// Settings
+int64_t nTransactionFee = 0;
//////////////////////////////////////////////////////////////////////////////
//
diff --git a/src/wallet.h b/src/wallet.h
index feb5cbf0c7..e4452a3093 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -23,6 +23,9 @@
#include <utility>
#include <vector>
+// Settings
+extern int64_t nTransactionFee;
+
class CAccountingEntry;
class CCoinControl;
class COutput;