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,11 +23,32 @@ bool CMasternodeConfig::read(std::string& strErr) {
continue;
}
std::istringstream iss(line);
std::string alias, ip, privKey, txHash, outputIndex;
if (!(iss >> alias >> ip >> privKey >> txHash >> outputIndex)) {
strErr = "Could not parse masternode.conf line: " + line;
streamConfig.close();
return false;
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){
@ -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,94 +19,95 @@ class CMasternodeConfig
{
public:
class CMasternodeEntry {
private:
std::string alias;
std::string ip;
std::string privKey;
std::string txHash;
std::string outputIndex;
std::string donationAddress;
std::string donationPercentage;
class CMasternodeEntry {
public:
private:
std::string alias;
std::string ip;
std::string privKey;
std::string txHash;
std::string outputIndex;
std::string donationAddress;
std::string donationPercent;
public:
CMasternodeEntry(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex) {
this->alias = alias;
this->ip = ip;
this->privKey = privKey;
this->txHash = txHash;
this->outputIndex = 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 {
return alias;
}
const std::string& getAlias() const {
return alias;
}
void setAlias(const std::string& alias) {
this->alias = alias;
}
void setAlias(const std::string& alias) {
this->alias = alias;
}
const std::string& getOutputIndex() const {
return outputIndex;
}
const std::string& getOutputIndex() const {
return outputIndex;
}
const std::string& getDonationAddress() const {
return donationAddress;
}
void setOutputIndex(const std::string& outputIndex) {
this->outputIndex = outputIndex;
}
const std::string& getDonationPercentage() const {
return donationPercentage;
}
const std::string& getPrivKey() const {
return privKey;
}
void setOutputIndex(const std::string& outputIndex) {
this->outputIndex = outputIndex;
}
void setPrivKey(const std::string& privKey) {
this->privKey = privKey;
}
const std::string& getPrivKey() const {
return privKey;
}
const std::string& getTxHash() const {
return txHash;
}
void setPrivKey(const std::string& privKey) {
this->privKey = privKey;
}
void setTxHash(const std::string& txHash) {
this->txHash = txHash;
}
const std::string& getTxHash() const {
return txHash;
}
const std::string& getIp() const {
return ip;
}
void setTxHash(const std::string& txHash) {
this->txHash = txHash;
}
void setIp(const std::string& ip) {
this->ip = ip;
}
const std::string& getIp() const {
return ip;
}
const std::string& getDonationAddress() const {
return donationAddress;
}
void setIp(const std::string& ip) {
this->ip = ip;
}
};
const std::string& getDonationPercentage() const {
return donationPercent;
}
};
CMasternodeConfig() {
entries = std::vector<CMasternodeEntry>();
}
CMasternodeConfig() {
entries = std::vector<CMasternodeEntry>();
}
void clear();
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;
}
std::vector<CMasternodeEntry>& getEntries() {
return entries;
}
private:
std::vector<CMasternodeEntry> entries;
std::vector<CMasternodeEntry> entries;
};
#endif /* SRC_MASTERNODECONFIG_H_ */

View File

@ -535,16 +535,18 @@ Value masternode(const Array& params, bool fHelp)
Object resultObj;
BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries()) {
Object mnObj;
mnObj.push_back(Pair("alias", mne.getAlias()));
mnObj.push_back(Pair("address", mne.getIp()));
mnObj.push_back(Pair("privateKey", mne.getPrivKey()));
mnObj.push_back(Pair("txHash", mne.getTxHash()));
mnObj.push_back(Pair("outputIndex", mne.getOutputIndex()));
resultObj.push_back(Pair("masternode", mnObj));
}
Object mnObj;
mnObj.push_back(Pair("alias", mne.getAlias()));
mnObj.push_back(Pair("address", mne.getIp()));
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));
}
return resultObj;
return resultObj;
}
if (strCommand == "outputs"){