-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor(rpc): migrate composite RPCs to client conversion table, drop ParseInt{32,64}V(), lay foundation to drop ParseBoolV()
#7099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fd6ccaf
635ecd9
e2ee1f7
ac537fc
53a66ca
11bf976
2d5817e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| Updated RPCs | ||
| ------------ | ||
|
|
||
| * Dash RPCs will no longer permit submitting strings to boolean input fields in line with validation | ||
| enforced on upstream RPCs, where this is already the case. Requests must now use unquoted `true` | ||
| or `false`. | ||
|
|
||
| * The following RPCs are affected, `bls generate`, `bls fromsecret`, `coinjoinsalt generate`, | ||
| `coinjoinsalt set`, `masternode connect`, `protx diff`, `protx list`, `protx register`, | ||
| `protx register_legacy`, `protx register_evo`, `protx register_fund`, `protx register_fund_legacy`, | ||
| `protx register_fund_evo`, `protx revoke`, `protx update_registrar`, `protx update_registrar_legacy`, | ||
| `protx update_service`, `protx update_service_evo`, `quorum info`, `quorum platformsign`, | ||
| `quorum rotationinfo`, `quorum sign`. | ||
|
|
||
| * This restriction can be relaxed by setting `-deprecatedrpc=permissive_bool` at runtime | ||
| but is liable to be removed in future versions of Dash Core. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -713,7 +713,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request, | |||||||||||||||||||||||||||||||||||
| paramIdx++; | ||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||
| uint256 collateralHash(ParseHashV(request.params[paramIdx], "collateralHash")); | ||||||||||||||||||||||||||||||||||||
| int32_t collateralIndex = ParseInt32V(request.params[paramIdx + 1], "collateralIndex"); | ||||||||||||||||||||||||||||||||||||
| int32_t collateralIndex = request.params[paramIdx + 1].getInt<int>(); | ||||||||||||||||||||||||||||||||||||
| if (collateralHash.IsNull() || collateralIndex < 0) { | ||||||||||||||||||||||||||||||||||||
| throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("invalid hash or index: %s-%d", collateralHash.ToString(), collateralIndex)); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
@@ -1277,7 +1277,7 @@ static RPCHelpMan protx_revoke() | |||||||||||||||||||||||||||||||||||
| CBLSSecretKey keyOperator = ParseBLSSecretKey(request.params[1].get_str(), "operatorKey"); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (!request.params[2].isNull()) { | ||||||||||||||||||||||||||||||||||||
| int32_t nReason = ParseInt32V(request.params[2], "reason"); | ||||||||||||||||||||||||||||||||||||
| int32_t nReason = request.params[2].getInt<int>(); | ||||||||||||||||||||||||||||||||||||
| if (nReason < 0 || nReason > CProUpRevTx::REASON_LAST) { | ||||||||||||||||||||||||||||||||||||
| throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("invalid reason %d, must be between 0 and %d", nReason, CProUpRevTx::REASON_LAST)); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
@@ -1462,7 +1462,7 @@ static RPCHelpMan protx_list() | |||||||||||||||||||||||||||||||||||
| bool detailed = !request.params[1].isNull() ? ParseBoolV(request.params[1], "detailed") : false; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| LOCK2(wallet->cs_wallet, ::cs_main); | ||||||||||||||||||||||||||||||||||||
| int height = !request.params[2].isNull() ? ParseInt32V(request.params[2], "height") : chainman.ActiveChain().Height(); | ||||||||||||||||||||||||||||||||||||
| int height = !request.params[2].isNull() ? request.params[2].getInt<int>() : chainman.ActiveChain().Height(); | ||||||||||||||||||||||||||||||||||||
| if (height < 1 || height > chainman.ActiveChain().Height()) { | ||||||||||||||||||||||||||||||||||||
| throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid height specified"); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
@@ -1495,7 +1495,7 @@ static RPCHelpMan protx_list() | |||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||
| LOCK(::cs_main); | ||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||
| int height = !request.params[2].isNull() ? ParseInt32V(request.params[2], "height") : chainman.ActiveChain().Height(); | ||||||||||||||||||||||||||||||||||||
| int height = !request.params[2].isNull() ? request.params[2].getInt<int>() : chainman.ActiveChain().Height(); | ||||||||||||||||||||||||||||||||||||
| if (height < 1 || height > chainman.ActiveChain().Height()) { | ||||||||||||||||||||||||||||||||||||
| throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid height specified"); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
@@ -1587,20 +1587,43 @@ static uint256 ParseBlock(const UniValue& v, const ChainstateManager& chainman, | |||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||
| return ParseHashV(v, strName); | ||||||||||||||||||||||||||||||||||||
| } catch (...) { | ||||||||||||||||||||||||||||||||||||
| int h = ParseInt32V(v, strName); | ||||||||||||||||||||||||||||||||||||
| if (h < 1 || h > chainman.ActiveChain().Height()) | ||||||||||||||||||||||||||||||||||||
| bool fail{false}; int32_t h{0}; | ||||||||||||||||||||||||||||||||||||
| if (v.isNum()) { | ||||||||||||||||||||||||||||||||||||
| h = v.getInt<int>(); | ||||||||||||||||||||||||||||||||||||
| } else if (!ParseInt32(v.get_str(), &h)) { | ||||||||||||||||||||||||||||||||||||
| fail = true; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if (fail || h < 1 || h > chainman.ActiveChain().Height()) { | ||||||||||||||||||||||||||||||||||||
| throw std::runtime_error(strprintf("%s must be a block hash or chain height and not %s", strName, v.getValStr())); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| return *chainman.ActiveChain()[h]->phashBlock; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
1587
to
1599
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep malformed block identifiers on These helpers catch 💡 Suggested fix- throw std::runtime_error(strprintf("%s must be a block hash or chain height and not %s", strName, v.getValStr()));
+ throw JSONRPCError(RPC_INVALID_PARAMETER,
+ strprintf("%s must be a block hash or chain height and not %s",
+ strName, v.getValStr()));Apply the same change in both helpers. Also applies to: 1642-1652 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| static const CBlockIndex* ParseBlockIndex(const UniValue& v, const ChainstateManager& chainman, const std::string& strName) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| AssertLockHeld(::cs_main); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||
| const auto hash{ParseBlock(v, chainman, strName)}; | ||||||||||||||||||||||||||||||||||||
| const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash); | ||||||||||||||||||||||||||||||||||||
| if (!pindex) { | ||||||||||||||||||||||||||||||||||||
| throw std::runtime_error(strprintf("Block %s with hash %s not found", strName, v.getValStr())); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| return pindex; | ||||||||||||||||||||||||||||||||||||
| } catch (...) { | ||||||||||||||||||||||||||||||||||||
| // Same phrasing as ParseBlock() as it can parse heights | ||||||||||||||||||||||||||||||||||||
| throw std::runtime_error(strprintf("%s must be a block hash or chain height and not %s", strName, v.getValStr())); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1607
to
+1617
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since
Suggested change
The current catch (...) swallows the more specific "not found" error when a valid hash isn't in the index, replacing it with the generic "must be a block hash or chain height" message. Dropping it fixes that. |
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| static RPCHelpMan protx_diff() | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| return RPCHelpMan{"protx diff", | ||||||||||||||||||||||||||||||||||||
| "\nCalculates a diff between two deterministic masternode lists. The result also contains proof data.\n", | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| {"baseBlock", RPCArg::Type::NUM, RPCArg::Optional::NO, "The starting block height."}, | ||||||||||||||||||||||||||||||||||||
| {"block", RPCArg::Type::NUM, RPCArg::Optional::NO, "The ending block height."}, | ||||||||||||||||||||||||||||||||||||
| {"baseBlock", RPCArg::Type::STR, RPCArg::Optional::NO, "The starting block hash or height."}, | ||||||||||||||||||||||||||||||||||||
| {"block", RPCArg::Type::STR, RPCArg::Optional::NO, "The ending block hash or height."}, | ||||||||||||||||||||||||||||||||||||
|
UdjinM6 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||
| {"extended", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED, "Show additional fields."}, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| CSimplifiedMNListDiff::GetJsonHelp(/*key=*/"", /*optional=*/false), | ||||||||||||||||||||||||||||||||||||
|
|
@@ -1635,31 +1658,13 @@ static RPCHelpMan protx_diff() | |||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| static const CBlockIndex* ParseBlockIndex(const UniValue& v, const ChainstateManager& chainman, const std::string& strName) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| AssertLockHeld(::cs_main); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||
| uint256 hash = ParseHashV(v, strName); | ||||||||||||||||||||||||||||||||||||
| const CBlockIndex* pblockindex = chainman.m_blockman.LookupBlockIndex(hash); | ||||||||||||||||||||||||||||||||||||
| if (!pblockindex) | ||||||||||||||||||||||||||||||||||||
| throw std::runtime_error(strprintf("Block %s with hash %s not found", strName, v.getValStr())); | ||||||||||||||||||||||||||||||||||||
| return pblockindex; | ||||||||||||||||||||||||||||||||||||
| } catch (...) { | ||||||||||||||||||||||||||||||||||||
| int h = ParseInt32V(v, strName); | ||||||||||||||||||||||||||||||||||||
| if (h < 1 || h > chainman.ActiveChain().Height()) | ||||||||||||||||||||||||||||||||||||
| throw std::runtime_error(strprintf("%s must be a chain height and not %s", strName, v.getValStr())); | ||||||||||||||||||||||||||||||||||||
| return chainman.ActiveChain()[h]; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| static RPCHelpMan protx_listdiff() | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| return RPCHelpMan{"protx listdiff", | ||||||||||||||||||||||||||||||||||||
| "\nCalculate a full MN list diff between two masternode lists.\n", | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| {"baseBlock", RPCArg::Type::NUM, RPCArg::Optional::NO, "The starting block height."}, | ||||||||||||||||||||||||||||||||||||
| {"block", RPCArg::Type::NUM, RPCArg::Optional::NO, "The ending block height."}, | ||||||||||||||||||||||||||||||||||||
| {"baseBlock", RPCArg::Type::STR, RPCArg::Optional::NO, "The starting block hash or height."}, | ||||||||||||||||||||||||||||||||||||
| {"block", RPCArg::Type::STR, RPCArg::Optional::NO, "The ending block hash or height."}, | ||||||||||||||||||||||||||||||||||||
|
UdjinM6 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| RPCResult { | ||||||||||||||||||||||||||||||||||||
| RPCResult::Type::OBJ, "", "", | ||||||||||||||||||||||||||||||||||||
|
|
@@ -1834,8 +1839,8 @@ static RPCHelpMan evodb_verify() | |||||||||||||||||||||||||||||||||||
| "This is a read-only operation that does not modify the database.\n" | ||||||||||||||||||||||||||||||||||||
| "If no heights are specified, defaults to the full range from DIP0003 activation to chain tip.\n", | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| {"startBlock", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "The starting block height (defaults to DIP0003 activation height)."}, | ||||||||||||||||||||||||||||||||||||
| {"stopBlock", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "The ending block height (defaults to current chain tip)."}, | ||||||||||||||||||||||||||||||||||||
| {"startBlock", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "The starting block hash or height (defaults to DIP0003 activation height)."}, | ||||||||||||||||||||||||||||||||||||
| {"stopBlock", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "The ending block hash or height (defaults to current chain tip)."}, | ||||||||||||||||||||||||||||||||||||
|
UdjinM6 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| RPCResult{ | ||||||||||||||||||||||||||||||||||||
| RPCResult::Type::OBJ, "", "", | ||||||||||||||||||||||||||||||||||||
|
|
@@ -1872,8 +1877,8 @@ static RPCHelpMan evodb_repair() | |||||||||||||||||||||||||||||||||||
| "If verification fails, recalculates diffs from blockchain data and replaces corrupted records.\n" | ||||||||||||||||||||||||||||||||||||
| "If no heights are specified, defaults to the full range from DIP0003 activation to chain tip.\n", | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| {"startBlock", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "The starting block height (defaults to DIP0003 activation height)."}, | ||||||||||||||||||||||||||||||||||||
| {"stopBlock", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "The ending block height (defaults to current chain tip)."}, | ||||||||||||||||||||||||||||||||||||
| {"startBlock", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "The starting block hash or height (defaults to DIP0003 activation height)."}, | ||||||||||||||||||||||||||||||||||||
| {"stopBlock", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "The ending block hash or height (defaults to current chain tip)."}, | ||||||||||||||||||||||||||||||||||||
|
UdjinM6 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| RPCResult{ | ||||||||||||||||||||||||||||||||||||
| RPCResult::Type::OBJ, "", "", | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.