35 m_client_model(&client_model),
m_node(client_model.
node()),
36 optionsModel(client_model.getOptionsModel()), addressTableModel(nullptr),
37 transactionTableModel(nullptr), recentRequestsTableModel(nullptr),
38 cachedEncryptionStatus(Unencrypted), timer(new QTimer(this)) {
86 if (!
m_wallet->tryGetBalances(new_balances, block_hash)) {
117 const QString &label,
bool isMine,
118 const QString &purpose,
int status) {
137 bool fSubtractFeeFromAmount =
false;
138 QList<SendCoinsRecipient> recipients = transaction.
getRecipients();
139 std::vector<CRecipient> vecSend;
141 if (recipients.empty()) {
146 QSet<QString> setAddress;
151 if (rcp.fSubtractFeeFromAmount) {
152 fSubtractFeeFromAmount =
true;
157 if (rcp.paymentRequest.IsInitialized()) {
159 const payments::PaymentDetails &details =
160 rcp.paymentRequest.getDetails();
161 for (
int i = 0; i < details.outputs_size(); i++) {
162 const payments::Output &out = details.outputs(i);
163 if (out.amount() <= 0) {
167 subtotal += int64_t(out.amount()) *
SATOSHI;
168 const uint8_t *scriptStr = (
const uint8_t *)out.script().data();
169 CScript scriptPubKey(scriptStr,
170 scriptStr + out.script().size());
172 CRecipient recipient = {scriptPubKey, nAmount,
173 rcp.fSubtractFeeFromAmount};
174 vecSend.push_back(recipient);
193 setAddress.insert(rcp.address);
199 rcp.fSubtractFeeFromAmount};
200 vecSend.push_back(recipient);
205 if (setAddress.size() != nAddresses) {
211 if (total > nBalance) {
216 int nChangePosRet = -1;
219 auto &newTx = transaction.
getWtx();
220 const auto &res =
m_wallet->createTransaction(
221 vecSend, coinControl, !
wallet().privateKeysDisabled(),
222 nChangePosRet, nFeeRequired);
223 newTx = res ? *res :
nullptr;
225 if (fSubtractFeeFromAmount && newTx) {
230 if (!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance) {
243 if (nFeeRequired >
m_wallet->getDefaultMaxTxFee()) {
253 QByteArray transaction_array;
255 std::vector<std::pair<std::string, std::string>> vOrderForm;
258 if (rcp.paymentRequest.IsInitialized()) {
260 if (PaymentServer::verifyExpired(rcp.paymentRequest.getDetails())) {
266 rcp.paymentRequest.SerializeToString(&value);
267 vOrderForm.emplace_back(
"PaymentRequest", std::move(value));
271 if (!rcp.message.isEmpty()) {
274 vOrderForm.emplace_back(
"Message", rcp.message.toStdString());
279 auto &newTx = transaction.
getWtx();
284 transaction_array.append((
const char *)ssTx.data(), ssTx.size());
291 if (!rcp.paymentRequest.IsInitialized())
294 std::string strAddress = rcp.address.toStdString();
297 std::string strLabel = rcp.label.toStdString();
302 m_wallet->setAddressBook(dest, strLabel,
"send");
303 }
else if (
name != strLabel) {
305 m_wallet->setAddressBook(dest, strLabel,
"");
345 return m_wallet->encryptWallet(passphrase);
354 return m_wallet->unlock(passPhrase);
362 return m_wallet->changeWalletPassphrase(oldPass, newPass);
367 qDebug() <<
"NotifyUnload";
368 bool invoked = QMetaObject::invokeMethod(walletModel,
"unload");
373 qDebug() <<
"NotifyKeyStoreStatusChanged";
374 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateStatus",
375 Qt::QueuedConnection);
381 const std::string &label,
bool isMine,
382 const std::string &purpose,
384 QString strAddress = QString::fromStdString(
386 QString strLabel = QString::fromStdString(label);
387 QString strPurpose = QString::fromStdString(purpose);
389 qDebug() <<
"NotifyAddressBookChanged: " + strAddress +
" " + strLabel +
390 " isMine=" + QString::number(isMine) +
391 " purpose=" + strPurpose +
392 " status=" + QString::number(status);
393 bool invoked = QMetaObject::invokeMethod(
394 walletmodel,
"updateAddressBook", Q_ARG(QString, strAddress),
395 Q_ARG(QString, strLabel), Q_ARG(
bool, isMine),
396 Q_ARG(QString, strPurpose), Q_ARG(
int, status));
404 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateTransaction",
405 Qt::QueuedConnection);
412 bool invoked = QMetaObject::invokeMethod(
413 walletmodel,
"showProgress", Qt::QueuedConnection,
414 Q_ARG(QString, QString::fromStdString(title)), Q_ARG(
int, nProgress));
419 bool fHaveWatchonly) {
420 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateWatchOnlyFlag",
421 Qt::QueuedConnection,
422 Q_ARG(
bool, fHaveWatchonly));
428 QMetaObject::invokeMethod(walletmodel,
"canGetAddressesChanged");
439 std::placeholders::_2, std::placeholders::_3,
440 std::placeholders::_4, std::placeholders::_5));
443 std::placeholders::_2));
445 ShowProgress,
this, std::placeholders::_1, std::placeholders::_2));
479 :
wallet(_wallet), valid(_valid), relock(_relock) {}
482 if (valid && relock) {
483 wallet->setWalletLocked(
true);
494 std::vector<std::string> &vReceiveRequests) {
496 vReceiveRequests =
m_wallet->getDestValues(
"rr");
501 const std::string &sRequest) {
504 std::stringstream ss;
507 std::string key =
"rr" + ss.str();
509 return sRequest.empty() ?
m_wallet->eraseDestData(dest, key)
510 :
m_wallet->addDestData(dest, key, sRequest);
518 return QString::fromStdString(
m_wallet->getWalletName());
523 return name.isEmpty() ?
"[" + tr(
"default wallet") +
"]" :
name;
static constexpr Amount SATOSHI
std::string EncodeCashAddr(const CTxDestination &dst, const CChainParams ¶ms)
const CChainParams & Params()
Return the currently selected parameters.
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.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Model for Bitcoin network client.
BlockHash getBestBlockHash() EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex)
Double ended buffer combining vector and stream-like interfaces.
Interface from Qt to configuration data structure for Bitcoin client.
Model for list of recently generated payment requests / bitcoincash: 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
void loadReceiveRequests(std::vector< std::string > &vReceiveRequests)
EncryptionStatus cachedEncryptionStatus
ClientModel * m_client_model
std::unique_ptr< interfaces::Handler > m_handler_watch_only_changed
BlockHash m_cached_last_update_tip
interfaces::Node & m_node
std::unique_ptr< interfaces::Handler > m_handler_transaction_changed
void pollBalanceChanged()
Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so.
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)
BlockHash getLastBlockProcessed() const
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
void message(const QString &title, const QString &message, unsigned int style)
void coinsSent(interfaces::Wallet &wallet, SendCoinsRecipient recipient, QByteArray transaction)
void setClientModel(ClientModel *client_model)
const CChainParams & getChainParams() const
bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
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
QString getDisplayName() const
void checkBalanceChanged(const interfaces::WalletBalances &new_balances)
void unsubscribeFromCoreSignals()
void updateTransaction()
New transaction, or transaction changed status.
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
New, updated or removed address book entry.
WalletModel(std::unique_ptr< interfaces::Wallet > wallet, ClientModel &client_model, const PlatformStyle *platformStyle, QObject *parent=nullptr)
void updateWatchOnlyFlag(bool fHaveWatchonly)
Watch-only added.
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 reassignAmounts(int nChangePosRet)
void setTransactionFee(const Amount newFee)
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 void commitTransaction(CTransactionRef tx, WalletValueMap value_map, WalletOrderForm order_form)=0
Commit transaction.
static constexpr auto MODEL_UPDATE_DELAY
A delay between model updates.
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
CTxDestination DecodeDestination(const std::string &addr, const CChainParams ¶ms)
Implement std::hash so RCUPtr can be used as a key for maps or sets.
bilingual_str ErrorString(const Result< T > &result)
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 > CTxDestination
A txout script template with a specific destination.
static constexpr Amount zero() noexcept
A BlockHash is a unqiue identifier for a block.
A TxId is the identifier of a transaction.
Collection of wallet balances.
bool balanceChanged(const WalletBalances &prev) const
ChangeType
General change type (added, updated, removed).
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 NotifyTransactionChanged(WalletModel *walletmodel, const TxId &hash, ChangeType status)
static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel)