diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2012-05-22 23:07:46 +0000 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2012-05-22 23:07:46 +0000 |
commit | a49927a46d578d142411c52b17c6f11bb19da03d (patch) | |
tree | 90f2c7ecaee23e2e9539e9264a44c803290cff4e /src | |
parent | d7534272c62583320dc8d4a1ea71a41c715ef559 (diff) | |
parent | d67b0434f24a629372000b0bd573ea9013ca3d90 (diff) |
Merge branch '0.6.0.x' into 0.6.x
Conflicts:
bitcoin-qt.pro
doc/README
doc/README_windows.txt
share/setup.nsi
src/bitcoinrpc.h
src/db.h
src/headers.h
src/init.cpp
src/main.cpp
src/main.h
src/noui.h
src/qt/bitcoin.cpp
src/qt/locale/bitcoin_en.ts
src/qt/walletmodel.cpp
src/script.cpp
src/ui_interface.h
src/util.cpp
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoinrpc.cpp | 6 | ||||
-rw-r--r-- | src/db.cpp | 16 | ||||
-rw-r--r-- | src/db.h | 9 | ||||
-rw-r--r-- | src/main.cpp | 52 | ||||
-rw-r--r-- | src/main.h | 15 | ||||
-rw-r--r-- | src/qt/bitcoinaddressvalidator.cpp | 20 | ||||
-rw-r--r-- | src/qt/bitcoingui.cpp | 4 | ||||
-rw-r--r-- | src/qt/csvmodelwriter.cpp | 5 | ||||
-rw-r--r-- | src/qt/forms/askpassphrasedialog.ui | 3 | ||||
-rw-r--r-- | src/qt/optionsdialog.cpp | 3 | ||||
-rw-r--r-- | src/wallet.cpp | 3 |
11 files changed, 100 insertions, 36 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index cf6e4fb6b7..a954050b31 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -839,7 +839,8 @@ Value movecmd(const Array& params, bool fHelp) strComment = params[4].get_str(); CWalletDB walletdb(pwalletMain->strWalletFile); - walletdb.TxnBegin(); + if (!walletdb.TxnBegin()) + throw JSONRPCError(-20, "database error"); int64 nNow = GetAdjustedTime(); @@ -861,7 +862,8 @@ Value movecmd(const Array& params, bool fHelp) credit.strComment = strComment; walletdb.WriteAccountingEntry(credit); - walletdb.TxnCommit(); + if (!walletdb.TxnCommit()) + throw JSONRPCError(-20, "database error"); return true; } diff --git a/src/db.cpp b/src/db.cpp index 4d2965fac9..2d9d552467 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -410,9 +410,15 @@ bool CTxDB::ReadOwnerTxes(uint160 hash160, int nMinHeight, vector<CTransaction>& string strType; uint160 hashItem; CDiskTxPos pos; - ssKey >> strType >> hashItem >> pos; int nItemHeight; - ssValue >> nItemHeight; + + try { + ssKey >> strType >> hashItem >> pos; + ssValue >> nItemHeight; + } + catch (std::exception &e) { + return error("%s() : deserialize error", __PRETTY_FUNCTION__); + } // Read transaction if (strType != "owner" || hashItem != hash160) @@ -532,6 +538,8 @@ bool CTxDB::LoadBlockIndex() return false; // Unserialize + + try { string strType; ssKey >> strType; if (strType == "blockindex" && !fRequestShutdown) @@ -563,6 +571,10 @@ bool CTxDB::LoadBlockIndex() { break; // if shutdown requested or finished loading block index } + } // try + catch (std::exception &e) { + return error("%s() : deserialize error", __PRETTY_FUNCTION__); + } } pcursor->close(); @@ -72,8 +72,13 @@ protected: return false; // Unserialize value - CDataStream ssValue((char*)datValue.get_data(), (char*)datValue.get_data() + datValue.get_size(), SER_DISK, CLIENT_VERSION); - ssValue >> value; + try { + CDataStream ssValue((char*)datValue.get_data(), (char*)datValue.get_data() + datValue.get_size(), SER_DISK, CLIENT_VERSION); + ssValue >> value; + } + catch (std::exception &e) { + return false; + } // Clear and free memory memset(datValue.get_data(), 0, datValue.get_size()); diff --git a/src/main.cpp b/src/main.cpp index ad5ab6e4be..6e5f9fb871 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1490,7 +1490,9 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew) { uint256 hash = GetHash(); - txdb.TxnBegin(); + if (!txdb.TxnBegin()) + return error("SetBestChain() : TxnBegin failed"); + if (pindexGenesisBlock == NULL && hash == hashGenesisBlock) { txdb.WriteHashBestChain(hash); @@ -1539,7 +1541,10 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew) printf("SetBestChain() : ReadFromDisk failed\n"); break; } - txdb.TxnBegin(); + if (!txdb.TxnBegin()) { + printf("SetBestChain() : TxnBegin 2 failed\n"); + break; + } // errors now are not fatal, we still did a reorganisation to a new chain in a valid way if (!block.SetBestChainInner(txdb, pindex)) break; @@ -1597,7 +1602,8 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos) pindexNew->bnChainWork = (pindexNew->pprev ? pindexNew->pprev->bnChainWork : 0) + pindexNew->GetBlockWork(); CTxDB txdb; - txdb.TxnBegin(); + if (!txdb.TxnBegin()) + return false; txdb.WriteBlockIndex(CDiskBlockIndex(pindexNew)); if (!txdb.TxnCommit()) return false; @@ -1825,7 +1831,7 @@ bool CheckDiskSpace(uint64 nAdditionalBytes) if (nFreeBytesAvailable < (uint64)15000000 + nAdditionalBytes) { fShutdown = true; - string strMessage = _("Warning: Disk space is low "); + string strMessage = _("Warning: Disk space is low"); strMiscWarning = strMessage; printf("*** %s\n", strMessage.c_str()); ThreadSafeMessageBox(strMessage, "Bitcoin", wxOK | wxICON_EXCLAMATION | wxMODAL); @@ -2392,6 +2398,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) return error("message inv size() = %d", vInv.size()); } + // find last block in inv vector + unsigned int nLastBlock = (unsigned int)(-1); + for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) { + if (vInv[vInv.size() - 1 - nInv].type == MSG_BLOCK) { + nLastBlock = vInv.size() - 1 - nInv; + break; + } + } CTxDB txdb("r"); for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) { @@ -2405,13 +2419,19 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (fDebug) printf(" got inventory: %s %s\n", inv.ToString().c_str(), fAlreadyHave ? "have" : "new"); - // Always request the last block in an inv bundle (even if we already have it), as it is the - // trigger for the other side to send further invs. If we are stuck on a (very long) side chain, - // this is necessary to connect earlier received orphan blocks to the chain again. - if (!fAlreadyHave || (inv.type == MSG_BLOCK && nInv==vInv.size()-1)) + if (!fAlreadyHave) pfrom->AskFor(inv); - if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash)) + else if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash)) { pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(mapOrphanBlocks[inv.hash])); + } else if (nInv == nLastBlock) { + // In case we are on a very long side-chain, it is possible that we already have + // the last block in an inv bundle sent in response to getblocks. Try to detect + // this situation and push another getblocks to continue. + std::vector<CInv> vGetData(1,inv); + pfrom->PushGetBlocks(mapBlockIndex[inv.hash], uint256(0)); + if (fDebug) + printf("force request: %s\n", inv.ToString().c_str()); + } // Track requests for our stuff Inventory(inv.hash); @@ -2787,7 +2807,7 @@ bool ProcessMessages(CNode* pfrom) unsigned int nMessageSize = hdr.nMessageSize; if (nMessageSize > MAX_SIZE) { - printf("ProcessMessage(%s, %u bytes) : nMessageSize > MAX_SIZE\n", strCommand.c_str(), nMessageSize); + printf("ProcessMessages(%s, %u bytes) : nMessageSize > MAX_SIZE\n", strCommand.c_str(), nMessageSize); continue; } if (nMessageSize > vRecv.size()) @@ -2803,7 +2823,7 @@ bool ProcessMessages(CNode* pfrom) memcpy(&nChecksum, &hash, sizeof(nChecksum)); if (nChecksum != hdr.nChecksum) { - printf("ProcessMessage(%s, %u bytes) : CHECKSUM ERROR nChecksum=%08x hdr.nChecksum=%08x\n", + printf("ProcessMessages(%s, %u bytes) : CHECKSUM ERROR nChecksum=%08x hdr.nChecksum=%08x\n", strCommand.c_str(), nMessageSize, nChecksum, hdr.nChecksum); continue; } @@ -2828,22 +2848,22 @@ bool ProcessMessages(CNode* pfrom) if (strstr(e.what(), "end of data")) { // Allow exceptions from underlength message on vRecv - printf("ProcessMessage(%s, %u bytes) : Exception '%s' caught, normally caused by a message being shorter than its stated length\n", strCommand.c_str(), nMessageSize, e.what()); + printf("ProcessMessages(%s, %u bytes) : Exception '%s' caught, normally caused by a message being shorter than its stated length\n", strCommand.c_str(), nMessageSize, e.what()); } else if (strstr(e.what(), "size too large")) { // Allow exceptions from overlong size - printf("ProcessMessage(%s, %u bytes) : Exception '%s' caught\n", strCommand.c_str(), nMessageSize, e.what()); + printf("ProcessMessages(%s, %u bytes) : Exception '%s' caught\n", strCommand.c_str(), nMessageSize, e.what()); } else { - PrintExceptionContinue(&e, "ProcessMessage()"); + PrintExceptionContinue(&e, "ProcessMessages()"); } } catch (std::exception& e) { - PrintExceptionContinue(&e, "ProcessMessage()"); + PrintExceptionContinue(&e, "ProcessMessages()"); } catch (...) { - PrintExceptionContinue(NULL, "ProcessMessage()"); + PrintExceptionContinue(NULL, "ProcessMessages()"); } if (!fRet) diff --git a/src/main.h b/src/main.h index 2439572e19..241ef46c8f 100644 --- a/src/main.h +++ b/src/main.h @@ -594,7 +594,13 @@ public: // Read transaction if (fseek(filein, pos.nTxPos, SEEK_SET) != 0) return error("CTransaction::ReadFromDisk() : fseek failed"); - filein >> *this; + + try { + filein >> *this; + } + catch (std::exception &e) { + return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__); + } // Return file pointer if (pfileRet) @@ -976,7 +982,12 @@ public: filein.nType |= SER_BLOCKHEADERONLY; // Read block - filein >> *this; + try { + filein >> *this; + } + catch (std::exception &e) { + return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__); + } // Check the header if (!CheckProofOfWork(GetHash(), nBits)) diff --git a/src/qt/bitcoinaddressvalidator.cpp b/src/qt/bitcoinaddressvalidator.cpp index 373877808f..c804ad0d57 100644 --- a/src/qt/bitcoinaddressvalidator.cpp +++ b/src/qt/bitcoinaddressvalidator.cpp @@ -21,9 +21,12 @@ BitcoinAddressValidator::BitcoinAddressValidator(QObject *parent) : QValidator::State BitcoinAddressValidator::validate(QString &input, int &pos) const { // Correction - for(int idx=0; idx<input.size(); ++idx) + for(int idx=0; idx<input.size();) { - switch(input.at(idx).unicode()) + bool removeChar = false; + QChar ch = input.at(idx); + // Transform characters that are visually close + switch(ch.unicode()) { case 'l': case 'I': @@ -33,9 +36,22 @@ QValidator::State BitcoinAddressValidator::validate(QString &input, int &pos) co case 'O': input[idx] = QChar('o'); break; + // Qt categorizes these as "Other_Format" not "Separator_Space" + case 0x200B: // ZERO WIDTH SPACE + case 0xFEFF: // ZERO WIDTH NO-BREAK SPACE + removeChar = true; + break; default: break; } + // Remove whitespace + if(ch.isSpace()) + removeChar = true; + // To next character + if(removeChar) + input.remove(idx, 1); + else + ++idx; } // Validation diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index e776f3537b..3cae99ebc9 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1,8 +1,8 @@ /* * Qt4 bitcoin GUI. * - * W.J. van der Laan 20011-2012 - * The Bitcoin Developers 20011-2012 + * W.J. van der Laan 2011-2012 + * The Bitcoin Developers 2011-2012 */ #include "bitcoingui.h" #include "transactiontablemodel.h" diff --git a/src/qt/csvmodelwriter.cpp b/src/qt/csvmodelwriter.cpp index 84578b3322..8a50bbab3f 100644 --- a/src/qt/csvmodelwriter.cpp +++ b/src/qt/csvmodelwriter.cpp @@ -27,8 +27,9 @@ void CSVModelWriter::addColumn(const QString &title, int column, int role) static void writeValue(QTextStream &f, const QString &value) { - // TODO: quoting if " or \n in string - f << "\"" << value << "\""; + QString escaped = value; + escaped.replace('"', "\"\""); + f << "\"" << escaped << "\""; } static void writeSep(QTextStream &f) diff --git a/src/qt/forms/askpassphrasedialog.ui b/src/qt/forms/askpassphrasedialog.ui index 3f6b668e06..ff3a77165b 100644 --- a/src/qt/forms/askpassphrasedialog.ui +++ b/src/qt/forms/askpassphrasedialog.ui @@ -28,9 +28,6 @@ <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QLabel" name="warningLabel"> - <property name="text"> - <string>TextLabel</string> - </property> <property name="textFormat"> <enum>Qt::RichText</enum> </property> diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 59c44ac5f9..0c43647b10 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -213,7 +213,7 @@ MainOptionsPage::MainOptionsPage(QWidget *parent): proxy_hbox->addStretch(1); layout->addLayout(proxy_hbox); - QLabel *fee_help = new QLabel(tr("Optional transaction fee per kB that helps make sure your transactions are processed quickly. Most transactions are 1 kB. Fee 0.01 recommended.")); + QLabel *fee_help = new QLabel(tr("Optional transaction fee per kB that helps make sure your transactions are processed quickly. Most transactions are 1 kB. Fee 0.01 recommended.")); fee_help->setWordWrap(true); layout->addWidget(fee_help); @@ -222,7 +222,6 @@ MainOptionsPage::MainOptionsPage(QWidget *parent): QLabel *fee_label = new QLabel(tr("Pay transaction &fee")); fee_hbox->addWidget(fee_label); fee_edit = new BitcoinAmountField(); - fee_edit->setToolTip(tr("Optional transaction fee per kB that helps make sure your transactions are processed quickly. Most transactions are 1 kB. Fee 0.01 recommended.")); fee_label->setBuddy(fee_edit); fee_hbox->addWidget(fee_edit); diff --git a/src/wallet.cpp b/src/wallet.cpp index d0684130a6..d7a70fe563 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -242,7 +242,8 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) if (fFileBacked) { pwalletdbEncryption = new CWalletDB(strWalletFile); - pwalletdbEncryption->TxnBegin(); + if (!pwalletdbEncryption->TxnBegin()) + return false; pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey); } |