aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/wallettools/README.md4
-rw-r--r--doc/multiwallet-qt.md14
-rw-r--r--src/main.cpp16
-rw-r--r--src/miner.cpp16
-rw-r--r--src/qt/Makefile.am6
-rw-r--r--src/qt/bitcoingui.cpp5
-rw-r--r--src/qt/bitcoingui.h8
-rw-r--r--src/qt/walletframe.cpp117
-rw-r--r--src/qt/walletframe.h16
-rw-r--r--src/qt/walletstack.cpp174
-rw-r--r--src/qt/walletstack.h104
-rw-r--r--src/qt/walletview.cpp35
-rw-r--r--src/qt/walletview.h3
-rw-r--r--src/serialize.h6
-rw-r--r--src/test/serialize_tests.cpp60
-rw-r--r--src/wallet.cpp17
16 files changed, 238 insertions, 363 deletions
diff --git a/contrib/wallettools/README.md b/contrib/wallettools/README.md
index 358f52569e..3a71ba1436 100644
--- a/contrib/wallettools/README.md
+++ b/contrib/wallettools/README.md
@@ -1,2 +1,4 @@
### Wallet Tools ###
-Contains a wallet change password and unlock script.
+These are two simple python scripts which send the appropriate RPC commands to unlock a wallet and change a wallet password. **They are intended to prevent users from having to enter their password as a command-line argument which could then be stored in the console buffer/history in plaintext.**
+
+Both tools rely on bitcoin/bitcoind running with `server=1` and an `rpcuser` and `rpcpassword` set in `bitcoin.conf`. They can be easily modified for non-standard ports. [walletunlock.py](/contrib/wallettools/walletunlock.py) unlocks the wallet for 60 seconds by default, changeable in code, and both modules rely upon python-json-rpc.
diff --git a/doc/multiwallet-qt.md b/doc/multiwallet-qt.md
index 8d695552b5..3caab81807 100644
--- a/doc/multiwallet-qt.md
+++ b/doc/multiwallet-qt.md
@@ -4,7 +4,7 @@ Multiwallet Qt Development and Integration Strategy
In order to support loading of multiple wallets in bitcoin-qt, a few changes in the UI architecture will be needed.
Fortunately, only four of the files in the existing project are affected by this change.
-Three new classes have been implemented in three new .h/.cpp file pairs, with much of the functionality that was previously
+Two new classes have been implemented in two new .h/.cpp file pairs, with much of the functionality that was previously
implemented in the BitcoinGUI class moved over to these new classes.
The two existing files most affected, by far, are bitcoingui.h and bitcoingui.cpp, as the BitcoinGUI class will require
@@ -12,7 +12,7 @@ some major retrofitting.
Only requiring some minor changes is bitcoin.cpp.
-Finally, three new headers and source files will have to be added to bitcoin-qt.pro.
+Finally, two new headers and source files will have to be added to bitcoin-qt.pro.
Changes to class BitcoinGUI
---------------------------
@@ -23,13 +23,9 @@ A new class called *WalletView* inheriting from QStackedWidget has been written
these page views. In addition to owning these five page views, a WalletView also has a pointer to a WalletModel instance.
This allows the construction of multiple WalletView objects, each rendering a distinct wallet.
-A second class called *WalletStack*, also inheriting from QStackedWidget, has been written to handle switching focus between
-different loaded wallets. In its current implementation, as a QStackedWidget, only one wallet can be viewed at a time -
-but this can be changed later.
-
-A third class called *WalletFrame* inheriting from QFrame has been written as a container for embedding all wallet-related
-controls into BitcoinGUI. At present it just contains a WalletStack instance and does little more than passing on messages
-from BitcoinGUI to the WalletStack, which in turn passes them to the individual WalletViews. It is a WalletFrame instance
+A second class called *WalletFrame* inheriting from QFrame has been written as a container for embedding all wallet-related
+controls into BitcoinGUI. At present it contains the WalletView instances for the wallets and does little more than passing on messages
+from BitcoinGUI to the currently selected WalletView. It is a WalletFrame instance
that takes the place of what used to be centralWidget in BitcoinGUI. The purpose of this class is to allow future
refinements of the wallet controls with minimal need for further modifications to BitcoinGUI, thus greatly simplifying
merges while reducing the risk of breaking top-level stuff.
diff --git a/src/main.cpp b/src/main.cpp
index 215a7ba620..ba2e83ce76 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -722,15 +722,18 @@ int64 GetMinFee(const CTransaction& tx, bool fAllowFree, enum GetMinFee_mode mod
{
// There is a free transaction area in blocks created by most miners,
// * If we are relaying we allow transactions up to DEFAULT_BLOCK_PRIORITY_SIZE - 1000
- // to be considered to fall into this category
- // * If we are creating a transaction we allow transactions up to DEFAULT_BLOCK_PRIORITY_SIZE - 17000
- // (= 10000) to be considered safe and assume they can likely make it into this section
- if (nBytes < (mode == GMF_SEND ? (DEFAULT_BLOCK_PRIORITY_SIZE - 17000) : (DEFAULT_BLOCK_PRIORITY_SIZE - 1000)))
+ // to be considered to fall into this category. We don't want to encourage sending
+ // multiple transactions instead of one big transaction to avoid fees.
+ // * If we are creating a transaction we allow transactions up to 1,000 bytes
+ // to be considered safe and assume they can likely make it into this section.
+ if (nBytes < (mode == GMF_SEND ? 1000 : (DEFAULT_BLOCK_PRIORITY_SIZE - 1000)))
nMinFee = 0;
}
- // To limit dust spam, require base fee if any output is less than 0.01
- if (nMinFee < nBaseFee)
+ // This code can be removed after enough miners have upgraded to version 0.9.
+ // Until then, be safe when sending and require a fee if any output
+ // is less than CENT:
+ if (nMinFee < nBaseFee && mode == GMF_SEND)
{
BOOST_FOREACH(const CTxOut& txout, tx.vout)
if (txout.nValue < CENT)
@@ -3674,7 +3677,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
vector<uint256> vWorkQueue;
vector<uint256> vEraseQueue;
- CDataStream vMsg(vRecv);
CTransaction tx;
vRecv >> tx;
diff --git a/src/miner.cpp b/src/miner.cpp
index e9c1d9aff9..83684fa349 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -238,9 +238,21 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
}
if (fMissingInputs) continue;
- // Priority is sum(valuein * age) / txsize
+ // Priority is sum(valuein * age) / modified_txsize
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
- dPriority /= nTxSize;
+ unsigned int nTxSizeMod = nTxSize;
+ // In order to avoid disincentivizing cleaning up the UTXO set we don't count
+ // the constant overhead for each txin and up to 110 bytes of scriptSig (which
+ // is enough to cover a compressed pubkey p2sh redemption) for priority.
+ // Providing any more cleanup incentive than making additional inputs free would
+ // risk encouraging people to create junk outputs to redeem later.
+ BOOST_FOREACH(const CTxIn& txin, tx.vin)
+ {
+ unsigned int offset = 41U + min(110U, (unsigned int)txin.scriptSig.size());
+ if (nTxSizeMod > offset)
+ nTxSizeMod -= offset;
+ }
+ dPriority /= nTxSizeMod;
// This is a more accurate fee-per-kilobyte than is used by the client code, because the
// client code rounds up the size to the nearest 1K. That's good, because it gives an
diff --git a/src/qt/Makefile.am b/src/qt/Makefile.am
index e7ae0a905f..5892f6aca0 100644
--- a/src/qt/Makefile.am
+++ b/src/qt/Makefile.am
@@ -51,7 +51,7 @@ QT_MOC_CPP = moc_aboutdialog.cpp moc_addressbookpage.cpp \
moc_signverifymessagedialog.cpp moc_splashscreen.cpp moc_trafficgraphwidget.cpp moc_transactiondesc.cpp \
moc_transactiondescdialog.cpp moc_transactionfilterproxy.cpp \
moc_transactiontablemodel.cpp moc_transactionview.cpp moc_walletframe.cpp \
- moc_walletmodel.cpp moc_walletstack.cpp moc_walletview.cpp
+ moc_walletmodel.cpp moc_walletview.cpp
BITCOIN_MM = macdockiconhandler.mm macnotificationhandler.mm
QR_CPP = qrcodedialog.cpp
@@ -75,7 +75,7 @@ BITCOIN_QT_H = aboutdialog.h addressbookpage.h addresstablemodel.h \
sendcoinsdialog.h sendcoinsentry.h signverifymessagedialog.h splashscreen.h \
trafficgraphwidget.h transactiondescdialog.h transactiondesc.h transactionfilterproxy.h \
transactionrecord.h transactiontablemodel.h transactionview.h walletframe.h \
- walletmodel.h walletmodeltransaction.h walletstack.h walletview.h
+ walletmodel.h walletmodeltransaction.h walletview.h
RES_ICONS = res/icons/bitcoin.png res/icons/address-book.png \
res/icons/quit.png res/icons/send.png res/icons/toolbar.png \
@@ -105,7 +105,7 @@ BITCOIN_QT_CPP = aboutdialog.cpp addressbookpage.cpp \
signverifymessagedialog.cpp splashscreen.cpp trafficgraphwidget.cpp transactiondesc.cpp \
transactiondescdialog.cpp transactionfilterproxy.cpp transactionrecord.cpp \
transactiontablemodel.cpp transactionview.cpp walletframe.cpp \
- walletmodel.cpp walletmodeltransaction.cpp walletstack.cpp walletview.cpp
+ walletmodel.cpp walletmodeltransaction.cpp walletview.cpp
RES_IMAGES = res/images/about.png res/images/splash.png \
res/images/splash_testnet.png
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index 23a221120f..3336a8afd3 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -447,26 +447,31 @@ void BitcoinGUI::aboutClicked()
void BitcoinGUI::gotoOverviewPage()
{
+ overviewAction->setChecked(true);
if (walletFrame) walletFrame->gotoOverviewPage();
}
void BitcoinGUI::gotoHistoryPage()
{
+ historyAction->setChecked(true);
if (walletFrame) walletFrame->gotoHistoryPage();
}
void BitcoinGUI::gotoAddressBookPage()
{
+ addressBookAction->setChecked(true);
if (walletFrame) walletFrame->gotoAddressBookPage();
}
void BitcoinGUI::gotoReceiveCoinsPage()
{
+ receiveCoinsAction->setChecked(true);
if (walletFrame) walletFrame->gotoReceiveCoinsPage();
}
void BitcoinGUI::gotoSendCoinsPage(QString addr)
{
+ sendCoinsAction->setChecked(true);
if (walletFrame) walletFrame->gotoSendCoinsPage(addr);
}
diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h
index e2dd5dc6bc..e5a92fed93 100644
--- a/src/qt/bitcoingui.h
+++ b/src/qt/bitcoingui.h
@@ -61,14 +61,6 @@ public:
void removeAllWallets();
- /** Used by WalletView to allow access to needed QActions */
- // Todo: Use Qt signals for these
- QAction * getOverviewAction() { return overviewAction; }
- QAction * getHistoryAction() { return historyAction; }
- QAction * getAddressBookAction() { return addressBookAction; }
- QAction * getReceiveCoinsAction() { return receiveCoinsAction; }
- QAction * getSendCoinsAction() { return sendCoinsAction; }
-
protected:
void changeEvent(QEvent *e);
void closeEvent(QCloseEvent *event);
diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp
index 8d6a1b387e..f754bd5e71 100644
--- a/src/qt/walletframe.cpp
+++ b/src/qt/walletframe.cpp
@@ -5,20 +5,21 @@
* The Bitcoin Developers 2011-2013
*/
#include "walletframe.h"
+#include "walletview.h"
#include "bitcoingui.h"
-#include "walletstack.h"
#include <QHBoxLayout>
#include <QMessageBox>
+#include <QStackedWidget>
WalletFrame::WalletFrame(BitcoinGUI *_gui) :
- QFrame(_gui)
+ QFrame(_gui),
+ gui(_gui)
{
// Leave HBox hook for adding a list view later
QHBoxLayout *walletFrameLayout = new QHBoxLayout(this);
setContentsMargins(0,0,0,0);
- walletStack = new WalletStack(this);
- walletStack->setBitcoinGUI(_gui);
+ walletStack = new QStackedWidget(this);
walletFrameLayout->setContentsMargins(0,0,0,0);
walletFrameLayout->addWidget(walletStack);
}
@@ -29,95 +30,157 @@ WalletFrame::~WalletFrame()
void WalletFrame::setClientModel(ClientModel *clientModel)
{
- if (clientModel)
- walletStack->setClientModel(clientModel);
+ this->clientModel = clientModel;
}
bool WalletFrame::addWallet(const QString& name, WalletModel *walletModel)
{
- return walletStack->addWallet(name, walletModel);
+ if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
+ return false;
+
+ WalletView *walletView = new WalletView(this);
+ walletView->setBitcoinGUI(gui);
+ walletView->setClientModel(clientModel);
+ walletView->setWalletModel(walletModel);
+ walletView->showOutOfSyncWarning(bOutOfSync);
+
+ /* TODO we should goto the currently selected page once dynamically adding wallets is supported */
+ walletView->gotoOverviewPage();
+ walletStack->addWidget(walletView);
+ mapWalletViews[name] = walletView;
+
+ // Ensure a walletView is able to show the main window
+ connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
+
+ return true;
}
bool WalletFrame::setCurrentWallet(const QString& name)
{
- // TODO: Check if valid name
- return walletStack->setCurrentWallet(name);
+ if (mapWalletViews.count(name) == 0)
+ return false;
+
+ WalletView *walletView = mapWalletViews.value(name);
+ walletStack->setCurrentWidget(walletView);
+ walletView->setEncryptionStatus();
+ return true;
+}
+
+bool WalletFrame::removeWallet(const QString &name)
+{
+ if (mapWalletViews.count(name) == 0)
+ return false;
+
+ WalletView *walletView = mapWalletViews.take(name);
+ walletStack->removeWidget(walletView);
+ return true;
}
void WalletFrame::removeAllWallets()
{
- walletStack->removeAllWallets();
+ QMap<QString, WalletView*>::const_iterator i;
+ for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
+ walletStack->removeWidget(i.value());
+ mapWalletViews.clear();
}
bool WalletFrame::handlePaymentRequest(const SendCoinsRecipient &recipient)
{
- return walletStack->handlePaymentRequest(recipient);
+ WalletView *walletView = (WalletView*)walletStack->currentWidget();
+ if (!walletView)
+ return false;
+
+ return walletView->handlePaymentRequest(recipient);
}
void WalletFrame::showOutOfSyncWarning(bool fShow)
{
- if (!walletStack)
- return;
-
- walletStack->showOutOfSyncWarning(fShow);
+ bOutOfSync = fShow;
+ QMap<QString, WalletView*>::const_iterator i;
+ for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
+ i.value()->showOutOfSyncWarning(fShow);
}
void WalletFrame::gotoOverviewPage()
{
- walletStack->gotoOverviewPage();
+ QMap<QString, WalletView*>::const_iterator i;
+ for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
+ i.value()->gotoOverviewPage();
}
void WalletFrame::gotoHistoryPage()
{
- walletStack->gotoHistoryPage();
+ QMap<QString, WalletView*>::const_iterator i;
+ for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
+ i.value()->gotoHistoryPage();
}
void WalletFrame::gotoAddressBookPage()
{
- walletStack->gotoAddressBookPage();
+ QMap<QString, WalletView*>::const_iterator i;
+ for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
+ i.value()->gotoAddressBookPage();
}
void WalletFrame::gotoReceiveCoinsPage()
{
- walletStack->gotoReceiveCoinsPage();
+ QMap<QString, WalletView*>::const_iterator i;
+ for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
+ i.value()->gotoReceiveCoinsPage();
}
void WalletFrame::gotoSendCoinsPage(QString addr)
{
- walletStack->gotoSendCoinsPage(addr);
+ QMap<QString, WalletView*>::const_iterator i;
+ for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
+ i.value()->gotoSendCoinsPage(addr);
}
void WalletFrame::gotoSignMessageTab(QString addr)
{
- walletStack->gotoSignMessageTab(addr);
+ WalletView *walletView = (WalletView*)walletStack->currentWidget();
+ if (walletView)
+ walletView->gotoSignMessageTab(addr);
}
void WalletFrame::gotoVerifyMessageTab(QString addr)
{
- walletStack->gotoSignMessageTab(addr);
+ WalletView *walletView = (WalletView*)walletStack->currentWidget();
+ if (walletView)
+ walletView->gotoVerifyMessageTab(addr);
}
void WalletFrame::encryptWallet(bool status)
{
- walletStack->encryptWallet(status);
+ WalletView *walletView = (WalletView*)walletStack->currentWidget();
+ if (walletView)
+ walletView->encryptWallet(status);
}
void WalletFrame::backupWallet()
{
- walletStack->backupWallet();
+ WalletView *walletView = (WalletView*)walletStack->currentWidget();
+ if (walletView)
+ walletView->backupWallet();
}
void WalletFrame::changePassphrase()
{
- walletStack->changePassphrase();
+ WalletView *walletView = (WalletView*)walletStack->currentWidget();
+ if (walletView)
+ walletView->changePassphrase();
}
void WalletFrame::unlockWallet()
{
- walletStack->unlockWallet();
+ WalletView *walletView = (WalletView*)walletStack->currentWidget();
+ if (walletView)
+ walletView->unlockWallet();
}
void WalletFrame::setEncryptionStatus()
{
- walletStack->setEncryptionStatus();
+ WalletView *walletView = (WalletView*)walletStack->currentWidget();
+ if (walletView)
+ walletView->setEncryptionStatus();
}
diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h
index eaae053ccd..5011987963 100644
--- a/src/qt/walletframe.h
+++ b/src/qt/walletframe.h
@@ -8,12 +8,17 @@
#define WALLETFRAME_H
#include <QFrame>
+#include <QMap>
class BitcoinGUI;
class ClientModel;
class SendCoinsRecipient;
class WalletModel;
-class WalletStack;
+class WalletView;
+
+QT_BEGIN_NAMESPACE
+class QStackedWidget;
+QT_END_NAMESPACE
class WalletFrame : public QFrame
{
@@ -27,7 +32,7 @@ public:
bool addWallet(const QString& name, WalletModel *walletModel);
bool setCurrentWallet(const QString& name);
-
+ bool removeWallet(const QString &name);
void removeAllWallets();
bool handlePaymentRequest(const SendCoinsRecipient& recipient);
@@ -35,7 +40,12 @@ public:
void showOutOfSyncWarning(bool fShow);
private:
- WalletStack *walletStack;
+ QStackedWidget *walletStack;
+ BitcoinGUI *gui;
+ ClientModel *clientModel;
+ QMap<QString, WalletView*> mapWalletViews;
+
+ bool bOutOfSync;
public slots:
/** Switch to overview (home) page */
diff --git a/src/qt/walletstack.cpp b/src/qt/walletstack.cpp
deleted file mode 100644
index 4ef87aed52..0000000000
--- a/src/qt/walletstack.cpp
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Qt4 bitcoin GUI.
- *
- * W.J. van der Laan 2011-2012
- * The Bitcoin Developers 2011-2013
- */
-#include "walletstack.h"
-#include "walletview.h"
-#include "bitcoingui.h"
-
-#include <QMap>
-#include <QMessageBox>
-
-WalletStack::WalletStack(QWidget *parent) :
- QStackedWidget(parent),
- gui(0),
- clientModel(0),
- bOutOfSync(true)
-{
- setContentsMargins(0,0,0,0);
-}
-
-WalletStack::~WalletStack()
-{
-}
-
-bool WalletStack::addWallet(const QString& name, WalletModel *walletModel)
-{
- if (!gui || !clientModel || !walletModel || mapWalletViews.count(name) > 0)
- return false;
-
- WalletView *walletView = new WalletView(this, gui);
- walletView->setBitcoinGUI(gui);
- walletView->setClientModel(clientModel);
- walletView->setWalletModel(walletModel);
- walletView->showOutOfSyncWarning(bOutOfSync);
- addWidget(walletView);
- mapWalletViews[name] = walletView;
-
- // Ensure a walletView is able to show the main window
- connect(walletView, SIGNAL(showNormalIfMinimized()), gui, SLOT(showNormalIfMinimized()));
-
- return true;
-}
-
-bool WalletStack::removeWallet(const QString& name)
-{
- if (mapWalletViews.count(name) == 0)
- return false;
-
- WalletView *walletView = mapWalletViews.take(name);
- removeWidget(walletView);
- return true;
-}
-
-void WalletStack::removeAllWallets()
-{
- QMap<QString, WalletView*>::const_iterator i;
- for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
- removeWidget(i.value());
- mapWalletViews.clear();
-}
-
-bool WalletStack::handlePaymentRequest(const SendCoinsRecipient &recipient)
-{
- WalletView *walletView = (WalletView*)currentWidget();
- if (!walletView)
- return false;
-
- return walletView->handlePaymentRequest(recipient);
-}
-
-void WalletStack::showOutOfSyncWarning(bool fShow)
-{
- bOutOfSync = fShow;
- QMap<QString, WalletView*>::const_iterator i;
- for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
- i.value()->showOutOfSyncWarning(fShow);
-}
-
-void WalletStack::gotoOverviewPage()
-{
- QMap<QString, WalletView*>::const_iterator i;
- for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
- i.value()->gotoOverviewPage();
-}
-
-void WalletStack::gotoHistoryPage()
-{
- QMap<QString, WalletView*>::const_iterator i;
- for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
- i.value()->gotoHistoryPage();
-}
-
-void WalletStack::gotoAddressBookPage()
-{
- QMap<QString, WalletView*>::const_iterator i;
- for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
- i.value()->gotoAddressBookPage();
-}
-
-void WalletStack::gotoReceiveCoinsPage()
-{
- QMap<QString, WalletView*>::const_iterator i;
- for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
- i.value()->gotoReceiveCoinsPage();
-}
-
-void WalletStack::gotoSendCoinsPage(QString addr)
-{
- QMap<QString, WalletView*>::const_iterator i;
- for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i)
- i.value()->gotoSendCoinsPage(addr);
-}
-
-void WalletStack::gotoSignMessageTab(QString addr)
-{
- WalletView *walletView = (WalletView*)currentWidget();
- if (walletView)
- walletView->gotoSignMessageTab(addr);
-}
-
-void WalletStack::gotoVerifyMessageTab(QString addr)
-{
- WalletView *walletView = (WalletView*)currentWidget();
- if (walletView)
- walletView->gotoVerifyMessageTab(addr);
-}
-
-void WalletStack::encryptWallet(bool status)
-{
- WalletView *walletView = (WalletView*)currentWidget();
- if (walletView)
- walletView->encryptWallet(status);
-}
-
-void WalletStack::backupWallet()
-{
- WalletView *walletView = (WalletView*)currentWidget();
- if (walletView)
- walletView->backupWallet();
-}
-
-void WalletStack::changePassphrase()
-{
- WalletView *walletView = (WalletView*)currentWidget();
- if (walletView)
- walletView->changePassphrase();
-}
-
-void WalletStack::unlockWallet()
-{
- WalletView *walletView = (WalletView*)currentWidget();
- if (walletView)
- walletView->unlockWallet();
-}
-
-void WalletStack::setEncryptionStatus()
-{
- WalletView *walletView = (WalletView*)currentWidget();
- if (walletView)
- walletView->setEncryptionStatus();
-}
-
-bool WalletStack::setCurrentWallet(const QString& name)
-{
- if (mapWalletViews.count(name) == 0)
- return false;
-
- WalletView *walletView = mapWalletViews.value(name);
- setCurrentWidget(walletView);
- walletView->setEncryptionStatus();
- return true;
-}
diff --git a/src/qt/walletstack.h b/src/qt/walletstack.h
deleted file mode 100644
index 74b9f09081..0000000000
--- a/src/qt/walletstack.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Qt4 bitcoin GUI.
- *
- * W.J. van der Laan 2011-2012
- * The Bitcoin Developers 2011-2013
- */
-#ifndef WALLETSTACK_H
-#define WALLETSTACK_H
-
-#include <QStackedWidget>
-#include <QMap>
-#include <boost/shared_ptr.hpp>
-
-class BitcoinGUI;
-class TransactionTableModel;
-class ClientModel;
-class WalletModel;
-class WalletView;
-class TransactionView;
-class OverviewPage;
-class AddressBookPage;
-class SendCoinsDialog;
-class SendCoinsRecipient;
-class SignVerifyMessageDialog;
-class Notificator;
-class RPCConsole;
-
-class CWalletManager;
-
-QT_BEGIN_NAMESPACE
-class QLabel;
-class QModelIndex;
-QT_END_NAMESPACE
-
-/*
- WalletStack class. This class is a container for WalletView instances. It takes the place of centralWidget.
- It was added to support multiple wallet functionality. It communicates with both the client and the
- wallet models to give the user an up-to-date view of the current core state. It manages all the wallet views
- it contains and updates them accordingly.
- */
-class WalletStack : public QStackedWidget
-{
- Q_OBJECT
-
-public:
- explicit WalletStack(QWidget *parent = 0);
- ~WalletStack();
-
- void setBitcoinGUI(BitcoinGUI *gui) { this->gui = gui; }
-
- void setClientModel(ClientModel *clientModel) { this->clientModel = clientModel; }
-
- bool addWallet(const QString& name, WalletModel *walletModel);
- bool removeWallet(const QString& name);
-
- void removeAllWallets();
-
- bool handlePaymentRequest(const SendCoinsRecipient &recipient);
-
- void showOutOfSyncWarning(bool fShow);
-
-private:
- BitcoinGUI *gui;
- ClientModel *clientModel;
- QMap<QString, WalletView*> mapWalletViews;
-
- bool bOutOfSync;
-
-public slots:
- bool setCurrentWallet(const QString& name);
-
- /** Switch to overview (home) page */
- void gotoOverviewPage();
- /** Switch to history (transactions) page */
- void gotoHistoryPage();
- /** Switch to address book page */
- void gotoAddressBookPage();
- /** Switch to receive coins page */
- void gotoReceiveCoinsPage();
- /** Switch to send coins page */
- void gotoSendCoinsPage(QString addr = "");
-
- /** Show Sign/Verify Message dialog and switch to sign message tab */
- void gotoSignMessageTab(QString addr = "");
- /** Show Sign/Verify Message dialog and switch to verify message tab */
- void gotoVerifyMessageTab(QString addr = "");
-
- /** Encrypt the wallet */
- void encryptWallet(bool status);
- /** Backup the wallet */
- void backupWallet();
- /** Change encrypted wallet passphrase */
- void changePassphrase();
- /** Ask for passphrase to unlock wallet temporarily */
- void unlockWallet();
-
- /** Set the encryption status as shown in the UI.
- @param[in] status current encryption status
- @see WalletModel::EncryptionStatus
- */
- void setEncryptionStatus();
-};
-
-#endif // WALLETSTACK_H
diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp
index efb74efaa0..d7cef971ed 100644
--- a/src/qt/walletview.cpp
+++ b/src/qt/walletview.cpp
@@ -29,9 +29,9 @@
#include <QFileDialog>
#include <QPushButton>
-WalletView::WalletView(QWidget *parent, BitcoinGUI *_gui):
+WalletView::WalletView(QWidget *parent):
QStackedWidget(parent),
- gui(_gui),
+ gui(0),
clientModel(0),
walletModel(0)
{
@@ -54,12 +54,8 @@ WalletView::WalletView(QWidget *parent, BitcoinGUI *_gui):
transactionsPage->setLayout(vbox);
addressBookPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::SendingTab);
-
receiveCoinsPage = new AddressBookPage(AddressBookPage::ForEditing, AddressBookPage::ReceivingTab);
-
- sendCoinsPage = new SendCoinsDialog(gui);
-
- signVerifyMessageDialog = new SignVerifyMessageDialog(gui);
+ sendCoinsPage = new SendCoinsDialog();
addWidget(overviewPage);
addWidget(transactionsPage);
@@ -68,7 +64,6 @@ WalletView::WalletView(QWidget *parent, BitcoinGUI *_gui):
addWidget(sendCoinsPage);
// Clicking on a transaction on the overview page simply sends you to transaction history page
- connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), this, SLOT(gotoHistoryPage()));
connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
// Double-clicking on a transaction on the transaction history page shows details
@@ -82,8 +77,6 @@ WalletView::WalletView(QWidget *parent, BitcoinGUI *_gui):
connect(receiveCoinsPage, SIGNAL(signMessage(QString)), this, SLOT(gotoSignMessageTab(QString)));
// Clicking on "Export" allows to export the transaction list
connect(exportButton, SIGNAL(clicked()), transactionView, SLOT(exportClicked()));
-
- gotoOverviewPage();
}
WalletView::~WalletView()
@@ -93,6 +86,10 @@ WalletView::~WalletView()
void WalletView::setBitcoinGUI(BitcoinGUI *gui)
{
this->gui = gui;
+ if(gui)
+ {
+ connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage()));
+ }
}
void WalletView::setClientModel(ClientModel *clientModel)
@@ -109,7 +106,7 @@ void WalletView::setClientModel(ClientModel *clientModel)
void WalletView::setWalletModel(WalletModel *walletModel)
{
this->walletModel = walletModel;
- if (walletModel)
+ if (walletModel && gui)
{
// Receive and report messages from wallet thread
connect(walletModel, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
@@ -120,7 +117,6 @@ void WalletView::setWalletModel(WalletModel *walletModel)
addressBookPage->setModel(walletModel->getAddressTableModel());
receiveCoinsPage->setModel(walletModel->getAddressTableModel());
sendCoinsPage->setModel(walletModel);
- signVerifyMessageDialog->setModel(walletModel);
setEncryptionStatus();
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));
@@ -152,31 +148,26 @@ void WalletView::incomingTransaction(const QModelIndex& parent, int start, int /
void WalletView::gotoOverviewPage()
{
- gui->getOverviewAction()->setChecked(true);
setCurrentWidget(overviewPage);
}
void WalletView::gotoHistoryPage()
{
- gui->getHistoryAction()->setChecked(true);
setCurrentWidget(transactionsPage);
}
void WalletView::gotoAddressBookPage()
{
- gui->getAddressBookAction()->setChecked(true);
setCurrentWidget(addressBookPage);
}
void WalletView::gotoReceiveCoinsPage()
{
- gui->getReceiveCoinsAction()->setChecked(true);
setCurrentWidget(receiveCoinsPage);
}
void WalletView::gotoSendCoinsPage(QString addr)
{
- gui->getSendCoinsAction()->setChecked(true);
setCurrentWidget(sendCoinsPage);
if (!addr.isEmpty())
@@ -185,7 +176,10 @@ void WalletView::gotoSendCoinsPage(QString addr)
void WalletView::gotoSignMessageTab(QString addr)
{
- // call show() in showTab_SM()
+ // calls show() in showTab_SM()
+ SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(this);
+ signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
+ signVerifyMessageDialog->setModel(walletModel);
signVerifyMessageDialog->showTab_SM(true);
if (!addr.isEmpty())
@@ -194,7 +188,10 @@ void WalletView::gotoSignMessageTab(QString addr)
void WalletView::gotoVerifyMessageTab(QString addr)
{
- // call show() in showTab_VM()
+ // calls show() in showTab_VM()
+ SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(this);
+ signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);
+ signVerifyMessageDialog->setModel(walletModel);
signVerifyMessageDialog->showTab_VM(true);
if (!addr.isEmpty())
diff --git a/src/qt/walletview.h b/src/qt/walletview.h
index ce4e051098..e3ff253d3c 100644
--- a/src/qt/walletview.h
+++ b/src/qt/walletview.h
@@ -36,7 +36,7 @@ class WalletView : public QStackedWidget
Q_OBJECT
public:
- explicit WalletView(QWidget *parent, BitcoinGUI *_gui);
+ explicit WalletView(QWidget *parent);
~WalletView();
void setBitcoinGUI(BitcoinGUI *gui);
@@ -64,7 +64,6 @@ private:
AddressBookPage *addressBookPage;
AddressBookPage *receiveCoinsPage;
SendCoinsDialog *sendCoinsPage;
- SignVerifyMessageDialog *signVerifyMessageDialog;
TransactionView *transactionView;
diff --git a/src/serialize.h b/src/serialize.h
index e3d9939bcc..ca3c962240 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -216,18 +216,24 @@ uint64 ReadCompactSize(Stream& is)
unsigned short xSize;
READDATA(is, xSize);
nSizeRet = xSize;
+ if (nSizeRet < 253)
+ throw std::ios_base::failure("non-canonical ReadCompactSize()");
}
else if (chSize == 254)
{
unsigned int xSize;
READDATA(is, xSize);
nSizeRet = xSize;
+ if (nSizeRet < 0x10000u)
+ throw std::ios_base::failure("non-canonical ReadCompactSize()");
}
else
{
uint64 xSize;
READDATA(is, xSize);
nSizeRet = xSize;
+ if (nSizeRet < 0x100000000LLu)
+ throw std::ios_base::failure("non-canonical ReadCompactSize()");
}
if (nSizeRet > (uint64)MAX_SIZE)
throw std::ios_base::failure("ReadCompactSize() : size too large");
diff --git a/src/test/serialize_tests.cpp b/src/test/serialize_tests.cpp
index 19ffdcab66..50139df09e 100644
--- a/src/test/serialize_tests.cpp
+++ b/src/test/serialize_tests.cpp
@@ -39,7 +39,67 @@ BOOST_AUTO_TEST_CASE(varints)
ss >> VARINT(j);
BOOST_CHECK_MESSAGE(i == j, "decoded:" << j << " expected:" << i);
}
+}
+
+BOOST_AUTO_TEST_CASE(compactsize)
+{
+ CDataStream ss(SER_DISK, 0);
+ vector<char>::size_type i, j;
+
+ for (i = 1; i <= MAX_SIZE; i *= 2)
+ {
+ WriteCompactSize(ss, i-1);
+ WriteCompactSize(ss, i);
+ }
+ for (i = 1; i <= MAX_SIZE; i *= 2)
+ {
+ j = ReadCompactSize(ss);
+ BOOST_CHECK_MESSAGE((i-1) == j, "decoded:" << j << " expected:" << (i-1));
+ j = ReadCompactSize(ss);
+ BOOST_CHECK_MESSAGE(i == j, "decoded:" << j << " expected:" << i);
+ }
+}
+
+static bool isCanonicalException(const std::ios_base::failure& ex)
+{
+ return std::string("non-canonical ReadCompactSize()") == ex.what();
+}
+
+BOOST_AUTO_TEST_CASE(noncanonical)
+{
+ // Write some non-canonical CompactSize encodings, and
+ // make sure an exception is thrown when read back.
+ CDataStream ss(SER_DISK, 0);
+ vector<char>::size_type n;
+
+ // zero encoded with three bytes:
+ ss.write("\xfd\x00\x00", 3);
+ BOOST_CHECK_EXCEPTION(ReadCompactSize(ss), std::ios_base::failure, isCanonicalException);
+
+ // 0xfc encoded with three bytes:
+ ss.write("\xfd\xfc\x00", 3);
+ BOOST_CHECK_EXCEPTION(ReadCompactSize(ss), std::ios_base::failure, isCanonicalException);
+
+ // 0xfd encoded with three bytes is OK:
+ ss.write("\xfd\xfd\x00", 3);
+ n = ReadCompactSize(ss);
+ BOOST_CHECK(n == 0xfd);
+
+ // zero encoded with five bytes:
+ ss.write("\xfe\x00\x00\x00\x00", 5);
+ BOOST_CHECK_EXCEPTION(ReadCompactSize(ss), std::ios_base::failure, isCanonicalException);
+
+ // 0xffff encoded with five bytes:
+ ss.write("\xfe\xff\xff\x00\x00", 5);
+ BOOST_CHECK_EXCEPTION(ReadCompactSize(ss), std::ios_base::failure, isCanonicalException);
+
+ // zero encoded with nine bytes:
+ ss.write("\xff\x00\x00\x00\x00\x00\x00\x00\x00", 9);
+ BOOST_CHECK_EXCEPTION(ReadCompactSize(ss), std::ios_base::failure, isCanonicalException);
+ // 0x01ffffff encoded with nine bytes:
+ ss.write("\xff\xff\xff\xff\x01\x00\x00\x00\x00", 9);
+ BOOST_CHECK_EXCEPTION(ReadCompactSize(ss), std::ios_base::failure, isCanonicalException);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 0f0ce7e631..6f61cfc734 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -1231,9 +1231,10 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend,
}
int64 nChange = nValueIn - nValue - nFeeRet;
- // if sub-cent change is required, the fee must be raised to at least nMinTxFee
- // or until nChange becomes zero
- // NOTE: this depends on the exact behaviour of GetMinFee
+ // The following if statement should be removed once enough miners
+ // have upgraded to the 0.9 GetMinFee() rules. Until then, this avoids
+ // creating free transactions that have change outputs less than
+ // CENT bitcoins.
if (nFeeRet < CTransaction::nMinTxFee && nChange > 0 && nChange < CENT)
{
int64 nMoveToFee = min(nChange, CTransaction::nMinTxFee - nFeeRet);
@@ -1299,7 +1300,15 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend,
strFailReason = _("Transaction too large");
return false;
}
- dPriority /= nBytes;
+ unsigned int nTxSizeMod = nBytes;
+ // See miner.c's dPriority logic for the matching network-node side code.
+ BOOST_FOREACH(const CTxIn& txin, (*(CTransaction*)&wtxNew).vin)
+ {
+ unsigned int offset = 41U + min(110U, (unsigned int)txin.scriptSig.size());
+ if (nTxSizeMod > offset)
+ nTxSizeMod -= offset;
+ }
+ dPriority /= nTxSizeMod;
// Check that enough fee is included
int64 nPayFee = nTransactionFee * (1 + (int64)nBytes / 1000);