Skip to content

Commit 27ceba6

Browse files
Merge commit '38600fcc1bdfda7043973a4e65d53e174fbf7249'
2 parents 31a53eb + 38600fc commit 27ceba6

File tree

5 files changed

+691
-520
lines changed

5 files changed

+691
-520
lines changed

libbitcoinkernel-sys/bitcoin/src/bitcoin-chainstate.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,25 @@
1414
#include <windows.h>
1515
// clang-format on
1616
#include <codecvt>
17-
#include <shellapi.h>
1817
#include <locale>
18+
#include <shellapi.h>
1919
#endif
2020

2121
using namespace btck;
2222

23-
std::vector<unsigned char> hex_string_to_char_vec(std::string_view hex)
23+
std::vector<std::byte> hex_string_to_byte_vec(std::string_view hex)
2424
{
25-
std::vector<unsigned char> bytes;
25+
std::vector<std::byte> bytes;
2626
bytes.reserve(hex.length() / 2);
2727

2828
for (size_t i{0}; i < hex.length(); i += 2) {
29-
unsigned char byte;
30-
auto [ptr, ec] = std::from_chars(hex.data() + i, hex.data() + i + 2, byte, 16);
31-
if (ec == std::errc{} && ptr == hex.data() + i + 2) {
32-
bytes.push_back(byte);
29+
uint8_t byte_value;
30+
auto [ptr, ec] = std::from_chars(hex.data() + i, hex.data() + i + 2, byte_value, 16);
31+
32+
if (ec != std::errc{} || ptr != hex.data() + i + 2) {
33+
throw std::invalid_argument("Invalid hex character");
3334
}
35+
bytes.push_back(static_cast<std::byte>(byte_value));
3436
}
3537
return bytes;
3638
}
@@ -47,7 +49,7 @@ class KernelLog
4749
class TestValidationInterface : public ValidationInterface<TestValidationInterface>
4850
{
4951
public:
50-
TestValidationInterface() : ValidationInterface() {}
52+
TestValidationInterface() = default;
5153

5254
std::optional<std::string> m_expected_valid_block = std::nullopt;
5355

@@ -104,7 +106,7 @@ class TestValidationInterface : public ValidationInterface<TestValidationInterfa
104106
class TestKernelNotifications : public KernelNotifications<TestKernelNotifications>
105107
{
106108
public:
107-
void BlockTipHandler(btck_SynchronizationState, const btck_BlockIndex*, double) override
109+
void BlockTipHandler(btck_SynchronizationState, const BlockTreeEntry, double) override
108110
{
109111
std::cout << "Block tip changed" << std::endl;
110112
}
@@ -206,7 +208,7 @@ int main(int argc, char* argv[])
206208
continue;
207209
}
208210

209-
auto raw_block{hex_string_to_char_vec(line)};
211+
auto raw_block{hex_string_to_byte_vec(line)};
210212
std::unique_ptr<Block> block;
211213
try {
212214
block = std::make_unique<Block>(raw_block);

0 commit comments

Comments
 (0)