PIVX Core  5.6.99
P2P Digital Currency
masternode.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2012 The Bitcoin developers
2 // Copyright (c) 2015-2022 The PIVX Core developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "activemasternode.h"
7 #include "db.h"
8 #include "evo/deterministicmns.h"
9 #include "key_io.h"
10 #include "masternode-payments.h"
11 #include "masternodeconfig.h"
12 #include "masternodeman.h"
13 #include "netaddress.h"
14 #include "netbase.h"
16 #include "rpc/server.h"
17 #ifdef ENABLE_WALLET
18 #include "wallet/wallet.h"
19 #include "wallet/rpcwallet.h"
20 #endif
21 
22 #include <univalue.h>
23 
24 #include <boost/tokenizer.hpp>
25 
26 // Duplicated from rpcevo.cpp for the compatibility phase. Remove after v6
27 static UniValue DmnToJson(const CDeterministicMNCPtr dmn)
28 {
30  dmn->ToJson(ret);
31  Coin coin;
32  if (!WITH_LOCK(cs_main, return pcoinsTip->GetUTXOCoin(dmn->collateralOutpoint, coin); )) {
33  return ret;
34  }
35  CTxDestination dest;
36  if (!ExtractDestination(coin.out.scriptPubKey, dest)) {
37  return ret;
38  }
39  ret.pushKV("collateralAddress", EncodeDestination(dest));
40  return ret;
41 }
42 
44 {
45  if (request.fHelp || !request.params.empty()) {
46  throw std::runtime_error(
47  "mnping \n"
48  "\nSend masternode ping. Only for remote masternodes on Regtest\n"
49 
50  "\nResult:\n"
51  "{\n"
52  " \"sent\": (string YES|NO) Whether the ping was sent and, if not, the error.\n"
53  "}\n"
54 
55  "\nExamples:\n" +
56  HelpExampleCli("mnping", "") + HelpExampleRpc("mnping", ""));
57  }
58 
59  if (!Params().IsRegTestNet()) {
60  throw JSONRPCError(RPC_MISC_ERROR, "command available only for RegTest network");
61  }
62 
63  if (!fMasterNode) {
64  throw JSONRPCError(RPC_MISC_ERROR, "this is not a masternode");
65  }
66 
68  std::string strError;
69  ret.pushKV("sent", activeMasternode.SendMasternodePing(strError) ?
70  "YES" : strprintf("NO (%s)", strError));
71  return ret;
72 }
73 
75 {
76  if (request.fHelp || (request.params.size() < 1 || request.params.size() > 2)) {
77  throw std::runtime_error(
78  "initmasternode \"privkey\" ( \"address\" )\n"
79  "\nInitialize masternode on demand if it's not already initialized.\n"
80  "\nArguments:\n"
81  "1. privkey (string, required) The masternode private key.\n"
82  "2. address (string, optional) The IP:Port of the masternode. (Only needed for legacy masternodes)\n"
83 
84  "\nResult:\n"
85  " success (string) if the masternode initialization succeeded.\n"
86 
87  "\nExamples:\n" +
88  HelpExampleCli("initmasternode", "\"9247iC59poZmqBYt9iDh9wDam6v9S1rW5XekjLGyPnDhrDkP4AK\" \"187.24.32.124:51472\"") +
89  HelpExampleRpc("initmasternode", "\"bls-sk1xye8es37kk7y2mz7mad6yz7fdygttexqwhypa0u86hzw2crqgxfqy29ajm\""));
90  }
91 
92  std::string _strMasterNodePrivKey = request.params[0].get_str();
93  if (_strMasterNodePrivKey.empty()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Masternode key cannot be empty.");
94 
95  const auto& params = Params();
96  bool isDeterministic = _strMasterNodePrivKey.find(params.Bech32HRP(CChainParams::BLS_SECRET_KEY)) != std::string::npos;
97  if (isDeterministic) {
101  }
102  auto res = activeMasternodeManager->SetOperatorKey(_strMasterNodePrivKey);
103  if (!res) throw std::runtime_error(res.getError());
104  const CBlockIndex* pindexTip = WITH_LOCK(cs_main, return chainActive.Tip(); );
105  activeMasternodeManager->Init(pindexTip);
107  throw std::runtime_error(activeMasternodeManager->GetStatus());
108  }
109  return "success";
110  }
111  // legacy
112  if (request.params.size() < 2) throw JSONRPCError(RPC_INVALID_PARAMETER, "Must specify the IP address for legacy mn");
113  std::string _strMasterNodeAddr = request.params[1].get_str();
114  auto res = initMasternode(_strMasterNodePrivKey, _strMasterNodeAddr, false);
115  if (!res) throw std::runtime_error(res.getError());
116  return "success";
117 }
118 
120 {
121  if (request.fHelp || request.params.size() > 0)
122  throw std::runtime_error(
123  "getcachedblockhashes \n"
124  "\nReturn the block hashes cached in the masternode manager\n"
125 
126  "\nResult:\n"
127  "[\n"
128  " ...\n"
129  " \"xxxx\", (string) hash at Index d (height modulo max cache size)\n"
130  " ...\n"
131  "]\n"
132 
133  "\nExamples:\n" +
134  HelpExampleCli("getcachedblockhashes", "") + HelpExampleRpc("getcachedblockhashes", ""));
135 
136  std::vector<uint256> vCacheCopy = mnodeman.GetCachedBlocks();
138  for (int i = 0; (unsigned) i < vCacheCopy.size(); i++) {
139  ret.push_back(vCacheCopy[i].ToString());
140  }
141  return ret;
142 }
143 
144 static inline bool filter(const std::string& str, const std::string& strFilter)
145 {
146  return str.find(strFilter) != std::string::npos;
147 }
148 
149 static inline bool filterMasternode(const UniValue& dmno, const std::string& strFilter, bool fEnabled)
150 {
151  return strFilter.empty() || (filter("ENABLED", strFilter) && fEnabled)
152  || (filter("POSE_BANNED", strFilter) && !fEnabled)
153  || (filter(dmno["proTxHash"].get_str(), strFilter))
154  || (filter(dmno["collateralHash"].get_str(), strFilter))
155  || (filter(dmno["collateralAddress"].get_str(), strFilter))
156  || (filter(dmno["dmnstate"]["ownerAddress"].get_str(), strFilter))
157  || (filter(dmno["dmnstate"]["operatorPubKey"].get_str(), strFilter))
158  || (filter(dmno["dmnstate"]["votingAddress"].get_str(), strFilter));
159 }
160 
162 {
163  if (request.fHelp || (request.params.size() > 1))
164  throw std::runtime_error(
165  "listmasternodes ( \"filter\" )\n"
166  "\nGet a ranked list of masternodes\n"
167 
168  "\nArguments:\n"
169  "1. \"filter\" (string, optional) Filter search text. Partial match by txhash, status, or addr.\n"
170 
171  // !TODO: update for DMNs
172  "\nResult:\n"
173  "[\n"
174  " {\n"
175  " \"rank\": n, (numeric) Masternode Rank (or 0 if not enabled)\n"
176  " \"type\": \"legacy\"|\"deterministic\", (string) type of masternode\n"
177  " \"txhash\": \"hash\", (string) Collateral transaction hash\n"
178  " \"outidx\": n, (numeric) Collateral transaction output index\n"
179  " \"pubkey\": \"key\", (string) Masternode public key used for message broadcasting\n"
180  " \"status\": s, (string) Status (ENABLED/EXPIRED/REMOVE/etc)\n"
181  " \"addr\": \"addr\", (string) Masternode PIVX address\n"
182  " \"version\": v, (numeric) Masternode protocol version\n"
183  " \"lastseen\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last seen\n"
184  " \"activetime\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) masternode has been active\n"
185  " \"lastpaid\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) masternode was last paid\n"
186  " }\n"
187  " ,...\n"
188  "]\n"
189 
190  "\nExamples:\n" +
191  HelpExampleCli("listmasternodes", "") + HelpExampleRpc("listmasternodes", ""));
192 
193 
194  const std::string& strFilter = request.params.size() > 0 ? request.params[0].get_str() : "";
196 
197  if (deterministicMNManager->LegacyMNObsolete()) {
198  auto mnList = deterministicMNManager->GetListAtChainTip();
199  mnList.ForEachMN(false, [&](const CDeterministicMNCPtr& dmn) {
200  UniValue obj = DmnToJson(dmn);
201  if (filterMasternode(obj, strFilter, !dmn->IsPoSeBanned())) {
202  ret.push_back(obj);
203  }
204  });
205  return ret;
206  }
207 
208  // Legacy masternodes (!TODO: remove when transition to dmn is complete)
209  const CBlockIndex* chainTip = GetChainTip();
210  if (!chainTip) return "[]";
211  int nHeight = chainTip->nHeight;
212  auto mnList = deterministicMNManager->GetListAtChainTip();
213 
214  int count_enabled = mnodeman.CountEnabled();
215  std::vector<std::pair<int64_t, MasternodeRef>> vMasternodeRanks = mnodeman.GetMasternodeRanks(nHeight);
216  for (int pos=0; pos < (int) vMasternodeRanks.size(); pos++) {
217  const auto& s = vMasternodeRanks[pos];
219  const CMasternode& mn = *(s.second);
220 
221  if (!mn.mnPayeeScript.empty()) {
222  // Deterministic masternode
223  auto dmn = mnList.GetMNByCollateral(mn.vin.prevout);
224  if (dmn) {
225  UniValue obj = DmnToJson(dmn);
226  bool fEnabled = !dmn->IsPoSeBanned();
227  if (filterMasternode(obj, strFilter, fEnabled)) {
228  // Added for backward compatibility with legacy masternodes
229  obj.pushKV("type", "deterministic");
230  obj.pushKV("txhash", obj["proTxHash"].get_str());
231  obj.pushKV("addr", obj["dmnstate"]["payoutAddress"].get_str());
232  obj.pushKV("status", fEnabled ? "ENABLED" : "POSE_BANNED");
233  obj.pushKV("rank", fEnabled ? pos : 0);
234  ret.push_back(obj);
235  }
236  }
237  continue;
238  }
239 
240  std::string strVin = mn.vin.prevout.ToStringShort();
241  std::string strTxHash = mn.vin.prevout.hash.ToString();
242  uint32_t oIdx = mn.vin.prevout.n;
243 
244  if (strFilter != "" && strTxHash.find(strFilter) == std::string::npos &&
245  mn.Status().find(strFilter) == std::string::npos &&
246  EncodeDestination(mn.pubKeyCollateralAddress.GetID()).find(strFilter) == std::string::npos) continue;
247 
248  std::string strStatus = mn.Status();
249  std::string strHost;
250  int port;
251  SplitHostPort(mn.addr.ToString(), port, strHost);
252  CNetAddr node;
253  LookupHost(strHost.c_str(), node, false);
254  std::string strNetwork = GetNetworkName(node.GetNetwork());
255 
256  obj.pushKV("rank", (strStatus == "ENABLED" ? pos : -1));
257  obj.pushKV("type", "legacy");
258  obj.pushKV("network", strNetwork);
259  obj.pushKV("txhash", strTxHash);
260  obj.pushKV("outidx", (uint64_t)oIdx);
261  obj.pushKV("pubkey", EncodeDestination(mn.pubKeyMasternode.GetID()));
262  obj.pushKV("status", strStatus);
264  obj.pushKV("version", mn.protocolVersion);
265  obj.pushKV("lastseen", (int64_t)mn.lastPing.sigTime);
266  obj.pushKV("activetime", (int64_t)(mn.lastPing.sigTime - mn.sigTime));
267  obj.pushKV("lastpaid", (int64_t)mnodeman.GetLastPaid(s.second, count_enabled, chainTip));
268 
269  ret.push_back(obj);
270  }
271 
272  return ret;
273 }
274 
276 {
277  if (request.fHelp || (request.params.size() > 0))
278  throw std::runtime_error(
279  "getmasternodecount\n"
280  "\nGet masternode count values\n"
281 
282  "\nResult:\n"
283  "{\n"
284  " \"total\": n, (numeric) Total masternodes\n"
285  " \"stable\": n, (numeric) Stable count\n"
286  " \"enabled\": n, (numeric) Enabled masternodes\n"
287  " \"inqueue\": n, (numeric) Masternodes in queue\n"
288  " \"ipv4\": n, (numeric) Number of IPv4 masternodes\n"
289  " \"ipv6\": n, (numeric) Number of IPv6 masternodes\n"
290  " \"onion\": n (numeric) Number of Tor masternodes\n"
291  "}\n"
292 
293  "\nExamples:\n" +
294  HelpExampleCli("getmasternodecount", "") + HelpExampleRpc("getmasternodecount", ""));
295 
297  int nCount = 0;
298  const CBlockIndex* pChainTip = GetChainTip();
299  if (!pChainTip) return "unknown";
300 
301  mnodeman.GetNextMasternodeInQueueForPayment(pChainTip->nHeight, true, nCount, pChainTip);
302  auto infoMNs = mnodeman.getMNsInfo();
303 
304  obj.pushKV("total", infoMNs.total);
305  obj.pushKV("stable", infoMNs.stableSize);
306  obj.pushKV("enabled", infoMNs.enabledSize);
307  obj.pushKV("inqueue", nCount);
308  obj.pushKV("ipv4", infoMNs.ipv4);
309  obj.pushKV("ipv6", infoMNs.ipv6);
310  obj.pushKV("onion", infoMNs.onion);
311 
312  return obj;
313 }
314 
316 {
317  if (request.fHelp || (request.params.size() != 0))
318  throw std::runtime_error(
319  "masternodecurrent\n"
320  "\nGet current masternode winner (scheduled to be paid next).\n"
321 
322  "\nResult:\n"
323  "{\n"
324  " \"protocol\": xxxx, (numeric) Protocol version\n"
325  " \"txhash\": \"xxxx\", (string) Collateral transaction hash\n"
326  " \"pubkey\": \"xxxx\", (string) MN Public key\n"
327  " \"lastseen\": xxx, (numeric) Time since epoch of last seen\n"
328  " \"activeseconds\": xxx, (numeric) Seconds MN has been active\n"
329  "}\n"
330 
331  "\nExamples:\n" +
332  HelpExampleCli("masternodecurrent", "") + HelpExampleRpc("masternodecurrent", ""));
333 
334  const CBlockIndex* pChainTip = GetChainTip();
335  if (!pChainTip) return "unknown";
336 
337  int nCount = 0;
338  MasternodeRef winner = mnodeman.GetNextMasternodeInQueueForPayment(pChainTip->nHeight + 1, true, nCount, pChainTip);
339  if (winner) {
341  obj.pushKV("protocol", (int64_t)winner->protocolVersion);
342  obj.pushKV("txhash", winner->vin.prevout.hash.ToString());
343  obj.pushKV("pubkey", EncodeDestination(winner->pubKeyCollateralAddress.GetID()));
344  obj.pushKV("lastseen", winner->lastPing.IsNull() ? winner->sigTime : (int64_t)winner->lastPing.sigTime);
345  obj.pushKV("activeseconds", winner->lastPing.IsNull() ? 0 : (int64_t)(winner->lastPing.sigTime - winner->sigTime));
346  return obj;
347  }
348 
349  throw std::runtime_error("unknown");
350 }
351 
352 bool StartMasternodeEntry(UniValue& statusObjRet, CMasternodeBroadcast& mnbRet, bool& fSuccessRet, const CMasternodeConfig::CMasternodeEntry& mne, std::string& errorMessage, std::string strCommand = "")
353 {
354  int nIndex;
355  if(!mne.castOutputIndex(nIndex)) {
356  return false;
357  }
358 
359  CTxIn vin = CTxIn(uint256S(mne.getTxHash()), uint32_t(nIndex));
360  CMasternode* pmn = mnodeman.Find(vin.prevout);
361  if (pmn != nullptr) {
362  if (strCommand == "missing") return false;
363  if (strCommand == "disabled" && pmn->IsEnabled()) return false;
364  }
365 
366  fSuccessRet = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), errorMessage, mnbRet, false, mnodeman.GetBestHeight());
367 
368  statusObjRet.pushKV("alias", mne.getAlias());
369  statusObjRet.pushKV("result", fSuccessRet ? "success" : "failed");
370  statusObjRet.pushKV("error", fSuccessRet ? "" : errorMessage);
371 
372  return true;
373 }
374 
375 void RelayMNB(CMasternodeBroadcast& mnb, const bool fSuccess, int& successful, int& failed)
376 {
377  if (fSuccess) {
378  successful++;
380  mnb.Relay();
381  } else {
382  failed++;
383  }
384 }
385 
386 void RelayMNB(CMasternodeBroadcast& mnb, const bool fSucces)
387 {
388  int successful = 0, failed = 0;
389  return RelayMNB(mnb, fSucces, successful, failed);
390 }
391 
392 void SerializeMNB(UniValue& statusObjRet, const CMasternodeBroadcast& mnb, const bool fSuccess, int& successful, int& failed)
393 {
394  bool isBIP155 = mnb.addr.IsAddrV1Compatible();
395  int version = isBIP155 ? PROTOCOL_VERSION | ADDRV2_FORMAT : PROTOCOL_VERSION;
396  if(fSuccess) {
397  successful++;
398  CDataStream ssMnb(SER_NETWORK, version);
399  ssMnb << mnb;
400  statusObjRet.pushKV("hex", HexStr(ssMnb));
401  } else {
402  failed++;
403  }
404 }
405 
406 void SerializeMNB(UniValue& statusObjRet, const CMasternodeBroadcast& mnb, const bool fSuccess)
407 {
408  int successful = 0, failed = 0;
409  return SerializeMNB(statusObjRet, mnb, fSuccess, successful, failed);
410 }
411 
413 {
414  // Skip after legacy obsolete. !TODO: remove when transition to DMN is complete
415  if (deterministicMNManager->LegacyMNObsolete()) {
416  throw JSONRPCError(RPC_MISC_ERROR, "startmasternode is not supported when deterministic masternode list is active (DIP3)");
417  }
418 
419  CWallet* const pwallet = GetWalletForJSONRPCRequest(request);
420 
421  if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
422  return NullUniValue;
423 
424  std::string strCommand;
425  if (!request.params.empty()) {
426  strCommand = request.params[0].get_str();
427  }
428 
429  if (strCommand == "local")
430  throw JSONRPCError(RPC_INVALID_PARAMETER, "Local start is deprecated. Start your masternode from the controller wallet instead.");
431  if (strCommand == "many")
432  throw JSONRPCError(RPC_INVALID_PARAMETER, "Many set is deprecated. Use either 'all', 'missing', or 'disabled'.");
433 
434  if (request.fHelp || request.params.size() < 2 || request.params.size() > 4 ||
435  (strCommand == "alias" && request.params.size() < 3))
436  throw std::runtime_error(
437  "startmasternode \"all|missing|disabled|alias\" lock_wallet ( \"alias\" reload_conf )\n"
438  "\nAttempts to start one or more masternode(s)\n" +
439  HelpRequiringPassphrase(pwallet) + "\n"
440 
441  "\nArguments:\n"
442  "1. set (string, required) Specify which set of masternode(s) to start.\n"
443  "2. lock_wallet (boolean, required) Lock wallet after completion.\n"
444  "3. alias (string, optional) Masternode alias. Required if using 'alias' as the set.\n"
445  "4. reload_conf (boolean, optional, default=False) reload the masternodes.conf data from disk"
446 
447  "\nResult:\n"
448  "{\n"
449  " \"overall\": \"xxxx\", (string) Overall status message\n"
450  " \"detail\": [\n"
451  " {\n"
452  " \"alias\": \"xxxx\", (string) Node alias\n"
453  " \"result\": \"xxxx\", (string) 'success' or 'failed'\n"
454  " \"error\": \"xxxx\" (string) Error message, if failed\n"
455  " }\n"
456  " ,...\n"
457  " ]\n"
458  "}\n"
459 
460  "\nExamples:\n" +
461  HelpExampleCli("startmasternode", "\"alias\" false \"my_mn\"") + HelpExampleRpc("startmasternode", "\"alias\" false \"my_mn\""));
462 
463  RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL, UniValue::VSTR, UniValue::VBOOL}, true);
464 
465  EnsureWalletIsUnlocked(pwallet);
466 
467  bool fLock = request.params[1].get_bool();
468  bool fReload = request.params.size() > 3 ? request.params[3].get_bool() : false;
469 
470  // Check reload param
471  if (fReload) {
473  std::string error;
474  if (!masternodeConfig.read(error)) {
475  throw std::runtime_error("Error reloading masternode.conf, " + error);
476  }
477  }
478 
479  if (strCommand == "all" || strCommand == "missing" || strCommand == "disabled") {
480  if ((strCommand == "missing" || strCommand == "disabled") &&
483  throw std::runtime_error("You can't use this command until masternode list is synced\n");
484  }
485 
486  int successful = 0;
487  int failed = 0;
488 
489  UniValue resultsObj(UniValue::VARR);
490 
492  UniValue statusObj(UniValue::VOBJ);
494  std::string errorMessage;
495  bool fSuccess = false;
496  if (!StartMasternodeEntry(statusObj, mnb, fSuccess, mne, errorMessage, strCommand))
497  continue;
498  resultsObj.push_back(statusObj);
499  RelayMNB(mnb, fSuccess, successful, failed);
500  }
501  if (fLock)
502  pwallet->Lock();
503 
504  UniValue returnObj(UniValue::VOBJ);
505  returnObj.pushKV("overall", strprintf("Successfully started %d masternodes, failed to start %d, total %d", successful, failed, successful + failed));
506  returnObj.pushKV("detail", resultsObj);
507 
508  return returnObj;
509  }
510 
511  if (strCommand == "alias") {
512  std::string alias = request.params[2].get_str();
513 
514  bool found = false;
515 
516  UniValue resultsObj(UniValue::VARR);
517  UniValue statusObj(UniValue::VOBJ);
518 
520  if (mne.getAlias() == alias) {
522  found = true;
523  std::string errorMessage;
524  bool fSuccess = false;
525  if (!StartMasternodeEntry(statusObj, mnb, fSuccess, mne, errorMessage, strCommand))
526  continue;
527  RelayMNB(mnb, fSuccess);
528  break;
529  }
530  }
531 
532  if (fLock)
533  pwallet->Lock();
534 
535  if(!found) {
536  statusObj.pushKV("alias", alias);
537  statusObj.pushKV("result", "failed");
538  statusObj.pushKV("error", "Could not find alias in config. Verify with listmasternodeconf.");
539  }
540 
541  return statusObj;
542  }
543  throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid set name %s.", strCommand));
544 }
545 
547 {
548  if (request.fHelp || (request.params.size() != 0))
549  throw std::runtime_error(
550  "createmasternodekey\n"
551  "\nCreate a new masternode private key\n"
552 
553  "\nResult:\n"
554  "\"key\" (string) Masternode private key\n"
555 
556  "\nExamples:\n" +
557  HelpExampleCli("createmasternodekey", "") + HelpExampleRpc("createmasternodekey", ""));
558 
559  CKey secret;
560  secret.MakeNewKey(false);
561 
562  return KeyIO::EncodeSecret(secret);
563 }
564 
566 {
567  CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
568 
569  if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
570  return NullUniValue;
571 
572  if (request.fHelp || (request.params.size() != 0))
573  throw std::runtime_error(
574  "getmasternodeoutputs\n"
575  "\nPrint all masternode transaction outputs\n"
576 
577  "\nResult:\n"
578  "[\n"
579  " {\n"
580  " \"txhash\": \"xxxx\", (string) output transaction hash\n"
581  " \"outputidx\": n (numeric) output index number\n"
582  " }\n"
583  " ,...\n"
584  "]\n"
585 
586  "\nExamples:\n" +
587  HelpExampleCli("getmasternodeoutputs", "") + HelpExampleRpc("getmasternodeoutputs", ""));
588 
589  // Find possible candidates
590  CWallet::AvailableCoinsFilter coinsFilter;
591  coinsFilter.fIncludeDelegated = false;
593  coinsFilter.nMinOutValue = coinsFilter.nMaxOutValue;
594  coinsFilter.fIncludeLocked = true;
595  std::vector<COutput> possibleCoins;
596  pwallet->AvailableCoins(&possibleCoins, nullptr, coinsFilter);
597 
599  for (COutput& out : possibleCoins) {
601  obj.pushKV("txhash", out.tx->GetHash().ToString());
602  obj.pushKV("outputidx", out.i);
603  ret.push_back(obj);
604  }
605 
606  return ret;
607 }
608 
610 {
611  std::string strFilter = "";
612 
613  if (request.params.size() == 1) strFilter = request.params[0].get_str();
614 
615  if (request.fHelp || (request.params.size() > 1))
616  throw std::runtime_error(
617  "listmasternodeconf ( \"filter\" )\n"
618  "\nPrint masternode.conf in JSON format\n"
619 
620  "\nArguments:\n"
621  "1. \"filter\" (string, optional) Filter search text. Partial match on alias, address, txHash, or status.\n"
622 
623  "\nResult:\n"
624  "[\n"
625  " {\n"
626  " \"alias\": \"xxxx\", (string) masternode alias\n"
627  " \"address\": \"xxxx\", (string) masternode IP address\n"
628  " \"privateKey\": \"xxxx\", (string) masternode private key\n"
629  " \"txHash\": \"xxxx\", (string) transaction hash\n"
630  " \"outputIndex\": n, (numeric) transaction output index\n"
631  " \"status\": \"xxxx\" (string) masternode status\n"
632  " }\n"
633  " ,...\n"
634  "]\n"
635 
636  "\nExamples:\n" +
637  HelpExampleCli("listmasternodeconf", "") + HelpExampleRpc("listmasternodeconf", ""));
638 
639  std::vector<CMasternodeConfig::CMasternodeEntry> mnEntries;
640  mnEntries = masternodeConfig.getEntries();
641 
643 
645  int nIndex;
646  if(!mne.castOutputIndex(nIndex))
647  continue;
648  CTxIn vin = CTxIn(uint256S(mne.getTxHash()), uint32_t(nIndex));
649  CMasternode* pmn = mnodeman.Find(vin.prevout);
650 
651  std::string strStatus = pmn ? pmn->Status() : "MISSING";
652 
653  if (strFilter != "" && mne.getAlias().find(strFilter) == std::string::npos &&
654  mne.getIp().find(strFilter) == std::string::npos &&
655  mne.getTxHash().find(strFilter) == std::string::npos &&
656  strStatus.find(strFilter) == std::string::npos) continue;
657 
658  UniValue mnObj(UniValue::VOBJ);
659  mnObj.pushKV("alias", mne.getAlias());
660  mnObj.pushKV("address", mne.getIp());
661  mnObj.pushKV("privateKey", mne.getPrivKey());
662  mnObj.pushKV("txHash", mne.getTxHash());
663  mnObj.pushKV("outputIndex", mne.getOutputIndex());
664  mnObj.pushKV("status", strStatus);
665  ret.push_back(mnObj);
666  }
667 
668  return ret;
669 }
670 
672 {
673  if (request.fHelp || (request.params.size() != 0))
674  throw std::runtime_error(
675  "getmasternodestatus\n"
676  "\nPrint masternode status\n"
677 
678  "\nResult (if legacy masternode):\n"
679  "{\n"
680  " \"txhash\": \"xxxx\", (string) Collateral transaction hash\n"
681  " \"outputidx\": n, (numeric) Collateral transaction output index number\n"
682  " \"netaddr\": \"xxxx\", (string) Masternode network address\n"
683  " \"addr\": \"xxxx\", (string) PIVX address for masternode payments\n"
684  " \"status\": \"xxxx\", (string) Masternode status\n"
685  " \"message\": \"xxxx\" (string) Masternode status message\n"
686  "}\n"
687  "\n"
688  "\nResult (if deterministic masternode):\n"
689  "{\n"
690  "... !TODO ...\n"
691  "}\n"
692 
693  "\nExamples:\n" +
694  HelpExampleCli("getmasternodestatus", "") + HelpExampleRpc("getmasternodestatus", ""));
695 
696  if (!fMasterNode)
697  throw JSONRPCError(RPC_MISC_ERROR, _("This is not a masternode."));
698 
699  bool fLegacyMN = (activeMasternode.vin != nullopt);
700  bool fDeterministicMN = (activeMasternodeManager != nullptr);
701 
702  if (!fLegacyMN && !fDeterministicMN) {
703  throw JSONRPCError(RPC_MISC_ERROR, _("Active Masternode not initialized."));
704  }
705 
706  if (fDeterministicMN) {
707  if (!deterministicMNManager->IsDIP3Enforced()) {
708  // this should never happen as ProTx transactions are not accepted yet
709  throw JSONRPCError(RPC_MISC_ERROR, _("Deterministic masternodes are not enforced yet"));
710  }
712  UniValue mnObj(UniValue::VOBJ);
713  auto dmn = deterministicMNManager->GetListAtChainTip().GetMNByOperatorKey(amninfo->pubKeyOperator);
714  if (dmn) {
715  dmn->ToJson(mnObj);
716  }
717  mnObj.pushKV("netaddr", amninfo->service.ToString());
718  mnObj.pushKV("status", activeMasternodeManager->GetStatus());
719  return mnObj;
720  }
721 
722  // Legacy code !TODO: remove when transition to DMN is complete
723  if (deterministicMNManager->LegacyMNObsolete()) {
724  throw JSONRPCError(RPC_MISC_ERROR, _("Legacy Masternode is obsolete."));
725  }
726 
727  CMasternode* pmn = mnodeman.Find(activeMasternode.vin->prevout);
728 
729  if (pmn) {
730  UniValue mnObj(UniValue::VOBJ);
731  mnObj.pushKV("txhash", activeMasternode.vin->prevout.hash.ToString());
732  mnObj.pushKV("outputidx", (uint64_t)activeMasternode.vin->prevout.n);
733  mnObj.pushKV("netaddr", activeMasternode.service.ToString());
734  mnObj.pushKV("addr", EncodeDestination(pmn->pubKeyCollateralAddress.GetID()));
735  mnObj.pushKV("status", activeMasternode.GetStatus());
736  mnObj.pushKV("message", activeMasternode.GetStatusMessage());
737  return mnObj;
738  }
739  throw std::runtime_error("Masternode not found in the list of available masternodes. Current status: "
741 }
742 
744 {
745  if (request.fHelp || request.params.size() > 2)
746  throw std::runtime_error(
747  "getmasternodewinners ( blocks \"filter\" )\n"
748  "\nPrint the masternode winners for the last n blocks\n"
749 
750  "\nArguments:\n"
751  "1. blocks (numeric, optional) Number of previous blocks to show (default: 10)\n"
752  "2. filter (string, optional) Search filter matching MN address\n"
753 
754  "\nResult (single winner):\n"
755  "[\n"
756  " {\n"
757  " \"nHeight\": n, (numeric) block height\n"
758  " \"winner\": {\n"
759  " \"address\": \"xxxx\", (string) PIVX MN Address\n"
760  " \"nVotes\": n, (numeric) Number of votes for winner\n"
761  " }\n"
762  " }\n"
763  " ,...\n"
764  "]\n"
765 
766  "\nResult (multiple winners):\n"
767  "[\n"
768  " {\n"
769  " \"nHeight\": n, (numeric) block height\n"
770  " \"winner\": [\n"
771  " {\n"
772  " \"address\": \"xxxx\", (string) PIVX MN Address\n"
773  " \"nVotes\": n, (numeric) Number of votes for winner\n"
774  " }\n"
775  " ,...\n"
776  " ]\n"
777  " }\n"
778  " ,...\n"
779  "]\n"
780 
781  "\nExamples:\n" +
782  HelpExampleCli("getmasternodewinners", "") + HelpExampleRpc("getmasternodewinners", ""));
783 
784  int nHeight = WITH_LOCK(cs_main, return chainActive.Height());
785  if (nHeight < 0) return "[]";
786 
787  int nLast = 10;
788  std::string strFilter = "";
789 
790  if (request.params.size() >= 1)
791  nLast = atoi(request.params[0].get_str());
792 
793  if (request.params.size() == 2)
794  strFilter = request.params[1].get_str();
795 
797 
798  for (int i = nHeight - nLast; i < nHeight + 20; i++) {
800  obj.pushKV("nHeight", i);
801 
802  std::string strPayment = GetRequiredPaymentsString(i);
803  if (strFilter != "" && strPayment.find(strFilter) == std::string::npos) continue;
804 
805  if (strPayment.find(',') != std::string::npos) {
806  UniValue winner(UniValue::VARR);
807  boost::char_separator<char> sep(",");
808  boost::tokenizer< boost::char_separator<char> > tokens(strPayment, sep);
809  for (const std::string& t : tokens) {
810  UniValue addr(UniValue::VOBJ);
811  std::size_t pos = t.find(":");
812  std::string strAddress = t.substr(0,pos);
813  uint64_t nVotes = atoi(t.substr(pos+1));
814  addr.pushKV("address", strAddress);
815  addr.pushKV("nVotes", nVotes);
816  winner.push_back(addr);
817  }
818  obj.pushKV("winner", winner);
819  } else if (strPayment.find("Unknown") == std::string::npos) {
820  UniValue winner(UniValue::VOBJ);
821  std::size_t pos = strPayment.find(":");
822  std::string strAddress = strPayment.substr(0,pos);
823  uint64_t nVotes = atoi(strPayment.substr(pos+1));
824  winner.pushKV("address", strAddress);
825  winner.pushKV("nVotes", nVotes);
826  obj.pushKV("winner", winner);
827  } else {
828  UniValue winner(UniValue::VOBJ);
829  winner.pushKV("address", strPayment);
830  winner.pushKV("nVotes", 0);
831  obj.pushKV("winner", winner);
832  }
833 
834  ret.push_back(obj);
835  }
836 
837  return ret;
838 }
839 
841 {
842  if (request.fHelp || request.params.size() > 1)
843  throw std::runtime_error(
844  "getmasternodescores ( blocks )\n"
845  "\nPrint list of winning masternode by score\n"
846 
847  "\nArguments:\n"
848  "1. blocks (numeric, optional) Show the last n blocks (default 10)\n"
849 
850  "\nResult:\n"
851  "{\n"
852  " xxxx: \"xxxx\" (numeric : string) Block height : Masternode hash\n"
853  " ,...\n"
854  "}\n"
855 
856  "\nExamples:\n" +
857  HelpExampleCli("getmasternodescores", "") + HelpExampleRpc("getmasternodescores", ""));
858 
859  int nLast = 10;
860 
861  if (request.params.size() == 1) {
862  try {
863  nLast = std::stoi(request.params[0].get_str());
864  } catch (const std::invalid_argument&) {
865  throw std::runtime_error("Exception on param 2");
866  }
867  }
868 
869  std::vector<std::pair<MasternodeRef, int>> vMnScores = mnodeman.GetMnScores(nLast);
870  if (vMnScores.empty()) return "unknown";
871 
873  for (const auto& p : vMnScores) {
874  const MasternodeRef& mn = p.first;
875  const int nHeight = p.second;
876  obj.pushKV(strprintf("%d", nHeight), mn->vin.prevout.hash.ToString().c_str());
877  }
878  return obj;
879 }
880 
881 bool DecodeAddrV1(CMasternodeBroadcast& mnb, std::string strHexMnb) {
882  std::vector<unsigned char> mnbData(ParseHex(strHexMnb));
883  CDataStream ssData(mnbData, SER_NETWORK, PROTOCOL_VERSION);
884  try {
885  ssData >> mnb;
886  }
887  catch (const std::exception&) {
888  return false;
889  }
890 
891  return true;
892 }
893 
894 bool DecodeHexMnb(CMasternodeBroadcast& mnb, std::string strHexMnb) {
895 
896  if (!IsHex(strHexMnb))
897  return false;
898 
899  bool MNAddrV1 = DecodeAddrV1(mnb, strHexMnb);
900  if (!MNAddrV1) {
901  std::vector<unsigned char> mnbData(ParseHex(strHexMnb));
902  CDataStream ssData(mnbData, SER_NETWORK, PROTOCOL_VERSION | ADDRV2_FORMAT);
903  try {
904  ssData >> mnb;
905  }
906  catch (const std::exception&) {
907  return false;
908  }
909  return true;
910  }
911  return true;
912 }
913 
915 {
916  CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
917 
918  if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
919  return NullUniValue;
920 
921  std::string strCommand;
922  if (request.params.size() >= 1)
923  strCommand = request.params[0].get_str();
924  if (request.fHelp || (strCommand != "alias" && strCommand != "all") || (strCommand == "alias" && request.params.size() < 2))
925  throw std::runtime_error(
926  "createmasternodebroadcast \"command\" ( \"alias\")\n"
927  "\nCreates a masternode broadcast message for one or all masternodes configured in masternode.conf\n" +
928  HelpRequiringPassphrase(pwallet) + "\n"
929 
930  "\nArguments:\n"
931  "1. \"command\" (string, required) \"alias\" for single masternode, \"all\" for all masternodes\n"
932  "2. \"alias\" (string, required if command is \"alias\") Alias of the masternode\n"
933 
934  "\nResult (all):\n"
935  "{\n"
936  " \"overall\": \"xxx\", (string) Overall status message indicating number of successes.\n"
937  " \"detail\": [ (array) JSON array of broadcast objects.\n"
938  " {\n"
939  " \"alias\": \"xxx\", (string) Alias of the masternode.\n"
940  " \"success\": true|false, (boolean) Success status.\n"
941  " \"hex\": \"xxx\" (string, if success=true) Hex encoded broadcast message.\n"
942  " \"error_message\": \"xxx\" (string, if success=false) Error message, if any.\n"
943  " }\n"
944  " ,...\n"
945  " ]\n"
946  "}\n"
947 
948  "\nResult (alias):\n"
949  "{\n"
950  " \"alias\": \"xxx\", (string) Alias of the masternode.\n"
951  " \"success\": true|false, (boolean) Success status.\n"
952  " \"hex\": \"xxx\" (string, if success=true) Hex encoded broadcast message.\n"
953  " \"error_message\": \"xxx\" (string, if success=false) Error message, if any.\n"
954  "}\n"
955 
956  "\nExamples:\n" +
957  HelpExampleCli("createmasternodebroadcast", "alias mymn1") + HelpExampleRpc("createmasternodebroadcast", "alias mymn1"));
958 
959  EnsureWalletIsUnlocked(pwallet);
960 
961  if (strCommand == "alias")
962  {
963  // wait for reindex and/or import to finish
964  if (fImporting || fReindex)
965  throw JSONRPCError(RPC_INTERNAL_ERROR, "Wait for reindex and/or import to finish");
966 
967  std::string alias = request.params[1].get_str();
968  bool found = false;
969 
970  UniValue statusObj(UniValue::VOBJ);
971  statusObj.pushKV("alias", alias);
972 
974  if(mne.getAlias() == alias) {
976  found = true;
977  std::string errorMessage;
978  bool fSuccess = false;
979  if (!StartMasternodeEntry(statusObj, mnb, fSuccess, mne, errorMessage, strCommand))
980  continue;
981  SerializeMNB(statusObj, mnb, fSuccess);
982  break;
983  }
984  }
985 
986  if(!found) {
987  statusObj.pushKV("success", false);
988  statusObj.pushKV("error_message", "Could not find alias in config. Verify with listmasternodeconf.");
989  }
990 
991  return statusObj;
992  }
993 
994  if (strCommand == "all")
995  {
996  // wait for reindex and/or import to finish
997  if (fImporting || fReindex)
998  throw JSONRPCError(RPC_INTERNAL_ERROR, "Wait for reindex and/or import to finish");
999 
1000  int successful = 0;
1001  int failed = 0;
1002 
1003  UniValue resultsObj(UniValue::VARR);
1004 
1006  UniValue statusObj(UniValue::VOBJ);
1008  std::string errorMessage;
1009  bool fSuccess = false;
1010  if (!StartMasternodeEntry(statusObj, mnb, fSuccess, mne, errorMessage, strCommand))
1011  continue;
1012  SerializeMNB(statusObj, mnb, fSuccess, successful, failed);
1013  resultsObj.push_back(statusObj);
1014  }
1015 
1016  UniValue returnObj(UniValue::VOBJ);
1017  returnObj.pushKV("overall", strprintf("Successfully created broadcast messages for %d masternodes, failed to create %d, total %d", successful, failed, successful + failed));
1018  returnObj.pushKV("detail", resultsObj);
1019 
1020  return returnObj;
1021  }
1022  return NullUniValue;
1023 }
1024 
1026 {
1027  if (request.fHelp || request.params.size() != 1)
1028  throw std::runtime_error(
1029  "decodemasternodebroadcast \"hexstring\"\n"
1030  "\nCommand to decode masternode broadcast messages\n"
1031 
1032  "\nArgument:\n"
1033  "1. \"hexstring\" (string) The hex encoded masternode broadcast message\n"
1034 
1035  "\nResult:\n"
1036  "{\n"
1037  " \"vin\": \"xxxx\" (string) The unspent output which is holding the masternode collateral\n"
1038  " \"addr\": \"xxxx\" (string) IP address of the masternode\n"
1039  " \"pubkeycollateral\": \"xxxx\" (string) Collateral address's public key\n"
1040  " \"pubkeymasternode\": \"xxxx\" (string) Masternode's public key\n"
1041  " \"vchsig\": \"xxxx\" (string) Base64-encoded signature of this message (verifiable via pubkeycollateral)\n"
1042  " \"sigtime\": \"nnn\" (numeric) Signature timestamp\n"
1043  " \"sigvalid\": \"xxx\" (string) \"true\"/\"false\" whether or not the mnb signature checks out.\n"
1044  " \"protocolversion\": \"nnn\" (numeric) Masternode's protocol version\n"
1045  " \"nMessVersion\": \"nnn\" (numeric) MNB Message version number\n"
1046  " \"lastping\" : { (object) JSON object with information about the masternode's last ping\n"
1047  " \"vin\": \"xxxx\" (string) The unspent output of the masternode which is signing the message\n"
1048  " \"blockhash\": \"xxxx\" (string) Current chaintip blockhash minus 12\n"
1049  " \"sigtime\": \"nnn\" (numeric) Signature time for this ping\n"
1050  " \"sigvalid\": \"xxx\" (string) \"true\"/\"false\" whether or not the mnp signature checks out.\n"
1051  " \"vchsig\": \"xxxx\" (string) Base64-encoded signature of this ping (verifiable via pubkeymasternode)\n"
1052  " \"nMessVersion\": \"nnn\" (numeric) MNP Message version number\n"
1053  " }\n"
1054  "}\n"
1055 
1056  "\nExamples:\n" +
1057  HelpExampleCli("decodemasternodebroadcast", "hexstring") + HelpExampleRpc("decodemasternodebroadcast", "hexstring"));
1058 
1060 
1061  if (!DecodeHexMnb(mnb, request.params[0].get_str()))
1062  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Masternode broadcast message decode failed");
1063 
1064  UniValue resultObj(UniValue::VOBJ);
1065 
1066  resultObj.pushKV("vin", mnb.vin.prevout.ToString());
1067  resultObj.pushKV("addr", mnb.addr.ToString());
1068  resultObj.pushKV("pubkeycollateral", EncodeDestination(mnb.pubKeyCollateralAddress.GetID()));
1069  resultObj.pushKV("pubkeymasternode", EncodeDestination(mnb.pubKeyMasternode.GetID()));
1070  resultObj.pushKV("vchsig", mnb.GetSignatureBase64());
1071  resultObj.pushKV("sigtime", mnb.sigTime);
1072  resultObj.pushKV("sigvalid", mnb.CheckSignature() ? "true" : "false");
1073  resultObj.pushKV("protocolversion", mnb.protocolVersion);
1074  resultObj.pushKV("nMessVersion", mnb.nMessVersion);
1075 
1076  UniValue lastPingObj(UniValue::VOBJ);
1077  lastPingObj.pushKV("vin", mnb.lastPing.vin.prevout.ToString());
1078  lastPingObj.pushKV("blockhash", mnb.lastPing.blockHash.ToString());
1079  lastPingObj.pushKV("sigtime", mnb.lastPing.sigTime);
1080  lastPingObj.pushKV("sigvalid", mnb.lastPing.CheckSignature(mnb.pubKeyMasternode.GetID()) ? "true" : "false");
1081  lastPingObj.pushKV("vchsig", mnb.lastPing.GetSignatureBase64());
1082  lastPingObj.pushKV("nMessVersion", mnb.lastPing.nMessVersion);
1083 
1084  resultObj.pushKV("lastping", lastPingObj);
1085 
1086  return resultObj;
1087 }
1088 
1090 {
1091  if (request.fHelp || request.params.size() != 1)
1092  throw std::runtime_error(
1093  "relaymasternodebroadcast \"hexstring\"\n"
1094  "\nCommand to relay masternode broadcast messages\n"
1095 
1096  "\nArguments:\n"
1097  "1. \"hexstring\" (string) The hex encoded masternode broadcast message\n"
1098 
1099  "\nExamples:\n" +
1100  HelpExampleCli("relaymasternodebroadcast", "hexstring") + HelpExampleRpc("relaymasternodebroadcast", "hexstring"));
1101 
1102 
1104 
1105  if (!DecodeHexMnb(mnb, request.params[0].get_str()))
1106  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Masternode broadcast message decode failed");
1107 
1108  if(!mnb.CheckSignature())
1109  throw JSONRPCError(RPC_INVALID_PARAMETER, "Masternode broadcast signature verification failed");
1110 
1112  mnb.Relay();
1113 
1114  return strprintf("Masternode broadcast sent (service %s, vin %s)", mnb.addr.ToString(), mnb.vin.ToString());
1115 }
1116 
1117 // clang-format off
1118 static const CRPCCommand commands[] =
1119 { // category name actor (function) okSafe argNames
1120  // --------------------- --------------------------- -------------------------- ------ --------
1121  { "masternode", "createmasternodebroadcast", &createmasternodebroadcast, true, {"command","alias"} },
1122  { "masternode", "createmasternodekey", &createmasternodekey, true, {} },
1123  { "masternode", "decodemasternodebroadcast", &decodemasternodebroadcast, true, {"hexstring"} },
1124  { "masternode", "getmasternodecount", &getmasternodecount, true, {} },
1125  { "masternode", "getmasternodeoutputs", &getmasternodeoutputs, true, {} },
1126  { "masternode", "getmasternodescores", &getmasternodescores, true, {"blocks"} },
1127  { "masternode", "getmasternodestatus", &getmasternodestatus, true, {} },
1128  { "masternode", "getmasternodewinners", &getmasternodewinners, true, {"blocks","filter"} },
1129  { "masternode", "initmasternode", &initmasternode, true, {"privkey","address","deterministic"} },
1130  { "masternode", "listmasternodeconf", &listmasternodeconf, true, {"filter"} },
1131  { "masternode", "listmasternodes", &listmasternodes, true, {"filter"} },
1132  { "masternode", "masternodecurrent", &masternodecurrent, true, {} },
1133  { "masternode", "relaymasternodebroadcast", &relaymasternodebroadcast, true, {"hexstring"} },
1134  { "masternode", "startmasternode", &startmasternode, true, {"set","lock_wallet","alias","reload_conf"} },
1135 
1137  { "hidden", "getcachedblockhashes", &getcachedblockhashes, true, {} },
1138  { "hidden", "mnping", &mnping, true, {} },
1139 };
1140 // clang-format on
1141 
1143 {
1144  for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
1145  tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
1146 }
OperationResult initMasternode(const std::string &_strMasterNodePrivKey, const std::string &_strMasterNodeAddr, bool isFromInit)
CActiveDeterministicMasternodeManager * activeMasternodeManager
const CChainParams & Params()
Return the currently selected parameters.
uint256 hash
Definition: transaction.h:35
std::string ToStringShort() const
Definition: transaction.cpp:13
uint32_t n
Definition: transaction.h:36
masternode_state_t GetState() const
OperationResult SetOperatorKey(const std::string &strMNOperatorPrivKey)
const CActiveMasternodeInfo * GetInfo() const
void Init(const CBlockIndex *pindexTip)
Optional< CTxIn > vin
std::string GetStatusMessage() const
bool SendMasternodePing(std::string &errorMessage)
Ping Masternode.
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:139
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:151
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:405
int Height() const
Return the maximal height in the chain.
Definition: chain.h:450
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:72
An encapsulated private key.
Definition: key.h:30
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
Definition: key.cpp:158
static bool Create(const CTxIn &vin, 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.
Definition: masternode.cpp:290
bool CheckSignature() const
Definition: masternode.cpp:353
const std::string & getTxHash() const
const std::string & getOutputIndex() const
const std::string & getIp() const
bool castOutputIndex(int &n) const
const std::string & getPrivKey() const
const std::string & getAlias() const
bool read(std::string &strErr)
std::vector< CMasternodeEntry > getEntries()
CMasternodePing lastPing
Definition: masternode.h:104
CService addr
Definition: masternode.h:97
CTxIn vin
Definition: masternode.h:96
CPubKey pubKeyMasternode
Definition: masternode.h:99
CScript mnPayeeScript
Definition: masternode.h:230
std::string Status() const
Definition: masternode.h:209
int protocolVersion
Definition: masternode.h:101
int64_t sigTime
Definition: masternode.h:100
bool IsEnabled() const
Definition: masternode.h:193
CPubKey pubKeyCollateralAddress
Definition: masternode.h:98
void UpdateMasternodeList(CMasternodeBroadcast &mnb)
Update masternode list and maps using provided CMasternodeBroadcast.
int CountEnabled(bool only_legacy=false) const
std::vector< std::pair< int64_t, MasternodeRef > > GetMasternodeRanks(int nBlockHeight) const
std::vector< std::pair< MasternodeRef, int > > GetMnScores(int nLast) const
vector of pairs <masternode winner, height>
MasternodeRef GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int &nCount, const CBlockIndex *pChainTip=nullptr) const
Find an entry in the masternode list that is next to be paid.
int GetBestHeight() const
int64_t GetLastPaid(const MasternodeRef &mn, int count_enabled, const CBlockIndex *BlockReading) const
Get the time a masternode was last paid.
CMasternodeMan::MNsInfo getMNsInfo() const
CMasternode * Find(const COutPoint &collateralOut)
Find an entry.
std::vector< uint256 > GetCachedBlocks() const
int64_t sigTime
Definition: masternode.h:46
uint256 blockHash
Definition: masternode.h:45
Network address.
Definition: netaddress.h:120
enum Network GetNetwork() const
Definition: netaddress.cpp:489
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Definition: netaddress.cpp:469
std::string ToString() const
Definition: transaction.cpp:18
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:167
std::string name
Definition: server.h:137
PIVX RPC command dispatcher.
Definition: server.h:147
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:314
std::string ToString() const
Definition: netaddress.cpp:954
bool CheckSignature(const CKeyID &keyID) const
std::string GetSignatureBase64() const
An input of a transaction.
Definition: transaction.h:94
std::string ToString() const
Definition: transaction.cpp:53
COutPoint prevout
Definition: transaction.h:96
CScript scriptPubKey
Definition: transaction.h:140
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:577
A UTXO entry.
Definition: coins.h:32
CTxOut out
unspent transaction output
Definition: coins.h:41
UniValue params
Definition: server.h:47
bool fHelp
Definition: server.h:48
int GetSyncPhase() const
const std::string & get_str() const
@ VOBJ
Definition: univalue.h:21
@ VARR
Definition: univalue.h:21
size_t size() const
Definition: univalue.h:68
bool empty() const
Definition: univalue.h:66
bool push_back(const UniValue &val)
Definition: univalue.cpp:108
bool pushKV(const std::string &key, const UniValue &val)
Definition: univalue.cpp:133
bool get_bool() const
std::string ToString() const
Definition: uint256.cpp:65
bool empty() const
Definition: prevector.h:281
std::unique_ptr< CDeterministicMNManager > deterministicMNManager
std::shared_ptr< const CDeterministicMN > CDeterministicMNCPtr
bool AvailableCoins(std::vector< COutput > *pCoins, const CCoinControl *coinControl=nullptr, AvailableCoinsFilter coinsFilter=AvailableCoinsFilter()) const
populate vCoins with vector of available COutputs.
Definition: wallet.cpp:2555
bool Lock()
Definition: wallet.cpp:397
std::string GetRequiredPaymentsString(int nBlockHeight)
std::shared_ptr< CMasternode > MasternodeRef
Definition: masternode.h:24
CMasternodeConfig masternodeConfig
CMasternodeMan mnodeman
Masternode manager.
CActiveMasternode activeMasternode
Keep track of the active Masternode.
std::string EncodeSecret(const CKey &key)
Definition: key_io.cpp:145
std::string EncodeDestination(const CWDestination &address, const CChainParams::Base58Type addrType)
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:80
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
Definition: netbase.cpp:71
std::string GetNetworkName(enum Network net)
Definition: netbase.cpp:55
bool LookupHost(const std::string &name, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
Definition: netbase.cpp:149
UniValue getmasternodewinners(const JSONRPCRequest &request)
Definition: masternode.cpp:743
UniValue initmasternode(const JSONRPCRequest &request)
Definition: masternode.cpp:74
UniValue createmasternodebroadcast(const JSONRPCRequest &request)
Definition: masternode.cpp:914
void RegisterMasternodeRPCCommands(CRPCTable &tableRPC)
Register masternode RPC commands.
bool DecodeHexMnb(CMasternodeBroadcast &mnb, std::string strHexMnb)
Definition: masternode.cpp:894
UniValue relaymasternodebroadcast(const JSONRPCRequest &request)
UniValue masternodecurrent(const JSONRPCRequest &request)
Definition: masternode.cpp:315
UniValue getmasternodeoutputs(const JSONRPCRequest &request)
Definition: masternode.cpp:565
bool StartMasternodeEntry(UniValue &statusObjRet, CMasternodeBroadcast &mnbRet, bool &fSuccessRet, const CMasternodeConfig::CMasternodeEntry &mne, std::string &errorMessage, std::string strCommand="")
Definition: masternode.cpp:352
UniValue createmasternodekey(const JSONRPCRequest &request)
Definition: masternode.cpp:546
UniValue decodemasternodebroadcast(const JSONRPCRequest &request)
void SerializeMNB(UniValue &statusObjRet, const CMasternodeBroadcast &mnb, const bool fSuccess, int &successful, int &failed)
Definition: masternode.cpp:392
UniValue startmasternode(const JSONRPCRequest &request)
Definition: masternode.cpp:412
UniValue getmasternodescores(const JSONRPCRequest &request)
Definition: masternode.cpp:840
bool DecodeAddrV1(CMasternodeBroadcast &mnb, std::string strHexMnb)
Definition: masternode.cpp:881
UniValue listmasternodes(const JSONRPCRequest &request)
Definition: masternode.cpp:161
UniValue getmasternodecount(const JSONRPCRequest &request)
Definition: masternode.cpp:275
UniValue mnping(const JSONRPCRequest &request)
Definition: masternode.cpp:43
UniValue listmasternodeconf(const JSONRPCRequest &request)
Definition: masternode.cpp:609
UniValue getmasternodestatus(const JSONRPCRequest &request)
Definition: masternode.cpp:671
UniValue getcachedblockhashes(const JSONRPCRequest &request)
Definition: masternode.cpp:119
void RelayMNB(CMasternodeBroadcast &mnb, const bool fSuccess, int &successful, int &failed)
Definition: masternode.cpp:375
UniValue JSONRPCError(int code, const std::string &message)
Definition: protocol.cpp:53
@ RPC_MISC_ERROR
General application defined errors.
Definition: protocol.h:41
@ RPC_INVALID_PARAMETER
Ran out of memory during operation.
Definition: protocol.h:46
@ RPC_INTERNAL_ERROR
Definition: protocol.h:37
@ RPC_DESERIALIZATION_ERROR
Database error.
Definition: protocol.h:48
CWallet * GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
Definition: rpcwallet.cpp:39
std::string HelpRequiringPassphrase(CWallet *const pwallet)
Definition: rpcwallet.cpp:54
void EnsureWalletIsUnlocked(CWallet *const pwallet, bool fAllowAnonOnly)
Definition: rpcwallet.cpp:71
bool EnsureWalletIsAvailable(CWallet *const pwallet, bool avoidException)
Definition: rpcwallet.cpp:59
@ SER_NETWORK
Definition: serialize.h:174
std::string HelpExampleCli(std::string methodname, std::string args)
Definition: server.cpp:527
void RPCTypeCheck(const UniValue &params, const std::list< UniValue::VType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
Definition: server.cpp:63
std::string HelpExampleRpc(std::string methodname, std::string args)
Definition: server.cpp:532
CRPCTable tableRPC
Definition: server.cpp:565
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet, bool fColdStake)
Parse a standard scriptPubKey for the destination address.
Definition: standard.cpp:162
boost::variant< CNoDestination, CKeyID, CScriptID, CExchangeKeyID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:72
CBLSPublicKey pubKeyOperator
CAmount nMNCollateralAmt
Definition: params.h:184
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:247
std::atomic< bool > fMasterNode
Definition: system.cpp:87
bool error(const char *fmt, const Args &... args)
Definition: system.h:77
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a Optional result.
Definition: system.h:65
TierTwoSyncState g_tiertwo_sync_state
#define MASTERNODE_SYNC_FAILED
#define MASTERNODE_SYNC_LIST
#define strprintf
Definition: tinyformat.h:1056
uint256 uint256S(const char *str)
Definition: uint256.h:157
const UniValue NullUniValue
Definition: univalue.cpp:13
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
std::vector< unsigned char > ParseHex(const char *psz)
bool IsHex(const std::string &str)
int atoi(const std::string &str)
#define ARRAYLEN(array)
std::unique_ptr< CCoinsViewCache > pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: validation.cpp:206
std::atomic< bool > fImporting
Definition: validation.cpp:94
CBlockIndex * GetChainTip()
Return a reliable pointer (in mapBlockIndex) to the chain's tip index.
Definition: validation.cpp:194
std::atomic< bool > fReindex
Definition: validation.cpp:95
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:84
void RegisterValidationInterface(CValidationInterface *pwalletIn)
Register a wallet to receive updates from core.