Changeset View
Changeset View
Standalone View
Standalone View
src/qt/addresstablemodel.cpp
Show First 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | if (role == Qt::EditRole) { | ||||
// Do nothing, if old address == new address | // Do nothing, if old address == new address | ||||
else if (newAddress == curAddress) { | else if (newAddress == curAddress) { | ||||
editStatus = NO_CHANGES; | editStatus = NO_CHANGES; | ||||
return false; | return false; | ||||
} | } | ||||
// Check for duplicate addresses to prevent accidental deletion of | // Check for duplicate addresses to prevent accidental deletion of | ||||
// addresses, if you try to paste an existing address over another | // addresses, if you try to paste an existing address over another | ||||
// address (with a different label) | // address (with a different label) | ||||
if (walletModel->wallet().getAddress(newAddress)) { | if (walletModel->wallet().getAddress( | ||||
newAddress, /* name= */ nullptr, /* is_mine= */ nullptr, | |||||
/* purpose= */ nullptr)) { | |||||
editStatus = DUPLICATE_ADDRESS; | editStatus = DUPLICATE_ADDRESS; | ||||
return false; | return false; | ||||
} | } | ||||
// Double-check that we're not overwriting a receiving address | // Double-check that we're not overwriting a receiving address | ||||
else if (rec->type == AddressTableEntry::Sending) { | else if (rec->type == AddressTableEntry::Sending) { | ||||
// Remove old entry | // Remove old entry | ||||
walletModel->wallet().delAddressBook(curAddress); | walletModel->wallet().delAddressBook(curAddress); | ||||
// Add new entry with new address | // Add new entry with new address | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | QString AddressTableModel::addRow(const QString &type, const QString &label, | ||||
if (type == Send) { | if (type == Send) { | ||||
if (!walletModel->validateAddress(address)) { | if (!walletModel->validateAddress(address)) { | ||||
editStatus = INVALID_ADDRESS; | editStatus = INVALID_ADDRESS; | ||||
return QString(); | return QString(); | ||||
} | } | ||||
// Check for duplicate addresses | // Check for duplicate addresses | ||||
if (walletModel->wallet().getAddress( | if (walletModel->wallet().getAddress( | ||||
DecodeDestination(strAddress, walletModel->getChainParams()))) { | DecodeDestination(strAddress, walletModel->getChainParams()), | ||||
/* name= */ nullptr, /* is_mine= */ nullptr, | |||||
/* purpose= */ nullptr)) { | |||||
editStatus = DUPLICATE_ADDRESS; | editStatus = DUPLICATE_ADDRESS; | ||||
return QString(); | return QString(); | ||||
} | } | ||||
} else if (type == Receive) { | } else if (type == Receive) { | ||||
// Generate a new address to associate with given label | // Generate a new address to associate with given label | ||||
CPubKey newKey; | CPubKey newKey; | ||||
if (!walletModel->wallet().getKeyFromPool(false /* internal */, | if (!walletModel->wallet().getKeyFromPool(false /* internal */, | ||||
newKey)) { | newKey)) { | ||||
Show All 39 Lines | |||||
} | } | ||||
/* Look up label for address in address book, if not found return empty string. | /* Look up label for address in address book, if not found return empty string. | ||||
*/ | */ | ||||
QString AddressTableModel::labelForAddress(const QString &address) const { | QString AddressTableModel::labelForAddress(const QString &address) const { | ||||
CTxDestination destination = | CTxDestination destination = | ||||
DecodeDestination(address.toStdString(), walletModel->getChainParams()); | DecodeDestination(address.toStdString(), walletModel->getChainParams()); | ||||
std::string name; | std::string name; | ||||
if (walletModel->wallet().getAddress(destination, &name)) { | if (walletModel->wallet().getAddress(destination, &name, | ||||
/* is_mine= */ nullptr, | |||||
/* purpose= */ nullptr)) { | |||||
return QString::fromStdString(name); | return QString::fromStdString(name); | ||||
} | } | ||||
return QString(); | return QString(); | ||||
} | } | ||||
int AddressTableModel::lookupAddress(const QString &address) const { | int AddressTableModel::lookupAddress(const QString &address) const { | ||||
QModelIndexList lst = match(index(0, Address, QModelIndex()), Qt::EditRole, | QModelIndexList lst = match(index(0, Address, QModelIndex()), Qt::EditRole, | ||||
address, 1, Qt::MatchExactly); | address, 1, Qt::MatchExactly); | ||||
Show All 15 Lines |