Skip to content

Commit 01ee293

Browse files
committed
rpc: make setting platform{HTTP,P2P}Port optional if using netInfo
1 parent 1d36005 commit 01ee293

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/rpc/evo.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,21 @@ static RPCArg GetRpcArg(const std::string& strParamName)
184184
"Platform P2P node ID, derived from P2P public key."}
185185
},
186186
{"platformP2PPort",
187+
{"platformP2PPort", RPCArg::Type::STR, RPCArg::Optional::NO,
188+
"Address in the form \"ADDR:PORT\" used by Platform for peer-to-peer connection.\n"
189+
"Must be unique on the network. Can be set to an empty string, which will require a ProUpServTx afterwards."}
190+
},
191+
{"platformP2PPort_update",
187192
{"platformP2PPort", RPCArg::Type::STR, RPCArg::Optional::NO,
188193
"Address in the form \"ADDR:PORT\" used by Platform for peer-to-peer connection.\n"
189194
"Must be unique on the network."}
190195
},
191196
{"platformHTTPPort",
197+
{"platformHTTPPort", RPCArg::Type::STR, RPCArg::Optional::NO,
198+
"Address in the form \"ADDR:PORT\" used by Platform for their HTTPS API.\n"
199+
"Must be unique on the network. Can be set to an empty string, which will require a ProUpServTx afterwards."}
200+
},
201+
{"platformHTTPPort_update",
192202
{"platformHTTPPort", RPCArg::Type::STR, RPCArg::Optional::NO,
193203
"Address in the form \"ADDR:PORT\" used by Platform for their HTTPS API.\n"
194204
"Must be unique on the network."}
@@ -736,7 +746,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
736746
}
737747
ptx.platformNodeID.SetHex(request.params[paramIdx + 6].get_str());
738748

739-
ProcessNetInfoPlatform(ptx, request.params[paramIdx + 7], request.params[paramIdx + 8]);
749+
ProcessNetInfoPlatform(ptx, request.params[paramIdx + 7], request.params[paramIdx + 8], /*optional=*/true);
740750

741751
paramIdx += 3;
742752
}
@@ -944,8 +954,8 @@ static RPCHelpMan protx_update_service_evo()
944954
GetRpcArg("coreP2PAddrs_update"),
945955
GetRpcArg("operatorKey"),
946956
GetRpcArg("platformNodeID"),
947-
GetRpcArg("platformP2PPort"),
948-
GetRpcArg("platformHTTPPort"),
957+
GetRpcArg("platformP2PPort_update"),
958+
GetRpcArg("platformHTTPPort_update"),
949959
GetRpcArg("operatorPayoutAddress"),
950960
GetRpcArg("feeSourceAddress"),
951961
GetRpcArg("submit"),
@@ -1006,7 +1016,7 @@ static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& reques
10061016
}
10071017
ptx.platformNodeID.SetHex(request.params[paramIdx].get_str());
10081018

1009-
ProcessNetInfoPlatform(ptx, request.params[paramIdx + 1], request.params[paramIdx + 2]);
1019+
ProcessNetInfoPlatform(ptx, request.params[paramIdx + 1], request.params[paramIdx + 2], /*optional=*/false);
10101020

10111021
paramIdx += 3;
10121022
}

src/rpc/evo_util.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ template void ProcessNetInfoCore(CProRegTx& ptx, const UniValue& input, const bo
6363
template void ProcessNetInfoCore(CProUpServTx& ptx, const UniValue& input, const bool optional);
6464

6565
template <typename ProTx>
66-
void ProcessNetInfoPlatform(ProTx& ptx, const UniValue& input_p2p, const UniValue& input_http)
66+
void ProcessNetInfoPlatform(ProTx& ptx, const UniValue& input_p2p, const UniValue& input_http, const bool optional)
6767
{
6868
CHECK_NONFATAL(ptx.netInfo);
6969

@@ -75,7 +75,23 @@ void ProcessNetInfoPlatform(ProTx& ptx, const UniValue& input_p2p, const UniValu
7575
}
7676

7777
const auto& input_str{input.getValStr()};
78-
if (!IsNumeric(input_str)) {
78+
if (input_str.empty()) {
79+
if (!optional) {
80+
// Mandatory field, cannot specify blank value
81+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid param for %s, cannot be empty", field_name));
82+
}
83+
if (!ptx.netInfo->CanStorePlatform()) {
84+
// We can tolerate blank values if netInfo can store platform fields, if it cannot, we are relying
85+
// on platform{HTTP,P2P}Port, where it is mandatory even if their netInfo counterpart is optional.
86+
throw JSONRPCError(RPC_INVALID_PARAMETER,
87+
strprintf("Invalid param for %s, ProTx version only supports ports", field_name));
88+
}
89+
if (!ptx.netInfo->IsEmpty()) {
90+
// Blank values are tolerable so long as no other field has been populated.
91+
throw JSONRPCError(RPC_INVALID_PARAMETER,
92+
strprintf("Invalid param for %s, cannot be empty if other fields populated", field_name));
93+
}
94+
} else if (!IsNumeric(input_str)) {
7995
// Cannot be parsed as a number (port) so must be an addr:port string
8096
if (!ptx.netInfo->CanStorePlatform()) {
8197
throw JSONRPCError(RPC_INVALID_PARAMETER,

src/rpc/evo_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ void ProcessNetInfoCore(ProTx& ptx, const UniValue& input, const bool optional);
1313

1414
/** Process setting (legacy) Platform network information fields based on ProTx version */
1515
template <typename ProTx>
16-
void ProcessNetInfoPlatform(ProTx& ptx, const UniValue& input_p2p, const UniValue& input_http);
16+
void ProcessNetInfoPlatform(ProTx& ptx, const UniValue& input_p2p, const UniValue& input_http, const bool optional);
1717

1818
#endif // BITCOIN_RPC_EVO_UTIL_H

0 commit comments

Comments
 (0)