bool CMasternodeBroadcast::Create(CTxIn txin, CService service, CKey keyCollateralAddressNew, CPubKey pubKeyCollateralAddressNew, CKey keyMasternodeNew, CPubKey pubKeyMasternodeNew, std::string& strErrorRet, CMasternodeBroadcast& mnbRet) { // wait for reindex and/or import to finish if (fImporting || fReindex) return false; LogPrint("masternode", "CMasternodeBroadcast::Create -- pubKeyCollateralAddressNew = %s, pubKeyMasternodeNew.GetID() = %s\n", CBitcoinAddress(pubKeyCollateralAddressNew.GetID()).ToString(), pubKeyMasternodeNew.GetID().ToString()); CMasternodePing mnp(txin); if (!mnp.Sign(keyMasternodeNew, pubKeyMasternodeNew)) { strErrorRet = strprintf("Failed to sign ping, masternode=%s", txin.prevout.ToStringShort()); LogPrintf("CMasternodeBroadcast::Create -- %s\n", strErrorRet); mnbRet = CMasternodeBroadcast(); return false; } mnbRet = CMasternodeBroadcast(service, txin, pubKeyCollateralAddressNew, pubKeyMasternodeNew, PROTOCOL_VERSION); if (!mnbRet.IsValidNetAddr()) { strErrorRet = strprintf("Invalid IP address, masternode=%s", txin.prevout.ToStringShort()); LogPrintf("CMasternodeBroadcast::Create -- %s\n", strErrorRet); mnbRet = CMasternodeBroadcast(); return false; } mnbRet.lastPing = mnp; if (!mnbRet.Sign(keyCollateralAddressNew)) { strErrorRet = strprintf("Failed to sign broadcast, masternode=%s", txin.prevout.ToStringShort()); LogPrintf("CMasternodeBroadcast::Create -- %s\n", strErrorRet); mnbRet = CMasternodeBroadcast(); return false; } return true; }
bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateralAddress, CPubKey pubKeyCollateralAddress, CKey keyMasternode, CPubKey pubKeyMasternode, std::string &errorMessage) { CMasternodeBroadcast mnb; CMasternodePing mnp(vin); if(!mnp.Sign(keyMasternode, pubKeyMasternode)){ errorMessage = strprintf("Failed to sign ping, vin: %s", vin.ToString()); LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage); return false; } mnodeman.mapSeenMasternodePing.insert(make_pair(mnp.GetHash(), mnp)); LogPrintf("CActiveMasternode::Register() - Adding to Masternode list\n service: %s\n vin: %s\n", service.ToString(), vin.ToString()); mnb = CMasternodeBroadcast(service, vin, pubKeyCollateralAddress, pubKeyMasternode, PROTOCOL_VERSION); mnb.lastPing = mnp; if(!mnb.Sign(keyCollateralAddress)){ errorMessage = strprintf("Failed to sign broadcast, vin: %s", vin.ToString()); LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage); return false; } mnodeman.mapSeenMasternodeBroadcast.insert(make_pair(mnb.GetHash(), mnb)); masternodeSync.AddedMasternodeList(mnb.GetHash()); CMasternode* pmn = mnodeman.Find(vin); if(pmn == NULL) { CMasternode mn(mnb); mnodeman.Add(mn); } else { pmn->UpdateFromNewBroadcast(mnb); } //send to all peers LogPrintf("CActiveMasternode::Register() - RelayElectionEntry vin = %s\n", vin.ToString()); mnb.Relay(); return true; }
bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateralAddress, CPubKey pubKeyCollateralAddress, CKey keyMasternode, CPubKey pubKeyMasternode, std::string& errorMessage) { CMasternodeBroadcast mnb; CMasternodePing mnp(vin); if (!mnp.Sign(keyMasternode, pubKeyMasternode)) { errorMessage = strprintf("Failed to sign ping, vin: %s", vin.ToString()); LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage); return false; } mnodeman.mapSeenMasternodePing.insert(make_pair(mnp.GetHash(), mnp)); LogPrintf("CActiveMasternode::Register() - Adding to Masternode list\n service: %s\n vin: %s\n", service.ToString(), vin.ToString()); mnb = CMasternodeBroadcast(service, vin, pubKeyCollateralAddress, pubKeyMasternode, PROTOCOL_VERSION); mnb.lastPing = mnp; if (!mnb.Sign(keyCollateralAddress)) { errorMessage = strprintf("Failed to sign broadcast, vin: %s", vin.ToString()); LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage); return false; } mnodeman.mapSeenMasternodeBroadcast.insert(make_pair(mnb.GetHash(), mnb)); masternodeSync.AddedMasternodeList(mnb.GetHash()); CMasternode* pmn = mnodeman.Find(vin); if (pmn == NULL) { CMasternode mn(mnb); mnodeman.Add(mn); } else { pmn->UpdateFromNewBroadcast(mnb); } //send to all peers LogPrintf("CActiveMasternode::Register() - RelayElectionEntry vin = %s\n", vin.ToString()); mnb.Relay(); /* * IT'S SAFE TO REMOVE THIS IN FURTHER VERSIONS * AFTER MIGRATION TO V12 IS DONE */ if (IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return true; // for migration purposes inject our node in old masternodes' list too std::string retErrorMessage; std::vector<unsigned char> vchMasterNodeSignature; int64_t masterNodeSignatureTime = GetAdjustedTime(); std::string donationAddress = ""; int donationPercantage = 0; std::string vchPubKey(pubKeyCollateralAddress.begin(), pubKeyCollateralAddress.end()); std::string vchPubKey2(pubKeyMasternode.begin(), pubKeyMasternode.end()); std::string strMessage = service.ToString() + boost::lexical_cast<std::string>(masterNodeSignatureTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(PROTOCOL_VERSION) + donationAddress + boost::lexical_cast<std::string>(donationPercantage); if (!obfuScationSigner.SignMessage(strMessage, retErrorMessage, vchMasterNodeSignature, keyCollateralAddress)) { errorMessage = "dsee sign message failed: " + retErrorMessage; LogPrintf("CActiveMasternode::Register() - Error: %s\n", errorMessage.c_str()); return false; } if (!obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, vchMasterNodeSignature, strMessage, retErrorMessage)) { errorMessage = "dsee verify message failed: " + retErrorMessage; LogPrintf("CActiveMasternode::Register() - Error: %s\n", errorMessage.c_str()); return false; } LOCK(cs_vNodes); BOOST_FOREACH (CNode* pnode, vNodes) pnode->PushMessage("dsee", vin, service, vchMasterNodeSignature, masterNodeSignatureTime, pubKeyCollateralAddress, pubKeyMasternode, -1, -1, masterNodeSignatureTime, PROTOCOL_VERSION, donationAddress, donationPercantage); /* * END OF "REMOVE" */ return true; }