Skip to content

Commit

Permalink
Return error when no ScriptPubKeyMan is available for specified type
Browse files Browse the repository at this point in the history
Summary:
When a CWallet doesn't have a ScriptPubKeyMan for the requested type
in GetNewDestination, give a meaningful error. Also handle this in
Qt which did not do anything with errors.

Backport of Core [[bitcoin/bitcoin#16528 | PR16528]] [39/43] : bitcoin/bitcoin@3c19fdd

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D8467
  • Loading branch information
achow101 authored and deadalnix committed Nov 19, 2020
1 parent a58b36f commit f53059d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
44 changes: 34 additions & 10 deletions src/qt/receivecoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,41 @@ void ReceiveCoinsDialog::on_receiveButton_clicked() {
OutputType address_type = model->wallet().getDefaultAddressType();
address = model->getAddressTableModel()->addRow(AddressTableModel::Receive,
label, "", address_type);
SendCoinsRecipient info(address, label, ui->reqAmount->value(),
ui->reqMessage->text());
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModel(model);
dialog->setInfo(info);
dialog->show();
clear();

/* Store request for later reference */
model->getRecentRequestsTableModel()->addNewRequest(info);
switch (model->getAddressTableModel()->getEditStatus()) {
case AddressTableModel::EditStatus::OK: {
// Success
SendCoinsRecipient info(address, label, ui->reqAmount->value(),
ui->reqMessage->text());
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModel(model);
dialog->setInfo(info);
dialog->show();

/* Store request for later reference */
model->getRecentRequestsTableModel()->addNewRequest(info);
break;
}
case AddressTableModel::EditStatus::WALLET_UNLOCK_FAILURE:
QMessageBox::critical(this, windowTitle(),
tr("Could not unlock wallet."),
QMessageBox::Ok, QMessageBox::Ok);
break;
case AddressTableModel::EditStatus::KEY_GENERATION_FAILURE:
QMessageBox::critical(this, windowTitle(),
tr("Could not generate new %1 address")
.arg(QString::fromStdString(
FormatOutputType(address_type))),
QMessageBox::Ok, QMessageBox::Ok);
break;
// These aren't valid return values for our action
case AddressTableModel::EditStatus::INVALID_ADDRESS:
case AddressTableModel::EditStatus::DUPLICATE_ADDRESS:
case AddressTableModel::EditStatus::NO_CHANGES:
assert(false);
}
clear();
}

void ReceiveCoinsDialog::on_recentRequestsView_doubleClicked(
Expand Down
3 changes: 3 additions & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3618,6 +3618,9 @@ bool CWallet::GetNewDestination(const OutputType type, const std::string label,
if (spk_man) {
spk_man->TopUp();
result = spk_man->GetNewDestination(type, dest, error);
} else {
error = strprintf("Error: No %s addresses available.",
FormatOutputType(type));
}
if (result) {
SetAddressBook(dest, label, "receive");
Expand Down

0 comments on commit f53059d

Please sign in to comment.