Skip to content

Commit 12dac06

Browse files
committed
WIP: configure address with setupmasternode
1 parent d87559a commit 12dac06

File tree

5 files changed

+25
-39
lines changed

5 files changed

+25
-39
lines changed

divi/src/MasternodeBroadcastFactory.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,10 @@ bool createArgumentsFromConfig(
9494
return false;
9595
}
9696

97-
if (configEntry.getRewardAddress().empty())
98-
rewardScript = CMasternode::GetDefaultRewardScript(pubkeyCollateralAddress);
99-
else {
100-
const CBitcoinAddress addr(configEntry.getRewardAddress());
101-
if (!addr.IsValid()) {
102-
strErrorRet = strprintf("Invalid reward address for masternode: %s", configEntry.getRewardAddress());
103-
return false;
104-
}
105-
rewardScript = GetScriptForDestination(addr.Get());
106-
}
97+
/* If a custom reward address should be used, this is overridden by
98+
setupmasternode directly after creating the entry (not loaded through
99+
the config file). */
100+
rewardScript = CMasternode::GetDefaultRewardScript(pubkeyCollateralAddress);
107101

108102
return true;
109103
}

divi/src/masternodeconfig.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ boost::filesystem::path GetMasternodeConfigFile(const Settings& settings)
4141
} // anonymous namespace
4242

4343
void CMasternodeConfig::add(const std::string& alias, const std::string& ip, const std::string& privKey,
44-
const std::string& txHash, const std::string& outputIndex,
45-
const std::string& rewardAddr)
44+
const std::string& txHash, const std::string& outputIndex)
4645
{
47-
entries.emplace_back(alias, ip, privKey, txHash, outputIndex, rewardAddr);
46+
entries.emplace_back(alias, ip, privKey, txHash, outputIndex);
4847
}
4948

5049
bool CMasternodeConfig::read(const Settings& settings, std::string& strErr)
@@ -88,12 +87,7 @@ bool CMasternodeConfig::read(const Settings& settings, std::string& strErr)
8887
}
8988
}
9089

91-
/* This might fail if there is no address, but that is fine and we will
92-
just leave the string empty in that case. */
93-
std::string rewardAddr;
94-
iss >> rewardAddr;
95-
96-
add(alias, ip, privKey, txHash, outputIndex, rewardAddr);
90+
add(alias, ip, privKey, txHash, outputIndex);
9791
}
9892

9993
streamConfig.close();

divi/src/masternodeconfig.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,17 @@ class CMasternodeConfig
2626
std::string privKey;
2727
std::string txHash;
2828
std::string outputIndex;
29-
std::string rewardAddress;
3029

3130
public:
3231
CMasternodeEntry(const std::string& alias, const std::string& ip,
3332
const std::string& privKey,
34-
const std::string& txHash, const std::string& outputIndex,
35-
const std::string& rewardAddress)
33+
const std::string& txHash, const std::string& outputIndex)
3634
{
3735
this->alias = alias;
3836
this->ip = ip;
3937
this->privKey = privKey;
4038
this->txHash = txHash;
4139
this->outputIndex = outputIndex;
42-
this->rewardAddress = rewardAddress;
4340
}
4441

4542
const std::string& getAlias() const
@@ -92,16 +89,6 @@ class CMasternodeConfig
9289
this->ip = ip;
9390
}
9491

95-
const std::string& getRewardAddress() const
96-
{
97-
return rewardAddress;
98-
}
99-
100-
void setRewardAddress(const std::string& addr)
101-
{
102-
this->rewardAddress = addr;
103-
}
104-
10592
/** Tries to parse the entry's input reference into an outpoint.
10693
* Returns true on success. */
10794
bool parseInputReference(COutPoint& outp) const;
@@ -112,8 +99,7 @@ class CMasternodeConfig
11299
void clear();
113100
bool read(const Settings& settings, std::string& strErr);
114101
void add(const std::string& alias, const std::string& ip, const std::string& privKey,
115-
const std::string& txHash, const std::string& outputIndex,
116-
const std::string& rewardAddr);
102+
const std::string& txHash, const std::string& outputIndex);
117103
const std::vector<CMasternodeEntry>& getEntries() const;
118104
int getCount() const;
119105

divi/src/rpcmasternode.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ Value signmnbroadcast(const Array& params, bool fHelp)
263263

264264
Value setupmasternode(const Array& params, bool fHelp)
265265
{
266-
if (fHelp || params.size() < 5 || params.size() > 6)
266+
if (fHelp || params.size() < 5 || params.size() > 7)
267267
throw std::runtime_error(
268-
"setupmasternode alias txhash outputIndex collateralPubKey ip_address\n"
268+
"setupmasternode alias txhash outputIndex collateralPubKey ip_address (reward_address)\n"
269269
"\nStarts escrows funds for some purpose.\n"
270270

271271
"\nArguments:\n"
@@ -274,6 +274,7 @@ Value setupmasternode(const Array& params, bool fHelp)
274274
"3. outputIndex (string, required) Output index transaction. \n"
275275
"4. collateralPubkey (string, required) collateral pubkey. \n"
276276
"5. ip_address (string, required) Local ip address of this node\n"
277+
"6. reward_address (string, optional) A custom reward address, defaults to the collateral address\n"
277278
"\nResult:\n"
278279
"\"protocol_version\" (string) Protocol version used for serialization.\n"
279280
"\"message_to_sign\" (string) Hex-encoded msg requiring collateral signature.\n"
@@ -307,7 +308,7 @@ Value setupmasternode(const Array& params, bool fHelp)
307308
if (ipAndPort.find(':') == std::string::npos)
308309
ipAndPort += ":" + std::to_string(Params().GetDefaultPort());
309310

310-
CMasternodeConfig::CMasternodeEntry config(alias,ipAndPort,"",txHash,outputIndex,"");
311+
CMasternodeConfig::CMasternodeEntry config(alias,ipAndPort,"",txHash,outputIndex);
311312

312313
CMasternodeBroadcast mnb;
313314
std::string errorMsg;
@@ -316,6 +317,17 @@ Value setupmasternode(const Array& params, bool fHelp)
316317
throw JSONRPCError(RPC_INVALID_PARAMS,errorMsg);
317318
}
318319

320+
/* If we have a custom reward address, override the one from the broadcast.
321+
This is fine, as it would only invalidate the broadcast signature and
322+
the broadcast created is not yet signed anyway. */
323+
if (params.size() >= 6 && !params[5].get_str().empty())
324+
{
325+
const CBitcoinAddress addr(params[5].get_str());
326+
if (!addr.IsValid())
327+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid reward address");
328+
mnb.rewardScript = GetScriptForDestination(addr.Get());
329+
}
330+
319331
CDataStream ss(SER_NETWORK,PROTOCOL_VERSION);
320332
result.push_back(Pair("protocol_version", PROTOCOL_VERSION ));
321333
result.push_back(Pair("message_to_sign", HexStr(mnb.getMessageToSign()) ));

divi/src/test/ActiveMasternode_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ActiveMasternodeTestFixture
3030

3131
void AddDummyConfiguration(CTxIn txIn, CService service)
3232
{
33-
configurations_->add("dummy configuration", service.ToString(), "", txIn.prevout.hash.ToString(), std::to_string(txIn.prevout.n), "");
33+
configurations_->add("dummy configuration", service.ToString(), "", txIn.prevout.hash.ToString(), std::to_string(txIn.prevout.n));
3434
}
3535
void disableMasternode()
3636
{

0 commit comments

Comments
 (0)