mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
refactor: Hand-replace some ParseHex -> ""_hex
The following scripted-diff commit will replace ParseHex("...") with "..."_hex_u8, but this replacement will not work in cases where vectors are needed instead of arrays, and is not ideal in cases where std::byte is accepted.
For example, it is currently necessary to use _hex_v_u8 when calling CScript operator<< because that operator does not currently support std::array or std::byte.
Conversely, it is incorrect to use _hex_v instead of _hex in net_processing.cpp for the MakeAndPushMessage argument, because if the argument is a std::vector it is considered variable-length and serialized with a size prefix, but if the argument is a std::array or Span is it considered fixed length and serialized without a prefix.
By the same logic, it is also safe to change the NUMS_H constant in pubkey.cpp from a std::vector to std::array because it is never serialized.
This commit is contained in:
@@ -35,6 +35,8 @@
|
||||
// Uncomment if you want to output updated JSON tests.
|
||||
// #define UPDATE_JSON_TESTS
|
||||
|
||||
using namespace util::hex_literals;
|
||||
|
||||
static const unsigned int gFlags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC;
|
||||
|
||||
unsigned int ParseScriptFlags(std::string strFlags);
|
||||
@@ -1413,7 +1415,7 @@ BOOST_AUTO_TEST_CASE(script_FindAndDelete)
|
||||
// prefix, leaving 02ff03 which is push-two-bytes:
|
||||
s = ScriptFromHex("0302ff030302ff03");
|
||||
d = ScriptFromHex("03");
|
||||
expect = CScript() << ParseHex("ff03") << ParseHex("ff03");
|
||||
expect = CScript() << "ff03"_hex_v_u8 << "ff03"_hex_v_u8;
|
||||
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 2);
|
||||
BOOST_CHECK(s == expect);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user