34 m_client_model(client_model),
m_node(client_model.node()),
35 optionsModel(client_model.getOptionsModel()), addressTableModel(nullptr),
36 transactionTableModel(nullptr), recentRequestsTableModel(nullptr),
37 cachedEncryptionStatus(Unencrypted), cachedNumBlocks(0) {
52 QTimer *timer =
new QTimer(
this);
72 if (!
m_wallet->tryGetBalances(new_balances, numBlocks,
102 const QString &label,
bool isMine,
103 const QString &purpose,
int status) {
122 bool fSubtractFeeFromAmount =
false;
123 QList<SendCoinsRecipient> recipients = transaction.
getRecipients();
124 std::vector<CRecipient> vecSend;
126 if (recipients.empty()) {
131 QSet<QString> setAddress;
136 if (rcp.fSubtractFeeFromAmount) {
137 fSubtractFeeFromAmount =
true;
142 if (rcp.paymentRequest.IsInitialized()) {
144 const payments::PaymentDetails &details =
145 rcp.paymentRequest.getDetails();
146 for (
int i = 0; i < details.outputs_size(); i++) {
147 const payments::Output &out = details.outputs(i);
148 if (out.amount() <= 0) {
152 subtotal += int64_t(out.amount()) *
SATOSHI;
153 const uint8_t *scriptStr = (
const uint8_t *)out.script().data();
154 CScript scriptPubKey(scriptStr,
155 scriptStr + out.script().size());
157 CRecipient recipient = {scriptPubKey, nAmount,
159 vecSend.push_back(recipient);
178 setAddress.insert(rcp.address);
184 rcp.fSubtractFeeFromAmount};
185 vecSend.push_back(recipient);
190 if (setAddress.size() != nAddresses) {
196 if (total > nBalance) {
201 int nChangePosRet = -1;
204 auto &newTx = transaction.
getWtx();
205 newTx =
m_wallet->createTransaction(
206 vecSend, coinControl, !
wallet().privateKeysDisabled() ,
207 nChangePosRet, nFeeRequired, error);
209 if (fSubtractFeeFromAmount && newTx) {
214 if (!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance) {
217 Q_EMIT
message(tr(
"Send Coins"),
226 if (nFeeRequired >
m_wallet->getDefaultMaxTxFee()) {
236 QByteArray transaction_array;
238 std::vector<std::pair<std::string, std::string>> vOrderForm;
241 if (rcp.paymentRequest.IsInitialized()) {
243 if (PaymentServer::verifyExpired(rcp.paymentRequest.getDetails())) {
249 rcp.paymentRequest.SerializeToString(&value);
250 vOrderForm.emplace_back(
"PaymentRequest", std::move(value));
254 if (!rcp.message.isEmpty()) {
257 vOrderForm.emplace_back(
"Message", rcp.message.toStdString());
262 auto &newTx = transaction.
getWtx();
267 transaction_array.append(&(ssTx[0]), ssTx.
size());
274 if (!rcp.paymentRequest.IsInitialized())
277 std::string strAddress = rcp.address.toStdString();
280 std::string strLabel = rcp.label.toStdString();
283 if (!
m_wallet->getAddress(dest, &name,
nullptr,
285 m_wallet->setAddressBook(dest, strLabel,
"send");
286 }
else if (name != strLabel) {
288 m_wallet->setAddressBook(dest, strLabel,
"");
331 return m_wallet->encryptWallet(passphrase);
344 return m_wallet->unlock(passPhrase);
352 return m_wallet->changeWalletPassphrase(oldPass, newPass);
357 qDebug() <<
"NotifyUnload";
358 bool invoked = QMetaObject::invokeMethod(walletModel,
"unload");
363 qDebug() <<
"NotifyKeyStoreStatusChanged";
364 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateStatus",
365 Qt::QueuedConnection);
371 const std::string &label,
bool isMine,
372 const std::string &purpose,
374 QString strAddress = QString::fromStdString(
376 QString strLabel = QString::fromStdString(label);
377 QString strPurpose = QString::fromStdString(purpose);
379 qDebug() <<
"NotifyAddressBookChanged: " + strAddress +
" " + strLabel +
380 " isMine=" + QString::number(isMine) +
381 " purpose=" + strPurpose +
382 " status=" + QString::number(status);
383 bool invoked = QMetaObject::invokeMethod(
384 walletmodel,
"updateAddressBook", Qt::QueuedConnection,
385 Q_ARG(QString, strAddress), Q_ARG(QString, strLabel),
386 Q_ARG(
bool, isMine), Q_ARG(QString, strPurpose), Q_ARG(
int, status));
394 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateTransaction",
395 Qt::QueuedConnection);
402 bool invoked = QMetaObject::invokeMethod(
403 walletmodel,
"showProgress", Qt::QueuedConnection,
404 Q_ARG(QString, QString::fromStdString(title)), Q_ARG(
int, nProgress));
409 bool fHaveWatchonly) {
410 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateWatchOnlyFlag",
411 Qt::QueuedConnection,
412 Q_ARG(
bool, fHaveWatchonly));
418 QMetaObject::invokeMethod(walletmodel,
"canGetAddressesChanged");
429 std::placeholders::_2, std::placeholders::_3,
430 std::placeholders::_4, std::placeholders::_5));
433 std::placeholders::_2));
435 ShowProgress,
this, std::placeholders::_1, std::placeholders::_2));
469 :
wallet(_wallet), valid(_valid), relock(_relock) {}
484 std::vector<std::string> &vReceiveRequests) {
486 vReceiveRequests =
m_wallet->getDestValues(
"rr");
491 const std::string &sRequest) {
494 std::stringstream ss;
497 std::string key =
"rr" + ss.str();
499 return sRequest.empty() ?
m_wallet->eraseDestData(dest, key)
500 :
m_wallet->addDestData(dest, key, sRequest);
508 return QString::fromStdString(
m_wallet->getWalletName());
513 return name.isEmpty() ?
"[" + tr(
"default wallet") +
"]" :
name;
void loadReceiveRequests(std::vector< std::string > &vReceiveRequests)
Model for list of recently generated payment requests / bitcoincash: URIs.
TransactionTableModel * transactionTableModel
std::shared_ptr< CWallet > m_wallet
interfaces::Wallet & wallet() const
static constexpr Amount zero()
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::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
QList< SendCoinsRecipient > getRecipients() const
static constexpr Amount SATOSHI
static const bool DEFAULT_DISABLE_WALLET
std::unique_ptr< interfaces::Handler > m_handler_status_changed
bool fSubtractFeeFromAmount
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
Double ended buffer combining vector and stream-like interfaces.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).
void setTransactionFee(const Amount newFee)
AddressTableModel * getAddressTableModel()
EncryptionStatus getEncryptionStatus() const
UnlockContext(WalletModel *wallet, bool valid, bool relock)
static void NotifyCanGetAddressesChanged(WalletModel *walletmodel)
void coinsSent(interfaces::Wallet &wallet, SendCoinsRecipient recipient, QByteArray transaction)
const CChainParams & getChainParams() const
void updateTransaction()
New transaction, or transaction changed status.
Collection of wallet balances.
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)
void reassignAmounts(int nChangePosRet)
std::unique_ptr< interfaces::Wallet > m_wallet
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl &coinControl)
void encryptionStatusChanged()
OptionsModel * optionsModel
CTxDestination DecodeDestination(const std::string &addr, const CChainParams ¶ms)
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
QString getWalletName() const
TransactionTableModel * getTransactionTableModel()
EncryptionStatus cachedEncryptionStatus
UI model for the transaction table of a wallet.
Model for Bitcoin network client.
Qt model of the address book in the core.
static void NotifyTransactionChanged(WalletModel *walletmodel, const TxId &hash, ChangeType status)
static const int MODEL_UPDATE_DELAY
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
std::unique_ptr< interfaces::Handler > m_handler_show_progress
bool validateAddress(const QString &address)
static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel)
void updateWatchOnlyFlag(bool fHaveWatchonly)
Watch-only added.
static void NotifyUnload(WalletModel *walletModel)
bool fForceCheckBalanceChanged
std::unique_ptr< interfaces::Handler > m_handler_can_get_addrs_changed
RecentRequestsTableModel * getRecentRequestsTableModel()
Interface from Qt to configuration data structure for Bitcoin client.
const CChainParams & Params()
Return the currently selected parameters.
Serialized script, used inside transaction inputs and outputs.
Interface to Bitcoin wallet from Qt view code.
A TxId is the identifier of a transaction.
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)
bool setWalletEncrypted(bool encrypted, const SecureString &passphrase)
interfaces::Node & m_node
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 EncodeCashAddr(const CTxDestination &dst, const CChainParams ¶ms)
CTransactionRef & getWtx()
QString getDisplayName() const
AddressTableModel * addressTableModel
static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
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 saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
bool balanceChanged(const WalletBalances &prev) const
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
New, updated or removed address book entry.
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
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
void pollBalanceChanged()
Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so...
OptionsModel * getOptionsModel()
void subscribeToCoreSignals()