2019-01-29 15:53:14 +01:00
|
|
|
// Copyright (c) 2014-2019 The Dash Core developers
|
2017-05-05 13:26:27 +02:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef PRIVATESENDSERVER_H
|
|
|
|
#define PRIVATESENDSERVER_H
|
|
|
|
|
|
|
|
#include "net.h"
|
|
|
|
#include "privatesend.h"
|
|
|
|
|
|
|
|
class CPrivateSendServer;
|
|
|
|
|
|
|
|
// The main object for accessing mixing
|
|
|
|
extern CPrivateSendServer privateSendServer;
|
|
|
|
|
|
|
|
/** Used to keep track of current status of mixing pool
|
|
|
|
*/
|
2018-09-04 12:54:59 +02:00
|
|
|
class CPrivateSendServer : public CPrivateSendBaseSession, public CPrivateSendBaseManager
|
2017-05-05 13:26:27 +02:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
// Mixing uses collateral transactions to trust parties entering the pool
|
|
|
|
// to behave honestly. If they don't it takes their money.
|
2017-09-20 14:02:53 +02:00
|
|
|
std::vector<CTransactionRef> vecSessionCollaterals;
|
2017-05-05 13:26:27 +02:00
|
|
|
|
2019-01-07 11:21:10 +01:00
|
|
|
// Maximum number of participants in a certain session, random between min and max.
|
|
|
|
int nSessionMaxParticipants;
|
|
|
|
|
2017-05-05 13:26:27 +02:00
|
|
|
bool fUnitTest;
|
|
|
|
|
|
|
|
/// Add a clients entry to the pool
|
2018-10-25 16:31:32 +02:00
|
|
|
bool AddEntry(const CPrivateSendEntry& entryNew, PoolMessage& nMessageIDRet);
|
2017-05-05 13:26:27 +02:00
|
|
|
/// Add signature to a txin
|
|
|
|
bool AddScriptSig(const CTxIn& txin);
|
|
|
|
|
|
|
|
/// Charge fees to bad actors (Charge clients a fee if they're abusive)
|
2017-09-19 16:51:38 +02:00
|
|
|
void ChargeFees(CConnman& connman);
|
2017-05-05 13:26:27 +02:00
|
|
|
/// Rarely charge fees to pay miners
|
2017-09-19 16:51:38 +02:00
|
|
|
void ChargeRandomFees(CConnman& connman);
|
2017-05-05 13:26:27 +02:00
|
|
|
|
|
|
|
/// Check for process
|
2017-09-19 16:51:38 +02:00
|
|
|
void CheckPool(CConnman& connman);
|
2017-05-05 13:26:27 +02:00
|
|
|
|
2017-09-19 16:51:38 +02:00
|
|
|
void CreateFinalTransaction(CConnman& connman);
|
|
|
|
void CommitFinalTransaction(CConnman& connman);
|
2017-05-05 13:26:27 +02:00
|
|
|
|
|
|
|
/// Is this nDenom and txCollateral acceptable?
|
2018-11-05 10:29:07 +01:00
|
|
|
bool IsAcceptableDSA(const CPrivateSendAccept& dsa, PoolMessage& nMessageIDRet);
|
|
|
|
bool CreateNewSession(const CPrivateSendAccept& dsa, PoolMessage& nMessageIDRet, CConnman& connman);
|
|
|
|
bool AddUserToExistingSession(const CPrivateSendAccept& dsa, PoolMessage& nMessageIDRet);
|
2017-05-05 13:26:27 +02:00
|
|
|
/// Do we have enough users to take entries?
|
2019-01-08 11:36:12 +01:00
|
|
|
bool IsSessionReady();
|
2017-05-05 13:26:27 +02:00
|
|
|
|
|
|
|
/// Check that all inputs are signed. (Are all inputs signed?)
|
|
|
|
bool IsSignaturesComplete();
|
|
|
|
/// Check to make sure a given input matches an input in the pool and its scriptSig is valid
|
|
|
|
bool IsInputScriptSigValid(const CTxIn& txin);
|
|
|
|
/// Are these outputs compatible with other client in the pool?
|
2017-12-04 07:06:07 +01:00
|
|
|
bool IsOutputsCompatibleWithSessionDenom(const std::vector<CTxOut>& vecTxOut);
|
2017-05-05 13:26:27 +02:00
|
|
|
|
|
|
|
// Set the 'state' value, with some logging and capturing when the state changed
|
|
|
|
void SetState(PoolState nStateNew);
|
|
|
|
|
|
|
|
/// Relay mixing Messages
|
2017-09-19 16:51:38 +02:00
|
|
|
void RelayFinalTransaction(const CTransaction& txFinal, CConnman& connman);
|
|
|
|
void PushStatus(CNode* pnode, PoolStatusUpdate nStatusUpdate, PoolMessage nMessageID, CConnman& connman);
|
|
|
|
void RelayStatus(PoolStatusUpdate nStatusUpdate, CConnman& connman, PoolMessage nMessageID = MSG_NOERR);
|
|
|
|
void RelayCompletedTransaction(PoolMessage nMessageID, CConnman& connman);
|
2017-05-05 13:26:27 +02:00
|
|
|
|
|
|
|
void SetNull();
|
|
|
|
|
|
|
|
public:
|
2018-11-05 10:29:07 +01:00
|
|
|
CPrivateSendServer() :
|
2019-01-08 11:36:12 +01:00
|
|
|
vecSessionCollaterals(),
|
|
|
|
nSessionMaxParticipants(0),
|
|
|
|
fUnitTest(false) {}
|
2017-05-05 13:26:27 +02:00
|
|
|
|
2017-02-06 14:31:37 +01:00
|
|
|
void ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);
|
2017-05-05 13:26:27 +02:00
|
|
|
|
2017-09-19 16:51:38 +02:00
|
|
|
void CheckTimeout(CConnman& connman);
|
|
|
|
void CheckForCompleteQueue(CConnman& connman);
|
2017-05-05 13:26:27 +02:00
|
|
|
|
2018-07-16 14:47:37 +02:00
|
|
|
void DoMaintenance(CConnman& connman);
|
|
|
|
};
|
2017-05-05 13:26:27 +02:00
|
|
|
|
|
|
|
#endif
|