diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index c0b6f28bba61..9c43ec44df89 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -691,11 +691,14 @@ struct CompareBlocksByHeight UniValue getchaintips(const UniValue& params, bool fHelp) { - if (fHelp || params.size() != 0) + if (fHelp || params.size() > 2) throw runtime_error( - "getchaintips\n" + "getchaintips ( count branchlen )\n" "Return information about all known tips in the block tree," " including the main chain as well as orphaned branches.\n" + "\nArguments:\n" + "1. count (numeric, optional) only show this much of latest tips\n" + "2. branchlen (numeric, optional) only show tips that have equal or greater length of branch\n" "\nResult:\n" "[\n" " {\n" @@ -740,15 +743,27 @@ UniValue getchaintips(const UniValue& params, bool fHelp) // Always report the currently active tip. setTips.insert(chainActive.Tip()); + int nBranchMin = -1; + int nCountMax = INT_MAX; + + if(params.size() >= 1) + nCountMax = params[0].get_int(); + + if(params.size() == 2) + nBranchMin = params[1].get_int(); + /* Construct the output array. */ UniValue res(UniValue::VARR); BOOST_FOREACH(const CBlockIndex* block, setTips) { + const int branchLen = block->nHeight - chainActive.FindFork(block)->nHeight; + if(branchLen < nBranchMin) continue; + + if(nCountMax-- < 1) break; + UniValue obj(UniValue::VOBJ); obj.push_back(Pair("height", block->nHeight)); obj.push_back(Pair("hash", block->phashBlock->GetHex())); - - const int branchLen = block->nHeight - chainActive.FindFork(block)->nHeight; obj.push_back(Pair("branchlen", branchLen)); string status; diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 89de31c2fed6..f7aec227e667 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -49,6 +49,8 @@ static const CRPCConvertParam vRPCConvertParams[] = { "listreceivedbyaccount", 2 }, { "getbalance", 1 }, { "getbalance", 2 }, + { "getchaintips", 0 }, + { "getchaintips", 1 }, { "getblockhash", 0 }, { "move", 2 }, { "move", 3 }, diff --git a/src/rpcmasternode-budget.cpp b/src/rpcmasternode-budget.cpp index 81a50dcd4bbc..9bfa46e7422a 100644 --- a/src/rpcmasternode-budget.cpp +++ b/src/rpcmasternode-budget.cpp @@ -44,7 +44,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) " getvotes - Show detailed votes list for proposal\n" " list - List all proposals\n" " nextblock - Get info about next superblock for budget system\n" - " nextsuperblocksize - Get superblock size for a given blockheight\n" + " nextsuperblocksize - Get superblock size for a given blockheight\n" " projection - Show the projection of which proposals will be paid the next cycle\n" " vote - Vote on a proposal by single masternode (using dash.conf setup)\n" " vote-many - Vote on a proposal by all masternodes (using masternode.conf setup)\n" @@ -76,7 +76,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "prepare") { if (params.size() != 7) - throw runtime_error("Correct usage is 'mnbudget prepare '"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget prepare '"); int nBlockMin = 0; LOCK(cs_main); @@ -94,7 +94,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(pindex != NULL) nBlockMin = pindex->nHeight; if(nBlockStart < nBlockMin) - return "Invalid block start, must be more than current height."; + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block start, must be more than current height."); CBitcoinAddress address(params[5].get_str()); if (!address.IsValid()) @@ -111,7 +111,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) std::string strError = ""; if(!budgetProposalBroadcast.IsValid(pindex, strError, false)) - return "Proposal is not valid - " + budgetProposalBroadcast.GetHash().ToString() + " - " + strError; + throw JSONRPCError(RPC_INTERNAL_ERROR, "Proposal is not valid - " + budgetProposalBroadcast.GetHash().ToString() + " - " + strError); bool useIX = false; //true; // if (params.size() > 7) { @@ -122,7 +122,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) CWalletTx wtx; if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, budgetProposalBroadcast.GetHash(), useIX)){ - return "Error making collateral transaction for proposal. Please check your wallet balance and make sure your wallet is unlocked."; + throw JSONRPCError(RPC_INTERNAL_ERROR, "Error making collateral transaction for proposal. Please check your wallet balance and make sure your wallet is unlocked."); } // make our change address @@ -136,10 +136,10 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "submit") { if (params.size() != 8) - throw runtime_error("Correct usage is 'mnbudget submit '"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget submit '"); if(!masternodeSync.IsBlockchainSynced()){ - return "Must wait for client to sync with masternode network. Try again in a minute or so."; + throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Must wait for client to sync with masternode network. Try again in a minute or so."); } int nBlockMin = 0; @@ -158,7 +158,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(pindex != NULL) nBlockMin = pindex->nHeight; if(nBlockStart < nBlockMin) - return "Invalid payment count, must be more than current height."; + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid payment count, must be more than current height."); CBitcoinAddress address(params[5].get_str()); if (!address.IsValid()) @@ -175,12 +175,12 @@ UniValue mnbudget(const UniValue& params, bool fHelp) std::string strError = ""; if(!budgetProposalBroadcast.IsValid(pindex, strError)){ - return "Proposal is not valid - " + budgetProposalBroadcast.GetHash().ToString() + " - " + strError; + throw JSONRPCError(RPC_INTERNAL_ERROR, "Proposal is not valid - " + budgetProposalBroadcast.GetHash().ToString() + " - " + strError); } int nConf = 0; if(!IsBudgetCollateralValid(hash, budgetProposalBroadcast.GetHash(), strError, budgetProposalBroadcast.nTime, nConf)){ - return "Proposal FeeTX is not valid - " + hash.ToString() + " - " + strError; + throw JSONRPCError(RPC_INTERNAL_ERROR, "Proposal FeeTX is not valid - " + hash.ToString() + " - " + strError); } budget.mapSeenMasternodeBudgetProposals.insert(make_pair(budgetProposalBroadcast.GetHash(), budgetProposalBroadcast)); @@ -194,7 +194,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "vote-many") { if(params.size() != 3) - throw runtime_error("Correct usage is 'mnbudget vote-many '"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget vote-many [yes|no]'"); uint256 hash; std::string strVote; @@ -202,7 +202,8 @@ UniValue mnbudget(const UniValue& params, bool fHelp) hash = ParseHashV(params[1], "Proposal hash"); strVote = params[2].get_str(); - if(strVote != "yes" && strVote != "no") return "You can only vote 'yes' or 'no'"; + if(strVote != "yes" && strVote != "no") + throw JSONRPCError(RPC_INVALID_PARAMETER, "You can only vote 'yes' or 'no'"); int nVote = VOTE_ABSTAIN; if(strVote == "yes") nVote = VOTE_YES; if(strVote == "no") nVote = VOTE_NO; @@ -279,7 +280,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "vote-alias") { if(params.size() != 4) - throw runtime_error("Correct usage is 'mnbudget vote-alias '"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget vote-alias [yes|no] '"); uint256 hash; std::string strVote; @@ -288,7 +289,8 @@ UniValue mnbudget(const UniValue& params, bool fHelp) strVote = params[2].get_str(); std::string strAlias = params[3].get_str(); - if(strVote != "yes" && strVote != "no") return "You can only vote 'yes' or 'no'"; + if(strVote != "yes" && strVote != "no") + throw JSONRPCError(RPC_INVALID_PARAMETER, "You can only vote 'yes' or 'no'"); int nVote = VOTE_ABSTAIN; if(strVote == "yes") nVote = VOTE_YES; if(strVote == "no") nVote = VOTE_NO; @@ -368,12 +370,13 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "vote") { if (params.size() != 3) - throw runtime_error("Correct usage is 'mnbudget vote '"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget vote [yes|no]'"); uint256 hash = ParseHashV(params[1], "Proposal hash"); std::string strVote = params[2].get_str(); - if(strVote != "yes" && strVote != "no") return "You can only vote 'yes' or 'no'"; + if(strVote != "yes" && strVote != "no") + throw JSONRPCError(RPC_INVALID_PARAMETER, "You can only vote 'yes' or 'no'"); int nVote = VOTE_ABSTAIN; if(strVote == "yes") nVote = VOTE_YES; if(strVote == "no") nVote = VOTE_NO; @@ -383,17 +386,17 @@ UniValue mnbudget(const UniValue& params, bool fHelp) std::string errorMessage; if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)) - return "Error upon calling SetKey"; + throw JSONRPCError(RPC_INTERNAL_ERROR, "Error upon calling SetKey"); CMasternode* pmn = mnodeman.Find(activeMasternode.vin); if(pmn == NULL) { - return "Failure to find masternode in list : " + activeMasternode.vin.ToString(); + throw JSONRPCError(RPC_INTERNAL_ERROR, "Failure to find masternode in list : " + activeMasternode.vin.ToString()); } CBudgetVote vote(activeMasternode.vin, hash, nVote); if(!vote.Sign(keyMasternode, pubKeyMasternode)){ - return "Failure to sign."; + throw JSONRPCError(RPC_INTERNAL_ERROR, "Failure to sign."); } std::string strError = ""; @@ -402,7 +405,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) vote.Relay(); return "Voted successfully"; } else { - return "Error voting : " + strError; + throw JSONRPCError(RPC_INTERNAL_ERROR, "Error voting : " + strError); } } @@ -429,6 +432,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) UniValue bObj(UniValue::VOBJ); bObj.push_back(Pair("URL", pbudgetProposal->GetURL())); bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); + bObj.push_back(Pair("FeeTXHash", pbudgetProposal->nFeeTXHash.ToString())); bObj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); bObj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); bObj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); @@ -458,7 +462,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "list") { if (params.size() > 2) - throw runtime_error("Correct usage is 'mnbudget list [valid]'"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget list [valid]'"); std::string strShow = "valid"; if (params.size() == 2) strShow = params[1].get_str(); @@ -487,7 +491,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) bObj.push_back(Pair("Name", pbudgetProposal->GetName())); bObj.push_back(Pair("URL", pbudgetProposal->GetURL())); bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); - bObj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString())); + bObj.push_back(Pair("FeeTXHash", pbudgetProposal->nFeeTXHash.ToString())); bObj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); bObj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); bObj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); @@ -517,13 +521,14 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "getproposalhash") { if (params.size() != 2) - throw runtime_error("Correct usage is 'mnbudget getproposalhash '"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget getproposalhash '"); std::string strProposalName = SanitizeString(params[1].get_str()); CBudgetProposal* pbudgetProposal = budget.FindProposal(strProposalName); - if(pbudgetProposal == NULL) return "Unknown proposal"; + if(pbudgetProposal == NULL) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown proposal"); UniValue resultObj(UniValue::VOBJ); @@ -548,13 +553,14 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "getproposal") { if (params.size() != 2) - throw runtime_error("Correct usage is 'mnbudget getproposal '"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget getproposal '"); uint256 hash = ParseHashV(params[1], "Proposal hash"); CBudgetProposal* pbudgetProposal = budget.FindProposal(hash); - if(pbudgetProposal == NULL) return "Unknown proposal"; + if(pbudgetProposal == NULL) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown proposal"); CBlockIndex* pindex; { @@ -570,7 +576,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) UniValue obj(UniValue::VOBJ); obj.push_back(Pair("Name", pbudgetProposal->GetName())); obj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); - obj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString())); + obj.push_back(Pair("FeeTXHash", pbudgetProposal->nFeeTXHash.ToString())); obj.push_back(Pair("URL", pbudgetProposal->GetURL())); obj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); obj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); @@ -597,7 +603,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp) if(strCommand == "getvotes") { if (params.size() != 2) - throw runtime_error("Correct usage is 'mnbudget getvotes '"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnbudget getvotes '"); uint256 hash = ParseHashV(params[1], "Proposal hash"); @@ -605,7 +611,8 @@ UniValue mnbudget(const UniValue& params, bool fHelp) CBudgetProposal* pbudgetProposal = budget.FindProposal(hash); - if(pbudgetProposal == NULL) return "Unknown proposal"; + if(pbudgetProposal == NULL) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown proposal"); std::map::iterator it = pbudgetProposal->mapVotes.begin(); while(it != pbudgetProposal->mapVotes.end()){ @@ -639,7 +646,7 @@ UniValue mnbudgetvoteraw(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 6) throw runtime_error( - "mnbudgetvoteraw