5 #if defined(HAVE_CONFIG_H)
31 #include <validation.h>
33 #include <QFontMetrics>
36 #include <QTextDocument>
38 static const std::array<int, 9>
confTargets = { {2, 4, 6, 12, 24, 48, 144, 504, 1008} };
40 if (index+1 >
static_cast<int>(
confTargets.size())) {
49 for (
unsigned int i = 0; i <
confTargets.size(); i++) {
63 fNewRecipientAllowed(true),
65 platformStyle(_platformStyle)
92 QAction *clipboardQuantityAction =
new QAction(tr(
"Copy quantity"),
this);
93 QAction *clipboardAmountAction =
new QAction(tr(
"Copy amount"),
this);
94 QAction *clipboardFeeAction =
new QAction(tr(
"Copy fee"),
this);
95 QAction *clipboardAfterFeeAction =
new QAction(tr(
"Copy after fee"),
this);
96 QAction *clipboardBytesAction =
new QAction(tr(
"Copy bytes"),
this);
97 QAction *clipboardLowOutputAction =
new QAction(tr(
"Copy dust"),
this);
98 QAction *clipboardChangeAction =
new QAction(tr(
"Copy change"),
this);
116 if (!settings.contains(
"fFeeSectionMinimized"))
117 settings.setValue(
"fFeeSectionMinimized",
true);
118 if (!settings.contains(
"nFeeRadio") && settings.contains(
"nTransactionFee") && settings.value(
"nTransactionFee").toLongLong() > 0)
119 settings.setValue(
"nFeeRadio", 1);
120 if (!settings.contains(
"nFeeRadio"))
121 settings.setValue(
"nFeeRadio", 0);
122 if (!settings.contains(
"nSmartFeeSliderPosition"))
123 settings.setValue(
"nSmartFeeSliderPosition", 0);
124 if (!settings.contains(
"nTransactionFee"))
128 ui->
groupFee->button((
int)std::max(0, std::min(1, settings.value(
"nFeeRadio").toInt())))->setChecked(
true);
145 this->
model = _model;
149 for(
int i = 0; i <
ui->
entries->count(); ++i)
195 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));
200 if (settings.value(
"nSmartFeeSliderPosition").toInt() != 0) {
203 int nConfirmTarget = 25 - settings.value(
"nSmartFeeSliderPosition").toInt();
204 settings.setValue(
"nConfTarget", nConfirmTarget);
205 settings.remove(
"nSmartFeeSliderPosition");
207 if (settings.value(
"nConfTarget").toInt() == 0)
218 settings.setValue(
"nFeeRadio",
ui->
groupFee->checkedId());
227 QList<SendCoinsRecipient> recipients;
230 for(
int i = 0; i <
ui->
entries->count(); ++i)
237 recipients.append(entry->
getValue());
247 if(!valid || recipients.isEmpty())
279 QStringList formatted;
289 QString address = rcp.address;
291 QString recipientElement;
294 if(rcp.label.length() > 0)
297 recipientElement.append(QString(
" (%1)").arg(address));
301 recipientElement.append(tr(
"%1 to %2").arg(amount, address));
304 formatted.append(recipientElement);
308 question_string.append(tr(
"Do you want to draft this transaction?"));
310 question_string.append(tr(
"Are you sure you want to send?"));
313 question_string.append(
"<br /><span style='font-size:10pt;'>");
315 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));
317 question_string.append(tr(
"Please, review your transaction."));
319 question_string.append(
"</span>%1");
324 question_string.append(
"<hr /><b>");
325 question_string.append(tr(
"Transaction fee"));
326 question_string.append(
"</b>");
329 question_string.append(
" (" + QString::number((
double)
m_current_transaction->getTransactionSize() / 1000) +
" kB): ");
332 question_string.append(
"<span style='color:#aa0000; font-weight:bold;'>");
334 question_string.append(
"</span><br />");
337 question_string.append(
"<span style='font-size:10pt; font-weight:normal;'>");
339 question_string.append(tr(
"You can increase the fee later (signals Replace-By-Fee, BIP-125)."));
341 question_string.append(tr(
"Not signalling Replace-By-Fee, BIP-125."));
343 question_string.append(
"</span>");
347 question_string.append(
"<hr />");
349 QStringList alternativeUnits;
355 question_string.append(QString(
"<b>%1</b>: <b>%2</b>").arg(tr(
"Total Amount"))
357 question_string.append(QString(
"<br /><span style='font-size:10pt; font-weight:normal;'>(=%1)</span>")
358 .arg(alternativeUnits.join(
" " + tr(
"or") +
" ")));
360 if (formatted.size() > 1) {
361 question_string = question_string.arg(
"");
362 informative_text = tr(
"To review recipient list click \"Show Details...\"");
363 detailed_text = formatted.join(
"\n\n");
365 question_string = question_string.arg(
"<br /><br />" + formatted.at(0));
376 QString question_string, informative_text, detailed_text;
377 if (!
PrepareSendText(question_string, informative_text, detailed_text))
return;
383 confirmationDialog.
exec();
384 QMessageBox::StandardButton retval =
static_cast<QMessageBox::StandardButton
>(confirmationDialog.result());
386 if(retval != QMessageBox::Yes)
392 bool send_failure =
false;
396 bool complete =
false;
405 msgBox.setText(
"Unsigned Transaction");
406 msgBox.setInformativeText(
"The PSBT has been copied to the clipboard. You can also save it.");
407 msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
408 msgBox.setDefaultButton(QMessageBox::Discard);
409 switch (msgBox.exec()) {
410 case QMessageBox::Save: {
411 QString selectedFilter;
412 QString fileNameSuggestion =
"";
416 fileNameSuggestion.append(
" - ");
418 QString labelOrAddress = rcp.label.isEmpty() ? rcp.address : rcp.label;
420 fileNameSuggestion.append(labelOrAddress +
"-" + amount);
423 fileNameSuggestion.append(
".psbt");
425 tr(
"Save Transaction Data"), fileNameSuggestion,
426 tr(
"Partially Signed Transaction (Binary) (*.psbt)"), &selectedFilter);
427 if (filename.isEmpty()) {
436 case QMessageBox::Discard:
475 ui->
entries->takeAt(0)->widget()->deleteLater();
506 qApp->processEvents();
509 bar->setSliderPosition(bar->maximum());
529 entry->deleteLater();
536 for(
int i = 0; i <
ui->
entries->count(); ++i)
624 QPair<QString, CClientUIInterface::MessageBoxFlags> msgParams;
630 switch(sendCoinsReturn.
status)
633 msgParams.first = tr(
"The recipient address is not valid. Please recheck.");
636 msgParams.first = tr(
"The amount to pay must be larger than 0.");
639 msgParams.first = tr(
"The amount exceeds your balance.");
642 msgParams.first = tr(
"The total exceeds your balance when the %1 transaction fee is included.").arg(msgArg);
645 msgParams.first = tr(
"Duplicate address found: addresses should only be used once each.");
648 msgParams.first = tr(
"Transaction creation failed!");
655 msgParams.first = tr(
"Payment request expired.");
664 Q_EMIT
message(tr(
"Send Coins"), msgParams.first, msgParams.second);
695 for (
int i = 0; i <
ui->
entries->count(); ++i) {
697 if (e && !e->isHidden() && e != entry) {
772 QColor warning_colour(255 - (lightness / 5), 176 - (lightness / 3), 48 - (lightness / 14));
779 ui->
labelFeeEstimation->setText(tr(
"Estimated to begin confirmation within %n block(s).",
"", returned_target));
833 if (!checked &&
model)
850 if (state == Qt::Unchecked)
887 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?"),
888 QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
890 if(btnRetVal == QMessageBox::Yes)
905 if (!associatedLabel.isEmpty())
928 for(
int i = 0; i <
ui->
entries->count(); ++i)
931 if(entry && !entry->isHidden())
959 : QMessageBox(parent), secDelay(_secDelay), confirmButtonText(_confirmButtonText)
961 setIcon(QMessageBox::Question);
962 setWindowTitle(title);
964 setInformativeText(informative_text);
965 setDetailedText(detailed_text);
966 setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
967 setDefaultButton(QMessageBox::Cancel);
977 return QMessageBox::exec();
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.
void setEnabled(bool fEnabled)
Enable/Disable.
void setSingleStep(const CAmount &step)
Set single step in satoshis.
void SetMinValue(const CAmount &value)
Set the minimum value in satoshis.
void setDisplayUnit(int unit)
Change unit used to display amount.
void setValue(const CAmount &value)
void SetAllowEmpty(bool allow)
If allow empty is set to false the field will be set to the minimum allowed value if left empty.
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as HTML string (with unit)
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
static QList< Unit > availableUnits()
Get list of units, for drop-down box.
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
Optional< unsigned int > m_confirm_target
Override the default confirmation target if set.
Optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
bool fAllowWatchOnly
Includes watch only addresses which are solvable.
Optional< CFeeRate > m_feerate
Override the wallet's m_pay_tx_fee if set.
Double ended buffer combining vector and stream-like interfaces.
Fee rate in satoshis per kilobyte: CAmount / kB.
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Model for Bitcoin network client.
void numBlocksChanged(int count, const QDateTime &blockDate, double nVerificationProgress, bool header, SynchronizationState sync_state)
static void updateLabels(CCoinControl &m_coin_control, WalletModel *, QDialog *)
static QList< CAmount > payAmounts
static bool fSubtractFeeFromAmount
int getDisplayUnit() const
bool getCoinControlFeatures() const
void coinControlFeaturesChanged(bool)
void displayUnitChanged(int unit)
void setEnabled(bool enabled)
Dialog for sending bitcoins.
void useAvailableBalance(SendCoinsEntry *entry)
ClientModel * clientModel
void coinControlChangeEdited(const QString &)
void coinControlChangeChecked(int)
void coinControlClipboardFee()
void updateNumberOfBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, bool headers, SynchronizationState sync_state)
void on_sendButton_clicked()
void on_buttonChooseFee_clicked()
void processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg=QString())
void setClientModel(ClientModel *clientModel)
void updateTabsAndLabels()
void updateFeeSectionControls()
std::unique_ptr< CCoinControl > m_coin_control
SendCoinsEntry * addEntry()
void pasteEntry(const SendCoinsRecipient &rv)
void updateFeeMinimizedLabel()
const PlatformStyle * platformStyle
void coinControlClipboardQuantity()
void coinControlButtonClicked()
void coinControlClipboardAfterFee()
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 setModel(WalletModel *model)
void coinControlClipboardLowOutput()
bool handlePaymentRequest(const SendCoinsRecipient &recipient)
void setBalance(const interfaces::WalletBalances &balances)
void coinControlClipboardAmount()
void updateCoinControlState(CCoinControl &ctrl)
void setAddress(const QString &address)
void coinControlClipboardChange()
std::unique_ptr< WalletModelTransaction > m_current_transaction
bool fNewRecipientAllowed
void removeEntry(SendCoinsEntry *entry)
void updateSmartFeeLabel()
void coinControlClipboardBytes()
void message(const QString &title, const QString &message, unsigned int style)
SendCoinsDialog(const PlatformStyle *platformStyle, QWidget *parent=nullptr)
void coinsSent(const uint256 &txid)
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)
bool isClear()
Return whether the entry is still empty and unedited.
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()
bool fSubtractFeeFromAmount
SendConfirmationDialog(const QString &title, const QString &text, const QString &informative_text="", const QString &detailed_text="", int secDelay=SEND_CONFIRM_DELAY, const QString &confirmText="Send", QWidget *parent=nullptr)
QAbstractButton * yesButton
QString confirmButtonText
QWidget * scrollAreaWidgetContents
QLabel * labelCoinControlQuantity
QHBoxLayout * horizontalLayoutSmartFee
QLabel * fallbackFeeWarningLabel
QLabel * labelCoinControlAutomaticallySelected
QLabel * labelCoinControlBytes
QValidatedLineEdit * lineEditCoinControlChange
QLabel * labelCoinControlChange
QRadioButton * radioSmartFee
QLabel * labelCoinControlChangeLabel
QLabel * labelFeeMinimized
QPushButton * buttonMinimizeFee
QLabel * labelCustomFeeWarning
QLabel * labelCoinControlInsuffFunds
QCheckBox * checkBoxCoinControlChange
QLabel * labelBalanceName
QRadioButton * radioCustomFee
QPushButton * pushButtonCoinControl
void setupUi(QDialog *SendCoinsDialog)
QLabel * labelCustomPerKilobyte
QFrame * frameCoinControl
QComboBox * confTargetSelector
QFrame * frameFeeSelection
QPushButton * clearButton
QLabel * labelCoinControlLowOutput
QWidget * widgetCoinControl
BitcoinAmountField * customFee
QLabel * labelFeeEstimation
QLabel * labelCoinControlAfterFee
QLabel * labelCoinControlFee
QPushButton * buttonChooseFee
QLabel * labelCoinControlAmount
Interface to Bitcoin wallet from Qt view code.
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
AddressTableModel * getAddressTableModel()
OptionsModel * getOptionsModel()
interfaces::Wallet & wallet() const
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl &coinControl)
interfaces::Node & node() const
UnlockContext requestUnlock()
void balanceChanged(const interfaces::WalletBalances &balances)
QString getWalletName() const
@ AmountWithFeeExceedsBalance
@ TransactionCreationFailed
virtual CAmount getAvailableBalance(const CCoinControl &coin_control)=0
Get available balance.
virtual CAmount getRequiredFee(unsigned int tx_bytes)=0
Get required fee.
virtual TransactionError fillPSBT(int sighash_type, bool sign, bool bip32derivs, PartiallySignedTransaction &psbtx, bool &complete, size_t *n_signed)=0
Fill PSBT.
virtual unsigned int getConfirmTarget()=0
Get tx confirm target.
virtual CAmount getDefaultMaxTxFee()=0
Get max tx fee.
virtual bool isSpendable(const CTxDestination &dest)=0
Return whether wallet has private key.
virtual WalletBalances getBalances()=0
Get balances.
virtual CAmount getMinimumFee(unsigned int tx_bytes, const CCoinControl &coin_control, int *returned_target, FeeReason *reason)=0
Get minimum fee.
virtual bool privateKeysDisabled()=0
CTxDestination DecodeDestination(const std::string &str)
QString HtmlEscape(const QString &str, bool fMultiLine)
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)
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)
static const std::array< int, 9 > confTargets
int getConfTargetForIndex(int index)
int getIndexForConfTarget(int target)
#define SEND_CONFIRM_DELAY
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
std::string EncodeBase64(Span< const unsigned char > input)
A mutable version of CTransaction.
A version of CTransaction with the PSBT format.
Collection of wallet balances.
CAmount watch_only_balance
static secp256k1_context * ctx
SynchronizationState
Current sync state passed to tip changed callbacks.
static const int PROTOCOL_VERSION
network protocol versioning
constexpr CAmount DEFAULT_PAY_TX_FEE
-paytxfee default