From 378c1244d34af8a8b97f17e149ed958b3781689f Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 26 Jan 2018 11:46:37 +0100 Subject: [PATCH 1/6] Version 1.2.0.1 --- install-dependencies.sh | 2 +- sono-qt.pro | 2 +- src/clientversion.h | 2 +- src/main.cpp | 12 +- src/net.cpp | 2 +- src/qt/bitcoingui.cpp | 87 +-- src/qt/bitcoingui.h | 8 +- src/qt/forms/aboutdialog.ui | 4 +- src/qt/forms/blockbrowser.ui | 31 +- src/qt/forms/coincontroldialog.ui | 7 + src/qt/forms/overviewpage.ui | 15 +- src/qt/guiutil.cpp | 6 + src/qt/guiutil.h | 2 + src/qt/overviewpage.cpp | 2 +- src/qt/transactiondesc.cpp | 4 +- src/version.h | 2 +- src/wallet.cpp | 10 +- src/wallet.h | 18 +- src/wallet.h.Lt6884 | 1014 ----------------------------- src/wallet.h.hE6884 | 1014 ----------------------------- src/wallet.h.pc6884 | 1014 ----------------------------- 21 files changed, 120 insertions(+), 3138 deletions(-) delete mode 100644 src/wallet.h.Lt6884 delete mode 100644 src/wallet.h.hE6884 delete mode 100644 src/wallet.h.pc6884 diff --git a/install-dependencies.sh b/install-dependencies.sh index d6a6d49..e9c8853 100644 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -16,7 +16,7 @@ echo "nproc: $NPROC" ################################################################# # Install all necessary packages for building Bhcoin # ################################################################# -sudo apt-get install -y qt4-qmake libqt4-dev libminiupnpc-dev libdb++-dev libdb-dev libcrypto++-dev libqrencode-dev libboost-all-dev build-essential libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev libssl-dev libdb++-dev libssl-dev ufw git software-properties-common +sudo apt-get install -y qt4-qmake libqt4-dev libminiupnpc-dev libdb++-dev libdb-dev libcrypto++-dev libqrencode-dev libboost-all-dev build-essential libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev libssl-dev libdb++-dev libssl-dev ufw git software-properties-common qt5-default sudo add-apt-repository -y ppa:bitcoin/bitcoin sudo apt-get update sudo apt-get install -y libdb4.8-dev libdb4.8++-dev diff --git a/sono-qt.pro b/sono-qt.pro index bd30786..f727b20 100644 --- a/sono-qt.pro +++ b/sono-qt.pro @@ -1,6 +1,6 @@ TEMPLATE = app TARGET = SONO-qt -VERSION = 1.2.0.0 +VERSION = 1.2.0.1 INCLUDEPATH += src src/json src/qt src/qt/plugins/mrichtexteditor DEFINES += ENABLE_WALLET DEFINES += BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE diff --git a/src/clientversion.h b/src/clientversion.h index 36a5ca5..c9b3064 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -9,7 +9,7 @@ #define CLIENT_VERSION_MAJOR 1 #define CLIENT_VERSION_MINOR 2 #define CLIENT_VERSION_REVISION 0 -#define CLIENT_VERSION_BUILD 0 +#define CLIENT_VERSION_BUILD 1 // Set to true for release, false for prerelease or test build #define CLIENT_VERSION_IS_RELEASE true diff --git a/src/main.cpp b/src/main.cpp index 3aa9b79..7149777 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2431,7 +2431,7 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c CBlockIndex *pindex = pindexBest; if(IsProofOfStake() && pindex != NULL){ if(pindex->GetBlockHash() == hashPrevBlock){ - CAmount masternodePaymentAmount = GetMasternodePayment(pindex->nHeight+1, vtx[1].GetValueOut()); + int64_t masternodePaymentAmount = GetMasternodePayment(pindex->nHeight+1, vtx[1].GetValueOut()); bool fIsInitialDownload = IsInitialBlockDownload(); // If we don't already have its previous block, skip masternode payment step @@ -3395,12 +3395,20 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, return false; } + int64_t nTime; CAddress addrMe; CAddress addrFrom; uint64_t nNonce = 1; vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe; + bool badVersion = false; + if (pfrom->nVersion < MIN_PEER_PROTO_VERSION) + badVersion = true; + if (nBestHeight >= 250000 && pfrom->nVersion < 70004) + badVersion = true; + + if (badVersion) { // disconnect from peers older than this proto version LogPrintf("partner %s using obsolete version %i; disconnecting\n", pfrom->addr.ToString(), pfrom->nVersion); @@ -4287,7 +4295,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) int64_t GetMasternodePayment(int nHeight, int64_t blockValue) { - int64_t ret = blockValue * 0.25; // 25% + int64_t ret = blockValue * 0.25; //25% for masternodes return ret; } diff --git a/src/net.cpp b/src/net.cpp index 6a2848c..2b3453c 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -30,7 +30,7 @@ using namespace std; using namespace boost; -static const int MAX_OUTBOUND_CONNECTIONS = 12; // Reduced to 12 connections. ( Manual edit to suit your needs) +static const int MAX_OUTBOUND_CONNECTIONS = 32; // Increased to 32 connections. ( Manual edit to suit your needs) bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false); diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 6963b96..112ce2b 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -38,7 +38,7 @@ #include "messagepage.h" #include "blockbrowser.h" #include "forms/sidetoolbar.h" - +#include "transactiondesc.h" #ifdef Q_OS_MAC #include "macdockiconhandler.h" @@ -93,7 +93,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): { //resize(970, 570); resize(1080, 662); - setWindowTitle(tr("SONO") + " - " + tr("Wallet")); + setWindowTitle(tr("Project SONO") + " - " + tr("Wallet")); #ifndef Q_OS_MAC qApp->setWindowIcon(QIcon(":icons/bitcoin")); setWindowIcon(QIcon(":icons/bitcoin")); @@ -121,8 +121,8 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): // Create tabs overviewPage = new OverviewPage(); // Create trading page - // tradingDialogPage = new tradingDialog(this); - // tradingDialogPage->setObjectName("tradingDialog"); + // tradingDialogPage = new tradingDialog(this); + // tradingDialogPage->setObjectName("tradingDialog"); transactionsPage = new QWidget(this); QVBoxLayout *vbox = new QVBoxLayout(); @@ -144,9 +144,9 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): messagePage = new MessagePage(this); - //clientcontrolPage = new ClientControlPage(this); + // clientcontrolPage = new ClientControlPage(this); - //multisigPage = new MultisigDialog(this); + // multisigPage = new MultisigDialog(this); centralStackedWidget = new QStackedWidget(this); @@ -159,9 +159,9 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): centralStackedWidget->addWidget(masternodeManagerPage); centralStackedWidget->addWidget(messagePage); centralStackedWidget->addWidget(blockBrowser); - // centralStackedWidget->addWidget(clientcontrolPage); - //TradingAction->setChecked(true); - // centralStackedWidget->addWidget(tradingDialogPage); + // centralStackedWidget->addWidget(clientcontrolPage); + // TradingAction->setChecked(true); + // centralStackedWidget->addWidget(tradingDialogPage); QWidget *centralWidget = new QWidget(); QVBoxLayout *centralLayout = new QVBoxLayout(centralWidget); @@ -201,15 +201,13 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): frameBlocksLayout->addStretch(); frameBlocksLayout->addWidget(labelBlocksIcon); frameBlocksLayout->addStretch(); - //frameBlocksLayout->addWidget(netLabel); - //frameBlocksLayout->addStretch(); - + toolbar->addWidget(frameBlocks); if (GetBoolArg("-staking", true)) { QTimer *timerStakingIcon = new QTimer(labelStakingIcon); connect(timerStakingIcon, SIGNAL(timeout()), this, SLOT(updateStakingIcon())); - timerStakingIcon->start(20 * 1000); + timerStakingIcon->start(30 * 1000); updateStakingIcon(); } @@ -234,9 +232,6 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): statusBar()->addWidget(progressBarLabel); statusBar()->addWidget(progressBar); - statusBar()->addPermanentWidget(frameBlocks); - statusBar()->setObjectName("statusBar"); - statusBar()->setStyleSheet("#statusBar { color: #101010; background-color: #f9f9f9); }"); syncIconMovie = new QMovie(fUseBlackTheme ? ":/movies/update_spinner_black" : ":/movies/update_spinner", "mng", this); @@ -458,11 +453,8 @@ void BitcoinGUI::createToolBars() fLiteMode = GetBoolArg("-litemode", false); toolbar = new QToolBar(tr("Tabs toolbar")); - toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - toolbar->setContextMenuPolicy(Qt::PreventContextMenu); - toolbar->setObjectName("tabs"); toolbar->setStyleSheet("QToolButton { color: #101010; font-weight:bold;} QToolButton:hover { background-color: #c1cbcb } QToolButton:checked { background-color: #c1cbcb } QToolButton:pressed { background-color: none } #tabs { color: #101010; background-color: #f9f9f9); }"); @@ -486,7 +478,7 @@ void BitcoinGUI::createToolBars() toolbar->addAction(historyAction); toolbar->addAction(addressBookAction); toolbar->addAction(masternodeManagerAction); - // toolbar->addAction(clientcontrolAction); + // toolbar->addAction(clientcontrolAction); toolbar->addAction(blockAction); if (!fLiteMode){ @@ -756,49 +748,59 @@ void BitcoinGUI::setNumBlocks(int count) statusBar()->setVisible(true); } -void BitcoinGUI::message(const QString &title, const QString &message, bool modal, unsigned int style) +void BitcoinGUI::message(const QString& title, const QString& message, unsigned int style, bool* ret) { - QString strTitle = tr("SONO") + " - "; + QString strTitle = tr("LUX Core"); // default title // Default to information icon int nMBoxIcon = QMessageBox::Information; int nNotifyIcon = Notificator::Information; - // Check for usage of predefined title - switch (style) { - case CClientUIInterface::MSG_ERROR: - strTitle += tr("Error"); - break; - case CClientUIInterface::MSG_WARNING: - strTitle += tr("Warning"); - break; - case CClientUIInterface::MSG_INFORMATION: - strTitle += tr("Information"); - break; - default: - strTitle += title; // Use supplied title + QString msgType; + + // Prefer supplied title over style based title + if (!title.isEmpty()) { + msgType = title; + } else { + switch (style) { + case CClientUIInterface::MSG_ERROR: + msgType = tr("Error"); + break; + case CClientUIInterface::MSG_WARNING: + msgType = tr("Warning"); + break; + case CClientUIInterface::MSG_INFORMATION: + msgType = tr("Information"); + break; + default: + break; + } } + // Append title to "LUX - " + if (!msgType.isEmpty()) + strTitle += " - " + msgType; // Check for error/warning icon if (style & CClientUIInterface::ICON_ERROR) { nMBoxIcon = QMessageBox::Critical; nNotifyIcon = Notificator::Critical; - } - else if (style & CClientUIInterface::ICON_WARNING) { + } else if (style & CClientUIInterface::ICON_WARNING) { nMBoxIcon = QMessageBox::Warning; nNotifyIcon = Notificator::Warning; } // Display message - if (modal) { + if (style & CClientUIInterface::MODAL) { // Check for buttons, use OK as default, if none was supplied QMessageBox::StandardButton buttons; if (!(buttons = (QMessageBox::StandardButton)(style & CClientUIInterface::BTN_MASK))) buttons = QMessageBox::Ok; - QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons); - mBox.exec(); - } - else + showNormalIfMinimized(); + QMessageBox mBox((QMessageBox::Icon)nMBoxIcon, strTitle, message, buttons, this); + int r = mBox.exec(); + if (ret != NULL) + *ret = r == QMessageBox::Ok; + } else notificator->notify((Notificator::Class)nNotifyIcon, strTitle, message); } @@ -1271,6 +1273,7 @@ void BitcoinGUI::updateStakingIcon() } } + void BitcoinGUI::detectShutdown() { if (ShutdownRequested()) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index b6bd769..338a5a8 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -158,7 +158,7 @@ public slots: @param[in] style style definitions (icon and used buttons - buttons only for message boxes) @see CClientUIInterface::MessageBoxFlags */ - void message(const QString &title, const QString &message, bool modal, unsigned int style); + void message(const QString& title, const QString& message, unsigned int style, bool* ret = NULL); /** Asks the user whether to pay the transaction fee or to cancel the transaction. It is currently not possible to pass a return value to another thread through BlockingQueuedConnection, so an indirected pointer is used. @@ -204,11 +204,13 @@ private slots: /** Handle tray icon clicked */ void trayIconActivated(QSystemTrayIcon::ActivationReason reason); #endif - /** Show incoming transaction notification for new transactions. - + /* + Show incoming transaction notification for new transactions. The new items are those between start and end inclusive, under the given parent item. */ + void incomingTransaction(const QModelIndex & parent, int start, int end); + void incomingMessage(const QModelIndex & parent, int start, int end); /** Encrypt the wallet */ void encryptWallet(); diff --git a/src/qt/forms/aboutdialog.ui b/src/qt/forms/aboutdialog.ui index 5ad4ce3..065d9be 100644 --- a/src/qt/forms/aboutdialog.ui +++ b/src/qt/forms/aboutdialog.ui @@ -63,7 +63,7 @@ IBeamCursor - 3.0.4 + 1.2.0.1 Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse @@ -93,7 +93,7 @@ Copyright © 2009-2017 The Bitcoin developers Copyright © 2012-2017 The NovaCoin developers -Copyright © 2017 The SONO developers +Copyright © 2018 The Project SONO developers Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse diff --git a/src/qt/forms/blockbrowser.ui b/src/qt/forms/blockbrowser.ui index 6de5a7a..68b7258 100644 --- a/src/qt/forms/blockbrowser.ui +++ b/src/qt/forms/blockbrowser.ui @@ -657,22 +657,16 @@ 510 - 390 - 120 - 60 + 400 + 141 + 31 - - - 0 - 0 - - - - - 120 - 60 - + + + 75 + true + background:lightgrey; @@ -680,15 +674,6 @@ Update Statistics - - false - - - false - - - false - diff --git a/src/qt/forms/coincontroldialog.ui b/src/qt/forms/coincontroldialog.ui index 6cb437b..40a683d 100644 --- a/src/qt/forms/coincontroldialog.ui +++ b/src/qt/forms/coincontroldialog.ui @@ -425,6 +425,13 @@ + + + + (1 locked) + + + diff --git a/src/qt/forms/overviewpage.ui b/src/qt/forms/overviewpage.ui index d64ea15..7f94db4 100644 --- a/src/qt/forms/overviewpage.ui +++ b/src/qt/forms/overviewpage.ui @@ -7,7 +7,7 @@ 0 0 972 - 594 + 618 @@ -149,6 +149,9 @@ 0 + + 0 + Qt::Horizontal @@ -303,12 +306,12 @@ - - - Spendable: + + + 0 - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + Qt::Horizontal diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 8b1c84f..03a8495 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -460,6 +460,12 @@ void HelpMessageBox::showOrPrint() #endif } +void setClipboard(const QString& str) +{ + QApplication::clipboard()->setText(str, QClipboard::Clipboard); + QApplication::clipboard()->setText(str, QClipboard::Selection); +} + void SetBlackThemeQSS(QApplication& app) { app.setStyleSheet("QWidget { background: rgb(41,44,48); }" diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 1e71e6c..494f415 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -48,6 +48,8 @@ namespace GUIUtil */ void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole); + void setClipboard(const QString& str); + /** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when no suffix is provided by the user. diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index ed9f148..22e067a 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -37,7 +37,7 @@ OverviewPage::OverviewPage(QWidget *parent) : { ui->setupUi(this); - ui->frameluxsend->setVisible(true); // Hide darksend features + ui->frameluxsend->setVisible(false); // Hide darksend features //QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture); //ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 5a21218..ec9d0d8 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -199,7 +199,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco strHTML += "" + tr("Debit") + ": " + BitcoinUnits::formatWithUnit(unit, -wallet->GetDebit(txin)) + "
"; BOOST_FOREACH(const CTxOut& txout, wtx.vout) if (wallet->IsMine(txout)) - strHTML += "" + tr("Credit") + ": " + BitcoinUnits::formatWithUnit(unit, wallet->GetCredit(txout)) + "
"; + strHTML += "" + tr("Credit - mixed (DEBUG)") + ": " + BitcoinUnits::formatWithUnit(unit, wallet->GetCredit(txout)) + "
"; } } @@ -216,7 +216,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco strHTML += "" + tr("Transaction ID") + ": " + TransactionRecord::formatSubTxId(wtx.GetHash(), rec->idx) + "
"; if (wtx.IsCoinBase() || wtx.IsCoinStake()) - strHTML += "
" + tr("Generated coins must mature 188 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, its state will change to \"not accepted\" and it won't be spendable. This may occasionally happen if another node generates a block within a few seconds of yours.") + "
"; + strHTML += "
" + tr("Generated coins must mature 51 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, its state will change to \"not accepted\" and it won't be spendable. This may occasionally happen if another node generates a block within a few seconds of yours.") + "
"; // // Debug view diff --git a/src/version.h b/src/version.h index ba60500..3ba9689 100644 --- a/src/version.h +++ b/src/version.h @@ -30,7 +30,7 @@ static const int DATABASE_VERSION = 70510; // network protocol versioning // -static const int PROTOCOL_VERSION = 70004; +static const int PROTOCOL_VERSION = 70005; // intial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209; diff --git a/src/wallet.cpp b/src/wallet.cpp index 395845e..05f1ab4 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -34,7 +34,7 @@ int64_t nReserveBalance = 0; int64_t nMinimumInputValue = 0; //static unsigned int GetStakeSplitAge() { return 9 * 24 * 60 * 60; } -static int64_t GetStakeCombineThreshold() { return 500 * COIN; } +static int64_t GetStakeCombineThreshold() { return 1000 * COIN; } int64_t gcd(int64_t n,int64_t m) { return m == 0 ? n : gcd(m, n % m); } static uint64_t CoinWeightCost(const COutput &out) @@ -1204,7 +1204,7 @@ int64_t CWallet::GetBalanceNoLocks() const return nTotal; } -CAmount CWallet::GetAnonymizedBalance() const +int64_t CWallet::GetAnonymizedBalance() const { int64_t nTotal = 0; { @@ -1277,7 +1277,7 @@ double CWallet::GetAverageAnonymizedRounds() const return fTotal/fCount; } -CAmount CWallet::GetNormalizedAnonymizedBalance() const +int64_t CWallet::GetNormalizedAnonymizedBalance() const { int64_t nTotal = 0; @@ -1311,7 +1311,7 @@ CAmount CWallet::GetNormalizedAnonymizedBalance() const return nTotal; } -CAmount CWallet::GetDenominatedBalance(bool onlyDenom, bool onlyUnconfirmed) const +int64_t CWallet::GetDenominatedBalance(bool onlyDenom, bool onlyUnconfirmed) const { int64_t nTotal = 0; { @@ -3488,7 +3488,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int // Masternode Payments int payments = 1; // start masternode payments - bool bMasterNodePayment = true; // note was false, set true to test + bool bMasterNodePayment = false; // note was false, set true to test if ( Params().NetworkID() == CChainParams::TESTNET ){ if (GetTime() > START_MASTERNODE_PAYMENTS_TESTNET ){ diff --git a/src/wallet.h b/src/wallet.h index d41269b..b61bb25 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -102,7 +102,7 @@ class CWallet : public CCryptoKeyStore, public CWalletInterface private: bool SelectCoinsForStaking(int64_t nTargetValue, unsigned int nSpendTime, std::set >& setCoinsRet, int64_t& nValueRet) const; //bool SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, std::set >& setCoinsRet, int64_t& nValueRet, const CCoinControl *coinControl=NULL) const; - bool SelectCoins(CAmount nTargetValue, unsigned int nSpendTime, std::set >& setCoinsRet, int64_t& nValueRet, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX = false) const; + bool SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, std::set >& setCoinsRet, int64_t& nValueRet, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX = false) const; CWalletDB *pwalletdbEncryption; // the current wallet version: clients below this version are not able to load the wallet @@ -145,6 +145,14 @@ class CWallet : public CCryptoKeyStore, public CWalletInterface uint32_t nStealth, nFoundStealth; // for reporting, zero before use + //MultiSend + std::vector > vMultiSend; + bool fMultiSendStake; + bool fMultiSendMasternodeReward; + bool fMultiSendNotify; + std::string strMultiSendChangeAddress; + int nLastMultiSendHeight; + std::vector vDisabledAddresses; typedef std::map MasterKeyMap; MasterKeyMap mapMasterKeys; @@ -206,7 +214,7 @@ class CWallet : public CCryptoKeyStore, public CWalletInterface void UnlockCoin(COutPoint& output); void UnlockAllCoins(); void ListLockedCoins(std::vector& vOutpts); - CAmount GetTotalValue(std::vector vCoins); + int64_t GetTotalValue(std::vector vCoins); // keystore implementation // Generate a new key @@ -265,10 +273,10 @@ class CWallet : public CCryptoKeyStore, public CWalletInterface int64_t GetStake() const; int64_t GetNewMint() const; - CAmount GetAnonymizedBalance() const; + int64_t GetAnonymizedBalance() const; double GetAverageAnonymizedRounds() const; - CAmount GetNormalizedAnonymizedBalance() const; - CAmount GetDenominatedBalance(bool onlyDenom=true, bool onlyUnconfirmed=false) const; + int64_t GetNormalizedAnonymizedBalance() const; + int64_t GetDenominatedBalance(bool onlyDenom=true, bool onlyUnconfirmed=false) const; bool CreateTransaction(const std::vector >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, int32_t& nChangePos, std::string& strFailReason, const CCoinControl *coinControl=NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX=false); bool CreateTransaction(CScript scriptPubKey, int64_t nValue, std::string& sNarr, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl *coinControl=NULL); diff --git a/src/wallet.h.Lt6884 b/src/wallet.h.Lt6884 deleted file mode 100644 index 7b48271..0000000 --- a/src/wallet.h.Lt6884 +++ /dev/null @@ -1,1014 +0,0 @@ -// Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2012 The Bitcoin developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_WALLET_H -#define BITCOIN_WALLET_H - -#include "walletdb.h" - -#include -#include - -#include - -#include "crypter.h" -#include "main.h" -#include "key.h" -#include "keystore.h" -#include "script.h" -#include "ui_interface.h" -#include "util.h" -#include "stealth.h" - -// Settings -extern int64_t nTransactionFee; -extern int64_t nReserveBalance; -extern int64_t nMinimumInputValue; -extern bool fWalletUnlockStakingOnly; -extern bool fConfChange; - -class CAccountingEntry; -class CCoinControl; -class CWalletTx; -class CReserveKey; -class COutput; -class CWalletDB; - -typedef std::map StealthKeyMetaMap; -typedef std::map mapValue_t; - -/** (client) version numbers for particular wallet features */ -enum WalletFeature -{ - FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getinfo's clientversion output) - - FEATURE_WALLETCRYPT = 40000, // wallet encryption input < comprepubkey to avoid exploit - FEATURE_COMPRPUBKEY = 60000, // compressed public keys - - FEATURE_LATEST = 60000 -}; - -enum AvailableCoinsType -{ - ALL_COINS = 1, - ONLY_DENOMINATED = 2, - ONLY_NONDENOMINATED = 3, - ONLY_NONDENOMINATED_NOTMN = 4 // ONLY_NONDENOMINATED and not 1000 SONO at the same time -}; - -/** IsMine() return codes */ -enum isminetype -{ - ISMINE_NO = 0, - ISMINE_WATCH_ONLY = 1, - ISMINE_SPENDABLE = 2, - ISMINE_ALL = ISMINE_WATCH_ONLY | ISMINE_SPENDABLE -}; - - -/** A key pool entry */ -class CKeyPool -{ -public: - int64_t nTime; - CPubKey vchPubKey; - - CKeyPool() - { - nTime = GetTime(); - } - - CKeyPool(const CPubKey& vchPubKeyIn) - { - nTime = GetTime(); - vchPubKey = vchPubKeyIn; - } - - IMPLEMENT_SERIALIZE - ( - if (!(nType & SER_GETHASH)) - READWRITE(nVersion); - READWRITE(nTime); - READWRITE(vchPubKey); - ) -}; - -/** A CWallet is an extension of a keystore, which also maintains a set of transactions and balances, - * and provides the ability to create new transactions. - */ -class CWallet : public CCryptoKeyStore, public CWalletInterface -{ -private: - bool SelectCoinsForStaking(int64_t nTargetValue, unsigned int nSpendTime, std::set >& setCoinsRet, int64_t& nValueRet) const; - //bool SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, std::set >& setCoinsRet, int64_t& nValueRet, const CCoinControl *coinControl=NULL) const; - bool SelectCoins(CAmount nTargetValue, unsigned int nSpendTime, std::set >& setCoinsRet, int64_t& nValueRet, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX = false) const; - CWalletDB *pwalletdbEncryption; - - // the current wallet version: clients below this version are not able to load the wallet - int nWalletVersion; - - // the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded - int nWalletMaxVersion; - -public: - /// Main wallet lock. - /// This lock protects all the fields added by CWallet - /// except for: - /// fFileBacked (immutable after instantiation) - /// strWalletFile (immutable after instantiation) - mutable CCriticalSection cs_wallet; - - bool SelectCoinsDark(int64_t nValueMin, int64_t nValueMax, std::vector& setCoinsRet, int64_t& nValueRet, int nDarksendRoundsMin, int nDarksendRoundsMax) const; - bool SelectCoinsByDenominations(int nDenom, int64_t nValueMin, int64_t nValueMax, std::vector& setCoinsRet, vector& vCoins, int64_t& nValueRet, int nDarksendRoundsMin, int nDarksendRoundsMax); - bool SelectCoinsDarkDenominated(int64_t nTargetValue, std::vector& setCoinsRet, int64_t& nValueRet) const; - bool SelectCoinsMasternode(CTxIn& vin, int64_t& nValueRet, CScript& pubScript) const; - bool HasCollateralInputs() const; - bool IsCollateralAmount(int64_t nInputAmount) const; - int CountInputsWithAmount(int64_t nInputAmount); - - bool SelectCoinsCollateral(std::vector& setCoinsRet, int64_t& nValueRet) const ; - bool SelectCoinsWithoutDenomination(int64_t nTargetValue, std::set >& setCoinsRet, int64_t& nValueRet) const; - bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx); - - bool fFileBacked; - bool fWalletUnlockAnonymizeOnly; - std::string strWalletFile; - - std::set setKeyPool; - std::map mapKeyMetadata; - - std::set stealthAddresses; - StealthKeyMetaMap mapStealthKeyMeta; - - int nLastFilteredHeight; - - uint32_t nStealth, nFoundStealth; // for reporting, zero before use - - - typedef std::map MasterKeyMap; - MasterKeyMap mapMasterKeys; - unsigned int nMasterKeyMaxID; - - std::map mapMyAdrenalineNodes; - bool AddAdrenalineNodeConfig(CAdrenalineNodeConfig nodeConfig); - - CWallet() - { - SetNull(); - } - CWallet(std::string strWalletFileIn) - { - SetNull(); - - strWalletFile = strWalletFileIn; - fFileBacked = true; - } - - void SetNull() - { - nWalletVersion = FEATURE_BASE; - nWalletMaxVersion = FEATURE_BASE; - fFileBacked = false; - nMasterKeyMaxID = 0; - pwalletdbEncryption = NULL; - nOrderPosNext = 0; - nTimeFirstKey = 0; - nLastFilteredHeight = 0; - fWalletUnlockAnonymizeOnly = false; - } - - std::map mapWallet; - int64_t nOrderPosNext; - std::map mapRequestCount; - - std::map mapAddressBook; - - CPubKey vchDefaultKey; - - std::set setLockedCoins; - - int64_t nTimeFirstKey; - - // check whether we are allowed to upgrade (or already support) to the named feature - bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; } - - void AvailableCoinsForStaking(std::vector& vCoins, unsigned int nSpendTime) const; - void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX = false) const; - void AvailableCoinsMN(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX = false) const; - bool SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, int64_t& nValueRet) const; - bool SelectCoinsMinConfByCoinAge(int64_t nTargetValue, unsigned int nSpendTime, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, int64_t& nValueRet) const; - - bool IsSpent(const uint256& hash, unsigned int n) const; - - bool IsLockedCoin(uint256 hash, unsigned int n) const; - void LockCoin(COutPoint& output); - void UnlockCoin(COutPoint& output); - void UnlockAllCoins(); - void ListLockedCoins(std::vector& vOutpts); - CAmount GetTotalValue(std::vector vCoins); - - // keystore implementation - // Generate a new key - CPubKey GenerateNewKey(); - // Adds a key to the store, and saves it to disk. - bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey); - // Adds a key to the store, without saving it to disk (used by LoadWallet) - bool LoadKey(const CKey& key, const CPubKey &pubkey) { return CCryptoKeyStore::AddKeyPubKey(key, pubkey); } - // Load metadata (used by LoadWallet) - bool LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &metadata); - - bool LoadMinVersion(int nVersion) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; } - - // Adds an encrypted key to the store, and saves it to disk. - bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret); - // Adds an encrypted key to the store, without saving it to disk (used by LoadWallet) - bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret); - bool AddCScript(const CScript& redeemScript); - bool LoadCScript(const CScript& redeemScript); - - bool Lock(); - bool Unlock(const SecureString& strWalletPassphrase, bool anonimizeOnly = false); - bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase); - bool EncryptWallet(const SecureString& strWalletPassphrase); - - void GetKeyBirthTimes(std::map &mapKeyBirth) const; - - - /** Increment the next transaction order id - @return next transaction order id - */ - int64_t IncOrderPosNext(CWalletDB *pwalletdb = NULL); - - typedef std::pair TxPair; - typedef std::multimap TxItems; - - /** Get the wallet's activity log - @return multimap of ordered transactions and accounting entries - @warning Returned pointers are *only* valid within the scope of passed acentries - */ - TxItems OrderedTxItems(std::list& acentries, std::string strAccount = ""); - - void MarkDirty(); - bool AddToWallet(const CWalletTx& wtxIn); - void SyncTransaction(const CTransaction& tx, const CBlock* pblock, bool fConnect = true); - bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate); - void EraseFromWallet(const uint256 &hash); - void WalletUpdateSpent(const CTransaction& prevout, bool fBlock = false); - int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); - void ReacceptWalletTransactions(); - void ResendWalletTransactions(bool fForce = false); - int64_t GetBalance() const; - int64_t GetBalanceNoLocks() const; - int64_t GetUnconfirmedBalance() const; - int64_t GetImmatureBalance() const; - int64_t GetStake() const; - int64_t GetNewMint() const; - - CAmount GetAnonymizedBalance() const; - double GetAverageAnonymizedRounds() const; - CAmount GetNormalizedAnonymizedBalance() const; - CAmount GetDenominatedBalance(bool onlyDenom=true, bool onlyUnconfirmed=false) const; - - bool CreateTransaction(const std::vector >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, int32_t& nChangePos, std::string& strFailReason, const CCoinControl *coinControl=NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX=false); - bool CreateTransaction(CScript scriptPubKey, int64_t nValue, std::string& sNarr, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl *coinControl=NULL); - bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey); - - uint64_t GetStakeWeight() const; - bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64_t nSearchInterval, int64_t nFees, CTransaction& txNew, CKey& key); - - std::string SendMoney(CScript scriptPubKey, int64_t nValue, std::string& sNarr, CWalletTx& wtxNew, bool fAskFee=false); - std::string SendMoneyToDestination(const CTxDestination &address, int64_t nValue, std::string& sNarr, CWalletTx& wtxNew, bool fAskFee=false); - - bool NewStealthAddress(std::string& sError, std::string& sLabel, CStealthAddress& sxAddr); - bool AddStealthAddress(CStealthAddress& sxAddr); - bool UnlockStealthAddresses(const CKeyingMaterial& vMasterKeyIn); - bool UpdateStealthAddress(std::string &addr, std::string &label, bool addIfNotExist); - - bool CreateStealthTransaction(CScript scriptPubKey, int64_t nValue, std::vector& P, std::vector& narr, std::string& sNarr, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl* coinControl=NULL); - std::string SendStealthMoney(CScript scriptPubKey, int64_t nValue, std::vector& P, std::vector& narr, std::string& sNarr, CWalletTx& wtxNew, bool fAskFee=false); - bool SendStealthMoneyToDestination(CStealthAddress& sxAddress, int64_t nValue, std::string& sNarr, CWalletTx& wtxNew, std::string& sError, bool fAskFee=false); - bool FindStealthTransactions(const CTransaction& tx, mapValue_t& mapNarr); - - std::string PrepareluxsendDenominate(int minRounds, int maxRounds); - bool CreateCollateralTransaction(CTransaction& txCollateral, std::string strReason); - bool ConvertList(std::vector vCoins, std::vector& vecAmounts); - - bool NewKeyPool(); - bool TopUpKeyPool(unsigned int nSize = 0); - int64_t AddReserveKey(const CKeyPool& keypool); - void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool); - void KeepKey(int64_t nIndex); - void ReturnKey(int64_t nIndex); - bool GetKeyFromPool(CPubKey &key); - int64_t GetOldestKeyPoolTime(); - void GetAllReserveKeys(std::set& setAddress) const; - - std::set< std::set > GetAddressGroupings(); - std::map GetAddressBalances(); - - - bool IsDenominated(const CTxIn &txin) const; - - bool IsDenominated(const CTransaction& tx) const - { - /* - Return false if ANY inputs are non-denom - */ - bool ret = true; - BOOST_FOREACH(const CTxIn& txin, tx.vin) - { - if(!IsDenominated(txin)) { - ret = false; - } - } - return ret; - } - - bool IsDenominatedAmount(int64_t nInputAmount) const; - - - bool IsMine(const CTxIn& txin) const; - int64_t GetDebit(const CTxIn& txin) const; - bool IsMine(const CTxOut& txout) const - { - return ::IsMine(*this, txout.scriptPubKey); - } - int64_t GetCredit(const CTxOut& txout) const - { - if (!MoneyRange(txout.nValue)) - throw std::runtime_error("CWallet::GetCredit() : value out of range"); - return (IsMine(txout) ? txout.nValue : 0); - } - bool IsChange(const CTxOut& txout) const; - int64_t GetChange(const CTxOut& txout) const - { - if (!MoneyRange(txout.nValue)) - throw std::runtime_error("CWallet::GetChange() : value out of range"); - return (IsChange(txout) ? txout.nValue : 0); - } - bool IsMine(const CTransaction& tx) const - { - BOOST_FOREACH(const CTxOut& txout, tx.vout) - if (IsMine(txout) && txout.nValue >= nMinimumInputValue) - return true; - return false; - } - bool IsFromMe(const CTransaction& tx) const - { - return (GetDebit(tx) > 0); - } - int64_t GetDebit(const CTransaction& tx) const - { - int64_t nDebit = 0; - BOOST_FOREACH(const CTxIn& txin, tx.vin) - { - nDebit += GetDebit(txin); - if (!MoneyRange(nDebit)) - throw std::runtime_error("CWallet::GetDebit() : value out of range"); - } - return nDebit; - } - int64_t GetCredit(const CTransaction& tx) const - { - int64_t nCredit = 0; - BOOST_FOREACH(const CTxOut& txout, tx.vout) - { - nCredit += GetCredit(txout); - if (!MoneyRange(nCredit)) - throw std::runtime_error("CWallet::GetCredit() : value out of range"); - } - return nCredit; - } - int64_t GetChange(const CTransaction& tx) const - { - int64_t nChange = 0; - BOOST_FOREACH(const CTxOut& txout, tx.vout) - { - nChange += GetChange(txout); - if (!MoneyRange(nChange)) - throw std::runtime_error("CWallet::GetChange() : value out of range"); - } - return nChange; - } - void SetBestChain(const CBlockLocator& loc); - - DBErrors LoadWallet(bool& fFirstRunRet); - - bool SetAddressBookName(const CTxDestination& address, const std::string& strName); - - bool DelAddressBookName(const CTxDestination& address); - - void UpdatedTransaction(const uint256 &hashTx); - - void Inventory(const uint256 &hash) - { - { - LOCK(cs_wallet); - std::map::iterator mi = mapRequestCount.find(hash); - if (mi != mapRequestCount.end()) - (*mi).second++; - } - } - - unsigned int GetKeyPoolSize() - { - AssertLockHeld(cs_wallet); // setKeyPool - return setKeyPool.size(); - } - - bool SetDefaultKey(const CPubKey &vchPubKey); - - // signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower - bool SetMinVersion(enum WalletFeature, CWalletDB* pwalletdbIn = NULL, bool fExplicit = false); - - // change which version we're allowed to upgrade to (note that this does not immediately imply upgrading to that format) - bool SetMaxVersion(int nVersion); - - // get the current wallet format (the oldest client version guaranteed to understand this wallet) - int GetVersion() { LOCK(cs_wallet); return nWalletVersion; } - - void FixSpentCoins(int& nMismatchSpent, int64_t& nBalanceInQuestion, bool fCheckOnly = false); - void DisableTransaction(const CTransaction &tx); - - /** Address book entry changed. - * @note called with lock cs_wallet held. - */ - boost::signals2::signal NotifyAddressBookChanged; - - /** Wallet transaction added, removed or updated. - * @note called with lock cs_wallet held. - */ - boost::signals2::signal NotifyTransactionChanged; -}; - -/** A key allocated from the key pool. */ -class CReserveKey -{ -protected: - CWallet* pwallet; - int64_t nIndex; - CPubKey vchPubKey; -public: - CReserveKey(CWallet* pwalletIn) - { - nIndex = -1; - pwallet = pwalletIn; - } - - ~CReserveKey() - { - ReturnKey(); - } - - void ReturnKey(); - bool GetReservedKey(CPubKey &pubkey); - void KeepKey(); -}; - - -typedef std::map mapValue_t; - - -static void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue) -{ - if (!mapValue.count("n")) - { - nOrderPos = -1; // TODO: calculate elsewhere - return; - } - nOrderPos = atoi64(mapValue["n"].c_str()); -} - - -static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue) -{ - if (nOrderPos == -1) - return; - mapValue["n"] = i64tostr(nOrderPos); -} - - -/** A transaction with a bunch of additional info that only the owner cares about. - * It includes any unrecorded transactions needed to link it back to the block chain. - */ -class CWalletTx : public CMerkleTx -{ -private: - const CWallet* pwallet; - -public: - std::vector vtxPrev; - mapValue_t mapValue; - std::vector > vOrderForm; - unsigned int fTimeReceivedIsTxTime; - unsigned int nTimeReceived; // time received by this node - unsigned int nTimeSmart; - char fFromMe; - std::string strFromAccount; - std::vector vfSpent; // which outputs are already spent - int64_t nOrderPos; // position in ordered transaction list - - // memory only - mutable bool fDebitCached; - mutable bool fCreditCached; - mutable bool fAvailableCreditCached; - mutable bool fChangeCached; - mutable int64_t nDebitCached; - mutable int64_t nCreditCached; - mutable int64_t nAvailableCreditCached; - mutable int64_t nChangeCached; - - CWalletTx() - { - Init(NULL); - } - - CWalletTx(const CWallet* pwalletIn) - { - Init(pwalletIn); - } - - CWalletTx(const CWallet* pwalletIn, const CMerkleTx& txIn) : CMerkleTx(txIn) - { - Init(pwalletIn); - } - - CWalletTx(const CWallet* pwalletIn, const CTransaction& txIn) : CMerkleTx(txIn) - { - Init(pwalletIn); - } - - void Init(const CWallet* pwalletIn) - { - pwallet = pwalletIn; - vtxPrev.clear(); - mapValue.clear(); - vOrderForm.clear(); - fTimeReceivedIsTxTime = false; - nTimeReceived = 0; - nTimeSmart = 0; - fFromMe = false; - strFromAccount.clear(); - vfSpent.clear(); - fDebitCached = false; - fCreditCached = false; - fAvailableCreditCached = false; - fChangeCached = false; - nDebitCached = 0; - nCreditCached = 0; - nAvailableCreditCached = 0; - nChangeCached = 0; - nOrderPos = -1; - } - - IMPLEMENT_SERIALIZE - ( - CWalletTx* pthis = const_cast(this); - if (fRead) - pthis->Init(NULL); - char fSpent = false; - - if (!fRead) - { - pthis->mapValue["fromaccount"] = pthis->strFromAccount; - - std::string str; - BOOST_FOREACH(char f, vfSpent) - { - str += (f ? '1' : '0'); - if (f) - fSpent = true; - } - pthis->mapValue["spent"] = str; - - WriteOrderPos(pthis->nOrderPos, pthis->mapValue); - - if (nTimeSmart) - pthis->mapValue["timesmart"] = strprintf("%u", nTimeSmart); - } - - nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion,ser_action); - READWRITE(vtxPrev); - READWRITE(mapValue); - READWRITE(vOrderForm); - READWRITE(fTimeReceivedIsTxTime); - READWRITE(nTimeReceived); - READWRITE(fFromMe); - READWRITE(fSpent); - - if (fRead) - { - pthis->strFromAccount = pthis->mapValue["fromaccount"]; - - if (mapValue.count("spent")) - BOOST_FOREACH(char c, pthis->mapValue["spent"]) - pthis->vfSpent.push_back(c != '0'); - else - pthis->vfSpent.assign(vout.size(), fSpent); - - ReadOrderPos(pthis->nOrderPos, pthis->mapValue); - - pthis->nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(pthis->mapValue["timesmart"]) : 0; - } - - pthis->mapValue.erase("fromaccount"); - pthis->mapValue.erase("version"); - pthis->mapValue.erase("spent"); - pthis->mapValue.erase("n"); - pthis->mapValue.erase("timesmart"); - ) - - // marks certain txout's as spent - // returns true if any update took place - bool UpdateSpent(const std::vector& vfNewSpent) - { - bool fReturn = false; - for (unsigned int i = 0; i < vfNewSpent.size(); i++) - { - if (i == vfSpent.size()) - break; - - if (vfNewSpent[i] && !vfSpent[i]) - { - vfSpent[i] = true; - fReturn = true; - fAvailableCreditCached = false; - } - } - return fReturn; - } - - // make sure balances are recalculated - void MarkDirty() - { - fCreditCached = false; - fAvailableCreditCached = false; - fDebitCached = false; - fChangeCached = false; - } - - void BindWallet(CWallet *pwalletIn) - { - pwallet = pwalletIn; - MarkDirty(); - } - - void MarkSpent(unsigned int nOut) - { - if (nOut >= vout.size()) - throw std::runtime_error("CWalletTx::MarkSpent() : nOut out of range"); - vfSpent.resize(vout.size()); - if (!vfSpent[nOut]) - { - vfSpent[nOut] = true; - fAvailableCreditCached = false; - } - } - - void MarkUnspent(unsigned int nOut) - { - if (nOut >= vout.size()) - throw std::runtime_error("CWalletTx::MarkUnspent() : nOut out of range"); - vfSpent.resize(vout.size()); - if (vfSpent[nOut]) - { - vfSpent[nOut] = false; - fAvailableCreditCached = false; - } - } - - bool IsSpent(unsigned int nOut) const - { - if (nOut >= vout.size()) - throw std::runtime_error("CWalletTx::IsSpent() : nOut out of range"); - if (nOut >= vfSpent.size()) - return false; - return (!!vfSpent[nOut]); - } - - int64_t IsDenominated() const - { - if (vin.empty()) - return 0; - return pwallet->IsDenominated(*this); - } - - int64_t GetDebit() const - { - if (vin.empty()) - return 0; - if (fDebitCached) - return nDebitCached; - nDebitCached = pwallet->GetDebit(*this); - fDebitCached = true; - return nDebitCached; - } - - int64_t GetCredit(bool fUseCache=true) const - { - // Must wait until coinbase is safely deep enough in the chain before valuing it - if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0) - return 0; - - // GetBalance can assume transactions in mapWallet won't change - if (fUseCache && fCreditCached) - return nCreditCached; - nCreditCached = pwallet->GetCredit(*this); - fCreditCached = true; - return nCreditCached; - } - - int64_t GetAvailableCredit(bool fUseCache=true) const - { - // Must wait until coinbase is safely deep enough in the chain before valuing it - if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0) - return 0; - - if (fUseCache && fAvailableCreditCached) - return nAvailableCreditCached; - - int64_t nCredit = 0; - for (unsigned int i = 0; i < vout.size(); i++) - { - if (!IsSpent(i)) - { - const CTxOut &txout = vout[i]; - nCredit += pwallet->GetCredit(txout); - if (!MoneyRange(nCredit)) - throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range"); - } - } - - nAvailableCreditCached = nCredit; - fAvailableCreditCached = true; - return nCredit; - } - - - int64_t GetChange() const - { - if (fChangeCached) - return nChangeCached; - nChangeCached = pwallet->GetChange(*this); - fChangeCached = true; - return nChangeCached; - } - - void GetAmounts(std::list >& listReceived, - std::list >& listSent, int64_t& nFee, std::string& strSentAccount) const; - - void GetAccountAmounts(const std::string& strAccount, int64_t& nReceived, - int64_t& nSent, int64_t& nFee) const; - - bool IsFromMe() const - { - return (GetDebit() > 0); - } - - bool IsTrusted() const - { - // Quick answer in most cases - if (!IsFinalTx(*this)) - return false; - int nDepth = GetDepthInMainChain(); - if (nDepth >= 1) - return true; - if (nDepth < 0) - return false; - if (fConfChange || !IsFromMe()) // using wtx's cached debit - return false; - - // If no confirmations but it's from us, we can still - // consider it confirmed if all dependencies are confirmed - std::map mapPrev; - std::vector vWorkQueue; - vWorkQueue.reserve(vtxPrev.size()+1); - vWorkQueue.push_back(this); - for (unsigned int i = 0; i < vWorkQueue.size(); i++) - { - const CMerkleTx* ptx = vWorkQueue[i]; - - if (!IsFinalTx(*ptx)) - return false; - int nPDepth = ptx->GetDepthInMainChain(); - if (nPDepth >= 1) - continue; - if (nPDepth < 0) - return false; - if (!pwallet->IsFromMe(*ptx)) - return false; - - if (mapPrev.empty()) - { - BOOST_FOREACH(const CMerkleTx& tx, vtxPrev) - mapPrev[tx.GetHash()] = &tx; - } - - BOOST_FOREACH(const CTxIn& txin, ptx->vin) - { - if (!mapPrev.count(txin.prevout.hash)) - return false; - vWorkQueue.push_back(mapPrev[txin.prevout.hash]); - } - } - - return true; - } - - bool WriteToDisk(); - - int64_t GetTxTime() const; - int GetRequestCount() const; - - void AddSupportingTransactions(CTxDB& txdb); - - bool AcceptWalletTransaction(CTxDB& txdb); - bool AcceptWalletTransaction(); - - void RelayWalletTransaction(CTxDB& txdb); - void RelayWalletTransaction(); -}; - - - - -class COutput -{ -public: - const CWalletTx *tx; - int i; - int nDepth; - bool fSpendable; - - COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn) - { - tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; - } - - std::string ToString() const - { - return strprintf("COutput(%s, %d, %d) [%s]", tx->GetHash().ToString(), i, nDepth, FormatMoney(tx->vout[i].nValue)); - } - - //Used with darksend. Will return fees, then denominations, everything else, then very small inputs that aren't fees - int Priority() const - { - if(tx->vout[i].nValue == DARKSEND_FEE) return -1000; - BOOST_FOREACH(int64_t d, darkSendDenominations) - if(tx->vout[i].nValue == d) return 900; - if(tx->vout[i].nValue < 1*COIN) return 1000; - - //nondenom return largest first - return -(tx->vout[i].nValue/COIN); - } - - void print() const - { - LogPrintf("%s\n", ToString().c_str()); - } -}; - - - - -/** Private key that includes an expiration date in case it never gets used. */ -class CWalletKey -{ -public: - CPrivKey vchPrivKey; - int64_t nTimeCreated; - int64_t nTimeExpires; - std::string strComment; - //// todo: add something to note what created it (user, getnewaddress, change) - //// maybe should have a map property map - - CWalletKey(int64_t nExpires=0) - { - nTimeCreated = (nExpires ? GetTime() : 0); - nTimeExpires = nExpires; - } - - IMPLEMENT_SERIALIZE - ( - if (!(nType & SER_GETHASH)) - READWRITE(nVersion); - READWRITE(vchPrivKey); - READWRITE(nTimeCreated); - READWRITE(nTimeExpires); - READWRITE(strComment); - ) -}; - - - - - - -/** Account information. - * Stored in wallet with key "acc"+string account name. - */ -class CAccount -{ -public: - CPubKey vchPubKey; - - CAccount() - { - SetNull(); - } - - void SetNull() - { - vchPubKey = CPubKey(); - } - - IMPLEMENT_SERIALIZE - ( - if (!(nType & SER_GETHASH)) - READWRITE(nVersion); - READWRITE(vchPubKey); - ) -}; - - - -/** Internal transfers. - * Database key is acentry. - */ -class CAccountingEntry -{ -public: - std::string strAccount; - int64_t nCreditDebit; - int64_t nTime; - std::string strOtherAccount; - std::string strComment; - mapValue_t mapValue; - int64_t nOrderPos; // position in ordered transaction list - uint64_t nEntryNo; - - CAccountingEntry() - { - SetNull(); - } - - void SetNull() - { - nCreditDebit = 0; - nTime = 0; - strAccount.clear(); - strOtherAccount.clear(); - strComment.clear(); - nOrderPos = -1; - } - - IMPLEMENT_SERIALIZE - ( - CAccountingEntry& me = *const_cast(this); - if (!(nType & SER_GETHASH)) - READWRITE(nVersion); - // Note: strAccount is serialized as part of the key, not here. - READWRITE(nCreditDebit); - READWRITE(nTime); - READWRITE(strOtherAccount); - - if (!fRead) - { - WriteOrderPos(nOrderPos, me.mapValue); - - if (!(mapValue.empty() && _ssExtra.empty())) - { - CDataStream ss(nType, nVersion); - ss.insert(ss.begin(), '\0'); - ss << mapValue; - ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end()); - me.strComment.append(ss.str()); - } - } - - READWRITE(strComment); - - size_t nSepPos = strComment.find("\0", 0, 1); - if (fRead) - { - me.mapValue.clear(); - if (std::string::npos != nSepPos) - { - CDataStream ss(std::vector(strComment.begin() + nSepPos + 1, strComment.end()), nType, nVersion); - ss >> me.mapValue; - me._ssExtra = std::vector(ss.begin(), ss.end()); - } - ReadOrderPos(me.nOrderPos, me.mapValue); - } - if (std::string::npos != nSepPos) - me.strComment.erase(nSepPos); - - me.mapValue.erase("n"); - ) - -private: - std::vector _ssExtra; -}; - -#endif diff --git a/src/wallet.h.hE6884 b/src/wallet.h.hE6884 deleted file mode 100644 index 7b48271..0000000 --- a/src/wallet.h.hE6884 +++ /dev/null @@ -1,1014 +0,0 @@ -// Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2012 The Bitcoin developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_WALLET_H -#define BITCOIN_WALLET_H - -#include "walletdb.h" - -#include -#include - -#include - -#include "crypter.h" -#include "main.h" -#include "key.h" -#include "keystore.h" -#include "script.h" -#include "ui_interface.h" -#include "util.h" -#include "stealth.h" - -// Settings -extern int64_t nTransactionFee; -extern int64_t nReserveBalance; -extern int64_t nMinimumInputValue; -extern bool fWalletUnlockStakingOnly; -extern bool fConfChange; - -class CAccountingEntry; -class CCoinControl; -class CWalletTx; -class CReserveKey; -class COutput; -class CWalletDB; - -typedef std::map StealthKeyMetaMap; -typedef std::map mapValue_t; - -/** (client) version numbers for particular wallet features */ -enum WalletFeature -{ - FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getinfo's clientversion output) - - FEATURE_WALLETCRYPT = 40000, // wallet encryption input < comprepubkey to avoid exploit - FEATURE_COMPRPUBKEY = 60000, // compressed public keys - - FEATURE_LATEST = 60000 -}; - -enum AvailableCoinsType -{ - ALL_COINS = 1, - ONLY_DENOMINATED = 2, - ONLY_NONDENOMINATED = 3, - ONLY_NONDENOMINATED_NOTMN = 4 // ONLY_NONDENOMINATED and not 1000 SONO at the same time -}; - -/** IsMine() return codes */ -enum isminetype -{ - ISMINE_NO = 0, - ISMINE_WATCH_ONLY = 1, - ISMINE_SPENDABLE = 2, - ISMINE_ALL = ISMINE_WATCH_ONLY | ISMINE_SPENDABLE -}; - - -/** A key pool entry */ -class CKeyPool -{ -public: - int64_t nTime; - CPubKey vchPubKey; - - CKeyPool() - { - nTime = GetTime(); - } - - CKeyPool(const CPubKey& vchPubKeyIn) - { - nTime = GetTime(); - vchPubKey = vchPubKeyIn; - } - - IMPLEMENT_SERIALIZE - ( - if (!(nType & SER_GETHASH)) - READWRITE(nVersion); - READWRITE(nTime); - READWRITE(vchPubKey); - ) -}; - -/** A CWallet is an extension of a keystore, which also maintains a set of transactions and balances, - * and provides the ability to create new transactions. - */ -class CWallet : public CCryptoKeyStore, public CWalletInterface -{ -private: - bool SelectCoinsForStaking(int64_t nTargetValue, unsigned int nSpendTime, std::set >& setCoinsRet, int64_t& nValueRet) const; - //bool SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, std::set >& setCoinsRet, int64_t& nValueRet, const CCoinControl *coinControl=NULL) const; - bool SelectCoins(CAmount nTargetValue, unsigned int nSpendTime, std::set >& setCoinsRet, int64_t& nValueRet, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX = false) const; - CWalletDB *pwalletdbEncryption; - - // the current wallet version: clients below this version are not able to load the wallet - int nWalletVersion; - - // the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded - int nWalletMaxVersion; - -public: - /// Main wallet lock. - /// This lock protects all the fields added by CWallet - /// except for: - /// fFileBacked (immutable after instantiation) - /// strWalletFile (immutable after instantiation) - mutable CCriticalSection cs_wallet; - - bool SelectCoinsDark(int64_t nValueMin, int64_t nValueMax, std::vector& setCoinsRet, int64_t& nValueRet, int nDarksendRoundsMin, int nDarksendRoundsMax) const; - bool SelectCoinsByDenominations(int nDenom, int64_t nValueMin, int64_t nValueMax, std::vector& setCoinsRet, vector& vCoins, int64_t& nValueRet, int nDarksendRoundsMin, int nDarksendRoundsMax); - bool SelectCoinsDarkDenominated(int64_t nTargetValue, std::vector& setCoinsRet, int64_t& nValueRet) const; - bool SelectCoinsMasternode(CTxIn& vin, int64_t& nValueRet, CScript& pubScript) const; - bool HasCollateralInputs() const; - bool IsCollateralAmount(int64_t nInputAmount) const; - int CountInputsWithAmount(int64_t nInputAmount); - - bool SelectCoinsCollateral(std::vector& setCoinsRet, int64_t& nValueRet) const ; - bool SelectCoinsWithoutDenomination(int64_t nTargetValue, std::set >& setCoinsRet, int64_t& nValueRet) const; - bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx); - - bool fFileBacked; - bool fWalletUnlockAnonymizeOnly; - std::string strWalletFile; - - std::set setKeyPool; - std::map mapKeyMetadata; - - std::set stealthAddresses; - StealthKeyMetaMap mapStealthKeyMeta; - - int nLastFilteredHeight; - - uint32_t nStealth, nFoundStealth; // for reporting, zero before use - - - typedef std::map MasterKeyMap; - MasterKeyMap mapMasterKeys; - unsigned int nMasterKeyMaxID; - - std::map mapMyAdrenalineNodes; - bool AddAdrenalineNodeConfig(CAdrenalineNodeConfig nodeConfig); - - CWallet() - { - SetNull(); - } - CWallet(std::string strWalletFileIn) - { - SetNull(); - - strWalletFile = strWalletFileIn; - fFileBacked = true; - } - - void SetNull() - { - nWalletVersion = FEATURE_BASE; - nWalletMaxVersion = FEATURE_BASE; - fFileBacked = false; - nMasterKeyMaxID = 0; - pwalletdbEncryption = NULL; - nOrderPosNext = 0; - nTimeFirstKey = 0; - nLastFilteredHeight = 0; - fWalletUnlockAnonymizeOnly = false; - } - - std::map mapWallet; - int64_t nOrderPosNext; - std::map mapRequestCount; - - std::map mapAddressBook; - - CPubKey vchDefaultKey; - - std::set setLockedCoins; - - int64_t nTimeFirstKey; - - // check whether we are allowed to upgrade (or already support) to the named feature - bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; } - - void AvailableCoinsForStaking(std::vector& vCoins, unsigned int nSpendTime) const; - void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX = false) const; - void AvailableCoinsMN(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX = false) const; - bool SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, int64_t& nValueRet) const; - bool SelectCoinsMinConfByCoinAge(int64_t nTargetValue, unsigned int nSpendTime, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, int64_t& nValueRet) const; - - bool IsSpent(const uint256& hash, unsigned int n) const; - - bool IsLockedCoin(uint256 hash, unsigned int n) const; - void LockCoin(COutPoint& output); - void UnlockCoin(COutPoint& output); - void UnlockAllCoins(); - void ListLockedCoins(std::vector& vOutpts); - CAmount GetTotalValue(std::vector vCoins); - - // keystore implementation - // Generate a new key - CPubKey GenerateNewKey(); - // Adds a key to the store, and saves it to disk. - bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey); - // Adds a key to the store, without saving it to disk (used by LoadWallet) - bool LoadKey(const CKey& key, const CPubKey &pubkey) { return CCryptoKeyStore::AddKeyPubKey(key, pubkey); } - // Load metadata (used by LoadWallet) - bool LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &metadata); - - bool LoadMinVersion(int nVersion) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; } - - // Adds an encrypted key to the store, and saves it to disk. - bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret); - // Adds an encrypted key to the store, without saving it to disk (used by LoadWallet) - bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret); - bool AddCScript(const CScript& redeemScript); - bool LoadCScript(const CScript& redeemScript); - - bool Lock(); - bool Unlock(const SecureString& strWalletPassphrase, bool anonimizeOnly = false); - bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase); - bool EncryptWallet(const SecureString& strWalletPassphrase); - - void GetKeyBirthTimes(std::map &mapKeyBirth) const; - - - /** Increment the next transaction order id - @return next transaction order id - */ - int64_t IncOrderPosNext(CWalletDB *pwalletdb = NULL); - - typedef std::pair TxPair; - typedef std::multimap TxItems; - - /** Get the wallet's activity log - @return multimap of ordered transactions and accounting entries - @warning Returned pointers are *only* valid within the scope of passed acentries - */ - TxItems OrderedTxItems(std::list& acentries, std::string strAccount = ""); - - void MarkDirty(); - bool AddToWallet(const CWalletTx& wtxIn); - void SyncTransaction(const CTransaction& tx, const CBlock* pblock, bool fConnect = true); - bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate); - void EraseFromWallet(const uint256 &hash); - void WalletUpdateSpent(const CTransaction& prevout, bool fBlock = false); - int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); - void ReacceptWalletTransactions(); - void ResendWalletTransactions(bool fForce = false); - int64_t GetBalance() const; - int64_t GetBalanceNoLocks() const; - int64_t GetUnconfirmedBalance() const; - int64_t GetImmatureBalance() const; - int64_t GetStake() const; - int64_t GetNewMint() const; - - CAmount GetAnonymizedBalance() const; - double GetAverageAnonymizedRounds() const; - CAmount GetNormalizedAnonymizedBalance() const; - CAmount GetDenominatedBalance(bool onlyDenom=true, bool onlyUnconfirmed=false) const; - - bool CreateTransaction(const std::vector >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, int32_t& nChangePos, std::string& strFailReason, const CCoinControl *coinControl=NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX=false); - bool CreateTransaction(CScript scriptPubKey, int64_t nValue, std::string& sNarr, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl *coinControl=NULL); - bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey); - - uint64_t GetStakeWeight() const; - bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64_t nSearchInterval, int64_t nFees, CTransaction& txNew, CKey& key); - - std::string SendMoney(CScript scriptPubKey, int64_t nValue, std::string& sNarr, CWalletTx& wtxNew, bool fAskFee=false); - std::string SendMoneyToDestination(const CTxDestination &address, int64_t nValue, std::string& sNarr, CWalletTx& wtxNew, bool fAskFee=false); - - bool NewStealthAddress(std::string& sError, std::string& sLabel, CStealthAddress& sxAddr); - bool AddStealthAddress(CStealthAddress& sxAddr); - bool UnlockStealthAddresses(const CKeyingMaterial& vMasterKeyIn); - bool UpdateStealthAddress(std::string &addr, std::string &label, bool addIfNotExist); - - bool CreateStealthTransaction(CScript scriptPubKey, int64_t nValue, std::vector& P, std::vector& narr, std::string& sNarr, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl* coinControl=NULL); - std::string SendStealthMoney(CScript scriptPubKey, int64_t nValue, std::vector& P, std::vector& narr, std::string& sNarr, CWalletTx& wtxNew, bool fAskFee=false); - bool SendStealthMoneyToDestination(CStealthAddress& sxAddress, int64_t nValue, std::string& sNarr, CWalletTx& wtxNew, std::string& sError, bool fAskFee=false); - bool FindStealthTransactions(const CTransaction& tx, mapValue_t& mapNarr); - - std::string PrepareluxsendDenominate(int minRounds, int maxRounds); - bool CreateCollateralTransaction(CTransaction& txCollateral, std::string strReason); - bool ConvertList(std::vector vCoins, std::vector& vecAmounts); - - bool NewKeyPool(); - bool TopUpKeyPool(unsigned int nSize = 0); - int64_t AddReserveKey(const CKeyPool& keypool); - void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool); - void KeepKey(int64_t nIndex); - void ReturnKey(int64_t nIndex); - bool GetKeyFromPool(CPubKey &key); - int64_t GetOldestKeyPoolTime(); - void GetAllReserveKeys(std::set& setAddress) const; - - std::set< std::set > GetAddressGroupings(); - std::map GetAddressBalances(); - - - bool IsDenominated(const CTxIn &txin) const; - - bool IsDenominated(const CTransaction& tx) const - { - /* - Return false if ANY inputs are non-denom - */ - bool ret = true; - BOOST_FOREACH(const CTxIn& txin, tx.vin) - { - if(!IsDenominated(txin)) { - ret = false; - } - } - return ret; - } - - bool IsDenominatedAmount(int64_t nInputAmount) const; - - - bool IsMine(const CTxIn& txin) const; - int64_t GetDebit(const CTxIn& txin) const; - bool IsMine(const CTxOut& txout) const - { - return ::IsMine(*this, txout.scriptPubKey); - } - int64_t GetCredit(const CTxOut& txout) const - { - if (!MoneyRange(txout.nValue)) - throw std::runtime_error("CWallet::GetCredit() : value out of range"); - return (IsMine(txout) ? txout.nValue : 0); - } - bool IsChange(const CTxOut& txout) const; - int64_t GetChange(const CTxOut& txout) const - { - if (!MoneyRange(txout.nValue)) - throw std::runtime_error("CWallet::GetChange() : value out of range"); - return (IsChange(txout) ? txout.nValue : 0); - } - bool IsMine(const CTransaction& tx) const - { - BOOST_FOREACH(const CTxOut& txout, tx.vout) - if (IsMine(txout) && txout.nValue >= nMinimumInputValue) - return true; - return false; - } - bool IsFromMe(const CTransaction& tx) const - { - return (GetDebit(tx) > 0); - } - int64_t GetDebit(const CTransaction& tx) const - { - int64_t nDebit = 0; - BOOST_FOREACH(const CTxIn& txin, tx.vin) - { - nDebit += GetDebit(txin); - if (!MoneyRange(nDebit)) - throw std::runtime_error("CWallet::GetDebit() : value out of range"); - } - return nDebit; - } - int64_t GetCredit(const CTransaction& tx) const - { - int64_t nCredit = 0; - BOOST_FOREACH(const CTxOut& txout, tx.vout) - { - nCredit += GetCredit(txout); - if (!MoneyRange(nCredit)) - throw std::runtime_error("CWallet::GetCredit() : value out of range"); - } - return nCredit; - } - int64_t GetChange(const CTransaction& tx) const - { - int64_t nChange = 0; - BOOST_FOREACH(const CTxOut& txout, tx.vout) - { - nChange += GetChange(txout); - if (!MoneyRange(nChange)) - throw std::runtime_error("CWallet::GetChange() : value out of range"); - } - return nChange; - } - void SetBestChain(const CBlockLocator& loc); - - DBErrors LoadWallet(bool& fFirstRunRet); - - bool SetAddressBookName(const CTxDestination& address, const std::string& strName); - - bool DelAddressBookName(const CTxDestination& address); - - void UpdatedTransaction(const uint256 &hashTx); - - void Inventory(const uint256 &hash) - { - { - LOCK(cs_wallet); - std::map::iterator mi = mapRequestCount.find(hash); - if (mi != mapRequestCount.end()) - (*mi).second++; - } - } - - unsigned int GetKeyPoolSize() - { - AssertLockHeld(cs_wallet); // setKeyPool - return setKeyPool.size(); - } - - bool SetDefaultKey(const CPubKey &vchPubKey); - - // signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower - bool SetMinVersion(enum WalletFeature, CWalletDB* pwalletdbIn = NULL, bool fExplicit = false); - - // change which version we're allowed to upgrade to (note that this does not immediately imply upgrading to that format) - bool SetMaxVersion(int nVersion); - - // get the current wallet format (the oldest client version guaranteed to understand this wallet) - int GetVersion() { LOCK(cs_wallet); return nWalletVersion; } - - void FixSpentCoins(int& nMismatchSpent, int64_t& nBalanceInQuestion, bool fCheckOnly = false); - void DisableTransaction(const CTransaction &tx); - - /** Address book entry changed. - * @note called with lock cs_wallet held. - */ - boost::signals2::signal NotifyAddressBookChanged; - - /** Wallet transaction added, removed or updated. - * @note called with lock cs_wallet held. - */ - boost::signals2::signal NotifyTransactionChanged; -}; - -/** A key allocated from the key pool. */ -class CReserveKey -{ -protected: - CWallet* pwallet; - int64_t nIndex; - CPubKey vchPubKey; -public: - CReserveKey(CWallet* pwalletIn) - { - nIndex = -1; - pwallet = pwalletIn; - } - - ~CReserveKey() - { - ReturnKey(); - } - - void ReturnKey(); - bool GetReservedKey(CPubKey &pubkey); - void KeepKey(); -}; - - -typedef std::map mapValue_t; - - -static void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue) -{ - if (!mapValue.count("n")) - { - nOrderPos = -1; // TODO: calculate elsewhere - return; - } - nOrderPos = atoi64(mapValue["n"].c_str()); -} - - -static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue) -{ - if (nOrderPos == -1) - return; - mapValue["n"] = i64tostr(nOrderPos); -} - - -/** A transaction with a bunch of additional info that only the owner cares about. - * It includes any unrecorded transactions needed to link it back to the block chain. - */ -class CWalletTx : public CMerkleTx -{ -private: - const CWallet* pwallet; - -public: - std::vector vtxPrev; - mapValue_t mapValue; - std::vector > vOrderForm; - unsigned int fTimeReceivedIsTxTime; - unsigned int nTimeReceived; // time received by this node - unsigned int nTimeSmart; - char fFromMe; - std::string strFromAccount; - std::vector vfSpent; // which outputs are already spent - int64_t nOrderPos; // position in ordered transaction list - - // memory only - mutable bool fDebitCached; - mutable bool fCreditCached; - mutable bool fAvailableCreditCached; - mutable bool fChangeCached; - mutable int64_t nDebitCached; - mutable int64_t nCreditCached; - mutable int64_t nAvailableCreditCached; - mutable int64_t nChangeCached; - - CWalletTx() - { - Init(NULL); - } - - CWalletTx(const CWallet* pwalletIn) - { - Init(pwalletIn); - } - - CWalletTx(const CWallet* pwalletIn, const CMerkleTx& txIn) : CMerkleTx(txIn) - { - Init(pwalletIn); - } - - CWalletTx(const CWallet* pwalletIn, const CTransaction& txIn) : CMerkleTx(txIn) - { - Init(pwalletIn); - } - - void Init(const CWallet* pwalletIn) - { - pwallet = pwalletIn; - vtxPrev.clear(); - mapValue.clear(); - vOrderForm.clear(); - fTimeReceivedIsTxTime = false; - nTimeReceived = 0; - nTimeSmart = 0; - fFromMe = false; - strFromAccount.clear(); - vfSpent.clear(); - fDebitCached = false; - fCreditCached = false; - fAvailableCreditCached = false; - fChangeCached = false; - nDebitCached = 0; - nCreditCached = 0; - nAvailableCreditCached = 0; - nChangeCached = 0; - nOrderPos = -1; - } - - IMPLEMENT_SERIALIZE - ( - CWalletTx* pthis = const_cast(this); - if (fRead) - pthis->Init(NULL); - char fSpent = false; - - if (!fRead) - { - pthis->mapValue["fromaccount"] = pthis->strFromAccount; - - std::string str; - BOOST_FOREACH(char f, vfSpent) - { - str += (f ? '1' : '0'); - if (f) - fSpent = true; - } - pthis->mapValue["spent"] = str; - - WriteOrderPos(pthis->nOrderPos, pthis->mapValue); - - if (nTimeSmart) - pthis->mapValue["timesmart"] = strprintf("%u", nTimeSmart); - } - - nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion,ser_action); - READWRITE(vtxPrev); - READWRITE(mapValue); - READWRITE(vOrderForm); - READWRITE(fTimeReceivedIsTxTime); - READWRITE(nTimeReceived); - READWRITE(fFromMe); - READWRITE(fSpent); - - if (fRead) - { - pthis->strFromAccount = pthis->mapValue["fromaccount"]; - - if (mapValue.count("spent")) - BOOST_FOREACH(char c, pthis->mapValue["spent"]) - pthis->vfSpent.push_back(c != '0'); - else - pthis->vfSpent.assign(vout.size(), fSpent); - - ReadOrderPos(pthis->nOrderPos, pthis->mapValue); - - pthis->nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(pthis->mapValue["timesmart"]) : 0; - } - - pthis->mapValue.erase("fromaccount"); - pthis->mapValue.erase("version"); - pthis->mapValue.erase("spent"); - pthis->mapValue.erase("n"); - pthis->mapValue.erase("timesmart"); - ) - - // marks certain txout's as spent - // returns true if any update took place - bool UpdateSpent(const std::vector& vfNewSpent) - { - bool fReturn = false; - for (unsigned int i = 0; i < vfNewSpent.size(); i++) - { - if (i == vfSpent.size()) - break; - - if (vfNewSpent[i] && !vfSpent[i]) - { - vfSpent[i] = true; - fReturn = true; - fAvailableCreditCached = false; - } - } - return fReturn; - } - - // make sure balances are recalculated - void MarkDirty() - { - fCreditCached = false; - fAvailableCreditCached = false; - fDebitCached = false; - fChangeCached = false; - } - - void BindWallet(CWallet *pwalletIn) - { - pwallet = pwalletIn; - MarkDirty(); - } - - void MarkSpent(unsigned int nOut) - { - if (nOut >= vout.size()) - throw std::runtime_error("CWalletTx::MarkSpent() : nOut out of range"); - vfSpent.resize(vout.size()); - if (!vfSpent[nOut]) - { - vfSpent[nOut] = true; - fAvailableCreditCached = false; - } - } - - void MarkUnspent(unsigned int nOut) - { - if (nOut >= vout.size()) - throw std::runtime_error("CWalletTx::MarkUnspent() : nOut out of range"); - vfSpent.resize(vout.size()); - if (vfSpent[nOut]) - { - vfSpent[nOut] = false; - fAvailableCreditCached = false; - } - } - - bool IsSpent(unsigned int nOut) const - { - if (nOut >= vout.size()) - throw std::runtime_error("CWalletTx::IsSpent() : nOut out of range"); - if (nOut >= vfSpent.size()) - return false; - return (!!vfSpent[nOut]); - } - - int64_t IsDenominated() const - { - if (vin.empty()) - return 0; - return pwallet->IsDenominated(*this); - } - - int64_t GetDebit() const - { - if (vin.empty()) - return 0; - if (fDebitCached) - return nDebitCached; - nDebitCached = pwallet->GetDebit(*this); - fDebitCached = true; - return nDebitCached; - } - - int64_t GetCredit(bool fUseCache=true) const - { - // Must wait until coinbase is safely deep enough in the chain before valuing it - if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0) - return 0; - - // GetBalance can assume transactions in mapWallet won't change - if (fUseCache && fCreditCached) - return nCreditCached; - nCreditCached = pwallet->GetCredit(*this); - fCreditCached = true; - return nCreditCached; - } - - int64_t GetAvailableCredit(bool fUseCache=true) const - { - // Must wait until coinbase is safely deep enough in the chain before valuing it - if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0) - return 0; - - if (fUseCache && fAvailableCreditCached) - return nAvailableCreditCached; - - int64_t nCredit = 0; - for (unsigned int i = 0; i < vout.size(); i++) - { - if (!IsSpent(i)) - { - const CTxOut &txout = vout[i]; - nCredit += pwallet->GetCredit(txout); - if (!MoneyRange(nCredit)) - throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range"); - } - } - - nAvailableCreditCached = nCredit; - fAvailableCreditCached = true; - return nCredit; - } - - - int64_t GetChange() const - { - if (fChangeCached) - return nChangeCached; - nChangeCached = pwallet->GetChange(*this); - fChangeCached = true; - return nChangeCached; - } - - void GetAmounts(std::list >& listReceived, - std::list >& listSent, int64_t& nFee, std::string& strSentAccount) const; - - void GetAccountAmounts(const std::string& strAccount, int64_t& nReceived, - int64_t& nSent, int64_t& nFee) const; - - bool IsFromMe() const - { - return (GetDebit() > 0); - } - - bool IsTrusted() const - { - // Quick answer in most cases - if (!IsFinalTx(*this)) - return false; - int nDepth = GetDepthInMainChain(); - if (nDepth >= 1) - return true; - if (nDepth < 0) - return false; - if (fConfChange || !IsFromMe()) // using wtx's cached debit - return false; - - // If no confirmations but it's from us, we can still - // consider it confirmed if all dependencies are confirmed - std::map mapPrev; - std::vector vWorkQueue; - vWorkQueue.reserve(vtxPrev.size()+1); - vWorkQueue.push_back(this); - for (unsigned int i = 0; i < vWorkQueue.size(); i++) - { - const CMerkleTx* ptx = vWorkQueue[i]; - - if (!IsFinalTx(*ptx)) - return false; - int nPDepth = ptx->GetDepthInMainChain(); - if (nPDepth >= 1) - continue; - if (nPDepth < 0) - return false; - if (!pwallet->IsFromMe(*ptx)) - return false; - - if (mapPrev.empty()) - { - BOOST_FOREACH(const CMerkleTx& tx, vtxPrev) - mapPrev[tx.GetHash()] = &tx; - } - - BOOST_FOREACH(const CTxIn& txin, ptx->vin) - { - if (!mapPrev.count(txin.prevout.hash)) - return false; - vWorkQueue.push_back(mapPrev[txin.prevout.hash]); - } - } - - return true; - } - - bool WriteToDisk(); - - int64_t GetTxTime() const; - int GetRequestCount() const; - - void AddSupportingTransactions(CTxDB& txdb); - - bool AcceptWalletTransaction(CTxDB& txdb); - bool AcceptWalletTransaction(); - - void RelayWalletTransaction(CTxDB& txdb); - void RelayWalletTransaction(); -}; - - - - -class COutput -{ -public: - const CWalletTx *tx; - int i; - int nDepth; - bool fSpendable; - - COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn) - { - tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; - } - - std::string ToString() const - { - return strprintf("COutput(%s, %d, %d) [%s]", tx->GetHash().ToString(), i, nDepth, FormatMoney(tx->vout[i].nValue)); - } - - //Used with darksend. Will return fees, then denominations, everything else, then very small inputs that aren't fees - int Priority() const - { - if(tx->vout[i].nValue == DARKSEND_FEE) return -1000; - BOOST_FOREACH(int64_t d, darkSendDenominations) - if(tx->vout[i].nValue == d) return 900; - if(tx->vout[i].nValue < 1*COIN) return 1000; - - //nondenom return largest first - return -(tx->vout[i].nValue/COIN); - } - - void print() const - { - LogPrintf("%s\n", ToString().c_str()); - } -}; - - - - -/** Private key that includes an expiration date in case it never gets used. */ -class CWalletKey -{ -public: - CPrivKey vchPrivKey; - int64_t nTimeCreated; - int64_t nTimeExpires; - std::string strComment; - //// todo: add something to note what created it (user, getnewaddress, change) - //// maybe should have a map property map - - CWalletKey(int64_t nExpires=0) - { - nTimeCreated = (nExpires ? GetTime() : 0); - nTimeExpires = nExpires; - } - - IMPLEMENT_SERIALIZE - ( - if (!(nType & SER_GETHASH)) - READWRITE(nVersion); - READWRITE(vchPrivKey); - READWRITE(nTimeCreated); - READWRITE(nTimeExpires); - READWRITE(strComment); - ) -}; - - - - - - -/** Account information. - * Stored in wallet with key "acc"+string account name. - */ -class CAccount -{ -public: - CPubKey vchPubKey; - - CAccount() - { - SetNull(); - } - - void SetNull() - { - vchPubKey = CPubKey(); - } - - IMPLEMENT_SERIALIZE - ( - if (!(nType & SER_GETHASH)) - READWRITE(nVersion); - READWRITE(vchPubKey); - ) -}; - - - -/** Internal transfers. - * Database key is acentry. - */ -class CAccountingEntry -{ -public: - std::string strAccount; - int64_t nCreditDebit; - int64_t nTime; - std::string strOtherAccount; - std::string strComment; - mapValue_t mapValue; - int64_t nOrderPos; // position in ordered transaction list - uint64_t nEntryNo; - - CAccountingEntry() - { - SetNull(); - } - - void SetNull() - { - nCreditDebit = 0; - nTime = 0; - strAccount.clear(); - strOtherAccount.clear(); - strComment.clear(); - nOrderPos = -1; - } - - IMPLEMENT_SERIALIZE - ( - CAccountingEntry& me = *const_cast(this); - if (!(nType & SER_GETHASH)) - READWRITE(nVersion); - // Note: strAccount is serialized as part of the key, not here. - READWRITE(nCreditDebit); - READWRITE(nTime); - READWRITE(strOtherAccount); - - if (!fRead) - { - WriteOrderPos(nOrderPos, me.mapValue); - - if (!(mapValue.empty() && _ssExtra.empty())) - { - CDataStream ss(nType, nVersion); - ss.insert(ss.begin(), '\0'); - ss << mapValue; - ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end()); - me.strComment.append(ss.str()); - } - } - - READWRITE(strComment); - - size_t nSepPos = strComment.find("\0", 0, 1); - if (fRead) - { - me.mapValue.clear(); - if (std::string::npos != nSepPos) - { - CDataStream ss(std::vector(strComment.begin() + nSepPos + 1, strComment.end()), nType, nVersion); - ss >> me.mapValue; - me._ssExtra = std::vector(ss.begin(), ss.end()); - } - ReadOrderPos(me.nOrderPos, me.mapValue); - } - if (std::string::npos != nSepPos) - me.strComment.erase(nSepPos); - - me.mapValue.erase("n"); - ) - -private: - std::vector _ssExtra; -}; - -#endif diff --git a/src/wallet.h.pc6884 b/src/wallet.h.pc6884 deleted file mode 100644 index 7b48271..0000000 --- a/src/wallet.h.pc6884 +++ /dev/null @@ -1,1014 +0,0 @@ -// Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2012 The Bitcoin developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_WALLET_H -#define BITCOIN_WALLET_H - -#include "walletdb.h" - -#include -#include - -#include - -#include "crypter.h" -#include "main.h" -#include "key.h" -#include "keystore.h" -#include "script.h" -#include "ui_interface.h" -#include "util.h" -#include "stealth.h" - -// Settings -extern int64_t nTransactionFee; -extern int64_t nReserveBalance; -extern int64_t nMinimumInputValue; -extern bool fWalletUnlockStakingOnly; -extern bool fConfChange; - -class CAccountingEntry; -class CCoinControl; -class CWalletTx; -class CReserveKey; -class COutput; -class CWalletDB; - -typedef std::map StealthKeyMetaMap; -typedef std::map mapValue_t; - -/** (client) version numbers for particular wallet features */ -enum WalletFeature -{ - FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getinfo's clientversion output) - - FEATURE_WALLETCRYPT = 40000, // wallet encryption input < comprepubkey to avoid exploit - FEATURE_COMPRPUBKEY = 60000, // compressed public keys - - FEATURE_LATEST = 60000 -}; - -enum AvailableCoinsType -{ - ALL_COINS = 1, - ONLY_DENOMINATED = 2, - ONLY_NONDENOMINATED = 3, - ONLY_NONDENOMINATED_NOTMN = 4 // ONLY_NONDENOMINATED and not 1000 SONO at the same time -}; - -/** IsMine() return codes */ -enum isminetype -{ - ISMINE_NO = 0, - ISMINE_WATCH_ONLY = 1, - ISMINE_SPENDABLE = 2, - ISMINE_ALL = ISMINE_WATCH_ONLY | ISMINE_SPENDABLE -}; - - -/** A key pool entry */ -class CKeyPool -{ -public: - int64_t nTime; - CPubKey vchPubKey; - - CKeyPool() - { - nTime = GetTime(); - } - - CKeyPool(const CPubKey& vchPubKeyIn) - { - nTime = GetTime(); - vchPubKey = vchPubKeyIn; - } - - IMPLEMENT_SERIALIZE - ( - if (!(nType & SER_GETHASH)) - READWRITE(nVersion); - READWRITE(nTime); - READWRITE(vchPubKey); - ) -}; - -/** A CWallet is an extension of a keystore, which also maintains a set of transactions and balances, - * and provides the ability to create new transactions. - */ -class CWallet : public CCryptoKeyStore, public CWalletInterface -{ -private: - bool SelectCoinsForStaking(int64_t nTargetValue, unsigned int nSpendTime, std::set >& setCoinsRet, int64_t& nValueRet) const; - //bool SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, std::set >& setCoinsRet, int64_t& nValueRet, const CCoinControl *coinControl=NULL) const; - bool SelectCoins(CAmount nTargetValue, unsigned int nSpendTime, std::set >& setCoinsRet, int64_t& nValueRet, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX = false) const; - CWalletDB *pwalletdbEncryption; - - // the current wallet version: clients below this version are not able to load the wallet - int nWalletVersion; - - // the maximum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded - int nWalletMaxVersion; - -public: - /// Main wallet lock. - /// This lock protects all the fields added by CWallet - /// except for: - /// fFileBacked (immutable after instantiation) - /// strWalletFile (immutable after instantiation) - mutable CCriticalSection cs_wallet; - - bool SelectCoinsDark(int64_t nValueMin, int64_t nValueMax, std::vector& setCoinsRet, int64_t& nValueRet, int nDarksendRoundsMin, int nDarksendRoundsMax) const; - bool SelectCoinsByDenominations(int nDenom, int64_t nValueMin, int64_t nValueMax, std::vector& setCoinsRet, vector& vCoins, int64_t& nValueRet, int nDarksendRoundsMin, int nDarksendRoundsMax); - bool SelectCoinsDarkDenominated(int64_t nTargetValue, std::vector& setCoinsRet, int64_t& nValueRet) const; - bool SelectCoinsMasternode(CTxIn& vin, int64_t& nValueRet, CScript& pubScript) const; - bool HasCollateralInputs() const; - bool IsCollateralAmount(int64_t nInputAmount) const; - int CountInputsWithAmount(int64_t nInputAmount); - - bool SelectCoinsCollateral(std::vector& setCoinsRet, int64_t& nValueRet) const ; - bool SelectCoinsWithoutDenomination(int64_t nTargetValue, std::set >& setCoinsRet, int64_t& nValueRet) const; - bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx); - - bool fFileBacked; - bool fWalletUnlockAnonymizeOnly; - std::string strWalletFile; - - std::set setKeyPool; - std::map mapKeyMetadata; - - std::set stealthAddresses; - StealthKeyMetaMap mapStealthKeyMeta; - - int nLastFilteredHeight; - - uint32_t nStealth, nFoundStealth; // for reporting, zero before use - - - typedef std::map MasterKeyMap; - MasterKeyMap mapMasterKeys; - unsigned int nMasterKeyMaxID; - - std::map mapMyAdrenalineNodes; - bool AddAdrenalineNodeConfig(CAdrenalineNodeConfig nodeConfig); - - CWallet() - { - SetNull(); - } - CWallet(std::string strWalletFileIn) - { - SetNull(); - - strWalletFile = strWalletFileIn; - fFileBacked = true; - } - - void SetNull() - { - nWalletVersion = FEATURE_BASE; - nWalletMaxVersion = FEATURE_BASE; - fFileBacked = false; - nMasterKeyMaxID = 0; - pwalletdbEncryption = NULL; - nOrderPosNext = 0; - nTimeFirstKey = 0; - nLastFilteredHeight = 0; - fWalletUnlockAnonymizeOnly = false; - } - - std::map mapWallet; - int64_t nOrderPosNext; - std::map mapRequestCount; - - std::map mapAddressBook; - - CPubKey vchDefaultKey; - - std::set setLockedCoins; - - int64_t nTimeFirstKey; - - // check whether we are allowed to upgrade (or already support) to the named feature - bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; } - - void AvailableCoinsForStaking(std::vector& vCoins, unsigned int nSpendTime) const; - void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX = false) const; - void AvailableCoinsMN(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX = false) const; - bool SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, int64_t& nValueRet) const; - bool SelectCoinsMinConfByCoinAge(int64_t nTargetValue, unsigned int nSpendTime, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, int64_t& nValueRet) const; - - bool IsSpent(const uint256& hash, unsigned int n) const; - - bool IsLockedCoin(uint256 hash, unsigned int n) const; - void LockCoin(COutPoint& output); - void UnlockCoin(COutPoint& output); - void UnlockAllCoins(); - void ListLockedCoins(std::vector& vOutpts); - CAmount GetTotalValue(std::vector vCoins); - - // keystore implementation - // Generate a new key - CPubKey GenerateNewKey(); - // Adds a key to the store, and saves it to disk. - bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey); - // Adds a key to the store, without saving it to disk (used by LoadWallet) - bool LoadKey(const CKey& key, const CPubKey &pubkey) { return CCryptoKeyStore::AddKeyPubKey(key, pubkey); } - // Load metadata (used by LoadWallet) - bool LoadKeyMetadata(const CPubKey &pubkey, const CKeyMetadata &metadata); - - bool LoadMinVersion(int nVersion) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; } - - // Adds an encrypted key to the store, and saves it to disk. - bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret); - // Adds an encrypted key to the store, without saving it to disk (used by LoadWallet) - bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret); - bool AddCScript(const CScript& redeemScript); - bool LoadCScript(const CScript& redeemScript); - - bool Lock(); - bool Unlock(const SecureString& strWalletPassphrase, bool anonimizeOnly = false); - bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase); - bool EncryptWallet(const SecureString& strWalletPassphrase); - - void GetKeyBirthTimes(std::map &mapKeyBirth) const; - - - /** Increment the next transaction order id - @return next transaction order id - */ - int64_t IncOrderPosNext(CWalletDB *pwalletdb = NULL); - - typedef std::pair TxPair; - typedef std::multimap TxItems; - - /** Get the wallet's activity log - @return multimap of ordered transactions and accounting entries - @warning Returned pointers are *only* valid within the scope of passed acentries - */ - TxItems OrderedTxItems(std::list& acentries, std::string strAccount = ""); - - void MarkDirty(); - bool AddToWallet(const CWalletTx& wtxIn); - void SyncTransaction(const CTransaction& tx, const CBlock* pblock, bool fConnect = true); - bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate); - void EraseFromWallet(const uint256 &hash); - void WalletUpdateSpent(const CTransaction& prevout, bool fBlock = false); - int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); - void ReacceptWalletTransactions(); - void ResendWalletTransactions(bool fForce = false); - int64_t GetBalance() const; - int64_t GetBalanceNoLocks() const; - int64_t GetUnconfirmedBalance() const; - int64_t GetImmatureBalance() const; - int64_t GetStake() const; - int64_t GetNewMint() const; - - CAmount GetAnonymizedBalance() const; - double GetAverageAnonymizedRounds() const; - CAmount GetNormalizedAnonymizedBalance() const; - CAmount GetDenominatedBalance(bool onlyDenom=true, bool onlyUnconfirmed=false) const; - - bool CreateTransaction(const std::vector >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, int32_t& nChangePos, std::string& strFailReason, const CCoinControl *coinControl=NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX=false); - bool CreateTransaction(CScript scriptPubKey, int64_t nValue, std::string& sNarr, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl *coinControl=NULL); - bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey); - - uint64_t GetStakeWeight() const; - bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64_t nSearchInterval, int64_t nFees, CTransaction& txNew, CKey& key); - - std::string SendMoney(CScript scriptPubKey, int64_t nValue, std::string& sNarr, CWalletTx& wtxNew, bool fAskFee=false); - std::string SendMoneyToDestination(const CTxDestination &address, int64_t nValue, std::string& sNarr, CWalletTx& wtxNew, bool fAskFee=false); - - bool NewStealthAddress(std::string& sError, std::string& sLabel, CStealthAddress& sxAddr); - bool AddStealthAddress(CStealthAddress& sxAddr); - bool UnlockStealthAddresses(const CKeyingMaterial& vMasterKeyIn); - bool UpdateStealthAddress(std::string &addr, std::string &label, bool addIfNotExist); - - bool CreateStealthTransaction(CScript scriptPubKey, int64_t nValue, std::vector& P, std::vector& narr, std::string& sNarr, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl* coinControl=NULL); - std::string SendStealthMoney(CScript scriptPubKey, int64_t nValue, std::vector& P, std::vector& narr, std::string& sNarr, CWalletTx& wtxNew, bool fAskFee=false); - bool SendStealthMoneyToDestination(CStealthAddress& sxAddress, int64_t nValue, std::string& sNarr, CWalletTx& wtxNew, std::string& sError, bool fAskFee=false); - bool FindStealthTransactions(const CTransaction& tx, mapValue_t& mapNarr); - - std::string PrepareluxsendDenominate(int minRounds, int maxRounds); - bool CreateCollateralTransaction(CTransaction& txCollateral, std::string strReason); - bool ConvertList(std::vector vCoins, std::vector& vecAmounts); - - bool NewKeyPool(); - bool TopUpKeyPool(unsigned int nSize = 0); - int64_t AddReserveKey(const CKeyPool& keypool); - void ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool); - void KeepKey(int64_t nIndex); - void ReturnKey(int64_t nIndex); - bool GetKeyFromPool(CPubKey &key); - int64_t GetOldestKeyPoolTime(); - void GetAllReserveKeys(std::set& setAddress) const; - - std::set< std::set > GetAddressGroupings(); - std::map GetAddressBalances(); - - - bool IsDenominated(const CTxIn &txin) const; - - bool IsDenominated(const CTransaction& tx) const - { - /* - Return false if ANY inputs are non-denom - */ - bool ret = true; - BOOST_FOREACH(const CTxIn& txin, tx.vin) - { - if(!IsDenominated(txin)) { - ret = false; - } - } - return ret; - } - - bool IsDenominatedAmount(int64_t nInputAmount) const; - - - bool IsMine(const CTxIn& txin) const; - int64_t GetDebit(const CTxIn& txin) const; - bool IsMine(const CTxOut& txout) const - { - return ::IsMine(*this, txout.scriptPubKey); - } - int64_t GetCredit(const CTxOut& txout) const - { - if (!MoneyRange(txout.nValue)) - throw std::runtime_error("CWallet::GetCredit() : value out of range"); - return (IsMine(txout) ? txout.nValue : 0); - } - bool IsChange(const CTxOut& txout) const; - int64_t GetChange(const CTxOut& txout) const - { - if (!MoneyRange(txout.nValue)) - throw std::runtime_error("CWallet::GetChange() : value out of range"); - return (IsChange(txout) ? txout.nValue : 0); - } - bool IsMine(const CTransaction& tx) const - { - BOOST_FOREACH(const CTxOut& txout, tx.vout) - if (IsMine(txout) && txout.nValue >= nMinimumInputValue) - return true; - return false; - } - bool IsFromMe(const CTransaction& tx) const - { - return (GetDebit(tx) > 0); - } - int64_t GetDebit(const CTransaction& tx) const - { - int64_t nDebit = 0; - BOOST_FOREACH(const CTxIn& txin, tx.vin) - { - nDebit += GetDebit(txin); - if (!MoneyRange(nDebit)) - throw std::runtime_error("CWallet::GetDebit() : value out of range"); - } - return nDebit; - } - int64_t GetCredit(const CTransaction& tx) const - { - int64_t nCredit = 0; - BOOST_FOREACH(const CTxOut& txout, tx.vout) - { - nCredit += GetCredit(txout); - if (!MoneyRange(nCredit)) - throw std::runtime_error("CWallet::GetCredit() : value out of range"); - } - return nCredit; - } - int64_t GetChange(const CTransaction& tx) const - { - int64_t nChange = 0; - BOOST_FOREACH(const CTxOut& txout, tx.vout) - { - nChange += GetChange(txout); - if (!MoneyRange(nChange)) - throw std::runtime_error("CWallet::GetChange() : value out of range"); - } - return nChange; - } - void SetBestChain(const CBlockLocator& loc); - - DBErrors LoadWallet(bool& fFirstRunRet); - - bool SetAddressBookName(const CTxDestination& address, const std::string& strName); - - bool DelAddressBookName(const CTxDestination& address); - - void UpdatedTransaction(const uint256 &hashTx); - - void Inventory(const uint256 &hash) - { - { - LOCK(cs_wallet); - std::map::iterator mi = mapRequestCount.find(hash); - if (mi != mapRequestCount.end()) - (*mi).second++; - } - } - - unsigned int GetKeyPoolSize() - { - AssertLockHeld(cs_wallet); // setKeyPool - return setKeyPool.size(); - } - - bool SetDefaultKey(const CPubKey &vchPubKey); - - // signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower - bool SetMinVersion(enum WalletFeature, CWalletDB* pwalletdbIn = NULL, bool fExplicit = false); - - // change which version we're allowed to upgrade to (note that this does not immediately imply upgrading to that format) - bool SetMaxVersion(int nVersion); - - // get the current wallet format (the oldest client version guaranteed to understand this wallet) - int GetVersion() { LOCK(cs_wallet); return nWalletVersion; } - - void FixSpentCoins(int& nMismatchSpent, int64_t& nBalanceInQuestion, bool fCheckOnly = false); - void DisableTransaction(const CTransaction &tx); - - /** Address book entry changed. - * @note called with lock cs_wallet held. - */ - boost::signals2::signal NotifyAddressBookChanged; - - /** Wallet transaction added, removed or updated. - * @note called with lock cs_wallet held. - */ - boost::signals2::signal NotifyTransactionChanged; -}; - -/** A key allocated from the key pool. */ -class CReserveKey -{ -protected: - CWallet* pwallet; - int64_t nIndex; - CPubKey vchPubKey; -public: - CReserveKey(CWallet* pwalletIn) - { - nIndex = -1; - pwallet = pwalletIn; - } - - ~CReserveKey() - { - ReturnKey(); - } - - void ReturnKey(); - bool GetReservedKey(CPubKey &pubkey); - void KeepKey(); -}; - - -typedef std::map mapValue_t; - - -static void ReadOrderPos(int64_t& nOrderPos, mapValue_t& mapValue) -{ - if (!mapValue.count("n")) - { - nOrderPos = -1; // TODO: calculate elsewhere - return; - } - nOrderPos = atoi64(mapValue["n"].c_str()); -} - - -static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue) -{ - if (nOrderPos == -1) - return; - mapValue["n"] = i64tostr(nOrderPos); -} - - -/** A transaction with a bunch of additional info that only the owner cares about. - * It includes any unrecorded transactions needed to link it back to the block chain. - */ -class CWalletTx : public CMerkleTx -{ -private: - const CWallet* pwallet; - -public: - std::vector vtxPrev; - mapValue_t mapValue; - std::vector > vOrderForm; - unsigned int fTimeReceivedIsTxTime; - unsigned int nTimeReceived; // time received by this node - unsigned int nTimeSmart; - char fFromMe; - std::string strFromAccount; - std::vector vfSpent; // which outputs are already spent - int64_t nOrderPos; // position in ordered transaction list - - // memory only - mutable bool fDebitCached; - mutable bool fCreditCached; - mutable bool fAvailableCreditCached; - mutable bool fChangeCached; - mutable int64_t nDebitCached; - mutable int64_t nCreditCached; - mutable int64_t nAvailableCreditCached; - mutable int64_t nChangeCached; - - CWalletTx() - { - Init(NULL); - } - - CWalletTx(const CWallet* pwalletIn) - { - Init(pwalletIn); - } - - CWalletTx(const CWallet* pwalletIn, const CMerkleTx& txIn) : CMerkleTx(txIn) - { - Init(pwalletIn); - } - - CWalletTx(const CWallet* pwalletIn, const CTransaction& txIn) : CMerkleTx(txIn) - { - Init(pwalletIn); - } - - void Init(const CWallet* pwalletIn) - { - pwallet = pwalletIn; - vtxPrev.clear(); - mapValue.clear(); - vOrderForm.clear(); - fTimeReceivedIsTxTime = false; - nTimeReceived = 0; - nTimeSmart = 0; - fFromMe = false; - strFromAccount.clear(); - vfSpent.clear(); - fDebitCached = false; - fCreditCached = false; - fAvailableCreditCached = false; - fChangeCached = false; - nDebitCached = 0; - nCreditCached = 0; - nAvailableCreditCached = 0; - nChangeCached = 0; - nOrderPos = -1; - } - - IMPLEMENT_SERIALIZE - ( - CWalletTx* pthis = const_cast(this); - if (fRead) - pthis->Init(NULL); - char fSpent = false; - - if (!fRead) - { - pthis->mapValue["fromaccount"] = pthis->strFromAccount; - - std::string str; - BOOST_FOREACH(char f, vfSpent) - { - str += (f ? '1' : '0'); - if (f) - fSpent = true; - } - pthis->mapValue["spent"] = str; - - WriteOrderPos(pthis->nOrderPos, pthis->mapValue); - - if (nTimeSmart) - pthis->mapValue["timesmart"] = strprintf("%u", nTimeSmart); - } - - nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion,ser_action); - READWRITE(vtxPrev); - READWRITE(mapValue); - READWRITE(vOrderForm); - READWRITE(fTimeReceivedIsTxTime); - READWRITE(nTimeReceived); - READWRITE(fFromMe); - READWRITE(fSpent); - - if (fRead) - { - pthis->strFromAccount = pthis->mapValue["fromaccount"]; - - if (mapValue.count("spent")) - BOOST_FOREACH(char c, pthis->mapValue["spent"]) - pthis->vfSpent.push_back(c != '0'); - else - pthis->vfSpent.assign(vout.size(), fSpent); - - ReadOrderPos(pthis->nOrderPos, pthis->mapValue); - - pthis->nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(pthis->mapValue["timesmart"]) : 0; - } - - pthis->mapValue.erase("fromaccount"); - pthis->mapValue.erase("version"); - pthis->mapValue.erase("spent"); - pthis->mapValue.erase("n"); - pthis->mapValue.erase("timesmart"); - ) - - // marks certain txout's as spent - // returns true if any update took place - bool UpdateSpent(const std::vector& vfNewSpent) - { - bool fReturn = false; - for (unsigned int i = 0; i < vfNewSpent.size(); i++) - { - if (i == vfSpent.size()) - break; - - if (vfNewSpent[i] && !vfSpent[i]) - { - vfSpent[i] = true; - fReturn = true; - fAvailableCreditCached = false; - } - } - return fReturn; - } - - // make sure balances are recalculated - void MarkDirty() - { - fCreditCached = false; - fAvailableCreditCached = false; - fDebitCached = false; - fChangeCached = false; - } - - void BindWallet(CWallet *pwalletIn) - { - pwallet = pwalletIn; - MarkDirty(); - } - - void MarkSpent(unsigned int nOut) - { - if (nOut >= vout.size()) - throw std::runtime_error("CWalletTx::MarkSpent() : nOut out of range"); - vfSpent.resize(vout.size()); - if (!vfSpent[nOut]) - { - vfSpent[nOut] = true; - fAvailableCreditCached = false; - } - } - - void MarkUnspent(unsigned int nOut) - { - if (nOut >= vout.size()) - throw std::runtime_error("CWalletTx::MarkUnspent() : nOut out of range"); - vfSpent.resize(vout.size()); - if (vfSpent[nOut]) - { - vfSpent[nOut] = false; - fAvailableCreditCached = false; - } - } - - bool IsSpent(unsigned int nOut) const - { - if (nOut >= vout.size()) - throw std::runtime_error("CWalletTx::IsSpent() : nOut out of range"); - if (nOut >= vfSpent.size()) - return false; - return (!!vfSpent[nOut]); - } - - int64_t IsDenominated() const - { - if (vin.empty()) - return 0; - return pwallet->IsDenominated(*this); - } - - int64_t GetDebit() const - { - if (vin.empty()) - return 0; - if (fDebitCached) - return nDebitCached; - nDebitCached = pwallet->GetDebit(*this); - fDebitCached = true; - return nDebitCached; - } - - int64_t GetCredit(bool fUseCache=true) const - { - // Must wait until coinbase is safely deep enough in the chain before valuing it - if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0) - return 0; - - // GetBalance can assume transactions in mapWallet won't change - if (fUseCache && fCreditCached) - return nCreditCached; - nCreditCached = pwallet->GetCredit(*this); - fCreditCached = true; - return nCreditCached; - } - - int64_t GetAvailableCredit(bool fUseCache=true) const - { - // Must wait until coinbase is safely deep enough in the chain before valuing it - if ((IsCoinBase() || IsCoinStake()) && GetBlocksToMaturity() > 0) - return 0; - - if (fUseCache && fAvailableCreditCached) - return nAvailableCreditCached; - - int64_t nCredit = 0; - for (unsigned int i = 0; i < vout.size(); i++) - { - if (!IsSpent(i)) - { - const CTxOut &txout = vout[i]; - nCredit += pwallet->GetCredit(txout); - if (!MoneyRange(nCredit)) - throw std::runtime_error("CWalletTx::GetAvailableCredit() : value out of range"); - } - } - - nAvailableCreditCached = nCredit; - fAvailableCreditCached = true; - return nCredit; - } - - - int64_t GetChange() const - { - if (fChangeCached) - return nChangeCached; - nChangeCached = pwallet->GetChange(*this); - fChangeCached = true; - return nChangeCached; - } - - void GetAmounts(std::list >& listReceived, - std::list >& listSent, int64_t& nFee, std::string& strSentAccount) const; - - void GetAccountAmounts(const std::string& strAccount, int64_t& nReceived, - int64_t& nSent, int64_t& nFee) const; - - bool IsFromMe() const - { - return (GetDebit() > 0); - } - - bool IsTrusted() const - { - // Quick answer in most cases - if (!IsFinalTx(*this)) - return false; - int nDepth = GetDepthInMainChain(); - if (nDepth >= 1) - return true; - if (nDepth < 0) - return false; - if (fConfChange || !IsFromMe()) // using wtx's cached debit - return false; - - // If no confirmations but it's from us, we can still - // consider it confirmed if all dependencies are confirmed - std::map mapPrev; - std::vector vWorkQueue; - vWorkQueue.reserve(vtxPrev.size()+1); - vWorkQueue.push_back(this); - for (unsigned int i = 0; i < vWorkQueue.size(); i++) - { - const CMerkleTx* ptx = vWorkQueue[i]; - - if (!IsFinalTx(*ptx)) - return false; - int nPDepth = ptx->GetDepthInMainChain(); - if (nPDepth >= 1) - continue; - if (nPDepth < 0) - return false; - if (!pwallet->IsFromMe(*ptx)) - return false; - - if (mapPrev.empty()) - { - BOOST_FOREACH(const CMerkleTx& tx, vtxPrev) - mapPrev[tx.GetHash()] = &tx; - } - - BOOST_FOREACH(const CTxIn& txin, ptx->vin) - { - if (!mapPrev.count(txin.prevout.hash)) - return false; - vWorkQueue.push_back(mapPrev[txin.prevout.hash]); - } - } - - return true; - } - - bool WriteToDisk(); - - int64_t GetTxTime() const; - int GetRequestCount() const; - - void AddSupportingTransactions(CTxDB& txdb); - - bool AcceptWalletTransaction(CTxDB& txdb); - bool AcceptWalletTransaction(); - - void RelayWalletTransaction(CTxDB& txdb); - void RelayWalletTransaction(); -}; - - - - -class COutput -{ -public: - const CWalletTx *tx; - int i; - int nDepth; - bool fSpendable; - - COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn) - { - tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; - } - - std::string ToString() const - { - return strprintf("COutput(%s, %d, %d) [%s]", tx->GetHash().ToString(), i, nDepth, FormatMoney(tx->vout[i].nValue)); - } - - //Used with darksend. Will return fees, then denominations, everything else, then very small inputs that aren't fees - int Priority() const - { - if(tx->vout[i].nValue == DARKSEND_FEE) return -1000; - BOOST_FOREACH(int64_t d, darkSendDenominations) - if(tx->vout[i].nValue == d) return 900; - if(tx->vout[i].nValue < 1*COIN) return 1000; - - //nondenom return largest first - return -(tx->vout[i].nValue/COIN); - } - - void print() const - { - LogPrintf("%s\n", ToString().c_str()); - } -}; - - - - -/** Private key that includes an expiration date in case it never gets used. */ -class CWalletKey -{ -public: - CPrivKey vchPrivKey; - int64_t nTimeCreated; - int64_t nTimeExpires; - std::string strComment; - //// todo: add something to note what created it (user, getnewaddress, change) - //// maybe should have a map property map - - CWalletKey(int64_t nExpires=0) - { - nTimeCreated = (nExpires ? GetTime() : 0); - nTimeExpires = nExpires; - } - - IMPLEMENT_SERIALIZE - ( - if (!(nType & SER_GETHASH)) - READWRITE(nVersion); - READWRITE(vchPrivKey); - READWRITE(nTimeCreated); - READWRITE(nTimeExpires); - READWRITE(strComment); - ) -}; - - - - - - -/** Account information. - * Stored in wallet with key "acc"+string account name. - */ -class CAccount -{ -public: - CPubKey vchPubKey; - - CAccount() - { - SetNull(); - } - - void SetNull() - { - vchPubKey = CPubKey(); - } - - IMPLEMENT_SERIALIZE - ( - if (!(nType & SER_GETHASH)) - READWRITE(nVersion); - READWRITE(vchPubKey); - ) -}; - - - -/** Internal transfers. - * Database key is acentry. - */ -class CAccountingEntry -{ -public: - std::string strAccount; - int64_t nCreditDebit; - int64_t nTime; - std::string strOtherAccount; - std::string strComment; - mapValue_t mapValue; - int64_t nOrderPos; // position in ordered transaction list - uint64_t nEntryNo; - - CAccountingEntry() - { - SetNull(); - } - - void SetNull() - { - nCreditDebit = 0; - nTime = 0; - strAccount.clear(); - strOtherAccount.clear(); - strComment.clear(); - nOrderPos = -1; - } - - IMPLEMENT_SERIALIZE - ( - CAccountingEntry& me = *const_cast(this); - if (!(nType & SER_GETHASH)) - READWRITE(nVersion); - // Note: strAccount is serialized as part of the key, not here. - READWRITE(nCreditDebit); - READWRITE(nTime); - READWRITE(strOtherAccount); - - if (!fRead) - { - WriteOrderPos(nOrderPos, me.mapValue); - - if (!(mapValue.empty() && _ssExtra.empty())) - { - CDataStream ss(nType, nVersion); - ss.insert(ss.begin(), '\0'); - ss << mapValue; - ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end()); - me.strComment.append(ss.str()); - } - } - - READWRITE(strComment); - - size_t nSepPos = strComment.find("\0", 0, 1); - if (fRead) - { - me.mapValue.clear(); - if (std::string::npos != nSepPos) - { - CDataStream ss(std::vector(strComment.begin() + nSepPos + 1, strComment.end()), nType, nVersion); - ss >> me.mapValue; - me._ssExtra = std::vector(ss.begin(), ss.end()); - } - ReadOrderPos(me.nOrderPos, me.mapValue); - } - if (std::string::npos != nSepPos) - me.strComment.erase(nSepPos); - - me.mapValue.erase("n"); - ) - -private: - std::vector _ssExtra; -}; - -#endif From f4078ba00704e88dc39f8c52e7ba604515eb7c66 Mon Sep 17 00:00:00 2001 From: Mike <31688573+zPools@users.noreply.github.com> Date: Fri, 26 Jan 2018 11:52:10 +0100 Subject: [PATCH 2/6] Update transactiondesc.cpp Minor fix --- src/qt/transactiondesc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index ec9d0d8..1b878e8 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -199,7 +199,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco strHTML += "" + tr("Debit") + ": " + BitcoinUnits::formatWithUnit(unit, -wallet->GetDebit(txin)) + "
"; BOOST_FOREACH(const CTxOut& txout, wtx.vout) if (wallet->IsMine(txout)) - strHTML += "" + tr("Credit - mixed (DEBUG)") + ": " + BitcoinUnits::formatWithUnit(unit, wallet->GetCredit(txout)) + "
"; + strHTML += "" + tr("Credit") + ": " + BitcoinUnits::formatWithUnit(unit, wallet->GetCredit(txout)) + "
"; } } From 58221d585608e1535ec5ecdebb8270c8fb277760 Mon Sep 17 00:00:00 2001 From: Mike <31688573+zPools@users.noreply.github.com> Date: Fri, 26 Jan 2018 11:55:05 +0100 Subject: [PATCH 3/6] Update bitcoingui.cpp Minor fix --- src/qt/bitcoingui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 112ce2b..96541b3 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -750,7 +750,7 @@ void BitcoinGUI::setNumBlocks(int count) void BitcoinGUI::message(const QString& title, const QString& message, unsigned int style, bool* ret) { - QString strTitle = tr("LUX Core"); // default title + QString strTitle = tr("SONO"); // default title // Default to information icon int nMBoxIcon = QMessageBox::Information; int nNotifyIcon = Notificator::Information; From 2bacc83f761bbe092e6c3564d83c1e55e7404209 Mon Sep 17 00:00:00 2001 From: Mike <31688573+zPools@users.noreply.github.com> Date: Fri, 26 Jan 2018 15:30:14 +0100 Subject: [PATCH 4/6] Update coincontroldialog.cpp Forgot to turn it on --- src/qt/coincontroldialog.cpp | 52 ++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp index 68ce073..432cfa2 100644 --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -38,8 +38,8 @@ CoinControlDialog::CoinControlDialog(QWidget *parent) : QAction *copyLabelAction = new QAction(tr("Copy label"), this); QAction *copyAmountAction = new QAction(tr("Copy amount"), this); copyTransactionHashAction = new QAction(tr("Copy transaction ID"), this); // we need to enable/disable this - //lockAction = new QAction(tr("Lock unspent"), this); // we need to enable/disable this - //unlockAction = new QAction(tr("Unlock unspent"), this); // we need to enable/disable this + lockAction = new QAction(tr("Lock unspent"), this); // we need to enable/disable this + unlockAction = new QAction(tr("Unlock unspent"), this); // we need to enable/disable this // context menu contextMenu = new QMenu(); @@ -48,8 +48,8 @@ CoinControlDialog::CoinControlDialog(QWidget *parent) : contextMenu->addAction(copyAmountAction); contextMenu->addAction(copyTransactionHashAction); //contextMenu->addSeparator(); - //contextMenu->addAction(lockAction); - //contextMenu->addAction(unlockAction); + contextMenu->addAction(lockAction); + contextMenu->addAction(unlockAction); // context menu signals connect(ui->treeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint))); @@ -57,8 +57,8 @@ CoinControlDialog::CoinControlDialog(QWidget *parent) : connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel())); connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount())); connect(copyTransactionHashAction, SIGNAL(triggered()), this, SLOT(copyTransactionHash())); - //connect(lockAction, SIGNAL(triggered()), this, SLOT(lockCoin())); - //connect(unlockAction, SIGNAL(triggered()), this, SLOT(unlockCoin())); + connect(lockAction, SIGNAL(triggered()), this, SLOT(lockCoin())); + connect(unlockAction, SIGNAL(triggered()), this, SLOT(unlockCoin())); // clipboard actions QAction *clipboardQuantityAction = new QAction(tr("Copy quantity"), this); @@ -186,22 +186,22 @@ void CoinControlDialog::showMenu(const QPoint &point) if (item->text(COLUMN_TXHASH).length() == 64) // transaction hash is 64 characters (this means its a child node, so its not a parent node in tree mode) { copyTransactionHashAction->setEnabled(true); - //if (model->isLockedCoin(uint256(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt())) - //{ - // lockAction->setEnabled(false); - // unlockAction->setEnabled(true); - //} - //else - //{ - // lockAction->setEnabled(true); - // unlockAction->setEnabled(false); - //} + if (model->isLockedCoin(uint256(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt())) + { + lockAction->setEnabled(false); + unlockAction->setEnabled(true); + } + else + { + lockAction->setEnabled(true); + unlockAction->setEnabled(false); + } } else // this means click on parent node in tree mode -> disable all { copyTransactionHashAction->setEnabled(false); - //lockAction->setEnabled(false); - //unlockAction->setEnabled(false); + lockAction->setEnabled(false); + unlockAction->setEnabled(false); } // show context menu @@ -240,7 +240,7 @@ void CoinControlDialog::copyTransactionHash() } // context menu action: lock coin -/*void CoinControlDialog::lockCoin() +void CoinControlDialog::lockCoin() { if (contextMenuItem->checkState(COLUMN_CHECKBOX) == Qt::Checked) contextMenuItem->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked); @@ -250,17 +250,17 @@ void CoinControlDialog::copyTransactionHash() contextMenuItem->setDisabled(true); contextMenuItem->setIcon(COLUMN_CHECKBOX, QIcon(":/icons/lock_closed")); updateLabelLocked(); -}*/ +} // context menu action: unlock coin -/*void CoinControlDialog::unlockCoin() +void CoinControlDialog::unlockCoin() { COutPoint outpt(uint256(contextMenuItem->text(COLUMN_TXHASH).toStdString()), contextMenuItem->text(COLUMN_VOUT_INDEX).toUInt()); model->unlockCoin(outpt); contextMenuItem->setDisabled(false); contextMenuItem->setIcon(COLUMN_CHECKBOX, QIcon()); updateLabelLocked(); -}*/ +} // copy label "Quantity" to clipboard void CoinControlDialog::clipboardQuantity() @@ -399,7 +399,7 @@ QString CoinControlDialog::getPriorityLabel(double dPriority) } // shows count of locked unspent outputs -/*void CoinControlDialog::updateLabelLocked() +void CoinControlDialog::updateLabelLocked() { vector vOutpts; model->listLockedCoins(vOutpts); @@ -409,7 +409,7 @@ QString CoinControlDialog::getPriorityLabel(double dPriority) ui->labelLocked->setVisible(true); } else ui->labelLocked->setVisible(false); -}*/ +} void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) { @@ -678,13 +678,13 @@ void CoinControlDialog::updateView() itemOutput->setText(COLUMN_VOUT_INDEX, QString::number(out.i)); // disable locked coins - /*if (model->isLockedCoin(txhash, out.i)) + if (model->isLockedCoin(txhash, out.i)) { COutPoint outpt(txhash, out.i); coinControl->UnSelect(outpt); // just to be sure itemOutput->setDisabled(true); itemOutput->setIcon(COLUMN_CHECKBOX, QIcon(":/icons/lock_closed")); - }*/ + } // set checkbox if (coinControl->IsSelected(txhash, out.i)) From 59f8505446311cac9a1eda9765bab573232fcae6 Mon Sep 17 00:00:00 2001 From: Mike <31688573+zPools@users.noreply.github.com> Date: Fri, 26 Jan 2018 15:31:03 +0100 Subject: [PATCH 5/6] Update coincontroldialog.h Forgot to turn it on --- src/qt/coincontroldialog.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qt/coincontroldialog.h b/src/qt/coincontroldialog.h index 4d2cb82..dad177e 100644 --- a/src/qt/coincontroldialog.h +++ b/src/qt/coincontroldialog.h @@ -42,8 +42,8 @@ class CoinControlDialog : public QDialog QMenu *contextMenu; QTreeWidgetItem *contextMenuItem; QAction *copyTransactionHashAction; - //QAction *lockAction; - //QAction *unlockAction; + QAction *lockAction; + QAction *unlockAction; QString strPad(QString, int, QString); void sortView(int, Qt::SortOrder); @@ -70,8 +70,8 @@ private slots: void copyLabel(); void copyAddress(); void copyTransactionHash(); - //void lockCoin(); - //void unlockCoin(); + void lockCoin(); + void unlockCoin(); void clipboardQuantity(); void clipboardAmount(); void clipboardFee(); @@ -86,7 +86,7 @@ private slots: void headerSectionClicked(int); void buttonBoxClicked(QAbstractButton*); void buttonSelectAllClicked(); - //void updateLabelLocked(); + void updateLabelLocked(); }; #endif // COINCONTROLDIALOG_H From 54648af5379bc070d3796a90d21fa30305ba93db Mon Sep 17 00:00:00 2001 From: Mike <31688573+zPools@users.noreply.github.com> Date: Fri, 26 Jan 2018 22:26:23 +0100 Subject: [PATCH 6/6] Update main.cpp Earlier kick off --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7149777..0751465 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3405,7 +3405,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (pfrom->nVersion < MIN_PEER_PROTO_VERSION) badVersion = true; - if (nBestHeight >= 250000 && pfrom->nVersion < 70004) + if (nBestHeight >= 192500 && pfrom->nVersion < 70004) badVersion = true; if (badVersion)