5 #if defined(HAVE_CONFIG_H) 27 #include <validation.h> 37 #include <QFontMetrics> 40 #include <QTextDocument> 45 static 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++) {
70 fNewRecipientAllowed(true),
72 platformStyle(_platformStyle)
99 QAction *clipboardQuantityAction =
new QAction(tr(
"Copy quantity"),
this);
100 QAction *clipboardAmountAction =
new QAction(tr(
"Copy amount"),
this);
101 QAction *clipboardFeeAction =
new QAction(tr(
"Copy fee"),
this);
102 QAction *clipboardAfterFeeAction =
new QAction(tr(
"Copy after fee"),
this);
103 QAction *clipboardBytesAction =
new QAction(tr(
"Copy bytes"),
this);
104 QAction *clipboardLowOutputAction =
new QAction(tr(
"Copy dust"),
this);
105 QAction *clipboardChangeAction =
new QAction(tr(
"Copy change"),
this);
123 if (!settings.contains(
"fFeeSectionMinimized"))
124 settings.setValue(
"fFeeSectionMinimized",
true);
125 if (!settings.contains(
"nFeeRadio") && settings.contains(
"nTransactionFee") && settings.value(
"nTransactionFee").toLongLong() > 0)
126 settings.setValue(
"nFeeRadio", 1);
127 if (!settings.contains(
"nFeeRadio"))
128 settings.setValue(
"nFeeRadio", 0);
129 if (!settings.contains(
"nSmartFeeSliderPosition"))
130 settings.setValue(
"nSmartFeeSliderPosition", 0);
131 if (!settings.contains(
"nTransactionFee"))
135 ui->
groupFee->button((
int)std::max(0, std::min(1, settings.value(
"nFeeRadio").toInt())))->setChecked(
true);
154 this->
model = _model;
158 for(
int i = 0; i <
ui->
entries->count(); ++i)
184 #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) 212 ui->
sendButton->setToolTip(tr(
"Connect your hardware wallet first."));
216 ui->
sendButton->setToolTip(tr(
"Set external signer script path in Options -> Wallet"));
220 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(
PACKAGE_NAME));
225 if (settings.value(
"nSmartFeeSliderPosition").toInt() != 0) {
228 int nConfirmTarget = 25 - settings.value(
"nSmartFeeSliderPosition").toInt();
229 settings.setValue(
"nConfTarget", nConfirmTarget);
230 settings.remove(
"nSmartFeeSliderPosition");
232 if (settings.value(
"nConfTarget").toInt() == 0)
243 settings.setValue(
"nFeeRadio",
ui->
groupFee->checkedId());
252 QList<SendCoinsRecipient> recipients;
255 for(
int i = 0; i <
ui->
entries->count(); ++i)
262 recipients.append(entry->
getValue());
272 if(!valid || recipients.isEmpty())
304 QStringList formatted;
314 QString address = rcp.address;
316 QString recipientElement;
319 if(rcp.label.length() > 0)
322 recipientElement.append(QString(
" (%1)").arg(address));
326 recipientElement.append(tr(
"%1 to %2").arg(amount, address));
329 formatted.append(recipientElement);
334 question_string.append(tr(
"Do you want to create this transaction?"));
335 question_string.append(
"<br /><span style='font-size:10pt;'>");
340 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(
PACKAGE_NAME));
345 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(
PACKAGE_NAME));
348 question_string.append(tr(
"Please, review your transaction."));
350 question_string.append(
"</span>%1");
355 question_string.append(
"<hr /><b>");
356 question_string.append(tr(
"Transaction fee"));
357 question_string.append(
"</b>");
360 question_string.append(
" (" + QString::number((
double)
m_current_transaction->getTransactionSize() / 1000) +
" kB): ");
363 question_string.append(
"<span style='color:#aa0000; font-weight:bold;'>");
365 question_string.append(
"</span><br />");
368 question_string.append(
"<span style='font-size:10pt; font-weight:normal;'>");
370 question_string.append(tr(
"You can increase the fee later (signals Replace-By-Fee, BIP-125)."));
372 question_string.append(tr(
"Not signalling Replace-By-Fee, BIP-125."));
374 question_string.append(
"</span>");
378 question_string.append(
"<hr />");
380 QStringList alternativeUnits;
385 question_string.append(QString(
"<b>%1</b>: <b>%2</b>").arg(tr(
"Total Amount"))
387 question_string.append(QString(
"<br /><span style='font-size:10pt; font-weight:normal;'>(=%1)</span>")
388 .arg(alternativeUnits.join(
" " + tr(
"or") +
" ")));
390 if (formatted.size() > 1) {
391 question_string = question_string.arg(
"");
392 informative_text = tr(
"To review recipient list click \"Show Details…\"");
393 detailed_text = formatted.join(
"\n\n");
395 question_string = question_string.arg(
"<br /><br />" + formatted.at(0));
408 msgBox.setText(
"Unsigned Transaction");
409 msgBox.setInformativeText(
"The PSBT has been copied to the clipboard. You can also save it.");
410 msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
411 msgBox.setDefaultButton(QMessageBox::Discard);
412 switch (msgBox.exec()) {
413 case QMessageBox::Save: {
414 QString selectedFilter;
415 QString fileNameSuggestion =
"";
419 fileNameSuggestion.append(
" - ");
421 QString labelOrAddress = rcp.label.isEmpty() ? rcp.address : rcp.label;
423 fileNameSuggestion.append(labelOrAddress +
"-" + amount);
426 fileNameSuggestion.append(
".psbt");
428 tr(
"Save Transaction Data"), fileNameSuggestion,
430 tr(
"Partially Signed Transaction (Binary)") + QLatin1String(
" (*.psbt)"), &selectedFilter);
431 if (filename.isEmpty()) {
434 std::ofstream out{filename.toLocal8Bit().data(), std::ofstream::out | std::ofstream::binary};
440 case QMessageBox::Discard:
451 }
catch (
const std::runtime_error& e) {
452 QMessageBox::critical(
nullptr, tr(
"Sign failed"), e.what());
457 QMessageBox::critical(
nullptr, tr(
"External signer not found"),
"External signer not found");
462 QMessageBox::critical(
nullptr, tr(
"External signer failure"),
"External signer failure");
480 QString question_string, informative_text, detailed_text;
481 if (!
PrepareSendText(question_string, informative_text, detailed_text))
return;
484 const QString confirmation = tr(
"Confirm send coins");
488 confirmationDialog->setAttribute(Qt::WA_DeleteOnClose);
490 const auto retval =
static_cast<QMessageBox::StandardButton
>(confirmationDialog->exec());
492 if(retval != QMessageBox::Yes && retval != QMessageBox::Save)
498 bool send_failure =
false;
499 if (retval == QMessageBox::Save) {
503 bool complete =
false;
514 bool broadcast =
true;
518 bool complete =
false;
526 broadcast = complete && !send_failure;
570 ui->
entries->takeAt(0)->widget()->deleteLater();
601 qApp->processEvents();
604 bar->setSliderPosition(bar->maximum());
624 entry->deleteLater();
631 for(
int i = 0; i <
ui->
entries->count(); ++i)
721 QPair<QString, CClientUIInterface::MessageBoxFlags> msgParams;
727 switch(sendCoinsReturn.
status)
730 msgParams.first = tr(
"The recipient address is not valid. Please recheck.");
733 msgParams.first = tr(
"The amount to pay must be larger than 0.");
736 msgParams.first = tr(
"The amount exceeds your balance.");
739 msgParams.first = tr(
"The total exceeds your balance when the %1 transaction fee is included.").arg(msgArg);
742 msgParams.first = tr(
"Duplicate address found: addresses should only be used once each.");
745 msgParams.first = tr(
"Transaction creation failed!");
757 Q_EMIT
message(tr(
"Send Coins"), msgParams.first, msgParams.second);
788 for (
int i = 0; i <
ui->
entries->count(); ++i) {
790 if (e && !e->isHidden() && e != entry) {
865 QColor warning_colour(255 - (lightness / 5), 176 - (lightness / 3), 48 - (lightness / 14));
872 ui->
labelFeeEstimation->setText(tr(
"Estimated to begin confirmation within %n block(s).",
"", returned_target));
926 if (!checked &&
model) {
944 if (state == Qt::Unchecked)
981 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?"),
982 QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
984 if(btnRetVal == QMessageBox::Yes)
999 if (!associatedLabel.isEmpty())
1022 for(
int i = 0; i <
ui->
entries->count(); ++i)
1025 if(entry && !entry->isHidden())
1053 : QMessageBox(parent), secDelay(_secDelay), m_enable_send(enable_send)
1055 setIcon(QMessageBox::Question);
1056 setWindowTitle(title);
1058 setInformativeText(informative_text);
1059 setDetailedText(detailed_text);
1060 setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
1061 if (always_show_unsigned || !enable_send) addButton(QMessageBox::Save);
1062 setDefaultButton(QMessageBox::Cancel);
1076 return QMessageBox::exec();
std::shared_ptr< const CTransaction > CTransactionRef
virtual bool privateKeysDisabled()=0
bool signWithExternalSigner(PartiallySignedTransaction &psbt, CMutableTransaction &mtx, bool &complete)
QLabel * labelCoinControlChange
void removeEntry(SendCoinsEntry *entry)
Predefined combinations for certain default usage cases.
QLabel * labelCoinControlAmount
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
OptionsModel * getOptionsModel() const
interfaces::Wallet & wallet() const
void setValue(const SendCoinsRecipient &value)
Utility functions used by the Bitcoin Qt UI.
QLabel * labelFeeEstimation
SynchronizationState
Current sync state passed to tip changed callbacks.
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const wallet::CCoinControl &coinControl)
void presentPSBT(PartiallySignedTransaction &psbt)
void sendButtonClicked(bool checked)
void updateFeeMinimizedLabel()
QLabel * labelCustomFeeWarning
void on_buttonChooseFee_clicked()
SendCoinsRecipient getValue()
QHBoxLayout * horizontalLayoutSmartFee
QWidget * widgetCoinControl
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text...
UnlockContext requestUnlock()
QPushButton * clearButton
void coinControlClipboardQuantity()
void coinControlClipboardAfterFee()
void setAddress(const QString &address)
QFrame * frameFeeSelection
interfaces::WalletBalances getCachedBalance() const
virtual CAmount getDefaultMaxTxFee()=0
Get max tx fee.
QLabel * labelCoinControlFee
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
QValidatedLineEdit * lineEditCoinControlChange
#define SEND_CONFIRM_DELAY
BitcoinUnit getDisplayUnit() const
std::string EncodeBase64(Span< const unsigned char > input)
void coinControlFeaturesChanged(bool)
QRadioButton * radioCustomFee
QString HtmlEscape(const QString &str, bool fMultiLine)
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
A version of CTransaction with the PSBT format.
Double ended buffer combining vector and stream-like interfaces.
QLabel * labelCoinControlAfterFee
void ShowModalDialogAsynchronously(QDialog *dialog)
Shows a QDialog instance asynchronously, and deletes it on close.
static constexpr std::array confTargets
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized...
virtual bool isSpendable(const CTxDestination &dest)=0
Return whether wallet has private key.
QLabel * labelCoinControlQuantity
A single entry in the dialog for sending bitcoins.
QLabel * labelCoinControlLowOutput
QPushButton * pushButtonCoinControl
QLabel * labelCoinControlAutomaticallySelected
static QString formatWithUnit(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
constexpr auto dialog_flags
void coinControlFeatureChanged(bool)
virtual bool hasExternalSigner()=0
std::unique_ptr< wallet::CCoinControl > m_coin_control
QWidget * setupTabChain(QWidget *prev)
Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://...
std::unique_ptr< WalletModelTransaction > m_current_transaction
int64_t CAmount
Amount in satoshis (Can be negative)
constexpr CAmount DEFAULT_PAY_TX_FEE
-paytxfee default
static QList< CAmount > payAmounts
QWidget * setupTabChain(QWidget *prev)
Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://...
QLabel * labelBalanceName
SendCoinsEntry * addEntry()
bool validate(interfaces::Node &node)
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
CAmount watch_only_balance
void displayUnitChanged(BitcoinUnit unit)
void setBalance(const interfaces::WalletBalances &balances)
void setAddress(const QString &address)
void setEnabled(bool fEnabled)
Enable/Disable.
void coinControlClipboardChange()
Collection of wallet balances.
void useAvailableBalance(SendCoinsEntry *entry)
void setClientModel(ClientModel *clientModel)
void setClipboard(const QString &str)
ClientModel * clientModel
void updateCoinControlState()
static secp256k1_context * ctx
void numBlocksChanged(int count, const QDateTime &blockDate, double nVerificationProgress, SyncType header, SynchronizationState sync_state)
QPushButton * buttonChooseFee
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
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.html#connect-3), that guaranties that all exceptions are handled within the slot.
Dialog for sending bitcoins.
QLabel * labelFeeMinimized
QCheckBox * checkBoxCoinControlChange
void coinControlChangeEdited(const QString &)
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
QString getWalletName() const
void SetMinValue(const CAmount &value)
Set the minimum value in satoshis.
bool getEnablePSBTControls() const
interfaces::Node & node() const
void removeEntry(SendCoinsEntry *entry)
Model for Bitcoin network client.
void setSingleStep(const CAmount &step)
Set single step in satoshis.
void coinControlUpdateLabels()
bool isMultiwallet() const
void setModel(WalletModel *model)
int getConfTargetForIndex(int index)
SendCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent=nullptr)
bool getCoinControlFeatures() const
void setupUi(QDialog *SendCoinsDialog)
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)
static CTransactionRef MakeTransactionRef(Tx &&txIn)
QRadioButton * radioSmartFee
void checkSubtractFeeFromAmount()
bool isClear()
Return whether the entry is still empty and unedited.
void minimizeFeeSection(bool fMinimize)
void coinControlClipboardLowOutput()
QLabel * labelCoinControlChangeLabel
void updateFeeSectionControls()
QWidget * scrollAreaWidgetContents
void subtractFeeFromAmountChanged()
static bool fSubtractFeeFromAmount
void updateSmartFeeLabel()
bool PrepareSendText(QString &question_string, QString &informative_text, QString &detailed_text)
static void updateLabels(wallet::CCoinControl &m_coin_control, WalletModel *, QDialog *)
QString confirmButtonText
int getIndexForConfTarget(int target)
void updateTabsAndLabels()
const CChainParams & Params()
Return the currently selected parameters.
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 ...
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
QLabel * labelCoinControlBytes
void setAmount(const CAmount &amount)
void setModel(WalletModel *model)
void processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg=QString())
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
QComboBox * confTargetSelector
void setEnabled(bool enabled)
void coinControlClipboardBytes()
void useAvailableBalance(SendCoinsEntry *entry)
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.
virtual unsigned int getConfirmTarget()=0
Get tx confirm target.
AddressTableModel * getAddressTableModel() const
CAmount getAvailableBalance(const wallet::CCoinControl *control)
static QString formatHtmlWithUnit(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as HTML string (with unit)
bool fSubtractFeeFromAmount
QFrame * frameCoinControl
const PlatformStyle * platformStyle
QString formatNiceTimeOffset(qint64 secs)
void coinControlClipboardAmount()
void sendCoins(WalletModelTransaction &transaction)
void on_buttonMinimizeFee_clicked()
QLabel * fallbackFeeWarningLabel
QString m_psbt_button_text
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
void pasteEntry(const SendCoinsRecipient &rv)
void setDisplayUnit(BitcoinUnit new_unit)
Change unit used to display amount.
QAbstractButton * yesButton
BitcoinAmountField * customFee
virtual CAmount getRequiredFee(unsigned int tx_bytes)=0
Get required fee.
void message(const QString &title, const QString &message, unsigned int style)
void coinsSent(const uint256 &txid)
QLabel * labelCustomPerKilobyte
QAbstractButton * m_psbt_button
bool fNewRecipientAllowed
virtual CAmount getMinimumFee(unsigned int tx_bytes, const wallet::CCoinControl &coin_control, int *returned_target, FeeReason *reason)=0
Get minimum fee.
QPushButton * buttonMinimizeFee
void setValue(const CAmount &value)
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
void setText(const QString &)
void balanceChanged(const interfaces::WalletBalances &balances)
void coinControlButtonClicked()
void coinControlClipboardFee()
QLabel * labelCoinControlInsuffFunds
void SetAllowEmpty(bool allow)
If allow empty is set to false the field will be set to the minimum allowed value if left empty...
void updateNumberOfBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, SyncType synctype, SynchronizationState sync_state)
void coinControlChangeChecked(int)