src/activemasternode.cpp
//
// Bootup the Masternode, look for a 2500 BRO input and register on the network
//
Bootup the Masternode, look for a 2500 BRO input and register on the network
Bootup the Masternode look for a 2500 BRO input and register on the network
void CActiveMasternode::ManageStatus()
{
    std::string errorMessage;
    if (!fMasterNode) return;
    if (fDebug) LogPrintf("CActiveMasternode::ManageStatus() - Begin\n");
    if (Params().NetworkID() != CBaseChainParams::REGTEST && !masternodeSync.IsBlockchainSynced()) {
        status = ACTIVE_MASTERNODE_SYNC_IN_PROCESS;
        LogPrintf("CActiveMasternode::ManageStatus() - %s\n", GetStatus());
        return;
    }
    if (status == ACTIVE_MASTERNODE_SYNC_IN_PROCESS) status = ACTIVE_MASTERNODE_INITIAL;
    if (status == ACTIVE_MASTERNODE_INITIAL) {
        CMasternode* pmn;
        pmn = mnodeman.Find(pubKeyMasternode);
        if (pmn != NULL) {
            pmn->Check();
            if (pmn->IsEnabled() && pmn->protocolVersion == PROTOCOL_VERSION) EnableHotColdMasterNode(pmn->vin, pmn->addr);
        }
    }
    if (status != ACTIVE_MASTERNODE_STARTED) {
        status = ACTIVE_MASTERNODE_NOT_CAPABLE;
        notCapableReason = "";
        if (pwalletMain->IsLocked()) {
            notCapableReason = "Wallet is locked.";
            LogPrintf("CActiveMasternode::ManageStatus() - not capable: %s\n", notCapableReason);
            return;
        }
        if (pwalletMain->GetBalance() == 0) {
            notCapableReason = "Hot node, waiting for remote activation.";
            LogPrintf("CActiveMasternode::ManageStatus() - not capable: %s\n", notCapableReason);
            return;
        }
        if (strMasterNodeAddr.empty()) {
            if (!GetLocal(service)) {
                notCapableReason = "Can't detect external address. Please use the masternodeaddr configuration option.";
                LogPrintf("CActiveMasternode::ManageStatus() - not capable: %s\n", notCapableReason);
                return;
            }
        } else {
            service = CService(strMasterNodeAddr);
        }
        if (Params().NetworkID() == CBaseChainParams::MAIN) {
            if (service.GetPort() != 33455) {
                notCapableReason = strprintf("Invalid port: %u - only 33455 is supported on mainnet.", service.GetPort());
                LogPrintf("CActiveMasternode::ManageStatus() - not capable: %s\n", notCapableReason);
                return;
            }
        } else if (service.GetPort() == 33455) {
            notCapableReason = strprintf("Invalid port: %u - 33455 is only supported on mainnet.", service.GetPort());
            LogPrintf("CActiveMasternode::ManageStatus() - not capable: %s\n", notCapableReason);
            return;
        }
        LogPrintf("CActiveMasternode::ManageStatus() - Checking inbound connection to '%s'\n", service.ToString());
        CNode* pnode = ConnectNode((CAddress)service, NULL, false);
        if (!pnode) {
            notCapableReason = "Could not connect to " + service.ToString();
            LogPrintf("CActiveMasternode::ManageStatus() - not capable: %s\n", notCapableReason);
            return;
        }
        pnode->Release();
        CPubKey pubKeyCollateralAddress;
        CKey keyCollateralAddress;
        if (GetMasterNodeVin(vin, pubKeyCollateralAddress, keyCollateralAddress)) {
            if (GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS) {
                status = ACTIVE_MASTERNODE_INPUT_TOO_NEW;
                notCapableReason = strprintf("%s - %d confirmations", GetStatus(), GetInputAge(vin));
                LogPrintf("CActiveMasternode::ManageStatus() - %s\n", notCapableReason);
                return;
            }
            LOCK(pwalletMain->cs_wallet);
            pwalletMain->LockCoin(vin.prevout);
            CPubKey pubKeyMasternode;
            CKey keyMasternode;
            if (!obfuScationSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)) {
                notCapableReason = "Error upon calling SetKey: " + errorMessage;
                LogPrintf("Register::ManageStatus() - %s\n", notCapableReason);
                return;
            }
            if (!Register(vin, service, keyCollateralAddress, pubKeyCollateralAddress, keyMasternode, pubKeyMasternode, errorMessage)) {
                notCapableReason = "Error on Register: " + errorMessage;
                LogPrintf("Register::ManageStatus() - %s\n", notCapableReason);
                return;
            }
            LogPrintf("CActiveMasternode::ManageStatus() - Is capable master node!\n");
            status = ACTIVE_MASTERNODE_STARTED;
            return;
        } else {
            notCapableReason = "Could not find suitable coins!";
            LogPrintf("CActiveMasternode::ManageStatus() - %s\n", notCapableReason);
            return;
        }
    }
    if (!SendMasternodePing(errorMessage)) {
        LogPrintf("CActiveMasternode::ManageStatus() - Error on Ping: %s\n", errorMessage);
    }
}
void CActiveMasternode :: ManageStatus ( ) { std :: string errorMessage ; if ( ! fMasterNode ) return ; if ( fDebug ) LogPrintf ( " \n " ) ; if ( Params ( ) . NetworkID ( ) != CBaseChainParams :: REGTEST && ! masternodeSync . IsBlockchainSynced ( ) ) { status = ACTIVE_MASTERNODE_SYNC_IN_PROCESS ; LogPrintf ( " \n " , GetStatus ( ) ) ; return ; } if ( status == ACTIVE_MASTERNODE_SYNC_IN_PROCESS ) status = ACTIVE_MASTERNODE_INITIAL ; if ( status == ACTIVE_MASTERNODE_INITIAL ) { CMasternode * pmn ; pmn = mnodeman . Find ( pubKeyMasternode ) ; if ( pmn != NULL ) { pmn -> Check ( ) ; if ( pmn -> IsEnabled ( ) && pmn -> protocolVersion == PROTOCOL_VERSION ) EnableHotColdMasterNode ( pmn -> vin , pmn -> addr ) ; } } if ( status != ACTIVE_MASTERNODE_STARTED ) { status = ACTIVE_MASTERNODE_NOT_CAPABLE ; notCapableReason = " " ; if ( pwalletMain -> IsLocked ( ) ) { notCapableReason = " " ; LogPrintf ( " \n " , notCapableReason ) ; return ; } if ( pwalletMain -> GetBalance ( ) == 0 ) { notCapableReason = " " ; LogPrintf ( " \n " , notCapableReason ) ; return ; } if ( strMasterNodeAddr . empty ( ) ) { if ( ! GetLocal ( service ) ) { notCapableReason = " " ; LogPrintf ( " \n " , notCapableReason ) ; return ; } } else { service = CService ( strMasterNodeAddr ) ; } if ( Params ( ) . NetworkID ( ) == CBaseChainParams :: MAIN ) { if ( service . GetPort ( ) != 33455 ) { notCapableReason = strprintf ( " " , service . GetPort ( ) ) ; LogPrintf ( " \n " , notCapableReason ) ; return ; } } else if ( service . GetPort ( ) == 33455 ) { notCapableReason = strprintf ( " " , service . GetPort ( ) ) ; LogPrintf ( " \n " , notCapableReason ) ; return ; } LogPrintf ( " \n " , service . ToString ( ) ) ; CNode * pnode = ConnectNode ( ( CAddress ) service , NULL , false ) ; if ( ! pnode ) { notCapableReason = " " + service . ToString ( ) ; LogPrintf ( " \n " , notCapableReason ) ; return ; } pnode -> Release ( ) ; CPubKey pubKeyCollateralAddress ; CKey keyCollateralAddress ; if ( GetMasterNodeVin ( vin , pubKeyCollateralAddress , keyCollateralAddress ) ) { if ( GetInputAge ( vin ) < MASTERNODE_MIN_CONFIRMATIONS ) { status = ACTIVE_MASTERNODE_INPUT_TOO_NEW ; notCapableReason = strprintf ( " " , GetStatus ( ) , GetInputAge ( vin ) ) ; LogPrintf ( " \n " , notCapableReason ) ; return ; } LOCK ( pwalletMain -> cs_wallet ) ; pwalletMain -> LockCoin ( vin . prevout ) ; CPubKey pubKeyMasternode ; CKey keyMasternode ; if ( ! obfuScationSigner . SetKey ( strMasterNodePrivKey , errorMessage , keyMasternode , pubKeyMasternode ) ) { notCapableReason = " " + errorMessage ; LogPrintf ( " \n " , notCapableReason ) ; return ; } if ( ! Register ( vin , service , keyCollateralAddress , pubKeyCollateralAddress , keyMasternode , pubKeyMasternode , errorMessage ) ) { notCapableReason = " " + errorMessage ; LogPrintf ( " \n " , notCapableReason ) ; return ; } LogPrintf ( " \n " ) ; status = ACTIVE_MASTERNODE_STARTED ; return ; } else { notCapableReason = " " ; LogPrintf ( " \n " , notCapableReason ) ; return ; } } if ( ! SendMasternodePing ( errorMessage ) ) { LogPrintf ( " \n " , errorMessage ) ; } }
Bootup the Masternode, look for a 2500 BRO input and register on the network
Bootup the Masternode look for a 2500 BRO input and register on the network
//need correct blocks to send ping // Set defaults // Choose coins to use // send to all nodes //send to all peers