mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
privatesend|qt|rpc|wallet: Improve CPrivateSendClientOptions
- Makes it singleton to make sure we always only have one instance of it - Protects its members by making them private and adding set/getters - Makes it thread safe
This commit is contained in:
parent
50b09b88e4
commit
8fedc083fc
@ -24,12 +24,14 @@
|
||||
|
||||
std::map<const std::string, CPrivateSendClientManager*> privateSendClientManagers;
|
||||
CPrivateSendClientQueueManager privateSendClientQueueManager;
|
||||
CPrivateSendClientOptions privateSendClientOptions;
|
||||
|
||||
CPrivateSendClientOptions* CPrivateSendClientOptions::_instance{nullptr};
|
||||
std::once_flag CPrivateSendClientOptions::onceFlag;
|
||||
|
||||
void CPrivateSendClientQueueManager::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman, bool enable_bip61)
|
||||
{
|
||||
if (fMasternodeMode) return;
|
||||
if (!privateSendClientOptions.fEnablePrivateSend) return;
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) return;
|
||||
if (!masternodeSync.IsBlockchainSynced()) return;
|
||||
|
||||
if (!CheckDiskSpace()) {
|
||||
@ -122,7 +124,7 @@ void CPrivateSendClientQueueManager::ProcessMessage(CNode* pfrom, const std::str
|
||||
void CPrivateSendClientManager::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman, bool enable_bip61)
|
||||
{
|
||||
if (fMasternodeMode) return;
|
||||
if (!privateSendClientOptions.fEnablePrivateSend) return;
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) return;
|
||||
if (!masternodeSync.IsBlockchainSynced()) return;
|
||||
|
||||
if (!CheckDiskSpace()) {
|
||||
@ -145,7 +147,7 @@ void CPrivateSendClientManager::ProcessMessage(CNode* pfrom, const std::string&
|
||||
void CPrivateSendClientSession::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman, bool enable_bip61)
|
||||
{
|
||||
if (fMasternodeMode) return;
|
||||
if (!privateSendClientOptions.fEnablePrivateSend) return;
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) return;
|
||||
if (!masternodeSync.IsBlockchainSynced()) return;
|
||||
|
||||
if (strCommand == NetMsgType::DSSTATUSUPDATE) {
|
||||
@ -287,7 +289,7 @@ void CPrivateSendClientSession::SetNull()
|
||||
//
|
||||
void CPrivateSendClientSession::UnlockCoins()
|
||||
{
|
||||
if (!privateSendClientOptions.fEnablePrivateSend) return;
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) return;
|
||||
|
||||
while (true) {
|
||||
TRY_LOCK(mixingWallet->cs_wallet, lockWallet);
|
||||
@ -427,7 +429,7 @@ void CPrivateSendClientManager::CheckTimeout()
|
||||
{
|
||||
if (fMasternodeMode) return;
|
||||
|
||||
if (!privateSendClientOptions.fEnablePrivateSend || !IsMixing()) return;
|
||||
if (!CPrivateSendClientOptions::IsEnabled() || !IsMixing()) return;
|
||||
|
||||
LOCK(cs_deqsessions);
|
||||
for (auto& session : deqSessions) {
|
||||
@ -551,7 +553,7 @@ void CPrivateSendClientSession::ProcessPoolStateUpdate(CPrivateSendStatusUpdate
|
||||
//
|
||||
bool CPrivateSendClientSession::SignFinalTransaction(const CTransaction& finalTransactionNew, CNode* pnode, CConnman& connman)
|
||||
{
|
||||
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false;
|
||||
if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
|
||||
|
||||
if (fMasternodeMode || pnode == nullptr) return false;
|
||||
if (!mixingMasternode) return false;
|
||||
@ -693,14 +695,14 @@ bool CPrivateSendClientManager::WaitForAnotherBlock()
|
||||
{
|
||||
if (!masternodeSync.IsBlockchainSynced()) return true;
|
||||
|
||||
if (privateSendClientOptions.fPrivateSendMultiSession) return false;
|
||||
if (CPrivateSendClientOptions::IsMultiSessionEnabled()) return false;
|
||||
|
||||
return nCachedBlockHeight - nCachedLastSuccessBlock < nMinBlocksToWait;
|
||||
}
|
||||
|
||||
bool CPrivateSendClientManager::CheckAutomaticBackup()
|
||||
{
|
||||
if (!privateSendClientOptions.fEnablePrivateSend || !IsMixing()) return false;
|
||||
if (!CPrivateSendClientOptions::IsEnabled() || !IsMixing()) return false;
|
||||
|
||||
switch (nWalletBackups) {
|
||||
case 0:
|
||||
@ -778,7 +780,7 @@ bool CPrivateSendClientSession::DoAutomaticDenominating(CConnman& connman, bool
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false;
|
||||
if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
|
||||
|
||||
CAmount nBalanceNeedsAnonymized;
|
||||
|
||||
@ -811,7 +813,7 @@ bool CPrivateSendClientSession::DoAutomaticDenominating(CConnman& connman, bool
|
||||
|
||||
// check if there is anything left to do
|
||||
CAmount nBalanceAnonymized = mixingWallet->GetAnonymizedBalance();
|
||||
nBalanceNeedsAnonymized = privateSendClientOptions.nPrivateSendAmount*COIN - nBalanceAnonymized;
|
||||
nBalanceNeedsAnonymized = CPrivateSendClientOptions::GetAmount() * COIN - nBalanceAnonymized;
|
||||
|
||||
if (nBalanceNeedsAnonymized < 0) {
|
||||
LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::DoAutomaticDenominating -- Nothing to do\n");
|
||||
@ -843,7 +845,7 @@ bool CPrivateSendClientSession::DoAutomaticDenominating(CConnman& connman, bool
|
||||
CAmount nBalanceDenominatedConf = mixingWallet->GetDenominatedBalance();
|
||||
CAmount nBalanceDenominatedUnconf = mixingWallet->GetDenominatedBalance(true);
|
||||
CAmount nBalanceDenominated = nBalanceDenominatedConf + nBalanceDenominatedUnconf;
|
||||
CAmount nBalanceToDenominate = privateSendClientOptions.nPrivateSendAmount * COIN - nBalanceDenominated;
|
||||
CAmount nBalanceToDenominate = CPrivateSendClientOptions::GetAmount() * COIN - nBalanceDenominated;
|
||||
|
||||
// adjust nBalanceNeedsAnonymized to consume final denom
|
||||
if (nBalanceDenominated - nBalanceAnonymized > nBalanceNeedsAnonymized) {
|
||||
@ -906,7 +908,7 @@ bool CPrivateSendClientSession::DoAutomaticDenominating(CConnman& connman, bool
|
||||
SetNull();
|
||||
|
||||
// should be no unconfirmed denoms in non-multi-session mode
|
||||
if (!privateSendClientOptions.fPrivateSendMultiSession && nBalanceDenominatedUnconf > 0) {
|
||||
if (!CPrivateSendClientOptions::IsMultiSessionEnabled() && nBalanceDenominatedUnconf > 0) {
|
||||
LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::DoAutomaticDenominating -- Found unconfirmed denominated outputs, will wait till they confirm to continue.\n");
|
||||
strAutoDenomResult = _("Found unconfirmed denominated outputs, will wait till they confirm to continue.");
|
||||
return false;
|
||||
@ -950,7 +952,7 @@ bool CPrivateSendClientSession::DoAutomaticDenominating(CConnman& connman, bool
|
||||
bool CPrivateSendClientManager::DoAutomaticDenominating(CConnman& connman, bool fDryRun)
|
||||
{
|
||||
if (fMasternodeMode) return false; // no client-side mixing on masternodes
|
||||
if (!privateSendClientOptions.fEnablePrivateSend || !IsMixing()) return false;
|
||||
if (!CPrivateSendClientOptions::IsEnabled() || !IsMixing()) return false;
|
||||
|
||||
if (!masternodeSync.IsBlockchainSynced()) {
|
||||
strAutoDenomResult = _("Can't mix while sync in progress.");
|
||||
@ -976,7 +978,7 @@ bool CPrivateSendClientManager::DoAutomaticDenominating(CConnman& connman, bool
|
||||
|
||||
LOCK(cs_deqsessions);
|
||||
bool fResult = true;
|
||||
if ((int)deqSessions.size() < privateSendClientOptions.nPrivateSendSessions) {
|
||||
if ((int)deqSessions.size() < CPrivateSendClientOptions::GetSessions()) {
|
||||
deqSessions.emplace_back(mixingWallet);
|
||||
}
|
||||
for (auto& session : deqSessions) {
|
||||
@ -1040,7 +1042,7 @@ CDeterministicMNCPtr CPrivateSendClientManager::GetRandomNotUsedMasternode()
|
||||
|
||||
bool CPrivateSendClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, CConnman& connman)
|
||||
{
|
||||
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false;
|
||||
if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
|
||||
|
||||
auto mnList = deterministicMNManager->GetListAtChainTip();
|
||||
|
||||
@ -1099,7 +1101,7 @@ bool CPrivateSendClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymize
|
||||
|
||||
bool CPrivateSendClientSession::StartNewQueue(CAmount nBalanceNeedsAnonymized, CConnman& connman)
|
||||
{
|
||||
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false;
|
||||
if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
|
||||
if (nBalanceNeedsAnonymized <= 0) return false;
|
||||
|
||||
int nTries = 0;
|
||||
@ -1252,7 +1254,7 @@ bool CPrivateSendClientSession::SubmitDenominate(CConnman& connman)
|
||||
|
||||
std::vector<std::pair<int, size_t> > vecInputsByRounds;
|
||||
|
||||
for (int i = 0; i < privateSendClientOptions.nPrivateSendRounds; i++) {
|
||||
for (int i = 0; i < CPrivateSendClientOptions::GetRounds(); i++) {
|
||||
if (PrepareDenominate(i, i, strError, vecPSInOutPairs, vecPSInOutPairsTmp, true)) {
|
||||
LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for %d rounds, success\n", i);
|
||||
vecInputsByRounds.emplace_back(i, vecPSInOutPairsTmp.size());
|
||||
@ -1278,7 +1280,7 @@ bool CPrivateSendClientSession::SubmitDenominate(CConnman& connman)
|
||||
}
|
||||
|
||||
// We failed? That's strange but let's just make final attempt and try to mix everything
|
||||
if (PrepareDenominate(0, privateSendClientOptions.nPrivateSendRounds - 1, strError, vecPSInOutPairs, vecPSInOutPairsTmp)) {
|
||||
if (PrepareDenominate(0, CPrivateSendClientOptions::GetRounds() - 1, strError, vecPSInOutPairs, vecPSInOutPairsTmp)) {
|
||||
LogPrint(BCLog::PRIVATESEND, "CPrivateSendClientSession::SubmitDenominate -- Running PrivateSend denominate for all rounds, success\n");
|
||||
return SendDenominate(vecPSInOutPairsTmp, connman);
|
||||
}
|
||||
@ -1291,7 +1293,7 @@ bool CPrivateSendClientSession::SubmitDenominate(CConnman& connman)
|
||||
|
||||
bool CPrivateSendClientSession::SelectDenominate(std::string& strErrorRet, std::vector<std::pair<CTxDSIn, CTxOut> >& vecPSInOutPairsRet)
|
||||
{
|
||||
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false;
|
||||
if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
|
||||
|
||||
if (mixingWallet->IsLocked(true)) {
|
||||
strErrorRet = "Wallet locked, unable to create transaction!";
|
||||
@ -1376,7 +1378,7 @@ bool CPrivateSendClientSession::PrepareDenominate(int nMinRounds, int nMaxRounds
|
||||
// Create collaterals by looping through inputs grouped by addresses
|
||||
bool CPrivateSendClientSession::MakeCollateralAmounts(CConnman& connman)
|
||||
{
|
||||
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false;
|
||||
if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
|
||||
|
||||
LOCK2(cs_main, mempool.cs);
|
||||
LOCK(mixingWallet->cs_wallet);
|
||||
@ -1420,7 +1422,7 @@ bool CPrivateSendClientSession::MakeCollateralAmounts(const CompactTallyItem& ta
|
||||
AssertLockHeld(mempool.cs);
|
||||
AssertLockHeld(mixingWallet->cs_wallet);
|
||||
|
||||
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false;
|
||||
if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
|
||||
|
||||
// Skip way too tiny amounts
|
||||
if (tallyItem.nAmount < CPrivateSend::GetCollateralAmount()) {
|
||||
@ -1515,7 +1517,7 @@ bool CPrivateSendClientSession::MakeCollateralAmounts(const CompactTallyItem& ta
|
||||
// Create denominations by looping through inputs grouped by addresses
|
||||
bool CPrivateSendClientSession::CreateDenominated(CAmount nBalanceToDenominate, CConnman& connman)
|
||||
{
|
||||
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false;
|
||||
if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
|
||||
|
||||
LOCK2(cs_main, mempool.cs);
|
||||
LOCK(mixingWallet->cs_wallet);
|
||||
@ -1553,7 +1555,7 @@ bool CPrivateSendClientSession::CreateDenominated(CAmount nBalanceToDenominate,
|
||||
AssertLockHeld(mempool.cs);
|
||||
AssertLockHeld(mixingWallet->cs_wallet);
|
||||
|
||||
if (!privateSendClientOptions.fEnablePrivateSend || !mixingWallet) return false;
|
||||
if (!CPrivateSendClientOptions::IsEnabled() || !mixingWallet) return false;
|
||||
|
||||
std::vector<CRecipient> vecSend;
|
||||
CKeyHolderStorage keyHolderStorageDenom;
|
||||
@ -1623,7 +1625,7 @@ bool CPrivateSendClientSession::CreateDenominated(CAmount nBalanceToDenominate,
|
||||
};
|
||||
|
||||
// add each output up to 11 times or until it can't be added again or until we reach nPrivateSendDenomsGoal
|
||||
while (needMoreOutputs() && nOutputs <= 10 && currentDenomIt->second < privateSendClientOptions.nPrivateSendDenomsGoal) {
|
||||
while (needMoreOutputs() && nOutputs <= 10 && currentDenomIt->second < CPrivateSendClientOptions::GetDenomsGoal()) {
|
||||
CScript scriptDenom = keyHolderStorageDenom.AddKey(mixingWallet);
|
||||
|
||||
vecSend.push_back((CRecipient) {scriptDenom, nDenomValue, false});
|
||||
@ -1646,7 +1648,7 @@ bool CPrivateSendClientSession::CreateDenominated(CAmount nBalanceToDenominate,
|
||||
for (const auto it : mapDenomCount) {
|
||||
// Check if this specific denom could use another loop, check that there aren't nPrivateSendDenomsGoal of this
|
||||
// denom and that our nValueLeft/nBalanceToDenominate is enough to create one of these denoms, if so, loop again.
|
||||
if (it.second < privateSendClientOptions.nPrivateSendDenomsGoal && (nValueLeft >= it.first + nOutputFee) && nBalanceToDenominate > 0) {
|
||||
if (it.second < CPrivateSendClientOptions::GetDenomsGoal() && (nValueLeft >= it.first + nOutputFee) && nBalanceToDenominate > 0) {
|
||||
finished = false;
|
||||
LogPrint(BCLog::PRIVATESEND,
|
||||
"CPrivateSendClientSession::CreateDenominated -- 1 - NOT finished - nDenomValue: %f, count: %d, nValueLeft: %f, nBalanceToDenominate: %f\n",
|
||||
@ -1686,7 +1688,7 @@ bool CPrivateSendClientSession::CreateDenominated(CAmount nBalanceToDenominate,
|
||||
auto it = mapDenomCount.find(nDenomValue);
|
||||
for (int i = 0; i < denomsToCreate; i++) {
|
||||
// Never go above the cap unless it's the largest denom
|
||||
if (nDenomValue != nLargestDenomValue && it->second >= privateSendClientOptions.nPrivateSendDenomsHardCap) break;
|
||||
if (nDenomValue != nLargestDenomValue && it->second >= CPrivateSendClientOptions::GetDenomsHardCap()) break;
|
||||
|
||||
CScript scriptDenom = keyHolderStorageDenom.AddKey(mixingWallet);
|
||||
vecSend.push_back((CRecipient) {scriptDenom, nDenomValue, false});
|
||||
@ -1785,7 +1787,7 @@ void CPrivateSendClientManager::UpdatedBlockTip(const CBlockIndex* pindex)
|
||||
|
||||
void CPrivateSendClientQueueManager::DoMaintenance()
|
||||
{
|
||||
if (!privateSendClientOptions.fEnablePrivateSend) return;
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) return;
|
||||
if (fMasternodeMode) return; // no client-side mixing on masternodes
|
||||
|
||||
if (!masternodeSync.IsBlockchainSynced() || ShutdownRequested()) return;
|
||||
@ -1795,7 +1797,7 @@ void CPrivateSendClientQueueManager::DoMaintenance()
|
||||
|
||||
void CPrivateSendClientManager::DoMaintenance(CConnman& connman)
|
||||
{
|
||||
if (!privateSendClientOptions.fEnablePrivateSend) return;
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) return;
|
||||
if (fMasternodeMode) return; // no client-side mixing on masternodes
|
||||
|
||||
if (!masternodeSync.IsBlockchainSynced() || ShutdownRequested()) return;
|
||||
@ -1843,18 +1845,6 @@ void CPrivateSendClientManager::GetJsonInfo(UniValue& obj) const
|
||||
obj.pushKV("sessions", arrSessions);
|
||||
}
|
||||
|
||||
void CPrivateSendClientOptions::GetJsonInfo(UniValue& obj) const
|
||||
{
|
||||
assert(obj.isObject());
|
||||
obj.pushKV("enabled", privateSendClientOptions.fEnablePrivateSend);
|
||||
obj.pushKV("multisession", privateSendClientOptions.fPrivateSendMultiSession);
|
||||
obj.pushKV("max_sessions", privateSendClientOptions.nPrivateSendSessions);
|
||||
obj.pushKV("max_rounds", privateSendClientOptions.nPrivateSendRounds);
|
||||
obj.pushKV("max_amount", privateSendClientOptions.nPrivateSendAmount);
|
||||
obj.pushKV("denoms_goal", privateSendClientOptions.nPrivateSendDenomsGoal);
|
||||
obj.pushKV("denoms_hardcap", privateSendClientOptions.nPrivateSendDenomsHardCap);
|
||||
}
|
||||
|
||||
void DoPrivateSendMaintenance(CConnman& connman)
|
||||
{
|
||||
privateSendClientQueueManager.DoMaintenance();
|
||||
@ -1862,3 +1852,65 @@ void DoPrivateSendMaintenance(CConnman& connman)
|
||||
pair.second->DoMaintenance(connman);
|
||||
}
|
||||
}
|
||||
|
||||
CPrivateSendClientOptions& CPrivateSendClientOptions::Get()
|
||||
{
|
||||
std::call_once(onceFlag, CPrivateSendClientOptions::Init);
|
||||
assert(CPrivateSendClientOptions::_instance);
|
||||
return *CPrivateSendClientOptions::_instance;
|
||||
}
|
||||
|
||||
void CPrivateSendClientOptions::SetEnabled(bool fEnabled)
|
||||
{
|
||||
CPrivateSendClientOptions& options = CPrivateSendClientOptions::Get();
|
||||
LOCK(options.cs_ps_options);
|
||||
options.fEnablePrivateSend = fEnabled;
|
||||
}
|
||||
|
||||
void CPrivateSendClientOptions::SetMultiSessionEnabled(bool fEnabled)
|
||||
{
|
||||
CPrivateSendClientOptions& options = CPrivateSendClientOptions::Get();
|
||||
LOCK(options.cs_ps_options);
|
||||
options.fPrivateSendMultiSession = fEnabled;
|
||||
}
|
||||
|
||||
void CPrivateSendClientOptions::SetRounds(int nRounds)
|
||||
{
|
||||
CPrivateSendClientOptions& options = CPrivateSendClientOptions::Get();
|
||||
LOCK(options.cs_ps_options);
|
||||
options.nPrivateSendRounds = nRounds;
|
||||
}
|
||||
|
||||
void CPrivateSendClientOptions::SetAmount(CAmount amount)
|
||||
{
|
||||
CPrivateSendClientOptions& options = CPrivateSendClientOptions::Get();
|
||||
LOCK(options.cs_ps_options);
|
||||
options.nPrivateSendAmount = amount;
|
||||
}
|
||||
|
||||
void CPrivateSendClientOptions::Init()
|
||||
{
|
||||
assert(!CPrivateSendClientOptions::_instance);
|
||||
static CPrivateSendClientOptions instance;
|
||||
LOCK(instance.cs_ps_options);
|
||||
instance.fPrivateSendMultiSession = gArgs.GetBoolArg("-privatesendmultisession", DEFAULT_PRIVATESEND_MULTISESSION);
|
||||
instance.nPrivateSendSessions = std::min(std::max((int)gArgs.GetArg("-privatesendsessions", DEFAULT_PRIVATESEND_SESSIONS), MIN_PRIVATESEND_SESSIONS), MAX_PRIVATESEND_SESSIONS);
|
||||
instance.nPrivateSendRounds = std::min(std::max((int)gArgs.GetArg("-privatesendrounds", DEFAULT_PRIVATESEND_ROUNDS), MIN_PRIVATESEND_ROUNDS), MAX_PRIVATESEND_ROUNDS);
|
||||
instance.nPrivateSendAmount = std::min(std::max((int)gArgs.GetArg("-privatesendamount", DEFAULT_PRIVATESEND_AMOUNT), MIN_PRIVATESEND_AMOUNT), MAX_PRIVATESEND_AMOUNT);
|
||||
instance.nPrivateSendDenomsGoal = std::min(std::max((int)gArgs.GetArg("-privatesenddenomsgoal", DEFAULT_PRIVATESEND_DENOMS_GOAL), MIN_PRIVATESEND_DENOMS_GOAL), MAX_PRIVATESEND_DENOMS_GOAL);
|
||||
instance.nPrivateSendDenomsHardCap = std::min(std::max((int)gArgs.GetArg("-privatesenddenomshardcap", DEFAULT_PRIVATESEND_DENOMS_HARDCAP), MIN_PRIVATESEND_DENOMS_HARDCAP), MAX_PRIVATESEND_DENOMS_HARDCAP);
|
||||
CPrivateSendClientOptions::_instance = &instance;
|
||||
}
|
||||
|
||||
void CPrivateSendClientOptions::GetJsonInfo(UniValue& obj)
|
||||
{
|
||||
assert(obj.isObject());
|
||||
CPrivateSendClientOptions& options = CPrivateSendClientOptions::Get();
|
||||
obj.pushKV("enabled", options.fEnablePrivateSend);
|
||||
obj.pushKV("multisession", options.fPrivateSendMultiSession);
|
||||
obj.pushKV("max_sessions", options.nPrivateSendSessions);
|
||||
obj.pushKV("max_rounds", options.nPrivateSendRounds);
|
||||
obj.pushKV("max_amount", options.nPrivateSendAmount);
|
||||
obj.pushKV("denoms_goal", options.nPrivateSendDenomsGoal);
|
||||
obj.pushKV("denoms_hardcap", options.nPrivateSendDenomsHardCap);
|
||||
}
|
||||
|
@ -61,9 +61,6 @@ extern std::map<const std::string, CPrivateSendClientManager*> privateSendClient
|
||||
// The object to track mixing queues
|
||||
extern CPrivateSendClientQueueManager privateSendClientQueueManager;
|
||||
|
||||
// The object to store application wide mixing options
|
||||
extern CPrivateSendClientOptions privateSendClientOptions;
|
||||
|
||||
class CPendingDsaRequest
|
||||
{
|
||||
private:
|
||||
@ -281,6 +278,27 @@ public:
|
||||
class CPrivateSendClientOptions
|
||||
{
|
||||
public:
|
||||
static int GetSessions() { return CPrivateSendClientOptions::Get().nPrivateSendSessions; }
|
||||
static int GetRounds() { return CPrivateSendClientOptions::Get().nPrivateSendRounds; }
|
||||
static int GetAmount() { return CPrivateSendClientOptions::Get().nPrivateSendAmount; }
|
||||
static int GetDenomsGoal() { return CPrivateSendClientOptions::Get().nPrivateSendDenomsGoal; }
|
||||
static int GetDenomsHardCap() { return CPrivateSendClientOptions::Get().nPrivateSendDenomsHardCap; }
|
||||
|
||||
static void SetEnabled(bool fEnabled);
|
||||
static void SetMultiSessionEnabled(bool fEnabled);
|
||||
static void SetRounds(int nRounds);
|
||||
static void SetAmount(CAmount amount);
|
||||
|
||||
static int IsEnabled() { return CPrivateSendClientOptions::Get().fEnablePrivateSend; }
|
||||
static int IsMultiSessionEnabled() { return CPrivateSendClientOptions::Get().fPrivateSendMultiSession; }
|
||||
|
||||
static void GetJsonInfo(UniValue& obj);
|
||||
|
||||
private:
|
||||
static CPrivateSendClientOptions* _instance;
|
||||
static std::once_flag onceFlag;
|
||||
|
||||
CCriticalSection cs_ps_options;
|
||||
int nPrivateSendSessions;
|
||||
int nPrivateSendRounds;
|
||||
int nPrivateSendAmount;
|
||||
@ -299,7 +317,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void GetJsonInfo(UniValue& obj) const;
|
||||
CPrivateSendClientOptions(const CPrivateSendClientOptions& other) = delete;
|
||||
CPrivateSendClientOptions& operator=(const CPrivateSendClientOptions&) = delete;
|
||||
|
||||
static CPrivateSendClientOptions& Get();
|
||||
static void Init();
|
||||
};
|
||||
|
||||
void DoPrivateSendMaintenance(CConnman& connman);
|
||||
|
@ -780,8 +780,8 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled)
|
||||
sendCoinsAction->setEnabled(enabled);
|
||||
sendCoinsMenuAction->setEnabled(enabled);
|
||||
#ifdef ENABLE_WALLET
|
||||
privateSendCoinsAction->setEnabled(enabled && privateSendClientOptions.fEnablePrivateSend);
|
||||
privateSendCoinsMenuAction->setEnabled(enabled && privateSendClientOptions.fEnablePrivateSend);
|
||||
privateSendCoinsAction->setEnabled(enabled && CPrivateSendClientOptions::IsEnabled());
|
||||
privateSendCoinsMenuAction->setEnabled(enabled && CPrivateSendClientOptions::IsEnabled());
|
||||
#else
|
||||
privateSendCoinsAction->setEnabled(enabled);
|
||||
privateSendCoinsMenuAction->setEnabled(enabled);
|
||||
|
@ -501,7 +501,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
|
||||
// unselect non-fully-mixed, this can happen when users switch from Send to PrivateSend
|
||||
if (coinControl()->IsUsingPrivateSend()) {
|
||||
int nRounds = model->getRealOutpointPrivateSendRounds(outpt);
|
||||
if (nRounds < privateSendClientOptions.nPrivateSendRounds) {
|
||||
if (nRounds < CPrivateSendClientOptions::GetRounds()) {
|
||||
coinControl()->UnSelect(outpt);
|
||||
fUnselectedNonMixed = true;
|
||||
continue;
|
||||
@ -707,7 +707,7 @@ void CoinControlDialog::updateView()
|
||||
COutPoint outpoint = COutPoint(out.tx->tx->GetHash(), out.i);
|
||||
int nRounds = model->getRealOutpointPrivateSendRounds(outpoint);
|
||||
|
||||
if ((coinControl()->IsUsingPrivateSend() && nRounds >= privateSendClientOptions.nPrivateSendRounds) || !(coinControl()->IsUsingPrivateSend())) {
|
||||
if ((coinControl()->IsUsingPrivateSend() && nRounds >= CPrivateSendClientOptions::GetRounds()) || !(coinControl()->IsUsingPrivateSend())) {
|
||||
nSum += out.tx->tx->vout[out.i].nValue;
|
||||
nChildren++;
|
||||
|
||||
|
@ -138,7 +138,7 @@ void OptionsModel::Init(bool resetSettings)
|
||||
settings.setValue("nPrivateSendRounds", DEFAULT_PRIVATESEND_ROUNDS);
|
||||
if (!gArgs.SoftSetArg("-privatesendrounds", settings.value("nPrivateSendRounds").toString().toStdString()))
|
||||
addOverriddenOption("-privatesendrounds");
|
||||
privateSendClientOptions.nPrivateSendRounds = settings.value("nPrivateSendRounds").toInt();
|
||||
CPrivateSendClientOptions::SetRounds(settings.value("nPrivateSendRounds").toInt());
|
||||
|
||||
if (!settings.contains("nPrivateSendAmount")) {
|
||||
// for migration from old settings
|
||||
@ -149,13 +149,13 @@ void OptionsModel::Init(bool resetSettings)
|
||||
}
|
||||
if (!gArgs.SoftSetArg("-privatesendamount", settings.value("nPrivateSendAmount").toString().toStdString()))
|
||||
addOverriddenOption("-privatesendamount");
|
||||
privateSendClientOptions.nPrivateSendAmount = settings.value("nPrivateSendAmount").toInt();
|
||||
CPrivateSendClientOptions::SetAmount(settings.value("nPrivateSendAmount").toInt());
|
||||
|
||||
if (!settings.contains("fPrivateSendMultiSession"))
|
||||
settings.setValue("fPrivateSendMultiSession", DEFAULT_PRIVATESEND_MULTISESSION);
|
||||
if (!gArgs.SoftSetBoolArg("-privatesendmultisession", settings.value("fPrivateSendMultiSession").toBool()))
|
||||
addOverriddenOption("-privatesendmultisession");
|
||||
privateSendClientOptions.fPrivateSendMultiSession = settings.value("fPrivateSendMultiSession").toBool();
|
||||
CPrivateSendClientOptions::SetMultiSessionEnabled(settings.value("fPrivateSendMultiSession").toBool());
|
||||
#endif
|
||||
|
||||
// Network
|
||||
@ -470,24 +470,24 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
|
||||
case PrivateSendRounds:
|
||||
if (settings.value("nPrivateSendRounds") != value)
|
||||
{
|
||||
privateSendClientOptions.nPrivateSendRounds = value.toInt();
|
||||
settings.setValue("nPrivateSendRounds", privateSendClientOptions.nPrivateSendRounds);
|
||||
CPrivateSendClientOptions::SetRounds(value.toInt());
|
||||
settings.setValue("nPrivateSendRounds", CPrivateSendClientOptions::GetRounds());
|
||||
Q_EMIT privateSendRoundsChanged();
|
||||
}
|
||||
break;
|
||||
case PrivateSendAmount:
|
||||
if (settings.value("nPrivateSendAmount") != value)
|
||||
{
|
||||
privateSendClientOptions.nPrivateSendAmount = value.toInt();
|
||||
settings.setValue("nPrivateSendAmount", privateSendClientOptions.nPrivateSendAmount);
|
||||
CPrivateSendClientOptions::SetAmount(value.toInt());
|
||||
settings.setValue("nPrivateSendAmount", CPrivateSendClientOptions::GetAmount());
|
||||
Q_EMIT privateSentAmountChanged();
|
||||
}
|
||||
break;
|
||||
case PrivateSendMultiSession:
|
||||
if (settings.value("fPrivateSendMultiSession") != value)
|
||||
{
|
||||
privateSendClientOptions.fPrivateSendMultiSession = value.toBool();
|
||||
settings.setValue("fPrivateSendMultiSession", privateSendClientOptions.fPrivateSendMultiSession);
|
||||
CPrivateSendClientOptions::SetMultiSessionEnabled(value.toBool());
|
||||
settings.setValue("fPrivateSendMultiSession", CPrivateSendClientOptions::IsMultiSessionEnabled());
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
@ -172,7 +172,7 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent)
|
||||
// start with displaying the "out of sync" warnings
|
||||
showOutOfSyncWarning(true);
|
||||
|
||||
if(!privateSendClientOptions.fEnablePrivateSend) return;
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) return;
|
||||
|
||||
// Disable any PS UI for masternode or when autobackup is disabled or failed for whatever reason
|
||||
if(fMasternodeMode || nWalletBackups <= 0){
|
||||
@ -310,7 +310,7 @@ void OverviewPage::setWalletModel(WalletModel *model)
|
||||
// Initialize PS UI
|
||||
privateSendStatus(true);
|
||||
|
||||
if(!privateSendClientOptions.fEnablePrivateSend) return;
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) return;
|
||||
|
||||
connect(model->getOptionsModel(), SIGNAL(privateSendRoundsChanged()), this, SLOT(updatePrivateSendProgress()));
|
||||
connect(model->getOptionsModel(), SIGNAL(privateSentAmountChanged()), this, SLOT(updatePrivateSendProgress()));
|
||||
@ -359,7 +359,7 @@ void OverviewPage::updatePrivateSendProgress()
|
||||
if(!walletModel) return;
|
||||
|
||||
QString strAmountAndRounds;
|
||||
QString strPrivateSendAmount = BitcoinUnits::formatHtmlWithUnit(nDisplayUnit, privateSendClientOptions.nPrivateSendAmount * COIN, false, BitcoinUnits::separatorAlways);
|
||||
QString strPrivateSendAmount = BitcoinUnits::formatHtmlWithUnit(nDisplayUnit, CPrivateSendClientOptions::GetAmount() * COIN, false, BitcoinUnits::separatorAlways);
|
||||
|
||||
if(currentBalance == 0)
|
||||
{
|
||||
@ -368,7 +368,7 @@ void OverviewPage::updatePrivateSendProgress()
|
||||
|
||||
// when balance is zero just show info from settings
|
||||
strPrivateSendAmount = strPrivateSendAmount.remove(strPrivateSendAmount.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1);
|
||||
strAmountAndRounds = strPrivateSendAmount + " / " + tr("%n Rounds", "", privateSendClientOptions.nPrivateSendRounds);
|
||||
strAmountAndRounds = strPrivateSendAmount + " / " + tr("%n Rounds", "", CPrivateSendClientOptions::GetRounds());
|
||||
|
||||
ui->labelAmountRounds->setToolTip(tr("No inputs detected"));
|
||||
ui->labelAmountRounds->setText(strAmountAndRounds);
|
||||
@ -380,15 +380,15 @@ void OverviewPage::updatePrivateSendProgress()
|
||||
CAmount nMaxToAnonymize = nAnonymizableBalance + currentAnonymizedBalance;
|
||||
|
||||
// If it's more than the anon threshold, limit to that.
|
||||
if(nMaxToAnonymize > privateSendClientOptions.nPrivateSendAmount*COIN) nMaxToAnonymize = privateSendClientOptions.nPrivateSendAmount*COIN;
|
||||
if (nMaxToAnonymize > CPrivateSendClientOptions::GetAmount() * COIN) nMaxToAnonymize = CPrivateSendClientOptions::GetAmount() * COIN;
|
||||
|
||||
if(nMaxToAnonymize == 0) return;
|
||||
|
||||
if(nMaxToAnonymize >= privateSendClientOptions.nPrivateSendAmount * COIN) {
|
||||
if (nMaxToAnonymize >= CPrivateSendClientOptions::GetAmount() * COIN) {
|
||||
ui->labelAmountRounds->setToolTip(tr("Found enough compatible inputs to mix %1")
|
||||
.arg(strPrivateSendAmount));
|
||||
strPrivateSendAmount = strPrivateSendAmount.remove(strPrivateSendAmount.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1);
|
||||
strAmountAndRounds = strPrivateSendAmount + " / " + tr("%n Rounds", "", privateSendClientOptions.nPrivateSendRounds);
|
||||
strAmountAndRounds = strPrivateSendAmount + " / " + tr("%n Rounds", "", CPrivateSendClientOptions::GetRounds());
|
||||
} else {
|
||||
QString strMaxToAnonymize = BitcoinUnits::formatHtmlWithUnit(nDisplayUnit, nMaxToAnonymize, false, BitcoinUnits::separatorAlways);
|
||||
ui->labelAmountRounds->setToolTip(tr("Not enough compatible inputs to mix <span style='%1'>%2</span>,<br>"
|
||||
@ -399,7 +399,7 @@ void OverviewPage::updatePrivateSendProgress()
|
||||
strMaxToAnonymize = strMaxToAnonymize.remove(strMaxToAnonymize.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1);
|
||||
strAmountAndRounds = "<span style='" + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_ERROR) + "'>" +
|
||||
QString(BitcoinUnits::factor(nDisplayUnit) == 1 ? "" : "~") + strMaxToAnonymize +
|
||||
" / " + tr("%n Rounds", "", privateSendClientOptions.nPrivateSendRounds) + "</span>";
|
||||
" / " + tr("%n Rounds", "", CPrivateSendClientOptions::GetRounds()) + "</span>";
|
||||
}
|
||||
ui->labelAmountRounds->setText(strAmountAndRounds);
|
||||
|
||||
@ -438,7 +438,7 @@ void OverviewPage::updatePrivateSendProgress()
|
||||
|
||||
// apply some weights to them ...
|
||||
float denomWeight = 1;
|
||||
float anonNormWeight = privateSendClientOptions.nPrivateSendRounds;
|
||||
float anonNormWeight = CPrivateSendClientOptions::GetRounds();
|
||||
float anonFullWeight = 2;
|
||||
float fullWeight = denomWeight + anonNormWeight + anonFullWeight;
|
||||
// ... and calculate the whole progress
|
||||
@ -454,7 +454,7 @@ void OverviewPage::updatePrivateSendProgress()
|
||||
tr("Denominated") + ": %2%<br/>" +
|
||||
tr("Partially mixed") + ": %3%<br/>" +
|
||||
tr("Mixed") + ": %4%<br/>" +
|
||||
tr("Denominated inputs have %5 of %n rounds on average", "", privateSendClientOptions.nPrivateSendRounds))
|
||||
tr("Denominated inputs have %5 of %n rounds on average", "", CPrivateSendClientOptions::GetRounds()))
|
||||
.arg(progress).arg(denomPart).arg(anonNormPart).arg(anonFullPart)
|
||||
.arg(nAverageAnonymizedRounds);
|
||||
ui->privateSendProgress->setToolTip(strToolPip);
|
||||
@ -462,10 +462,10 @@ void OverviewPage::updatePrivateSendProgress()
|
||||
|
||||
void OverviewPage::updateAdvancedPSUI(bool fShowAdvancedPSUI) {
|
||||
this->fShowAdvancedPSUI = fShowAdvancedPSUI;
|
||||
int nNumItems = (!privateSendClientOptions.fEnablePrivateSend || !fShowAdvancedPSUI) ? NUM_ITEMS : NUM_ITEMS_ADV;
|
||||
int nNumItems = (!CPrivateSendClientOptions::IsEnabled() || !fShowAdvancedPSUI) ? NUM_ITEMS : NUM_ITEMS_ADV;
|
||||
SetupTransactionList(nNumItems);
|
||||
|
||||
if (!privateSendClientOptions.fEnablePrivateSend) return;
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) return;
|
||||
|
||||
ui->framePrivateSend->setVisible(true);
|
||||
ui->labelCompletitionText->setVisible(fShowAdvancedPSUI);
|
||||
|
@ -155,13 +155,12 @@ void WalletModel::pollBalanceChanged()
|
||||
if(!lockWallet)
|
||||
return;
|
||||
|
||||
if(fForceCheckBalanceChanged || chainActive.Height() != cachedNumBlocks || privateSendClientOptions.nPrivateSendRounds != cachedPrivateSendRounds)
|
||||
{
|
||||
if (fForceCheckBalanceChanged || chainActive.Height() != cachedNumBlocks || CPrivateSendClientOptions::GetRounds() != cachedPrivateSendRounds) {
|
||||
fForceCheckBalanceChanged = false;
|
||||
|
||||
// Balance and number of transactions might have changed
|
||||
cachedNumBlocks = chainActive.Height();
|
||||
cachedPrivateSendRounds = privateSendClientOptions.nPrivateSendRounds;
|
||||
cachedPrivateSendRounds = CPrivateSendClientOptions::GetRounds();
|
||||
|
||||
checkBalanceChanged();
|
||||
if(transactionTableModel)
|
||||
|
@ -32,7 +32,7 @@ UniValue privatesend(const JSONRPCRequest& request)
|
||||
if (fMasternodeMode)
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Client-side mixing is not supported on masternodes");
|
||||
|
||||
if (!privateSendClientOptions.fEnablePrivateSend) {
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) {
|
||||
if (!gArgs.GetBoolArg("-enableprivatesend", true)) {
|
||||
// otherwise it's on by default, unless cmd line option says otherwise
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing is disabled via -enableprivatesend=0 command line option, remove it to enable mixing again");
|
||||
@ -136,7 +136,7 @@ UniValue getprivatesendinfo(const JSONRPCRequest& request)
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
|
||||
privateSendClientOptions.GetJsonInfo(obj);
|
||||
CPrivateSendClientOptions::GetJsonInfo(obj);
|
||||
|
||||
obj.pushKV("queue_size", privateSendClientQueueManager.GetQueueSize());
|
||||
|
||||
|
@ -364,7 +364,7 @@ void WalletInit::Start(CScheduler& scheduler)
|
||||
// Run a thread to flush wallet periodically
|
||||
scheduler.scheduleEvery(MaybeCompactWalletDB, 500);
|
||||
|
||||
if (!fMasternodeMode && privateSendClientOptions.fEnablePrivateSend) {
|
||||
if (!fMasternodeMode && CPrivateSendClientOptions::IsEnabled()) {
|
||||
scheduler.scheduleEvery(std::bind(&DoPrivateSendMaintenance, std::ref(*g_connman)), 1 * 1000);
|
||||
}
|
||||
}
|
||||
@ -372,7 +372,7 @@ void WalletInit::Start(CScheduler& scheduler)
|
||||
void WalletInit::Flush()
|
||||
{
|
||||
for (CWallet* pwallet : GetWallets()) {
|
||||
if (privateSendClientOptions.fEnablePrivateSend) {
|
||||
if (CPrivateSendClientOptions::IsEnabled()) {
|
||||
// Stop PrivateSend, release keys
|
||||
auto it = privateSendClientManagers.find(pwallet->GetName());
|
||||
it->second->ResetPool();
|
||||
@ -407,37 +407,24 @@ void WalletInit::AutoLockMasternodeCollaterals()
|
||||
|
||||
void WalletInit::InitPrivateSendSettings()
|
||||
{
|
||||
if (!HasWallets()) {
|
||||
privateSendClientOptions.fEnablePrivateSend = false;
|
||||
} else {
|
||||
privateSendClientOptions.fEnablePrivateSend = gArgs.GetBoolArg("-enableprivatesend", true);
|
||||
CPrivateSendClientOptions::SetEnabled(HasWallets() ? gArgs.GetBoolArg("-enableprivatesend", true) : false);
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) {
|
||||
return;
|
||||
}
|
||||
bool fAutoStart = gArgs.GetBoolArg("-privatesendautostart", DEFAULT_PRIVATESEND_AUTOSTART);
|
||||
if (privateSendClientOptions.fEnablePrivateSend) {
|
||||
for (auto& pwallet : GetWallets()) {
|
||||
if (pwallet->IsLocked()) {
|
||||
privateSendClientManagers.at(pwallet->GetName())->StopMixing();
|
||||
} else if (fAutoStart) {
|
||||
privateSendClientManagers.at(pwallet->GetName())->StartMixing(pwallet);
|
||||
}
|
||||
for (auto& pwallet : GetWallets()) {
|
||||
if (pwallet->IsLocked()) {
|
||||
privateSendClientManagers.at(pwallet->GetName())->StopMixing();
|
||||
} else if (fAutoStart) {
|
||||
privateSendClientManagers.at(pwallet->GetName())->StartMixing(pwallet);
|
||||
}
|
||||
}
|
||||
privateSendClientOptions.fPrivateSendMultiSession = gArgs.GetBoolArg("-privatesendmultisession", DEFAULT_PRIVATESEND_MULTISESSION);
|
||||
privateSendClientOptions.nPrivateSendSessions = std::min(std::max((int)gArgs.GetArg("-privatesendsessions", DEFAULT_PRIVATESEND_SESSIONS), MIN_PRIVATESEND_SESSIONS), MAX_PRIVATESEND_SESSIONS);
|
||||
privateSendClientOptions.nPrivateSendRounds = std::min(std::max((int)gArgs.GetArg("-privatesendrounds", DEFAULT_PRIVATESEND_ROUNDS), MIN_PRIVATESEND_ROUNDS), MAX_PRIVATESEND_ROUNDS);
|
||||
privateSendClientOptions.nPrivateSendAmount = std::min(std::max((int)gArgs.GetArg("-privatesendamount", DEFAULT_PRIVATESEND_AMOUNT), MIN_PRIVATESEND_AMOUNT), MAX_PRIVATESEND_AMOUNT);
|
||||
privateSendClientOptions.nPrivateSendDenomsGoal = std::min(std::max((int)gArgs.GetArg("-privatesenddenomsgoal", DEFAULT_PRIVATESEND_DENOMS_GOAL), MIN_PRIVATESEND_DENOMS_GOAL), MAX_PRIVATESEND_DENOMS_GOAL);
|
||||
privateSendClientOptions.nPrivateSendDenomsHardCap = std::min(std::max((int)gArgs.GetArg("-privatesenddenomshardcap", DEFAULT_PRIVATESEND_DENOMS_HARDCAP), MIN_PRIVATESEND_DENOMS_HARDCAP), MAX_PRIVATESEND_DENOMS_HARDCAP);
|
||||
|
||||
if (privateSendClientOptions.fEnablePrivateSend) {
|
||||
LogPrintf("PrivateSend: autostart=%d, multisession=%d," /* Continued */
|
||||
"sessions=%d, rounds=%d, amount=%d, denoms_goal=%d, denoms_hardcap=%d\n",
|
||||
fAutoStart, privateSendClientOptions.fPrivateSendMultiSession,
|
||||
privateSendClientOptions.nPrivateSendSessions, privateSendClientOptions.nPrivateSendRounds,
|
||||
privateSendClientOptions.nPrivateSendAmount,
|
||||
privateSendClientOptions.nPrivateSendDenomsGoal, privateSendClientOptions.nPrivateSendDenomsHardCap);
|
||||
}
|
||||
|
||||
LogPrintf("PrivateSend: autostart=%d, multisession=%d," /* Continued */
|
||||
"sessions=%d, rounds=%d, amount=%d, denoms_goal=%d, denoms_hardcap=%d\n",
|
||||
fAutoStart, CPrivateSendClientOptions::IsMultiSessionEnabled(),
|
||||
CPrivateSendClientOptions::GetSessions(), CPrivateSendClientOptions::GetRounds(),
|
||||
CPrivateSendClientOptions::GetAmount(), CPrivateSendClientOptions::GetDenomsGoal(),
|
||||
CPrivateSendClientOptions::GetDenomsHardCap());
|
||||
}
|
||||
|
||||
void WalletInit::InitKeePass()
|
||||
|
@ -2682,7 +2682,7 @@ UniValue setprivatesendrounds(const JSONRPCRequest& request)
|
||||
if (nRounds > MAX_PRIVATESEND_ROUNDS || nRounds < MIN_PRIVATESEND_ROUNDS)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid number of rounds");
|
||||
|
||||
privateSendClientOptions.nPrivateSendRounds = nRounds;
|
||||
CPrivateSendClientOptions::SetRounds(nRounds);
|
||||
|
||||
return NullUniValue;
|
||||
}
|
||||
@ -2710,7 +2710,7 @@ UniValue setprivatesendamount(const JSONRPCRequest& request)
|
||||
if (nAmount > MAX_PRIVATESEND_AMOUNT || nAmount < MIN_PRIVATESEND_AMOUNT)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount of " + CURRENCY_UNIT + " as mixing goal amount");
|
||||
|
||||
privateSendClientOptions.nPrivateSendAmount = nAmount;
|
||||
CPrivateSendClientOptions::SetAmount(nAmount);
|
||||
|
||||
return NullUniValue;
|
||||
}
|
||||
|
@ -1662,7 +1662,7 @@ int CWallet::GetCappedOutpointPrivateSendRounds(const COutPoint& outpoint) const
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
int realPrivateSendRounds = GetRealOutpointPrivateSendRounds(outpoint);
|
||||
return realPrivateSendRounds > privateSendClientOptions.nPrivateSendRounds ? privateSendClientOptions.nPrivateSendRounds : realPrivateSendRounds;
|
||||
return realPrivateSendRounds > CPrivateSendClientOptions::GetRounds() ? CPrivateSendClientOptions::GetRounds() : realPrivateSendRounds;
|
||||
}
|
||||
|
||||
bool CWallet::IsDenominated(const COutPoint& outpoint) const
|
||||
@ -2364,7 +2364,7 @@ CAmount CWalletTx::GetAnonymizedCredit(bool fUseCache) const
|
||||
if (pwallet->IsSpent(hashTx, i) || !CPrivateSend::IsDenominatedAmount(txout.nValue)) continue;
|
||||
|
||||
const int nRounds = pwallet->GetCappedOutpointPrivateSendRounds(outpoint);
|
||||
if (nRounds >= privateSendClientOptions.nPrivateSendRounds){
|
||||
if (nRounds >= CPrivateSendClientOptions::GetRounds()) {
|
||||
nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE);
|
||||
if (!MoneyRange(nCredit))
|
||||
throw std::runtime_error(std::string(__func__) + ": value out of range");
|
||||
@ -2573,7 +2573,7 @@ CAmount CWallet::GetBalance() const
|
||||
|
||||
CAmount CWallet::GetAnonymizableBalance(bool fSkipDenominated, bool fSkipUnconfirmed) const
|
||||
{
|
||||
if(!privateSendClientOptions.fEnablePrivateSend) return 0;
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) return 0;
|
||||
|
||||
std::vector<CompactTallyItem> vecTally;
|
||||
if(!SelectCoinsGroupedByAddresses(vecTally, fSkipDenominated, true, fSkipUnconfirmed)) return 0;
|
||||
@ -2595,7 +2595,7 @@ CAmount CWallet::GetAnonymizableBalance(bool fSkipDenominated, bool fSkipUnconfi
|
||||
|
||||
CAmount CWallet::GetAnonymizedBalance() const
|
||||
{
|
||||
if(!privateSendClientOptions.fEnablePrivateSend) return 0;
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) return 0;
|
||||
|
||||
CAmount nTotal = 0;
|
||||
|
||||
@ -2612,7 +2612,7 @@ CAmount CWallet::GetAnonymizedBalance() const
|
||||
// that's ok as long as we use it for informational purposes only
|
||||
float CWallet::GetAverageAnonymizedRounds() const
|
||||
{
|
||||
if(!privateSendClientOptions.fEnablePrivateSend) return 0;
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) return 0;
|
||||
|
||||
int nTotal = 0;
|
||||
int nCount = 0;
|
||||
@ -2634,7 +2634,7 @@ float CWallet::GetAverageAnonymizedRounds() const
|
||||
// that's ok as long as we use it for informational purposes only
|
||||
CAmount CWallet::GetNormalizedAnonymizedBalance() const
|
||||
{
|
||||
if(!privateSendClientOptions.fEnablePrivateSend) return 0;
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) return 0;
|
||||
|
||||
CAmount nTotal = 0;
|
||||
|
||||
@ -2648,7 +2648,7 @@ CAmount CWallet::GetNormalizedAnonymizedBalance() const
|
||||
if (it->second.GetDepthInMainChain() < 0) continue;
|
||||
|
||||
int nRounds = GetCappedOutpointPrivateSendRounds(outpoint);
|
||||
nTotal += nValue * nRounds / privateSendClientOptions.nPrivateSendRounds;
|
||||
nTotal += nValue * nRounds / CPrivateSendClientOptions::GetRounds();
|
||||
}
|
||||
|
||||
return nTotal;
|
||||
@ -2656,7 +2656,7 @@ CAmount CWallet::GetNormalizedAnonymizedBalance() const
|
||||
|
||||
CAmount CWallet::GetDenominatedBalance(bool unconfirmed) const
|
||||
{
|
||||
if(!privateSendClientOptions.fEnablePrivateSend) return 0;
|
||||
if (!CPrivateSendClientOptions::IsEnabled()) return 0;
|
||||
|
||||
CAmount nTotal = 0;
|
||||
|
||||
@ -2831,11 +2831,11 @@ void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, const
|
||||
if (nCoinType == CoinType::ONLY_FULLY_MIXED) {
|
||||
if (!CPrivateSend::IsDenominatedAmount(pcoin->tx->vout[i].nValue)) continue;
|
||||
int nRounds = GetCappedOutpointPrivateSendRounds(COutPoint(wtxid, i));
|
||||
found = nRounds >= privateSendClientOptions.nPrivateSendRounds;
|
||||
found = nRounds >= CPrivateSendClientOptions::GetRounds();
|
||||
} else if(nCoinType == CoinType::ONLY_READY_TO_MIX) {
|
||||
if (!CPrivateSend::IsDenominatedAmount(pcoin->tx->vout[i].nValue)) continue;
|
||||
int nRounds = GetCappedOutpointPrivateSendRounds(COutPoint(wtxid, i));
|
||||
found = nRounds < privateSendClientOptions.nPrivateSendRounds;
|
||||
found = nRounds < CPrivateSendClientOptions::GetRounds();
|
||||
} else if(nCoinType == CoinType::ONLY_NONDENOMINATED) {
|
||||
if (CPrivateSend::IsCollateralAmount(pcoin->tx->vout[i].nValue)) continue; // do not use collateral amounts
|
||||
found = !CPrivateSend::IsDenominatedAmount(pcoin->tx->vout[i].nValue);
|
||||
@ -3217,7 +3217,7 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
|
||||
// Make sure to include mixed preset inputs only,
|
||||
// even if some non-mixed inputs were manually selected via CoinControl
|
||||
int nRounds = GetRealOutpointPrivateSendRounds(outpoint);
|
||||
if (nRounds < privateSendClientOptions.nPrivateSendRounds) continue;
|
||||
if (nRounds < CPrivateSendClientOptions::GetRounds()) continue;
|
||||
}
|
||||
nValueFromPresetInputs += pcoin->tx->vout[outpoint.n].nValue;
|
||||
setPresetCoins.insert(CInputCoin(pcoin, outpoint.n));
|
||||
@ -3420,7 +3420,7 @@ bool CWallet::SelectCoinsGroupedByAddresses(std::vector<CompactTallyItem>& vecTa
|
||||
// otherwise they will just lead to higher fee / lower priority
|
||||
if(wtx.tx->vout[i].nValue <= nSmallestDenom/10) continue;
|
||||
// ignore mixed
|
||||
if(GetCappedOutpointPrivateSendRounds(COutPoint(outpoint.hash, i)) >= privateSendClientOptions.nPrivateSendRounds) continue;
|
||||
if (GetCappedOutpointPrivateSendRounds(COutPoint(outpoint.hash, i)) >= CPrivateSendClientOptions::GetRounds()) continue;
|
||||
}
|
||||
|
||||
if (itTallyItem == mapTally.end()) {
|
||||
|
Loading…
Reference in New Issue
Block a user