ScriptPubKeyToUniv
and ScriptToUniv
into a single function, but this didn’t seem to belong in that PR. There are a few other minor cleanups here as well focused on style and making some fuzz tests run faster
ScriptPubKeyToUniv
and ScriptToUniv
into a single function, but this didn’t seem to belong in that PR. There are a few other minor cleanups here as well focused on style and making some fuzz tests run faster
Now that #22650 is merged, I rebased and finished this. This PR follows up with some cleanup, and addresses all the comments in the first PR that were left for now.
Just so we have them at-hand, I took all the original comments from #22650’s review, and am putting them here.
@jonatack: maybe I’m missing something but perhaps merge ScriptPubKeyToUniv and ScriptToUniv into a single function
Done b9ad1d9
@jonatack: Named args could be nice wherever this function is invoked
and
@MarcoFalke: If you decide to do it here, at least use the proper clang-tidy format, so that it can be checked by the clang compiler
Done e9f3f1b
@MarcoFalke: as a follow-up it could make sense to de-duplicate the common help text
Done fe71ac8
@MarcoFalke: I think you can drop one of these statements to make the fuzz test run ~twice as fast. An alternative (to test both code paths) would be to deserialize a bool from the fuzzing input and use uint256{bool_val}
and
@meshcollider: This should really be replaced with include_address=true/false checks on ScriptPubKeyToUniv(script, o4, fIncludeHex, include_address)
Done e749168
104@@ -103,6 +105,5 @@ FUZZ_TARGET_INIT(transaction, initialize_transaction)
105 (void)IsWitnessStandard(tx, coins_view_cache);
106
107 UniValue u(UniValue::VOBJ);
108- TxToUniv(tx, /* hashBlock */ uint256::ZERO, u);
109- TxToUniv(tx, /* hashBlock */ uint256::ONE, u);
110+ TxToUniv(tx, /* hashBlock= */ uint256{fuzzed_data_provider.ConsumeBool()}, /* entry= */ u, fuzzed_data_provider.ConsumeBool());
not a fan of re-using the same buffer, thus nVersion for this bool.
try { ds >> bool{}; }
might be nicer
1761@@ -1762,7 +1762,7 @@ static RPCHelpMan gettransaction()
1762
1763 if (verbose) {
1764 UniValue decoded(UniValue::VOBJ);
1765- TxToUniv(*wtx.tx, uint256(), decoded, false);
1766+ TxToUniv(*wtx.tx, /* hashBlock= */ uint256(), /* entry= */ decoded, /* include_hex= */ false);
nit: Maybe before using named args, fix the argument name first?
0 TxToUniv(*wtx.tx, /*block_hash=*/uint256{}, /*entry=*/decoded, /*include_hex=*/false);
hashBlock
was used pretty regularly so I thought there might be some convention I wasn’t aware of - I guess not so I’m happy to be able to do this
106+ bool include_hex;
107+ try {
108+ ds >> block_hash;
109+ ds >> include_hex;
110+ } catch (const std::ios_base::failure&) {
111+ return;
false
, you can remove the early return (This is also what FuzzedDataProvider would do)
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
154
155- out.pushKV("asm", ScriptToAsmStr(scriptPubKey));
156- if (include_hex) out.pushKV("hex", HexStr(scriptPubKey));
157+ out.pushKV("asm", ScriptToAsmStr(script));
158+ if (include_hex) {
159+ out.pushKV("hex", HexStr(script));
52@@ -53,8 +53,7 @@ UniValue ValueFromAmount(const CAmount amount);
53 std::string FormatScript(const CScript& script);
54 std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
55 std::string SighashToStr(unsigned char sighash_type);
56-void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool include_hex, bool include_address = true);
57-void ScriptToUniv(const CScript& script, UniValue& out);
58-void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS);
59+void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex = true, bool include_address = false);
optional<UniValue>
in case it can fail) instead of having it as second parameter. It would seem better API design to me.
ScriptToUniv
, but TxToUniv
, entryToJSON
, and probably more. Anyways I want to spend some more time on this and don’t want to end up doing too much in this PR
Can you take a quick look at the last two commits in this draft PR #23507?
a) is this along the lines of what you are thinking?
b) do you think it is worthwhile for me to do this across the codebase in #23507, eg entryToJSON
, TxToJSON
, etc… can be improved in the same way
Feel free to answer those in the linked PR and not here
1273@@ -1274,7 +1274,7 @@ static RPCHelpMan gettxout()
1274 {RPCResult::Type::STR, "asm", ""},
1275 {RPCResult::Type::STR_HEX, "hex", ""},
1276 {RPCResult::Type::STR, "type", "The type, eg pubkeyhash"},
1277- {RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
1278+ {RPCResult::Type::STR, "address", /* optional */ true, DESTINATION_ADDRESS},
🐙 This pull request conflicts with the target branch and needs rebase.
Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a “draft”.