8 #include "validation.h" 27 if (fHelp || params.
size() != 1)
28 throw std::runtime_error(
29 "privatesend \"command\"\n" 31 "1. \"command\" (string or set of strings, required) The command to execute\n" 32 "\nAvailable commands:\n" 33 " start - Start mixing\n" 34 " stop - Stop mixing\n" 35 " reset - Reset mixing\n" 38 if(params[0].get_str() ==
"start") {
45 return "Mixing is not supported from masternodes";
52 if(params[0].get_str() ==
"stop") {
54 return "Mixing was stopped";
57 if(params[0].get_str() ==
"reset") {
59 return "Mixing was reset";
62 return "Unknown command, please see \"help privatesend\"";
67 if (fHelp || params.
size() != 0)
68 throw std::runtime_error(
70 "Returns an object containing mixing pool related information.\n");
89 ?
"WARNING: keypool is almost depleted!" :
""));
98 std::string strCommand;
99 if (params.
size() >= 1) {
100 strCommand = params[0].
get_str();
103 if (strCommand ==
"start-many")
107 (strCommand !=
"start" && strCommand !=
"start-alias" && strCommand !=
"start-all" && strCommand !=
"start-missing" &&
108 strCommand !=
"start-disabled" && strCommand !=
"list" && strCommand !=
"list-conf" && strCommand !=
"count" &&
109 strCommand !=
"debug" && strCommand !=
"current" && strCommand !=
"winner" && strCommand !=
"winners" && strCommand !=
"genkey" &&
110 strCommand !=
"connect" && strCommand !=
"outputs" && strCommand !=
"status"))
111 throw std::runtime_error(
112 "masternode \"command\"...\n" 113 "Set of commands to execute masternode related actions\n" 115 "1. \"command\" (string or set of strings, required) The command to execute\n" 116 "\nAvailable commands:\n" 117 " count - Print number of all known masternodes (optional: 'ps', 'enabled', 'all', 'qualify')\n" 118 " current - Print info on current masternode winner to be paid the next block (calculated locally)\n" 119 " debug - Print masternode status\n" 120 " genkey - Generate new masternodeprivkey\n" 121 " outputs - Print masternode compatible outputs\n" 122 " start - Start local Hot masternode configured in dash.conf\n" 123 " start-alias - Start single remote masternode by assigned alias configured in masternode.conf\n" 124 " start-<mode> - Start remote masternodes configured in masternode.conf (<mode>: 'all', 'missing', 'disabled')\n" 125 " status - Print masternode status information\n" 126 " list - Print list of all known masternodes (see masternodelist for more info)\n" 127 " list-conf - Print masternode.conf in JSON format\n" 128 " winner - Print info on next masternode winner to vote for\n" 129 " winners - Print list of masternode winners\n" 132 if (strCommand ==
"list")
136 for (
unsigned int i = 1; i < params.
size(); i++) {
142 if(strCommand ==
"connect")
144 if (params.
size() < 2)
147 std::string strAddress = params[1].
get_str();
150 if (!
Lookup(strAddress.c_str(), addr, 0,
false))
158 return "successfully connected";
161 if (strCommand ==
"count")
163 if (params.
size() > 2)
166 if (params.
size() == 1)
169 std::string strMode = params[1].
get_str();
174 if (strMode ==
"enabled")
181 if (strMode ==
"qualify")
184 if (strMode ==
"all")
185 return strprintf(
"Total: %d (PS Compatible: %d / Enabled: %d / Qualify: %d)",
190 if (strCommand ==
"current" || strCommand ==
"winner")
200 nHeight = pindex->
nHeight + (strCommand ==
"current" ? 1 : 10);
218 if (strCommand ==
"debug")
233 if (strCommand ==
"start")
251 if (strCommand ==
"start-alias")
253 if (params.
size() < 2)
261 std::string strAlias = params[1].
get_str();
271 std::string strError;
276 statusObj.
push_back(
Pair(
"result", fResult ?
"successful" :
"failed"));
290 statusObj.
push_back(
Pair(
"errorMessage",
"Could not find alias in config. Verify with list-conf."));
297 if (strCommand ==
"start-all" || strCommand ==
"start-missing" || strCommand ==
"start-disabled")
314 std::string strError;
321 if(strCommand ==
"start-missing" && fFound)
continue;
322 if(strCommand ==
"start-disabled" && fFound && mn.IsEnabled())
continue;
328 statusObj.push_back(
Pair(
"result", fResult ?
"successful" :
"failed"));
336 statusObj.push_back(
Pair(
"errorMessage", strError));
344 returnObj.
push_back(
Pair(
"overall",
strprintf(
"Successfully started %d masternodes, failed to start %d, total %d", nSuccessful, nFailed, nSuccessful + nFailed)));
350 if (strCommand ==
"genkey")
358 if (strCommand ==
"list-conf")
367 std::string strStatus = fFound ? mn.GetStatus() :
"MISSING";
382 if (strCommand ==
"outputs") {
384 std::vector<COutput> vPossibleCoins;
396 if (strCommand ==
"status")
415 if (strCommand ==
"winners")
427 std::string strFilter =
"";
429 if (params.
size() >= 2) {
430 nLast =
atoi(params[1].get_str());
433 if (params.
size() == 3) {
434 strFilter = params[2].
get_str();
437 if (params.
size() > 3)
442 for(
int i = nHeight - nLast; i < nHeight + 20; i++) {
444 if (strFilter !=
"" && strPayment.find(strFilter) == std::string::npos)
continue;
456 std::string strMode =
"status";
457 std::string strFilter =
"";
459 if (params.
size() >= 1) strMode = params[0].get_str();
460 if (params.
size() == 2) strFilter = params[1].get_str();
463 strMode !=
"activeseconds" && strMode !=
"addr" && strMode !=
"full" && strMode !=
"info" &&
464 strMode !=
"lastseen" && strMode !=
"lastpaidtime" && strMode !=
"lastpaidblock" &&
465 strMode !=
"protocol" && strMode !=
"payee" && strMode !=
"pubkey" &&
466 strMode !=
"rank" && strMode !=
"status"))
468 throw std::runtime_error(
469 "masternodelist ( \"mode\" \"filter\" )\n" 470 "Get a list of masternodes in different modes\n" 472 "1. \"mode\" (string, optional/required to use filter, defaults = status) The mode to run list in\n" 473 "2. \"filter\" (string, optional) Filter results. Partial match by outpoint by default in all modes,\n" 474 " additional matches in some modes are also available\n" 475 "\nAvailable modes:\n" 476 " activeseconds - Print number of seconds masternode recognized by the network as enabled\n" 477 " (since latest issued \"masternode start/start-many/start-alias\")\n" 478 " addr - Print ip address associated with a masternode (can be additionally filtered, partial match)\n" 479 " full - Print info in format 'status protocol payee lastseen activeseconds lastpaidtime lastpaidblock IP'\n" 480 " (can be additionally filtered, partial match)\n" 481 " info - Print info in format 'status protocol payee lastseen activeseconds sentinelversion sentinelstate IP'\n" 482 " (can be additionally filtered, partial match)\n" 483 " lastpaidblock - Print the last block height a node was paid on the network\n" 484 " lastpaidtime - Print the last time a node was paid on the network\n" 485 " lastseen - Print timestamp of when a masternode was last seen on the network\n" 486 " payee - Print Dash address associated with a masternode (can be additionally filtered,\n" 488 " protocol - Print protocol of a masternode (can be additionally filtered, exact match))\n" 489 " pubkey - Print the masternode (not collateral) public key\n" 490 " rank - Print rank of a masternode based on current block\n" 491 " status - Print masternode status: PRE_ENABLED / ENABLED / EXPIRED / WATCHDOG_EXPIRED / NEW_START_REQUIRED /\n" 492 " UPDATE_REQUIRED / POSE_BAN / OUTPOINT_SPENT (can be additionally filtered, partial match)\n" 496 if (strMode ==
"full" || strMode ==
"lastpaidtime" || strMode ==
"lastpaidblock") {
506 if (strMode ==
"rank") {
511 if (strFilter !=
"" && strOutpoint.find(strFilter) == std::string::npos)
continue;
516 for (
auto& mnpair : mapMasternodes) {
518 std::string strOutpoint = mnpair.first.ToStringShort();
519 if (strMode ==
"activeseconds") {
520 if (strFilter !=
"" && strOutpoint.find(strFilter) == std::string::npos)
continue;
522 }
else if (strMode ==
"addr") {
524 if (strFilter !=
"" && strAddress.find(strFilter) == std::string::npos &&
525 strOutpoint.find(strFilter) == std::string::npos)
continue;
527 }
else if (strMode ==
"full") {
528 std::ostringstream streamFull;
529 streamFull << std::setw(18) <<
538 std::string strFull = streamFull.str();
539 if (strFilter !=
"" && strFull.find(strFilter) == std::string::npos &&
540 strOutpoint.find(strFilter) == std::string::npos)
continue;
542 }
else if (strMode ==
"info") {
543 std::ostringstream streamInfo;
544 streamInfo << std::setw(18) <<
553 std::string strInfo = streamInfo.str();
554 if (strFilter !=
"" && strInfo.find(strFilter) == std::string::npos &&
555 strOutpoint.find(strFilter) == std::string::npos)
continue;
557 }
else if (strMode ==
"lastpaidblock") {
558 if (strFilter !=
"" && strOutpoint.find(strFilter) == std::string::npos)
continue;
560 }
else if (strMode ==
"lastpaidtime") {
561 if (strFilter !=
"" && strOutpoint.find(strFilter) == std::string::npos)
continue;
563 }
else if (strMode ==
"lastseen") {
564 if (strFilter !=
"" && strOutpoint.find(strFilter) == std::string::npos)
continue;
566 }
else if (strMode ==
"payee") {
568 std::string strPayee = address.
ToString();
569 if (strFilter !=
"" && strPayee.find(strFilter) == std::string::npos &&
570 strOutpoint.find(strFilter) == std::string::npos)
continue;
572 }
else if (strMode ==
"protocol") {
574 strOutpoint.find(strFilter) == std::string::npos)
continue;
576 }
else if (strMode ==
"pubkey") {
577 if (strFilter !=
"" && strOutpoint.find(strFilter) == std::string::npos)
continue;
579 }
else if (strMode ==
"status") {
581 if (strFilter !=
"" && strStatus.find(strFilter) == std::string::npos &&
582 strOutpoint.find(strFilter) == std::string::npos)
continue;
590 bool DecodeHexVecMnb(std::vector<CMasternodeBroadcast>& vecMnb, std::string strHexMnb) {
592 if (!
IsHex(strHexMnb))
595 std::vector<unsigned char> mnbData(
ParseHex(strHexMnb));
600 catch (
const std::exception&) {
609 std::string strCommand;
610 if (params.
size() >= 1)
611 strCommand = params[0].get_str();
614 (strCommand !=
"create-alias" && strCommand !=
"create-all" && strCommand !=
"decode" && strCommand !=
"relay"))
615 throw std::runtime_error(
616 "masternodebroadcast \"command\"...\n" 617 "Set of commands to create and relay masternode broadcast messages\n" 619 "1. \"command\" (string or set of strings, required) The command to execute\n" 620 "\nAvailable commands:\n" 621 " create-alias - Create single remote masternode broadcast message by assigned alias configured in masternode.conf\n" 622 " create-all - Create remote masternode broadcast messages for all masternodes configured in masternode.conf\n" 623 " decode - Decode masternode broadcast message\n" 624 " relay - Relay masternode broadcast message to the network\n" 627 if (strCommand ==
"create-alias")
633 if (params.
size() < 2)
642 std::string strAlias = params[1].
get_str();
645 std::vector<CMasternodeBroadcast> vecMnb;
652 std::string strError;
657 statusObj.
push_back(
Pair(
"result", fResult ?
"successful" :
"failed"));
659 vecMnb.push_back(mnb);
672 statusObj.
push_back(
Pair(
"errorMessage",
"Could not find alias in config. Verify with list-conf."));
679 if (strCommand ==
"create-all")
690 std::vector<CMasternodeConfig::CMasternodeEntry> mnEntries;
697 std::vector<CMasternodeBroadcast> vecMnb;
700 std::string strError;
707 statusObj.push_back(
Pair(
"result", fResult ?
"successful" :
"failed"));
711 vecMnb.push_back(mnb);
714 statusObj.push_back(
Pair(
"errorMessage", strError));
723 returnObj.
push_back(
Pair(
"overall",
strprintf(
"Successfully created broadcast messages for %d masternodes, failed to create %d, total %d", nSuccessful, nFailed, nSuccessful + nFailed)));
730 if (strCommand ==
"decode")
732 if (params.
size() != 2)
735 std::vector<CMasternodeBroadcast> vecMnb;
768 resultObj.
push_back(
Pair(
"errorMessage",
"Masternode broadcast signature verification failed"));
774 returnObj.
push_back(
Pair(
"overall",
strprintf(
"Successfully decoded broadcast messages for %d masternodes, failed to decode %d, total %d", nSuccessful, nFailed, nSuccessful + nFailed)));
779 if (strCommand ==
"relay")
781 if (params.
size() < 2 || params.
size() > 3)
784 "1. \"hex\" (string, required) Broadcast messages hex string\n" 785 "2. fast (string, optional) If none, using safe method\n");
787 std::vector<CMasternodeBroadcast> vecMnb;
794 bool fSafe = params.
size() == 2;
815 }
else fResult =
false;
822 resultObj.
push_back(
Pair(
"errorMessage",
"Masternode broadcast signature verification failed"));
828 returnObj.
push_back(
Pair(
"overall",
strprintf(
"Successfully relayed broadcast messages for %d masternodes, failed to relay %d, total %d", nSuccessful, nFailed, nSuccessful + nFailed)));
838 if (fHelp || params.
size() != 1) {
839 throw std::runtime_error(
840 "sentinelping version\n" 843 "1. version (string, required) Sentinel version in the form \"x.x.x\"\n" 845 "state (boolean) Ping result\n"
void EnsureWalletIsUnlocked()
std::string GetStateString() const
uint32_t nSentinelVersion
CMasternodeSync masternodeSync
CPrivateSendServer privateSendServer
std::vector< CMasternodeEntry > & getEntries()
bool CheckMnbAndUpdateMasternodeList(CNode *pfrom, CMasternodeBroadcast mnb, int &nDos, CConnman &connman)
Perform complete check and only then update list and maps.
CMasternodeConfig masternodeConfig
CActiveMasternode activeMasternode
void Relay(CConnman &connman)
std::string GetStatus() const
UniValue privatesend(const UniValue ¶ms, bool fHelp)
CCriticalSection cs_wallet
const std::string & getOutputIndex() const
bool Get(const COutPoint &outpoint, CMasternode &masternodeRet)
Versions of Find that are safe to use from outside the class.
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
static const int PRIVATESEND_KEYS_THRESHOLD_WARNING
std::vector< unsigned char > vchSig
const_iterator end() const
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
const std::string & getTxHash() const
bool GetMasternodeRanks(rank_pair_vec_t &vecMasternodeRanksRet, int nBlockHeight=-1, int nMinProtocol=0)
UniValue sentinelping(const UniValue ¶ms, bool fHelp)
bool IsHex(const string &str)
masternode_info_t infoMixingMasternode
std::string ToString(bool fUseGetnameinfo=true) const
bool DecodeHexVecMnb(std::vector< CMasternodeBroadcast > &vecMnb, std::string strHexMnb)
bool push_back(const UniValue &val)
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Ran out of memory during operation.
std::vector< unsigned char > vchSig
const std::string & getIp() const
std::string ToString() const
string EncodeBase64(const unsigned char *pch, size_t len)
uint32_t StringVersionToInt(const std::string &strVersion)
Converts version strings to 4-byte unsigned integer.
std::string SafeIntVersionToString(uint32_t nVersion)
Copy of the IntVersionToString, that returns "Invalid version" string instead of throwing std::bad_ca...
void UpdateLastPaid(const CBlockIndex *pindex)
std::string GetStatus() const
bool UpdateSentinelPing(int version)
std::string GetRequiredPaymentsString(int nBlockHeight)
const_iterator begin() const
UniValue masternode(const UniValue ¶ms, bool fHelp)
static const int ACTIVE_MASTERNODE_INITIAL
uint256 uint256S(const char *str)
bool GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int &nCountRet, masternode_info_t &mnInfoRet)
Find an entry in the masternode list that is next to be paid.
static bool Create(const COutPoint &outpoint, const CService &service, const CKey &keyCollateralAddressNew, const CPubKey &pubKeyCollateralAddressNew, const CKey &keyMasternodeNew, const CPubKey &pubKeyMasternodeNew, std::string &strErrorRet, CMasternodeBroadcast &mnbRet)
Create Masternode broadcast, needs to be relayed manually after that.
vector< unsigned char > ParseHex(const char *psz)
std::vector< rank_pair_t > rank_pair_vec_t
std::string ToString() const
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
int size()
Return the number of (unique) Masternodes.
static const int ACTIVE_MASTERNODE_STARTED
UniValue masternodebroadcast(const UniValue ¶ms, bool fHelp)
void ManageState(CConnman &connman)
Manage state of active Masternode.
CPrivateSendClient privateSendClient
UniValue masternodelist(const UniValue ¶ms, bool fHelp)
CPubKey pubKeyCollateralAddress
int CountEnabled(int nProtocolVersion=-1)
std::map< COutPoint, CMasternode > GetFullMasternodeMap()
int GetEntriesCount() const
bool CheckSignature(int &nDos)
static const int PROTOCOL_VERSION
bool IsBlockchainSynced()
bool Lookup(const char *pszName, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
static const int MIN_PRIVATESEND_PEER_PROTO_VERSION
minimum peer version accepted by mixing pool
std::unique_ptr< CConnman > g_connman
const UniValue NullUniValue
void NotifyMasternodeUpdates(CConnman &connman)
CBlockIndex * Tip() const
const std::string & getAlias() const
bool GetMasternodeOutpointAndKeys(COutPoint &outpointRet, CPubKey &pubKeyRet, CKey &keyRet, std::string strTxHash="", std::string strOutputIndex="")
Get 1000DASH output and keys which can be used for the Masternode.
void UpdateMasternodeList(CMasternodeBroadcast mnb, CConnman &connman)
Update masternode list and maps using provided CMasternodeBroadcast.
Dash Core is not connected.
UniValue getpoolinfo(const UniValue ¶ms, bool fHelp)
bool DoAutomaticDenominating(CConnman &connman, bool fDryRun=false)
Passively run mixing in the background according to the configuration in settings.
int nHeight
height of the entry in the chain. The genesis block has height 0
std::string ToStringShort() const
const std::string & getPrivKey() const
bool IsMasternodeListSynced()
UniValue JSONRPCError(int code, const string &message)
int64_t nKeysLeftSinceAutoBackup
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
std::string get_str() const
int atoi(const std::string &str)
bool fPrivateSendMultiSession
void AvailableCoins(std::vector< COutput > &vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL, bool fIncludeZeroValue=false, AvailableCoinsType nCoinType=ALL_COINS, bool fUseInstantSend=false) const