Line data Source code
1 : // Copyright (c) 2014-2015 The Dash developers 2 : // Copyright (c) 2015-2020 The PIVX Core developers 3 : // Distributed under the MIT software license, see the accompanying 4 : // file COPYING or https://www.opensource.org/licenses/mit-license.php. 5 : 6 : #ifndef PIVX_MASTERNODECONFIG_H 7 : #define PIVX_MASTERNODECONFIG_H 8 : 9 : #include "sync.h" 10 : #include <string> 11 : #include <vector> 12 : 13 : class CMasternodeConfig; 14 : extern CMasternodeConfig masternodeConfig; 15 : 16 : class CMasternodeConfig 17 : { 18 : public: 19 : class CMasternodeEntry 20 : { 21 : private: 22 : std::string alias; 23 : std::string ip; 24 : std::string privKey; 25 : std::string txHash; 26 : std::string outputIndex; 27 : 28 : public: 29 20 : CMasternodeEntry(std::string& _alias, std::string& _ip, std::string& _privKey, std::string& _txHash, std::string& _outputIndex) : 30 100 : alias(_alias), ip(_ip), privKey(_privKey), txHash(_txHash), outputIndex(_outputIndex) { } 31 : 32 50 : const std::string& getAlias() const { return alias; } 33 2 : const std::string& getOutputIndex() const { return outputIndex; } 34 : bool castOutputIndex(int& n) const; 35 10 : const std::string& getPrivKey() const { return privKey; } 36 16 : const std::string& getTxHash() const { return txHash; } 37 14 : const std::string& getIp() const { return ip; } 38 : }; 39 : 40 479 : CMasternodeConfig() { entries = std::vector<CMasternodeEntry>(); } 41 : 42 18 : void clear() { LOCK(cs_entries); entries.clear(); } 43 : bool read(std::string& strErr); 44 : CMasternodeConfig::CMasternodeEntry* add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex); 45 : void remove(std::string alias); 46 : 47 730 : std::vector<CMasternodeEntry> getEntries() { LOCK(cs_entries); return entries; } 48 : 49 355 : int getCount() 50 : { 51 355 : LOCK(cs_entries); 52 355 : int c = -1; 53 356 : for (const auto& e : entries) { 54 1 : if (!e.getAlias().empty()) c++; 55 : } 56 355 : return c; 57 : } 58 : 59 : private: 60 : std::vector<CMasternodeEntry> entries; 61 : Mutex cs_entries; 62 : }; 63 : 64 : 65 : #endif // PIVX_MASTERNODECONFIG_H