38 #include <QMessageBox> 46 QObject(parent), wallet(_wallet), optionsModel(_optionsModel), addressTableModel(0),
47 contractTableModel(0),
48 transactionTableModel(0),
49 recentRequestsTableModel(0),
51 tokenTransactionTableModel(0),
53 cachedUnconfirmedBalance(0),
54 cachedImmatureBalance(0),
56 cachedWatchOnlyBalance(0),
57 cachedWatchUnconfBalance(0),
58 cachedWatchImmatureBalance(0),
59 cachedWatchOnlyStake(0),
60 cachedEncryptionStatus(Unencrypted),
172 if(cachedNumBlocksChanged)
191 CAmount newWatchOnlyBalance = 0;
192 CAmount newWatchUnconfBalance = 0;
193 CAmount newWatchImmatureBalance = 0;
214 Q_EMIT
balanceChanged(newBalance, newUnconfirmedBalance, newImmatureBalance, newStake,
215 newWatchOnlyBalance, newWatchUnconfBalance, newWatchImmatureBalance, newWatchOnlyStake);
234 bool isMine,
const QString &purpose,
int status)
249 return addressParsed.
IsValid();
255 bool fSubtractFeeFromAmount =
false;
256 QList<SendCoinsRecipient> recipients = transaction.
getRecipients();
257 std::vector<CRecipient> vecSend;
259 if(recipients.empty())
264 QSet<QString> setAddress;
270 if (rcp.fSubtractFeeFromAmount)
271 fSubtractFeeFromAmount =
true;
273 if (rcp.paymentRequest.IsInitialized())
280 if (out.
amount() <= 0)
continue;
282 const unsigned char* scriptStr = (
const unsigned char*)out.
script().data();
283 CScript scriptPubKey(scriptStr, scriptStr+out.
script().size());
286 vecSend.push_back(recipient);
304 setAddress.insert(rcp.address);
308 CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount};
314 if(setAddress.size() != nAddresses)
332 int nChangePosRet = -1;
333 std::string strFailReason;
337 bool fCreated =
wallet->
CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, nChangePosRet, strFailReason, coinControl);
340 if (fSubtractFeeFromAmount && fCreated)
345 if(!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance)
349 Q_EMIT
message(tr(
"Send Coins"), QString::fromStdString(strFailReason),
366 QByteArray transaction_array;
374 if (rcp.paymentRequest.IsInitialized())
382 std::string key(
"PaymentRequest");
384 rcp.paymentRequest.SerializeToString(&value);
385 newTx->
vOrderForm.push_back(make_pair(key, value));
387 else if (!rcp.message.isEmpty())
388 newTx->
vOrderForm.push_back(make_pair(
"Message", rcp.message.toStdString()));
398 transaction_array.append(&(ssTx[0]), ssTx.
size());
406 if (!rcp.paymentRequest.IsInitialized())
408 std::string strAddress = rcp.address.toStdString();
410 std::string strLabel = rcp.label.toStdString();
421 else if (mi->second.name != strLabel)
531 int walletHasBackup = settings.value(
"walletBackupsNumber", 0).toInt();
532 settings.setValue(
"walletBackupsNumber", walletHasBackup + (ret ? 1 : 0));
540 return settings.value(
"walletBackupsNumber", 0).toBool();
545 if(QFile::exists(filename))
548 QString walletBak = QString::fromStdString(pathWalletBak.string());
564 qDebug() <<
"NotifyKeyStoreStatusChanged";
565 QMetaObject::invokeMethod(walletmodel,
"updateStatus", Qt::QueuedConnection);
570 const std::string &purpose,
ChangeType status)
573 QString strLabel = QString::fromStdString(label);
574 QString strPurpose = QString::fromStdString(purpose);
576 qDebug() <<
"NotifyAddressBookChanged: " + strAddress +
" " + strLabel +
" isMine=" + QString::number(isMine) +
" purpose=" + strPurpose +
" status=" + QString::number(status);
577 QMetaObject::invokeMethod(walletmodel,
"updateAddressBook", Qt::QueuedConnection,
578 Q_ARG(QString, strAddress),
579 Q_ARG(QString, strLabel),
581 Q_ARG(QString, strPurpose),
590 QMetaObject::invokeMethod(walletmodel,
"updateTransaction", Qt::QueuedConnection);
593 static void ShowProgress(
WalletModel *walletmodel,
const std::string &title,
int nProgress)
596 QMetaObject::invokeMethod(walletmodel,
"showProgress", Qt::QueuedConnection,
597 Q_ARG(QString, QString::fromStdString(title)),
598 Q_ARG(
int, nProgress));
601 static void NotifyWatchonlyChanged(
WalletModel *walletmodel,
bool fHaveWatchonly)
603 QMetaObject::invokeMethod(walletmodel,
"updateWatchOnlyFlag", Qt::QueuedConnection,
604 Q_ARG(
bool, fHaveWatchonly));
608 const std::string &
address,
const std::string &label,
const std::string &abi,
ChangeType status)
610 QString strAddress = QString::fromStdString(
address);
611 QString strLabel = QString::fromStdString(label);
612 QString strAbi = QString::fromStdString(abi);
614 qDebug() <<
"NotifyContractBookChanged: " + strAddress +
" " + strLabel +
" status=" + QString::number(status);
615 QMetaObject::invokeMethod(walletmodel,
"updateContractBook", Qt::QueuedConnection,
616 Q_ARG(QString, strAddress),
617 Q_ARG(QString, strLabel),
618 Q_ARG(QString, strAbi),
628 wallet->
ShowProgress.connect(boost::bind(ShowProgress,
this, _1, _2));
636 wallet->
NotifyStatusChanged.disconnect(boost::bind(&NotifyKeyStoreStatusChanged,
this, _1));
639 wallet->
ShowProgress.disconnect(boost::bind(ShowProgress,
this, _1, _2));
683 wallet->setWalletLocked(
true);
689 wallet->updateStatus();
702 return wallet->
GetPubKey(address, vchPubKeyOut);
712 return wallet->
GetKey(address, vchPrivKeyOut);
719 for (
const COutPoint& outpoint : vOutpoints)
721 if (!wallet->
mapWallet.count(outpoint.hash))
continue;
722 int nDepth = wallet->
mapWallet[outpoint.hash].GetDepthInMainChain();
723 if (nDepth < 0)
continue;
724 COutput out(&wallet->
mapWallet[outpoint.hash], outpoint.n, nDepth,
true ,
true ,
true );
725 vOutputs.push_back(out);
739 std::vector<COutput> vecOutputs;
741 for (
const COutput& out : vecOutputs)
744 const CScript& scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey;
747 if(fValidAddress &&
CFabcoinAddress(address).ToString() == fabTokenAddress && out.tx->tx->vout[out.i].nValue)
758 for (
auto& group : wallet->
ListCoins()) {
760 for (
auto& coin : group.second) {
761 resultGroup.emplace_back(std::move(coin));
799 std::stringstream ss;
801 std::string key =
"rr" + ss.str();
804 if (sRequest.empty())
830 std::unique_ptr<CFeeBumper> feeBump;
835 feeBump.reset(
new CFeeBumper(wallet, hash, coin_control, 0));
839 QMessageBox::critical(0, tr(
"Fee bump error"), tr(
"Increasing transaction fee failed") +
"<br />(" +
840 (feeBump->getErrors().size() ? QString::fromStdString(feeBump->getErrors()[0]) :
"") +
")");
845 QString questionString = tr(
"Do you want to increase the fee?");
846 questionString.append(
"<br />");
847 CAmount oldFee = feeBump->getOldFee();
848 CAmount newFee = feeBump->getNewFee();
849 questionString.append(
"<table style=\"text-align: left;\">");
850 questionString.append(
"<tr><td>");
851 questionString.append(tr(
"Current fee:"));
852 questionString.append(
"</td><td>");
854 questionString.append(
"</td></tr><tr><td>");
855 questionString.append(tr(
"Increase:"));
856 questionString.append(
"</td><td>");
858 questionString.append(
"</td></tr><tr><td>");
859 questionString.append(tr(
"New fee:"));
860 questionString.append(
"</td><td>");
862 questionString.append(
"</td></tr></table>");
864 confirmationDialog.
exec();
865 QMessageBox::StandardButton retval = (QMessageBox::StandardButton)confirmationDialog.result();
868 if (retval != QMessageBox::Yes) {
882 res = feeBump->signTransaction(wallet);
885 QMessageBox::critical(0, tr(
"Fee bump error"), tr(
"Can't sign transaction."));
891 res = feeBump->commit(wallet);
894 QMessageBox::critical(0, tr(
"Fee bump error"), tr(
"Could not commit transaction") +
"<br />(" +
895 QString::fromStdString(feeBump->getErrors()[0])+
")");
936 std::map<uint256, CTokenInfo>::iterator it = wallet->
mapToken.find(hash);
938 return it != wallet->
mapToken.end();
960 std::vector<CTokenInfo> listInvalid;
963 std::string strAddress = info.second.strSenderAddress;
967 listInvalid.push_back(info.second);
void loadReceiveRequests(std::vector< std::string > &vReceiveRequests)
Model for list of recently generated payment requests / fabcoin: URIs.
TransactionTableModel * transactionTableModel
void getOutputs(const std::vector< COutPoint > &vOutpoints, std::vector< COutput > &vOutputs)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
RecentRequestsTableModel * recentRequestsTableModel
bool abandonTransaction(uint256 hash) const
void lockCoin(COutPoint &output)
void AvailableCoins(std::vector< COutput > &vCoins, bool fOnlySafe=true, const CCoinControl *coinControl=nullptr, const CAmount &nMinimumAmount=1, const CAmount &nMaximumAmount=MAX_MONEY, const CAmount &nMinimumSumAmount=MAX_MONEY, const uint64_t &nMaximumCount=0, const int &nMinDepth=0, const int &nMaxDepth=9999999) const
populate vCoins with vector of available COutputs.
CAmount GetAvailableBalance(const CCoinControl *coinControl=nullptr) const
#define TRY_LOCK(cs, name)
static bool isWalletEnabled()
TokenTransactionTableModel * tokenTransactionTableModel
bool IsSpendable(const CTxDestination &dest) const
std::map< CTxDestination, CAddressBookData > mapAddressBook
CCriticalSection cs_wallet
CAmount maxTxFee
Absolute maximum transaction fee (in liu) used by wallet and mempool (rejects high fee in sendrawtran...
UnlockContext requestUnlock()
void unsubscribeFromCoreSignals()
std::map< uint256, CTokenInfo > mapToken
bool bumpFee(uint256 hash)
bool isLockedCoin(uint256 hash, unsigned int n) const
base58-encoded Fabcoin addresses.
CAmount GetUnconfirmedBalance() const
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
ContractTableModel * contractTableModel
bool backupWallet(const QString &filename)
void updateEntry(const QString &address, const QString &label, const QString &abi, int status)
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey, SigVersion sigversion)
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const
bool AddTokenEntry(const CTokenInfo &token, bool fFlushOnClose=true)
bool isMineAddress(const std::string &strAddress)
bool existTokenEntry(const CTokenInfo &token)
ContractTableModel * getContractTableModel()
bool fSubtractFeeFromAmount
Double ended buffer combining vector and stream-like interfaces.
CAmount getUnconfirmedBalance() const
AddressTableModel * getAddressTableModel()
Keystore which keeps the private keys encrypted.
void balanceChanged(const CAmount &balance, const CAmount &unconfirmedBalance, const CAmount &immatureBalance, const CAmount &stake, const CAmount &watchOnlyBalance, const CAmount &watchUnconfBalance, const CAmount &watchImmatureBalance, const CAmount &watchOnlyStake)
bool EncryptWallet(const SecureString &strWalletPassphrase)
QString getRestoreParam()
bool getPrivKey(const CKeyID &address, CKey &vchPrivKeyOut) const
TokenTransactionTableModel * getTokenTransactionTableModel()
const ::std::string & script() const
bool transactionCanBeAbandoned(uint256 hash) const
void newPossibleKeyChange(CWallet *wallet)
CAmount GetImmatureBalance() const
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
mapValue_t mapValue
Key/value map with information about the transaction.
void setTransactionFee(const CAmount &newFee)
bool CreateTransaction(const std::vector< CRecipient > &vecSend, CWalletTx &wtxNew, CReserveKey &reservekey, CAmount &nFeeRet, int &nChangePosInOut, std::string &strFailReason, const CCoinControl &coin_control, bool sign=true, CAmount nGasFee=0, bool hasSender=false)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
CAmount GetUnconfirmedWatchOnlyBalance() const
UnlockContext(WalletModel *wallet, bool valid, bool relock)
int64_t CAmount
Amount in lius (Can be negative)
QList< SendCoinsRecipient > getRecipients()
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
boost::signals2::signal< void(CCryptoKeyStore *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
void checkBalanceChanged()
CAmount getWatchBalance() const
int Height() const
Return the maximal height in the chain.
void push_back(const T &value)
unsigned int nTxConfirmTarget
bool AbandonTransaction(const uint256 &hashTx)
void UnlockCoin(const COutPoint &output)
bool signalRbf
Signal BIP-125 replace by fee.
CAmount cachedImmatureBalance
ChangeType
General change type (added, updated, removed).
bool isSpent(const COutPoint &outpoint) const
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet, txnouttype *typeRet)
void reassignAmounts(int nChangePosRet)
bool TransactionCanBeAbandoned(const uint256 &hashTx) const
Return whether transaction can be abandoned.
const ::payments::Output & outputs(int index) const
uint256 uint256S(const char *str)
An encapsulated public key.
UI model for the transaction table of a wallet.
bool getPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
CAmount GetBalance() const
TokenItemModel * getTokenItemModel()
TokenItemModel * tokenItemModel
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl &coinControl)
static bool verifyExpired(const payments::PaymentDetails &requestDetails)
bool EraseDestData(const CTxDestination &dest, const std::string &key)
Erases a destination data tuple in the store and on disk.
std::string ToString() const
bool GetKey(const CKeyID &address, CKey &keyOut) const override
OptionsModel * optionsModel
CAmount cachedWatchOnlyBalance
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
CScript GetScriptForDestination(const CTxDestination &dest)
TransactionTableModel * getTransactionTableModel()
EncryptionStatus cachedEncryptionStatus
An outpoint - a combination of a transaction hash and an index n into its vout.
bool transactionCanBeBumped(uint256 hash) const
void CopyFrom(const UnlockContext &rhs)
bool restoreWallet(const QString &filename, const QString ¶m)
UI model for the transaction table of a wallet.
CTxDestination Get() const
inline::google::protobuf::uint64 amount() const
std::vector< CTokenInfo > getInvalidTokens()
void LockCoin(const COutPoint &output)
Qt model of the address book in the core.
CAmount getWatchImmatureBalance() const
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
A transaction with a bunch of additional info that only the owner cares about.
void encryptionStatusChanged(int status)
EncryptionStatus getEncryptionStatus() const
std::map< CTxDestination, std::vector< COutput > > ListCoins() const
Return list of available coins and locked coins grouped by non-change output address.
Qt model of the contract book in the core.
std::string GetRejectReason() const
CAmount GetWatchOnlyBalance() const
bool validateAddress(const QString &address)
WalletModel(const PlatformStyle *platformStyle, CWallet *wallet, OptionsModel *optionsModel, QObject *parent=0)
void updateWatchOnlyFlag(bool fHaveWatchonly)
CAmount cachedWatchOnlyStake
Capture information about block/transaction validation.
CReserveKey * getPossibleKeyChange()
bool isUnspentAddress(const std::string &address) const
CAmount cachedWatchUnconfBalance
bool fForceCheckBalanceChanged
CAmount GetImmatureWatchOnlyBalance() const
const CWalletTx * GetWalletTx(const uint256 &hash) const
CAmount cachedWatchImmatureBalance
RecentRequestsTableModel * getRecentRequestsTableModel()
boost::signals2::signal< void(CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)> NotifyAddressBookChanged
Address book entry changed.
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
void listLockedCoins(std::vector< COutPoint > &vOutpts)
A key allocated from the key pool.
Interface from Qt to configuration data structure for Fabcoin client.
boost::signals2::signal< void(CWallet *wallet, const std::string &address, const std::string &label, const std::string &abi, ChangeType status)> NotifyContractBookChanged
Contract book entry changed.
Serialized script, used inside transaction inputs and outputs.
Interface to Fabcoin wallet from Qt view code.
bool RemoveTokenEntry(const uint256 &tokenHash, bool fFlushOnClose=true)
bool SignalsOptInRBF(const CTransaction &tx)
bool fWalletUnlockStakingOnly
CAmount getWatchStake() const
bool setWalletEncrypted(bool encrypted, const SecureString &passphrase)
void unlockCoin(COutPoint &output)
void message(const QString &title, const QString &message, unsigned int style)
A reference to a CKey: the Hash160 of its serialized public key.
CAmount cachedUnconfirmedBalance
bool haveWatchOnly() const
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
bool removeTokenEntry(const std::string &sHash)
std::unique_ptr< CConnman > g_connman
void notifyWatchonlyChanged(bool fHaveWatchonly)
Data model for a walletmodel transaction.
void coinsSent(CWallet *wallet, SendCoinsRecipient recipient, QByteArray transaction)
std::map< uint256, CWalletTx > mapWallet
CAmount getImmatureBalance() const
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
void checkTokenBalanceChanged()
AddressTableModel * addressTableModel
std::vector< std::string > GetDestValues(const std::string &prefix) const
Get all destination values matching a prefix.
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as HTML string (with unit)
const fs::path & GetDataDir(bool fNetSpecific)
bool IsLockedCoin(uint256 hash, unsigned int n) const
int64_t GetTime()
GetTimeMicros() and GetTimeMillis() both return the system time, but in different units...
struct evm_uint160be address(struct evm_env *env)
An encapsulated private key.
void updateContractBook(const QString &address, const QString &label, const QString &abi, int status)
virtual bool HaveWatchOnly(const CScript &dest) const override
void checkTokenBalanceChanged()
bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
Adds a destination data tuple to the store, and saves it to disk.
bool getDefaultWalletRbf() const
void listCoins(std::map< QString, std::vector< COutput > > &mapCoins) const
bool IsSpent(const uint256 &hash, unsigned int n) const
Outpoint is spent if any non-conflicted transaction spends it:
bool BackupWallet(const std::string &strDest)
void updateConfirmations()
bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
CWalletTx * getTransaction()
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
bool addTokenEntry(const CTokenInfo &token)
CAmount getWatchUnconfirmedBalance() 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)
bool addTokenTxEntry(const CTokenTx &tokenTx, bool fFlushOnClose=true)
bool AddTokenTxEntry(const CTokenTx &tokenTx, bool fFlushOnClose=true)
int getDefaultConfirmTarget() const
void updateConfirmations()
void pollBalanceChanged()
CAmount getBalance(const CCoinControl *coinControl=nullptr) const
OptionsModel * getOptionsModel()
bool Unlock(const SecureString &strWalletPassphrase)
void subscribeToCoreSignals()
std::vector< std::pair< std::string, std::string > > vOrderForm
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey, CConnman *connman, CValidationState &state)
Call after CreateTransaction unless you want to abort.