Browse Source

update to work with new lock system, add protocol.* to build system

miguelfreitas
Wladimir J. van der Laan 14 years ago
parent
commit
c5aa1b139a
  1. 7
      bitcoin-qt.pro
  2. 11
      src/main.cpp
  3. 1
      src/main.h
  4. 22
      src/qt/addresstablemodel.cpp
  5. 3
      src/qt/addresstablemodel.h
  6. 2
      src/qt/clientmodel.cpp
  7. 5
      src/qt/editaddressdialog.cpp
  8. 4
      src/qt/transactiondesc.cpp
  9. 10
      src/qt/transactiontablemodel.cpp
  10. 8
      src/qt/walletmodel.cpp
  11. 2
      src/wallet.cpp

7
bitcoin-qt.pro

@ -91,7 +91,9 @@ HEADERS += src/qt/bitcoingui.h \
src/qt/qvalidatedlineedit.h \ src/qt/qvalidatedlineedit.h \
src/qt/bitcoinunits.h \ src/qt/bitcoinunits.h \
src/qt/qvaluecombobox.h \ src/qt/qvaluecombobox.h \
src/qt/askpassphrasedialog.h src/qt/askpassphrasedialog.h \
src/protocol.h
SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/qt/transactiontablemodel.cpp \ src/qt/transactiontablemodel.cpp \
src/qt/addresstablemodel.cpp \ src/qt/addresstablemodel.cpp \
@ -136,7 +138,8 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/qt/qvalidatedlineedit.cpp \ src/qt/qvalidatedlineedit.cpp \
src/qt/bitcoinunits.cpp \ src/qt/bitcoinunits.cpp \
src/qt/qvaluecombobox.cpp \ src/qt/qvaluecombobox.cpp \
src/qt/askpassphrasedialog.cpp src/qt/askpassphrasedialog.cpp \
src/protocol.cpp
RESOURCES += \ RESOURCES += \
src/qt/bitcoin.qrc src/qt/bitcoin.qrc

11
src/main.cpp

@ -31,6 +31,7 @@ map<uint256, CBlockIndex*> mapBlockIndex;
uint256 hashGenesisBlock("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"); uint256 hashGenesisBlock("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f");
static CBigNum bnProofOfWorkLimit(~uint256(0) >> 32); static CBigNum bnProofOfWorkLimit(~uint256(0) >> 32);
const int nTotalBlocksEstimate = 140700; // Conservative estimate of total nr of blocks on main chain const int nTotalBlocksEstimate = 140700; // Conservative estimate of total nr of blocks on main chain
int nMaxBlocksOfOtherNodes = 0; // Maximum amount of blocks that other nodes claim to have
const int nInitialBlockThreshold = 120; // Regard blocks up until N-threshold as "initial download" const int nInitialBlockThreshold = 120; // Regard blocks up until N-threshold as "initial download"
CBlockIndex* pindexGenesisBlock = NULL; CBlockIndex* pindexGenesisBlock = NULL;
int nBestHeight = -1; int nBestHeight = -1;
@ -726,6 +727,12 @@ int GetTotalBlocksEstimate()
} }
} }
// Return maximum amount of blocks that other nodes claim to have
int GetMaxBlocksOfOtherNodes()
{
return nMaxBlocksOfOtherNodes;
}
bool IsInitialBlockDownload() bool IsInitialBlockDownload()
{ {
if (pindexBest == NULL || nBestHeight < (GetTotalBlocksEstimate()-nInitialBlockThreshold)) if (pindexBest == NULL || nBestHeight < (GetTotalBlocksEstimate()-nInitialBlockThreshold))
@ -1837,9 +1844,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
pfrom->fSuccessfullyConnected = true; pfrom->fSuccessfullyConnected = true;
printf("version message: version %d, blocks=%d\n", pfrom->nVersion, pfrom->nStartingHeight); printf("version message: version %d, blocks=%d\n", pfrom->nVersion, pfrom->nStartingHeight);
if(pfrom->nStartingHeight > nTotalBlocksEstimate) if(pfrom->nStartingHeight > nMaxBlocksOfOtherNodes)
{ {
nTotalBlocksEstimate = pfrom->nStartingHeight; nMaxBlocksOfOtherNodes = pfrom->nStartingHeight;
} }
} }

1
src/main.h

@ -99,6 +99,7 @@ void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash
bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey); bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey);
bool CheckProofOfWork(uint256 hash, unsigned int nBits); bool CheckProofOfWork(uint256 hash, unsigned int nBits);
int GetTotalBlocksEstimate(); int GetTotalBlocksEstimate();
int GetMaxBlocksOfOtherNodes();
bool IsInitialBlockDownload(); bool IsInitialBlockDownload();
std::string GetWarnings(std::string strFor); std::string GetWarnings(std::string strFor);

22
src/qt/addresstablemodel.cpp

@ -39,8 +39,7 @@ struct AddressTablePriv
{ {
cachedAddressTable.clear(); cachedAddressTable.clear();
CRITICAL_BLOCK(wallet->cs_KeyStore) CRITICAL_BLOCK(wallet->cs_wallet)
CRITICAL_BLOCK(wallet->cs_mapAddressBook)
{ {
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, std::string)& item, wallet->mapAddressBook) BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, std::string)& item, wallet->mapAddressBook)
{ {
@ -170,7 +169,7 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
// Double-check that we're not overwriting a receiving address // Double-check that we're not overwriting a receiving address
if(rec->type == AddressTableEntry::Sending) if(rec->type == AddressTableEntry::Sending)
{ {
CRITICAL_BLOCK(wallet->cs_mapAddressBook) CRITICAL_BLOCK(wallet->cs_wallet)
{ {
// Remove old entry // Remove old entry
wallet->DelAddressBookName(rec->address.toStdString()); wallet->DelAddressBookName(rec->address.toStdString());
@ -255,7 +254,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
return QString(); return QString();
} }
// Check for duplicate addresses // Check for duplicate addresses
CRITICAL_BLOCK(wallet->cs_mapAddressBook) CRITICAL_BLOCK(wallet->cs_wallet)
{ {
if(wallet->mapAddressBook.count(strAddress)) if(wallet->mapAddressBook.count(strAddress))
{ {
@ -274,15 +273,20 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
editStatus = WALLET_UNLOCK_FAILURE; editStatus = WALLET_UNLOCK_FAILURE;
return QString(); return QString();
} }
std::vector<unsigned char> newKey;
strAddress = CBitcoinAddress(wallet->GetOrReuseKeyFromPool()).ToString(); if(!wallet->GetKeyFromPool(newKey, true))
{
editStatus = KEY_GENERATION_FAILURE;
return QString();
}
strAddress = CBitcoinAddress(newKey).ToString();
} }
else else
{ {
return QString(); return QString();
} }
// Add entry and update list // Add entry and update list
CRITICAL_BLOCK(wallet->cs_mapAddressBook) CRITICAL_BLOCK(wallet->cs_wallet)
wallet->SetAddressBookName(strAddress, strLabel); wallet->SetAddressBookName(strAddress, strLabel);
updateList(); updateList();
return QString::fromStdString(strAddress); return QString::fromStdString(strAddress);
@ -298,7 +302,7 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex & paren
// Also refuse to remove receiving addresses. // Also refuse to remove receiving addresses.
return false; return false;
} }
CRITICAL_BLOCK(wallet->cs_mapAddressBook) CRITICAL_BLOCK(wallet->cs_wallet)
{ {
wallet->DelAddressBookName(rec->address.toStdString()); wallet->DelAddressBookName(rec->address.toStdString());
} }
@ -315,7 +319,7 @@ void AddressTableModel::update()
*/ */
QString AddressTableModel::labelForAddress(const QString &address) const QString AddressTableModel::labelForAddress(const QString &address) const
{ {
CRITICAL_BLOCK(wallet->cs_mapAddressBook) CRITICAL_BLOCK(wallet->cs_wallet)
{ {
CBitcoinAddress address_parsed(address.toStdString()); CBitcoinAddress address_parsed(address.toStdString());
std::map<CBitcoinAddress, std::string>::iterator mi = wallet->mapAddressBook.find(address_parsed); std::map<CBitcoinAddress, std::string>::iterator mi = wallet->mapAddressBook.find(address_parsed);

3
src/qt/addresstablemodel.h

@ -29,7 +29,8 @@ public:
OK, OK,
INVALID_ADDRESS, INVALID_ADDRESS,
DUPLICATE_ADDRESS, DUPLICATE_ADDRESS,
WALLET_UNLOCK_FAILURE WALLET_UNLOCK_FAILURE,
KEY_GENERATION_FAILURE
}; };
static const QString Send; /* Send addres */ static const QString Send; /* Send addres */

2
src/qt/clientmodel.cpp

@ -61,7 +61,7 @@ bool ClientModel::inInitialBlockDownload() const
int ClientModel::getTotalBlocksEstimate() const int ClientModel::getTotalBlocksEstimate() const
{ {
return GetTotalBlocksEstimate(); return GetMaxBlocksOfOtherNodes();
} }
OptionsModel *ClientModel::getOptionsModel() OptionsModel *ClientModel::getOptionsModel()

5
src/qt/editaddressdialog.cpp

@ -97,6 +97,11 @@ void EditAddressDialog::accept()
tr("Could not unlock wallet."), tr("Could not unlock wallet."),
QMessageBox::Ok, QMessageBox::Ok); QMessageBox::Ok, QMessageBox::Ok);
return; return;
case AddressTableModel::KEY_GENERATION_FAILURE:
QMessageBox::critical(this, windowTitle(),
tr("New key generation failed."),
QMessageBox::Ok, QMessageBox::Ok);
return;
} }
return; return;

4
src/qt/transactiondesc.cpp

@ -50,7 +50,7 @@ QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx)
QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx) QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
{ {
QString strHTML; QString strHTML;
CRITICAL_BLOCK(wallet->cs_mapAddressBook) CRITICAL_BLOCK(wallet->cs_wallet)
{ {
strHTML.reserve(4000); strHTML.reserve(4000);
strHTML += "<html><font face='verdana, arial, helvetica, sans-serif'>"; strHTML += "<html><font face='verdana, arial, helvetica, sans-serif'>";
@ -257,7 +257,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
strHTML += "<br><b>Inputs:</b>"; strHTML += "<br><b>Inputs:</b>";
strHTML += "<ul>"; strHTML += "<ul>";
CRITICAL_BLOCK(wallet->cs_mapWallet) CRITICAL_BLOCK(wallet->cs_wallet)
{ {
BOOST_FOREACH(const CTxIn& txin, wtx.vin) BOOST_FOREACH(const CTxIn& txin, wtx.vin)
{ {

10
src/qt/transactiontablemodel.cpp

@ -69,7 +69,7 @@ struct TransactionTablePriv
qDebug() << "refreshWallet"; qDebug() << "refreshWallet";
#endif #endif
cachedWallet.clear(); cachedWallet.clear();
CRITICAL_BLOCK(wallet->cs_mapWallet) CRITICAL_BLOCK(wallet->cs_wallet)
{ {
for(std::map<uint256, CWalletTx>::iterator it = wallet->mapWallet.begin(); it != wallet->mapWallet.end(); ++it) for(std::map<uint256, CWalletTx>::iterator it = wallet->mapWallet.begin(); it != wallet->mapWallet.end(); ++it)
{ {
@ -95,7 +95,7 @@ struct TransactionTablePriv
QList<uint256> updated_sorted = updated; QList<uint256> updated_sorted = updated;
qSort(updated_sorted); qSort(updated_sorted);
CRITICAL_BLOCK(wallet->cs_mapWallet) CRITICAL_BLOCK(wallet->cs_wallet)
{ {
for(int update_idx = updated_sorted.size()-1; update_idx >= 0; --update_idx) for(int update_idx = updated_sorted.size()-1; update_idx >= 0; --update_idx)
{ {
@ -171,7 +171,7 @@ struct TransactionTablePriv
// simply re-use the cached status. // simply re-use the cached status.
if(rec->statusUpdateNeeded()) if(rec->statusUpdateNeeded())
{ {
CRITICAL_BLOCK(wallet->cs_mapWallet) CRITICAL_BLOCK(wallet->cs_wallet)
{ {
std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash); std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash);
@ -191,7 +191,7 @@ struct TransactionTablePriv
QString describe(TransactionRecord *rec) QString describe(TransactionRecord *rec)
{ {
CRITICAL_BLOCK(wallet->cs_mapWallet) CRITICAL_BLOCK(wallet->cs_wallet)
{ {
std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash); std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash);
if(mi != wallet->mapWallet.end()) if(mi != wallet->mapWallet.end())
@ -229,7 +229,7 @@ void TransactionTableModel::update()
QList<uint256> updated; QList<uint256> updated;
// Check if there are changes to wallet map // Check if there are changes to wallet map
TRY_CRITICAL_BLOCK(wallet->cs_mapWallet) TRY_CRITICAL_BLOCK(wallet->cs_wallet)
{ {
if(!wallet->vWalletUpdated.empty()) if(!wallet->vWalletUpdated.empty())
{ {

8
src/qt/walletmodel.cpp

@ -38,7 +38,7 @@ qint64 WalletModel::getUnconfirmedBalance() const
int WalletModel::getNumTransactions() const int WalletModel::getNumTransactions() const
{ {
int numTransactions = 0; int numTransactions = 0;
CRITICAL_BLOCK(wallet->cs_mapWallet) CRITICAL_BLOCK(wallet->cs_wallet)
{ {
numTransactions = wallet->mapWallet.size(); numTransactions = wallet->mapWallet.size();
} }
@ -117,7 +117,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList<SendCoinsRecipie
} }
CRITICAL_BLOCK(cs_main) CRITICAL_BLOCK(cs_main)
CRITICAL_BLOCK(wallet->cs_mapWallet) CRITICAL_BLOCK(wallet->cs_wallet)
{ {
// Sendmany // Sendmany
std::vector<std::pair<CScript, int64> > vecSend; std::vector<std::pair<CScript, int64> > vecSend;
@ -156,7 +156,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList<SendCoinsRecipie
foreach(const SendCoinsRecipient &rcp, recipients) foreach(const SendCoinsRecipient &rcp, recipients)
{ {
std::string strAddress = rcp.address.toStdString(); std::string strAddress = rcp.address.toStdString();
CRITICAL_BLOCK(wallet->cs_mapAddressBook) CRITICAL_BLOCK(wallet->cs_wallet)
{ {
if (!wallet->mapAddressBook.count(strAddress)) if (!wallet->mapAddressBook.count(strAddress))
wallet->SetAddressBookName(strAddress, rcp.label.toStdString()); wallet->SetAddressBookName(strAddress, rcp.label.toStdString());
@ -231,7 +231,7 @@ bool WalletModel::setWalletLocked(bool locked, const std::string &passPhrase)
bool WalletModel::changePassphrase(const std::string &oldPass, const std::string &newPass) bool WalletModel::changePassphrase(const std::string &oldPass, const std::string &newPass)
{ {
bool retval; bool retval;
CRITICAL_BLOCK(wallet->cs_vMasterKey) CRITICAL_BLOCK(wallet->cs_wallet)
{ {
wallet->Lock(); // Make sure wallet is locked before attempting pass change wallet->Lock(); // Make sure wallet is locked before attempting pass change
retval = wallet->ChangeWalletPassphrase(oldPass, newPass); retval = wallet->ChangeWalletPassphrase(oldPass, newPass);

2
src/wallet.cpp

@ -731,7 +731,7 @@ int64 CWallet::GetBalance() const
int64 CWallet::GetUnconfirmedBalance() const int64 CWallet::GetUnconfirmedBalance() const
{ {
int64 nTotal = 0; int64 nTotal = 0;
CRITICAL_BLOCK(cs_mapWallet) CRITICAL_BLOCK(cs_wallet)
{ {
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{ {

Loading…
Cancel
Save