14 #include <qt/forms/ui_psbtoperationsdialog.h>
30 m_wallet_model(wallet_model),
31 m_client_model(client_model)
34 setWindowTitle(
"PSBT Operations");
41 connect(
m_ui->closeButton, &QPushButton::clicked,
this, &PSBTOperationsDialog::close);
43 m_ui->signTransactionButton->setEnabled(
false);
44 m_ui->broadcastTransactionButton->setEnabled(
false);
61 showStatus(tr(
"Failed to load transaction: %1")
68 m_ui->signTransactionButton->setEnabled(
false);
71 m_ui->broadcastTransactionButton->setEnabled(complete);
86 showStatus(tr(
"Failed to sign transaction: %1")
93 if (!complete && !ctx.
isValid()) {
95 }
else if (!complete && n_signed < 1) {
97 }
else if (!complete) {
98 showStatus(tr(
"Signed %1 inputs, but more signatures are still required.").arg(n_signed),
101 showStatus(tr(
"Signed transaction successfully. Transaction is ready to broadcast."),
103 m_ui->broadcastTransactionButton->setEnabled(
true);
118 std::string err_string;
123 showStatus(tr(
"Transaction broadcast successfully! Transaction ID: %1")
126 showStatus(tr(
"Transaction broadcast failed: %1")
142 QString selected_filter;
143 QString filename_suggestion =
"";
147 filename_suggestion.append(
"-");
153 filename_suggestion.append(address_str +
"-" + amount);
156 filename_suggestion.append(
".psbt");
158 tr(
"Save Transaction Data"), filename_suggestion,
160 tr(
"Partially Signed Transaction (Binary)") + QLatin1String(
" (*.psbt)"), &selected_filter);
161 if (filename.isEmpty()) {
164 std::ofstream out{filename.toLocal8Bit().data(), std::ofstream::out | std::ofstream::binary};
177 QString tx_description =
"";
179 for (
const CTxOut& out : psbtx.
tx->vout) {
182 totalAmount += out.
nValue;
183 tx_description.append(tr(
" * Sends %1 to %2")
186 tx_description.append(
"<br>");
190 tx_description.append(
" * ");
191 if (!*analysis.
fee) {
193 tx_description.append(tr(
"Unable to calculate transaction fee or total transaction amount."));
195 tx_description.append(tr(
"Pays transaction fee: "));
199 tx_description.append(
"<hr />");
200 QStringList alternativeUnits;
207 tx_description.append(QString(
"<b>%1</b>: <b>%2</b>").arg(tr(
"Total Amount"))
209 tx_description.append(QString(
"<br /><span style='font-size:10pt; font-weight:normal;'>(=%1)</span>")
210 .arg(alternativeUnits.join(
" " + tr(
"or") +
" ")));
214 if (num_unsigned > 0) {
215 tx_description.append(
"<br><br>");
216 tx_description.append(tr(
"Transaction has %1 unsigned inputs.").arg(QString::number(num_unsigned)));
219 return tx_description.toStdString();
223 m_ui->statusBar->setText(msg);
226 m_ui->statusBar->setStyleSheet(
"QLabel { background-color : lightgreen }");
230 m_ui->statusBar->setStyleSheet(
"QLabel { background-color : orange }");
234 m_ui->statusBar->setStyleSheet(
"QLabel { background-color : red }");
238 m_ui->statusBar->show();
260 switch (analysis.
next) {
266 QString need_sig_text = tr(
"Transaction still needs signature(s).");
269 need_sig_text +=
" " + tr(
"(But no wallet is loaded.)");
272 need_sig_text +=
" " + tr(
"(But this wallet cannot sign transactions.)");
274 }
else if (n_could_sign < 1) {
275 need_sig_text +=
" " + tr(
"(But this wallet does not have the right keys.)");
int64_t CAmount
Amount in satoshis (Can be negative)
static QString format(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
static QString formatHtmlWithUnit(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as HTML string (with unit)
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
static QString formatWithUnit(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
An output of a transaction.
Model for Bitcoin network client.
interfaces::Node & node() const
OptionsModel * getOptionsModel()
BitcoinUnit getDisplayUnit() const
Dialog showing transaction details.
PartiallySignedTransaction m_transaction_data
PSBTOperationsDialog(QWidget *parent, WalletModel *walletModel, ClientModel *clientModel)
void broadcastTransaction()
void updateTransactionDisplay()
WalletModel * m_wallet_model
Ui::PSBTOperationsDialog * m_ui
void openWithPSBT(PartiallySignedTransaction psbtx)
size_t couldSignInputs(const PartiallySignedTransaction &psbtx)
void showTransactionStatus(const PartiallySignedTransaction &psbtx)
void showStatus(const QString &msg, StatusLevel level)
ClientModel * m_client_model
std::string renderTransaction(const PartiallySignedTransaction &psbtx)
Interface to Bitcoin wallet from Qt view code.
interfaces::Wallet & wallet() const
UnlockContext requestUnlock()
virtual TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string &err_string)=0
Broadcast transaction.
virtual TransactionError fillPSBT(int sighash_type, bool sign, bool bip32derivs, size_t *n_signed, PartiallySignedTransaction &psbtx, bool &complete)=0
Fill PSBT.
virtual bool privateKeysDisabled()=0
bilingual_str TransactionErrorString(const TransactionError err)
std::string EncodeDestination(const CTxDestination &dest)
bool error(const char *fmt, const Args &... args)
Utility functions used by the Bitcoin Qt UI.
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when ...
constexpr auto dialog_flags
void setClipboard(const QString &str)
PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx)
Provides helpful miscellaneous information about where a PSBT is in the signing workflow.
static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE
Maximum fee rate for sendrawtransaction and testmempoolaccept RPC calls.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
size_t CountPSBTUnsignedInputs(const PartiallySignedTransaction &psbt)
Counts the unsigned inputs of a PSBT.
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized.
bool FinalizePSBT(PartiallySignedTransaction &psbtx)
Finalizes a PSBT if possible, combining partial signatures.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
A mutable version of CTransaction.
A version of CTransaction with the PSBT format.
std::optional< CMutableTransaction > tx
Holds the results of AnalyzePSBT (miscellaneous information about a PSBT)
std::optional< CAmount > fee
Amount of fee being paid by the transaction.
PSBTRole next
Which of the BIP 174 roles needs to handle the transaction next.
std::string EncodeBase64(Span< const unsigned char > input)
static const int PROTOCOL_VERSION
network protocol versioning