mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 11:13:23 -03:00
move-only: helper function to present PSBT
This commit does not change behavior. Review hint: git show --color-moved --color-moved-ws=allow-indentation-change
This commit is contained in:
parent
72f97289c4
commit
026b5b4523
2 changed files with 49 additions and 42 deletions
|
@ -401,6 +401,52 @@ bool SendCoinsDialog::PrepareSendText(QString& question_string, QString& informa
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SendCoinsDialog::presentPSBT(PartiallySignedTransaction& psbtx)
|
||||||
|
{
|
||||||
|
// Serialize the PSBT
|
||||||
|
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
|
||||||
|
ssTx << psbtx;
|
||||||
|
GUIUtil::setClipboard(EncodeBase64(ssTx.str()).c_str());
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setText("Unsigned Transaction");
|
||||||
|
msgBox.setInformativeText("The PSBT has been copied to the clipboard. You can also save it.");
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
|
||||||
|
msgBox.setDefaultButton(QMessageBox::Discard);
|
||||||
|
switch (msgBox.exec()) {
|
||||||
|
case QMessageBox::Save: {
|
||||||
|
QString selectedFilter;
|
||||||
|
QString fileNameSuggestion = "";
|
||||||
|
bool first = true;
|
||||||
|
for (const SendCoinsRecipient &rcp : m_current_transaction->getRecipients()) {
|
||||||
|
if (!first) {
|
||||||
|
fileNameSuggestion.append(" - ");
|
||||||
|
}
|
||||||
|
QString labelOrAddress = rcp.label.isEmpty() ? rcp.address : rcp.label;
|
||||||
|
QString amount = BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount);
|
||||||
|
fileNameSuggestion.append(labelOrAddress + "-" + amount);
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
fileNameSuggestion.append(".psbt");
|
||||||
|
QString filename = GUIUtil::getSaveFileName(this,
|
||||||
|
tr("Save Transaction Data"), fileNameSuggestion,
|
||||||
|
//: Expanded name of the binary PSBT file format. See: BIP 174.
|
||||||
|
tr("Partially Signed Transaction (Binary)") + QLatin1String(" (*.psbt)"), &selectedFilter);
|
||||||
|
if (filename.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::ofstream out{filename.toLocal8Bit().data(), std::ofstream::out | std::ofstream::binary};
|
||||||
|
out << ssTx.str();
|
||||||
|
out.close();
|
||||||
|
Q_EMIT message(tr("PSBT saved"), "PSBT saved to disk", CClientUIInterface::MSG_INFORMATION);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QMessageBox::Discard:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
} // msgBox.exec()
|
||||||
|
}
|
||||||
|
|
||||||
void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
|
void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
|
||||||
{
|
{
|
||||||
if(!model || !model->getOptionsModel())
|
if(!model || !model->getOptionsModel())
|
||||||
|
@ -481,48 +527,7 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
|
||||||
|
|
||||||
// Copy PSBT to clipboard and offer to save
|
// Copy PSBT to clipboard and offer to save
|
||||||
assert(!complete);
|
assert(!complete);
|
||||||
// Serialize the PSBT
|
presentPSBT(psbtx);
|
||||||
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
|
|
||||||
ssTx << psbtx;
|
|
||||||
GUIUtil::setClipboard(EncodeBase64(ssTx.str()).c_str());
|
|
||||||
QMessageBox msgBox;
|
|
||||||
msgBox.setText("Unsigned Transaction");
|
|
||||||
msgBox.setInformativeText("The PSBT has been copied to the clipboard. You can also save it.");
|
|
||||||
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
|
|
||||||
msgBox.setDefaultButton(QMessageBox::Discard);
|
|
||||||
switch (msgBox.exec()) {
|
|
||||||
case QMessageBox::Save: {
|
|
||||||
QString selectedFilter;
|
|
||||||
QString fileNameSuggestion = "";
|
|
||||||
bool first = true;
|
|
||||||
for (const SendCoinsRecipient &rcp : m_current_transaction->getRecipients()) {
|
|
||||||
if (!first) {
|
|
||||||
fileNameSuggestion.append(" - ");
|
|
||||||
}
|
|
||||||
QString labelOrAddress = rcp.label.isEmpty() ? rcp.address : rcp.label;
|
|
||||||
QString amount = BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount);
|
|
||||||
fileNameSuggestion.append(labelOrAddress + "-" + amount);
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
fileNameSuggestion.append(".psbt");
|
|
||||||
QString filename = GUIUtil::getSaveFileName(this,
|
|
||||||
tr("Save Transaction Data"), fileNameSuggestion,
|
|
||||||
//: Expanded name of the binary PSBT file format. See: BIP 174.
|
|
||||||
tr("Partially Signed Transaction (Binary)") + QLatin1String(" (*.psbt)"), &selectedFilter);
|
|
||||||
if (filename.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::ofstream out{filename.toLocal8Bit().data(), std::ofstream::out | std::ofstream::binary};
|
|
||||||
out << ssTx.str();
|
|
||||||
out.close();
|
|
||||||
Q_EMIT message(tr("PSBT saved"), "PSBT saved to disk", CClientUIInterface::MSG_INFORMATION);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QMessageBox::Discard:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
} // msgBox.exec()
|
|
||||||
} else {
|
} else {
|
||||||
assert(!model->wallet().privateKeysDisabled());
|
assert(!model->wallet().privateKeysDisabled());
|
||||||
// now send the prepared transaction
|
// now send the prepared transaction
|
||||||
|
|
|
@ -70,6 +70,8 @@ private:
|
||||||
bool fFeeMinimized;
|
bool fFeeMinimized;
|
||||||
const PlatformStyle *platformStyle;
|
const PlatformStyle *platformStyle;
|
||||||
|
|
||||||
|
// Copy PSBT to clipboard and offer to save it.
|
||||||
|
void presentPSBT(PartiallySignedTransaction& psbt);
|
||||||
// Process WalletModel::SendCoinsReturn and generate a pair consisting
|
// Process WalletModel::SendCoinsReturn and generate a pair consisting
|
||||||
// of a message and message flags for use in Q_EMIT message().
|
// of a message and message flags for use in Q_EMIT message().
|
||||||
// Additional parameter msgArg can be used via .arg(msgArg).
|
// Additional parameter msgArg can be used via .arg(msgArg).
|
||||||
|
|
Loading…
Add table
Reference in a new issue