Skip to content

Commit 77d17ee

Browse files
domob1812galpHub
authored andcommitted
Clean up some mn config code.
This is a bunch of related and straight-forward cleanups to the code around masternode configuration: Pass arguments as const& instead of by value, mark functions as const, and move helper functions from being static in a class and declared inside the header to just being inside an anonymous namespace in the cpp file.
1 parent 29b2ca7 commit 77d17ee

File tree

7 files changed

+63
-76
lines changed

7 files changed

+63
-76
lines changed

divi/src/MasternodeBroadcastFactory.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ extern CChain chainActive;
1717
extern bool fReindex;
1818
extern bool fImporting;
1919

20-
bool CMasternodeBroadcastFactory::checkBlockchainSync(std::string& strErrorRet, bool fOffline)
20+
namespace
21+
{
22+
23+
bool checkBlockchainSync(std::string& strErrorRet, bool fOffline)
2124
{
2225
if (!fOffline && !IsBlockchainSynced()) {
2326
strErrorRet = "Sync in progress. Must wait until sync is complete to start Masternode";
@@ -26,7 +29,7 @@ bool CMasternodeBroadcastFactory::checkBlockchainSync(std::string& strErrorRet,
2629
}
2730
return true;
2831
}
29-
bool CMasternodeBroadcastFactory::setMasternodeKeys(
32+
bool setMasternodeKeys(
3033
const std::string& strKeyMasternode,
3134
std::pair<CKey,CPubKey>& masternodeKeyPair,
3235
std::string& strErrorRet)
@@ -38,7 +41,7 @@ bool CMasternodeBroadcastFactory::setMasternodeKeys(
3841
}
3942
return true;
4043
}
41-
bool CMasternodeBroadcastFactory::setMasternodeCollateralKeys(
44+
bool setMasternodeCollateralKeys(
4245
const std::string& txHash,
4346
const std::string& outputIndex,
4447
const std::string& service,
@@ -63,7 +66,7 @@ bool CMasternodeBroadcastFactory::setMasternodeCollateralKeys(
6366
return true;
6467
}
6568

66-
bool CMasternodeBroadcastFactory::checkMasternodeCollateral(
69+
bool checkMasternodeCollateral(
6770
const CTxIn& txin,
6871
const std::string& txHash,
6972
const std::string& outputIndex,
@@ -95,7 +98,7 @@ bool CMasternodeBroadcastFactory::checkMasternodeCollateral(
9598
return true;
9699
}
97100

98-
bool CMasternodeBroadcastFactory::createArgumentsFromConfig(
101+
bool createArgumentsFromConfig(
99102
const CMasternodeConfig::CMasternodeEntry configEntry,
100103
std::string& strErrorRet,
101104
bool fOffline,
@@ -121,6 +124,8 @@ bool CMasternodeBroadcastFactory::createArgumentsFromConfig(
121124
return true;
122125
}
123126

127+
} // anonymous namespace
128+
124129
bool CMasternodeBroadcastFactory::Create(
125130
const CMasternodeConfig::CMasternodeEntry configEntry,
126131
CPubKey pubkeyCollateralAddress,
@@ -278,10 +283,10 @@ CMasternodePing createDelayedMasternodePing(const CMasternodeBroadcast& mnb)
278283
} // anonymous namespace
279284

280285
void CMasternodeBroadcastFactory::createWithoutSignatures(
281-
CTxIn txin,
282-
CService service,
283-
CPubKey pubKeyCollateralAddressNew,
284-
CPubKey pubKeyMasternodeNew,
286+
const CTxIn& txin,
287+
const CService& service,
288+
const CPubKey& pubKeyCollateralAddressNew,
289+
const CPubKey& pubKeyMasternodeNew,
285290
const MasternodeTier nMasternodeTier,
286291
bool deferRelay,
287292
CMasternodeBroadcast& mnbRet)
@@ -299,12 +304,12 @@ void CMasternodeBroadcastFactory::createWithoutSignatures(
299304
}
300305

301306
bool CMasternodeBroadcastFactory::Create(
302-
CTxIn txin,
303-
CService service,
304-
CKey keyCollateralAddressNew,
305-
CPubKey pubKeyCollateralAddressNew,
306-
CKey keyMasternodeNew,
307-
CPubKey pubKeyMasternodeNew,
307+
const CTxIn& txin,
308+
const CService& service,
309+
const CKey& keyCollateralAddressNew,
310+
const CPubKey& pubKeyCollateralAddressNew,
311+
const CKey& keyMasternodeNew,
312+
const CPubKey& pubKeyMasternodeNew,
308313
const MasternodeTier nMasternodeTier,
309314
std::string& strErrorRet,
310315
CMasternodeBroadcast& mnbRet,

divi/src/MasternodeBroadcastFactory.h

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class CMasternodeBroadcastFactory
3737
std::string& strErrorRet);
3838
private:
3939
static void createWithoutSignatures(
40-
CTxIn txin,
41-
CService service,
42-
CPubKey pubKeyCollateralAddressNew,
43-
CPubKey pubKeyMasternodeNew,
40+
const CTxIn& txin,
41+
const CService& service,
42+
const CPubKey& pubKeyCollateralAddressNew,
43+
const CPubKey& pubKeyMasternodeNew,
4444
MasternodeTier nMasternodeTier,
4545
bool deferRelay,
4646
CMasternodeBroadcast& mnbRet);
@@ -57,45 +57,15 @@ class CMasternodeBroadcastFactory
5757
CMasternodeBroadcast& mnb,
5858
std::string& strErrorRet);
5959

60-
static bool Create(CTxIn vin,
61-
CService service,
62-
CKey keyCollateralAddressNew,
63-
CPubKey pubKeyCollateralAddressNew,
64-
CKey keyMasternodeNew,
65-
CPubKey pubKeyMasternodeNew,
66-
MasternodeTier nMasternodeTier,
67-
std::string& strErrorRet,
68-
CMasternodeBroadcast& mnbRet,
69-
bool deferRelay);
70-
static bool checkBlockchainSync(
71-
std::string& strErrorRet, bool fOffline);
72-
static bool setMasternodeKeys(
73-
const std::string& strKeyMasternode,
74-
std::pair<CKey,CPubKey>& masternodeKeyPair,
75-
std::string& strErrorRet);
76-
static bool setMasternodeCollateralKeys(
77-
const std::string& txHash,
78-
const std::string& outputIndex,
79-
const std::string& service,
80-
bool collateralPrivKeyIsRemote,
81-
CTxIn& txin,
82-
std::pair<CKey,CPubKey>& masternodeCollateralKeyPair,
83-
std::string& error);
84-
static bool checkMasternodeCollateral(
85-
const CTxIn& txin,
86-
const std::string& txHash,
87-
const std::string& outputIndex,
88-
const std::string& service,
89-
MasternodeTier& nMasternodeTier,
90-
std::string& strErrorRet);
91-
static bool createArgumentsFromConfig(
92-
const CMasternodeConfig::CMasternodeEntry configEntry,
93-
std::string& strErrorRet,
94-
bool fOffline,
95-
bool collateralPrivKeyIsRemote,
96-
CTxIn& txin,
97-
std::pair<CKey,CPubKey>& masternodeKeyPair,
98-
std::pair<CKey,CPubKey>& masternodeCollateralKeyPair,
99-
MasternodeTier& nMasternodeTier);
60+
static bool Create(const CTxIn& vin,
61+
const CService& service,
62+
const CKey& keyCollateralAddressNew,
63+
const CPubKey& pubKeyCollateralAddressNew,
64+
const CKey& keyMasternodeNew,
65+
const CPubKey& pubKeyMasternodeNew,
66+
MasternodeTier nMasternodeTier,
67+
std::string& strErrorRet,
68+
CMasternodeBroadcast& mnbRet,
69+
bool deferRelay);
10070
};
101-
#endif //MASTERNODE_BROADCAST_FACTORY_H
71+
#endif //MASTERNODE_BROADCAST_FACTORY_H

divi/src/masternode-sync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class CMasternodeSync
8585
bool MasternodeWinnersListIsSync(CNode* pnode, const int64_t now);
8686
void Process(bool networkIsRegtest);
8787
bool IsSynced() const;
88-
bool IsMasternodeListSynced() { return RequestedMasternodeAssets > MASTERNODE_SYNC_LIST; }
88+
bool IsMasternodeListSynced() const { return RequestedMasternodeAssets > MASTERNODE_SYNC_LIST; }
8989
void AskForMN(CNode* pnode, const CTxIn& vin) const;
9090
};
9191

divi/src/masternode.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,10 @@ bool CMasternode::IsValidNetAddr() const
258258
(IsReachable(addr) && addr.IsRoutable());
259259
}
260260

261-
CMasternodeBroadcast::CMasternodeBroadcast(CService newAddr, CTxIn newVin, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, const MasternodeTier nMasternodeTier, int protocolVersionIn)
261+
CMasternodeBroadcast::CMasternodeBroadcast(
262+
const CService& newAddr, const CTxIn& newVin,
263+
const CPubKey& pubKeyCollateralAddressNew, const CPubKey& pubKeyMasternodeNew,
264+
const MasternodeTier nMasternodeTier, const int protocolVersionIn)
262265
{
263266
vin = newVin;
264267
addr = newAddr;

divi/src/masternode.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,19 @@ class CMasternode
146146

147147
class CMasternodeBroadcast : public CMasternode
148148
{
149-
public:
150-
CMasternodeBroadcast() = default;
149+
private:
151150
CMasternodeBroadcast(
152-
CService newAddr,
153-
CTxIn newVin,
154-
CPubKey pubKeyCollateralAddress,
155-
CPubKey pubKeyMasternode,
151+
const CService& newAddr,
152+
const CTxIn& newVin,
153+
const CPubKey& pubKeyCollateralAddress,
154+
const CPubKey& pubKeyMasternode,
156155
MasternodeTier nMasternodeTier,
157156
int protocolVersionIn);
157+
158+
friend class CMasternodeBroadcastFactory;
159+
160+
public:
161+
CMasternodeBroadcast() = default;
158162
CMasternodeBroadcast(const CMasternode& mn);
159163

160164
void Relay() const;

divi/src/masternodeconfig.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ boost::filesystem::path GetMasternodeConfigFile()
2323
if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir() / pathConfigFile;
2424
return pathConfigFile;
2525
}
26-
void CMasternodeConfig::add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex)
26+
27+
void CMasternodeConfig::add(const std::string& alias, const std::string& ip, const std::string& privKey,
28+
const std::string& txHash, const std::string& outputIndex)
2729
{
28-
CMasternodeEntry cme(alias, ip, privKey, txHash, outputIndex);
29-
entries.push_back(cme);
30+
entries.emplace_back(alias, ip, privKey, txHash, outputIndex);
3031
}
3132

3233
bool CMasternodeConfig::read(std::string& strErr)
@@ -94,15 +95,16 @@ CMasternodeConfig::CMasternodeConfig()
9495
{
9596
entries = std::vector<CMasternodeEntry>();
9697
}
98+
9799
const std::vector<CMasternodeConfig::CMasternodeEntry>& CMasternodeConfig::getEntries() const
98100
{
99101
return entries;
100102
}
101103

102-
int CMasternodeConfig::getCount()
104+
int CMasternodeConfig::getCount() const
103105
{
104106
int c = -1;
105-
BOOST_FOREACH (CMasternodeEntry e, entries) {
107+
for (const auto& e : entries) {
106108
if (e.getAlias() != "") c++;
107109
}
108110
return c;

divi/src/masternodeconfig.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class CMasternodeConfig
2525
std::string outputIndex;
2626

2727
public:
28-
CMasternodeEntry(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex)
28+
CMasternodeEntry(const std::string& alias, const std::string& ip,
29+
const std::string& privKey,
30+
const std::string& txHash, const std::string& outputIndex)
2931
{
3032
this->alias = alias;
3133
this->ip = ip;
@@ -91,9 +93,10 @@ class CMasternodeConfig
9193

9294
void clear();
9395
bool read(std::string& strErr);
94-
void add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex);
96+
void add(const std::string& alias, const std::string& ip, const std::string& privKey,
97+
const std::string& txHash, const std::string& outputIndex);
9598
const std::vector<CMasternodeEntry>& getEntries() const;
96-
int getCount();
99+
int getCount() const;
97100

98101
private:
99102
std::vector<CMasternodeEntry> entries;

0 commit comments

Comments
 (0)