aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bitcoinrpc.cpp38
-rw-r--r--src/main.cpp2
-rw-r--r--src/qt/addressbookpage.cpp10
-rw-r--r--src/qt/bitcoingui.cpp2
-rw-r--r--src/qt/forms/aboutdialog.ui9
-rw-r--r--src/qt/forms/qrcodedialog.ui15
-rw-r--r--src/qt/qrcodedialog.cpp82
-rw-r--r--src/qt/qrcodedialog.h4
-rw-r--r--src/util.cpp2
-rw-r--r--src/util.h20
10 files changed, 96 insertions, 88 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index 2525c2d5db..7c991144d3 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -1281,14 +1281,21 @@ Value listtransactions(const Array& params, bool fHelp)
if (params.size() > 2)
nFrom = params[2].get_int();
+ if (nCount < 0)
+ throw JSONRPCError(-8, "Negative count");
+ if (nFrom < 0)
+ throw JSONRPCError(-8, "Negative from");
+
Array ret;
CWalletDB walletdb(pwalletMain->strWalletFile);
- // Firs: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap:
+ // First: get all CWalletTx and CAccountingEntry into a sorted-by-time multimap.
typedef pair<CWalletTx*, CAccountingEntry*> TxPair;
typedef multimap<int64, TxPair > TxItems;
TxItems txByTime;
+ // Note: maintaining indices in the database of (account,time) --> txid and (account, time) --> acentry
+ // would make this much faster for applications that do this a lot.
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
CWalletTx* wtx = &((*it).second);
@@ -1301,10 +1308,8 @@ Value listtransactions(const Array& params, bool fHelp)
txByTime.insert(make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry)));
}
- // Now: iterate backwards until we have nCount items to return:
- TxItems::reverse_iterator it = txByTime.rbegin();
- if (txByTime.size() > nFrom) std::advance(it, nFrom);
- for (; it != txByTime.rend(); ++it)
+ // iterate backwards until we have nCount items to return:
+ for (TxItems::reverse_iterator it = txByTime.rbegin(); it != txByTime.rend(); ++it)
{
CWalletTx *const pwtx = (*it).second.first;
if (pwtx != 0)
@@ -1313,18 +1318,21 @@ Value listtransactions(const Array& params, bool fHelp)
if (pacentry != 0)
AcentryToJSON(*pacentry, strAccount, ret);
- if (ret.size() >= nCount) break;
+ if (ret.size() >= (nCount+nFrom)) break;
}
- // ret is now newest to oldest
+ // ret is newest to oldest
- // Make sure we return only last nCount items (sends-to-self might give us an extra):
- if (ret.size() > nCount)
- {
- Array::iterator last = ret.begin();
- std::advance(last, nCount);
- ret.erase(last, ret.end());
- }
- std::reverse(ret.begin(), ret.end()); // oldest to newest
+ if (nFrom > ret.size()) nFrom = ret.size();
+ if (nFrom+nCount > ret.size()) nCount = ret.size()-nFrom;
+ Array::iterator first = ret.begin();
+ std::advance(first, nFrom);
+ Array::iterator last = ret.begin();
+ std::advance(last, nFrom+nCount);
+
+ if (last != ret.end()) ret.erase(last, ret.end());
+ if (first != ret.begin()) ret.erase(ret.begin(), first);
+
+ std::reverse(ret.begin(), ret.end()); // Return oldest to newest
return ret;
}
diff --git a/src/main.cpp b/src/main.cpp
index b9c9db7a62..bdafae8eb8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3361,8 +3361,6 @@ void static BitcoinMiner(CWallet *pwallet)
while (fGenerateBitcoins)
{
- if (AffinityBugWorkaround(ThreadBitcoinMiner))
- return;
if (fShutdown)
return;
while (vNodes.empty() || IsInitialBlockDownload())
diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp
index 88212835de..3e55c39e04 100644
--- a/src/qt/addressbookpage.cpp
+++ b/src/qt/addressbookpage.cpp
@@ -310,16 +310,12 @@ void AddressBookPage::on_showQRCode_clicked()
QTableView *table = ui->tableView;
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);
-
- QRCodeDialog *d;
foreach (QModelIndex index, indexes)
{
- QString address = index.data().toString(),
- label = index.sibling(index.row(), 0).data().toString(),
- title = QString("%1 << %2 >>").arg(label).arg(address);
+ QString address = index.data().toString(), label = index.sibling(index.row(), 0).data(Qt::EditRole).toString();
- QRCodeDialog *d = new QRCodeDialog(title, address, label, tab == ReceivingTab, this);
- d->show();
+ QRCodeDialog *dialog = new QRCodeDialog(address, label, tab == ReceivingTab, this);
+ dialog->show();
}
#endif
}
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index 9c1e05d0c1..3c31f291c2 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -388,7 +388,7 @@ void BitcoinGUI::createTrayIcon()
#else
// Note: On Mac, the dock icon is used to provide the tray's functionality.
MacDockIconHandler *dockIconHandler = MacDockIconHandler::instance();
- connect(dockIconHandler, SIGNAL(dockIconClicked()), openBitcoinAction, SLOT(trigger()));
+ connect(dockIconHandler, SIGNAL(dockIconClicked()), toggleHideAction, SLOT(trigger()));
trayIconMenu = dockIconHandler->dockMenu();
#endif
diff --git a/src/qt/forms/aboutdialog.ui b/src/qt/forms/aboutdialog.ui
index 127b90965a..6e342e5e8a 100644
--- a/src/qt/forms/aboutdialog.ui
+++ b/src/qt/forms/aboutdialog.ui
@@ -52,6 +52,9 @@
<property name="text">
<string>&lt;b&gt;Bitcoin&lt;/b&gt; version</string>
</property>
+ <property name="textInteractionFlags">
+ <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
</widget>
</item>
<item>
@@ -62,6 +65,9 @@
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
+ <property name="textInteractionFlags">
+ <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
</widget>
</item>
<item>
@@ -93,6 +99,9 @@ This product includes software developed by the OpenSSL Project for use in the O
<property name="wordWrap">
<bool>true</bool>
</property>
+ <property name="textInteractionFlags">
+ <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
</widget>
</item>
<item>
diff --git a/src/qt/forms/qrcodedialog.ui b/src/qt/forms/qrcodedialog.ui
index fa21f60b9e..714b1d6cd8 100644
--- a/src/qt/forms/qrcodedialog.ui
+++ b/src/qt/forms/qrcodedialog.ui
@@ -34,6 +34,9 @@
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
</widget>
</item>
<item>
@@ -44,7 +47,7 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="QCheckBox" name="chkReq">
+ <widget class="QCheckBox" name="chkReqPayment">
<property name="enabled">
<bool>true</bool>
</property>
@@ -56,7 +59,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
- <widget class="QLabel" name="lblAm1">
+ <widget class="QLabel" name="lblAmount">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
@@ -91,7 +94,7 @@
</widget>
</item>
<item>
- <widget class="QLabel" name="lblAm2">
+ <widget class="QLabel" name="lblBTC">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
@@ -113,7 +116,7 @@
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
- <widget class="QLabel" name="label_3">
+ <widget class="QLabel" name="lblLabel">
<property name="text">
<string>Label:</string>
</property>
@@ -136,7 +139,7 @@
</widget>
</item>
<item row="1" column="0">
- <widget class="QLabel" name="label_4">
+ <widget class="QLabel" name="lblMessage">
<property name="text">
<string>Message:</string>
</property>
@@ -194,7 +197,7 @@
<resources/>
<connections>
<connection>
- <sender>chkReq</sender>
+ <sender>chkReqPayment</sender>
<signal>clicked(bool)</signal>
<receiver>lnReqAmount</receiver>
<slot>setEnabled(bool)</slot>
diff --git a/src/qt/qrcodedialog.cpp b/src/qt/qrcodedialog.cpp
index 82959831de..9965f1438f 100644
--- a/src/qt/qrcodedialog.cpp
+++ b/src/qt/qrcodedialog.cpp
@@ -8,21 +8,19 @@
#include <qrencode.h>
-#define EXPORT_IMAGE_SIZE 256
+#define EXPORT_IMAGE_SIZE 256
-QRCodeDialog::QRCodeDialog(const QString &title, const QString &addr, const QString &label, bool enableReq, QWidget *parent) :
- QDialog(parent),
- ui(new Ui::QRCodeDialog),
- address(addr)
+QRCodeDialog::QRCodeDialog(const QString &addr, const QString &label, bool enableReq, QWidget *parent) :
+ QDialog(parent), ui(new Ui::QRCodeDialog), address(addr)
{
ui->setupUi(this);
- setWindowTitle(title);
+ setWindowTitle(QString("%1").arg(address));
setAttribute(Qt::WA_DeleteOnClose);
- ui->chkReq->setVisible(enableReq);
+ ui->chkReqPayment->setVisible(enableReq);
ui->lnReqAmount->setVisible(enableReq);
- ui->lblAm1->setVisible(enableReq);
- ui->lblAm2->setVisible(enableReq);
+ ui->lblAmount->setVisible(enableReq);
+ ui->lblBTC->setVisible(enableReq);
ui->lnLabel->setText(label);
@@ -37,19 +35,28 @@ QRCodeDialog::~QRCodeDialog()
void QRCodeDialog::genCode()
{
QString uri = getURI();
- //qDebug() << "Encoding:" << uri.toUtf8().constData();
- QRcode *code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
- myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
- myImage.fill(0xffffff);
- unsigned char *p = code->data;
- for(int y = 0; y < code->width; y++) {
- for(int x = 0; x < code->width; x++) {
- myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
- p++;
+
+ if (uri != "")
+ {
+ ui->lblQRCode->setText("");
+
+ QRcode *code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
+ myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
+ myImage.fill(0xffffff);
+ unsigned char *p = code->data;
+ for (int y = 0; y < code->width; y++)
+ {
+ for (int x = 0; x < code->width; x++)
+ {
+ myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
+ p++;
+ }
}
+ QRcode_free(code);
+ ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300));
}
- QRcode_free(code);
- ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300));
+ else
+ ui->lblQRCode->setText(tr("Resulting URI too long, try to reduce the text for label / message."));
}
QString QRCodeDialog::getURI()
@@ -57,41 +64,49 @@ QString QRCodeDialog::getURI()
QString ret = QString("bitcoin:%1").arg(address);
int paramCount = 0;
- if(ui->chkReq->isChecked() && ui->lnReqAmount->text().isEmpty() == false) {
- bool ok= false;
- double amount = ui->lnReqAmount->text().toDouble(&ok);
- if(ok) {
- ret += QString("?amount=%1X8").arg(ui->lnReqAmount->text());
+ if (ui->chkReqPayment->isChecked() && !ui->lnReqAmount->text().isEmpty())
+ {
+ bool ok = false;
+ ui->lnReqAmount->text().toDouble(&ok);
+ if (ok)
+ {
+ ret += QString("?amount=%1").arg(ui->lnReqAmount->text());
paramCount++;
}
}
- if(ui->lnLabel->text().isEmpty() == false) {
+ if (!ui->lnLabel->text().isEmpty())
+ {
QString lbl(QUrl::toPercentEncoding(ui->lnLabel->text()));
ret += QString("%1label=%2").arg(paramCount == 0 ? "?" : "&").arg(lbl);
paramCount++;
}
- if(ui->lnMessage->text().isEmpty() == false) {
+ if (!ui->lnMessage->text().isEmpty())
+ {
QString msg(QUrl::toPercentEncoding(ui->lnMessage->text()));
ret += QString("%1message=%2").arg(paramCount == 0 ? "?" : "&").arg(msg);
paramCount++;
}
- return ret;
+ // limit URI length to 255 chars, to prevent a DoS against the QR-Code dialog
+ if (ret.length() < 256)
+ return ret;
+ else
+ return QString("");
}
-void QRCodeDialog::on_lnReqAmount_textChanged(const QString &)
+void QRCodeDialog::on_lnReqAmount_textChanged(const QString &arg1)
{
genCode();
}
-void QRCodeDialog::on_lnLabel_textChanged(const QString &)
+void QRCodeDialog::on_lnLabel_textChanged(const QString &arg1)
{
genCode();
}
-void QRCodeDialog::on_lnMessage_textChanged(const QString &)
+void QRCodeDialog::on_lnMessage_textChanged(const QString &arg1)
{
genCode();
}
@@ -99,12 +114,11 @@ void QRCodeDialog::on_lnMessage_textChanged(const QString &)
void QRCodeDialog::on_btnSaveAs_clicked()
{
QString fn = GUIUtil::getSaveFileName(this, tr("Save Image..."), QString(), tr("PNG Images (*.png)"));
- if(!fn.isEmpty()) {
+ if (!fn.isEmpty())
myImage.scaled(EXPORT_IMAGE_SIZE, EXPORT_IMAGE_SIZE).save(fn);
- }
}
-void QRCodeDialog::on_chkReq_toggled(bool)
+void QRCodeDialog::on_chkReqPayment_toggled(bool)
{
genCode();
}
diff --git a/src/qt/qrcodedialog.h b/src/qt/qrcodedialog.h
index 7463a8810e..ad0611605b 100644
--- a/src/qt/qrcodedialog.h
+++ b/src/qt/qrcodedialog.h
@@ -13,7 +13,7 @@ class QRCodeDialog : public QDialog
Q_OBJECT
public:
- explicit QRCodeDialog(const QString &title, const QString &address, const QString &label, bool allowReq, QWidget *parent = 0);
+ explicit QRCodeDialog(const QString &addr, const QString &label, bool enableReq, QWidget *parent = 0);
~QRCodeDialog();
private slots:
@@ -22,7 +22,7 @@ private slots:
void on_lnMessage_textChanged(const QString &arg1);
void on_btnSaveAs_clicked();
- void on_chkReq_toggled(bool checked);
+ void on_chkReqPayment_toggled(bool checked);
private:
Ui::QRCodeDialog *ui;
diff --git a/src/util.cpp b/src/util.cpp
index c4464748fc..911388b37d 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -805,7 +805,7 @@ boost::filesystem::path GetDefaultDataDir()
pathRet = fs::path(pszHome);
#ifdef MAC_OSX
// Mac
- pathRet /= "Library" / "Application Support";
+ pathRet /= "Library/Application Support";
filesystem::create_directory(pathRet);
return pathRet / "Bitcoin";
#else
diff --git a/src/util.h b/src/util.h
index d205260d8e..f6cb3caa1d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -706,26 +706,6 @@ inline void ExitThread(size_t nExitCode)
-inline bool AffinityBugWorkaround(void(*pfn)(void*))
-{
-#ifdef WIN32
- // Sometimes after a few hours affinity gets stuck on one processor
- DWORD_PTR dwProcessAffinityMask = -1;
- DWORD_PTR dwSystemAffinityMask = -1;
- GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinityMask, &dwSystemAffinityMask);
- DWORD dwPrev1 = SetThreadAffinityMask(GetCurrentThread(), dwProcessAffinityMask);
- DWORD dwPrev2 = SetThreadAffinityMask(GetCurrentThread(), dwProcessAffinityMask);
- if (dwPrev2 != dwProcessAffinityMask)
- {
- printf("AffinityBugWorkaround() : SetThreadAffinityMask=%d, ProcessAffinityMask=%d, restarting thread\n", dwPrev2, dwProcessAffinityMask);
- if (!CreateThread(pfn, NULL))
- printf("Error: CreateThread() failed\n");
- return true;
- }
-#endif
- return false;
-}
-
inline uint32_t ByteReverse(uint32_t value)
{
value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);