 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
36 #include <QTextStream>
40 transactionTableModel(0),
41 cachedBalance(0), cachedUnconfirmedBalance(0), spendableBalance(0), cachedImmatureBalance(0), cachedWatchOnlyBalance(0),
42 cachedWatchUnconfBalance(0), cachedWatchImmatureBalance(0),
43 cachedEncryptionStatus(Unencrypted),
44 cachedNumBlocks(0), cachedTxLocks(0),
150 static uint8_t waitLonger = 0;
198 CAmount newSpendableBalance = newBalance - newImmatureBalance;
199 static bool stkEnabled =
false;
201 CAmount newWatchOnlyBalance = 0;
202 CAmount newWatchUnconfBalance = 0;
203 CAmount newWatchImmatureBalance = 0;
230 Q_EMIT
balanceChanged(newBalance, newUnconfirmedBalance, newImmatureBalance,
231 newWatchOnlyBalance, newWatchUnconfBalance, newWatchImmatureBalance);
265 bool valid = (
regex_match(address.toStdString(), std::regex(
"[a-zA-z0-9]+")))&&(address.length()==99||address.length()==110);
266 return valid||addressParsed.
IsValid();
272 QList<SendCoinsRecipient> recipients = transaction.
getRecipients();
273 std::vector<std::pair<CScript, CAmount> > vecSend;
275 if (recipients.empty()) {
283 QSet<QString> setAddress;
295 setAddress.insert(rcp.
address);
299 vecSend.push_back(std::pair<CScript, CAmount>(scriptPubKey, rcp.
amount));
304 if (setAddress.size() != nAddresses) {
310 if (total > nBalance) {
319 std::string strFailReason;
324 bool fCreated =
wallet->
CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, strFailReason, coinControl, recipients[0].inputType, recipients[0].useSwiftTX);
328 if ((total + nFeeRequired) > nBalance) {
331 Q_EMIT
message(tr(
"Send Coins"), QString::fromStdString(strFailReason),
346 QByteArray transaction_array;
348 std::string stealthAddr = transaction.
getRecipients()[0].address.toStdString();
440 return error(
"ERROR: Failed to backup wallet!");
449 qDebug() <<
"NotifyKeyStoreStatusChanged";
450 QMetaObject::invokeMethod(walletmodel,
"updateStatus", Qt::QueuedConnection);
455 QString strAddress = QString::fromStdString(
CBitcoinAddress(address).ToString());
456 QString strLabel = QString::fromStdString(label);
457 QString strPurpose = QString::fromStdString(purpose);
459 qDebug() <<
"NotifyAddressBookChanged : " + strAddress +
" " + strLabel +
" isMine=" + QString::number(isMine) +
" purpose=" + strPurpose +
" status=" + QString::number(status);
460 QMetaObject::invokeMethod(walletmodel,
"updateAddressBook", Qt::QueuedConnection,
461 Q_ARG(QString, strAddress),
462 Q_ARG(QString, strLabel),
464 Q_ARG(QString, strPurpose),
469 static bool fQueueNotifications =
false;
470 static std::vector<std::pair<uint256, ChangeType> > vQueueNotifications;
473 if (fQueueNotifications) {
474 vQueueNotifications.push_back(std::make_pair(hash, status));
478 QString strHash = QString::fromStdString(hash.
GetHex());
480 qDebug() <<
"NotifyTransactionChanged : " + strHash +
" status= " + QString::number(status);
481 QMetaObject::invokeMethod(walletmodel,
"updateTransaction", Qt::QueuedConnection
485 static void ShowProgress(
WalletModel* walletmodel,
const std::string& title,
int nProgress)
488 QMetaObject::invokeMethod(walletmodel,
"showProgress", Qt::QueuedConnection,
489 Q_ARG(QString, QString::fromStdString(title)),
490 Q_ARG(
int, nProgress));
493 static void NotifyWatchonlyChanged(
WalletModel* walletmodel,
bool fHaveWatchonly)
495 QMetaObject::invokeMethod(walletmodel,
"updateWatchOnlyFlag", Qt::QueuedConnection,
496 Q_ARG(
bool, fHaveWatchonly));
499 static void NotifyWalletBacked(
WalletModel* model,
const bool& fSuccess,
const std::string& filename)
502 std::string title =
"Backup ";
506 title +=
"Successful: ";
507 method = CClientUIInterface::MessageBoxFlags::MSG_INFORMATION;
509 message =
"There was an error trying to save the wallet data to ";
511 method = CClientUIInterface::MessageBoxFlags::MSG_ERROR;
514 message +=
_(filename.data());
517 QMetaObject::invokeMethod(model,
"message", Qt::QueuedConnection,
518 Q_ARG(QString, QString::fromStdString(title)),
519 Q_ARG(QString, QString::fromStdString(message)),
520 Q_ARG(
unsigned int, (
unsigned int)method));
600 for (
const COutPoint& outpoint : vOutpoints) {
603 if (nDepth < 0)
continue;
605 vOutputs.push_back(out);
618 std::vector<COutput> vCoins;
622 std::vector<COutPoint> vLockedCoins;
626 for (
const COutPoint& outpoint : vLockedCoins) {
629 if (nDepth < 0)
continue;
632 vCoins.push_back(out);
635 for (
const COutput& out : vCoins) {
646 mapCoins[QString::fromStdString(
CBitcoinAddress(address).ToString())].push_back(out);
678 for (
const PAIRTYPE(std::string, std::string) & item2 : item.second.
destdata)
679 if (item2.first.size() > 2 && item2.first.substr(0, 2) ==
"rr")
680 vReceiveRequests.push_back(item2.second);
687 std::stringstream ss;
689 std::string
key =
"rr" + ss.str();
692 if (sRequest.empty())
734 GeneratePrcycoins(fGenerate,
wallet, nGenProcLimit);
735 if (
false && fGenerate) {
738 GeneratePrcycoins(fGenerate,
wallet, nGenProcLimit);
759 std::vector<std::map<QString, QString> > txs;
764 for (std::map<uint256, CWalletTx>::iterator tx = txMap.begin(); tx != txMap.end(); ++tx) {
765 if (tx->second.GetDepthInMainChain() > 0) {
786 if (prevout.
n < prev.
vout.size()) {
791 totalIn += decodedAmount;
803 if (vamount != 0 && firstOut == 0) {
806 totalamount+=vamount;
813 std::map<QString, QString> txData;
822 txData[
"confirmations"] = QString::number(0);
829 txData[
"address"]=
"";
835 if (!txData[
"address"].length()) {
836 txData[
"address"] = QString(TxRecord.address.c_str());
841 txData[
"id"] = QString(TxRecord.hash.GetHex().c_str());
843 switch (TxRecord.type) {
845 txData[
"type"] = QString(
"Mined");
850 txData[
"type"] = QString(
"Payment to yourself");
856 txData[
"type"] = QString(
"Sent");
863 txData[
"type"] = QString(
"Received");
866 txData[
"type"] = QString(
"Minted");
870 txData[
"type"] = QString(
"Masternode");
874 txData[
"type"] = QString(
"Payment");
884 QList<QString> AddressBookData;
885 for (std::map<CTxDestination, CAddressBookData>::iterator address = mapAddressBook.begin(); address != mapAddressBook.end(); ++address) {
886 QString desc = address->second.name.c_str();
889 AddressBookData.push_front(desc +
" | " + addressHash);
891 AddressBookData.push_front(addressHash);
894 return AddressBookData;
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
void LockCoin(COutPoint &output)
An input of a transaction.
std::atomic< bool > fImporting
void newPossibleKeyChange(CWallet *wallet)
OptionsModel * getOptionsModel()
bool isMine(CBitcoinAddress address)
std::vector< std::map< QString, QString > > getTXs(CWallet *wallet)
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
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.
CAmount cachedWatchOnlyBalance
void listLockedCoins(std::vector< COutPoint > &vOutpts)
void updateConfirmations()
CFeeRate minRelayTxFee
Fees smaller than this (in duffs) are considered zero fee (for relaying and mining) We are ~100 times...
bool fWalletUnlockStakingOnly
std::map< uint256, CWalletTx > mapWallet
@ TransactionCommitFailed
std::map< std::string, std::string > addrToTxHashMap
TransactionTableModel * transactionTableModel
Interface to Bitcoin wallet from Qt view code.
CAmount GetImmatureBalance() const
bool RevealTxOutAmount(const CTransaction &tx, const CTxOut &out, CAmount &amount, CKey &) const
std::vector< Match > regex_match(const std::string &password, const std::vector< std::pair< RegexTag, std::regex >> ®exen)
isminetype IsMine(const CTxIn &txin) const
Keystore which keeps the private keys encrypted.
std::string GetHex() const
@ TransactionCreationFailed
CChain chainActive
The currently-connected chain of blocks.
CScript GetScriptForDestination(const CTxDestination &dest)
StakingStatusError getStakingStatusError(QString &)
base58-encoded PRCY addresses.
Qt model of the address book in the core.
bool backupWallet(const QString &filename)
AddressTableModel * getAddressTableModel()
bool Unlock(const SecureString &strWalletPassphrase, bool anonimizeOnly=false)
int nHeight
height of the entry in the chain. The genesis block has height 0
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
A key allocated from the key pool.
@ AmountWithFeeExceedsBalance
CAmount GetSpendableBalance()
CAmount cachedWatchUnconfBalance
bool isShutdownRequested()
bool IsImportingOrReindexing()
void requireUnlock(AskPassphraseDialog::Context context)
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
bool checkBalanceChanged()
bool IsSpent(const uint256 &hash, unsigned int n)
Outpoint is spent if any non-conflicted transaction spends it:
bool CreateTransaction(CScript scriptPubKey, int64_t nValue, CWalletTx &wtxNew, CReserveKey &reservekey, int64_t &nFeeRet, std::string &strFailReason, const CCoinControl *coinControl)
TransactionTableModel * getTransactionTableModel()
#define TRY_LOCK(cs, name)
A reference to a CKey: the Hash160 of its serialized public key.
unsigned int getTransactionSize()
bool getPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
std::string ToString() const
CAmount cachedUnconfirmedBalance
CAmount cachedImmatureBalance
void UnlockCoin(COutPoint &output)
QAbstractTableModel * txTableModel
UI model for a transaction.
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.
std::map< QString, QString > getTx(CWallet *wallet, CWalletTx tx)
boost::signals2::signal< void(const bool &fSuccess, const std::string &filename)> NotifyWalletBacked
notify wallet file backed up
AddressTableModel * addressTableModel
boost::signals2::signal< void(CCryptoKeyStore *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
RecursiveMutex cs_main
Global state.
CAmount cachedWatchImmatureBalance
Interface from Qt to configuration data structure for Bitcoin client.
CAmount GetUnconfirmedWatchOnlyBalance() const
void emitBalanceChanged()
CAmount getLockedBalance() const
void lockCoin(COutPoint &output)
void unsubscribeFromCoreSignals()
bool validateAddress(const QString &address)
void updateWatchOnlyFlag(bool fHaveWatchonly)
An output of a transaction.
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result.
bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
std::vector< CTxOut > vout
void message(const QString &title, const QString &message, unsigned int style)
void setTransactionFee(const CAmount &newFee)
bool IsLockedCoin(uint256 hash, unsigned int n) const
bool lockForStakingOnly(const SecureString &passPhrase=SecureString())
CAmount MinimumStakeAmount() const
QList< QString > getAddressBookData(CWallet *wallet)
bool IsChange(const CTxOut &txout) const
CAmount GetLockedCoins() const
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
const CWalletTx * GetWalletTx(const uint256 &hash) const
bool isLockedCoin(uint256 hash, unsigned int n) const
void generateCoins(bool fGenerate, int nGenProcLimit)
EncryptionStatus getEncryptionStatus() const
#define PAIRTYPE(t1, t2)
This is needed because the foreach macro can't get over the comma in pair<t1, t2>
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
CAmount getWatchImmatureBalance() const
int64_t CAmount
Amount in PRCY (Can be negative)
void loadReceiveRequests(std::vector< std::string > &vReceiveRequests)
CAmount getSpendableBalance() const
256-bit unsigned big integer.
CAmount GetUnconfirmedBalance() const
bool getSeedPhrase(std::string &phrase) const
Serialized script, used inside transaction inputs and outputs.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
bool SendToStealthAddress(const std::string &stealthAddr, CAmount nValue, CWalletTx &wtxNew, bool fUseIX=false, int ringSize=5)
CAmount GetWatchOnlyBalance() const
CAmount GetImmatureWatchOnlyBalance() const
bool isSpent(const COutPoint &outpoint) const
CWalletTx * getTransaction()
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
int Height() const
Return the maximal height in the chain.
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string.
bool EncryptWallet(const SecureString &strWalletPassphrase)
ChangeType
General change type (added, updated, removed).
int64_t nLastCoinStakeSearchInterval
UI model for the transaction table of a wallet.
An encapsulated public key.
bool AvailableCoins(std::vector< COutput > &vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL, bool fIncludeZeroValue=false, AvailableCoinsType nCoinType=ALL_COINS, bool fUseIX=false)
populate vCoins with vector of available COutputs.
void listCoins(std::map< QString, std::vector< COutput > > &mapCoins) const
bool setWalletEncrypted(bool encrypted, const SecureString &passphrase)
void unlockCoin(COutPoint &output)
OptionsModel * optionsModel
void getOutputs(const std::vector< COutPoint > &vOutpoints, std::vector< COutput > &vOutputs)
static QList< TransactionRecord > decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx)
Decompose CWallet transaction to model transaction records.
An encapsulated private key.
CAmount getMinStakingAmount() const
std::atomic< bool > fReindex
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
bool fForceCheckBalanceChanged
A transaction with a bunch of additional info that only the owner cares about.
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl *coinControl=NULL)
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
GetPubKey implementation that also checks the mapHdPubKeys.
const CChainParams & Params()
Return the currently selected parameters.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
bool GetSeedPhrase(std::string &phrase)
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString(), bool stakingOnly=false)
CAmount getWatchBalance() const
COutPoint findMyOutPoint(const CTxIn &txin) const
QString dateTimeStr(const QDateTime &date)
void subscribeToCoreSignals()
const uint256 & GetHash() const
bool BackupWallet(const CWallet &wallet, const fs::path &strDest, bool fEnableCustom)
An outpoint - a combination of a transaction hash and an index n into its vout.
CAmount getWatchUnconfirmedBalance() const
bool haveWatchOnly() const
bool EraseDestData(const CTxDestination &dest, const std::string &key)
Erases a destination data tuple in the store and on disk.
bool isStakingOnlyUnlocked()
UnlockContext(bool valid, bool relock)
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
CAmount GetFee(size_t size) const
void balanceChanged(const CAmount &balance, const CAmount &unconfirmedBalance, const CAmount &immatureBalance, const CAmount &watchOnlyBalance, const CAmount &watchUnconfBalance, const CAmount &watchImmatureBalance)
QList< SendCoinsRecipient > getRecipients()
void CopyFrom(const UnlockContext &rhs)
QAbstractTableModel * getTxTableModel()
The block chain is a tree shaped structure starting with the genesis block at the root,...
virtual bool HaveWatchOnly(const CScript &dest) const
CAmount getUnconfirmedBalance() const
CTxDestination Get() const
void ListLockedCoins(std::vector< COutPoint > &vOutpts)
void pollBalanceChanged()
CAmount getImmatureBalance() const
MessageBoxFlags
Flags for CClientUIInterface::ThreadSafeMessageBox.
UnlockContext requestUnlock(AskPassphraseDialog::Context context, bool relock=false)
WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent=0)
Data model for a walletmodel transaction.
void notifyWatchonlyChanged(bool fHaveWatchonly)
EncryptionStatus cachedEncryptionStatus
std::map< CTxDestination, CAddressBookData > mapAddressBook
CAmount getBalance(const CCoinControl *coinControl=NULL) const
bool error(const char *fmt, const Args &... args)
CReserveKey * getPossibleKeyChange()
int walletUnlockCountStatus
void encryptionStatusChanged(int status)