Dash Core  0.12.2.1
P2P Digital Currency
privatesend-client.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2017 The Dash Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef PRIVATESENDCLIENT_H
6 #define PRIVATESENDCLIENT_H
7 
8 #include "masternode.h"
9 #include "privatesend.h"
10 #include "wallet/wallet.h"
11 #include "privatesend-util.h"
12 
13 class CPrivateSendClient;
14 class CConnman;
15 
16 static const int DENOMS_COUNT_MAX = 100;
17 
18 static const int DEFAULT_PRIVATESEND_ROUNDS = 2;
19 static const int DEFAULT_PRIVATESEND_AMOUNT = 1000;
20 static const int DEFAULT_PRIVATESEND_LIQUIDITY = 0;
21 static const bool DEFAULT_PRIVATESEND_MULTISESSION = false;
22 
23 // Warn user if mixing in gui or try to create backup if mixing in daemon mode
24 // when we have only this many keys left
25 static const int PRIVATESEND_KEYS_THRESHOLD_WARNING = 100;
26 // Stop mixing completely, it's too dangerous to continue when we have only this many keys left
27 static const int PRIVATESEND_KEYS_THRESHOLD_STOP = 50;
28 
29 // The main object for accessing mixing
31 
35 {
36 private:
38 
39  // Keep track of the used Masternodes
40  std::vector<COutPoint> vecMasternodesUsed;
41 
42  std::vector<CAmount> vecDenominationsSkipped;
43  std::vector<COutPoint> vecOutPointLocked;
44 
46  int nMinBlocksToWait; // how many blocks to wait after one successful mixing tx in non-multisession mode
47 
48  // Keep track of current block height
50 
53 
54  std::string strLastMessage;
55  std::string strAutoDenomResult;
56 
57  CMutableTransaction txMyCollateral; // client side collateral
58 
59  CKeyHolderStorage keyHolderStorage; // storage for keys used in PrepareDenominate
60 
62  void CheckPool();
63  void CompletedTransaction(PoolMessage nMessageID);
64 
65  bool IsDenomSkipped(CAmount nDenomValue) {
66  return std::find(vecDenominationsSkipped.begin(), vecDenominationsSkipped.end(), nDenomValue) != vecDenominationsSkipped.end();
67  }
68 
69  bool WaitForAnotherBlock();
70 
71  // Make sure we have enough keys since last backup
72  bool CheckAutomaticBackup();
73  bool JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CConnman& connman);
74  bool StartNewQueue(CAmount nValueMin, CAmount nBalanceNeedsAnonymized, CConnman& connman);
75 
77  bool CreateDenominated(CConnman& connman);
78  bool CreateDenominated(const CompactTallyItem& tallyItem, bool fCreateMixingCollaterals, CConnman& connman);
79 
81  bool MakeCollateralAmounts(CConnman& connman);
82  bool MakeCollateralAmounts(const CompactTallyItem& tallyItem, bool fTryDenominated, CConnman& connman);
83 
85  bool SubmitDenominate(CConnman& connman);
87  bool PrepareDenominate(int nMinRounds, int nMaxRounds, std::string& strErrorRet, std::vector<CTxIn>& vecTxInRet, std::vector<CTxOut>& vecTxOutRet);
89  bool SendDenominate(const std::vector<CTxIn>& vecTxIn, const std::vector<CTxOut>& vecTxOut, CConnman& connman);
90 
92  bool CheckPoolStateUpdate(PoolState nStateNew, int nEntriesCountNew, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID, int nSessionIDNew=0);
93  // Set the 'state' value, with some logging and capturing when the state changed
94  void SetState(PoolState nStateNew);
95 
97  bool SignFinalTransaction(const CTransaction& finalTransactionNew, CNode* pnode, CConnman& connman);
98 
99  void RelayIn(const CDarkSendEntry& entry, CConnman& connman);
100 
101  void SetNull();
102 
103 public:
109 
111  int nCachedNumBlocks; //used for the overview screen
112  bool fCreateAutoBackups; //builtin support for automatic backups
113 
116  nMinBlocksToWait(1),
121  fEnablePrivateSend(false),
123  nCachedNumBlocks(std::numeric_limits<int>::max()),
124  fCreateAutoBackups(true) { SetNull(); }
125 
126  void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv, CConnman& connman);
127 
129 
130  void SetMinBlocksToWait(int nMinBlocksToWaitIn) { nMinBlocksToWait = nMinBlocksToWaitIn; }
131 
132  void ResetPool();
133 
134  void UnlockCoins();
135 
136  std::string GetStatus();
137 
139  bool DoAutomaticDenominating(CConnman& connman, bool fDryRun=false);
140 
141  void CheckTimeout();
142 
144  void NewBlock();
145 
146  void UpdatedBlockTip(const CBlockIndex *pindex);
147 };
148 
150 
151 #endif
std::string strAutoDenomResult
bool PrepareDenominate(int nMinRounds, int nMaxRounds, std::string &strErrorRet, std::vector< CTxIn > &vecTxInRet, std::vector< CTxOut > &vecTxOutRet)
step 1: prepare denominated inputs and outputs
static const int DENOMS_COUNT_MAX
CMutableTransaction txMyCollateral
bool JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CConnman &connman)
void RelayIn(const CDarkSendEntry &entry, CConnman &connman)
CKeyHolderStorage keyHolderStorage
void ThreadCheckPrivateSendClient(CConnman &connman)
CPrivateSendClient privateSendClient
static const int DEFAULT_PRIVATESEND_AMOUNT
std::vector< CAmount > vecDenominationsSkipped
void SetState(PoolState nStateNew)
static const int PRIVATESEND_KEYS_THRESHOLD_WARNING
bool SubmitDenominate(CConnman &connman)
As a client, submit part of a future mixing transaction to a Masternode to start the process...
Definition: net.h:108
void CompletedTransaction(PoolMessage nMessageID)
static const int DEFAULT_PRIVATESEND_LIQUIDITY
masternode_info_t infoMixingMasternode
PoolMessage
Definition: privatesend.h:30
int64_t CAmount
Definition: amount.h:14
static const int DEFAULT_PRIVATESEND_ROUNDS
bool CreateDenominated(CConnman &connman)
Create denominations.
Definition: net.h:661
std::string strLastMessage
std::vector< COutPoint > vecOutPointLocked
void CheckPool()
Check for process.
bool SendDenominate(const std::vector< CTxIn > &vecTxIn, const std::vector< CTxOut > &vecTxOut, CConnman &connman)
step 2: send denominated inputs and outputs prepared in step 1
PoolStatusUpdate
Definition: privatesend.h:70
void SetMinBlocksToWait(int nMinBlocksToWaitIn)
void ProcessMessage(CNode *pfrom, std::string &strCommand, CDataStream &vRecv, CConnman &connman)
PoolState
Definition: privatesend.h:58
std::vector< COutPoint > vecMasternodesUsed
bool CheckPoolStateUpdate(PoolState nStateNew, int nEntriesCountNew, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID, int nSessionIDNew=0)
Get Masternode updates about the progress of mixing.
bool IsDenomSkipped(CAmount nDenomValue)
static const int PRIVATESEND_KEYS_THRESHOLD_STOP
CCriticalSection cs_darksend
bool SignFinalTransaction(const CTransaction &finalTransactionNew, CNode *pnode, CConnman &connman)
As a client, check and sign the final transaction.
bool MakeCollateralAmounts(CConnman &connman)
Split up large inputs or make fee sized inputs.
bool DoAutomaticDenominating(CConnman &connman, bool fDryRun=false)
Passively run mixing in the background according to the configuration in settings.
void UpdatedBlockTip(const CBlockIndex *pindex)
static const bool DEFAULT_PRIVATESEND_MULTISESSION
bool StartNewQueue(CAmount nValueMin, CAmount nBalanceNeedsAnonymized, CConnman &connman)
void NewBlock()
Process a new block.