@@ -412,19 +412,9 @@ bool CMasternodeBroadcast::Create(std::string strService, std::string strKeyMast
412
412
return false ;
413
413
}
414
414
415
- CService service = CService (strService);
416
- int mainnetDefaultPort = Params (CBaseChainParams::MAIN).GetDefaultPort ();
417
- if (Params ().NetworkID () == CBaseChainParams::MAIN) {
418
- if (service.GetPort () != mainnetDefaultPort) {
419
- strErrorRet = strprintf (" Invalid port %u for masternode %s, only %d is supported on mainnet." , service.GetPort (), strService, mainnetDefaultPort);
420
- LogPrint (" masternode" ," CMasternodeBroadcast::Create -- %s\n " , strErrorRet);
421
- return false ;
422
- }
423
- } else if (service.GetPort () == mainnetDefaultPort) {
424
- strErrorRet = strprintf (" Invalid port %u for masternode %s, %d is the only supported on mainnet." , service.GetPort (), strService, mainnetDefaultPort);
425
- LogPrint (" masternode" ," CMasternodeBroadcast::Create -- %s\n " , strErrorRet);
415
+ // The service needs the correct default port to work properly
416
+ if (!CheckDefaultPort (strService, strErrorRet, " CMasternodeBroadcast::Create" ))
426
417
return false ;
427
- }
428
418
429
419
return Create (txin, CService (strService), keyCollateralAddressNew, pubKeyCollateralAddressNew, keyMasternodeNew, pubKeyMasternodeNew, strErrorRet, mnbRet);
430
420
}
@@ -466,6 +456,21 @@ bool CMasternodeBroadcast::Create(CTxIn txin, CService service, CKey keyCollater
466
456
return true ;
467
457
}
468
458
459
+ bool CMasternodeBroadcast::CheckDefaultPort (std::string strService, std::string& strErrorRet, std::string strContext)
460
+ {
461
+ CService service = CService (strService);
462
+ int nDefaultPort = Params ().GetDefaultPort ();
463
+
464
+ if (service.GetPort () != nDefaultPort) {
465
+ strErrorRet = strprintf (" Invalid port %u for masternode %s, only %d is supported on %s-net." ,
466
+ service.GetPort (), strService, nDefaultPort, Params ().NetworkIDString ());
467
+ LogPrint (" masternode" , " %s - %s\n " , strContext, strErrorRet);
468
+ return false ;
469
+ }
470
+
471
+ return true ;
472
+ }
473
+
469
474
bool CMasternodeBroadcast::CheckAndUpdate (int & nDos)
470
475
{
471
476
// make sure signature isn't in the future (past is OK)
0 commit comments