5#if defined(HAVE_CONFIG_H)
43 m_client_model(&client_model),
45 optionsModel(client_model.getOptionsModel()),
46 addressTableModel(nullptr),
47 transactionTableModel(nullptr),
48 recentRequestsTableModel(nullptr),
49 cachedEncryptionStatus(Unencrypted),
50 timer(new QTimer(this))
102 if (!
m_wallet->tryGetBalances(new_balances, block_hash)) {
133 bool isMine,
const QString &purpose,
int status)
153 bool fSubtractFeeFromAmount =
false;
154 QList<SendCoinsRecipient> recipients = transaction.
getRecipients();
155 std::vector<CRecipient> vecSend;
157 if(recipients.empty())
162 QSet<QString> setAddress;
168 if (rcp.fSubtractFeeFromAmount)
169 fSubtractFeeFromAmount =
true;
179 setAddress.insert(rcp.address);
183 CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount};
189 if(setAddress.size() != nAddresses)
203 int nChangePosRet = -1;
206 auto& newTx = transaction.
getWtx();
207 newTx =
m_wallet->createTransaction(vecSend, coinControl, !
wallet().privateKeysDisabled() , nChangePosRet, nFeeRequired,
error);
209 if (fSubtractFeeFromAmount && newTx)
214 if(!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance)
218 Q_EMIT
message(tr(
"Send Coins"), QString::fromStdString(
error.translated),
226 if (nFeeRequired >
m_wallet->getDefaultMaxTxFee()) {
236 QByteArray transaction_array;
239 std::vector<std::pair<std::string, std::string>> vOrderForm;
242 if (!rcp.message.isEmpty())
243 vOrderForm.emplace_back(
"Message", rcp.message.toStdString());
246 auto& newTx = transaction.
getWtx();
251 transaction_array.append((
const char*)ssTx.
data(), ssTx.
size());
259 std::string strAddress = rcp.address.toStdString();
261 std::string strLabel = rcp.label.toStdString();
266 dest, &
name,
nullptr,
nullptr))
268 m_wallet->setAddressBook(dest, strLabel,
"send");
270 else if (
name != strLabel)
272 m_wallet->setAddressBook(dest, strLabel,
"");
276 Q_EMIT
coinsSent(
this, rcp, transaction_array);
322 return m_wallet->encryptWallet(passphrase);
335 return m_wallet->unlock(passPhrase);
342 return m_wallet->changeWalletPassphrase(oldPass, newPass);
348 qDebug() <<
"NotifyUnload";
349 bool invoked = QMetaObject::invokeMethod(walletModel,
"unload");
355 qDebug() <<
"NotifyKeyStoreStatusChanged";
356 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateStatus", Qt::QueuedConnection);
361 const CTxDestination &address,
const std::string &label,
bool isMine,
362 const std::string &purpose,
ChangeType status)
365 QString strLabel = QString::fromStdString(label);
366 QString strPurpose = QString::fromStdString(purpose);
368 qDebug() <<
"NotifyAddressBookChanged: " + strAddress +
" " + strLabel +
" isMine=" + QString::number(isMine) +
" purpose=" + strPurpose +
" status=" + QString::number(status);
369 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateAddressBook", Qt::QueuedConnection,
370 Q_ARG(QString, strAddress),
371 Q_ARG(QString, strLabel),
373 Q_ARG(QString, strPurpose),
382 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateTransaction", Qt::QueuedConnection);
389 bool invoked = QMetaObject::invokeMethod(walletmodel,
"showProgress", Qt::QueuedConnection,
390 Q_ARG(QString, QString::fromStdString(title)),
391 Q_ARG(
int, nProgress));
397 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateWatchOnlyFlag", Qt::QueuedConnection,
398 Q_ARG(
bool, fHaveWatchonly));
404 bool invoked = QMetaObject::invokeMethod(walletmodel,
"canGetAddressesChanged");
458 wallet->setWalletLocked(
true);
473 std::vector<bilingual_str> errors;
477 if (!
m_wallet->createBumpTransaction(hash, coin_control, errors, old_fee, new_fee, mtx)) {
478 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Increasing transaction fee failed") +
"<br />(" +
479 (errors.size() ? QString::fromStdString(errors[0].translated) :
"") +
")");
483 const bool create_psbt =
m_wallet->privateKeysDisabled();
486 QString questionString = create_psbt ? tr(
"Do you want to draft a transaction with fee increase?") : tr(
"Do you want to increase the fee?");
487 questionString.append(
"<br />");
488 questionString.append(
"<table style=\"text-align: left;\">");
489 questionString.append(
"<tr><td>");
490 questionString.append(tr(
"Current fee:"));
491 questionString.append(
"</td><td>");
493 questionString.append(
"</td></tr><tr><td>");
494 questionString.append(tr(
"Increase:"));
495 questionString.append(
"</td><td>");
497 questionString.append(
"</td></tr><tr><td>");
498 questionString.append(tr(
"New fee:"));
499 questionString.append(
"</td><td>");
501 questionString.append(
"</td></tr></table>");
505 questionString.append(
"<br><br>");
506 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."));
510 confirmationDialog->setAttribute(Qt::WA_DeleteOnClose);
512 const auto retval =
static_cast<QMessageBox::StandardButton
>(confirmationDialog->exec());
515 if (retval != QMessageBox::Yes) {
528 bool complete =
false;
531 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Can't draft transaction."));
543 if (!
m_wallet->signBumpTransaction(mtx)) {
544 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Can't sign transaction."));
548 if(!
m_wallet->commitBumpTransaction(hash, std::move(mtx), errors, new_hash)) {
549 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Could not commit transaction") +
"<br />(" +
550 QString::fromStdString(errors[0].translated)+
")");
561 res =
m_wallet->displayAddress(dest);
562 }
catch (
const std::runtime_error& e) {
563 QMessageBox::critical(
nullptr, tr(
"Can't display address"), e.what());
575 return QString::fromStdString(
m_wallet->getWalletName());
581 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(int 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.
std::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
Double ended buffer combining vector and stream-like interfaces.
Serialized script, used inside transaction inputs and outputs.
Model for Bitcoin network client.
uint256 getBestBlockHash()
Interface from Qt to configuration data structure for Bitcoin client.
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)
void CopyFrom(UnlockContext &&rhs)
Interface to Bitcoin wallet from Qt view code.
OptionsModel * optionsModel
bool validateAddress(const QString &address)
AddressTableModel * addressTableModel
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()
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
RecentRequestsTableModel * recentRequestsTableModel
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 displayAddress(std::string sAddress)
void setClientModel(ClientModel *client_model)
AddressTableModel * getAddressTableModel()
OptionsModel * getOptionsModel()
std::unique_ptr< interfaces::Handler > m_handler_can_get_addrs_changed
std::unique_ptr< interfaces::Handler > m_handler_unload
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl &coinControl)
EncryptionStatus getEncryptionStatus() const
interfaces::Wallet & wallet() const
RecentRequestsTableModel * getRecentRequestsTableModel()
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
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()
QString getWalletName() const
std::unique_ptr< interfaces::Handler > m_handler_show_progress
@ AmountWithFeeExceedsBalance
@ TransactionCreationFailed
void subscribeToCoreSignals()
TransactionTableModel * getTransactionTableModel()
Data model for a walletmodel transaction.
void setTransactionFee(const CAmount &newFee)
void reassignAmounts(int nChangePosRet)
QList< SendCoinsRecipient > getRecipients() const
CTransactionRef & getWtx()
virtual WalletClient & walletClient()=0
Get wallet client.
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).
virtual TransactionError fillPSBT(int sighash_type, bool sign, bool bip32derivs, size_t *n_signed, PartiallySignedTransaction &psbtx, bool &complete)=0
Fill PSBT.
virtual void commitTransaction(CTransactionRef tx, WalletValueMap value_map, WalletOrderForm order_form)=0
Commit transaction.
void push_back(const T &value)
static const int MODEL_UPDATE_DELAY
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
std::string EncodeDestination(const CTxDestination &dest)
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg)
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)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
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.
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.
bool balanceChanged(const WalletBalances &prev) const
bool error(const char *fmt, const Args &... args)
static secp256k1_context * ctx
ChangeType
General change type (added, updated, removed).
static const int PROTOCOL_VERSION
network protocol versioning
std::shared_ptr< CWallet > m_wallet
static const bool DEFAULT_DISABLE_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)