 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
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))
105 if (!
m_wallet->tryGetBalances(new_balances, block_hash)) {
136 bool isMine,
const QString &purpose,
int status)
156 bool fSubtractFeeFromAmount =
false;
157 QList<SendCoinsRecipient> recipients = transaction.
getRecipients();
158 std::vector<CRecipient> vecSend;
160 if(recipients.empty())
165 QSet<QString> setAddress;
171 if (rcp.fSubtractFeeFromAmount)
172 fSubtractFeeFromAmount =
true;
182 setAddress.insert(rcp.address);
186 CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount};
192 if(setAddress.size() != nAddresses)
206 int nChangePosRet = -1;
209 auto& newTx = transaction.
getWtx();
210 newTx =
m_wallet->createTransaction(vecSend, coinControl, !
wallet().privateKeysDisabled() , nChangePosRet, nFeeRequired,
error);
212 if (fSubtractFeeFromAmount && newTx)
217 if(!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance)
221 Q_EMIT
message(tr(
"Send Coins"), QString::fromStdString(
error.translated),
229 if (nFeeRequired >
m_wallet->getDefaultMaxTxFee()) {
239 QByteArray transaction_array;
242 std::vector<std::pair<std::string, std::string>> vOrderForm;
245 if (!rcp.message.isEmpty())
246 vOrderForm.emplace_back(
"Message", rcp.message.toStdString());
249 auto& newTx = transaction.
getWtx();
254 transaction_array.append((
const char*)ssTx.
data(), ssTx.
size());
262 std::string strAddress = rcp.address.toStdString();
264 std::string strLabel = rcp.label.toStdString();
269 dest, &
name,
nullptr,
nullptr))
271 m_wallet->setAddressBook(dest, strLabel,
"send");
273 else if (
name != strLabel)
275 m_wallet->setAddressBook(dest, strLabel,
"");
279 Q_EMIT
coinsSent(
this, rcp, transaction_array);
325 return m_wallet->encryptWallet(passphrase);
338 return m_wallet->unlock(passPhrase);
345 return m_wallet->changeWalletPassphrase(oldPass, newPass);
351 qDebug() <<
"NotifyUnload";
352 bool invoked = QMetaObject::invokeMethod(walletModel,
"unload");
358 qDebug() <<
"NotifyKeyStoreStatusChanged";
359 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateStatus", Qt::QueuedConnection);
364 const CTxDestination &address,
const std::string &label,
bool isMine,
365 const std::string &purpose,
ChangeType status)
368 QString strLabel = QString::fromStdString(label);
369 QString strPurpose = QString::fromStdString(purpose);
371 qDebug() <<
"NotifyAddressBookChanged: " + strAddress +
" " + strLabel +
" isMine=" + QString::number(isMine) +
" purpose=" + strPurpose +
" status=" + QString::number(status);
372 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateAddressBook", Qt::QueuedConnection,
373 Q_ARG(QString, strAddress),
374 Q_ARG(QString, strLabel),
376 Q_ARG(QString, strPurpose),
385 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateTransaction", Qt::QueuedConnection);
392 bool invoked = QMetaObject::invokeMethod(walletmodel,
"showProgress", Qt::QueuedConnection,
393 Q_ARG(QString, QString::fromStdString(title)),
394 Q_ARG(
int, nProgress));
400 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateWatchOnlyFlag", Qt::QueuedConnection,
401 Q_ARG(
bool, fHaveWatchonly));
407 bool invoked = QMetaObject::invokeMethod(walletmodel,
"canGetAddressesChanged");
461 wallet->setWalletLocked(
true);
476 std::vector<bilingual_str> errors;
480 if (!
m_wallet->createBumpTransaction(hash, coin_control, errors, old_fee, new_fee, mtx)) {
481 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Increasing transaction fee failed") +
"<br />(" +
482 (errors.size() ? QString::fromStdString(errors[0].translated) :
"") +
")");
488 QString questionString = tr(
"Do you want to increase the fee?");
489 questionString.append(
"<br />");
490 questionString.append(
"<table style=\"text-align: left;\">");
491 questionString.append(
"<tr><td>");
492 questionString.append(tr(
"Current fee:"));
493 questionString.append(
"</td><td>");
495 questionString.append(
"</td></tr><tr><td>");
496 questionString.append(tr(
"Increase:"));
497 questionString.append(
"</td><td>");
499 questionString.append(
"</td></tr><tr><td>");
500 questionString.append(tr(
"New fee:"));
501 questionString.append(
"</td><td>");
503 questionString.append(
"</td></tr></table>");
507 questionString.append(
"<br><br>");
508 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."));
512 confirmationDialog->setAttribute(Qt::WA_DeleteOnClose);
514 const auto retval =
static_cast<QMessageBox::StandardButton
>(confirmationDialog->exec());
517 if (retval != QMessageBox::Yes && retval != QMessageBox::Save) {
528 if (retval == QMessageBox::Save) {
530 bool complete =
false;
533 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Can't draft transaction."));
547 if (!
m_wallet->signBumpTransaction(mtx)) {
548 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Can't sign transaction."));
552 if(!
m_wallet->commitBumpTransaction(hash, std::move(mtx), errors, new_hash)) {
553 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Could not commit transaction") +
"<br />(" +
554 QString::fromStdString(errors[0].translated)+
")");
565 res =
m_wallet->displayAddress(dest);
566 }
catch (
const std::runtime_error& e) {
567 QMessageBox::critical(
nullptr, tr(
"Can't display address"), e.what());
579 return QString::fromStdString(
m_wallet->getWalletName());
585 return name.isEmpty() ?
"["+tr(
"default wallet")+
"]" :
name;
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
RecentRequestsTableModel * recentRequestsTableModel
OptionsModel * getOptionsModel()
void refresh(bool pk_hash_only=false)
bool bumpFee(uint256 hash, uint256 &new_hash)
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
void updateConfirmations()
uint256 getLastBlockProcessed() const
TransactionTableModel * transactionTableModel
Interface to Bitcoin wallet from Qt view code.
std::unique_ptr< interfaces::Handler > m_handler_status_changed
std::unique_ptr< interfaces::Handler > m_handler_show_progress
#define SEND_CONFIRM_DELAY
@ TransactionCreationFailed
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Qt model of the address book in the core.
static bool isWalletEnabled()
AddressTableModel * getAddressTableModel()
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
@ AmountWithFeeExceedsBalance
std::unique_ptr< interfaces::Handler > m_handler_watch_only_changed
std::unique_ptr< interfaces::Handler > m_handler_transaction_changed
std::unique_ptr< interfaces::Wallet > m_wallet
bool balanceChanged(const WalletBalances &prev) const
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as HTML string (with unit)
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const wallet::CCoinControl &coinControl)
TransactionTableModel * getTransactionTableModel()
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....
uint256 m_cached_last_update_tip
std::string EncodeBase64(Span< const unsigned char > input)
UnlockContext requestUnlock()
void setClientModel(ClientModel *client_model)
void setClipboard(const QString &str)
static void NotifyCanGetAddressesChanged(WalletModel *walletmodel)
std::unique_ptr< interfaces::Handler > m_handler_can_get_addrs_changed
AddressTableModel * addressTableModel
Interface from Qt to configuration data structure for Bitcoin client.
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
interfaces::Wallet & wallet() const
ChangeType
General change type (added, updated, removed).
void push_back(const T &value)
Collection of wallet balances.
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
static void NotifyAddressBookChanged(WalletModel *walletmodel, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)
std::unique_ptr< interfaces::Handler > m_handler_address_book_changed
void encryptionStatusChanged()
void unsubscribeFromCoreSignals()
virtual void commitTransaction(CTransactionRef tx, WalletValueMap value_map, WalletOrderForm order_form)=0
Commit transaction.
interfaces::WalletBalances m_cached_balances
bool validateAddress(const QString &address)
void updateWatchOnlyFlag(bool fHaveWatchonly)
void message(const QString &title, const QString &message, unsigned int style)
void setTransactionFee(const CAmount &newFee)
Model for list of recently generated payment requests / bitcoin: URIs.
bool setWalletEncrypted(const SecureString &passphrase)
static constexpr auto MODEL_UPDATE_DELAY
EncryptionStatus getEncryptionStatus() const
int64_t CAmount
Amount in satoshis (Can be negative)
std::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
QString getWalletName() const
void coinsSent(WalletModel *wallet, SendCoinsRecipient recipient, QByteArray transaction)
void checkBalanceChanged(const interfaces::WalletBalances &new_balances)
RecentRequestsTableModel * getRecentRequestsTableModel()
QList< SendCoinsRecipient > getRecipients() const
virtual WalletLoader & walletLoader()=0
Get wallet loader.
Serialized script, used inside transaction inputs and outputs.
static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel)
Model for Bitcoin network client.
std::unique_ptr< interfaces::Handler > m_handler_unload
UI model for the transaction table of a wallet.
OptionsModel * optionsModel
UnlockContext(WalletModel *wallet, bool valid, bool relock)
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
A version of CTransaction with the PSBT format.
static void NotifyTransactionChanged(WalletModel *walletmodel, const uint256 &hash, ChangeType status)
bool fForceCheckBalanceChanged
static void NotifyUnload(WalletModel *walletModel)
std::shared_ptr< CWallet > m_wallet
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
ClientModel * m_client_model
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
static const bool DEFAULT_DISABLE_WALLET
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
Double ended buffer combining vector and stream-like interfaces.
interfaces::Node & m_node
void subscribeToCoreSignals()
static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
bool error(const char *fmt, const Args &... args)
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
QString getDisplayName() const
A mutable version of CTransaction.
static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
WalletModel(std::unique_ptr< interfaces::Wallet > wallet, ClientModel &client_model, const PlatformStyle *platformStyle, QObject *parent=nullptr)
void CopyFrom(UnlockContext &&rhs)
void balanceChanged(const interfaces::WalletBalances &balances)
uint256 getBestBlockHash()
void pollBalanceChanged()
virtual TransactionError fillPSBT(int sighash_type, bool sign, bool bip32derivs, size_t *n_signed, PartiallySignedTransaction &psbtx, bool &complete)=0
Fill PSBT.
bool displayAddress(std::string sAddress)
CTransactionRef & getWtx()
Data model for a walletmodel transaction.
void notifyWatchonlyChanged(bool fHaveWatchonly)
EncryptionStatus cachedEncryptionStatus
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
std::string EncodeDestination(const CTxDestination &dest)
static secp256k1_context * ctx
void reassignAmounts(int nChangePosRet)
static const int PROTOCOL_VERSION
network protocol versioning
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).