5 #if defined(HAVE_CONFIG_H)
35 #include <QMessageBox>
46 m_client_model(&client_model),
48 optionsModel(client_model.getOptionsModel()),
49 timer(new QTimer(this))
105 if (!
m_wallet->tryGetBalances(new_balances, block_hash)) {
141 bool isMine,
const QString &purpose,
int status)
161 bool fSubtractFeeFromAmount =
false;
162 QList<SendCoinsRecipient> recipients = transaction.
getRecipients();
163 std::vector<CRecipient> vecSend;
165 if(recipients.empty())
170 QSet<QString> setAddress;
176 if (rcp.fSubtractFeeFromAmount)
177 fSubtractFeeFromAmount =
true;
187 setAddress.insert(rcp.address);
191 CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount};
197 if(setAddress.size() != nAddresses)
213 int nChangePosRet = -1;
215 auto& newTx = transaction.
getWtx();
216 const auto& res =
m_wallet->createTransaction(vecSend, coinControl, !
wallet().privateKeysDisabled(), nChangePosRet, nFeeRequired);
217 newTx = res ? *res :
nullptr;
219 if (fSubtractFeeFromAmount && newTx)
224 if(!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance)
236 if (nFeeRequired >
m_wallet->getDefaultMaxTxFee()) {
239 }
catch (
const std::runtime_error& err) {
241 Q_EMIT
message(tr(
"Send Coins"), QString::fromStdString(err.what()),
251 QByteArray transaction_array;
254 std::vector<std::pair<std::string, std::string>> vOrderForm;
257 if (!rcp.message.isEmpty())
258 vOrderForm.emplace_back(
"Message", rcp.message.toStdString());
261 auto& newTx = transaction.
getWtx();
266 transaction_array.append((
const char*)ssTx.
data(), ssTx.
size());
274 std::string strAddress = rcp.address.toStdString();
276 std::string strLabel = rcp.label.toStdString();
281 dest, &
name,
nullptr,
nullptr))
283 m_wallet->setAddressBook(dest, strLabel,
"send");
285 else if (
name != strLabel)
287 m_wallet->setAddressBook(dest, strLabel,
"");
291 Q_EMIT
coinsSent(
this, rcp, transaction_array);
323 if (
m_wallet->privateKeysDisabled()) {
340 return m_wallet->encryptWallet(passphrase);
353 return m_wallet->unlock(passPhrase);
360 return m_wallet->changeWalletPassphrase(oldPass, newPass);
366 qDebug() <<
"NotifyUnload";
367 bool invoked = QMetaObject::invokeMethod(walletModel,
"unload");
373 qDebug() <<
"NotifyKeyStoreStatusChanged";
374 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateStatus", Qt::QueuedConnection);
379 const CTxDestination &address,
const std::string &label,
bool isMine,
380 const std::string &purpose,
ChangeType status)
383 QString strLabel = QString::fromStdString(label);
384 QString strPurpose = QString::fromStdString(purpose);
386 qDebug() <<
"NotifyAddressBookChanged: " + strAddress +
" " + strLabel +
" isMine=" + QString::number(isMine) +
" purpose=" + strPurpose +
" status=" + QString::number(status);
387 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateAddressBook",
388 Q_ARG(QString, strAddress),
389 Q_ARG(QString, strLabel),
391 Q_ARG(QString, strPurpose),
400 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateTransaction", Qt::QueuedConnection);
407 bool invoked = QMetaObject::invokeMethod(walletmodel,
"showProgress", Qt::QueuedConnection,
408 Q_ARG(QString, QString::fromStdString(title)),
409 Q_ARG(
int, nProgress));
415 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateWatchOnlyFlag", Qt::QueuedConnection,
416 Q_ARG(
bool, fHaveWatchonly));
422 bool invoked = QMetaObject::invokeMethod(walletmodel,
"canGetAddressesChanged");
476 wallet->setWalletLocked(
true);
484 std::vector<bilingual_str> errors;
488 if (!
m_wallet->createBumpTransaction(hash, coin_control, errors, old_fee, new_fee, mtx)) {
489 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Increasing transaction fee failed") +
"<br />(" +
490 (errors.size() ? QString::fromStdString(errors[0].translated) :
"") +
")");
496 QString questionString = tr(
"Do you want to increase the fee?");
497 questionString.append(
"<br />");
498 questionString.append(
"<table style=\"text-align: left;\">");
499 questionString.append(
"<tr><td>");
500 questionString.append(tr(
"Current fee:"));
501 questionString.append(
"</td><td>");
503 questionString.append(
"</td></tr><tr><td>");
504 questionString.append(tr(
"Increase:"));
505 questionString.append(
"</td><td>");
507 questionString.append(
"</td></tr><tr><td>");
508 questionString.append(tr(
"New fee:"));
509 questionString.append(
"</td><td>");
511 questionString.append(
"</td></tr></table>");
515 questionString.append(
"<br><br>");
516 questionString.append(tr(
"Warning: This may pay the additional fee by reducing change outputs or adding inputs, when necessary. It may add a new change output if one does not already exist. These changes may potentially leak privacy."));
522 confirmationDialog->setAttribute(Qt::WA_DeleteOnClose);
524 const auto retval =
static_cast<QMessageBox::StandardButton
>(confirmationDialog->exec());
527 if (retval != QMessageBox::Yes && retval != QMessageBox::Save) {
538 if (retval == QMessageBox::Save) {
541 bool complete =
false;
544 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Can't draft transaction."));
558 if (!
m_wallet->signBumpTransaction(mtx)) {
559 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Can't sign transaction."));
563 if(!
m_wallet->commitBumpTransaction(hash, std::move(mtx), errors, new_hash)) {
564 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Could not commit transaction") +
"<br />(" +
565 QString::fromStdString(errors[0].translated)+
")");
576 res =
m_wallet->displayAddress(dest);
577 }
catch (
const std::runtime_error& e) {
578 QMessageBox::critical(
nullptr, tr(
"Can't display address"), e.what());
590 return QString::fromStdString(
m_wallet->getWalletName());
596 return name.isEmpty() ?
"["+tr(
"default wallet")+
"]" :
name;
int64_t CAmount
Amount in satoshis (Can be negative)
Qt model of the address book in the core.
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
static QString formatHtmlWithUnit(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as HTML string (with unit)
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
Serialized script, used inside transaction inputs and outputs.
Model for Bitcoin network client.
uint256 getBestBlockHash() EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex)
Interface from Qt to configuration data structure for Bitcoin client.
bool getEnablePSBTControls() const
Model for list of recently generated payment requests / bitcoin: URIs.
UI model for the transaction table of a wallet.
void updateConfirmations()
UnlockContext(WalletModel *wallet, bool valid, bool relock)
Interface to Bitcoin wallet from Qt view code.
OptionsModel * optionsModel
AddressTableModel * addressTableModel
RecentRequestsTableModel * getRecentRequestsTableModel() const
EncryptionStatus cachedEncryptionStatus
void refresh(bool pk_hash_only=false)
uint256 m_cached_last_update_tip
ClientModel * m_client_model
std::unique_ptr< interfaces::Handler > m_handler_watch_only_changed
interfaces::Node & m_node
std::unique_ptr< interfaces::Handler > m_handler_transaction_changed
void pollBalanceChanged()
AddressTableModel * getAddressTableModel() const
RecentRequestsTableModel * recentRequestsTableModel
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const wallet::CCoinControl &coinControl)
bool displayAddress(std::string sAddress) const
TransactionTableModel * transactionTableModel
bool setWalletEncrypted(const SecureString &passphrase)
void notifyWatchonlyChanged(bool fHaveWatchonly)
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
void message(const QString &title, const QString &message, unsigned int style)
bool validateAddress(const QString &address) const
void sendCoins(WalletModelTransaction &transaction)
void setClientModel(ClientModel *client_model)
CAmount getAvailableBalance(const wallet::CCoinControl *control)
bool isMultiwallet() const
std::unique_ptr< interfaces::Handler > m_handler_can_get_addrs_changed
std::unique_ptr< interfaces::Handler > m_handler_unload
interfaces::Wallet & wallet() const
EncryptionStatus getEncryptionStatus() const
TransactionTableModel * getTransactionTableModel() const
std::unique_ptr< interfaces::Handler > m_handler_status_changed
interfaces::WalletBalances m_cached_balances
bool fForceCheckBalanceChanged
void coinsSent(WalletModel *wallet, SendCoinsRecipient recipient, QByteArray transaction)
QString getDisplayName() const
OptionsModel * getOptionsModel() const
bool bumpFee(uint256 hash, uint256 &new_hash)
void checkBalanceChanged(const interfaces::WalletBalances &new_balances)
void unsubscribeFromCoreSignals()
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
uint256 getLastBlockProcessed() const
WalletModel(std::unique_ptr< interfaces::Wallet > wallet, ClientModel &client_model, const PlatformStyle *platformStyle, QObject *parent=nullptr)
void updateWatchOnlyFlag(bool fHaveWatchonly)
std::unique_ptr< interfaces::Handler > m_handler_address_book_changed
void encryptionStatusChanged()
std::unique_ptr< interfaces::Wallet > m_wallet
UnlockContext requestUnlock()
void balanceChanged(const interfaces::WalletBalances &balances)
static bool isWalletEnabled()
interfaces::WalletBalances getCachedBalance() const
QString getWalletName() const
std::unique_ptr< interfaces::Handler > m_handler_show_progress
@ AmountWithFeeExceedsBalance
@ TransactionCreationFailed
void subscribeToCoreSignals()
Data model for a walletmodel transaction.
void setTransactionFee(const CAmount &newFee)
void reassignAmounts(int nChangePosRet)
QList< SendCoinsRecipient > getRecipients() const
CTransactionRef & getWtx()
virtual WalletLoader & walletLoader()=0
Get wallet loader.
virtual TransactionError fillPSBT(int sighash_type, bool sign, bool bip32derivs, size_t *n_signed, PartiallySignedTransaction &psbtx, bool &complete)=0
Fill PSBT.
virtual CAmount getAvailableBalance(const wallet::CCoinControl &coin_control)=0
Get available balance.
virtual bool hasExternalSigner()=0
virtual void commitTransaction(CTransactionRef tx, WalletValueMap value_map, WalletOrderForm order_form)=0
Commit transaction.
virtual bool privateKeysDisabled()=0
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).
void push_back(const T &value)
std::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
static constexpr auto MODEL_UPDATE_DELAY
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
std::string EncodeDestination(const CTxDestination &dest)
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....
void setClipboard(const QString &str)
bilingual_str ErrorString(const Result< T > &result)
static const bool DEFAULT_DISABLE_WALLET
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
#define SEND_CONFIRM_DELAY
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
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.
Collection of wallet balances.
bool balanceChanged(const WalletBalances &prev) const
ChangeType
General change type (added, updated, removed).
std::string EncodeBase64(Span< const unsigned char > input)
static const int PROTOCOL_VERSION
network protocol versioning
std::shared_ptr< CWallet > m_wallet
static void NotifyUnload(WalletModel *walletModel)
static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
static void NotifyCanGetAddressesChanged(WalletModel *walletmodel)
static void NotifyAddressBookChanged(WalletModel *walletmodel, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)
static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel)
static void NotifyTransactionChanged(WalletModel *walletmodel, const uint256 &hash, ChangeType status)