|
14 | 14 | #include "netbase.h" |
15 | 15 | #include "protocol.h" |
16 | 16 |
|
| 17 | +void initMasternode(const std::string& _strMasterNodePrivKey, const std::string& _strMasterNodeAddr, bool isFromInit) |
| 18 | +{ |
| 19 | + if (!isFromInit && fMasterNode) { |
| 20 | + throw std::runtime_error("ERROR: Masternode already initialized.\n"); |
| 21 | + } |
| 22 | + |
| 23 | + LOCK(cs_main); // Lock cs_main so the node doesn't perform any action while we setup the Masternode |
| 24 | + LogPrintf("Initializing masternode, addr %s..\n", _strMasterNodeAddr.c_str()); |
| 25 | + |
| 26 | + if (_strMasterNodePrivKey.empty()) { |
| 27 | + throw std::runtime_error("ERROR: Masternode priv key cannot be empty.\n"); |
| 28 | + } |
| 29 | + |
| 30 | + if (_strMasterNodeAddr.empty()) { |
| 31 | + throw std::runtime_error("ERROR: Empty masternodeaddr\n"); |
| 32 | + } |
| 33 | + |
| 34 | + // Global params set |
| 35 | + strMasterNodeAddr = _strMasterNodeAddr; |
| 36 | + strMasterNodePrivKey = _strMasterNodePrivKey; |
| 37 | + |
| 38 | + // Address parsing. |
| 39 | + const CChainParams& params = Params(); |
| 40 | + int nPort; |
| 41 | + int nDefaultPort = params.GetDefaultPort(); |
| 42 | + std::string strHost; |
| 43 | + SplitHostPort(strMasterNodeAddr, nPort, strHost); |
| 44 | + |
| 45 | + // Allow for the port number to be omitted here and just double check |
| 46 | + // that if a port is supplied, it matches the required default port. |
| 47 | + if (nPort == 0) nPort = nDefaultPort; |
| 48 | + if (nPort != nDefaultPort && !params.IsRegTestNet()) { |
| 49 | + throw std::runtime_error(strprintf(_("Invalid -masternodeaddr port %d, only %d is supported on %s-net."), |
| 50 | + nPort, nDefaultPort, Params().NetworkIDString())); |
| 51 | + } |
| 52 | + CService addrTest(LookupNumeric(strHost.c_str(), nPort)); |
| 53 | + if (!addrTest.IsValid()) { |
| 54 | + throw std::runtime_error(strprintf(_("Invalid -masternodeaddr address: %s"), strMasterNodeAddr)); |
| 55 | + } |
| 56 | + |
| 57 | + CKey key; |
| 58 | + CPubKey pubkey; |
| 59 | + |
| 60 | + if (!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, key, pubkey)) { |
| 61 | + throw std::runtime_error(_("Invalid masternodeprivkey. Please see documenation.")); |
| 62 | + } |
| 63 | + activeMasternode.pubKeyMasternode = pubkey; |
| 64 | + fMasterNode = true; |
| 65 | +} |
| 66 | + |
17 | 67 | // |
18 | 68 | // Bootup the Masternode, look for a 10000 PIVX input and register on the network |
19 | 69 | // |
|
0 commit comments