Skip to content

Commit 3c19fdd

Browse files
committed
Return error when no ScriptPubKeyMan is available for specified type
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.
1 parent 388ba94 commit 3c19fdd

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

src/qt/receivecoinsdialog.cpp

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,40 @@ void ReceiveCoinsDialog::on_receiveButton_clicked()
157157
}
158158
}
159159
address = model->getAddressTableModel()->addRow(AddressTableModel::Receive, label, "", address_type);
160-
SendCoinsRecipient info(address, label,
161-
ui->reqAmount->value(), ui->reqMessage->text());
162-
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
163-
dialog->setAttribute(Qt::WA_DeleteOnClose);
164-
dialog->setModel(model);
165-
dialog->setInfo(info);
166-
dialog->show();
167-
clear();
168160

169-
/* Store request for later reference */
170-
model->getRecentRequestsTableModel()->addNewRequest(info);
161+
switch(model->getAddressTableModel()->getEditStatus())
162+
{
163+
case AddressTableModel::EditStatus::OK: {
164+
// Success
165+
SendCoinsRecipient info(address, label,
166+
ui->reqAmount->value(), ui->reqMessage->text());
167+
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
168+
dialog->setAttribute(Qt::WA_DeleteOnClose);
169+
dialog->setModel(model);
170+
dialog->setInfo(info);
171+
dialog->show();
172+
173+
/* Store request for later reference */
174+
model->getRecentRequestsTableModel()->addNewRequest(info);
175+
break;
176+
}
177+
case AddressTableModel::EditStatus::WALLET_UNLOCK_FAILURE:
178+
QMessageBox::critical(this, windowTitle(),
179+
tr("Could not unlock wallet."),
180+
QMessageBox::Ok, QMessageBox::Ok);
181+
break;
182+
case AddressTableModel::EditStatus::KEY_GENERATION_FAILURE:
183+
QMessageBox::critical(this, windowTitle(),
184+
tr("Could not generate new %1 address").arg(QString::fromStdString(FormatOutputType(address_type))),
185+
QMessageBox::Ok, QMessageBox::Ok);
186+
break;
187+
// These aren't valid return values for our action
188+
case AddressTableModel::EditStatus::INVALID_ADDRESS:
189+
case AddressTableModel::EditStatus::DUPLICATE_ADDRESS:
190+
case AddressTableModel::EditStatus::NO_CHANGES:
191+
assert(false);
192+
}
193+
clear();
171194
}
172195

173196
void ReceiveCoinsDialog::on_recentRequestsView_doubleClicked(const QModelIndex &index)

src/wallet/wallet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,6 +3227,8 @@ bool CWallet::GetNewDestination(const OutputType type, const std::string label,
32273227
if (spk_man) {
32283228
spk_man->TopUp();
32293229
result = spk_man->GetNewDestination(type, dest, error);
3230+
} else {
3231+
error = strprintf("Error: No %s addresses available.", FormatOutputType(type));
32303232
}
32313233
if (result) {
32323234
SetAddressBook(dest, label, "receive");

0 commit comments

Comments
 (0)