13 #include <qt/forms/ui_psbtoperationsdialog.h> 24 m_wallet_model(wallet_model),
25 m_client_model(client_model)
28 setWindowTitle(
"PSBT Operations");
35 connect(
m_ui->closeButton, &QPushButton::clicked,
this, &PSBTOperationsDialog::close);
37 m_ui->signTransactionButton->setEnabled(
false);
38 m_ui->broadcastTransactionButton->setEnabled(
false);
55 showStatus(tr(
"Failed to load transaction: %1")
60 m_ui->broadcastTransactionButton->setEnabled(complete);
73 showStatus(tr(
"Failed to sign transaction: %1")
80 if (!complete && n_signed < 1) {
82 }
else if (!complete) {
83 showStatus(tr(
"Signed %1 inputs, but more signatures are still required.").arg(n_signed),
86 showStatus(tr(
"Signed transaction successfully. Transaction is ready to broadcast."),
88 m_ui->broadcastTransactionButton->setEnabled(
true);
103 std::string err_string;
108 showStatus(tr(
"Transaction broadcast successfully! Transaction ID: %1")
111 showStatus(tr(
"Transaction broadcast failed: %1")
127 QString selected_filter;
128 QString filename_suggestion =
"";
132 filename_suggestion.append(
"-");
138 filename_suggestion.append(address_str +
"-" + amount);
141 filename_suggestion.append(
".psbt");
143 tr(
"Save Transaction Data"), filename_suggestion,
145 tr(
"Partially Signed Transaction (Binary)") + QLatin1String(
" (*.psbt)"), &selected_filter);
146 if (filename.isEmpty()) {
149 std::ofstream out(filename.toLocal8Bit().data(), std::ofstream::out | std::ofstream::binary);
162 QString tx_description =
"";
164 for (
const CTxOut& out : psbtx.
tx->vout) {
167 totalAmount += out.
nValue;
168 tx_description.append(tr(
" * Sends %1 to %2")
171 tx_description.append(
"<br>");
175 tx_description.append(
" * ");
176 if (!*analysis.
fee) {
178 tx_description.append(tr(
"Unable to calculate transaction fee or total transaction amount."));
180 tx_description.append(tr(
"Pays transaction fee: "));
184 tx_description.append(
"<hr />");
185 QStringList alternativeUnits;
192 tx_description.append(QString(
"<b>%1</b>: <b>%2</b>").arg(tr(
"Total Amount"))
194 tx_description.append(QString(
"<br /><span style='font-size:10pt; font-weight:normal;'>(=%1)</span>")
195 .arg(alternativeUnits.join(
" " + tr(
"or") +
" ")));
199 if (num_unsigned > 0) {
200 tx_description.append(
"<br><br>");
201 tx_description.append(tr(
"Transaction has %1 unsigned inputs.").arg(QString::number(num_unsigned)));
204 return tx_description.toStdString();
208 m_ui->statusBar->setText(msg);
211 m_ui->statusBar->setStyleSheet(
"QLabel { background-color : lightgreen }");
215 m_ui->statusBar->setStyleSheet(
"QLabel { background-color : orange }");
219 m_ui->statusBar->setStyleSheet(
"QLabel { background-color : red }");
223 m_ui->statusBar->show();
241 switch (analysis.
next) {
247 QString need_sig_text = tr(
"Transaction still needs signature(s).");
250 need_sig_text +=
" " + tr(
"(But this wallet cannot sign transactions.)");
252 }
else if (n_could_sign < 1) {
253 need_sig_text +=
" " + tr(
"(But this wallet does not have the right keys.)");
std::shared_ptr< const CTransaction > CTransactionRef
virtual bool privateKeysDisabled()=0
interfaces::Wallet & wallet() const
std::string renderTransaction(const PartiallySignedTransaction &psbtx)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
Utility functions used by the Bitcoin Qt UI.
Dialog showing transaction details.
PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx)
Provides helpful miscellaneous information about where a PSBT is in the signing workflow.
void broadcastTransaction()
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
bool FinalizePSBT(PartiallySignedTransaction &psbtx)
Finalizes a PSBT if possible, combining partial signatures.
PSBTRole next
Which of the BIP 174 roles needs to handle the transaction next.
Holds the results of AnalyzePSBT (miscellaneous information about a PSBT)
OptionsModel * getOptionsModel()
void updateTransactionDisplay()
bilingual_str TransactionErrorString(const TransactionError err)
A version of CTransaction with the PSBT format.
Double ended buffer combining vector and stream-like interfaces.
ClientModel * m_client_model
Ui::PSBTOperationsDialog * m_ui
void openWithPSBT(PartiallySignedTransaction psbtx)
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized...
int getDisplayUnit() const
constexpr auto dialog_flags
int64_t CAmount
Amount in satoshis (Can be negative)
size_t couldSignInputs(const PartiallySignedTransaction &psbtx)
std::string EncodeBase64(Span< const unsigned char > input)
void setClipboard(const QString &str)
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as HTML string (with unit)
static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE
Maximum fee rate for sendrawtransaction and testmempoolaccept RPC calls.
PartiallySignedTransaction m_transaction_data
interfaces::Node & node() const
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
void showTransactionStatus(const PartiallySignedTransaction &psbtx)
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
An output of a transaction.
Model for Bitcoin network client.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
size_t CountPSBTUnsignedInputs(const PartiallySignedTransaction &psbt)
Counts the unsigned inputs of a PSBT.
PSBTOperationsDialog(QWidget *parent, WalletModel *walletModel, ClientModel *clientModel)
TransactionError BroadcastTransaction(NodeContext &node, const CTransactionRef tx, std::string &err_string, const CAmount &max_tx_fee, bool relay, bool wait_callback)
Submit a transaction to the mempool and (optionally) relay it to all P2P peers.
void showStatus(const QString &msg, StatusLevel level)
std::optional< CAmount > fee
Amount of fee being paid by the transaction.
Interface to Bitcoin wallet from Qt view code.
static const int PROTOCOL_VERSION
network protocol versioning
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 ...
virtual NodeContext * context()
Get and set internal node context.
std::string EncodeDestination(const CTxDestination &dest)
A mutable version of CTransaction.
virtual TransactionError fillPSBT(int sighash_type, bool sign, bool bip32derivs, size_t *n_signed, PartiallySignedTransaction &psbtx, bool &complete)=0
Fill PSBT.
std::optional< CMutableTransaction > tx
bool error(const char *fmt, const Args &... args)
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
WalletModel * m_wallet_model
OptionsModel * getOptionsModel()