Changeset View
Changeset View
Standalone View
Standalone View
src/qt/addresstablemodel.cpp
| Show First 20 Lines • Show All 226 Lines • ▼ Show 20 Lines | AddressTableEntry *rec = | ||||
| static_cast<AddressTableEntry *>(index.internalPointer()); | static_cast<AddressTableEntry *>(index.internalPointer()); | ||||
| std::string strPurpose = | std::string strPurpose = | ||||
| (rec->type == AddressTableEntry::Sending ? "send" : "receive"); | (rec->type == AddressTableEntry::Sending ? "send" : "receive"); | ||||
| editStatus = OK; | editStatus = OK; | ||||
| if (role == Qt::EditRole) { | if (role == Qt::EditRole) { | ||||
| LOCK(wallet->cs_wallet); /* For SetAddressBook / DelAddressBook */ | LOCK(wallet->cs_wallet); /* For SetAddressBook / DelAddressBook */ | ||||
| CTxDestination curAddress = | CTxDestination curAddress = | ||||
| DecodeDestination(rec->address.toStdString()); | DecodeDestination(rec->address.toStdString(), wallet->chainParams); | ||||
| if (index.column() == Label) { | if (index.column() == Label) { | ||||
| // Do nothing, if old label == new label | // Do nothing, if old label == new label | ||||
| if (rec->label == value.toString()) { | if (rec->label == value.toString()) { | ||||
| editStatus = NO_CHANGES; | editStatus = NO_CHANGES; | ||||
| return false; | return false; | ||||
| } | } | ||||
| wallet->SetAddressBook(curAddress, value.toString().toStdString(), | wallet->SetAddressBook(curAddress, value.toString().toStdString(), | ||||
| strPurpose); | strPurpose); | ||||
| } else if (index.column() == Address) { | } else if (index.column() == Address) { | ||||
| CTxDestination newAddress = | CTxDestination newAddress = DecodeDestination( | ||||
| DecodeDestination(value.toString().toStdString()); | value.toString().toStdString(), wallet->chainParams); | ||||
| // Refuse to set invalid address, set error status and return false | // Refuse to set invalid address, set error status and return false | ||||
| if (boost::get<CNoDestination>(&newAddress)) { | if (boost::get<CNoDestination>(&newAddress)) { | ||||
| editStatus = INVALID_ADDRESS; | editStatus = INVALID_ADDRESS; | ||||
| return false; | return false; | ||||
| } | } | ||||
| // 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; | ||||
| ▲ Show 20 Lines • Show All 74 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 | ||||
| { | { | ||||
| LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
| if (wallet->mapAddressBook.count(DecodeDestination(strAddress))) { | if (wallet->mapAddressBook.count( | ||||
| DecodeDestination(strAddress, wallet->chainParams))) { | |||||
| 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 (!wallet->GetKeyFromPool(newKey)) { | if (!wallet->GetKeyFromPool(newKey)) { | ||||
| Show All 11 Lines | if (type == Send) { | ||||
| strAddress = EncodeDestination(newKey.GetID()); | strAddress = EncodeDestination(newKey.GetID()); | ||||
| } else { | } else { | ||||
| return QString(); | return QString(); | ||||
| } | } | ||||
| // Add entry | // Add entry | ||||
| { | { | ||||
| LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
| wallet->SetAddressBook(DecodeDestination(strAddress), strLabel, | wallet->SetAddressBook( | ||||
| DecodeDestination(strAddress, wallet->chainParams), strLabel, | |||||
| (type == Send ? "send" : "receive")); | (type == Send ? "send" : "receive")); | ||||
| } | } | ||||
| return QString::fromStdString(strAddress); | return QString::fromStdString(strAddress); | ||||
| } | } | ||||
| bool AddressTableModel::removeRows(int row, int count, | bool AddressTableModel::removeRows(int row, int count, | ||||
| const QModelIndex &parent) { | const QModelIndex &parent) { | ||||
| Q_UNUSED(parent); | Q_UNUSED(parent); | ||||
| AddressTableEntry *rec = priv->index(row); | AddressTableEntry *rec = priv->index(row); | ||||
| if (count != 1 || !rec || rec->type == AddressTableEntry::Receiving) { | if (count != 1 || !rec || rec->type == AddressTableEntry::Receiving) { | ||||
| // Can only remove one row at a time, and cannot remove rows not in | // Can only remove one row at a time, and cannot remove rows not in | ||||
| // model. | // model. | ||||
| // Also refuse to remove receiving addresses. | // Also refuse to remove receiving addresses. | ||||
| return false; | return false; | ||||
| } | } | ||||
| { | { | ||||
| LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
| wallet->DelAddressBook(DecodeDestination(rec->address.toStdString())); | wallet->DelAddressBook( | ||||
| DecodeDestination(rec->address.toStdString(), wallet->chainParams)); | |||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| /* 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 { | ||||
| { | { | ||||
| LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
| CTxDestination destination = DecodeDestination(address.toStdString()); | CTxDestination destination = | ||||
| DecodeDestination(address.toStdString(), wallet->chainParams); | |||||
| std::map<CTxDestination, CAddressBookData>::iterator mi = | std::map<CTxDestination, CAddressBookData>::iterator mi = | ||||
| wallet->mapAddressBook.find(destination); | wallet->mapAddressBook.find(destination); | ||||
| if (mi != wallet->mapAddressBook.end()) { | if (mi != wallet->mapAddressBook.end()) { | ||||
| return QString::fromStdString(mi->second.name); | return QString::fromStdString(mi->second.name); | ||||
| } | } | ||||
| } | } | ||||
| return QString(); | return QString(); | ||||
| } | } | ||||
| Show All 15 Lines | |||||