#include "addresstablemodel.h"
#include "guiutil.h"
+#include "walletmodel.h"
#include "headers.h"
{
cachedAddressTable.clear();
- CRITICAL_BLOCK(wallet->cs_mapKeys)
+ CRITICAL_BLOCK(cs_mapPubKeys)
CRITICAL_BLOCK(wallet->cs_mapAddressBook)
{
BOOST_FOREACH(const PAIRTYPE(std::string, std::string)& item, wallet->mapAddressBook)
}
};
-AddressTableModel::AddressTableModel(CWallet *wallet, QObject *parent) :
- QAbstractTableModel(parent),wallet(wallet),priv(0)
+AddressTableModel::AddressTableModel(CWallet *wallet, WalletModel *parent) :
+ QAbstractTableModel(parent),walletModel(parent),wallet(wallet),priv(0)
{
columns << tr("Label") << tr("Address");
priv = new AddressTablePriv(wallet);
return false;
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
+ editStatus = OK;
+
if(role == Qt::EditRole)
{
switch(index.column())
break;
case Address:
// Refuse to set invalid address
- if(!validateAddress(value.toString()))
+ if(!walletModel->validateAddress(value.toString()))
+ {
+ editStatus = INVALID_ADDRESS;
return false;
+ }
// Double-check that we're not overwriting receiving address
if(rec->type == AddressTableEntry::Sending)
{
- // Remove old entry
- wallet->EraseAddressBookName(rec->address.toStdString());
- // Add new entry with new address
- wallet->SetAddressBookName(value.toString().toStdString(), rec->label.toStdString());
+ CRITICAL_BLOCK(wallet->cs_mapAddressBook)
+ {
+ // Remove old entry
+ wallet->DelAddressBookName(rec->address.toStdString());
+ // Add new entry with new address
+ wallet->SetAddressBookName(value.toString().toStdString(), rec->label.toStdString());
+ }
rec->address = value.toString();
}
std::string strLabel = label.toStdString();
std::string strAddress = address.toStdString();
+ editStatus = OK;
+
+
if(type == Send)
{
+ if(!walletModel->validateAddress(address))
+ {
+ editStatus = INVALID_ADDRESS;
+ return QString();
+ }
// Check for duplicate
CRITICAL_BLOCK(wallet->cs_mapAddressBook)
{
if(wallet->mapAddressBook.count(strAddress))
{
+ editStatus = DUPLICATE_ADDRESS;
return QString();
}
}
{
// Generate a new address to associate with given label, optionally
// set as default receiving address.
- strAddress = PubKeyToAddress(wallet->GetKeyFromKeyPool());
+ strAddress = PubKeyToAddress(wallet->GetOrReuseKeyFromPool());
}
else
{
return QString();
}
// Add entry and update list
- wallet->SetAddressBookName(strAddress, strLabel);
+ CRITICAL_BLOCK(wallet->cs_mapAddressBook)
+ wallet->SetAddressBookName(strAddress, strLabel);
updateList();
return QString::fromStdString(strAddress);
}
// Also refuse to remove receiving addresses.
return false;
}
- wallet->EraseAddressBookName(rec->address.toStdString());
+ CRITICAL_BLOCK(wallet->cs_mapAddressBook)
+ {
+ wallet->DelAddressBookName(rec->address.toStdString());
+ }
updateList();
return true;
}
}
-bool AddressTableModel::validateAddress(const QString &address)
+/* Look up label for address in address book, if not found return empty string.
+ */
+QString AddressTableModel::labelForAddress(const QString &address) const
{
- uint160 hash160 = 0;
+ CRITICAL_BLOCK(wallet->cs_mapAddressBook)
+ {
+ std::map<std::string, std::string>::iterator mi = wallet->mapAddressBook.find(address.toStdString());
+ if (mi != wallet->mapAddressBook.end())
+ {
+ return QString::fromStdString(mi->second);
+ }
+ }
+ return QString();
+}
- return AddressToHash160(address.toStdString(), hash160);
+int AddressTableModel::lookupAddress(const QString &address) const
+{
+ QModelIndexList lst = match(index(0, Address, QModelIndex()),
+ Qt::EditRole, address, 1, Qt::MatchExactly);
+ if(lst.isEmpty())
+ {
+ return -1;
+ }
+ else
+ {
+ return lst.at(0).row();
+ }
}
+