Various masternode rpc changes/fixes (#1024)
* deprecate start-many * remove outdated "enforce" rpc and enforceMasternodePaymentsTime * "count" should lock cs_main and call GetNextMasternodeInQueueForPayment only when needed * "masternodelist" fixes: - rename "pubkey" -> payee", fix description - fix "filter" description - change "full" format: add lastpaidblock, move IP to the end of string to make it more table-ish - fix "status" description - fix "addr" filter, wasn't working - trivial refactoring * fix "start-alias" and "create-alias" error message - should be a bit more descriptive now * rpcmasternode trivial cleanup
This commit is contained in:
parent
4e6bb6a375
commit
19ae48a02e
@ -24,7 +24,7 @@ void EnsureWalletIsUnlocked();
|
||||
UniValue privatesend(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
throw std::runtime_error(
|
||||
"privatesend \"command\"\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"command\" (string or set of strings, required) The command to execute\n"
|
||||
@ -47,17 +47,17 @@ UniValue privatesend(const UniValue& params, bool fHelp)
|
||||
return "Mixing " + (result ? "started successfully" : ("start failed: " + darkSendPool.GetStatus() + ", will retry"));
|
||||
}
|
||||
|
||||
if(params[0].get_str() == "stop"){
|
||||
if(params[0].get_str() == "stop") {
|
||||
fEnablePrivateSend = false;
|
||||
return "Mixing was stopped";
|
||||
}
|
||||
|
||||
if(params[0].get_str() == "reset"){
|
||||
if(params[0].get_str() == "reset") {
|
||||
darkSendPool.ResetPool();
|
||||
return "Mixing was reset";
|
||||
}
|
||||
|
||||
if(params[0].get_str() == "status"){
|
||||
if(params[0].get_str() == "status") {
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("status", darkSendPool.GetStatus()));
|
||||
obj.push_back(Pair("keys_left", pwalletMain->nKeysLeftSinceAutoBackup));
|
||||
@ -72,7 +72,7 @@ UniValue privatesend(const UniValue& params, bool fHelp)
|
||||
UniValue getpoolinfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
throw std::runtime_error(
|
||||
"getpoolinfo\n"
|
||||
"Returns an object containing anonymous pool-related information.");
|
||||
|
||||
@ -89,13 +89,17 @@ UniValue getpoolinfo(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue masternode(const UniValue& params, bool fHelp)
|
||||
{
|
||||
string strCommand;
|
||||
if (params.size() >= 1)
|
||||
std::string strCommand;
|
||||
if (params.size() >= 1) {
|
||||
strCommand = params[0].get_str();
|
||||
}
|
||||
|
||||
if (strCommand == "start-many")
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "DEPRECATED, please use start-all instead");
|
||||
|
||||
if (fHelp ||
|
||||
(strCommand != "start" && strCommand != "start-alias" && strCommand != "start-many" && strCommand != "start-all" && strCommand != "start-missing" &&
|
||||
strCommand != "start-disabled" && strCommand != "list" && strCommand != "list-conf" && strCommand != "count" && strCommand != "enforce" &&
|
||||
(strCommand != "start" && strCommand != "start-alias" && strCommand != "start-all" && strCommand != "start-missing" &&
|
||||
strCommand != "start-disabled" && strCommand != "list" && strCommand != "list-conf" && strCommand != "count" &&
|
||||
strCommand != "debug" && strCommand != "current" && strCommand != "winner" && strCommand != "winners" && strCommand != "genkey" &&
|
||||
strCommand != "connect" && strCommand != "outputs" && strCommand != "status"))
|
||||
throw std::runtime_error(
|
||||
@ -109,7 +113,6 @@ UniValue masternode(const UniValue& params, bool fHelp)
|
||||
" current - Print info on current masternode winner to be paid the next block (calculated locally)\n"
|
||||
" debug - Print masternode status\n"
|
||||
" genkey - Generate new masternodeprivkey\n"
|
||||
" enforce - Enforce masternode payments\n"
|
||||
" outputs - Print masternode compatible outputs\n"
|
||||
" start - Start local Hot masternode configured in dash.conf\n"
|
||||
" start-alias - Start single remote masternode by assigned alias configured in masternode.conf\n"
|
||||
@ -125,55 +128,55 @@ UniValue masternode(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue newParams(UniValue::VARR);
|
||||
// forward params but skip "list"
|
||||
for (unsigned int i = 1; i < params.size(); i++)
|
||||
for (unsigned int i = 1; i < params.size(); i++) {
|
||||
newParams.push_back(params[i]);
|
||||
}
|
||||
return masternodelist(newParams, fHelp);
|
||||
}
|
||||
|
||||
if(strCommand == "connect")
|
||||
{
|
||||
std::string strAddress = "";
|
||||
if (params.size() == 2){
|
||||
strAddress = params[1].get_str();
|
||||
} else {
|
||||
if (params.size() < 2)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Masternode address required");
|
||||
}
|
||||
|
||||
std::string strAddress = params[1].get_str();
|
||||
|
||||
CService addr = CService(strAddress);
|
||||
|
||||
CNode *pnode = ConnectNode((CAddress)addr, NULL);
|
||||
if(pnode) {
|
||||
return "successfully connected";
|
||||
} else {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Error connecting");
|
||||
}
|
||||
if(!pnode)
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Couldn't connect to masternode %s", strAddress));
|
||||
|
||||
return "successfully connected";
|
||||
}
|
||||
|
||||
if (strCommand == "count")
|
||||
{
|
||||
if (params.size() > 2){
|
||||
if (params.size() > 2)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Too many parameters");
|
||||
}
|
||||
if (params.size() == 2)
|
||||
{
|
||||
int nCount = 0;
|
||||
|
||||
{
|
||||
LOCK(cs_main);
|
||||
if(chainActive.Tip())
|
||||
mnodeman.GetNextMasternodeInQueueForPayment(chainActive.Tip()->nHeight, true, nCount);
|
||||
}
|
||||
if (params.size() == 1)
|
||||
return mnodeman.size();
|
||||
|
||||
if(params[1].get_str() == "ps") return mnodeman.CountEnabled(MIN_PRIVATESEND_PEER_PROTO_VERSION);
|
||||
if(params[1].get_str() == "enabled") return mnodeman.CountEnabled();
|
||||
if(params[1].get_str() == "qualify") return nCount;
|
||||
if(params[1].get_str() == "all") return strprintf("Total: %d (PS Compatible: %d / Enabled: %d / Qualify: %d)",
|
||||
mnodeman.size(),
|
||||
mnodeman.CountEnabled(MIN_PRIVATESEND_PEER_PROTO_VERSION),
|
||||
mnodeman.CountEnabled(),
|
||||
nCount);
|
||||
}
|
||||
return mnodeman.size();
|
||||
std::string strMode = params[1].get_str();
|
||||
|
||||
if (strMode == "ps")
|
||||
return mnodeman.CountEnabled(MIN_PRIVATESEND_PEER_PROTO_VERSION);
|
||||
|
||||
if (strMode == "enabled")
|
||||
return mnodeman.CountEnabled();
|
||||
|
||||
LOCK(cs_main);
|
||||
int nCount;
|
||||
mnodeman.GetNextMasternodeInQueueForPayment(chainActive.Height(), true, nCount);
|
||||
|
||||
if (strMode == "qualify")
|
||||
return nCount;
|
||||
|
||||
if (strMode == "all")
|
||||
return strprintf("Total: %d (PS Compatible: %d / Enabled: %d / Qualify: %d)",
|
||||
mnodeman.size(), mnodeman.CountEnabled(MIN_PRIVATESEND_PEER_PROTO_VERSION),
|
||||
mnodeman.CountEnabled(), nCount);
|
||||
}
|
||||
|
||||
if (strCommand == "current" || strCommand == "winner")
|
||||
@ -210,20 +213,16 @@ UniValue masternode(const UniValue& params, bool fHelp)
|
||||
if(activeMasternode.nState != ACTIVE_MASTERNODE_INITIAL || !masternodeSync.IsBlockchainSynced())
|
||||
return activeMasternode.GetStatus();
|
||||
|
||||
CTxIn vin = CTxIn();
|
||||
CPubKey pubkey = CPubKey();
|
||||
CTxIn vin;
|
||||
CPubKey pubkey;
|
||||
CKey key;
|
||||
|
||||
if(!pwalletMain || !pwalletMain->GetMasternodeVinAndKeys(vin, pubkey, key))
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Missing masternode input, please look at the documentation for instructions on masternode creation");
|
||||
|
||||
return activeMasternode.GetStatus();
|
||||
}
|
||||
|
||||
if(strCommand == "enforce")
|
||||
{
|
||||
return (uint64_t)enforceMasternodePaymentsTime;
|
||||
}
|
||||
|
||||
if (strCommand == "start")
|
||||
{
|
||||
if(!fMasterNode)
|
||||
@ -242,42 +241,39 @@ UniValue masternode(const UniValue& params, bool fHelp)
|
||||
|
||||
if (strCommand == "start-alias")
|
||||
{
|
||||
if (params.size() < 2){
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Command needs at least 2 parameters");
|
||||
}
|
||||
|
||||
std::string alias = params[1].get_str();
|
||||
|
||||
if (params.size() < 2)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Please specify an alias");
|
||||
|
||||
LOCK(pwalletMain->cs_wallet);
|
||||
EnsureWalletIsUnlocked();
|
||||
|
||||
std::string strAlias = params[1].get_str();
|
||||
|
||||
bool found = false;
|
||||
bool fFound = false;
|
||||
|
||||
UniValue statusObj(UniValue::VOBJ);
|
||||
statusObj.push_back(Pair("alias", alias));
|
||||
statusObj.push_back(Pair("alias", strAlias));
|
||||
|
||||
BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries()) {
|
||||
if(mne.getAlias() == alias) {
|
||||
found = true;
|
||||
std::string errorMessage;
|
||||
if(mne.getAlias() == strAlias) {
|
||||
fFound = true;
|
||||
std::string strError;
|
||||
CMasternodeBroadcast mnb;
|
||||
|
||||
bool result = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), errorMessage, mnb);
|
||||
bool fResult = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), strError, mnb);
|
||||
|
||||
statusObj.push_back(Pair("result", result ? "successful" : "failed"));
|
||||
if(result) {
|
||||
statusObj.push_back(Pair("result", fResult ? "successful" : "failed"));
|
||||
if(fResult) {
|
||||
mnodeman.UpdateMasternodeList(mnb);
|
||||
mnb.Relay();
|
||||
} else {
|
||||
statusObj.push_back(Pair("errorMessage", errorMessage));
|
||||
statusObj.push_back(Pair("errorMessage", strError));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found) {
|
||||
if(!fFound) {
|
||||
statusObj.push_back(Pair("result", "failed"));
|
||||
statusObj.push_back(Pair("errorMessage", "Could not find alias in config. Verify with list-conf."));
|
||||
}
|
||||
@ -286,7 +282,7 @@ UniValue masternode(const UniValue& params, bool fHelp)
|
||||
|
||||
}
|
||||
|
||||
if (strCommand == "start-many" || strCommand == "start-all" || strCommand == "start-missing" || strCommand == "start-disabled")
|
||||
if (strCommand == "start-all" || strCommand == "start-missing" || strCommand == "start-disabled")
|
||||
{
|
||||
LOCK(pwalletMain->cs_wallet);
|
||||
EnsureWalletIsUnlocked();
|
||||
@ -295,13 +291,13 @@ UniValue masternode(const UniValue& params, bool fHelp)
|
||||
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "You can't use this command until masternode list is synced");
|
||||
}
|
||||
|
||||
int successful = 0;
|
||||
int failed = 0;
|
||||
int nSuccessful = 0;
|
||||
int nFailed = 0;
|
||||
|
||||
UniValue resultsObj(UniValue::VOBJ);
|
||||
|
||||
BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries()) {
|
||||
std::string errorMessage;
|
||||
std::string strError;
|
||||
|
||||
CTxIn vin = CTxIn(uint256S(mne.getTxHash()), uint32_t(atoi(mne.getOutputIndex().c_str())));
|
||||
CMasternode *pmn = mnodeman.Find(vin);
|
||||
@ -310,26 +306,26 @@ UniValue masternode(const UniValue& params, bool fHelp)
|
||||
if(strCommand == "start-missing" && pmn) continue;
|
||||
if(strCommand == "start-disabled" && pmn && pmn->IsEnabled()) continue;
|
||||
|
||||
bool result = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), errorMessage, mnb);
|
||||
bool fResult = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), strError, mnb);
|
||||
|
||||
UniValue statusObj(UniValue::VOBJ);
|
||||
statusObj.push_back(Pair("alias", mne.getAlias()));
|
||||
statusObj.push_back(Pair("result", result ? "successful" : "failed"));
|
||||
statusObj.push_back(Pair("result", fResult ? "successful" : "failed"));
|
||||
|
||||
if(result) {
|
||||
successful++;
|
||||
if (fResult) {
|
||||
nSuccessful++;
|
||||
mnodeman.UpdateMasternodeList(mnb);
|
||||
mnb.Relay();
|
||||
} else {
|
||||
failed++;
|
||||
statusObj.push_back(Pair("errorMessage", errorMessage));
|
||||
nFailed++;
|
||||
statusObj.push_back(Pair("errorMessage", strError));
|
||||
}
|
||||
|
||||
resultsObj.push_back(Pair("status", statusObj));
|
||||
}
|
||||
|
||||
UniValue returnObj(UniValue::VOBJ);
|
||||
returnObj.push_back(Pair("overall", strprintf("Successfully started %d masternodes, failed to start %d, total %d", successful, failed, successful + failed)));
|
||||
returnObj.push_back(Pair("overall", strprintf("Successfully started %d masternodes, failed to start %d, total %d", nSuccessful, nFailed, nSuccessful + nFailed)));
|
||||
returnObj.push_back(Pair("detail", resultsObj));
|
||||
|
||||
return returnObj;
|
||||
@ -343,7 +339,7 @@ UniValue masternode(const UniValue& params, bool fHelp)
|
||||
return CBitcoinSecret(secret).ToString();
|
||||
}
|
||||
|
||||
if(strCommand == "list-conf")
|
||||
if (strCommand == "list-conf")
|
||||
{
|
||||
UniValue resultObj(UniValue::VOBJ);
|
||||
|
||||
@ -366,22 +362,23 @@ UniValue masternode(const UniValue& params, bool fHelp)
|
||||
return resultObj;
|
||||
}
|
||||
|
||||
if (strCommand == "outputs"){
|
||||
if (strCommand == "outputs") {
|
||||
// Find possible candidates
|
||||
std::vector<COutput> vPossibleCoins;
|
||||
pwalletMain->AvailableCoins(vPossibleCoins, true, NULL, false, ONLY_1000);
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
BOOST_FOREACH(COutput& out, vPossibleCoins)
|
||||
BOOST_FOREACH(COutput& out, vPossibleCoins) {
|
||||
obj.push_back(Pair(out.tx->GetHash().ToString(), strprintf("%d", out.i)));
|
||||
}
|
||||
|
||||
return obj;
|
||||
|
||||
}
|
||||
|
||||
if(strCommand == "status")
|
||||
if (strCommand == "status")
|
||||
{
|
||||
if(!fMasterNode)
|
||||
if (!fMasterNode)
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "This is not a masternode");
|
||||
|
||||
UniValue mnObj(UniValue::VOBJ);
|
||||
@ -407,11 +404,11 @@ UniValue masternode(const UniValue& params, bool fHelp)
|
||||
int nLast = 10;
|
||||
std::string strFilter = "";
|
||||
|
||||
if (params.size() >= 2){
|
||||
if (params.size() >= 2) {
|
||||
nLast = atoi(params[1].get_str());
|
||||
}
|
||||
|
||||
if (params.size() == 3){
|
||||
if (params.size() == 3) {
|
||||
strFilter = params[2].get_str();
|
||||
}
|
||||
|
||||
@ -420,10 +417,9 @@ UniValue masternode(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
|
||||
for(int i = nHeight - nLast; i < nHeight + 20; i++)
|
||||
{
|
||||
for(int i = nHeight - nLast; i < nHeight + 20; i++) {
|
||||
std::string strPayment = GetRequiredPaymentsString(i);
|
||||
if(strFilter !="" && strPayment.find(strFilter) == string::npos) continue;
|
||||
if (strFilter !="" && strPayment.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strprintf("%d", i), strPayment));
|
||||
}
|
||||
|
||||
@ -444,29 +440,29 @@ UniValue masternodelist(const UniValue& params, bool fHelp)
|
||||
if (fHelp || (
|
||||
strMode != "activeseconds" && strMode != "addr" && strMode != "full" &&
|
||||
strMode != "lastseen" && strMode != "lastpaidtime" && strMode != "lastpaidblock" &&
|
||||
strMode != "protocol" && strMode != "pubkey" && strMode != "rank" && strMode != "status"))
|
||||
strMode != "protocol" && strMode != "payee" && strMode != "rank" && strMode != "status"))
|
||||
{
|
||||
throw runtime_error(
|
||||
throw std::runtime_error(
|
||||
"masternodelist ( \"mode\" \"filter\" )\n"
|
||||
"Get a list of masternodes in different modes\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"mode\" (string, optional/required to use filter, defaults = status) The mode to run list in\n"
|
||||
"2. \"filter\" (string, optional) Filter results. Partial match by IP by default in all modes,\n"
|
||||
"2. \"filter\" (string, optional) Filter results. Partial match by outpoint by default in all modes,\n"
|
||||
" additional matches in some modes are also available\n"
|
||||
"\nAvailable modes:\n"
|
||||
" activeseconds - Print number of seconds masternode recognized by the network as enabled\n"
|
||||
" (since latest issued \"masternode start/start-many/start-alias\")\n"
|
||||
" addr - Print ip address associated with a masternode (can be additionally filtered, partial match)\n"
|
||||
" full - Print info in format 'status protocol pubkey IP lastseen activeseconds lastpaidtime'\n"
|
||||
" full - Print info in format 'status protocol payee lastseen activeseconds lastpaidtime lastpaidblock IP'\n"
|
||||
" (can be additionally filtered, partial match)\n"
|
||||
" lastseen - Print timestamp of when a masternode was last seen on the network\n"
|
||||
" lastpaidblock - Print the last block height a node was paid on the network\n"
|
||||
" lastpaidtime - Print the last time a node was paid on the network\n"
|
||||
" protocol - Print protocol of a masternode (can be additionally filtered, exact match))\n"
|
||||
" pubkey - Print public key associated with a masternode (can be additionally filtered,\n"
|
||||
" lastseen - Print timestamp of when a masternode was last seen on the network\n"
|
||||
" payee - Print Dash address associated with a masternode (can be additionally filtered,\n"
|
||||
" partial match)\n"
|
||||
" protocol - Print protocol of a masternode (can be additionally filtered, exact match))\n"
|
||||
" rank - Print rank of a masternode based on current block\n"
|
||||
" status - Print masternode status: ENABLED / EXPIRED / VIN_SPENT / REMOVE / POS_ERROR\n"
|
||||
" status - Print masternode status: PRE_ENABLED / ENABLED / EXPIRED / OUTPOINT_SPENT / REMOVE\n"
|
||||
" (can be additionally filtered, partial match)\n"
|
||||
);
|
||||
}
|
||||
@ -482,64 +478,68 @@ UniValue masternodelist(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
if (strMode == "rank") {
|
||||
std::vector<pair<int, CMasternode> > vMasternodeRanks = mnodeman.GetMasternodeRanks(chainActive.Tip()->nHeight);
|
||||
int nHeight;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
nHeight = chainActive.Height();
|
||||
}
|
||||
std::vector<std::pair<int, CMasternode> > vMasternodeRanks = mnodeman.GetMasternodeRanks(nHeight);
|
||||
BOOST_FOREACH(PAIRTYPE(int, CMasternode)& s, vMasternodeRanks) {
|
||||
std::string strVin = s.second.vin.prevout.ToStringShort();
|
||||
if(strFilter !="" && strVin.find(strFilter) == string::npos) continue;
|
||||
obj.push_back(Pair(strVin, s.first));
|
||||
std::string strOutpoint = s.second.vin.prevout.ToStringShort();
|
||||
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strOutpoint, s.first));
|
||||
}
|
||||
} else {
|
||||
std::vector<CMasternode> vMasternodes = mnodeman.GetFullMasternodeVector();
|
||||
BOOST_FOREACH(CMasternode& mn, vMasternodes) {
|
||||
std::string strVin = mn.vin.prevout.ToStringShort();
|
||||
std::string strOutpoint = mn.vin.prevout.ToStringShort();
|
||||
if (strMode == "activeseconds") {
|
||||
if(strFilter !="" && strVin.find(strFilter) == string::npos) continue;
|
||||
obj.push_back(Pair(strVin, (int64_t)(mn.lastPing.sigTime - mn.sigTime)));
|
||||
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strOutpoint, (int64_t)(mn.lastPing.sigTime - mn.sigTime)));
|
||||
} else if (strMode == "addr") {
|
||||
if(strFilter !="" && mn.vin.prevout.hash.ToString().find(strFilter) == string::npos &&
|
||||
strVin.find(strFilter) == string::npos) continue;
|
||||
obj.push_back(Pair(strVin, mn.addr.ToString()));
|
||||
std::string strAddress = mn.addr.ToString();
|
||||
if (strFilter !="" && strAddress.find(strFilter) == std::string::npos &&
|
||||
strOutpoint.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strOutpoint, strAddress));
|
||||
} else if (strMode == "full") {
|
||||
std::ostringstream addrStream;
|
||||
addrStream << setw(21) << strVin;
|
||||
|
||||
std::ostringstream stringStream;
|
||||
stringStream << setw(9) <<
|
||||
std::ostringstream streamFull;
|
||||
streamFull << std::setw(9) <<
|
||||
mn.GetStatus() << " " <<
|
||||
mn.nProtocolVersion << " " <<
|
||||
CBitcoinAddress(mn.pubKeyCollateralAddress.GetID()).ToString() << " " << setw(21) <<
|
||||
mn.addr.ToString() << " " <<
|
||||
(int64_t)mn.lastPing.sigTime << " " << setw(8) <<
|
||||
(int64_t)(mn.lastPing.sigTime - mn.sigTime) << " " <<
|
||||
(int64_t)mn.GetLastPaidTime();
|
||||
std::string output = stringStream.str();
|
||||
stringStream << " " << strVin;
|
||||
if(strFilter !="" && stringStream.str().find(strFilter) == string::npos &&
|
||||
strVin.find(strFilter) == string::npos) continue;
|
||||
obj.push_back(Pair(addrStream.str(), output));
|
||||
} else if (strMode == "lastseen") {
|
||||
if(strFilter !="" && strVin.find(strFilter) == string::npos) continue;
|
||||
obj.push_back(Pair(strVin, (int64_t)mn.lastPing.sigTime));
|
||||
CBitcoinAddress(mn.pubKeyCollateralAddress.GetID()).ToString() << " " <<
|
||||
(int64_t)mn.lastPing.sigTime << " " << std::setw(8) <<
|
||||
(int64_t)(mn.lastPing.sigTime - mn.sigTime) << " " << std::setw(10) <<
|
||||
mn.GetLastPaidTime() << " " << std::setw(6) <<
|
||||
mn.GetLastPaidBlock() << " " <<
|
||||
mn.addr.ToString();
|
||||
std::string strFull = streamFull.str();
|
||||
if (strFilter !="" && strFull.find(strFilter) == std::string::npos &&
|
||||
strOutpoint.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strOutpoint, strFull));
|
||||
} else if (strMode == "lastpaidblock") {
|
||||
if (strFilter !="" && strVin.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strVin, mn.GetLastPaidBlock()));
|
||||
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strOutpoint, mn.GetLastPaidBlock()));
|
||||
} else if (strMode == "lastpaidtime") {
|
||||
if (strFilter !="" && strVin.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strVin, mn.GetLastPaidTime()));
|
||||
} else if (strMode == "protocol") {
|
||||
if(strFilter !="" && strFilter != strprintf("%d", mn.nProtocolVersion) &&
|
||||
strVin.find(strFilter) == string::npos) continue;
|
||||
obj.push_back(Pair(strVin, (int64_t)mn.nProtocolVersion));
|
||||
} else if (strMode == "pubkey") {
|
||||
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strOutpoint, mn.GetLastPaidTime()));
|
||||
} else if (strMode == "lastseen") {
|
||||
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strOutpoint, (int64_t)mn.lastPing.sigTime));
|
||||
} else if (strMode == "payee") {
|
||||
CBitcoinAddress address(mn.pubKeyCollateralAddress.GetID());
|
||||
|
||||
if(strFilter !="" && address.ToString().find(strFilter) == string::npos &&
|
||||
strVin.find(strFilter) == string::npos) continue;
|
||||
obj.push_back(Pair(strVin, address.ToString()));
|
||||
} else if(strMode == "status") {
|
||||
std::string strPayee = address.ToString();
|
||||
if (strFilter !="" && strPayee.find(strFilter) == std::string::npos &&
|
||||
strOutpoint.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strOutpoint, strPayee));
|
||||
} else if (strMode == "protocol") {
|
||||
if (strFilter !="" && strFilter != strprintf("%d", mn.nProtocolVersion) &&
|
||||
strOutpoint.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strOutpoint, (int64_t)mn.nProtocolVersion));
|
||||
} else if (strMode == "status") {
|
||||
std::string strStatus = mn.GetStatus();
|
||||
if(strFilter !="" && strVin.find(strFilter) == string::npos && strStatus.find(strFilter) == string::npos) continue;
|
||||
obj.push_back(Pair(strVin, strStatus));
|
||||
if (strFilter !="" && strStatus.find(strFilter) == std::string::npos &&
|
||||
strOutpoint.find(strFilter) == std::string::npos) continue;
|
||||
obj.push_back(Pair(strOutpoint, strStatus));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -551,7 +551,7 @@ bool DecodeHexVecMnb(std::vector<CMasternodeBroadcast>& vecMnb, std::string strH
|
||||
if (!IsHex(strHexMnb))
|
||||
return false;
|
||||
|
||||
vector<unsigned char> mnbData(ParseHex(strHexMnb));
|
||||
std::vector<unsigned char> mnbData(ParseHex(strHexMnb));
|
||||
CDataStream ssData(mnbData, SER_NETWORK, PROTOCOL_VERSION);
|
||||
try {
|
||||
ssData >> vecMnb;
|
||||
@ -565,13 +565,13 @@ bool DecodeHexVecMnb(std::vector<CMasternodeBroadcast>& vecMnb, std::string strH
|
||||
|
||||
UniValue masternodebroadcast(const UniValue& params, bool fHelp)
|
||||
{
|
||||
string strCommand;
|
||||
std::string strCommand;
|
||||
if (params.size() >= 1)
|
||||
strCommand = params[0].get_str();
|
||||
|
||||
if (fHelp ||
|
||||
(strCommand != "create-alias" && strCommand != "create-all" && strCommand != "decode" && strCommand != "relay"))
|
||||
throw runtime_error(
|
||||
throw std::runtime_error(
|
||||
"masternodebroadcast \"command\"... ( \"passphrase\" )\n"
|
||||
"Set of commands to create and relay masternode broadcast messages\n"
|
||||
"\nArguments:\n"
|
||||
@ -591,43 +591,41 @@ UniValue masternodebroadcast(const UniValue& params, bool fHelp)
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Wait for reindex and/or import to finish");
|
||||
|
||||
if (params.size() < 2)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Command needs at least 2 parameters");
|
||||
|
||||
std::string alias = params[1].get_str();
|
||||
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Please specify an alias");
|
||||
|
||||
LOCK(pwalletMain->cs_wallet);
|
||||
EnsureWalletIsUnlocked();
|
||||
|
||||
bool found = false;
|
||||
bool fFound = false;
|
||||
std::string strAlias = params[1].get_str();
|
||||
|
||||
UniValue statusObj(UniValue::VOBJ);
|
||||
std::vector<CMasternodeBroadcast> vecMnb;
|
||||
|
||||
statusObj.push_back(Pair("alias", alias));
|
||||
statusObj.push_back(Pair("alias", strAlias));
|
||||
|
||||
BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries()) {
|
||||
if(mne.getAlias() == alias) {
|
||||
found = true;
|
||||
std::string errorMessage;
|
||||
if(mne.getAlias() == strAlias) {
|
||||
fFound = true;
|
||||
std::string strError;
|
||||
CMasternodeBroadcast mnb;
|
||||
|
||||
bool result = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), errorMessage, mnb, true);
|
||||
bool fResult = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), strError, mnb, true);
|
||||
|
||||
statusObj.push_back(Pair("result", result ? "successful" : "failed"));
|
||||
if(result) {
|
||||
statusObj.push_back(Pair("result", fResult ? "successful" : "failed"));
|
||||
if(fResult) {
|
||||
vecMnb.push_back(mnb);
|
||||
CDataStream ssVecMnb(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssVecMnb << vecMnb;
|
||||
statusObj.push_back(Pair("hex", HexStr(ssVecMnb.begin(), ssVecMnb.end())));
|
||||
} else {
|
||||
statusObj.push_back(Pair("errorMessage", errorMessage));
|
||||
statusObj.push_back(Pair("errorMessage", strError));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found) {
|
||||
if(!fFound) {
|
||||
statusObj.push_back(Pair("result", "not found"));
|
||||
statusObj.push_back(Pair("errorMessage", "Could not find alias in config. Verify with list-conf."));
|
||||
}
|
||||
@ -648,30 +646,28 @@ UniValue masternodebroadcast(const UniValue& params, bool fHelp)
|
||||
std::vector<CMasternodeConfig::CMasternodeEntry> mnEntries;
|
||||
mnEntries = masternodeConfig.getEntries();
|
||||
|
||||
int successful = 0;
|
||||
int failed = 0;
|
||||
int nSuccessful = 0;
|
||||
int nFailed = 0;
|
||||
|
||||
UniValue resultsObj(UniValue::VOBJ);
|
||||
std::vector<CMasternodeBroadcast> vecMnb;
|
||||
|
||||
BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries()) {
|
||||
std::string errorMessage;
|
||||
|
||||
CTxIn vin = CTxIn(uint256S(mne.getTxHash()), uint32_t(atoi(mne.getOutputIndex().c_str())));
|
||||
std::string strError;
|
||||
CMasternodeBroadcast mnb;
|
||||
|
||||
bool result = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), errorMessage, mnb, true);
|
||||
bool fResult = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), strError, mnb, true);
|
||||
|
||||
UniValue statusObj(UniValue::VOBJ);
|
||||
statusObj.push_back(Pair("alias", mne.getAlias()));
|
||||
statusObj.push_back(Pair("result", result ? "successful" : "failed"));
|
||||
statusObj.push_back(Pair("result", fResult ? "successful" : "failed"));
|
||||
|
||||
if(result) {
|
||||
successful++;
|
||||
if(fResult) {
|
||||
nSuccessful++;
|
||||
vecMnb.push_back(mnb);
|
||||
} else {
|
||||
failed++;
|
||||
statusObj.push_back(Pair("errorMessage", errorMessage));
|
||||
nFailed++;
|
||||
statusObj.push_back(Pair("errorMessage", strError));
|
||||
}
|
||||
|
||||
resultsObj.push_back(Pair("status", statusObj));
|
||||
@ -680,7 +676,7 @@ UniValue masternodebroadcast(const UniValue& params, bool fHelp)
|
||||
CDataStream ssVecMnb(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssVecMnb << vecMnb;
|
||||
UniValue returnObj(UniValue::VOBJ);
|
||||
returnObj.push_back(Pair("overall", strprintf("Successfully created broadcast messages for %d masternodes, failed to create %d, total %d", successful, failed, successful + failed)));
|
||||
returnObj.push_back(Pair("overall", strprintf("Successfully created broadcast messages for %d masternodes, failed to create %d, total %d", nSuccessful, nFailed, nSuccessful + nFailed)));
|
||||
returnObj.push_back(Pair("detail", resultsObj));
|
||||
returnObj.push_back(Pair("hex", HexStr(ssVecMnb.begin(), ssVecMnb.end())));
|
||||
|
||||
@ -692,21 +688,21 @@ UniValue masternodebroadcast(const UniValue& params, bool fHelp)
|
||||
if (params.size() != 2)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'masternodebroadcast decode \"hexstring\"'");
|
||||
|
||||
int successful = 0;
|
||||
int failed = 0;
|
||||
int nDos = 0;
|
||||
|
||||
std::vector<CMasternodeBroadcast> vecMnb;
|
||||
UniValue returnObj(UniValue::VOBJ);
|
||||
|
||||
if (!DecodeHexVecMnb(vecMnb, params[1].get_str()))
|
||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Masternode broadcast message decode failed");
|
||||
|
||||
int nSuccessful = 0;
|
||||
int nFailed = 0;
|
||||
int nDos = 0;
|
||||
UniValue returnObj(UniValue::VOBJ);
|
||||
|
||||
BOOST_FOREACH(CMasternodeBroadcast& mnb, vecMnb) {
|
||||
UniValue resultObj(UniValue::VOBJ);
|
||||
|
||||
if(mnb.CheckSignature(nDos)) {
|
||||
successful++;
|
||||
nSuccessful++;
|
||||
resultObj.push_back(Pair("vin", mnb.vin.ToString()));
|
||||
resultObj.push_back(Pair("addr", mnb.addr.ToString()));
|
||||
resultObj.push_back(Pair("pubKeyCollateralAddress", CBitcoinAddress(mnb.pubKeyCollateralAddress.GetID()).ToString()));
|
||||
@ -724,14 +720,14 @@ UniValue masternodebroadcast(const UniValue& params, bool fHelp)
|
||||
|
||||
resultObj.push_back(Pair("lastPing", lastPingObj));
|
||||
} else {
|
||||
failed++;
|
||||
nFailed++;
|
||||
resultObj.push_back(Pair("errorMessage", "Masternode broadcast signature verification failed"));
|
||||
}
|
||||
|
||||
returnObj.push_back(Pair(mnb.GetHash().ToString(), resultObj));
|
||||
}
|
||||
|
||||
returnObj.push_back(Pair("overall", strprintf("Successfully decoded broadcast messages for %d masternodes, failed to decode %d, total %d", successful, failed, successful + failed)));
|
||||
returnObj.push_back(Pair("overall", strprintf("Successfully decoded broadcast messages for %d masternodes, failed to decode %d, total %d", nSuccessful, nFailed, nSuccessful + nFailed)));
|
||||
|
||||
return returnObj;
|
||||
}
|
||||
@ -744,16 +740,16 @@ UniValue masternodebroadcast(const UniValue& params, bool fHelp)
|
||||
"1. \"hex\" (string, required) Broadcast messages hex string\n"
|
||||
"2. fast (string, optional) If none, using safe method\n");
|
||||
|
||||
int successful = 0;
|
||||
int failed = 0;
|
||||
bool fSafe = params.size() == 2;
|
||||
|
||||
std::vector<CMasternodeBroadcast> vecMnb;
|
||||
UniValue returnObj(UniValue::VOBJ);
|
||||
|
||||
if (!DecodeHexVecMnb(vecMnb, params[1].get_str()))
|
||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Masternode broadcast message decode failed");
|
||||
|
||||
int nSuccessful = 0;
|
||||
int nFailed = 0;
|
||||
bool fSafe = params.size() == 2;
|
||||
UniValue returnObj(UniValue::VOBJ);
|
||||
|
||||
// verify all signatures first, bailout if any of them broken
|
||||
BOOST_FOREACH(CMasternodeBroadcast& mnb, vecMnb) {
|
||||
UniValue resultObj(UniValue::VOBJ);
|
||||
@ -774,17 +770,17 @@ UniValue masternodebroadcast(const UniValue& params, bool fHelp)
|
||||
} else fResult = false;
|
||||
|
||||
if(fResult) {
|
||||
successful++;
|
||||
nSuccessful++;
|
||||
resultObj.push_back(Pair(mnb.GetHash().ToString(), "successful"));
|
||||
} else {
|
||||
failed++;
|
||||
nFailed++;
|
||||
resultObj.push_back(Pair("errorMessage", "Masternode broadcast signature verification failed"));
|
||||
}
|
||||
|
||||
returnObj.push_back(Pair(mnb.GetHash().ToString(), resultObj));
|
||||
}
|
||||
|
||||
returnObj.push_back(Pair("overall", strprintf("Successfully relayed broadcast messages for %d masternodes, failed to relay %d, total %d", successful, failed, successful + failed)));
|
||||
returnObj.push_back(Pair("overall", strprintf("Successfully relayed broadcast messages for %d masternodes, failed to relay %d, total %d", nSuccessful, nFailed, nSuccessful + nFailed)));
|
||||
|
||||
return returnObj;
|
||||
}
|
||||
|
@ -113,8 +113,6 @@ bool fLiteMode = false;
|
||||
-2 - disabled because wallet was locked and we were not able to replenish keypool
|
||||
*/
|
||||
int nWalletBackups = 10;
|
||||
/** Spork enforcement enabled time */
|
||||
int64_t enforceMasternodePaymentsTime = 4085657524;
|
||||
bool fSucessfullyLoaded = false;
|
||||
string strBudgetMode = "";
|
||||
|
||||
|
@ -46,7 +46,6 @@
|
||||
extern bool fMasterNode;
|
||||
extern bool fLiteMode;
|
||||
extern int nWalletBackups;
|
||||
extern int64_t enforceMasternodePaymentsTime;
|
||||
extern int keysLoaded;
|
||||
extern bool fSucessfullyLoaded;
|
||||
extern std::string strBudgetMode;
|
||||
|
Loading…
Reference in New Issue
Block a user