diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp index 5e7d8e617..2987e5fdd 100644 --- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -244,33 +244,34 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value, if(role == Qt::EditRole) { - switch(index.column()) + LOCK(wallet->cs_wallet); /* For SetAddressBook / DelAddressBook */ + CTxDestination curAddress = CBitcoinAddress(rec->address.toStdString()).Get(); + if(index.column() == Label) { - case Label: // Do nothing, if old label == new label if(rec->label == value.toString()) { editStatus = NO_CHANGES; return false; } - wallet->SetAddressBook(CBitcoinAddress(rec->address.toStdString()).Get(), value.toString().toStdString(), strPurpose); - break; - case Address: - // Do nothing, if old address == new address - if(CBitcoinAddress(rec->address.toStdString()) == CBitcoinAddress(value.toString().toStdString())) - { - editStatus = NO_CHANGES; - return false; - } + wallet->SetAddressBook(curAddress, value.toString().toStdString(), strPurpose); + } else if(index.column() == Address) { + CTxDestination newAddress = CBitcoinAddress(value.toString().toStdString()).Get(); // Refuse to set invalid address, set error status and return false - else if(!walletModel->validateAddress(value.toString())) + if(boost::get(&newAddress)) { editStatus = INVALID_ADDRESS; return false; } + // Do nothing, if old address == new address + else if(newAddress == curAddress) + { + editStatus = NO_CHANGES; + return false; + } // Check for duplicate addresses to prevent accidental deletion of addresses, if you try // to paste an existing address over another address (with a different label) - else if(wallet->mapAddressBook.count(CBitcoinAddress(value.toString().toStdString()).Get())) + else if(wallet->mapAddressBook.count(newAddress)) { editStatus = DUPLICATE_ADDRESS; return false; @@ -278,15 +279,11 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value, // Double-check that we're not overwriting a receiving address else if(rec->type == AddressTableEntry::Sending) { - { - LOCK(wallet->cs_wallet); - // Remove old entry - wallet->DelAddressBook(CBitcoinAddress(rec->address.toStdString()).Get()); - // Add new entry with new address - wallet->SetAddressBook(CBitcoinAddress(value.toString().toStdString()).Get(), rec->label.toStdString(), strPurpose); - } + // Remove old entry + wallet->DelAddressBook(curAddress); + // Add new entry with new address + wallet->SetAddressBook(newAddress, rec->label.toStdString(), strPurpose); } - break; } return true; } diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index ba5c06064..cfa87c16b 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -548,6 +548,7 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipien else { CPubKey newKey; if (wallet->GetKeyFromPool(newKey)) { + LOCK(wallet->cs_wallet); // SetAddressBook CKeyID keyID = newKey.GetID(); wallet->SetAddressBook(keyID, strAccount, "refund"); diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index f08342b83..6f3e3b0aa 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -502,6 +502,7 @@ void WalletModel::listCoins(std::map >& mapCoins) std::vector vCoins; wallet->AvailableCoins(vCoins); + LOCK(wallet->cs_wallet); // ListLockedCoins, mapWallet std::vector vLockedCoins; wallet->ListLockedCoins(vLockedCoins); @@ -531,20 +532,24 @@ void WalletModel::listCoins(std::map >& mapCoins) bool WalletModel::isLockedCoin(uint256 hash, unsigned int n) const { + LOCK(wallet->cs_wallet); return wallet->IsLockedCoin(hash, n); } void WalletModel::lockCoin(COutPoint& output) { + LOCK(wallet->cs_wallet); wallet->LockCoin(output); } void WalletModel::unlockCoin(COutPoint& output) { + LOCK(wallet->cs_wallet); wallet->UnlockCoin(output); } void WalletModel::listLockedCoins(std::vector& vOutpts) { + LOCK(wallet->cs_wallet); wallet->ListLockedCoins(vOutpts); }