10 #include <validation.h> 27 #endif // ENABLE_WALLET 37 throw std::runtime_error(
38 "masternodelist ( \"mode\" \"filter\" )\n" 39 "Get a list of masternodes in different modes. This call is identical to 'masternode list' call.\n" 41 "1. \"mode\" (string, optional/required to use filter, defaults = json) The mode to run list in\n" 42 "2. \"filter\" (string, optional) Filter results. Partial match by outpoint by default in all modes,\n" 43 " additional matches in some modes are also available\n" 44 "\nAvailable modes:\n" 45 " addr - Print ip address associated with a masternode (can be additionally filtered, partial match)\n" 46 " full - Print info in format 'status payee lastpaidtime lastpaidblock IP'\n" 47 " (can be additionally filtered, partial match)\n" 48 " info - Print info in format 'status payee IP'\n" 49 " (can be additionally filtered, partial match)\n" 50 " json - Print info in JSON format (can be additionally filtered, partial match)\n" 51 " lastpaidblock - Print the last block height a node was paid on the network\n" 52 " lastpaidtime - Print the last time a node was paid on the network\n" 53 " owneraddress - Print the masternode owner Dash address\n" 54 " payee - Print the masternode payout Dash address (can be additionally filtered,\n" 56 " pubKeyOperator - Print the masternode operator public key\n" 57 " status - Print masternode status: ENABLED / POSE_BANNED\n" 58 " (can be additionally filtered, partial match)\n" 59 " votingaddress - Print the masternode voting Dash address\n" 70 for (
unsigned int i = 1; i < request.
params.
size(); i++) {
78 throw std::runtime_error(
79 "masternode connect \"address\"\n" 80 "Connect to given masternode\n" 82 "1. \"address\" (string, required) The address of the masternode to connect\n" 94 if (!
Lookup(strAddress.c_str(), addr, 0,
false))
102 return "successfully connected";
107 throw std::runtime_error(
108 "masternode count (\"mode\")\n" 109 " Get information about number of masternodes. Mode\n" 110 " usage is depricated, call without mode params returns\n" 111 " all values in JSON format.\n" 113 "1. \"mode\" (string, optional, DEPRICATED) Option to get number of masternodes in different states\n" 114 "\nAvailable modes:\n" 115 " total - total number of masternodes" 116 " ps - number of PrivateSend compatible masternodes" 117 " enabled - number of enabled masternodes" 118 " qualify - number of qualified masternodes" 119 " all - all above in one string" 129 int total = mnList.GetAllMNsCount();
130 int enabled = mnList.GetValidMNsCount();
143 if (strMode ==
"total")
146 if (strMode ==
"enabled")
149 if (strMode ==
"all")
150 return strprintf(
"Total: %d (Enabled: %d)",
159 auto payees = mnList.GetProjectedMNPayees(heightShift);
162 auto payee = payees.back();
163 CScript payeeScript = payee->pdmnState->scriptPayout;
170 obj.
push_back(
Pair(
"height", mnList.GetHeight() + heightShift));
171 obj.
push_back(
Pair(
"IP:port", payee->pdmnState->addr.ToString()));
172 obj.
push_back(
Pair(
"proTxHash", payee->proTxHash.ToString()));
173 obj.
push_back(
Pair(
"outpoint", payee->collateralOutpoint.ToStringShort()));
180 throw std::runtime_error(
181 "masternode winner\n" 182 "Print info on next masternode winner to vote for\n" 196 throw std::runtime_error(
197 "masternode current\n" 198 "Print info on current masternode winner to be paid the next block (calculated locally)\n" 211 void masternode_outputs_help()
213 throw std::runtime_error(
214 "masternode outputs\n" 215 "Print masternode compatible outputs\n" 223 masternode_outputs_help();
229 std::vector<COutput> vPossibleCoins;
235 for (
const auto& out : vPossibleCoins) {
236 obj.push_back(
Pair(out.tx->GetHash().ToString(),
strprintf(
"%d", out.i)));
242 #endif // ENABLE_WALLET 246 throw std::runtime_error(
247 "masternode status\n" 248 "Print masternode status information\n" 268 mnObj.
push_back(
Pair(
"proTxHash", dmn->proTxHash.ToString()));
269 mnObj.
push_back(
Pair(
"collateralHash", dmn->collateralOutpoint.hash.ToString()));
270 mnObj.
push_back(
Pair(
"collateralIndex", (
int)dmn->collateralOutpoint.n));
272 dmn->pdmnState->ToJson(stateObj);
283 throw std::runtime_error(
284 "masternode winners ( count \"filter\" )\n" 285 "Print list of masternode winners\n" 287 "1. count (numeric, optional) number of last winners to return\n" 288 "2. filter (string, optional) filter for returned winners\n" 307 std::string strFilter =
"";
319 for (
const auto &p : mapPayments) {
328 throw std::runtime_error(
329 "masternode \"command\" ...\n" 330 "Set of commands to execute masternode related actions\n" 332 "1. \"command\" (string or set of strings, required) The command to execute\n" 333 "\nAvailable commands:\n" 334 " count - Get information about number of masternodes (DEPRECATED options: 'total', 'ps', 'enabled', 'qualify', 'all')\n" 335 " current - Print info on current masternode winner to be paid the next block (calculated locally)\n" 337 " outputs - Print masternode compatible outputs\n" 339 " status - Print masternode status information\n" 340 " list - Print list of all known masternodes (see masternodelist for more info)\n" 341 " winner - Print info on next masternode winner to vote for\n" 342 " winners - Print list of masternode winners\n" 348 std::string strCommand;
353 if (request.
fHelp && strCommand.empty()) {
357 if (strCommand ==
"list") {
359 }
else if (strCommand ==
"connect") {
361 }
else if (strCommand ==
"count") {
363 }
else if (strCommand ==
"current") {
365 }
else if (strCommand ==
"winner") {
368 }
else if (strCommand ==
"outputs") {
369 return masternode_outputs(request);
370 #endif // ENABLE_WALLET 371 }
else if (strCommand ==
"status") {
373 }
else if (strCommand ==
"winners") {
382 std::string strMode =
"json";
383 std::string strFilter =
"";
388 std::transform(strMode.begin(), strMode.end(), strMode.begin(), ::tolower);
390 if (request.
fHelp || (
391 strMode !=
"addr" && strMode !=
"full" && strMode !=
"info" && strMode !=
"json" &&
392 strMode !=
"owneraddress" && strMode !=
"votingaddress" &&
393 strMode !=
"lastpaidtime" && strMode !=
"lastpaidblock" &&
394 strMode !=
"payee" && strMode !=
"pubkeyoperator" &&
395 strMode !=
"status"))
404 if (mnList.IsMNValid(dmn)) {
407 if (mnList.IsMNPoSeBanned(dmn)) {
408 return "POSE_BANNED";
413 if (dmn->pdmnState->nLastPaidHeight == 0) {
419 return (
int)pindex->
nTime;
423 std::string strOutpoint = dmn->collateralOutpoint.ToStringShort();
425 std::string collateralAddressStr =
"UNKNOWN";
433 CScript payeeScript = dmn->pdmnState->scriptPayout;
435 std::string payeeStr =
"UNKNOWN";
440 if (strMode ==
"addr") {
441 std::string strAddress = dmn->pdmnState->addr.ToString(
false);
442 if (strFilter !=
"" && strAddress.find(strFilter) == std::string::npos &&
443 strOutpoint.find(strFilter) == std::string::npos)
return;
445 }
else if (strMode ==
"full") {
446 std::ostringstream streamFull;
447 streamFull << std::setw(18) <<
448 dmnToStatus(dmn) <<
" " <<
449 payeeStr <<
" " << std::setw(10) <<
450 dmnToLastPaidTime(dmn) <<
" " << std::setw(6) <<
451 dmn->pdmnState->nLastPaidHeight <<
" " <<
452 dmn->pdmnState->addr.ToString();
453 std::string strFull = streamFull.str();
454 if (strFilter !=
"" && strFull.find(strFilter) == std::string::npos &&
455 strOutpoint.find(strFilter) == std::string::npos)
return;
457 }
else if (strMode ==
"info") {
458 std::ostringstream streamInfo;
459 streamInfo << std::setw(18) <<
460 dmnToStatus(dmn) <<
" " <<
462 dmn->pdmnState->addr.ToString();
463 std::string strInfo = streamInfo.str();
464 if (strFilter !=
"" && strInfo.find(strFilter) == std::string::npos &&
465 strOutpoint.find(strFilter) == std::string::npos)
return;
467 }
else if (strMode ==
"json") {
468 std::ostringstream streamInfo;
469 streamInfo << dmn->proTxHash.ToString() <<
" " <<
470 dmn->pdmnState->addr.ToString() <<
" " <<
472 dmnToStatus(dmn) <<
" " <<
473 dmnToLastPaidTime(dmn) <<
" " <<
474 dmn->pdmnState->nLastPaidHeight <<
" " <<
477 collateralAddressStr <<
" " <<
478 dmn->pdmnState->pubKeyOperator.Get().ToString();
479 std::string strInfo = streamInfo.str();
480 if (strFilter !=
"" && strInfo.find(strFilter) == std::string::npos &&
481 strOutpoint.find(strFilter) == std::string::npos)
return;
483 objMN.
push_back(
Pair(
"proTxHash", dmn->proTxHash.ToString()));
484 objMN.
push_back(
Pair(
"address", dmn->pdmnState->addr.ToString()));
487 objMN.
push_back(
Pair(
"lastpaidtime", dmnToLastPaidTime(dmn)));
488 objMN.
push_back(
Pair(
"lastpaidblock", dmn->pdmnState->nLastPaidHeight));
491 objMN.
push_back(
Pair(
"collateraladdress", collateralAddressStr));
492 objMN.
push_back(
Pair(
"pubkeyoperator", dmn->pdmnState->pubKeyOperator.Get().ToString()));
494 }
else if (strMode ==
"lastpaidblock") {
495 if (strFilter !=
"" && strOutpoint.find(strFilter) == std::string::npos)
return;
496 obj.
push_back(
Pair(strOutpoint, dmn->pdmnState->nLastPaidHeight));
497 }
else if (strMode ==
"lastpaidtime") {
498 if (strFilter !=
"" && strOutpoint.find(strFilter) == std::string::npos)
return;
500 }
else if (strMode ==
"payee") {
501 if (strFilter !=
"" && payeeStr.find(strFilter) == std::string::npos &&
502 strOutpoint.find(strFilter) == std::string::npos)
return;
504 }
else if (strMode ==
"owneraddress") {
505 if (strFilter !=
"" && strOutpoint.find(strFilter) == std::string::npos)
return;
507 }
else if (strMode ==
"pubkeyoperator") {
508 if (strFilter !=
"" && strOutpoint.find(strFilter) == std::string::npos)
return;
509 obj.
push_back(
Pair(strOutpoint, dmn->pdmnState->pubKeyOperator.Get().ToString()));
510 }
else if (strMode ==
"status") {
511 std::string strStatus = dmnToStatus(dmn);
512 if (strFilter !=
"" && strStatus.find(strFilter) == std::string::npos &&
513 strOutpoint.find(strFilter) == std::string::npos)
return;
515 }
else if (strMode ==
"votingaddress") {
516 if (strFilter !=
"" && strOutpoint.find(strFilter) == std::string::npos)
return;
void masternode_winners_help()
void RegisterMasternodeRPCCommands(CRPCTable &t)
Register masternode RPC commands.
UniValue masternode_status(const JSONRPCRequest &request)
static constexpr const CAllNodes AllNodes
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
std::string ToString(bool fUseGetnameinfo=true) const
Dash RPC command dispatcher.
UniValue masternode_current(const JSONRPCRequest &request)
UniValue masternode_connect(const JSONRPCRequest &request)
bool EnsureWalletIsAvailable(CWallet *const pwallet, bool avoidException)
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
CTxOut out
unspent transaction output
const std::string & get_str() const
UniValue masternode_winner(const JSONRPCRequest &request)
std::shared_ptr< const CDeterministicMN > CDeterministicMNCPtr
void masternode_current_help()
std::unique_ptr< CDeterministicMNManager > deterministicMNManager
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
UniValue GetNextMasternodeForPayment(int heightShift)
Invalid, missing or duplicate parameter.
void masternode_count_help()
UniValue masternode_count(const JSONRPCRequest &request)
bool GetUTXOCoin(const COutPoint &outpoint, Coin &coin)
bool push_back(const UniValue &val)
void masternode_connect_help()
CActiveMasternodeInfo activeMasternodeInfo
A combination of a network address (CNetAddr) and a (TCP) port.
void masternode_status_help()
A CService with information about it as peer.
void masternode_winner_help()
CoinType nCoinType
Controls which types of coins are allowed to be used (default: ALL_COINS)
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
static const CRPCCommand commands[]
UniValue masternode_winners(const JSONRPCRequest &request)
void AvailableCoins(std::vector< COutput > &vCoins, bool fOnlySafe=true, const CCoinControl *coinControl=nullptr, const CAmount &nMinimumAmount=1, const CAmount &nMaximumAmount=MAX_MONEY, const CAmount &nMinimumSumAmount=MAX_MONEY, const uint64_t nMaximumCount=0, const int nMinDepth=0, const int nMaxDepth=9999999) const
populate vCoins with vector of available COutputs.
UniValue masternodelist(const JSONRPCRequest &request)
std::string EncodeDestination(const CTxDestination &dest)
The block chain is a tree shaped structure starting with the genesis block at the root...
Serialized script, used inside transaction inputs and outputs.
void masternode_list_help()
std::map< int, std::string > GetRequiredPaymentsStrings(int nStartHeight, int nEndHeight)
bool Lookup(const char *pszName, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
std::unique_ptr< CConnman > g_connman
const UniValue NullUniValue
CWallet * GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
UniValue masternode(const JSONRPCRequest &request)
std::string GetStateString() const
std::string GetStatus() const
UniValue JSONRPCError(int code, const std::string &message)
int nHeight
height of the entry in the chain. The genesis block has height 0
CChain & chainActive
The currently-connected chain of blocks (protected by cs_main).
UniValue masternode_list(const JSONRPCRequest &request)
int atoi(const std::string &str)
CActiveMasternodeManager * activeMasternodeManager
std::string ToStringShort() const