5 #if defined(HAVE_CONFIG_H) 35 #include <QMessageBox> 46 m_client_model(&client_model),
48 optionsModel(client_model.getOptionsModel()),
49 addressTableModel(nullptr),
50 transactionTableModel(nullptr),
51 recentRequestsTableModel(nullptr),
52 cachedEncryptionStatus(Unencrypted),
53 timer(new QTimer(this))
109 if (!
m_wallet->tryGetBalances(new_balances, block_hash)) {
145 bool isMine,
const QString &purpose,
int status)
165 bool fSubtractFeeFromAmount =
false;
166 QList<SendCoinsRecipient> recipients = transaction.
getRecipients();
167 std::vector<CRecipient> vecSend;
169 if(recipients.empty())
174 QSet<QString> setAddress;
180 if (rcp.fSubtractFeeFromAmount)
181 fSubtractFeeFromAmount =
true;
191 setAddress.insert(rcp.address);
195 CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount};
201 if(setAddress.size() != nAddresses)
217 int nChangePosRet = -1;
219 auto& newTx = transaction.
getWtx();
220 const auto& res =
m_wallet->createTransaction(vecSend, coinControl, !
wallet().privateKeysDisabled() , nChangePosRet, nFeeRequired);
221 newTx = res ? *res :
nullptr;
223 if (fSubtractFeeFromAmount && newTx)
228 if(!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance)
240 if (nFeeRequired >
m_wallet->getDefaultMaxTxFee()) {
250 QByteArray transaction_array;
253 std::vector<std::pair<std::string, std::string>> vOrderForm;
256 if (!rcp.message.isEmpty())
257 vOrderForm.emplace_back(
"Message", rcp.message.toStdString());
260 auto& newTx = transaction.
getWtx();
265 transaction_array.append((
const char*)ssTx.
data(), ssTx.
size());
273 std::string strAddress = rcp.address.toStdString();
275 std::string strLabel = rcp.label.toStdString();
280 dest, &
name,
nullptr,
nullptr))
282 m_wallet->setAddressBook(dest, strLabel,
"send");
284 else if (
name != strLabel)
286 m_wallet->setAddressBook(dest, strLabel,
"");
290 Q_EMIT
coinsSent(
this, rcp, transaction_array);
322 if (
m_wallet->privateKeysDisabled()) {
339 return m_wallet->encryptWallet(passphrase);
352 return m_wallet->unlock(passPhrase);
359 return m_wallet->changeWalletPassphrase(oldPass, newPass);
365 qDebug() <<
"NotifyUnload";
366 bool invoked = QMetaObject::invokeMethod(walletModel,
"unload");
372 qDebug() <<
"NotifyKeyStoreStatusChanged";
373 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateStatus", Qt::QueuedConnection);
378 const CTxDestination &address,
const std::string &label,
bool isMine,
379 const std::string &purpose,
ChangeType status)
382 QString strLabel = QString::fromStdString(label);
383 QString strPurpose = QString::fromStdString(purpose);
385 qDebug() <<
"NotifyAddressBookChanged: " + strAddress +
" " + strLabel +
" isMine=" + QString::number(isMine) +
" purpose=" + strPurpose +
" status=" + QString::number(status);
386 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateAddressBook",
387 Q_ARG(QString, strAddress),
388 Q_ARG(QString, strLabel),
390 Q_ARG(QString, strPurpose),
399 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateTransaction", Qt::QueuedConnection);
406 bool invoked = QMetaObject::invokeMethod(walletmodel,
"showProgress", Qt::QueuedConnection,
407 Q_ARG(QString, QString::fromStdString(title)),
408 Q_ARG(
int, nProgress));
414 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateWatchOnlyFlag", Qt::QueuedConnection,
415 Q_ARG(
bool, fHaveWatchonly));
421 bool invoked = QMetaObject::invokeMethod(walletmodel,
"canGetAddressesChanged");
475 wallet->setWalletLocked(
true);
490 std::vector<bilingual_str> errors;
494 if (!
m_wallet->createBumpTransaction(hash, coin_control, errors, old_fee, new_fee, mtx)) {
495 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Increasing transaction fee failed") +
"<br />(" +
496 (errors.size() ? QString::fromStdString(errors[0].translated) :
"") +
")");
502 QString questionString = tr(
"Do you want to increase the fee?");
503 questionString.append(
"<br />");
504 questionString.append(
"<table style=\"text-align: left;\">");
505 questionString.append(
"<tr><td>");
506 questionString.append(tr(
"Current fee:"));
507 questionString.append(
"</td><td>");
509 questionString.append(
"</td></tr><tr><td>");
510 questionString.append(tr(
"Increase:"));
511 questionString.append(
"</td><td>");
513 questionString.append(
"</td></tr><tr><td>");
514 questionString.append(tr(
"New fee:"));
515 questionString.append(
"</td><td>");
517 questionString.append(
"</td></tr></table>");
521 questionString.append(
"<br><br>");
522 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."));
526 confirmationDialog->setAttribute(Qt::WA_DeleteOnClose);
528 const auto retval =
static_cast<QMessageBox::StandardButton
>(confirmationDialog->exec());
531 if (retval != QMessageBox::Yes && retval != QMessageBox::Save) {
542 if (retval == QMessageBox::Save) {
544 bool complete =
false;
547 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Can't draft transaction."));
561 if (!
m_wallet->signBumpTransaction(mtx)) {
562 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Can't sign transaction."));
566 if(!
m_wallet->commitBumpTransaction(hash, std::move(mtx), errors, new_hash)) {
567 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Could not commit transaction") +
"<br />(" +
568 QString::fromStdString(errors[0].translated)+
")");
579 res =
m_wallet->displayAddress(dest);
580 }
catch (
const std::runtime_error& e) {
581 QMessageBox::critical(
nullptr, tr(
"Can't display address"), e.what());
593 return QString::fromStdString(
m_wallet->getWalletName());
599 return name.isEmpty() ?
"["+tr(
"default wallet")+
"]" :
name;
Model for list of recently generated payment requests / bitcoin: URIs.
TransactionTableModel * transactionTableModel
Predefined combinations for certain default usage cases.
OptionsModel * getOptionsModel() const
interfaces::Wallet & wallet() const
void coinsSent(WalletModel *wallet, SendCoinsRecipient recipient, QByteArray transaction)
RecentRequestsTableModel * recentRequestsTableModel
std::unique_ptr< interfaces::Handler > m_handler_address_book_changed
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const wallet::CCoinControl &coinControl)
static bool isWalletEnabled()
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
UnlockContext requestUnlock()
std::unique_ptr< interfaces::Handler > m_handler_unload
void unsubscribeFromCoreSignals()
std::shared_ptr< CWallet > m_wallet
interfaces::WalletBalances getCachedBalance() const
TransactionTableModel * getTransactionTableModel() const
#define SEND_CONFIRM_DELAY
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
uint256 m_cached_last_update_tip
static constexpr auto MODEL_UPDATE_DELAY
std::string EncodeBase64(Span< const unsigned char > input)
QList< SendCoinsRecipient > getRecipients() const
bool validateAddress(const QString &address) const
static const bool DEFAULT_DISABLE_WALLET
std::unique_ptr< interfaces::Handler > m_handler_status_changed
A version of CTransaction with the PSBT format.
Double ended buffer combining vector and stream-like interfaces.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
EncryptionStatus getEncryptionStatus() const
void setTransactionFee(const CAmount &newFee)
bool bumpFee(uint256 hash, uint256 &new_hash)
UnlockContext(WalletModel *wallet, bool valid, bool relock)
int64_t CAmount
Amount in satoshis (Can be negative)
uint256 getBestBlockHash() EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex)
uint256 getLastBlockProcessed() const
static void NotifyCanGetAddressesChanged(WalletModel *walletmodel)
RecentRequestsTableModel * getRecentRequestsTableModel() const
void push_back(const T &value)
void setClientModel(ClientModel *client_model)
Collection of wallet balances.
void setClipboard(const QString &str)
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
static void NotifyAddressBookChanged(WalletModel *walletmodel, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)
static secp256k1_context * ctx
void reassignAmounts(int nChangePosRet)
std::unique_ptr< interfaces::Wallet > m_wallet
bool setWalletEncrypted(const SecureString &passphrase)
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.
void refresh(bool pk_hash_only=false)
void encryptionStatusChanged()
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
OptionsModel * optionsModel
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
QString getWalletName() const
EncryptionStatus cachedEncryptionStatus
bool getEnablePSBTControls() const
UI model for the transaction table of a wallet.
Model for Bitcoin network client.
bool isMultiwallet() const
Qt model of the address book in the core.
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
std::unique_ptr< interfaces::Handler > m_handler_show_progress
virtual CAmount getAvailableBalance(const wallet::CCoinControl &coin_control)=0
Get available balance.
ClientModel * m_client_model
static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel)
void updateWatchOnlyFlag(bool fHaveWatchonly)
static void NotifyUnload(WalletModel *walletModel)
bool fForceCheckBalanceChanged
std::unique_ptr< interfaces::Handler > m_handler_can_get_addrs_changed
Interface from Qt to configuration data structure for Bitcoin client.
Serialized script, used inside transaction inputs and outputs.
Interface to Bitcoin wallet from Qt view code.
virtual WalletLoader & walletLoader()=0
Get wallet loader.
interfaces::WalletBalances m_cached_balances
static const int PROTOCOL_VERSION
network protocol versioning
WalletModel(std::unique_ptr< interfaces::Wallet > wallet, ClientModel &client_model, const PlatformStyle *platformStyle, QObject *parent=nullptr)
interfaces::Node & m_node
static void NotifyTransactionChanged(WalletModel *walletmodel, const uint256 &hash, ChangeType status)
void message(const QString &title, const QString &message, unsigned int style)
void CopyFrom(UnlockContext &&rhs)
void notifyWatchonlyChanged(bool fHaveWatchonly)
Data model for a walletmodel transaction.
bilingual_str ErrorString(const Result< T > &result)
std::string EncodeDestination(const CTxDestination &dest)
CTransactionRef & getWtx()
QString getDisplayName() const
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.
AddressTableModel * getAddressTableModel() const
AddressTableModel * addressTableModel
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)
static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
void sendCoins(WalletModelTransaction &transaction)
std::unique_ptr< interfaces::Handler > m_handler_transaction_changed
virtual void commitTransaction(CTransactionRef tx, WalletValueMap value_map, WalletOrderForm order_form)=0
Commit transaction.
void checkBalanceChanged(const interfaces::WalletBalances &new_balances)
ChangeType
General change type (added, updated, removed).
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
void updateConfirmations()
std::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
bool balanceChanged(const WalletBalances &prev) const
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
void balanceChanged(const interfaces::WalletBalances &balances)
std::unique_ptr< interfaces::Handler > m_handler_watch_only_changed
void pollBalanceChanged()
void subscribeToCoreSignals()
bool displayAddress(std::string sAddress) const