@@ -401,6 +401,52 @@ bool SendCoinsDialog::PrepareSendText(QString& question_string, QString& informa
401401 return true ;
402402}
403403
404+ void SendCoinsDialog::presentPSBT (PartiallySignedTransaction& psbtx)
405+ {
406+ // Serialize the PSBT
407+ CDataStream ssTx (SER_NETWORK, PROTOCOL_VERSION);
408+ ssTx << psbtx;
409+ GUIUtil::setClipboard (EncodeBase64 (ssTx.str ()).c_str ());
410+ QMessageBox msgBox;
411+ msgBox.setText (" Unsigned Transaction" );
412+ msgBox.setInformativeText (" The PSBT has been copied to the clipboard. You can also save it." );
413+ msgBox.setStandardButtons (QMessageBox::Save | QMessageBox::Discard);
414+ msgBox.setDefaultButton (QMessageBox::Discard);
415+ switch (msgBox.exec ()) {
416+ case QMessageBox::Save: {
417+ QString selectedFilter;
418+ QString fileNameSuggestion = " " ;
419+ bool first = true ;
420+ for (const SendCoinsRecipient &rcp : m_current_transaction->getRecipients ()) {
421+ if (!first) {
422+ fileNameSuggestion.append (" - " );
423+ }
424+ QString labelOrAddress = rcp.label .isEmpty () ? rcp.address : rcp.label ;
425+ QString amount = BitcoinUnits::formatWithUnit (model->getOptionsModel ()->getDisplayUnit (), rcp.amount );
426+ fileNameSuggestion.append (labelOrAddress + " -" + amount);
427+ first = false ;
428+ }
429+ fileNameSuggestion.append (" .psbt" );
430+ QString filename = GUIUtil::getSaveFileName (this ,
431+ tr (" Save Transaction Data" ), fileNameSuggestion,
432+ // : Expanded name of the binary PSBT file format. See: BIP 174.
433+ tr (" Partially Signed Transaction (Binary)" ) + QLatin1String (" (*.psbt)" ), &selectedFilter);
434+ if (filename.isEmpty ()) {
435+ return ;
436+ }
437+ std::ofstream out{filename.toLocal8Bit ().data (), std::ofstream::out | std::ofstream::binary};
438+ out << ssTx.str ();
439+ out.close ();
440+ Q_EMIT message (tr (" PSBT saved" ), " PSBT saved to disk" , CClientUIInterface::MSG_INFORMATION);
441+ break ;
442+ }
443+ case QMessageBox::Discard:
444+ break ;
445+ default :
446+ assert (false );
447+ } // msgBox.exec()
448+ }
449+
404450void SendCoinsDialog::sendButtonClicked ([[maybe_unused]] bool checked)
405451{
406452 if (!model || !model->getOptionsModel ())
@@ -481,48 +527,7 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
481527
482528 // Copy PSBT to clipboard and offer to save
483529 assert (!complete);
484- // Serialize the PSBT
485- CDataStream ssTx (SER_NETWORK, PROTOCOL_VERSION);
486- ssTx << psbtx;
487- GUIUtil::setClipboard (EncodeBase64 (ssTx.str ()).c_str ());
488- QMessageBox msgBox;
489- msgBox.setText (" Unsigned Transaction" );
490- msgBox.setInformativeText (" The PSBT has been copied to the clipboard. You can also save it." );
491- msgBox.setStandardButtons (QMessageBox::Save | QMessageBox::Discard);
492- msgBox.setDefaultButton (QMessageBox::Discard);
493- switch (msgBox.exec ()) {
494- case QMessageBox::Save: {
495- QString selectedFilter;
496- QString fileNameSuggestion = " " ;
497- bool first = true ;
498- for (const SendCoinsRecipient &rcp : m_current_transaction->getRecipients ()) {
499- if (!first) {
500- fileNameSuggestion.append (" - " );
501- }
502- QString labelOrAddress = rcp.label .isEmpty () ? rcp.address : rcp.label ;
503- QString amount = BitcoinUnits::formatWithUnit (model->getOptionsModel ()->getDisplayUnit (), rcp.amount );
504- fileNameSuggestion.append (labelOrAddress + " -" + amount);
505- first = false ;
506- }
507- fileNameSuggestion.append (" .psbt" );
508- QString filename = GUIUtil::getSaveFileName (this ,
509- tr (" Save Transaction Data" ), fileNameSuggestion,
510- // : Expanded name of the binary PSBT file format. See: BIP 174.
511- tr (" Partially Signed Transaction (Binary)" ) + QLatin1String (" (*.psbt)" ), &selectedFilter);
512- if (filename.isEmpty ()) {
513- return ;
514- }
515- std::ofstream out{filename.toLocal8Bit ().data (), std::ofstream::out | std::ofstream::binary};
516- out << ssTx.str ();
517- out.close ();
518- Q_EMIT message (tr (" PSBT saved" ), " PSBT saved to disk" , CClientUIInterface::MSG_INFORMATION);
519- break ;
520- }
521- case QMessageBox::Discard:
522- break ;
523- default :
524- assert (false );
525- } // msgBox.exec()
530+ presentPSBT (psbtx);
526531 } else {
527532 assert (!model->wallet ().privateKeysDisabled ());
528533 // now send the prepared transaction
0 commit comments