Merge pull request #246 from UdjinM6/11.2-mn-donations

v0.11.2.x mn-donations
This commit is contained in:
evan82 2015-03-16 12:57:23 -07:00
commit 7574026fb2
3 changed files with 108 additions and 83 deletions

View File

@ -2,11 +2,12 @@
#include "net.h"
#include "masternodeconfig.h"
#include "util.h"
#include <base58.h>
CMasternodeConfig masternodeConfig;
void CMasternodeConfig::add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex) {
CMasternodeEntry cme(alias, ip, privKey, txHash, outputIndex);
void CMasternodeConfig::add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex, std::string donationAddress, std::string donationPercent) {
CMasternodeEntry cme(alias, ip, privKey, txHash, outputIndex, donationAddress, donationPercent);
entries.push_back(cme);
}
@ -22,12 +23,33 @@ bool CMasternodeConfig::read(std::string& strErr) {
continue;
}
std::istringstream iss(line);
std::string alias, ip, privKey, txHash, outputIndex;
std::string alias, ip, privKey, txHash, outputIndex, donation, donationAddress, donationPercent;
if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex >> donation)) {
donationAddress = "";
donationPercent = "";
iss.str(line);
iss.clear();
if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) {
strErr = "Could not parse masternode.conf line: " + line;
streamConfig.close();
return false;
}
} else {
size_t pos = donation.find_first_of(":");
if(pos == string::npos) { // no ":" found
donationPercent = "100";
donationAddress = donation;
} else {
donationPercent = donation.substr(pos + 1);
donationAddress = donation.substr(0, pos);
}
CBitcoinAddress address(donationAddress);
if (!address.IsValid()) {
strErr = "Invalid Darkcoin address in masternode.conf line: " + line;
streamConfig.close();
return false;
}
}
if(Params().NetworkID() == CChainParams::MAIN){
if(CService(ip).GetPort() != 9999) {
@ -42,7 +64,7 @@ bool CMasternodeConfig::read(std::string& strErr) {
}
add(alias, ip, privKey, txHash, outputIndex);
add(alias, ip, privKey, txHash, outputIndex, donationAddress, donationPercent);
}
streamConfig.close();

View File

@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Copyright (c) 2014-2015 The Darkcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -19,6 +19,7 @@ class CMasternodeConfig
{
public:
class CMasternodeEntry {
private:
@ -28,16 +29,17 @@ public:
std::string txHash;
std::string outputIndex;
std::string donationAddress;
std::string donationPercentage;
std::string donationPercent;
public:
CMasternodeEntry(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex) {
CMasternodeEntry(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex, std::string donationAddress, std::string donationPercent) {
this->alias = alias;
this->ip = ip;
this->privKey = privKey;
this->txHash = txHash;
this->outputIndex = outputIndex;
this->donationAddress = donationAddress;
this->donationPercent = donationPercent;
}
const std::string& getAlias() const {
@ -52,14 +54,6 @@ public:
return outputIndex;
}
const std::string& getDonationAddress() const {
return donationAddress;
}
const std::string& getDonationPercentage() const {
return donationPercentage;
}
void setOutputIndex(const std::string& outputIndex) {
this->outputIndex = outputIndex;
}
@ -87,6 +81,14 @@ public:
void setIp(const std::string& ip) {
this->ip = ip;
}
const std::string& getDonationAddress() const {
return donationAddress;
}
const std::string& getDonationPercentage() const {
return donationPercent;
}
};
CMasternodeConfig() {
@ -95,7 +97,7 @@ public:
void clear();
bool read(std::string& strErr);
void add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex);
void add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex, std::string donationAddress, std::string donationPercent);
std::vector<CMasternodeEntry>& getEntries() {
return entries;
@ -109,4 +111,3 @@ private:
#endif /* SRC_MASTERNODECONFIG_H_ */

View File

@ -541,6 +541,8 @@ Value masternode(const Array& params, bool fHelp)
mnObj.push_back(Pair("privateKey", mne.getPrivKey()));
mnObj.push_back(Pair("txHash", mne.getTxHash()));
mnObj.push_back(Pair("outputIndex", mne.getOutputIndex()));
mnObj.push_back(Pair("donationAddress", mne.getDonationAddress()));
mnObj.push_back(Pair("donationPercent", mne.getDonationPercentage()));
resultObj.push_back(Pair("masternode", mnObj));
}