Skip to content

Commit b7cd8a1

Browse files
committed
Allow configuration of reward address.
Allow setting a non-default reward script for masternodes, by editing the masternode.conf file explicitly. The RPC setupmasternode will not generate such configuration lines for now, and also "old" masternode.conf files will remain valid (with the default script).
1 parent c2505ed commit b7cd8a1

File tree

8 files changed

+59
-12
lines changed

8 files changed

+59
-12
lines changed

divi/src/MasternodeBroadcastFactory.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <wallet.h>
99
#include <chain.h>
1010
#include <base58address.h>
11+
#include <script/standard.h>
1112
#include <TransactionDiskAccessor.h>
1213
#include <timedata.h>
1314
#include <WalletTx.h>
@@ -105,6 +106,7 @@ bool createArgumentsFromConfig(
105106
bool collateralPrivKeyIsRemote,
106107
CTxIn& txin,
107108
std::pair<CKey,CPubKey>& masternodeKeyPair,
109+
CScript& rewardScript,
108110
std::pair<CKey,CPubKey>& masternodeCollateralKeyPair,
109111
MasternodeTier& nMasternodeTier
110112
)
@@ -121,6 +123,18 @@ bool createArgumentsFromConfig(
121123
{
122124
return false;
123125
}
126+
127+
if (configEntry.getRewardAddress().empty())
128+
rewardScript = CMasternode::GetDefaultRewardScript(masternodeCollateralKeyPair.second);
129+
else {
130+
const CBitcoinAddress addr(configEntry.getRewardAddress());
131+
if (!addr.IsValid()) {
132+
strErrorRet = strprintf("Invalid reward address for masternode: %s", configEntry.getRewardAddress());
133+
return false;
134+
}
135+
rewardScript = GetScriptForDestination(addr.Get());
136+
}
137+
124138
return true;
125139
}
126140

@@ -137,6 +151,7 @@ bool CMasternodeBroadcastFactory::Create(
137151
const bool deferRelay = true;
138152
CTxIn txin;
139153
std::pair<CKey,CPubKey> masternodeCollateralKeyPair;
154+
CScript rewardScript;
140155
std::pair<CKey,CPubKey> masternodeKeyPair;
141156
MasternodeTier nMasternodeTier;
142157

@@ -147,6 +162,7 @@ bool CMasternodeBroadcastFactory::Create(
147162
collateralPrivateKeyIsRemote,
148163
txin,
149164
masternodeKeyPair,
165+
rewardScript,
150166
masternodeCollateralKeyPair,
151167
nMasternodeTier))
152168
{
@@ -157,6 +173,7 @@ bool CMasternodeBroadcastFactory::Create(
157173
txin,
158174
CService(configEntry.getIp()),
159175
pubkeyCollateralAddress,
176+
rewardScript,
160177
masternodeKeyPair.second,
161178
nMasternodeTier,
162179
deferRelay,
@@ -185,6 +202,7 @@ bool CMasternodeBroadcastFactory::Create(
185202

186203
CTxIn txin;
187204
std::pair<CKey,CPubKey> masternodeCollateralKeyPair;
205+
CScript rewardScript;
188206
std::pair<CKey,CPubKey> masternodeKeyPair;
189207
MasternodeTier nMasternodeTier;
190208

@@ -195,6 +213,7 @@ bool CMasternodeBroadcastFactory::Create(
195213
collateralPrivateKeyIsRemote,
196214
txin,
197215
masternodeKeyPair,
216+
rewardScript,
198217
masternodeCollateralKeyPair,
199218
nMasternodeTier))
200219
{
@@ -205,6 +224,7 @@ bool CMasternodeBroadcastFactory::Create(
205224
CService(strService),
206225
masternodeCollateralKeyPair.first,
207226
masternodeCollateralKeyPair.second,
227+
rewardScript,
208228
masternodeKeyPair.first,
209229
masternodeKeyPair.second,
210230
nMasternodeTier,
@@ -286,6 +306,7 @@ void CMasternodeBroadcastFactory::createWithoutSignatures(
286306
const CTxIn& txin,
287307
const CService& service,
288308
const CPubKey& pubKeyCollateralAddressNew,
309+
const CScript& rewardScript,
289310
const CPubKey& pubKeyMasternodeNew,
290311
const MasternodeTier nMasternodeTier,
291312
bool deferRelay,
@@ -295,7 +316,9 @@ void CMasternodeBroadcastFactory::createWithoutSignatures(
295316
CBitcoinAddress(pubKeyCollateralAddressNew.GetID()).ToString(),
296317
pubKeyMasternodeNew.GetID().ToString());
297318

298-
mnbRet = CMasternodeBroadcast(service, txin, pubKeyCollateralAddressNew, pubKeyMasternodeNew, nMasternodeTier, PROTOCOL_VERSION);
319+
mnbRet = CMasternodeBroadcast(service, txin,
320+
pubKeyCollateralAddressNew, rewardScript, pubKeyMasternodeNew,
321+
nMasternodeTier, PROTOCOL_VERSION);
299322
const CMasternodePing mnp = (deferRelay
300323
? createDelayedMasternodePing(mnbRet)
301324
: createCurrentPing(txin));
@@ -308,6 +331,7 @@ bool CMasternodeBroadcastFactory::Create(
308331
const CService& service,
309332
const CKey& keyCollateralAddressNew,
310333
const CPubKey& pubKeyCollateralAddressNew,
334+
const CScript& rewardScript,
311335
const CKey& keyMasternodeNew,
312336
const CPubKey& pubKeyMasternodeNew,
313337
const MasternodeTier nMasternodeTier,
@@ -319,7 +343,7 @@ bool CMasternodeBroadcastFactory::Create(
319343
if (fImporting || fReindex) return false;
320344

321345
createWithoutSignatures(
322-
txin,service,pubKeyCollateralAddressNew,pubKeyMasternodeNew,nMasternodeTier,deferRelay,mnbRet);
346+
txin,service,pubKeyCollateralAddressNew,rewardScript,pubKeyMasternodeNew,nMasternodeTier,deferRelay,mnbRet);
323347

324348
if(!provideSignatures(keyMasternodeNew,pubKeyMasternodeNew,keyCollateralAddressNew,mnbRet,strErrorRet))
325349
{

divi/src/MasternodeBroadcastFactory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class CMasternodeBroadcastFactory
4040
const CTxIn& txin,
4141
const CService& service,
4242
const CPubKey& pubKeyCollateralAddressNew,
43+
const CScript& rewardScript,
4344
const CPubKey& pubKeyMasternodeNew,
4445
MasternodeTier nMasternodeTier,
4546
bool deferRelay,
@@ -61,6 +62,7 @@ class CMasternodeBroadcastFactory
6162
const CService& service,
6263
const CKey& keyCollateralAddressNew,
6364
const CPubKey& pubKeyCollateralAddressNew,
65+
const CScript& rewardScript,
6466
const CKey& keyMasternodeNew,
6567
const CPubKey& pubKeyMasternodeNew,
6668
MasternodeTier nMasternodeTier,

divi/src/masternode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,13 @@ bool CMasternode::IsValidNetAddr() const
273273

274274
CMasternodeBroadcast::CMasternodeBroadcast(
275275
const CService& newAddr, const CTxIn& newVin,
276-
const CPubKey& pubKeyCollateralAddressNew, const CPubKey& pubKeyMasternodeNew,
276+
const CPubKey& pubKeyCollateralAddressNew, const CScript& rewardScriptIn, const CPubKey& pubKeyMasternodeNew,
277277
const MasternodeTier nMasternodeTier, const int protocolVersionIn)
278278
{
279279
vin = newVin;
280280
addr = newAddr;
281281
pubKeyCollateralAddress = pubKeyCollateralAddressNew;
282-
rewardScript = GetDefaultRewardScript();
282+
rewardScript = rewardScriptIn;
283283
pubKeyMasternode = pubKeyMasternodeNew;
284284
protocolVersion = protocolVersionIn;
285285
nTier = nMasternodeTier;

divi/src/masternode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class CMasternodeBroadcast : public CMasternode
162162
const CService& newAddr,
163163
const CTxIn& newVin,
164164
const CPubKey& pubKeyCollateralAddress,
165+
const CScript& rewardScriptIn,
165166
const CPubKey& pubKeyMasternode,
166167
MasternodeTier nMasternodeTier,
167168
int protocolVersionIn);

divi/src/masternodeconfig.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ boost::filesystem::path GetMasternodeConfigFile()
2525
}
2626

2727
void CMasternodeConfig::add(const std::string& alias, const std::string& ip, const std::string& privKey,
28-
const std::string& txHash, const std::string& outputIndex)
28+
const std::string& txHash, const std::string& outputIndex,
29+
const std::string& rewardAddr)
2930
{
30-
entries.emplace_back(alias, ip, privKey, txHash, outputIndex);
31+
entries.emplace_back(alias, ip, privKey, txHash, outputIndex, rewardAddr);
3132
}
3233

3334
bool CMasternodeConfig::read(std::string& strErr)
@@ -71,7 +72,12 @@ bool CMasternodeConfig::read(std::string& strErr)
7172
}
7273
}
7374

74-
add(alias, ip, privKey, txHash, outputIndex);
75+
/* This might fail if there is no address, but that is fine and we will
76+
just leave the string empty in that case. */
77+
std::string rewardAddr;
78+
iss >> rewardAddr;
79+
80+
add(alias, ip, privKey, txHash, outputIndex, rewardAddr);
7581
}
7682

7783
streamConfig.close();

divi/src/masternodeconfig.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ class CMasternodeConfig
2323
std::string privKey;
2424
std::string txHash;
2525
std::string outputIndex;
26+
std::string rewardAddress;
2627

2728
public:
2829
CMasternodeEntry(const std::string& alias, const std::string& ip,
2930
const std::string& privKey,
30-
const std::string& txHash, const std::string& outputIndex)
31+
const std::string& txHash, const std::string& outputIndex,
32+
const std::string& rewardAddress)
3133
{
3234
this->alias = alias;
3335
this->ip = ip;
3436
this->privKey = privKey;
3537
this->txHash = txHash;
3638
this->outputIndex = outputIndex;
39+
this->rewardAddress = rewardAddress;
3740
}
3841

3942
const std::string& getAlias() const
@@ -87,14 +90,25 @@ class CMasternodeConfig
8790
{
8891
this->ip = ip;
8992
}
93+
94+
const std::string& getRewardAddress() const
95+
{
96+
return rewardAddress;
97+
}
98+
99+
void setRewardAddress(const std::string& addr)
100+
{
101+
this->rewardAddress = addr;
102+
}
90103
};
91104

92105
CMasternodeConfig();
93106

94107
void clear();
95108
bool read(std::string& strErr);
96109
void add(const std::string& alias, const std::string& ip, const std::string& privKey,
97-
const std::string& txHash, const std::string& outputIndex);
110+
const std::string& txHash, const std::string& outputIndex,
111+
const std::string& rewardAddr);
98112
const std::vector<CMasternodeEntry>& getEntries() const;
99113
int getCount() const;
100114

divi/src/rpcmasternode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ Value setupmasternode(const Array& params, bool fHelp)
266266
if (ipAndPort.find(':') == std::string::npos)
267267
ipAndPort += ":" + std::to_string(Params().GetDefaultPort());
268268

269-
CMasternodeConfig::CMasternodeEntry config(alias,ipAndPort,CBitcoinSecret(masternodeKey).ToString(),txHash,outputIndex);
269+
CMasternodeConfig::CMasternodeEntry config(alias,ipAndPort,CBitcoinSecret(masternodeKey).ToString(),txHash,outputIndex, "");
270270

271271
CMasternodeBroadcast mnb;
272272
std::string errorMsg;

divi/src/test/ActiveMasternode_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ActiveMasternodeTestFixture
2525

2626
void AddDummyConfiguration(CTxIn txIn, CService service)
2727
{
28-
configurations_->add("dummy configuration", service.ToString(), "", txIn.prevout.hash.ToString(), std::to_string(txIn.prevout.n));
28+
configurations_->add("dummy configuration", service.ToString(), "", txIn.prevout.hash.ToString(), std::to_string(txIn.prevout.n), "");
2929
}
3030
};
3131

@@ -98,4 +98,4 @@ BOOST_AUTO_TEST_CASE(willSetMatchingPubkeyForPrivateKey)
9898
BOOST_CHECK(activeMasternode_->pubKeyMasternode == expectedPubkey);
9999
}
100100

101-
BOOST_AUTO_TEST_SUITE_END()
101+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)