Merge pull request #1087 from sipa/fix_1086
authorGavin Andresen <gavinandresen@gmail.com>
Fri, 13 Apr 2012 01:22:15 +0000 (18:22 -0700)
committerGavin Andresen <gavinandresen@gmail.com>
Fri, 13 Apr 2012 01:22:15 +0000 (18:22 -0700)
Fix #1086: add /testnet to passed datadir

src/bitcoinrpc.cpp
src/main.cpp
src/qt/addressbookpage.cpp
src/qt/bitcoingui.cpp
src/qt/forms/aboutdialog.ui
src/qt/forms/qrcodedialog.ui
src/qt/qrcodedialog.cpp
src/qt/qrcodedialog.h
src/util.cpp
src/util.h

index 2525c2d..7c99114 100644 (file)
@@ -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;
 }
index b9c9db7..bdafae8 100644 (file)
@@ -3361,8 +3361,6 @@ void static BitcoinMiner(CWallet *pwallet)
 
     while (fGenerateBitcoins)
     {
-        if (AffinityBugWorkaround(ThreadBitcoinMiner))
-            return;
         if (fShutdown)
             return;
         while (vNodes.empty() || IsInitialBlockDownload())
index 8821283..3e55c39 100644 (file)
@@ -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
 }
index 9c1e05d..3c31f29 100644 (file)
@@ -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
 
index 127b909..6e342e5 100644 (file)
@@ -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>
index fa21f60..714b1d6 100644 (file)
@@ -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>
         <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>
            </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>
  <resources/>
  <connections>
   <connection>
-   <sender>chkReq</sender>
+   <sender>chkReqPayment</sender>
    <signal>clicked(bool)</signal>
    <receiver>lnReqAmount</receiver>
    <slot>setEnabled(bool)</slot>
index 8295983..9965f14 100644 (file)
@@ -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();
 }
index 7463a88..ad06116 100644 (file)
@@ -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;
index c446474..911388b 100644 (file)
@@ -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
index d205260..f6cb3ca 100644 (file)
@@ -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);