Skip to content

Commit 38600fc

Browse files
Squashed 'libbitcoinkernel-sys/bitcoin/' changes from abffb6d65875..35fced5df783
35fced5df783 kernel: Fix bitcoin-chainstate for windows c164264fd84e kernel: Add Purpose section to header documentation 9096c35c0510 kernel: Allowing reducing exports 6d0d4b250721 kernel: Add pure kernel bitcoin-chainstate ccd85f0333c4 kernel: Add functions to get the block hash from a block 925f21c37bbb kernel: Add block index utility functions to C header b7441841c960 kernel: Add function to read block undo data from disk to C header bc0e6f098e9e kernel: Add functions to read block from disk to C header 5120302f96f8 kernel: Add function for copying block data to C header 718ccee73213 kernel: Add functions for the block validation state to C header eb363ab30eab kernel: Add validation interface to C header 246886c6ea39 kernel: Add interrupt function to C header f3b34ca457b0 kernel: Add import blocks function to C header fe08857d5205 kernel: Add chainstate load options for in-memory dbs in C header f93f171e01ed kernel: Add options for reindexing in C header dca7b4c26e8b kernel: Add block validation to C header f031e9ce03b5 kernel: Add chainstate loading when instantiating a ChainstateManager 3cb99f73ece8 kernel: Add chainstate manager option for setting worker threads 9454ad8512c2 kernel: Add chainstate manager object to C header 3bead9ebdd22 kernel: Add notifications context option to C header dda805dfb64f kernel: Add chain params context option to C header ea5334925d48 kernel: Add kernel library context object 36fafbaef9d2 kernel: Add logging to kernel library C header d28eef5cf2a4 kernel: Introduce initial kernel C header API REVERT: abffb6d65875 kernel: Fix bitcoin-chainstate for windows REVERT: c9d7b71b7b96 kernel: Add Purpose section to header documentation REVERT: 88c53c323a4d kernel: Allowing reducing exports REVERT: deee70395cef kernel: Add pure kernel bitcoin-chainstate REVERT: 1a89d2f76bd6 kernel: Add functions to get the block hash from a block REVERT: dff6e326c929 kernel: Add block index utility functions to C header REVERT: f2a1c5e198fc kernel: Add function to read block undo data from disk to C header REVERT: 5e0e1cc30026 kernel: Add functions to read block from disk to C header REVERT: 6a3406caace5 kernel: Add function for copying block data to C header REVERT: 3ac6249b5b91 kernel: Add functions for the block validation state to C header REVERT: 366276d61913 kernel: Add validation interface to C header REVERT: bc4093175962 kernel: Add interrupt function to C header REVERT: 70c5d903cb29 kernel: Add import blocks function to C header REVERT: 2be42e3c1ae1 kernel: Add chainstate load options for in-memory dbs in C header REVERT: 6be186958803 kernel: Add options for reindexing in C header REVERT: 33445ec97008 kernel: Add block validation to C header REVERT: e63ec151b9da kernel: Add chainstate loading when instantiating a ChainstateManager REVERT: 171fbb8d118c kernel: Add chainstate manager option for setting worker threads REVERT: a00df723ac2f kernel: Add chainstate manager object to C header REVERT: 40a1f1d46338 kernel: Add notifications context option to C header REVERT: 506f82bcfb27 kernel: Add chain params context option to C header REVERT: c4074d7894fd kernel: Add kernel library context object REVERT: 54518fdc6f7f kernel: Add logging to kernel library C header REVERT: ff4a0ef4132a kernel: Introduce initial kernel C header API git-subtree-dir: libbitcoinkernel-sys/bitcoin git-subtree-split: 35fced5df783bc79720d8a74b89a5a0a62ebab72
1 parent 30bc73a commit 38600fc

File tree

5 files changed

+691
-520
lines changed

5 files changed

+691
-520
lines changed

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)