Skip to content

Commit f689530

Browse files
Sjorsgwillen
andcommitted
[gui] save PSBT to file
co-authored-by: Glenn Willen <[email protected]>
1 parent 1d05a9d commit f689530

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

src/qt/sendcoinsdialog.cpp

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ bool SendCoinsDialog::PrepareSendText(QString& question_string, QString& informa
314314

315315
question_string.append("<br /><span style='font-size:10pt;'>");
316316
if (model->wallet().privateKeysDisabled()) {
317-
question_string.append(tr("Please, review your transaction proposal. This will produce a Partially Signed Bitcoin Transaction (PSBT) which you can copy and then sign with e.g. an offline %1 wallet, or a PSBT-compatible hardware wallet.").arg(PACKAGE_NAME));
317+
question_string.append(tr("Please, review your transaction proposal. This will produce a Partially Signed Bitcoin Transaction (PSBT) which you can save or copy and then sign with e.g. an offline %1 wallet, or a PSBT-compatible hardware wallet.").arg(PACKAGE_NAME));
318318
} else {
319319
question_string.append(tr("Please, review your transaction."));
320320
}
@@ -380,7 +380,7 @@ void SendCoinsDialog::on_sendButton_clicked()
380380
assert(m_current_transaction);
381381

382382
const QString confirmation = model->wallet().privateKeysDisabled() ? tr("Confirm transaction proposal") : tr("Confirm send coins");
383-
const QString confirmButtonText = model->wallet().privateKeysDisabled() ? tr("Copy PSBT to clipboard") : tr("Send");
383+
const QString confirmButtonText = model->wallet().privateKeysDisabled() ? tr("Create Unsigned") : tr("Send");
384384
SendConfirmationDialog confirmationDialog(confirmation, question_string, informative_text, detailed_text, SEND_CONFIRM_DELAY, confirmButtonText, this);
385385
confirmationDialog.exec();
386386
QMessageBox::StandardButton retval = static_cast<QMessageBox::StandardButton>(confirmationDialog.result());
@@ -403,7 +403,43 @@ void SendCoinsDialog::on_sendButton_clicked()
403403
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
404404
ssTx << psbtx;
405405
GUIUtil::setClipboard(EncodeBase64(ssTx.str()).c_str());
406-
Q_EMIT message(tr("PSBT copied"), "Copied to clipboard", CClientUIInterface::MSG_INFORMATION);
406+
QMessageBox msgBox;
407+
msgBox.setText("Unsigned Transaction");
408+
msgBox.setInformativeText("The PSBT has been copied to the clipboard. You can also save it.");
409+
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
410+
msgBox.setDefaultButton(QMessageBox::Discard);
411+
switch (msgBox.exec()) {
412+
case QMessageBox::Save: {
413+
QString selectedFilter;
414+
QString fileNameSuggestion = "";
415+
bool first = true;
416+
for (const SendCoinsRecipient &rcp : m_current_transaction->getRecipients()) {
417+
if (!first) {
418+
fileNameSuggestion.append(" - ");
419+
}
420+
QString labelOrAddress = rcp.label.isEmpty() ? rcp.address : rcp.label;
421+
QString amount = BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount);
422+
fileNameSuggestion.append(labelOrAddress + "-" + amount);
423+
first = false;
424+
}
425+
fileNameSuggestion.append(".psbt");
426+
QString filename = GUIUtil::getSaveFileName(this,
427+
tr("Save Transaction Data"), fileNameSuggestion,
428+
tr("Partially Signed Transaction (Binary) (*.psbt)"), &selectedFilter);
429+
if (filename.isEmpty()) {
430+
return;
431+
}
432+
std::ofstream out(filename.toLocal8Bit().data());
433+
out << ssTx.str();
434+
out.close();
435+
Q_EMIT message(tr("PSBT saved"), "PSBT saved to disk", CClientUIInterface::MSG_INFORMATION);
436+
break;
437+
}
438+
case QMessageBox::Discard:
439+
break;
440+
default:
441+
assert(false);
442+
}
407443
} else {
408444
// now send the prepared transaction
409445
WalletModel::SendCoinsReturn sendStatus = model->sendCoins(*m_current_transaction);
@@ -422,10 +458,13 @@ void SendCoinsDialog::on_sendButton_clicked()
422458
coinControlUpdateLabels();
423459
}
424460
fNewRecipientAllowed = true;
461+
m_current_transaction.reset();
425462
}
426463

427464
void SendCoinsDialog::clear()
428465
{
466+
m_current_transaction.reset();
467+
429468
// Clear coin control settings
430469
CoinControlDialog::coinControl()->UnSelectAll();
431470
ui->checkBoxCoinControlChange->setChecked(false);

0 commit comments

Comments
 (0)