5#include <bitcoin-build-config.h>
8#include <qt/forms/ui_sendcoinsdialog.h>
19#include <chainparams.h>
25#include <validation.h>
37#include <QFontMetrics>
40#include <QTextDocument>
45static constexpr std::array
confTargets{2, 4, 6, 12, 24, 48, 144, 504, 1008};
47 if (index+1 >
static_cast<int>(
confTargets.size())) {
56 for (
unsigned int i = 0; i <
confTargets.size(); i++) {
65 QDialog(parent,
GUIUtil::dialog_flags),
73 ui->addButton->setIcon(
QIcon());
74 ui->clearButton->setIcon(
QIcon());
75 ui->sendButton->setIcon(
QIcon());
91#if (QT_VERSION >= QT_VERSION_CHECK(6, 7, 0))
120 if (!
settings.contains(
"fFeeSectionMinimized"))
121 settings.setValue(
"fFeeSectionMinimized",
true);
122 if (!
settings.contains(
"nFeeRadio") &&
settings.contains(
"nTransactionFee") &&
settings.value(
"nTransactionFee").toLongLong() > 0)
124 if (!
settings.contains(
"nFeeRadio"))
126 if (!
settings.contains(
"nSmartFeeSliderPosition"))
127 settings.setValue(
"nSmartFeeSliderPosition", 0);
128 ui->groupFee->setId(
ui->radioSmartFee, 0);
129 ui->groupFee->setId(
ui->radioCustomFee, 1);
130 ui->groupFee->button((
int)std::max(0, std::min(1,
settings.value(
"nFeeRadio").toInt())))->setChecked(
true);
131 ui->customFee->SetAllowEmpty(
false);
132 ui->customFee->setValue(
settings.value(
"nTransactionFee").toLongLong());
153 for(
int i = 0; i <
ui->entries->count(); ++i)
169 ui->frameCoinControl->setVisible(
_model->getOptionsModel()->getCoinControlFeatures());
194 ui->sendButton->setText(
tr(
"Sign on device"));
196 ui->sendButton->setEnabled(
true);
197 ui->sendButton->setToolTip(
tr(
"Connect your hardware wallet first."));
199 ui->sendButton->setEnabled(
false);
201 ui->sendButton->setToolTip(
tr(
"Set external signer script path in Options -> Wallet"));
204 ui->sendButton->setText(
tr(
"Cr&eate Unsigned"));
205 ui->sendButton->setToolTip(
tr(
"Creates a Partially Signed Bitcoin Transaction (PSBT) for use with e.g. an offline %1 wallet, or a PSBT-compatible hardware wallet.").arg(
CLIENT_NAME));
210 if (
settings.value(
"nSmartFeeSliderPosition").toInt() != 0) {
215 settings.remove(
"nSmartFeeSliderPosition");
217 if (
settings.value(
"nConfTarget").toInt() == 0)
228 settings.setValue(
"nFeeRadio",
ui->groupFee->checkedId());
240 for(
int i = 0; i <
ui->entries->count(); ++i)
247 recipients.append(entry->
getValue());
251 ui->scrollArea->ensureWidgetVisible(entry);
257 if(!valid || recipients.isEmpty())
306 if(
rcp.label.length() > 0)
327 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(
CLIENT_NAME));
332 question_string.append(
tr(
"Please, review your transaction. You can create and send this transaction or create 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(
CLIENT_NAME));
351 question_string.append(
"<span style='color:#aa0000; font-weight:bold;'>");
357 question_string.append(
"<span style='font-size:10pt; font-weight:normal;'>");
392 msgBox.setText(
tr(
"Unsigned Transaction",
"PSBT copied"));
393 msgBox.setInformativeText(
tr(
"The PSBT has been copied to the clipboard. You can also save it."));
394 msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
395 msgBox.setDefaultButton(QMessageBox::Discard);
396 msgBox.setObjectName(
"psbt_copied_message");
398 case QMessageBox::Save: {
416 if (filename.isEmpty()) {
419 std::ofstream out{filename.toLocal8Bit().data(), std::ofstream::out | std::ofstream::binary};
426 case QMessageBox::Discard:
434 std::optional<PSBTError> err;
437 }
catch (
const std::runtime_error&
e) {
438 QMessageBox::critical(
nullptr,
tr(
"Sign failed"),
e.what());
441 if (err == PSBTError::EXTERNAL_SIGNER_NOT_FOUND) {
443 const QString msg =
tr(
"External signer not found");
444 QMessageBox::critical(
nullptr, msg, msg);
447 if (err == PSBTError::EXTERNAL_SIGNER_FAILED) {
449 const QString msg =
tr(
"External signer failure");
450 QMessageBox::critical(
nullptr, msg, msg);
454 qWarning() <<
"Failed to sign PSBT";
478 const auto retval =
static_cast<QMessageBox::StandardButton
>(
confirmationDialog->exec());
480 if(retval != QMessageBox::Yes && retval != QMessageBox::Save)
487 if (retval == QMessageBox::Save) {
491 bool complete =
false;
508 bool complete =
false;
553 ui->checkBoxCoinControlChange->setChecked(
false);
554 ui->lineEditCoinControlChange->clear();
558 while(
ui->entries->count())
560 ui->entries->takeAt(0)->widget()->deleteLater();
581 ui->entries->addWidget(entry);
590 ui->scrollAreaWidgetContents->resize(
ui->scrollAreaWidgetContents->sizeHint());
595 QMetaObject::invokeMethod(
ui->scrollArea, [
this] {
596 if (ui->scrollArea->verticalScrollBar()) {
597 ui->scrollArea->verticalScrollBar()->setValue(ui->scrollArea->verticalScrollBar()->maximum());
599 }, Qt::QueuedConnection);
601 updateTabsAndLabels();
616 if (
ui->entries->count() == 1)
619 entry->deleteLater();
626 for(
int i = 0; i <
ui->entries->count(); ++i)
634 QWidget::setTabOrder(
prev,
ui->sendButton);
635 QWidget::setTabOrder(
ui->sendButton,
ui->clearButton);
636 QWidget::setTabOrder(
ui->clearButton,
ui->addButton);
637 return ui->addButton;
644 if(
ui->entries->count() == 1)
667 if(
ui->entries->count() == 1)
698 ui->labelBalanceName->setText(
tr(
"External balance:"));
722 msgParams.first =
tr(
"The recipient address is not valid. Please recheck.");
725 msgParams.first =
tr(
"The amount to pay must be larger than 0.");
728 msgParams.first =
tr(
"The amount exceeds your balance.");
731 msgParams.first =
tr(
"Duplicate address found: addresses should only be used once each.");
734 msgParams.first =
tr(
"Transaction creation failed!");
752 ui->horizontalLayoutSmartFee->setContentsMargins(0, (
fMinimize ? 0 : 6), 0, 0);
776 for (
int i = 0; i <
ui->entries->count(); ++i) {
778 if (
e && !
e->isHidden() &&
e != entry) {
779 amount -=
e->getValue().amount;
793 ui->confTargetSelector ->setEnabled(
ui->radioSmartFee->isChecked());
794 ui->labelSmartFee ->setEnabled(
ui->radioSmartFee->isChecked());
795 ui->labelSmartFee2 ->setEnabled(
ui->radioSmartFee->isChecked());
796 ui->labelSmartFee3 ->setEnabled(
ui->radioSmartFee->isChecked());
797 ui->labelFeeEstimation ->setEnabled(
ui->radioSmartFee->isChecked());
798 ui->labelCustomFeeWarning ->setEnabled(
ui->radioCustomFee->isChecked());
799 ui->labelCustomPerKilobyte ->setEnabled(
ui->radioCustomFee->isChecked());
800 ui->customFee ->setEnabled(
ui->radioCustomFee->isChecked());
808 if (
ui->radioSmartFee->isChecked())
809 ui->labelFeeMinimized->setText(
ui->labelSmartFee->text());
817 if (
ui->radioCustomFee->isChecked()) {
843 std::optional<int> returned_target;
850 ui->labelSmartFee2->show();
851 ui->labelFeeEstimation->setText(
"");
852 ui->fallbackFeeWarningLabel->setVisible(
true);
853 int lightness =
ui->fallbackFeeWarningLabel->palette().color(QPalette::WindowText).lightness();
855 ui->fallbackFeeWarningLabel->setStyleSheet(
"QLabel { color: " +
warning_colour.name() +
"; }");
860 ui->labelSmartFee2->hide();
861 ui->labelFeeEstimation->setText(
"");
862 if (returned_target) {
863 ui->labelFeeEstimation->setText(
tr(
"Estimated to begin confirmation within %n block(s).",
"", *returned_target));
865 ui->fallbackFeeWarningLabel->setVisible(
false);
910 ui->frameCoinControl->setVisible(
checked);
928#if (QT_VERSION >= QT_VERSION_CHECK(6, 7, 0))
934 if (state == Qt::Unchecked)
937 ui->labelCoinControlChangeLabel->clear();
941 coinControlChangeEdited(ui->lineEditCoinControlChange->text());
943 ui->lineEditCoinControlChange->setEnabled((state == Qt::Checked));
953 ui->labelCoinControlChangeLabel->setStyleSheet(
"QLabel{color:red;}");
959 ui->labelCoinControlChangeLabel->setText(
"");
963 ui->labelCoinControlChangeLabel->setText(
tr(
"Warning: Invalid Bitcoin address"));
968 ui->labelCoinControlChangeLabel->setText(
tr(
"Warning: Unknown change address"));
971 QMessageBox::StandardButton
btnRetVal = QMessageBox::question(
this,
tr(
"Confirm custom change address"),
tr(
"The address you selected for change is not part of this wallet. Any or all funds in your wallet may be sent to this address. Are you sure?"),
972 QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
978 ui->lineEditCoinControlChange->setText(
"");
979 ui->labelCoinControlChangeLabel->setStyleSheet(
"QLabel{color:black;}");
980 ui->labelCoinControlChangeLabel->setText(
"");
985 ui->labelCoinControlChangeLabel->setStyleSheet(
"QLabel{color:black;}");
992 ui->labelCoinControlChangeLabel->setText(
tr(
"(no label)"));
1012 for(
int i = 0; i <
ui->entries->count(); ++i)
1015 if(entry && !entry->isHidden())
1019 if (
rcp.fSubtractFeeFromAmount)
1030 ui->labelCoinControlAutomaticallySelected->hide();
1031 ui->widgetCoinControl->show();
1036 ui->labelCoinControlAutomaticallySelected->show();
1037 ui->widgetCoinControl->hide();
1038 ui->labelCoinControlInsuffFunds->hide();
1045 setIcon(QMessageBox::Question);
1066 return QMessageBox::exec();
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
int64_t CAmount
Amount in satoshis (Can be negative)
const CChainParams & Params()
Return the currently selected parameters.
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty 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)
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
Model for Bitcoin network client.
void numBlocksChanged(int count, const QDateTime &blockDate, double nVerificationProgress, SyncType header, SynchronizationState sync_state)
static QList< CAmount > payAmounts
static void updateLabels(wallet::CCoinControl &m_coin_control, WalletModel *, QDialog *)
static bool fSubtractFeeFromAmount
Double ended buffer combining vector and stream-like interfaces.
bool getEnablePSBTControls() const
void coinControlFeaturesChanged(bool)
void displayUnitChanged(BitcoinUnit unit)
BitcoinUnit getDisplayUnit() const
bool hasSigner()
Whether -signer was set or not.
A version of CTransaction with the PSBT format.
Dialog for sending bitcoins.
void useAvailableBalance(SendCoinsEntry *entry)
void presentPSBT(PartiallySignedTransaction &psbt)
ClientModel * clientModel
void coinControlChangeEdited(const QString &)
void coinControlClipboardFee()
void on_buttonChooseFee_clicked()
void processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg=QString())
void setClientModel(ClientModel *clientModel)
void updateTabsAndLabels()
void updateFeeSectionControls()
SendCoinsEntry * addEntry()
void updateNumberOfBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, SyncType synctype, SynchronizationState sync_state)
void pasteEntry(const SendCoinsRecipient &rv)
void updateFeeMinimizedLabel()
const PlatformStyle * platformStyle
std::unique_ptr< wallet::CCoinControl > m_coin_control
void coinControlClipboardQuantity()
void coinControlButtonClicked()
void coinControlClipboardAfterFee()
bool signWithExternalSigner(PartiallySignedTransaction &psbt, CMutableTransaction &mtx, bool &complete)
QWidget * setupTabChain(QWidget *prev)
Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://...
bool PrepareSendText(QString &question_string, QString &informative_text, QString &detailed_text)
void sendButtonClicked(bool checked)
void setModel(WalletModel *model)
void coinControlChangeChecked(Qt::CheckState)
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
void setBalance(const interfaces::WalletBalances &balances)
void coinControlClipboardAmount()
void setAddress(const QString &address)
void coinsSent(const Txid &txid)
void coinControlClipboardChange()
std::unique_ptr< WalletModelTransaction > m_current_transaction
bool fNewRecipientAllowed
void removeEntry(SendCoinsEntry *entry)
void updateSmartFeeLabel()
void updateCoinControlState()
void coinControlClipboardBytes()
void message(const QString &title, const QString &message, unsigned int style)
SendCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent=nullptr)
void on_buttonMinimizeFee_clicked()
void coinControlUpdateLabels()
void coinControlFeatureChanged(bool)
void minimizeFeeSection(bool fMinimize)
A single entry in the dialog for sending bitcoins.
void setAddress(const QString &address)
void subtractFeeFromAmountChanged()
void useAvailableBalance(SendCoinsEntry *entry)
void setValue(const SendCoinsRecipient &value)
void setModel(WalletModel *model)
void removeEntry(SendCoinsEntry *entry)
void setAmount(const CAmount &amount)
QWidget * setupTabChain(QWidget *prev)
Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://...
bool validate(interfaces::Node &node)
void checkSubtractFeeFromAmount()
SendCoinsRecipient getValue()
QString m_psbt_button_text
SendConfirmationDialog(const QString &title, const QString &text, const QString &informative_text="", const QString &detailed_text="", int secDelay=SEND_CONFIRM_DELAY, bool enable_send=true, bool always_show_unsigned=true, QWidget *parent=nullptr)
QAbstractButton * m_psbt_button
QAbstractButton * yesButton
QString confirmButtonText
Interface to Bitcoin wallet from Qt view code.
interfaces::Node & node() const
AddressTableModel * getAddressTableModel() const
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const wallet::CCoinControl &coinControl)
void sendCoins(WalletModelTransaction &transaction)
CAmount getAvailableBalance(const wallet::CCoinControl *control)
bool isMultiwallet() const
interfaces::Wallet & wallet() const
OptionsModel * getOptionsModel() const
UnlockContext requestUnlock()
void balanceChanged(const interfaces::WalletBalances &balances)
interfaces::WalletBalances getCachedBalance() const
QString getWalletName() const
@ TransactionCreationFailed
virtual CAmount getMaxTxFee()=0
Get max tx fee.
virtual CAmount getRequiredFee(unsigned int tx_bytes)=0
Get required fee.
virtual unsigned int getConfirmTarget()=0
Get tx confirm target.
virtual bool hasExternalSigner()=0
virtual bool isSpendable(const CTxDestination &dest)=0
Return whether wallet has private key.
virtual CAmount getMinimumFee(unsigned int tx_bytes, const wallet::CCoinControl &coin_control, std::optional< int > *returned_target, FeeReason *reason)=0
Get minimum fee.
virtual std::optional< common::PSBTError > fillPSBT(const common::PSBTFillOptions &options, size_t *n_signed, PartiallySignedTransaction &psbtx, bool &complete)=0
Fill PSBT.
virtual bool privateKeysDisabled()=0
bool m_allow_other_inputs
If true, the selection process can add extra unselected inputs from the wallet while requires all sel...
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
Utility functions used by the Bitcoin Qt UI.
QString HtmlEscape(const QString &str, bool fMultiLine)
void ShowModalDialogAsynchronously(QDialog *dialog)
Shows a QDialog instance asynchronously, and deletes it on close.
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 ...
QString formatNiceTimeOffset(qint64 secs)
auto ExceptionSafeConnect(Sender sender, Signal signal, Receiver receiver, Slot method, Qt::ConnectionType type=Qt::AutoConnection)
A drop-in replacement of QObject::connect function (see: https://doc.qt.io/qt-5/qobject....
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text.
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
void setClipboard(const QString &str)
Home for public enum and struct type definitions.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized.
int getConfTargetForIndex(int index)
int getIndexForConfTarget(int target)
static constexpr std::array confTargets
#define SEND_CONFIRM_DELAY
A mutable version of CTransaction.
Collection of wallet balances.
std::string EncodeBase64(std::span< const unsigned char > input)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
SynchronizationState
Current sync state passed to tip changed callbacks.
Home for public enum and struct type definitions.