Skip to content

Commit 9732e80

Browse files
committed
Do not try to register a deferred masternode.
When startmasternode is called with defer set to true, do not even attempt to register the masternode; just create the broadcast data and return it. This makes it possible to use the function even when the masternode is not yet valid, e.g. because the collateral does not have sufficient confirmations yet.
1 parent 31d1559 commit 9732e80

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

divi/src/rpcmasternode.cpp

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -505,57 +505,55 @@ Value startmasternode(const Array& params, bool fHelp)
505505
"\nResult:\n"
506506
"\"status\" (string) status of masternode\n");
507507

508-
std::string alias = params[0].get_str();
509-
bool deferRelay = (params.size() == 1)? false: params[1].get_bool();
508+
const std::string alias = params[0].get_str();
509+
const bool deferRelay = (params.size() == 1)? false: params[1].get_bool();
510510

511511
EnsureWalletIsUnlocked();
512512

513-
Object result;
514-
bool fFound = false;
515513
for(const auto& configEntry : masternodeConfig.getEntries())
516514
{
517-
if(configEntry.getAlias() == alias)
515+
if(configEntry.getAlias() != alias)
516+
continue;
517+
518+
Object result;
519+
std::string strError;
520+
CMasternodeBroadcast mnb;
521+
522+
if(!CMasternodeBroadcastFactory::Create(
523+
configEntry,
524+
strError,
525+
mnb,
526+
false,
527+
deferRelay))
518528
{
519-
fFound = true;
520-
std::string strError;
521-
CMasternodeBroadcast mnb;
522-
523-
if(!CMasternodeBroadcastFactory::Create(
524-
configEntry,
525-
strError,
526-
mnb,
527-
false,
528-
deferRelay))
529-
{
530-
break;
531-
}
529+
result.push_back(Pair("status", "failed"));
530+
result.push_back(Pair("error", strError));
531+
return result;
532+
}
532533

533-
if(CActiveMasternode::Register(mnb, deferRelay))
534-
{
535-
result.push_back(Pair("status", "success"));
536-
if(deferRelay)
537-
{
538-
CDataStream ss(SER_NETWORK,PROTOCOL_VERSION);
539-
ss << mnb;
540-
result.push_back(Pair("broadcastData", HexStr(ss.str()) ));
541-
}
542-
fFound = true;
543-
}
534+
if (deferRelay)
535+
{
536+
CDataStream ss(SER_NETWORK,PROTOCOL_VERSION);
537+
ss << mnb;
544538

545-
if(!fFound)
546-
{
547-
result.push_back(Pair("status", "failed"));
548-
result.push_back(Pair("error", strError));
549-
}
539+
result.push_back(Pair("status", "success"));
540+
result.push_back(Pair("broadcastData", HexStr(ss.str())));
550541

551-
break;
542+
return result;
552543
}
553-
}
554544

555-
if(!fFound)
556-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid alias, couldn't find MN. Check your masternode.conf file");
545+
if(!CActiveMasternode::Register(mnb, deferRelay))
546+
{
547+
result.push_back(Pair("status", "failed"));
548+
result.push_back(Pair("error", strError));
549+
return result;
550+
}
557551

558-
return result;
552+
result.push_back(Pair("status", "success"));
553+
return result;
554+
}
555+
556+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid alias, couldn't find MN. Check your masternode.conf file");
559557
}
560558

561559
Value createmasternodekey(const Array& params, bool fHelp)

0 commit comments

Comments
 (0)