Skip to content

Commit

Permalink
Merge bitcoin#28162: refactor: Revert additional univalue check in Pa…
Browse files Browse the repository at this point in the history
…rseSighashString

06199a9 refactor: Revert addition of univalue sighash string check (TheCharlatan)
0b47c16 doc: Correct release-notes for sighashtype exceptions (TheCharlatan)

Pull request description:

  This is a follow up for bitcoin#28113.

  The string type check is already done by the rpc parser / RPCHelpMan. Re-doing it is adding dead code. Instead, throwing an exception when the assumption does not hold is the already correct behavior. Pointed out in this [comment](https://github.com/bitcoin/bitcoin/pull/28113/files#r1274568557).

  Also correct the release note for the correct sighashtype exception change. There is no change in the handling of non-string sighashtype arugments. Pointed out in this [comment](https://github.com/bitcoin/bitcoin/pull/28113/files#r1274567555).

ACKs for top commit:
  MarcoFalke:
    lgtm ACK 06199a9
  jonatack:
    Tested ACK 06199a9
  stickies-v:
    ACK 06199a9

Tree-SHA512: 3faa6b3d2247624c0973df8d79c09fbf1f90ffb99f1be484e359b528f485c31affea45976759bd206e4c81cbb54ebba5ad0ef4127d1deacbfe2a58153fcc94ee
  • Loading branch information
fanquake authored and sidhujag committed Aug 5, 2023
1 parent 0b17a2d commit ae02a2a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions doc/release-notes-28113.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ RPC Wallet
----------

- The `signrawtransactionwithkey`, `signrawtransactionwithwallet`,
`walletprocesspsbt` and `descriptorprocesspsbt` calls now return more
specific RPC_INVALID_PARAMETER instead of RPC_PARSE_ERROR if their
sighashtype argument is malformed or not a string.
`walletprocesspsbt` and `descriptorprocesspsbt` calls now return the more
specific RPC_INVALID_PARAMETER error instead of RPC_MISC_ERROR if their
sighashtype argument is malformed.
8 changes: 5 additions & 3 deletions src/rpc/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,16 @@ UniValue DescribeAddress(const CTxDestination& dest)
return std::visit(DescribeAddressVisitor(), dest);
}

/**
* Returns a sighash value corresponding to the passed in argument.
*
* @pre The sighash argument should be string or null.
*/
int ParseSighashString(const UniValue& sighash)
{
if (sighash.isNull()) {
return SIGHASH_DEFAULT;
}
if (!sighash.isStr()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "sighash needs to be null or string");
}
const auto result{SighashFromStr(sighash.get_str())};
if (!result) {
throw JSONRPCError(RPC_INVALID_PARAMETER, util::ErrorString(result).original);
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/parse_univalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ FUZZ_TARGET(parse_univalue, .init = initialize_parse_univalue)
} catch (const std::runtime_error&) {
}
try {
(void)ParseSighashString(univalue);
if (univalue.isNull() || univalue.isStr()) (void)ParseSighashString(univalue);
} catch (const UniValue&) {
}
try {
Expand Down

0 comments on commit ae02a2a

Please sign in to comment.