Skip to content

Commit

Permalink
Merge pull request #263 from UdjinM6/v0.11.2.x_tabs_spaces
Browse files Browse the repository at this point in the history
V0.11.2.x format only: activemasternode
  • Loading branch information
evan82 committed Mar 22, 2015
2 parents 7cdf398 + 4f98a22 commit 30796a8
Showing 1 changed file with 83 additions and 83 deletions.
166 changes: 83 additions & 83 deletions src/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void CActiveMasternode::ManageStatus()
return;
}
} else {
service = CService(strMasterNodeAddr);
service = CService(strMasterNodeAddr);
}

LogPrintf("CActiveMasternode::ManageStatus() - Checking inbound connection to '%s'\n", service.ToString().c_str());
Expand Down Expand Up @@ -101,8 +101,8 @@ void CActiveMasternode::ManageStatus()

if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode))
{
LogPrintf("Register::ManageStatus() - Error upon calling SetKey: %s\n", errorMessage.c_str());
return;
LogPrintf("Register::ManageStatus() - Error upon calling SetKey: %s\n", errorMessage.c_str());
return;
}

/* donations are not supported in dash.conf */
Expand All @@ -128,63 +128,63 @@ void CActiveMasternode::ManageStatus()

// Send stop dseep to network for remote Masternode
bool CActiveMasternode::StopMasterNode(std::string strService, std::string strKeyMasternode, std::string& errorMessage) {
CTxIn vin;
CTxIn vin;
CKey keyMasternode;
CPubKey pubKeyMasternode;

if(!darkSendSigner.SetKey(strKeyMasternode, errorMessage, keyMasternode, pubKeyMasternode)) {
LogPrintf("CActiveMasternode::StopMasterNode() - Error: %s\n", errorMessage.c_str());
return false;
}
LogPrintf("CActiveMasternode::StopMasterNode() - Error: %s\n", errorMessage.c_str());
return false;
}

return StopMasterNode(vin, CService(strService), keyMasternode, pubKeyMasternode, errorMessage);
return StopMasterNode(vin, CService(strService), keyMasternode, pubKeyMasternode, errorMessage);
}

// Send stop dseep to network for main Masternode
bool CActiveMasternode::StopMasterNode(std::string& errorMessage) {
if(status != MASTERNODE_IS_CAPABLE && status != MASTERNODE_REMOTELY_ENABLED) {
errorMessage = "Masternode is not in a running status";
LogPrintf("CActiveMasternode::StopMasterNode() - Error: %s\n", errorMessage.c_str());
return false;
}
if(status != MASTERNODE_IS_CAPABLE && status != MASTERNODE_REMOTELY_ENABLED) {
errorMessage = "Masternode is not in a running status";
LogPrintf("CActiveMasternode::StopMasterNode() - Error: %s\n", errorMessage.c_str());
return false;
}

status = MASTERNODE_STOPPED;
status = MASTERNODE_STOPPED;

CPubKey pubKeyMasternode;
CKey keyMasternode;

if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode))
{
LogPrintf("Register::ManageStatus() - Error upon calling SetKey: %s\n", errorMessage.c_str());
return false;
LogPrintf("Register::ManageStatus() - Error upon calling SetKey: %s\n", errorMessage.c_str());
return false;
}

return StopMasterNode(vin, service, keyMasternode, pubKeyMasternode, errorMessage);
return StopMasterNode(vin, service, keyMasternode, pubKeyMasternode, errorMessage);
}

// Send stop dseep to network for any Masternode
bool CActiveMasternode::StopMasterNode(CTxIn vin, CService service, CKey keyMasternode, CPubKey pubKeyMasternode, std::string& errorMessage) {
pwalletMain->UnlockCoin(vin.prevout);
return Dseep(vin, service, keyMasternode, pubKeyMasternode, errorMessage, true);
pwalletMain->UnlockCoin(vin.prevout);
return Dseep(vin, service, keyMasternode, pubKeyMasternode, errorMessage, true);
}

bool CActiveMasternode::Dseep(std::string& errorMessage) {
if(status != MASTERNODE_IS_CAPABLE && status != MASTERNODE_REMOTELY_ENABLED) {
errorMessage = "Masternode is not in a running status";
LogPrintf("CActiveMasternode::Dseep() - Error: %s\n", errorMessage.c_str());
return false;
}
if(status != MASTERNODE_IS_CAPABLE && status != MASTERNODE_REMOTELY_ENABLED) {
errorMessage = "Masternode is not in a running status";
LogPrintf("CActiveMasternode::Dseep() - Error: %s\n", errorMessage.c_str());
return false;
}

CPubKey pubKeyMasternode;
CKey keyMasternode;

if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode))
{
LogPrintf("Register::ManageStatus() - Error upon calling SetKey: %s\n", errorMessage.c_str());
return false;
LogPrintf("CActiveMasternode::Dseep() - Error upon calling SetKey: %s\n", errorMessage.c_str());
return false;
}

return Dseep(vin, service, keyMasternode, pubKeyMasternode, errorMessage, false);
return Dseep(vin, service, keyMasternode, pubKeyMasternode, errorMessage, false);
}

bool CActiveMasternode::Dseep(CTxIn vin, CService service, CKey keyMasternode, CPubKey pubKeyMasternode, std::string &retErrorMessage, bool stop) {
Expand All @@ -196,14 +196,14 @@ bool CActiveMasternode::Dseep(CTxIn vin, CService service, CKey keyMasternode, C
std::string strMessage = service.ToString() + boost::lexical_cast<std::string>(masterNodeSignatureTime) + boost::lexical_cast<std::string>(stop);

if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchMasterNodeSignature, keyMasternode)) {
retErrorMessage = "sign message failed: " + errorMessage;
LogPrintf("CActiveMasternode::Dseep() - Error: %s\n", retErrorMessage.c_str());
retErrorMessage = "sign message failed: " + errorMessage;
LogPrintf("CActiveMasternode::Dseep() - Error: %s\n", retErrorMessage.c_str());
return false;
}

if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchMasterNodeSignature, strMessage, errorMessage)) {
retErrorMessage = "Verify message failed: " + errorMessage;
LogPrintf("CActiveMasternode::Dseep() - Error: %s\n", retErrorMessage.c_str());
retErrorMessage = "Verify message failed: " + errorMessage;
LogPrintf("CActiveMasternode::Dseep() - Error: %s\n", retErrorMessage.c_str());
return false;
}

Expand All @@ -215,9 +215,9 @@ bool CActiveMasternode::Dseep(CTxIn vin, CService service, CKey keyMasternode, C
}
else
{
// Seems like we are trying to send a ping while the Masternode is not registered in the network
retErrorMessage = "Darksend Masternode List doesn't include our Masternode, Shutting down Masternode pinging service! " + vin.ToString();
LogPrintf("CActiveMasternode::Dseep() - Error: %s\n", retErrorMessage.c_str());
// Seems like we are trying to send a ping while the Masternode is not registered in the network
retErrorMessage = "Darksend Masternode List doesn't include our Masternode, Shutting down Masternode pinging service! " + vin.ToString();
LogPrintf("CActiveMasternode::Dseep() - Error: %s\n", retErrorMessage.c_str());
status = MASTERNODE_NOT_CAPABLE;
notCapableReason = retErrorMessage;
return false;
Expand All @@ -231,7 +231,7 @@ bool CActiveMasternode::Dseep(CTxIn vin, CService service, CKey keyMasternode, C
}

bool CActiveMasternode::Register(std::string strService, std::string strKeyMasternode, std::string txHash, std::string strOutputIndex, std::string strDonationAddress, std::string strDonationPercentage, std::string& errorMessage) {
CTxIn vin;
CTxIn vin;
CPubKey pubKeyCollateralAddress;
CKey keyCollateralAddress;
CPubKey pubKeyMasternode;
Expand All @@ -241,41 +241,41 @@ bool CActiveMasternode::Register(std::string strService, std::string strKeyMaste

if(!darkSendSigner.SetKey(strKeyMasternode, errorMessage, keyMasternode, pubKeyMasternode))
{
LogPrintf("CActiveMasternode::Register() - Error upon calling SetKey: %s\n", errorMessage.c_str());
return false;
LogPrintf("CActiveMasternode::Register() - Error upon calling SetKey: %s\n", errorMessage.c_str());
return false;
}

if(!GetMasterNodeVin(vin, pubKeyCollateralAddress, keyCollateralAddress, txHash, strOutputIndex)) {
errorMessage = "could not allocate vin";
LogPrintf("Register::Register() - Error: %s\n", errorMessage.c_str());
return false;
}
errorMessage = "could not allocate vin";
LogPrintf("CActiveMasternode::Register() - Error: %s\n", errorMessage.c_str());
return false;
}

CBitcoinAddress address;
if (strDonationAddress != "")
if (strDonationAddress != "")
{
if(!address.SetString(strDonationAddress))
{
LogPrintf("Register::Register - Invalid Donation Address\n");
LogPrintf("CActiveMasternode::Register - Invalid Donation Address\n");
return false;
}
donationAddress.SetDestination(address.Get());

try {
donationPercentage = boost::lexical_cast<int>( strDonationPercentage );
} catch( boost::bad_lexical_cast const& ) {
LogPrintf("Register::Register - Invalid Donation Percentage (Couldn't cast)\n");
LogPrintf("CActiveMasternode::Register - Invalid Donation Percentage (Couldn't cast)\n");
return false;
}

if(donationPercentage < 0 || donationPercentage > 100)
{
LogPrintf("Register::Register - Donation Percentage Out Of Range\n");
LogPrintf("CActiveMasternode::Register - Donation Percentage Out Of Range\n");
return false;
}
}

return Register(vin, CService(strService), keyCollateralAddress, pubKeyCollateralAddress, keyMasternode, pubKeyMasternode, donationAddress, donationPercentage, errorMessage);
return Register(vin, CService(strService), keyCollateralAddress, pubKeyCollateralAddress, keyMasternode, pubKeyMasternode, donationAddress, donationPercentage, errorMessage);
}

bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateralAddress, CPubKey pubKeyCollateralAddress, CKey keyMasternode, CPubKey pubKeyMasternode, CScript donationAddress, int donationPercentage, std::string &retErrorMessage) {
Expand All @@ -290,16 +290,16 @@ bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateral
std::string strMessage = service.ToString() + boost::lexical_cast<std::string>(masterNodeSignatureTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(PROTOCOL_VERSION) + donationAddress.ToString() + boost::lexical_cast<std::string>(donationPercentage);

if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchMasterNodeSignature, keyCollateralAddress)) {
retErrorMessage = "sign message failed: " + errorMessage;
LogPrintf("CActiveMasternode::Register() - Error: %s\n", retErrorMessage.c_str());
return false;
retErrorMessage = "sign message failed: " + errorMessage;
LogPrintf("CActiveMasternode::Register() - Error: %s\n", retErrorMessage.c_str());
return false;
}

if(!darkSendSigner.VerifyMessage(pubKeyCollateralAddress, vchMasterNodeSignature, strMessage, errorMessage)) {
retErrorMessage = "Verify message failed: " + errorMessage;
LogPrintf("CActiveMasternode::Register() - Error: %s\n", retErrorMessage.c_str());
return false;
}
retErrorMessage = "Verify message failed: " + errorMessage;
LogPrintf("CActiveMasternode::Register() - Error: %s\n", retErrorMessage.c_str());
return false;
}

CMasternode* pmn = mnodeman.Find(vin);
if(pmn == NULL)
Expand All @@ -318,7 +318,7 @@ bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateral
}

bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey) {
return GetMasterNodeVin(vin, pubkey, secretKey, "", "");
return GetMasterNodeVin(vin, pubkey, secretKey, "", "");
}

bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey, std::string strTxHash, std::string strOutputIndex) {
Expand All @@ -329,35 +329,35 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr
COutput *selectedOutput;

// Find the vin
if(!strTxHash.empty()) {
// Let's find it
uint256 txHash(strTxHash);
if(!strTxHash.empty()) {
// Let's find it
uint256 txHash(strTxHash);
int outputIndex = boost::lexical_cast<int>(strOutputIndex);
bool found = false;
BOOST_FOREACH(COutput& out, possibleCoins) {
if(out.tx->GetHash() == txHash && out.i == outputIndex)
{
selectedOutput = &out;
found = true;
break;
}
}
if(!found) {
LogPrintf("CActiveMasternode::GetMasterNodeVin - Could not locate valid vin\n");
return false;
}
} else {
// No output specified, Select the first one
if(possibleCoins.size() > 0) {
selectedOutput = &possibleCoins[0];
} else {
LogPrintf("CActiveMasternode::GetMasterNodeVin - Could not locate specified vin from possible list\n");
return false;
}
bool found = false;
BOOST_FOREACH(COutput& out, possibleCoins) {
if(out.tx->GetHash() == txHash && out.i == outputIndex)
{
selectedOutput = &out;
found = true;
break;
}
}
if(!found) {
LogPrintf("CActiveMasternode::GetMasterNodeVin - Could not locate valid vin\n");
return false;
}
} else {
// No output specified, Select the first one
if(possibleCoins.size() > 0) {
selectedOutput = &possibleCoins[0];
} else {
LogPrintf("CActiveMasternode::GetMasterNodeVin - Could not locate specified vin from possible list\n");
return false;
}
}

// At this point we have a selected output, retrieve the associated info
return GetVinFromOutput(*selectedOutput, vin, pubkey, secretKey);
// At this point we have a selected output, retrieve the associated info
return GetVinFromOutput(*selectedOutput, vin, pubkey, secretKey);
}


Expand All @@ -366,10 +366,10 @@ bool CActiveMasternode::GetVinFromOutput(COutput out, CTxIn& vin, CPubKey& pubke

CScript pubScript;

vin = CTxIn(out.tx->GetHash(),out.i);
vin = CTxIn(out.tx->GetHash(),out.i);
pubScript = out.tx->vout[out.i].scriptPubKey; // the inputs PubKey

CTxDestination address1;
CTxDestination address1;
ExtractDestination(pubScript, address1);
CBitcoinAddress address2(address1);

Expand Down Expand Up @@ -401,7 +401,7 @@ vector<COutput> CActiveMasternode::SelectCoinsMasternode()
BOOST_FOREACH(const COutput& out, vCoins)
{
if(out.tx->vout[out.i].nValue == 1000*COIN) { //exactly
filteredCoins.push_back(out);
filteredCoins.push_back(out);
}
}
return filteredCoins;
Expand Down

0 comments on commit 30796a8

Please sign in to comment.