Skip to content

Commit 9cb6873

Browse files
committed
refactor: Prepare for ParseHex -> ""_hex scripted-diff
- Adds using namespace. - Extracts ToScript helper function from ScriptFromHex, to be used heavily in the next commit. - Changes ScriptFromHex from using ParseHex to TryParseHex, now asserting the string is valid. - Use even number of hex digits in comment (and apply replacement from next commit to only touch line once).
1 parent 50bc017 commit 9cb6873

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/bench/index_blockfilter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <memory>
2626
#include <vector>
2727

28+
using namespace util::hex_literals;
29+
2830
// Very simple block filter index sync benchmark, only using coinbase outputs.
2931
static void BlockFilterIndexSync(benchmark::Bench& bench)
3032
{

src/test/script_standard_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <univalue.h>
1818

19+
using namespace util::hex_literals;
1920

2021
BOOST_FIXTURE_TEST_SUITE(script_standard_tests, BasicTestingSetup)
2122

src/test/script_tests.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,10 +1356,16 @@ BOOST_AUTO_TEST_CASE(script_GetScriptAsm)
13561356
BOOST_CHECK_EQUAL(derSig + "83 " + pubKey, ScriptToAsmStr(CScript() << ToByteVector(ParseHex(derSig + "83")) << vchPubKey));
13571357
}
13581358

1359+
template <typename T>
1360+
CScript ToScript(const T& byte_container)
1361+
{
1362+
auto span{MakeUCharSpan(byte_container)};
1363+
return {span.begin(), span.end()};
1364+
}
1365+
13591366
static CScript ScriptFromHex(const std::string& str)
13601367
{
1361-
std::vector<unsigned char> data = ParseHex(str);
1362-
return CScript(data.begin(), data.end());
1368+
return ToScript(*Assert(TryParseHex(str)));
13631369
}
13641370

13651371
BOOST_AUTO_TEST_CASE(script_FindAndDelete)
@@ -1393,7 +1399,7 @@ BOOST_AUTO_TEST_CASE(script_FindAndDelete)
13931399
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1);
13941400
BOOST_CHECK(s == expect);
13951401

1396-
s = ScriptFromHex("0302ff030302ff03"); // PUSH 0x2ff03 PUSH 0x2ff03
1402+
s = ToScript("0302ff030302ff03"_hex); // PUSH 0x02ff03 PUSH 0x02ff03
13971403
d = ScriptFromHex("0302ff03");
13981404
expect = CScript();
13991405
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 2);

0 commit comments

Comments
 (0)