Skip to content

Commit

Permalink
Merge pull request #246 from UdjinM6/11.2-mn-donations
Browse files Browse the repository at this point in the history
v0.11.2.x mn-donations
  • Loading branch information
evan82 committed Mar 16, 2015
2 parents 8cd7f8e + 19bb993 commit 7574026
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 100 deletions.
38 changes: 30 additions & 8 deletions src/masternodeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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){
Expand All @@ -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();
Expand Down
167 changes: 84 additions & 83 deletions src/masternodeconfig.h
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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;

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;
}

const std::string& getAlias() const {
return alias;
}

void setAlias(const std::string& alias) {
this->alias = alias;
}

const std::string& getOutputIndex() const {
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;
}

const std::string& getPrivKey() const {
return privKey;
}

void setPrivKey(const std::string& privKey) {
this->privKey = privKey;
}

const std::string& getTxHash() const {
return txHash;
}

void setTxHash(const std::string& txHash) {
this->txHash = txHash;
}

const std::string& getIp() const {
return ip;
}

void setIp(const std::string& ip) {
this->ip = ip;
}
};

CMasternodeConfig() {
entries = std::vector<CMasternodeEntry>();
}

void clear();

class CMasternodeEntry {

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, 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;
}

void setAlias(const std::string& alias) {
this->alias = alias;
}

const std::string& getOutputIndex() const {
return outputIndex;
}

void setOutputIndex(const std::string& outputIndex) {
this->outputIndex = outputIndex;
}

const std::string& getPrivKey() const {
return privKey;
}

void setPrivKey(const std::string& privKey) {
this->privKey = privKey;
}

const std::string& getTxHash() const {
return txHash;
}

void setTxHash(const std::string& txHash) {
this->txHash = txHash;
}

const std::string& getIp() const {
return ip;
}

void setIp(const std::string& ip) {
this->ip = ip;
}

const std::string& getDonationAddress() const {
return donationAddress;
}

const std::string& getDonationPercentage() const {
return donationPercent;
}
};

CMasternodeConfig() {
entries = std::vector<CMasternodeEntry>();
}

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_ */

20 changes: 11 additions & 9 deletions src/rpcdarksend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"){
Expand Down

0 comments on commit 7574026

Please sign in to comment.