PRCYCoin  2.0.0.7rc1
P2P Digital Currency
budget.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2015 The Dash Developers
2 // Copyright (c) 2015-2018 The PIVX developers
3 // Copyright (c) 2018-2020 The DAPS Project developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include "activemasternode.h"
8 #include "wallet/db.h"
9 #include "init.h"
10 #include "main.h"
11 #include "masternode-budget.h"
12 #include "masternode-payments.h"
13 #include "masternode-sync.h"
14 #include "masternodeconfig.h"
15 #include "masternodeman.h"
16 #include "messagesigner.h"
17 #include "rpc/server.h"
18 #include "utilmoneystr.h"
19 
20 #include <univalue.h>
21 
22 #include <fstream>
23 
24 
25 void budgetToJSON(CBudgetProposal* pbudgetProposal, UniValue& bObj)
26 {
27  CTxDestination address1;
28  ExtractDestination(pbudgetProposal->GetPayee(), address1);
29  CBitcoinAddress address2(address1);
30 
31  bObj.push_back(Pair("Name", pbudgetProposal->GetName()));
32  bObj.push_back(Pair("URL", pbudgetProposal->GetURL()));
33  bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString()));
34  bObj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString()));
35  bObj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart()));
36  bObj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd()));
37  bObj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount()));
38  bObj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount()));
39  bObj.push_back(Pair("PaymentAddress", address2.ToString()));
40  bObj.push_back(Pair("Ratio", pbudgetProposal->GetRatio()));
41  bObj.push_back(Pair("Yeas", (int64_t)pbudgetProposal->GetYeas()));
42  bObj.push_back(Pair("Nays", (int64_t)pbudgetProposal->GetNays()));
43  bObj.push_back(Pair("Abstains", (int64_t)pbudgetProposal->GetAbstains()));
44  bObj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount() * pbudgetProposal->GetTotalPaymentCount())));
45  bObj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount())));
46  bObj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished()));
47 
48  std::string strError = "";
49  bObj.push_back(Pair("IsValid", pbudgetProposal->IsValid(strError)));
50  bObj.push_back(Pair("IsValidReason", strError.c_str()));
51  bObj.push_back(Pair("fValid", pbudgetProposal->fValid));
52 }
53 
54 UniValue preparebudget(const UniValue& params, bool fHelp)
55 {
56  int nBlockMin = 0;
57  CBlockIndex* pindexPrev = chainActive.Tip();
58 
59  if (fHelp || params.size() != 6)
60  throw std::runtime_error(
61  "preparebudget \"proposal-name\" \"url\" payment-count block-start \"prcycoin-address\" monthly-payment\n"
62  "\nPrepare proposal for network by signing and creating tx\n"
63 
64  "\nArguments:\n"
65  "1. \"proposal-name\": (string, required) Desired proposal name (20 character limit)\n"
66  "2. \"url\": (string, required) URL of proposal details (64 character limit)\n"
67  "3. payment-count: (numeric, required) Total number of monthly payments\n"
68  "4. block-start: (numeric, required) Starting super block height\n"
69  "5. \"prcycoin-address\": (string, required) PRCY address to send payments to\n"
70  "6. monthly-payment: (numeric, required) Monthly payment amount\n"
71 
72  "\nResult:\n"
73  "\"xxxx\" (string) proposal fee hash (if successful) or error message (if failed)\n"
74  "\nExamples:\n" +
75  HelpExampleCli("preparebudget", "\"test-proposal\" \"https://forum.prcycoin.com/t/test-proposal\" 2 820800 \"D9oc6C3dttUbv8zd7zGNq1qKBGf4ZQ1XEE\" 500") +
76  HelpExampleRpc("preparebudget", "\"test-proposal\" \"https://forum.prcycoin.com/t/test-proposal\" 2 820800 \"D9oc6C3dttUbv8zd7zGNq1qKBGf4ZQ1XEE\" 500"));
77 
79 
81 
82  std::string strProposalName = SanitizeString(params[0].get_str());
83  if (strProposalName.size() > 20)
84  throw std::runtime_error("Invalid proposal name, limit of 20 characters.");
85 
86  std::string strURL = SanitizeString(params[1].get_str());
87  if (strURL.size() > 64)
88  throw std::runtime_error("Invalid url, limit of 64 characters.");
89 
90  int nPaymentCount = params[2].get_int();
91  if (nPaymentCount < 1)
92  throw std::runtime_error("Invalid payment count, must be more than zero.");
93 
94  // Start must be in the next budget cycle
95  if (pindexPrev != NULL) nBlockMin = pindexPrev->nHeight - pindexPrev->nHeight % GetBudgetPaymentCycleBlocks() + GetBudgetPaymentCycleBlocks();
96 
97  int nBlockStart = params[3].get_int();
98  if (nBlockStart % GetBudgetPaymentCycleBlocks() != 0) {
99  int nNext = pindexPrev->nHeight - pindexPrev->nHeight % GetBudgetPaymentCycleBlocks() + GetBudgetPaymentCycleBlocks();
100  throw std::runtime_error(strprintf("Invalid block start - must be a budget cycle block. Next valid block: %d", nNext));
101  }
102 
103  int nBlockEnd = nBlockStart + GetBudgetPaymentCycleBlocks() * nPaymentCount; // End must be AFTER current cycle
104 
105  if (nBlockStart < nBlockMin)
106  throw std::runtime_error("Invalid block start, must be more than current height.");
107 
108  if (nBlockEnd < pindexPrev->nHeight)
109  throw std::runtime_error("Invalid ending block, starting block + (payment_cycle*payments) must be more than current height.");
110 
111  CBitcoinAddress address(params[4].get_str());
112  if (!address.IsValid())
113  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Prcycoin address");
114 
115  // Parse Prcycoin address
116  CScript scriptPubKey = GetScriptForDestination(address.Get());
117  CAmount nAmount = AmountFromValue(params[5]);
118 
119  //*************************************************************************
120 
121  // create transaction 15 minutes into the future, to allow for confirmation time
122  CBudgetProposalBroadcast budgetProposalBroadcast(strProposalName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, UINT256_ZERO);
123 
124  std::string strError = "";
125  if (!budgetProposalBroadcast.IsValid(strError, false))
126  throw std::runtime_error("Proposal is not valid - " + budgetProposalBroadcast.GetHash().ToString() + " - " + strError);
127 
128  bool useIX = false; //true;
129 
130  CWalletTx wtx;
131  if (!pwalletMain->GetBudgetSystemCollateralTX(wtx, budgetProposalBroadcast.GetHash(), useIX)) {
132  throw std::runtime_error("Error making collateral transaction for proposal. Please check your wallet balance.");
133  }
134 
135  // make our change address
136  CReserveKey reservekey(pwalletMain);
137  //send the tx to the network
138  pwalletMain->CommitTransaction(wtx, reservekey, useIX ? NetMsgType::IX : NetMsgType::TX);
139 
140  return wtx.GetHash().ToString();
141 }
142 
143 UniValue submitbudget(const UniValue& params, bool fHelp)
144 {
145  int nBlockMin = 0;
146  CBlockIndex* pindexPrev = chainActive.Tip();
147 
148  if (fHelp || params.size() != 7)
149  throw std::runtime_error(
150  "submitbudget \"proposal-name\" \"url\" payment-count block-start \"prcycoin-address\" monthly-payment \"fee-tx\"\n"
151  "\nSubmit proposal to the network\n"
152 
153  "\nArguments:\n"
154  "1. \"proposal-name\": (string, required) Desired proposal name (20 character limit)\n"
155  "2. \"url\": (string, required) URL of proposal details (64 character limit)\n"
156  "3. payment-count: (numeric, required) Total number of monthly payments\n"
157  "4. block-start: (numeric, required) Starting super block height\n"
158  "5. \"prcycoin-address\": (string, required) PRCY address to send payments to\n"
159  "6. monthly-payment: (numeric, required) Monthly payment amount\n"
160  "7. \"fee-tx\": (string, required) Transaction hash from preparebudget command\n"
161 
162  "\nResult:\n"
163  "\"xxxx\" (string) proposal hash (if successful) or error message (if failed)\n"
164  "\nExamples:\n" +
165  HelpExampleCli("submitbudget", "\"test-proposal\" \"https://forum.prcycoin.com/t/test-proposal\" 2 820800 \"D9oc6C3dttUbv8zd7zGNq1qKBGf4ZQ1XEE\" 500") +
166  HelpExampleRpc("submitbudget", "\"test-proposal\" \"https://forum.prcycoin.com/t/test-proposal\" 2 820800 \"D9oc6C3dttUbv8zd7zGNq1qKBGf4ZQ1XEE\" 500"));
167 
168  // Check these inputs the same way we check the vote commands:
169  // **********************************************************
170 
171  std::string strProposalName = SanitizeString(params[0].get_str());
172  if (strProposalName.size() > 20)
173  throw std::runtime_error("Invalid proposal name, limit of 20 characters.");
174 
175  std::string strURL = SanitizeString(params[1].get_str());
176  if (strURL.size() > 64)
177  throw std::runtime_error("Invalid url, limit of 64 characters.");
178 
179  int nPaymentCount = params[2].get_int();
180  if (nPaymentCount < 1)
181  throw std::runtime_error("Invalid payment count, must be more than zero.");
182 
183  // Start must be in the next budget cycle
184  if (pindexPrev != NULL) nBlockMin = pindexPrev->nHeight - pindexPrev->nHeight % GetBudgetPaymentCycleBlocks() + GetBudgetPaymentCycleBlocks();
185 
186  int nBlockStart = params[3].get_int();
187  if (nBlockStart % GetBudgetPaymentCycleBlocks() != 0) {
188  int nNext = pindexPrev->nHeight - pindexPrev->nHeight % GetBudgetPaymentCycleBlocks() + GetBudgetPaymentCycleBlocks();
189  throw std::runtime_error(strprintf("Invalid block start - must be a budget cycle block. Next valid block: %d", nNext));
190  }
191 
192  int nBlockEnd = nBlockStart + (GetBudgetPaymentCycleBlocks() * nPaymentCount); // End must be AFTER current cycle
193 
194  if (nBlockStart < nBlockMin)
195  throw std::runtime_error("Invalid block start, must be more than current height.");
196 
197  if (nBlockEnd < pindexPrev->nHeight)
198  throw std::runtime_error("Invalid ending block, starting block + (payment_cycle*payments) must be more than current height.");
199 
200  CBitcoinAddress address(params[4].get_str());
201  if (!address.IsValid())
202  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Prcycoin address");
203 
204  // Parse Prcycoin address
205  CScript scriptPubKey = GetScriptForDestination(address.Get());
206  CAmount nAmount = AmountFromValue(params[5]);
207  uint256 hash = ParseHashV(params[6], "parameter 1");
208 
209  //create the proposal incase we're the first to make it
210  CBudgetProposalBroadcast budgetProposalBroadcast(strProposalName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, hash);
211 
212  std::string strError = "";
213  int nConf = 0;
214  if (!IsBudgetCollateralValid(hash, budgetProposalBroadcast.GetHash(), strError, budgetProposalBroadcast.nTime, nConf)) {
215  throw std::runtime_error("Proposal FeeTX is not valid - " + hash.ToString() + " - " + strError);
216  }
217 
219  throw std::runtime_error("Must wait for client to sync with masternode network. Try again in a minute or so.");
220  }
221 
222  budget.mapSeenMasternodeBudgetProposals.insert(std::make_pair(budgetProposalBroadcast.GetHash(), budgetProposalBroadcast));
223  budgetProposalBroadcast.Relay();
224  if(budget.AddProposal(budgetProposalBroadcast)) {
225  return budgetProposalBroadcast.GetHash().ToString();
226  }
227  throw std::runtime_error("Invalid proposal, see debug.log for details.");
228 }
229 
230 UniValue mnbudgetvote(const UniValue& params, bool fHelp)
231 {
232  std::string strCommand;
233  if (params.size() >= 1) {
234  strCommand = params[0].get_str();
235 
236  // Backwards compatibility with legacy `mnbudget` command
237  if (strCommand == "vote") strCommand = "local";
238  if (strCommand == "vote-many") strCommand = "many";
239  if (strCommand == "vote-alias") strCommand = "alias";
240  }
241 
242  if (fHelp || (params.size() == 3 && (strCommand != "local" && strCommand != "many")) || (params.size() == 4 && strCommand != "alias") ||
243  params.size() > 4 || params.size() < 3)
244  throw std::runtime_error(
245  "mnbudgetvote \"local|many|alias\" \"votehash\" \"yes|no\" ( \"alias\" )\n"
246  "\nVote on a budget proposal\n"
247 
248  "\nArguments:\n"
249  "1. \"mode\" (string, required) The voting mode. 'local' for voting directly from a masternode, 'many' for voting with a MN controller and casting the same vote for each MN, 'alias' for voting with a MN controller and casting a vote for a single MN\n"
250  "2. \"votehash\" (string, required) The vote hash for the proposal\n"
251  "3. \"votecast\" (string, required) Your vote. 'yes' to vote for the proposal, 'no' to vote against\n"
252  "4. \"alias\" (string, required for 'alias' mode) The MN alias to cast a vote for.\n"
253 
254  "\nResult:\n"
255  "{\n"
256  " \"overall\": \"xxxx\", (string) The overall status message for the vote cast\n"
257  " \"detail\": [\n"
258  " {\n"
259  " \"node\": \"xxxx\", (string) 'local' or the MN alias\n"
260  " \"result\": \"xxxx\", (string) Either 'Success' or 'Failed'\n"
261  " \"error\": \"xxxx\", (string) Error message, if vote failed\n"
262  " }\n"
263  " ,...\n"
264  " ]\n"
265  "}\n"
266 
267  "\nExamples:\n" +
268  HelpExampleCli("mnbudgetvote", "\"local\" \"ed2f83cedee59a91406f5f47ec4d60bf5a7f9ee6293913c82976bd2d3a658041\" \"yes\"") +
269  HelpExampleRpc("mnbudgetvote", "\"local\" \"ed2f83cedee59a91406f5f47ec4d60bf5a7f9ee6293913c82976bd2d3a658041\" \"yes\""));
270 
271  uint256 hash = ParseHashV(params[1], "parameter 1");
272  std::string strVote = params[2].get_str();
273 
274  if (strVote != "yes" && strVote != "no") return "You can only vote 'yes' or 'no'";
275  int nVote = VOTE_ABSTAIN;
276  if (strVote == "yes") nVote = VOTE_YES;
277  if (strVote == "no") nVote = VOTE_NO;
278 
279  int success = 0;
280  int failed = 0;
281 
282  UniValue resultsObj(UniValue::VARR);
283 
284  if (strCommand == "local") {
285  CPubKey pubKeyMasternode;
286  CKey keyMasternode;
287 
288  UniValue statusObj(UniValue::VOBJ);
289 
290  while (true) {
291  if (!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, keyMasternode, pubKeyMasternode)) {
292  failed++;
293  statusObj.push_back(Pair("node", "local"));
294  statusObj.push_back(Pair("result", "failed"));
295  statusObj.push_back(Pair("error", "Masternode signing error, could not set key correctly."));
296  resultsObj.push_back(statusObj);
297  break;
298  }
299 
301  if (pmn == NULL) {
302  failed++;
303  statusObj.push_back(Pair("node", "local"));
304  statusObj.push_back(Pair("result", "failed"));
305  statusObj.push_back(Pair("error", "Failure to find masternode in list : " + activeMasternode.vin.ToString()));
306  resultsObj.push_back(statusObj);
307  break;
308  }
309 
310  CBudgetVote vote(activeMasternode.vin, hash, nVote);
311  if (!vote.Sign(keyMasternode, pubKeyMasternode)) {
312  failed++;
313  statusObj.push_back(Pair("node", "local"));
314  statusObj.push_back(Pair("result", "failed"));
315  statusObj.push_back(Pair("error", "Failure to sign."));
316  resultsObj.push_back(statusObj);
317  break;
318  }
319 
320  std::string strError = "";
321  if (budget.UpdateProposal(vote, NULL, strError)) {
322  success++;
323  budget.mapSeenMasternodeBudgetVotes.insert(std::make_pair(vote.GetHash(), vote));
324  vote.Relay();
325  statusObj.push_back(Pair("node", "local"));
326  statusObj.push_back(Pair("result", "success"));
327  statusObj.push_back(Pair("error", ""));
328  } else {
329  failed++;
330  statusObj.push_back(Pair("node", "local"));
331  statusObj.push_back(Pair("result", "failed"));
332  statusObj.push_back(Pair("error", "Error voting : " + strError));
333  }
334  resultsObj.push_back(statusObj);
335  break;
336  }
337 
338  UniValue returnObj(UniValue::VOBJ);
339  returnObj.push_back(Pair("overall", strprintf("Voted successfully %d time(s) and failed %d time(s).", success, failed)));
340  returnObj.push_back(Pair("detail", resultsObj));
341 
342  return returnObj;
343  }
344 
345  if (strCommand == "many") {
347  std::vector<unsigned char> vchMasterNodeSignature;
348  std::string strMasterNodeSignMessage;
349 
350  CPubKey pubKeyCollateralAddress;
351  CKey keyCollateralAddress;
352  CPubKey pubKeyMasternode;
353  CKey keyMasternode;
354 
355  UniValue statusObj(UniValue::VOBJ);
356 
357  if (!CMessageSigner::GetKeysFromSecret(mne.getPrivKey(), keyMasternode, pubKeyMasternode)) {
358  failed++;
359  statusObj.push_back(Pair("node", mne.getAlias()));
360  statusObj.push_back(Pair("result", "failed"));
361  statusObj.push_back(Pair("error", "Masternode signing error, could not set key correctly."));
362  resultsObj.push_back(statusObj);
363  continue;
364  }
365 
366  CMasternode* pmn = mnodeman.Find(pubKeyMasternode);
367  if (pmn == NULL) {
368  failed++;
369  statusObj.push_back(Pair("node", mne.getAlias()));
370  statusObj.push_back(Pair("result", "failed"));
371  statusObj.push_back(Pair("error", "Can't find masternode by pubkey"));
372  resultsObj.push_back(statusObj);
373  continue;
374  }
375 
376  CBudgetVote vote(pmn->vin, hash, nVote);
377  if (!vote.Sign(keyMasternode, pubKeyMasternode)) {
378  failed++;
379  statusObj.push_back(Pair("node", mne.getAlias()));
380  statusObj.push_back(Pair("result", "failed"));
381  statusObj.push_back(Pair("error", "Failure to sign."));
382  resultsObj.push_back(statusObj);
383  continue;
384  }
385 
386  std::string strError = "";
387  if (budget.UpdateProposal(vote, NULL, strError)) {
388  budget.mapSeenMasternodeBudgetVotes.insert(std::make_pair(vote.GetHash(), vote));
389  vote.Relay();
390  success++;
391  statusObj.push_back(Pair("node", mne.getAlias()));
392  statusObj.push_back(Pair("result", "success"));
393  statusObj.push_back(Pair("error", ""));
394  } else {
395  failed++;
396  statusObj.push_back(Pair("node", mne.getAlias()));
397  statusObj.push_back(Pair("result", "failed"));
398  statusObj.push_back(Pair("error", strError.c_str()));
399  }
400 
401  resultsObj.push_back(statusObj);
402  }
403 
404  UniValue returnObj(UniValue::VOBJ);
405  returnObj.push_back(Pair("overall", strprintf("Voted successfully %d time(s) and failed %d time(s).", success, failed)));
406  returnObj.push_back(Pair("detail", resultsObj));
407 
408  return returnObj;
409  }
410 
411  if (strCommand == "alias") {
412  std::string strAlias = params[3].get_str();
413  std::vector<CMasternodeConfig::CMasternodeEntry> mnEntries;
414  mnEntries = masternodeConfig.getEntries();
415 
417 
418  if( strAlias != mne.getAlias()) continue;
419 
420  std::vector<unsigned char> vchMasterNodeSignature;
421  std::string strMasterNodeSignMessage;
422 
423  CPubKey pubKeyCollateralAddress;
424  CKey keyCollateralAddress;
425  CPubKey pubKeyMasternode;
426  CKey keyMasternode;
427 
428  UniValue statusObj(UniValue::VOBJ);
429 
430  if(!CMessageSigner::GetKeysFromSecret(mne.getPrivKey(), keyMasternode, pubKeyMasternode)){
431  failed++;
432  statusObj.push_back(Pair("node", mne.getAlias()));
433  statusObj.push_back(Pair("result", "failed"));
434  statusObj.push_back(Pair("error", "Masternode signing error, could not set key correctly."));
435  resultsObj.push_back(statusObj);
436  continue;
437  }
438 
439  CMasternode* pmn = mnodeman.Find(pubKeyMasternode);
440  if(pmn == NULL)
441  {
442  failed++;
443  statusObj.push_back(Pair("node", mne.getAlias()));
444  statusObj.push_back(Pair("result", "failed"));
445  statusObj.push_back(Pair("error", "Can't find masternode by pubkey"));
446  resultsObj.push_back(statusObj);
447  continue;
448  }
449 
450  CBudgetVote vote(pmn->vin, hash, nVote);
451  if(!vote.Sign(keyMasternode, pubKeyMasternode)){
452  failed++;
453  statusObj.push_back(Pair("node", mne.getAlias()));
454  statusObj.push_back(Pair("result", "failed"));
455  statusObj.push_back(Pair("error", "Failure to sign."));
456  resultsObj.push_back(statusObj);
457  continue;
458  }
459 
460  std::string strError = "";
461  if(budget.UpdateProposal(vote, NULL, strError)) {
462  budget.mapSeenMasternodeBudgetVotes.insert(std::make_pair(vote.GetHash(), vote));
463  vote.Relay();
464  success++;
465  statusObj.push_back(Pair("node", mne.getAlias()));
466  statusObj.push_back(Pair("result", "success"));
467  statusObj.push_back(Pair("error", ""));
468  } else {
469  failed++;
470  statusObj.push_back(Pair("node", mne.getAlias()));
471  statusObj.push_back(Pair("result", "failed"));
472  statusObj.push_back(Pair("error", strError.c_str()));
473  }
474 
475  resultsObj.push_back(statusObj);
476  }
477 
478  UniValue returnObj(UniValue::VOBJ);
479  returnObj.push_back(Pair("overall", strprintf("Voted successfully %d time(s) and failed %d time(s).", success, failed)));
480  returnObj.push_back(Pair("detail", resultsObj));
481 
482  return returnObj;
483  }
484 
485  return NullUniValue;
486 }
487 
488 UniValue getbudgetvotes(const UniValue& params, bool fHelp)
489 {
490  if (params.size() != 1)
491  throw std::runtime_error(
492  "getbudgetvotes \"proposal-name\"\n"
493  "\nPrint vote information for a budget proposal\n"
494 
495  "\nArguments:\n"
496  "1. \"proposal-name\": (string, required) Name of the proposal\n"
497 
498  "\nResult:\n"
499  "[\n"
500  " {\n"
501  " \"mnId\": \"xxxx\", (string) Hash of the masternode's collateral transaction\n"
502  " \"nHash\": \"xxxx\", (string) Hash of the vote\n"
503  " \"Vote\": \"YES|NO\", (string) Vote cast ('YES' or 'NO')\n"
504  " \"nTime\": xxxx, (numeric) Time in seconds since epoch the vote was cast\n"
505  " \"fValid\": true|false, (boolean) 'true' if the vote is valid, 'false' otherwise\n"
506  " }\n"
507  " ,...\n"
508  "]\n"
509  "\nExamples:\n" +
510  HelpExampleCli("getbudgetvotes", "\"test-proposal\"") + HelpExampleRpc("getbudgetvotes", "\"test-proposal\""));
511 
512  std::string strProposalName = SanitizeString(params[0].get_str());
513 
515 
516  CBudgetProposal* pbudgetProposal = budget.FindProposal(strProposalName);
517 
518  if (pbudgetProposal == NULL) throw std::runtime_error("Unknown proposal name");
519 
520  std::map<uint256, CBudgetVote>::iterator it = pbudgetProposal->mapVotes.begin();
521  while (it != pbudgetProposal->mapVotes.end()) {
522  UniValue bObj(UniValue::VOBJ);
523  bObj.push_back(Pair("mnId", (*it).second.vin.prevout.hash.ToString()));
524  bObj.push_back(Pair("nHash", (*it).first.ToString().c_str()));
525  bObj.push_back(Pair("Vote", (*it).second.GetVoteString()));
526  bObj.push_back(Pair("nTime", (int64_t)(*it).second.nTime));
527  bObj.push_back(Pair("fValid", (*it).second.fValid));
528 
529  ret.push_back(bObj);
530 
531  it++;
532  }
533 
534  return ret;
535 }
536 
537 UniValue getnextsuperblock(const UniValue& params, bool fHelp)
538 {
539  if (fHelp || params.size() != 0)
540  throw std::runtime_error(
541  "getnextsuperblock\n"
542  "\nPrint the next super block height\n"
543 
544  "\nResult:\n"
545  "n (numeric) Block height of the next super block\n"
546  "\nExamples:\n" +
547  HelpExampleCli("getnextsuperblock", "") + HelpExampleRpc("getnextsuperblock", ""));
548 
549  CBlockIndex* pindexPrev = chainActive.Tip();
550  if (!pindexPrev) return "unknown";
551 
552  int nNext = pindexPrev->nHeight - pindexPrev->nHeight % GetBudgetPaymentCycleBlocks() + GetBudgetPaymentCycleBlocks();
553  return nNext;
554 }
555 
556 UniValue getbudgetprojection(const UniValue& params, bool fHelp)
557 {
558  if (fHelp || params.size() != 0)
559  throw std::runtime_error(
560  "getbudgetprojection\n"
561  "\nShow the projection of which proposals will be paid the next cycle\n"
562 
563  "\nResult:\n"
564  "[\n"
565  " {\n"
566  " \"Name\": \"xxxx\", (string) Proposal Name\n"
567  " \"URL\": \"xxxx\", (string) Proposal URL\n"
568  " \"Hash\": \"xxxx\", (string) Proposal vote hash\n"
569  " \"FeeHash\": \"xxxx\", (string) Proposal fee hash\n"
570  " \"BlockStart\": n, (numeric) Proposal starting block\n"
571  " \"BlockEnd\": n, (numeric) Proposal ending block\n"
572  " \"TotalPaymentCount\": n, (numeric) Number of payments\n"
573  " \"RemainingPaymentCount\": n, (numeric) Number of remaining payments\n"
574  " \"PaymentAddress\": \"xxxx\", (string) PRCY address of payment\n"
575  " \"Ratio\": x.xxx, (numeric) Ratio of yeas vs nays\n"
576  " \"Yeas\": n, (numeric) Number of yea votes\n"
577  " \"Nays\": n, (numeric) Number of nay votes\n"
578  " \"Abstains\": n, (numeric) Number of abstains\n"
579  " \"TotalPayment\": xxx.xxx, (numeric) Total payment amount\n"
580  " \"MonthlyPayment\": xxx.xxx, (numeric) Monthly payment amount\n"
581  " \"IsEstablished\": true|false, (boolean) Established (true) or (false)\n"
582  " \"IsValid\": true|false, (boolean) Valid (true) or Invalid (false)\n"
583  " \"IsValidReason\": \"xxxx\", (string) Error message, if any\n"
584  " \"fValid\": true|false, (boolean) Valid (true) or Invalid (false)\n"
585  " \"Alloted\": xxx.xxx, (numeric) Amount alloted in current period\n"
586  " \"TotalBudgetAlloted\": xxx.xxx (numeric) Total alloted\n"
587  " }\n"
588  " ,...\n"
589  "]\n"
590  "\nExamples:\n" +
591  HelpExampleCli("getbudgetprojection", "") + HelpExampleRpc("getbudgetprojection", ""));
592 
594  UniValue resultObj(UniValue::VOBJ);
595  CAmount nTotalAllotted = 0;
596 
597  std::vector<CBudgetProposal*> winningProps = budget.GetBudget();
598  for (CBudgetProposal* pbudgetProposal : winningProps) {
599  nTotalAllotted += pbudgetProposal->GetAllotted();
600 
601  CTxDestination address1;
602  ExtractDestination(pbudgetProposal->GetPayee(), address1);
603  CBitcoinAddress address2(address1);
604 
605  UniValue bObj(UniValue::VOBJ);
606  budgetToJSON(pbudgetProposal, bObj);
607  bObj.push_back(Pair("Alloted", ValueFromAmount(pbudgetProposal->GetAllotted())));
608  bObj.push_back(Pair("TotalBudgetAlloted", ValueFromAmount(nTotalAllotted)));
609 
610  ret.push_back(bObj);
611  }
612 
613  return ret;
614 }
615 
616 UniValue getbudgetinfo(const UniValue& params, bool fHelp)
617 {
618  if (fHelp || params.size() > 1)
619  throw std::runtime_error(
620  "getbudgetinfo ( \"proposal\" )\n"
621  "\nShow current masternode budgets\n"
622 
623  "\nArguments:\n"
624  "1. \"proposal\" (string, optional) Proposal name\n"
625 
626  "\nResult:\n"
627  "[\n"
628  " {\n"
629  " \"Name\": \"xxxx\", (string) Proposal Name\n"
630  " \"URL\": \"xxxx\", (string) Proposal URL\n"
631  " \"Hash\": \"xxxx\", (string) Proposal vote hash\n"
632  " \"FeeHash\": \"xxxx\", (string) Proposal fee hash\n"
633  " \"BlockStart\": n, (numeric) Proposal starting block\n"
634  " \"BlockEnd\": n, (numeric) Proposal ending block\n"
635  " \"TotalPaymentCount\": n, (numeric) Number of payments\n"
636  " \"RemainingPaymentCount\": n, (numeric) Number of remaining payments\n"
637  " \"PaymentAddress\": \"xxxx\", (string) PRCY address of payment\n"
638  " \"Ratio\": x.xxx, (numeric) Ratio of yeas vs nays\n"
639  " \"Yeas\": n, (numeric) Number of yea votes\n"
640  " \"Nays\": n, (numeric) Number of nay votes\n"
641  " \"Abstains\": n, (numeric) Number of abstains\n"
642  " \"TotalPayment\": xxx.xxx, (numeric) Total payment amount\n"
643  " \"MonthlyPayment\": xxx.xxx, (numeric) Monthly payment amount\n"
644  " \"IsEstablished\": true|false, (boolean) Established (true) or (false)\n"
645  " \"IsValid\": true|false, (boolean) Valid (true) or Invalid (false)\n"
646  " \"IsValidReason\": \"xxxx\", (string) Error message, if any\n"
647  " \"fValid\": true|false, (boolean) Valid (true) or Invalid (false)\n"
648  " }\n"
649  " ,...\n"
650  "]\n"
651  "\nExamples:\n" +
652  HelpExampleCli("getbudgetprojection", "") + HelpExampleRpc("getbudgetprojection", ""));
653 
655 
656  std::string strShow = "valid";
657  if (params.size() == 1) {
658  std::string strProposalName = SanitizeString(params[0].get_str());
659  CBudgetProposal* pbudgetProposal = budget.FindProposal(strProposalName);
660  if (pbudgetProposal == NULL) throw std::runtime_error("Unknown proposal name");
661  UniValue bObj(UniValue::VOBJ);
662  budgetToJSON(pbudgetProposal, bObj);
663  ret.push_back(bObj);
664  return ret;
665  }
666 
667  std::vector<CBudgetProposal*> winningProps = budget.GetAllProposals();
668  for (CBudgetProposal* pbudgetProposal : winningProps) {
669  if (strShow == "valid" && !pbudgetProposal->fValid) continue;
670 
671  UniValue bObj(UniValue::VOBJ);
672  budgetToJSON(pbudgetProposal, bObj);
673 
674  ret.push_back(bObj);
675  }
676 
677  return ret;
678 }
679 
680 UniValue mnbudgetrawvote(const UniValue& params, bool fHelp)
681 {
682  if (fHelp || params.size() != 6)
683  throw std::runtime_error(
684  "mnbudgetrawvote \"masternode-tx-hash\" masternode-tx-index \"proposal-hash\" yes|no time \"vote-sig\"\n"
685  "\nCompile and relay a proposal vote with provided external signature instead of signing vote internally\n"
686 
687  "\nArguments:\n"
688  "1. \"masternode-tx-hash\" (string, required) Transaction hash for the masternode\n"
689  "2. masternode-tx-index (numeric, required) Output index for the masternode\n"
690  "3. \"proposal-hash\" (string, required) Proposal vote hash\n"
691  "4. yes|no (boolean, required) Vote to cast\n"
692  "5. time (numeric, required) Time since epoch in seconds\n"
693  "6. \"vote-sig\" (string, required) External signature\n"
694 
695  "\nResult:\n"
696  "\"status\" (string) Vote status or error message\n"
697  "\nExamples:\n" +
698  HelpExampleCli("mnbudgetrawvote", "") + HelpExampleRpc("mnbudgetrawvote", ""));
699 
700  uint256 hashMnTx = ParseHashV(params[0], "mn tx hash");
701  int nMnTxIndex = params[1].get_int();
702  CTxIn vin = CTxIn(hashMnTx, nMnTxIndex);
703 
704  uint256 hashProposal = ParseHashV(params[2], "Proposal hash");
705  std::string strVote = params[3].get_str();
706 
707  if (strVote != "yes" && strVote != "no") return "You can only vote 'yes' or 'no'";
708  int nVote = VOTE_ABSTAIN;
709  if (strVote == "yes") nVote = VOTE_YES;
710  if (strVote == "no") nVote = VOTE_NO;
711 
712  int64_t nTime = params[4].get_int64();
713  std::string strSig = params[5].get_str();
714  bool fInvalid = false;
715  std::vector<unsigned char> vchSig = DecodeBase64(strSig.c_str(), &fInvalid);
716 
717  if (fInvalid)
718  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");
719 
720  CMasternode* pmn = mnodeman.Find(vin);
721  if (pmn == NULL) {
722  return "Failure to find masternode in list : " + vin.ToString();
723  }
724 
725  CBudgetVote vote(vin, hashProposal, nVote);
726  vote.nTime = nTime;
727  vote.vchSig = vchSig;
728 
729  if (!vote.SignatureValid(true)) {
730  return "Failure to verify signature.";
731  }
732 
733  std::string strError = "";
734  if (budget.UpdateProposal(vote, NULL, strError)) {
735  budget.mapSeenMasternodeBudgetVotes.insert(std::make_pair(vote.GetHash(), vote));
736  vote.Relay();
737  return "Voted successfully";
738  } else {
739  return "Error voting : " + strError;
740  }
741 }
742 
743 UniValue mnfinalbudget(const UniValue& params, bool fHelp)
744 {
745  std::string strCommand;
746  if (params.size() >= 1)
747  strCommand = params[0].get_str();
748 
749  if (fHelp ||
750  (strCommand != "suggest" && strCommand != "vote-many" && strCommand != "vote" && strCommand != "show" && strCommand != "getvotes"))
751  throw std::runtime_error(
752  "mnfinalbudget \"command\"... ( \"passphrase\" )\n"
753  "Vote or show current budgets\n"
754  "\nAvailable commands:\n"
755  " vote-many - Vote on a finalized budget\n"
756  " vote - Vote on a finalized budget\n"
757  " show - Show existing finalized budgets\n"
758  " getvotes - Get vote information for each finalized budget\n");
759 
760  if (strCommand == "vote-many") {
761  if (params.size() != 2)
762  throw std::runtime_error("Correct usage is 'mnfinalbudget vote-many BUDGET_HASH'");
763 
764  std::string strHash = params[1].get_str();
765  uint256 hash(uint256S(strHash));
766 
767  int success = 0;
768  int failed = 0;
769 
770  UniValue resultsObj(UniValue::VOBJ);
771 
773  std::vector<unsigned char> vchMasterNodeSignature;
774  std::string strMasterNodeSignMessage;
775 
776  CPubKey pubKeyCollateralAddress;
777  CKey keyCollateralAddress;
778  CPubKey pubKeyMasternode;
779  CKey keyMasternode;
780 
781  UniValue statusObj(UniValue::VOBJ);
782 
783  if (!CMessageSigner::GetKeysFromSecret(mne.getPrivKey(), keyMasternode, pubKeyMasternode)) {
784  failed++;
785  statusObj.push_back(Pair("result", "failed"));
786  statusObj.push_back(Pair("errorMessage", "Masternode signing error, could not set key correctly."));
787  resultsObj.push_back(Pair(mne.getAlias(), statusObj));
788  continue;
789  }
790 
791  CMasternode* pmn = mnodeman.Find(pubKeyMasternode);
792  if (pmn == NULL) {
793  failed++;
794  statusObj.push_back(Pair("result", "failed"));
795  statusObj.push_back(Pair("errorMessage", "Can't find masternode by pubkey"));
796  resultsObj.push_back(Pair(mne.getAlias(), statusObj));
797  continue;
798  }
799 
800 
801  CFinalizedBudgetVote vote(pmn->vin, hash);
802  if (!vote.Sign(keyMasternode, pubKeyMasternode)) {
803  failed++;
804  statusObj.push_back(Pair("result", "failed"));
805  statusObj.push_back(Pair("errorMessage", "Failure to sign."));
806  resultsObj.push_back(Pair(mne.getAlias(), statusObj));
807  continue;
808  }
809 
810  std::string strError = "";
811  if (budget.UpdateFinalizedBudget(vote, NULL, strError)) {
812  budget.mapSeenFinalizedBudgetVotes.insert(std::make_pair(vote.GetHash(), vote));
813  vote.Relay();
814  success++;
815  statusObj.push_back(Pair("result", "success"));
816  } else {
817  failed++;
818  statusObj.push_back(Pair("result", strError.c_str()));
819  }
820 
821  resultsObj.push_back(Pair(mne.getAlias(), statusObj));
822  }
823 
824  UniValue returnObj(UniValue::VOBJ);
825  returnObj.push_back(Pair("overall", strprintf("Voted successfully %d time(s) and failed %d time(s).", success, failed)));
826  returnObj.push_back(Pair("detail", resultsObj));
827 
828  return returnObj;
829  }
830 
831  if (strCommand == "vote") {
832  if (params.size() != 2)
833  throw std::runtime_error("Correct usage is 'mnfinalbudget vote BUDGET_HASH'");
834 
835  std::string strHash = params[1].get_str();
836  uint256 hash(uint256S(strHash));
837 
838  CPubKey pubKeyMasternode;
839  CKey keyMasternode;
840 
841  if (!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, keyMasternode, pubKeyMasternode))
842  return "Error upon calling SetKey";
843 
845  if (pmn == NULL) {
846  return "Failure to find masternode in list : " + activeMasternode.vin.ToString();
847  }
848 
850  if (!vote.Sign(keyMasternode, pubKeyMasternode)) {
851  return "Failure to sign.";
852  }
853 
854  std::string strError = "";
855  if (budget.UpdateFinalizedBudget(vote, NULL, strError)) {
856  budget.mapSeenFinalizedBudgetVotes.insert(std::make_pair(vote.GetHash(), vote));
857  vote.Relay();
858  return "success";
859  } else {
860  return "Error voting : " + strError;
861  }
862  }
863 
864  if (strCommand == "show") {
865  UniValue resultObj(UniValue::VOBJ);
866 
867  std::vector<CFinalizedBudget*> winningFbs = budget.GetFinalizedBudgets();
868  for (CFinalizedBudget* finalizedBudget : winningFbs) {
869  UniValue bObj(UniValue::VOBJ);
870  bObj.push_back(Pair("FeeTX", finalizedBudget->nFeeTXHash.ToString()));
871  bObj.push_back(Pair("Hash", finalizedBudget->GetHash().ToString()));
872  bObj.push_back(Pair("BlockStart", (int64_t)finalizedBudget->GetBlockStart()));
873  bObj.push_back(Pair("BlockEnd", (int64_t)finalizedBudget->GetBlockEnd()));
874  bObj.push_back(Pair("Proposals", finalizedBudget->GetProposals()));
875  bObj.push_back(Pair("VoteCount", (int64_t)finalizedBudget->GetVoteCount()));
876  bObj.push_back(Pair("Status", finalizedBudget->GetStatus()));
877 
878  std::string strError = "";
879  bObj.push_back(Pair("IsValid", finalizedBudget->IsValid(strError)));
880  bObj.push_back(Pair("IsValidReason", strError.c_str()));
881 
882  resultObj.push_back(Pair(finalizedBudget->GetName(), bObj));
883  }
884 
885  return resultObj;
886  }
887 
888  if (strCommand == "getvotes") {
889  if (params.size() != 2)
890  throw std::runtime_error("Correct usage is 'mnbudget getvotes budget-hash'");
891 
892  std::string strHash = params[1].get_str();
893  uint256 hash(uint256S(strHash));
894 
896 
897  CFinalizedBudget* pfinalBudget = budget.FindFinalizedBudget(hash);
898 
899  if (pfinalBudget == NULL) return "Unknown budget hash";
900 
901  std::map<uint256, CFinalizedBudgetVote>::iterator it = pfinalBudget->mapVotes.begin();
902  while (it != pfinalBudget->mapVotes.end()) {
903  UniValue bObj(UniValue::VOBJ);
904  bObj.push_back(Pair("nHash", (*it).first.ToString().c_str()));
905  bObj.push_back(Pair("nTime", (int64_t)(*it).second.nTime));
906  bObj.push_back(Pair("fValid", (*it).second.fValid));
907 
908  obj.push_back(Pair((*it).second.vin.prevout.ToStringShort(), bObj));
909 
910  it++;
911  }
912 
913  return obj;
914  }
915 
916  return NullUniValue;
917 }
918 
919 UniValue checkbudgets(const UniValue& params, bool fHelp)
920 {
921  if (fHelp || params.size() != 0)
922  throw std::runtime_error(
923  "checkbudgets\n"
924  "\nInitiates a budget check cycle manually\n"
925  "\nExamples:\n" +
926  HelpExampleCli("checkbudgets", "") + HelpExampleRpc("checkbudgets", ""));
927 
929 
930  return NullUniValue;
931 }
CTxIn
An input of a transaction.
Definition: transaction.h:83
CBudgetProposal::nFeeTXHash
uint256 nFeeTXHash
Definition: masternode-budget.h:472
LOCK2
#define LOCK2(cs1, cs2)
Definition: sync.h:183
UINT256_ZERO
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:129
CBudgetManager::mapSeenMasternodeBudgetProposals
std::map< uint256, CBudgetProposalBroadcast > mapSeenMasternodeBudgetProposals
Definition: masternode-budget.h:187
CBudgetManager::GetFinalizedBudgets
std::vector< CFinalizedBudget * > GetFinalizedBudgets()
Definition: masternode-budget.cpp:780
CBudgetManager::FindFinalizedBudget
CFinalizedBudget * FindFinalizedBudget(uint256 nHash)
Definition: masternode-budget.cpp:554
CBudgetVote::Sign
bool Sign(CKey &keyMasternode, CPubKey &pubKeyMasternode)
Definition: masternode-budget.cpp:1684
UniValue::VOBJ
@ VOBJ
Definition: univalue.h:21
activeMasternode
CActiveMasternode activeMasternode
Keep track of the active Masternode.
Definition: masternodeman.cpp:24
getbudgetprojection
UniValue getbudgetprojection(const UniValue &params, bool fHelp)
Definition: budget.cpp:556
getnextsuperblock
UniValue getnextsuperblock(const UniValue &params, bool fHelp)
Definition: budget.cpp:537
CWallet::CommitTransaction
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey, std::string strCommand=NetMsgType::TX)
Call after CreateTransaction unless you want to abort.
Definition: wallet.cpp:4458
CBudgetProposal::GetAmount
CAmount GetAmount()
Definition: masternode-budget.h:511
ValueFromAmount
UniValue ValueFromAmount(const CAmount &amount)
Definition: server.cpp:118
VOTE_YES
#define VOTE_YES
Definition: masternode-budget.h:30
chainActive
CChain chainActive
The currently-connected chain of blocks.
Definition: main.cpp:70
NullUniValue
const UniValue NullUniValue
Definition: univalue.cpp:78
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Definition: standard.cpp:285
CBudgetManager::mapSeenMasternodeBudgetVotes
std::map< uint256, CBudgetVote > mapSeenMasternodeBudgetVotes
Definition: masternode-budget.h:188
CBudgetManager::GetAllProposals
std::vector< CBudgetProposal * > GetAllProposals()
Definition: masternode-budget.cpp:669
CBudgetProposal::GetBlockEnd
int GetBlockEnd()
Definition: masternode-budget.h:500
CBitcoinAddress
base58-encoded PRCY addresses.
Definition: base58.h:109
CMasternodeMan::Find
CMasternode * Find(const CScript &payee)
Find an entry.
Definition: masternodeman.cpp:440
CActiveMasternode::vin
CTxIn vin
Definition: activemasternode.h:44
CMasternodeSync::IsBlockchainSynced
bool IsBlockchainSynced()
Definition: masternode-sync.cpp:32
CBlockIndex::nHeight
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:181
CReserveKey
A key allocated from the key pool.
Definition: wallet.h:679
CBudgetProposal::GetTotalPaymentCount
int GetTotalPaymentCount()
Definition: masternode-budget.cpp:1616
NetMsgType::IX
const char * IX
The ix message transmits a single SwiftX transaction.
Definition: protocol.cpp:48
checkbudgets
UniValue checkbudgets(const UniValue &params, bool fHelp)
Definition: budget.cpp:919
CBudgetProposal::GetRatio
double GetRatio()
Definition: masternode-budget.cpp:1530
masternode-sync.h
CBudgetProposal::GetAbstains
int GetAbstains()
Definition: masternode-budget.cpp:1574
SanitizeString
std::string SanitizeString(const std::string &str, int rule)
Remove unsafe chars.
Definition: utilstrencodings.cpp:32
CBudgetManager::UpdateProposal
bool UpdateProposal(CBudgetVote &vote, CNode *pfrom, std::string &strError)
Definition: masternode-budget.cpp:1320
masternodeman.h
CBudgetVote::Relay
void Relay()
Definition: masternode-budget.cpp:1678
CBase58Data::ToString
std::string ToString() const
Definition: base58.cpp:200
CBudgetProposal::GetRemainingPaymentCount
int GetRemainingPaymentCount()
Definition: masternode-budget.cpp:1621
CMasternode::vin
CTxIn vin
Definition: masternode.h:127
db.h
UniValue
Definition: univalue.h:19
CFinalizedBudgetVote::Relay
void Relay()
Definition: masternode-budget.cpp:2113
CBudgetManager::UpdateFinalizedBudget
bool UpdateFinalizedBudget(CFinalizedBudgetVote &vote, CNode *pfrom, std::string &strError)
Definition: masternode-budget.cpp:1347
CBudgetVote
Definition: masternode-budget.h:53
DecodeBase64
std::vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid)
Definition: utilstrencodings.cpp:150
masternodeSync
CMasternodeSync masternodeSync
Definition: masternode-sync.cpp:19
mnbudgetvote
UniValue mnbudgetvote(const UniValue &params, bool fHelp)
Definition: budget.cpp:230
strMasterNodePrivKey
std::string strMasterNodePrivKey
Definition: util.cpp:98
UniValue::get_str
const std::string & get_str() const
Definition: univalue.cpp:309
cs_main
RecursiveMutex cs_main
Global state.
Definition: main.cpp:65
CBudgetVote::GetHash
uint256 GetHash()
Definition: masternode-budget.h:79
CWallet::GetBudgetSystemCollateralTX
bool GetBudgetSystemCollateralTX(CTransaction &tx, uint256 hash, bool useIX)
Definition: wallet.cpp:3063
CBudgetProposal::nTime
int64_t nTime
Definition: masternode-budget.h:471
CBudgetProposal::GetYeas
int GetYeas()
Definition: masternode-budget.cpp:1548
mnodeman
CMasternodeMan mnodeman
Masternode manager.
Definition: masternodeman.cpp:22
UniValue::get_int64
int64_t get_int64() const
Definition: univalue.cpp:326
CBudgetManager::GetBudget
std::vector< CBudgetProposal * > GetBudget()
Definition: masternode-budget.cpp:701
CBudgetProposal
Definition: masternode-budget.h:451
init.h
CBudgetProposalBroadcast::Relay
void Relay()
Definition: masternode-budget.cpp:1652
CBudgetVote::SignatureValid
bool SignatureValid(bool fSignatureCheck)
Definition: masternode-budget.cpp:1708
getbudgetvotes
UniValue getbudgetvotes(const UniValue &params, bool fHelp)
Definition: budget.cpp:488
univalue.h
VOTE_ABSTAIN
#define VOTE_ABSTAIN
Definition: masternode-budget.h:29
JSONRPCError
UniValue JSONRPCError(int code, const std::string &message)
Definition: protocol.cpp:60
CAmount
int64_t CAmount
Amount in PRCY (Can be negative)
Definition: amount.h:17
mnbudgetrawvote
UniValue mnbudgetrawvote(const UniValue &params, bool fHelp)
Definition: budget.cpp:680
CFinalizedBudgetVote::Sign
bool Sign(CKey &keyMasternode, CPubKey &pubKeyMasternode)
Definition: masternode-budget.cpp:2119
HelpExampleRpc
std::string HelpExampleRpc(std::string methodname, std::string args)
Definition: server.cpp:607
masternode-payments.h
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
uint256S
uint256 uint256S(const char *str)
Definition: uint256.h:99
CBudgetManager::FindProposal
CBudgetProposal * FindProposal(const std::string &strProposalName)
Definition: masternode-budget.cpp:562
AmountFromValue
CAmount AmountFromValue(const UniValue &value)
Definition: server.cpp:107
CBudgetVote::nTime
int64_t nTime
Definition: masternode-budget.h:61
VOTE_NO
#define VOTE_NO
Definition: masternode-budget.h:31
CFinalizedBudget
Definition: masternode-budget.h:306
CFinalizedBudgetVote
Definition: masternode-budget.h:106
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:363
ExtractDestination
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Definition: standard.cpp:199
ParseHashV
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition: server.cpp:127
budgetToJSON
void budgetToJSON(CBudgetProposal *pbudgetProposal, UniValue &bObj)
Definition: budget.cpp:25
CBudgetProposal::IsEstablished
bool IsEstablished()
Definition: masternode-budget.h:488
CTxDestination
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:81
CMessageSigner::GetKeysFromSecret
static bool GetKeysFromSecret(const std::string &strSecret, CKey &keyRet, CPubKey &pubkeyRet)
Set the private/public key values, returns true if successful.
Definition: messagesigner.cpp:13
activemasternode.h
HelpExampleCli
std::string HelpExampleCli(std::string methodname, std::string args)
Definition: server.cpp:603
masternodeConfig
CMasternodeConfig masternodeConfig
Definition: masternodeconfig.cpp:13
RPC_INVALID_ADDRESS_OR_KEY
@ RPC_INVALID_ADDRESS_OR_KEY
Unexpected type was passed as parameter.
Definition: protocol.h:43
CBudgetVote::vchSig
std::vector< unsigned char > vchSig
Definition: masternode-budget.h:62
messagesigner.h
strprintf
#define strprintf
Definition: tinyformat.h:1056
CMasternode
Definition: masternode.h:107
CPubKey
An encapsulated public key.
Definition: pubkey.h:37
CBudgetProposal::IsValid
bool IsValid(std::string &strError, bool fCheckCollateral=true)
Definition: masternode-budget.cpp:1409
NetMsgType::TX
const char * TX
The tx message transmits a single transaction.
Definition: protocol.cpp:25
CKey
An encapsulated private key.
Definition: key.h:39
UniValue::get_int
int get_int() const
Definition: univalue.cpp:316
GetBudgetPaymentCycleBlocks
int GetBudgetPaymentCycleBlocks()
Definition: masternode-budget.cpp:28
utilmoneystr.h
CTxIn::ToString
std::string ToString() const
Definition: transaction.cpp:50
CBudgetManager::AddProposal
bool AddProposal(CBudgetProposal &budgetProposal)
Definition: masternode-budget.cpp:412
main.h
EnsureWalletIsUnlocked
void EnsureWalletIsUnlocked(bool fAllowAnonOnly=false)
Definition: rpcwallet.cpp:45
IsBudgetCollateralValid
bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string &strError, int64_t &nTime, int &nConf)
Definition: masternode-budget.cpp:37
CBudgetProposal::GetNays
int GetNays()
Definition: masternode-budget.cpp:1561
CWalletTx
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:792
CMasternodeConfig::CMasternodeEntry
Definition: masternodeconfig.h:22
CBudgetProposalBroadcast
Definition: masternode-budget.h:553
UniValue::push_back
bool push_back(const UniValue &val)
Definition: univalue.cpp:173
submitbudget
UniValue submitbudget(const UniValue &params, bool fHelp)
Definition: budget.cpp:143
masternode-budget.h
CWallet::cs_wallet
RecursiveMutex cs_wallet
Definition: wallet.h:301
UniValue::size
size_t size() const
Definition: univalue.h:69
CBudgetProposal::GetURL
std::string GetURL()
Definition: masternode-budget.h:498
CBudgetProposal::GetBlockStart
int GetBlockStart()
Definition: masternode-budget.h:499
CTransaction::GetHash
const uint256 & GetHash() const
Definition: transaction.h:342
CBudgetProposal::GetHash
uint256 GetHash()
Definition: masternode-budget.h:517
CChain::Tip
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or NULL if none.
Definition: chain.h:596
CBudgetProposal::GetName
std::string GetName()
Definition: masternode-budget.h:497
CBudgetProposal::mapVotes
std::map< uint256, CBudgetVote > mapVotes
Definition: masternode-budget.h:474
CBudgetManager::CheckAndRemove
void CheckAndRemove()
Definition: masternode-budget.cpp:430
CFinalizedBudget::mapVotes
std::map< uint256, CFinalizedBudgetVote > mapVotes
Definition: masternode-budget.h:318
budget
CBudgetManager budget
Definition: masternode-budget.cpp:19
UniValue::VARR
@ VARR
Definition: univalue.h:21
CBitcoinAddress::IsValid
bool IsValid() const
Definition: base58.cpp:254
server.h
CBudgetManager::mapSeenFinalizedBudgetVotes
std::map< uint256, CFinalizedBudgetVote > mapSeenFinalizedBudgetVotes
Definition: masternode-budget.h:191
CBudgetProposal::fValid
bool fValid
Definition: masternode-budget.h:459
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:162
CBitcoinAddress::Get
CTxDestination Get() const
Definition: base58.cpp:267
pwalletMain
CWallet * pwalletMain
Definition: wallet.cpp:49
masternodeconfig.h
preparebudget
UniValue preparebudget(const UniValue &params, bool fHelp)
Definition: budget.cpp:54
mnfinalbudget
UniValue mnfinalbudget(const UniValue &params, bool fHelp)
Definition: budget.cpp:743
getbudgetinfo
UniValue getbudgetinfo(const UniValue &params, bool fHelp)
Definition: budget.cpp:616
CFinalizedBudgetVote::GetHash
uint256 GetHash()
Definition: masternode-budget.h:123
CBudgetProposal::GetPayee
CScript GetPayee()
Definition: masternode-budget.h:501
CMasternodeConfig::getEntries
std::vector< CMasternodeEntry > & getEntries()
Definition: masternodeconfig.h:103
base_uint::ToString
std::string ToString() const
Definition: arith_uint256.cpp:199