diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-07-02 15:09:53 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-07-02 15:11:40 +0200 |
commit | 669b0a5835500c41b15501c5b9eb60ba1a2c7735 (patch) | |
tree | bf6aa100ee3bffd906ce5f8a33e7c7378e860c89 /src | |
parent | ebff5c40a234f38429965c391da020bbf8312b1b (diff) |
Check addresses in address book for validity
Diffstat (limited to 'src')
-rw-r--r-- | src/qt/addressbookdialog.cpp | 11 | ||||
-rw-r--r-- | src/qt/addresstablemodel.cpp | 7 | ||||
-rw-r--r-- | src/qt/addresstablemodel.h | 4 | ||||
-rw-r--r-- | src/qt/editaddressdialog.cpp | 31 | ||||
-rw-r--r-- | src/qt/editaddressdialog.h | 5 |
5 files changed, 42 insertions, 16 deletions
diff --git a/src/qt/addressbookdialog.cpp b/src/qt/addressbookdialog.cpp index ce9c6a5338..5eb60b77fd 100644 --- a/src/qt/addressbookdialog.cpp +++ b/src/qt/addressbookdialog.cpp @@ -48,7 +48,6 @@ void AddressBookDialog::setModel(AddressTableModel *model) ui->receiveTableView->setModel(receive_model); ui->receiveTableView->sortByColumn(0, Qt::AscendingOrder); - // Send filter QSortFilterProxyModel *send_model = new QSortFilterProxyModel(this); send_model->setSourceModel(model); @@ -120,10 +119,7 @@ void AddressBookDialog::on_editButton_clicked() EditAddressDialog::EditReceivingAddress); dlg.setModel(model); dlg.loadRow(selected.row()); - if(dlg.exec()) - { - dlg.saveCurrentRow(); - } + dlg.exec(); } void AddressBookDialog::on_newAddressButton_clicked() @@ -133,10 +129,7 @@ void AddressBookDialog::on_newAddressButton_clicked() EditAddressDialog::NewSendingAddress : EditAddressDialog::NewReceivingAddress); dlg.setModel(model); - if(dlg.exec()) - { - dlg.saveCurrentRow(); - } + dlg.exec(); } void AddressBookDialog::on_tabWidget_currentChanged(int index) diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp index ca605241ed..6829fea6e9 100644 --- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -263,3 +263,10 @@ void AddressTableModel::update() { } + +bool AddressTableModel::validateAddress(const QString &address) +{ + uint160 hash160 = 0; + + return AddressToHash160(address.toStdString(), hash160); +} diff --git a/src/qt/addresstablemodel.h b/src/qt/addresstablemodel.h index 3ababfc6b5..b509481e52 100644 --- a/src/qt/addresstablemodel.h +++ b/src/qt/addresstablemodel.h @@ -44,6 +44,10 @@ public: */ void updateList(); + /* Check address for validity + */ + bool validateAddress(const QString &address); + private: CWallet *wallet; AddressTablePriv *priv; diff --git a/src/qt/editaddressdialog.cpp b/src/qt/editaddressdialog.cpp index 8ffabf4798..7ea5638b4b 100644 --- a/src/qt/editaddressdialog.cpp +++ b/src/qt/editaddressdialog.cpp @@ -65,12 +65,6 @@ QString EditAddressDialog::saveCurrentRow() mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive, ui->labelEdit->text(), ui->addressEdit->text()); - if(address.isEmpty()) - { - QMessageBox::warning(this, windowTitle(), - tr("The address %1 is already in the address book.").arg(ui->addressEdit->text()), - QMessageBox::Ok, QMessageBox::Ok); - } break; case EditReceivingAddress: case EditSendingAddress: @@ -82,3 +76,28 @@ QString EditAddressDialog::saveCurrentRow() } return address; } + +void EditAddressDialog::accept() +{ + if(mode == NewSendingAddress || mode == EditSendingAddress) + { + // For sending addresses, check validity + // Not needed for receiving addresses, as those are generated + if(!model->validateAddress(ui->addressEdit->text())) + { + QMessageBox::warning(this, windowTitle(), + tr("The entered address \"%1\" is not a valid bitcoin address.").arg(ui->addressEdit->text()), + QMessageBox::Ok, QMessageBox::Ok); + return; + } + } + if(saveCurrentRow().isEmpty()) + { + QMessageBox::warning(this, windowTitle(), + tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()), + QMessageBox::Ok, QMessageBox::Ok); + return; + } + QDialog::accept(); +} + diff --git a/src/qt/editaddressdialog.h b/src/qt/editaddressdialog.h index 6f396d0457..6219961161 100644 --- a/src/qt/editaddressdialog.h +++ b/src/qt/editaddressdialog.h @@ -29,9 +29,12 @@ public: void setModel(AddressTableModel *model); void loadRow(int row); - QString saveCurrentRow(); + + void accept(); private: + QString saveCurrentRow(); + Ui::EditAddressDialog *ui; QDataWidgetMapper *mapper; Mode mode; |