Skip to content

Commit af389f3

Browse files
committed
rpc: deprecate key "service" replaced by "addresses"
IsDeprecatedRPCEnabled() is defined in RPC code but we construct UniValue objects outside of RPC code that are impacted. They are linked in binaries that do not include RPC logic. So, we need to implement a function that's functionally identical, IsServiceDeprecatedRPCEnabled().
1 parent 427be61 commit af389f3

File tree

9 files changed

+36
-10
lines changed

9 files changed

+36
-10
lines changed

src/coinjoin/client.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,9 @@ void CCoinJoinClientSession::GetJsonInfo(UniValue& obj) const
18761876
assert(mixingMasternode->pdmnState);
18771877
obj.pushKV("protxhash", mixingMasternode->proTxHash.ToString());
18781878
obj.pushKV("outpoint", mixingMasternode->collateralOutpoint.ToStringShort());
1879-
obj.pushKV("service", mixingMasternode->pdmnState->netInfo->GetPrimary().ToStringAddrPort());
1879+
if (m_wallet->chain().rpcEnableDeprecated("service")) {
1880+
obj.pushKV("service", mixingMasternode->pdmnState->netInfo->GetPrimary().ToStringAddrPort());
1881+
}
18801882
obj.pushKV("addresses", mixingMasternode->pdmnState->netInfo->ToJson());
18811883
}
18821884
obj.pushKV("denomination", ValueFromAmount(CoinJoin::DenominationToAmount(nSessionDenom)));

src/evo/core_write.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
ret.pushKV("type", ToUnderlying(nType));
6868
ret.pushKV("collateralHash", collateralOutpoint.hash.ToString());
6969
ret.pushKV("collateralIndex", (int)collateralOutpoint.n);
70-
ret.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
70+
if (IsServiceDeprecatedRPCEnabled()) {
71+
ret.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
72+
}
7173
ret.pushKV("addresses", netInfo->ToJson());
7274
ret.pushKV("ownerAddress", EncodeDestination(PKHash(keyIDOwner)));
7375
ret.pushKV("votingAddress", EncodeDestination(PKHash(keyIDVoting)));
@@ -115,7 +117,9 @@
115117
ret.pushKV("version", nVersion);
116118
ret.pushKV("type", ToUnderlying(nType));
117119
ret.pushKV("proTxHash", proTxHash.ToString());
118-
ret.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
120+
if (IsServiceDeprecatedRPCEnabled()) {
121+
ret.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
122+
}
119123
ret.pushKV("addresses", netInfo->ToJson());
120124
if (CTxDestination dest; ExtractDestination(scriptOperatorPayout, dest)) {
121125
ret.pushKV("operatorPayoutAddress", EncodeDestination(dest));

src/evo/dmnstate.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ UniValue CDeterministicMNState::ToJson(MnType nType) const
3939
{
4040
UniValue obj(UniValue::VOBJ);
4141
obj.pushKV("version", nVersion);
42-
obj.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
42+
if (IsServiceDeprecatedRPCEnabled()) {
43+
obj.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
44+
}
4345
obj.pushKV("addresses", netInfo->ToJson());
4446
obj.pushKV("registeredHeight", nRegisteredHeight);
4547
obj.pushKV("lastPaidHeight", nLastPaidHeight);
@@ -74,7 +76,9 @@ UniValue CDeterministicMNStateDiff::ToJson(MnType nType) const
7476
obj.pushKV("version", state.nVersion);
7577
}
7678
if (fields & Field_netInfo) {
77-
obj.pushKV("service", state.netInfo->GetPrimary().ToStringAddrPort());
79+
if (IsServiceDeprecatedRPCEnabled()) {
80+
obj.pushKV("service", state.netInfo->GetPrimary().ToStringAddrPort());
81+
}
7882
obj.pushKV("addresses", state.netInfo->ToJson());
7983
}
8084
if (fields & Field_nRegisteredHeight) {

src/evo/netinfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ UniValue ArrFromService(const CService& addr)
4242
return obj;
4343
}
4444

45+
bool IsServiceDeprecatedRPCEnabled()
46+
{
47+
const auto args = gArgs.GetArgs("-deprecatedrpc");
48+
return std::find(args.begin(), args.end(), "service") != args.end();
49+
}
50+
4551
bool NetInfoEntry::operator==(const NetInfoEntry& rhs) const
4652
{
4753
if (m_type != rhs.m_type) return false;

src/evo/netinfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ constexpr std::string_view NISToString(const NetInfoStatus code)
5353
assert(false);
5454
}
5555

56+
/* Identical to IsDeprecatedRPCEnabled("service"). For use outside of RPC code. */
57+
bool IsServiceDeprecatedRPCEnabled();
58+
5659
class NetInfoEntry
5760
{
5861
public:

src/evo/simplifiedmns.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
#include <core_io.h>
99
#include <deploymentstatus.h>
1010
#include <evo/deterministicmns.h>
11+
#include <evo/netinfo.h>
12+
#include <evo/specialtx.h>
1113
#include <llmq/blockprocessor.h>
1214
#include <llmq/commitment.h>
1315
#include <llmq/quorums.h>
1416
#include <node/blockstorage.h>
15-
#include <evo/specialtx.h>
1617

1718
#include <pubkey.h>
1819
#include <serialize.h>
@@ -78,7 +79,9 @@ UniValue CSimplifiedMNListEntry::ToJson(bool extended) const
7879
obj.pushKV("nType", ToUnderlying(nType));
7980
obj.pushKV("proRegTxHash", proRegTxHash.ToString());
8081
obj.pushKV("confirmedHash", confirmedHash.ToString());
81-
obj.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
82+
if (IsServiceDeprecatedRPCEnabled()) {
83+
obj.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
84+
}
8285
obj.pushKV("addresses", netInfo->ToJson());
8386
obj.pushKV("pubKeyOperator", pubKeyOperator.ToString());
8487
obj.pushKV("votingAddress", EncodeDestination(PKHash(keyIDVoting)));

src/rpc/coinjoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ static RPCHelpMan getcoinjoininfo()
427427
{
428428
{RPCResult::Type::STR_HEX, "protxhash", "The ProTxHash of the masternode"},
429429
{RPCResult::Type::STR_HEX, "outpoint", "The outpoint of the masternode"},
430-
{RPCResult::Type::STR, "service", "The IP address and port of the masternode"},
430+
{RPCResult::Type::STR, "service", "The IP address and port of the masternode (DEPRECATED, returned only if config option -deprecatedrpc=service is passed)"},
431431
{RPCResult::Type::ARR, "addresses", "Network addresses of the masternode",
432432
{
433433
{

src/rpc/masternode.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,9 @@ static RPCHelpMan masternodelist_helper(bool is_composite)
612612
strOutpoint.find(strFilter) == std::string::npos) return;
613613
UniValue objMN(UniValue::VOBJ);
614614
objMN.pushKV("proTxHash", dmn.proTxHash.ToString());
615-
objMN.pushKV("address", dmn.pdmnState->netInfo->GetPrimary().ToStringAddrPort());
615+
if (IsDeprecatedRPCEnabled("service")) {
616+
objMN.pushKV("address", dmn.pdmnState->netInfo->GetPrimary().ToStringAddrPort());
617+
}
616618
objMN.pushKV("addresses", dmn.pdmnState->netInfo->ToJson());
617619
objMN.pushKV("payee", payeeStr);
618620
objMN.pushKV("status", dmnToStatus(dmn));

src/rpc/quorums.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ static UniValue BuildQuorumInfo(const llmq::CQuorumBlockProcessor& quorum_block_
203203
const auto& dmn = quorum->members[i];
204204
UniValue mo(UniValue::VOBJ);
205205
mo.pushKV("proTxHash", dmn->proTxHash.ToString());
206-
mo.pushKV("service", dmn->pdmnState->netInfo->GetPrimary().ToStringAddrPort());
206+
if (IsDeprecatedRPCEnabled("service")) {
207+
mo.pushKV("service", dmn->pdmnState->netInfo->GetPrimary().ToStringAddrPort());
208+
}
207209
mo.pushKV("addresses", dmn->pdmnState->netInfo->ToJson());
208210
mo.pushKV("pubKeyOperator", dmn->pdmnState->pubKeyOperator.ToString());
209211
mo.pushKV("valid", quorum->qc->validMembers[i]);

0 commit comments

Comments
 (0)