5 #if defined(HAVE_CONFIG_H) 35 #include <QMessageBox> 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.
exec();
511 QMessageBox::StandardButton retval =
static_cast<QMessageBox::StandardButton
>(confirmationDialog.result());
514 if (retval != QMessageBox::Yes) {
527 bool complete =
false;
530 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Can't draft transaction."));
542 if (!
m_wallet->signBumpTransaction(mtx)) {
543 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Can't sign transaction."));
547 if(!
m_wallet->commitBumpTransaction(hash, std::move(mtx), errors, new_hash)) {
548 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Could not commit transaction") +
"<br />(" +
549 QString::fromStdString(errors[0].translated)+
")");
560 res =
m_wallet->displayAddress(dest);
561 }
catch (
const std::runtime_error& e) {
562 QMessageBox::critical(
nullptr, tr(
"Can't display address"), e.what());
574 return QString::fromStdString(
m_wallet->getWalletName());
580 return name.isEmpty() ?
"["+tr(
"default wallet")+
"]" :
name;
Model for list of recently generated payment requests / bitcoin: URIs.
TransactionTableModel * transactionTableModel
interfaces::Wallet & wallet() const
void coinsSent(WalletModel *wallet, SendCoinsRecipient recipient, QByteArray transaction)
RecentRequestsTableModel * recentRequestsTableModel
std::unique_ptr< interfaces::Handler > m_handler_address_book_changed
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
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
uint256 m_cached_last_update_tip
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
QList< SendCoinsRecipient > getRecipients() const
static const bool DEFAULT_DISABLE_WALLET
std::unique_ptr< interfaces::Handler > m_handler_status_changed
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg)
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.
AddressTableModel * getAddressTableModel()
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)
std::string EncodeBase64(Span< const unsigned char > input)
uint256 getLastBlockProcessed() const
static void NotifyCanGetAddressesChanged(WalletModel *walletmodel)
void push_back(const T &value)
void setClientModel(ClientModel *client_model)
bool displayAddress(std::string sAddress)
Collection of wallet balances.
void setClipboard(const QString &str)
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as HTML string (with unit)
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.
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl &coinControl)
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
TransactionTableModel * getTransactionTableModel()
EncryptionStatus cachedEncryptionStatus
std::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
UI model for the transaction table of a wallet.
Model for Bitcoin network client.
Qt model of the address book in the core.
static const int MODEL_UPDATE_DELAY
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
std::unique_ptr< interfaces::Handler > m_handler_show_progress
ClientModel * m_client_model
bool validateAddress(const QString &address)
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
RecentRequestsTableModel * getRecentRequestsTableModel()
virtual WalletClient & walletClient()=0
Get wallet client.
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.
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.
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 * addressTableModel
static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
uint256 getBestBlockHash()
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).
static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
void updateConfirmations()
bool balanceChanged(const WalletBalances &prev) const
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
bool error(const char *fmt, const Args &... args)
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()
OptionsModel * getOptionsModel()
void subscribeToCoreSignals()
Predefined combinations for certain default usage cases.
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).