Bitcoin Core 30.99.0
P2P Digital Currency
bitcoinkernel_wrapper.h
Go to the documentation of this file.
1// Copyright (c) 2024-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_KERNEL_BITCOINKERNEL_WRAPPER_H
6#define BITCOIN_KERNEL_BITCOINKERNEL_WRAPPER_H
7
9
10#include <array>
11#include <functional>
12#include <memory>
13#include <optional>
14#include <span>
15#include <stdexcept>
16#include <string>
17#include <string_view>
18#include <type_traits>
19#include <utility>
20#include <vector>
21
22namespace btck {
23
27 BLOCKSTORAGE = btck_LogCategory_BLOCKSTORAGE,
34 VALIDATION = btck_LogCategory_VALIDATION,
36};
37
38enum class LogLevel : btck_LogLevel {
42};
43
50};
51
56};
57
58enum class Warning : btck_Warning {
61};
62
67};
68
79};
80
85};
86
97};
98
99template <typename T>
100struct is_bitmask_enum : std::false_type {
101};
102
103template <>
104struct is_bitmask_enum<ScriptVerificationFlags> : std::true_type {
105};
106
107template <typename T>
108concept BitmaskEnum = is_bitmask_enum<T>::value;
109
110template <BitmaskEnum T>
111constexpr T operator|(T lhs, T rhs)
112{
113 return static_cast<T>(
114 static_cast<std::underlying_type_t<T>>(lhs) | static_cast<std::underlying_type_t<T>>(rhs));
115}
116
117template <BitmaskEnum T>
118constexpr T operator&(T lhs, T rhs)
119{
120 return static_cast<T>(
121 static_cast<std::underlying_type_t<T>>(lhs) & static_cast<std::underlying_type_t<T>>(rhs));
122}
123
124template <BitmaskEnum T>
125constexpr T operator^(T lhs, T rhs)
126{
127 return static_cast<T>(
128 static_cast<std::underlying_type_t<T>>(lhs) ^ static_cast<std::underlying_type_t<T>>(rhs));
129}
130
131template <BitmaskEnum T>
132constexpr T operator~(T value)
133{
134 return static_cast<T>(~static_cast<std::underlying_type_t<T>>(value));
135}
136
137template <BitmaskEnum T>
138constexpr T& operator|=(T& lhs, T rhs)
139{
140 return lhs = lhs | rhs;
141}
142
143template <BitmaskEnum T>
144constexpr T& operator&=(T& lhs, T rhs)
145{
146 return lhs = lhs & rhs;
147}
148
149template <BitmaskEnum T>
150constexpr T& operator^=(T& lhs, T rhs)
151{
152 return lhs = lhs ^ rhs;
153}
154
155template <typename T>
156T check(T ptr)
157{
158 if (ptr == nullptr) {
159 throw std::runtime_error("failed to instantiate btck object");
160 }
161 return ptr;
162}
163
164template <typename Collection, typename ValueType>
166{
167public:
168 using iterator_category = std::random_access_iterator_tag;
169 using iterator_concept = std::random_access_iterator_tag;
170 using difference_type = std::ptrdiff_t;
171 using value_type = ValueType;
172
173private:
174 const Collection* m_collection;
175 size_t m_idx;
176
177public:
178 Iterator() = default;
179 Iterator(const Collection* ptr) : m_collection{ptr}, m_idx{0} {}
180 Iterator(const Collection* ptr, size_t idx) : m_collection{ptr}, m_idx{idx} {}
181
182 // This is just a view, so return a copy.
183 auto operator*() const { return (*m_collection)[m_idx]; }
184 auto operator->() const { return (*m_collection)[m_idx]; }
185
186 auto& operator++() { m_idx++; return *this; }
187 auto operator++(int) { Iterator tmp = *this; ++(*this); return tmp; }
188
189 auto& operator--() { m_idx--; return *this; }
190 auto operator--(int) { auto temp = *this; --m_idx; return temp; }
191
192 auto& operator+=(difference_type n) { m_idx += n; return *this; }
193 auto& operator-=(difference_type n) { m_idx -= n; return *this; }
194
195 auto operator+(difference_type n) const { return Iterator(m_collection, m_idx + n); }
196 auto operator-(difference_type n) const { return Iterator(m_collection, m_idx - n); }
197
198 auto operator-(const Iterator& other) const { return static_cast<difference_type>(m_idx) - static_cast<difference_type>(other.m_idx); }
199
200 ValueType operator[](difference_type n) const { return (*m_collection)[m_idx + n]; }
201
202 auto operator<=>(const Iterator& other) const { return m_idx <=> other.m_idx; }
203
204 bool operator==(const Iterator& other) const { return m_collection == other.m_collection && m_idx == other.m_idx; }
205
206private:
207 friend Iterator operator+(difference_type n, const Iterator& it) { return it + n; }
208};
209
210template <typename Container, typename SizeFunc, typename GetFunc>
211concept IndexedContainer = requires(const Container& c, SizeFunc size_func, GetFunc get_func, std::size_t i) {
212 { std::invoke(size_func, c) } -> std::convertible_to<std::size_t>;
213 { std::invoke(get_func, c, i) }; // Return type is deduced
214};
215
216template <typename Container, auto SizeFunc, auto GetFunc>
217 requires IndexedContainer<Container, decltype(SizeFunc), decltype(GetFunc)>
218class Range
219{
220public:
221 using value_type = std::invoke_result_t<decltype(GetFunc), const Container&, size_t>;
222 using difference_type = std::ptrdiff_t;
225
226private:
227 const Container* m_container;
228
229public:
230 explicit Range(const Container& container) : m_container(&container)
231 {
232 static_assert(std::ranges::random_access_range<Range>);
233 }
234
235 iterator begin() const { return iterator(this, 0); }
236 iterator end() const { return iterator(this, size()); }
237
238 const_iterator cbegin() const { return begin(); }
239 const_iterator cend() const { return end(); }
240
241 size_t size() const { return std::invoke(SizeFunc, *m_container); }
242
243 bool empty() const { return size() == 0; }
244
245 value_type operator[](size_t index) const { return std::invoke(GetFunc, *m_container, index); }
246
247 value_type at(size_t index) const
248 {
249 if (index >= size()) {
250 throw std::out_of_range("Index out of range");
251 }
252 return (*this)[index];
253 }
254
255 value_type front() const { return (*this)[0]; }
256 value_type back() const { return (*this)[size() - 1]; }
257};
258
259#define MAKE_RANGE_METHOD(method_name, ContainerType, SizeFunc, GetFunc, container_expr) \
260 auto method_name() const & { \
261 return Range<ContainerType, SizeFunc, GetFunc>{container_expr}; \
262 } \
263 auto method_name() const && = delete;
264
265template <typename T>
266std::vector<std::byte> write_bytes(const T* object, int (*to_bytes)(const T*, btck_WriteBytes, void*))
267{
268 std::vector<std::byte> bytes;
269 struct UserData {
270 std::vector<std::byte>* bytes;
271 std::exception_ptr exception;
272 };
273 UserData user_data = UserData{.bytes = &bytes, .exception = nullptr};
274
275 constexpr auto const write = +[](const void* buffer, size_t len, void* user_data) -> int {
276 auto& data = *reinterpret_cast<UserData*>(user_data);
277 auto& bytes = *data.bytes;
278 try {
279 auto const* first = static_cast<const std::byte*>(buffer);
280 auto const* last = first + len;
281 bytes.insert(bytes.end(), first, last);
282 return 0;
283 } catch (...) {
284 data.exception = std::current_exception();
285 return -1;
286 }
287 };
288
289 if (to_bytes(object, write, &user_data) != 0) {
290 std::rethrow_exception(user_data.exception);
291 }
292 return bytes;
293}
294
295template <typename CType>
296class View
297{
298protected:
299 const CType* m_ptr;
300
301public:
302 explicit View(const CType* ptr) : m_ptr{check(ptr)} {}
303
304 const CType* get() const { return m_ptr; }
305};
306
307template <typename CType, CType* (*CopyFunc)(const CType*), void (*DestroyFunc)(CType*)>
309{
310protected:
311 CType* m_ptr;
312
313public:
314 explicit Handle(CType* ptr) : m_ptr{check(ptr)} {}
315
316 // Copy constructors
317 Handle(const Handle& other)
318 : m_ptr{check(CopyFunc(other.m_ptr))} {}
319 Handle& operator=(const Handle& other)
320 {
321 if (this != &other) {
322 Handle temp(other);
323 std::swap(m_ptr, temp.m_ptr);
324 }
325 return *this;
326 }
327
328 // Move constructors
329 Handle(Handle&& other) noexcept : m_ptr(other.m_ptr) { other.m_ptr = nullptr; }
330 Handle& operator=(Handle&& other) noexcept
331 {
332 DestroyFunc(m_ptr);
333 m_ptr = std::exchange(other.m_ptr, nullptr);
334 return *this;
335 }
336
337 template <typename ViewType>
338 requires std::derived_from<ViewType, View<CType>>
339 Handle(const ViewType& view)
340 : Handle{CopyFunc(view.get())}
341 {
342 }
343
344 ~Handle() { DestroyFunc(m_ptr); }
345
346 CType* get() { return m_ptr; }
347 const CType* get() const { return m_ptr; }
348};
349
350template <typename CType, void (*DestroyFunc)(CType*)>
352{
353protected:
354 struct Deleter {
355 void operator()(CType* ptr) const noexcept
356 {
357 if (ptr) DestroyFunc(ptr);
358 }
359 };
360 std::unique_ptr<CType, Deleter> m_ptr;
361
362public:
363 explicit UniqueHandle(CType* ptr) : m_ptr{check(ptr)} {}
364
365 CType* get() { return m_ptr.get(); }
366 const CType* get() const { return m_ptr.get(); }
367};
368
369class Transaction;
370class TransactionOutput;
371
372template <typename Derived>
374{
375private:
376 auto impl() const
377 {
378 return static_cast<const Derived*>(this)->get();
379 }
380
381 friend Derived;
382 ScriptPubkeyApi() = default;
383
384public:
385 bool Verify(int64_t amount,
386 const Transaction& tx_to,
387 std::span<const TransactionOutput> spent_outputs,
388 unsigned int input_index,
390 ScriptVerifyStatus& status) const;
391
392 std::vector<std::byte> ToBytes() const
393 {
395 }
396};
397
398class ScriptPubkeyView : public View<btck_ScriptPubkey>, public ScriptPubkeyApi<ScriptPubkeyView>
399{
400public:
401 explicit ScriptPubkeyView(const btck_ScriptPubkey* ptr) : View{ptr} {}
402};
403
404class ScriptPubkey : public Handle<btck_ScriptPubkey, btck_script_pubkey_copy, btck_script_pubkey_destroy>, public ScriptPubkeyApi<ScriptPubkey>
405{
406public:
407 explicit ScriptPubkey(std::span<const std::byte> raw)
408 : Handle{btck_script_pubkey_create(raw.data(), raw.size())} {}
409
411 : Handle(view) {}
412};
413
414template <typename Derived>
416{
417private:
418 auto impl() const
419 {
420 return static_cast<const Derived*>(this)->get();
421 }
422
423 friend Derived;
425
426public:
427 int64_t Amount() const
428 {
430 }
431
433 {
435 }
436};
437
438class TransactionOutputView : public View<btck_TransactionOutput>, public TransactionOutputApi<TransactionOutputView>
439{
440public:
441 explicit TransactionOutputView(const btck_TransactionOutput* ptr) : View{ptr} {}
442};
443
444class TransactionOutput : public Handle<btck_TransactionOutput, btck_transaction_output_copy, btck_transaction_output_destroy>, public TransactionOutputApi<TransactionOutput>
445{
446public:
447 explicit TransactionOutput(const ScriptPubkey& script_pubkey, int64_t amount)
448 : Handle{btck_transaction_output_create(script_pubkey.get(), amount)} {}
449
451 : Handle(view) {}
452};
453
454template <typename Derived>
456{
457private:
458 auto impl() const
459 {
460 return static_cast<const Derived*>(this)->get();
461 }
462
463 friend Derived;
464 TxidApi() = default;
465
466public:
467 bool operator==(const TxidApi& other) const
468 {
469 return btck_txid_equals(impl(), other.impl()) != 0;
470 }
471
472 bool operator!=(const TxidApi& other) const
473 {
474 return btck_txid_equals(impl(), other.impl()) == 0;
475 }
476
477 std::array<std::byte, 32> ToBytes() const
478 {
479 std::array<std::byte, 32> hash;
480 btck_txid_to_bytes(impl(), reinterpret_cast<unsigned char*>(hash.data()));
481 return hash;
482 }
483};
484
485class TxidView : public View<btck_Txid>, public TxidApi<TxidView>
486{
487public:
488 explicit TxidView(const btck_Txid* ptr) : View{ptr} {}
489};
490
491class Txid : public Handle<btck_Txid, btck_txid_copy, btck_txid_destroy>, public TxidApi<Txid>
492{
493public:
494 Txid(const TxidView& view)
495 : Handle(view) {}
496};
497
498template <typename Derived>
500{
501private:
502 auto impl() const
503 {
504 return static_cast<const Derived*>(this)->get();
505 }
506
507 friend Derived;
508 OutPointApi() = default;
509
510public:
511 uint32_t index() const
512 {
514 }
515
517 {
519 }
520};
521
522class OutPointView : public View<btck_TransactionOutPoint>, public OutPointApi<OutPointView>
523{
524public:
525 explicit OutPointView(const btck_TransactionOutPoint* ptr) : View{ptr} {}
526};
527
528class OutPoint : public Handle<btck_TransactionOutPoint, btck_transaction_out_point_copy, btck_transaction_out_point_destroy>, public OutPointApi<OutPoint>
529{
530public:
532 : Handle(view) {}
533};
534
535template <typename Derived>
537{
538private:
539 auto impl() const
540 {
541 return static_cast<const Derived*>(this)->get();
542 }
543
544 friend Derived;
546
547public:
549 {
551 }
552};
553
554class TransactionInputView : public View<btck_TransactionInput>, public TransactionInputApi<TransactionInputView>
555{
556public:
557 explicit TransactionInputView(const btck_TransactionInput* ptr) : View{ptr} {}
558};
559
560class TransactionInput : public Handle<btck_TransactionInput, btck_transaction_input_copy, btck_transaction_input_destroy>, public TransactionInputApi<TransactionInput>
561{
562public:
564 : Handle(view) {}
565};
566
567template <typename Derived>
569{
570private:
571 auto impl() const
572 {
573 return static_cast<const Derived*>(this)->get();
574 }
575
576public:
577 size_t CountOutputs() const
578 {
580 }
581
582 size_t CountInputs() const
583 {
585 }
586
588 {
590 }
591
592 TransactionInputView GetInput(size_t index) const
593 {
595 }
596
598 {
600 }
601
603
605
606 std::vector<std::byte> ToBytes() const
607 {
609 }
610};
611
612class TransactionView : public View<btck_Transaction>, public TransactionApi<TransactionView>
613{
614public:
615 explicit TransactionView(const btck_Transaction* ptr) : View{ptr} {}
616};
617
618class Transaction : public Handle<btck_Transaction, btck_transaction_copy, btck_transaction_destroy>, public TransactionApi<Transaction>
619{
620public:
621 explicit Transaction(std::span<const std::byte> raw_transaction)
622 : Handle{btck_transaction_create(raw_transaction.data(), raw_transaction.size())} {}
623
625 : Handle{view} {}
626};
627
628template <typename Derived>
630 const Transaction& tx_to,
631 const std::span<const TransactionOutput> spent_outputs,
632 unsigned int input_index,
634 ScriptVerifyStatus& status) const
635{
636 const btck_TransactionOutput** spent_outputs_ptr = nullptr;
637 std::vector<const btck_TransactionOutput*> raw_spent_outputs;
638 if (spent_outputs.size() > 0) {
639 raw_spent_outputs.reserve(spent_outputs.size());
640
641 for (const auto& output : spent_outputs) {
642 raw_spent_outputs.push_back(output.get());
643 }
644 spent_outputs_ptr = raw_spent_outputs.data();
645 }
646 auto result = btck_script_pubkey_verify(
647 impl(),
648 amount,
649 tx_to.get(),
650 spent_outputs_ptr, spent_outputs.size(),
651 input_index,
653 reinterpret_cast<btck_ScriptVerifyStatus*>(&status));
654 return result == 1;
655}
656
657template <typename Derived>
659{
660private:
661 auto impl() const
662 {
663 return static_cast<const Derived*>(this)->get();
664 }
665
666public:
667 bool operator==(const Derived& other) const
668 {
669 return btck_block_hash_equals(impl(), other.get()) != 0;
670 }
671
672 bool operator!=(const Derived& other) const
673 {
674 return btck_block_hash_equals(impl(), other.get()) == 0;
675 }
676
677 std::array<std::byte, 32> ToBytes() const
678 {
679 std::array<std::byte, 32> hash;
680 btck_block_hash_to_bytes(impl(), reinterpret_cast<unsigned char*>(hash.data()));
681 return hash;
682 }
683};
684
685class BlockHashView: public View<btck_BlockHash>, public BlockHashApi<BlockHashView>
686{
687public:
688 explicit BlockHashView(const btck_BlockHash* ptr) : View{ptr} {}
689};
690
691class BlockHash : public Handle<btck_BlockHash, btck_block_hash_copy, btck_block_hash_destroy>, public BlockHashApi<BlockHash>
692{
693public:
694 explicit BlockHash(const std::array<std::byte, 32>& hash)
695 : Handle{btck_block_hash_create(reinterpret_cast<const unsigned char*>(hash.data()))} {}
696
697 explicit BlockHash(btck_BlockHash* hash)
698 : Handle{hash} {}
699
701 : Handle{view} {}
702};
703
704class Block : public Handle<btck_Block, btck_block_copy, btck_block_destroy>
705{
706public:
707 Block(const std::span<const std::byte> raw_block)
708 : Handle{btck_block_create(raw_block.data(), raw_block.size())}
709 {
710 }
711
712 Block(btck_Block* block) : Handle{block} {}
713
714 size_t CountTransactions() const
715 {
717 }
718
719 TransactionView GetTransaction(size_t index) const
720 {
722 }
723
725
727 {
729 }
730
731 std::vector<std::byte> ToBytes() const
732 {
734 }
735};
736
737inline void logging_disable()
738{
740}
741
742inline void logging_set_options(const btck_LoggingOptions& logging_options)
743{
744 btck_logging_set_options(logging_options);
745}
746
748{
749 btck_logging_set_level_category(static_cast<btck_LogCategory>(category), static_cast<btck_LogLevel>(level));
750}
751
753{
754 btck_logging_enable_category(static_cast<btck_LogCategory>(category));
755}
756
758{
759 btck_logging_disable_category(static_cast<btck_LogCategory>(category));
760}
761
762template <typename T>
763concept Log = requires(T a, std::string_view message) {
764 { a.LogMessage(message) } -> std::same_as<void>;
765};
766
767template <Log T>
768class Logger : UniqueHandle<btck_LoggingConnection, btck_logging_connection_destroy>
769{
770public:
771 Logger(std::unique_ptr<T> log)
773 +[](void* user_data, const char* message, size_t message_len) { static_cast<T*>(user_data)->LogMessage({message, message_len}); },
774 log.release(),
775 +[](void* user_data) { delete static_cast<T*>(user_data); })}
776 {
777 }
778};
779
780class BlockTreeEntry : public View<btck_BlockTreeEntry>
781{
782public:
784 : View{entry}
785 {
786 }
787
788 std::optional<BlockTreeEntry> GetPrevious() const
789 {
790 auto entry{btck_block_tree_entry_get_previous(get())};
791 if (!entry) return std::nullopt;
792 return entry;
793 }
794
795 int32_t GetHeight() const
796 {
798 }
799
801 {
803 }
804};
805
807{
808public:
809 virtual ~KernelNotifications() = default;
810
811 virtual void BlockTipHandler(SynchronizationState state, BlockTreeEntry entry, double verification_progress) {}
812
813 virtual void HeaderTipHandler(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) {}
814
815 virtual void ProgressHandler(std::string_view title, int progress_percent, bool resume_possible) {}
816
817 virtual void WarningSetHandler(Warning warning, std::string_view message) {}
818
819 virtual void WarningUnsetHandler(Warning warning) {}
820
821 virtual void FlushErrorHandler(std::string_view error) {}
822
823 virtual void FatalErrorHandler(std::string_view error) {}
824};
825
827{
828private:
830
831public:
832 BlockValidationState(const btck_BlockValidationState* state) : m_state{state} {}
833
838
840 {
842 }
843
845 {
847 }
848};
849
851{
852public:
853 virtual ~ValidationInterface() = default;
854
855 virtual void BlockChecked(Block block, const BlockValidationState state) {}
856
857 virtual void PowValidBlock(BlockTreeEntry entry, Block block) {}
858
859 virtual void BlockConnected(Block block, BlockTreeEntry entry) {}
860
861 virtual void BlockDisconnected(Block block, BlockTreeEntry entry) {}
862};
863
864class ChainParams : public Handle<btck_ChainParameters, btck_chain_parameters_copy, btck_chain_parameters_destroy>
865{
866public:
868 : Handle{btck_chain_parameters_create(static_cast<btck_ChainType>(chain_type))} {}
869};
870
871class ContextOptions : public UniqueHandle<btck_ContextOptions, btck_context_options_destroy>
872{
873public:
875
876 void SetChainParams(ChainParams& chain_params)
877 {
878 btck_context_options_set_chainparams(get(), chain_params.get());
879 }
880
881 template <typename T>
882 void SetNotifications(std::shared_ptr<T> notifications)
883 {
884 static_assert(std::is_base_of_v<KernelNotifications, T>);
885 auto heap_notifications = std::make_unique<std::shared_ptr<T>>(std::move(notifications));
886 using user_type = std::shared_ptr<T>*;
888 get(),
890 .user_data = heap_notifications.release(),
891 .user_data_destroy = +[](void* user_data) { delete static_cast<user_type>(user_data); },
892 .block_tip = +[](void* user_data, btck_SynchronizationState state, const btck_BlockTreeEntry* entry, double verification_progress) { (*static_cast<user_type>(user_data))->BlockTipHandler(static_cast<SynchronizationState>(state), BlockTreeEntry{entry}, verification_progress); },
893 .header_tip = +[](void* user_data, btck_SynchronizationState state, int64_t height, int64_t timestamp, int presync) { (*static_cast<user_type>(user_data))->HeaderTipHandler(static_cast<SynchronizationState>(state), height, timestamp, presync == 1); },
894 .progress = +[](void* user_data, const char* title, size_t title_len, int progress_percent, int resume_possible) { (*static_cast<user_type>(user_data))->ProgressHandler({title, title_len}, progress_percent, resume_possible == 1); },
895 .warning_set = +[](void* user_data, btck_Warning warning, const char* message, size_t message_len) { (*static_cast<user_type>(user_data))->WarningSetHandler(static_cast<Warning>(warning), {message, message_len}); },
896 .warning_unset = +[](void* user_data, btck_Warning warning) { (*static_cast<user_type>(user_data))->WarningUnsetHandler(static_cast<Warning>(warning)); },
897 .flush_error = +[](void* user_data, const char* error, size_t error_len) { (*static_cast<user_type>(user_data))->FlushErrorHandler({error, error_len}); },
898 .fatal_error = +[](void* user_data, const char* error, size_t error_len) { (*static_cast<user_type>(user_data))->FatalErrorHandler({error, error_len}); },
899 });
900 }
901
902 template <typename T>
903 void SetValidationInterface(std::shared_ptr<T> validation_interface)
904 {
905 static_assert(std::is_base_of_v<ValidationInterface, T>);
906 auto heap_vi = std::make_unique<std::shared_ptr<T>>(std::move(validation_interface));
907 using user_type = std::shared_ptr<T>*;
909 get(),
911 .user_data = heap_vi.release(),
912 .user_data_destroy = +[](void* user_data) { delete static_cast<user_type>(user_data); },
913 .block_checked = +[](void* user_data, btck_Block* block, const btck_BlockValidationState* state) { (*static_cast<user_type>(user_data))->BlockChecked(Block{block}, BlockValidationState{state}); },
914 .pow_valid_block = +[](void* user_data, btck_Block* block, const btck_BlockTreeEntry* entry) { (*static_cast<user_type>(user_data))->PowValidBlock(BlockTreeEntry{entry}, Block{block}); },
915 .block_connected = +[](void* user_data, btck_Block* block, const btck_BlockTreeEntry* entry) { (*static_cast<user_type>(user_data))->BlockConnected(Block{block}, BlockTreeEntry{entry}); },
916 .block_disconnected = +[](void* user_data, btck_Block* block, const btck_BlockTreeEntry* entry) { (*static_cast<user_type>(user_data))->BlockDisconnected(Block{block}, BlockTreeEntry{entry}); },
917 });
918 }
919};
920
921class Context : public Handle<btck_Context, btck_context_copy, btck_context_destroy>
922{
923public:
925 : Handle{btck_context_create(opts.get())} {}
926
929
931 {
932 return btck_context_interrupt(get()) == 0;
933 }
934};
935
936class ChainstateManagerOptions : public UniqueHandle<btck_ChainstateManagerOptions, btck_chainstate_manager_options_destroy>
937{
938public:
939 ChainstateManagerOptions(const Context& context, const std::string& data_dir, const std::string& blocks_dir)
940 : UniqueHandle{btck_chainstate_manager_options_create(context.get(), data_dir.c_str(), data_dir.length(), blocks_dir.c_str(), blocks_dir.length())}
941 {
942 }
943
944 void SetWorkerThreads(int worker_threads)
945 {
947 }
948
949 bool SetWipeDbs(bool wipe_block_tree, bool wipe_chainstate)
950 {
951 return btck_chainstate_manager_options_set_wipe_dbs(get(), wipe_block_tree, wipe_chainstate) == 0;
952 }
953
954 void UpdateBlockTreeDbInMemory(bool block_tree_db_in_memory)
955 {
957 }
958
959 void UpdateChainstateDbInMemory(bool chainstate_db_in_memory)
960 {
962 }
963};
964
965class ChainView : public View<btck_Chain>
966{
967public:
968 explicit ChainView(const btck_Chain* ptr) : View{ptr} {}
969
971 {
972 return btck_chain_get_tip(get());
973 }
974
975 int32_t Height() const
976 {
977 return btck_chain_get_height(get());
978 }
979
980 int CountEntries() const
981 {
982 return btck_chain_get_height(get()) + 1;
983 }
984
986 {
987 return btck_chain_get_genesis(get());
988 }
989
990 BlockTreeEntry GetByHeight(int height) const
991 {
992 auto index{btck_chain_get_by_height(get(), height)};
993 if (!index) throw std::runtime_error("No entry in the chain at the provided height");
994 return index;
995 }
996
997 bool Contains(BlockTreeEntry& entry) const
998 {
999 return btck_chain_contains(get(), entry.get());
1000 }
1001
1002 MAKE_RANGE_METHOD(Entries, ChainView, &ChainView::CountEntries, &ChainView::GetByHeight, *this)
1003};
1004
1005template <typename Derived>
1007{
1008private:
1009 auto impl() const
1010 {
1011 return static_cast<const Derived*>(this)->get();
1012 }
1013
1014 friend Derived;
1015 CoinApi() = default;
1016
1017public:
1018 uint32_t GetConfirmationHeight() const { return btck_coin_confirmation_height(impl()); }
1019
1020 bool IsCoinbase() const { return btck_coin_is_coinbase(impl()) == 1; }
1021
1023 {
1025 }
1026};
1027
1028class CoinView : public View<btck_Coin>, public CoinApi<CoinView>
1029{
1030public:
1031 explicit CoinView(const btck_Coin* ptr) : View{ptr} {}
1032};
1033
1034class Coin : public Handle<btck_Coin, btck_coin_copy, btck_coin_destroy>, public CoinApi<Coin>
1035{
1036public:
1037 Coin(btck_Coin* coin) : Handle{coin} {}
1038
1039 Coin(const CoinView& view) : Handle{view} {}
1040};
1041
1042template <typename Derived>
1044{
1045private:
1046 auto impl() const
1047 {
1048 return static_cast<const Derived*>(this)->get();
1049 }
1050
1051 friend Derived;
1053
1054public:
1055 size_t Count() const
1056 {
1058 }
1059
1060 CoinView GetCoin(size_t index) const
1061 {
1063 }
1064
1066};
1067
1068class TransactionSpentOutputsView : public View<btck_TransactionSpentOutputs>, public TransactionSpentOutputsApi<TransactionSpentOutputsView>
1069{
1070public:
1072};
1073
1074class TransactionSpentOutputs : public Handle<btck_TransactionSpentOutputs, btck_transaction_spent_outputs_copy, btck_transaction_spent_outputs_destroy>,
1075 public TransactionSpentOutputsApi<TransactionSpentOutputs>
1076{
1077public:
1078 TransactionSpentOutputs(btck_TransactionSpentOutputs* transaction_spent_outputs) : Handle{transaction_spent_outputs} {}
1079
1081};
1082
1083class BlockSpentOutputs : public Handle<btck_BlockSpentOutputs, btck_block_spent_outputs_copy, btck_block_spent_outputs_destroy>
1084{
1085public:
1087 : Handle{block_spent_outputs}
1088 {
1089 }
1090
1091 size_t Count() const
1092 {
1093 return btck_block_spent_outputs_count(get());
1094 }
1095
1097 {
1099 }
1100
1101 MAKE_RANGE_METHOD(TxsSpentOutputs, BlockSpentOutputs, &BlockSpentOutputs::Count, &BlockSpentOutputs::GetTxSpentOutputs, *this)
1102};
1103
1104class ChainMan : UniqueHandle<btck_ChainstateManager, btck_chainstate_manager_destroy>
1105{
1106public:
1107 ChainMan(const Context& context, const ChainstateManagerOptions& chainman_opts)
1108 : UniqueHandle{btck_chainstate_manager_create(chainman_opts.get())}
1109 {
1110 }
1111
1112 bool ImportBlocks(const std::span<const std::string> paths)
1113 {
1114 std::vector<const char*> c_paths;
1115 std::vector<size_t> c_paths_lens;
1116 c_paths.reserve(paths.size());
1117 c_paths_lens.reserve(paths.size());
1118 for (const auto& path : paths) {
1119 c_paths.push_back(path.c_str());
1120 c_paths_lens.push_back(path.length());
1121 }
1122
1123 return btck_chainstate_manager_import_blocks(get(), c_paths.data(), c_paths_lens.data(), c_paths.size()) == 0;
1124 }
1125
1126 bool ProcessBlock(const Block& block, bool* new_block)
1127 {
1128 int _new_block;
1129 int res = btck_chainstate_manager_process_block(get(), block.get(), &_new_block);
1130 if (new_block) *new_block = _new_block == 1;
1131 return res == 0;
1132 }
1133
1135 {
1137 }
1138
1139 std::optional<BlockTreeEntry> GetBlockTreeEntry(const BlockHash& block_hash) const
1140 {
1141 auto entry{btck_chainstate_manager_get_block_tree_entry_by_hash(get(), block_hash.get())};
1142 if (!entry) return std::nullopt;
1143 return entry;
1144 }
1145
1146 std::optional<Block> ReadBlock(const BlockTreeEntry& entry) const
1147 {
1148 auto block{btck_block_read(get(), entry.get())};
1149 if (!block) return std::nullopt;
1150 return block;
1151 }
1152
1154 {
1155 return btck_block_spent_outputs_read(get(), entry.get());
1156 }
1157};
1158
1159} // namespace btck
1160
1161#endif // BITCOIN_KERNEL_BITCOINKERNEL_WRAPPER_H
int flags
Definition: bitcoin-tx.cpp:529
int btck_block_to_bytes(const btck_Block *block, btck_WriteBytes writer, void *user_data)
void btck_logging_disable()
This disables the global internal logger.
int btck_script_pubkey_to_bytes(const btck_ScriptPubkey *script_pubkey_, btck_WriteBytes writer, void *user_data)
int btck_chainstate_manager_import_blocks(btck_ChainstateManager *chainman, const char **block_file_paths_data, size_t *block_file_paths_lens, size_t block_file_paths_data_len)
Triggers the start of a reindex if the wipe options were previously set for the chainstate manager.
const btck_Coin * btck_transaction_spent_outputs_get_coin_at(const btck_TransactionSpentOutputs *transaction_spent_outputs, size_t coin_index)
Returns a coin contained in the transaction spent outputs at a certain index.
const btck_TransactionInput * btck_transaction_get_input_at(const btck_Transaction *transaction, size_t input_index)
Get the transaction input at the provided index.
void btck_logging_enable_category(btck_LogCategory category)
Enable a specific log category for the global internal logger.
uint32_t btck_coin_confirmation_height(const btck_Coin *coin)
Returns the block height where the transaction that created this coin was included in.
void btck_context_options_set_notifications(btck_ContextOptions *options, btck_NotificationInterfaceCallbacks notifications)
Set the kernel notifications for the context options.
btck_ContextOptions * btck_context_options_create()
Creates an empty context options.
int64_t btck_transaction_output_get_amount(const btck_TransactionOutput *output)
Get the amount in the output.
void btck_chainstate_manager_options_update_chainstate_db_in_memory(btck_ChainstateManagerOptions *chainman_opts, int chainstate_db_in_memory)
Sets chainstate db in memory in the options.
const btck_Txid * btck_transaction_out_point_get_txid(const btck_TransactionOutPoint *out_point)
Get the txid from the transaction out point.
void btck_logging_disable_category(btck_LogCategory category)
Disable a specific log category for the global internal logger.
const btck_BlockTreeEntry * btck_block_tree_entry_get_previous(const btck_BlockTreeEntry *entry)
Returns the previous block tree entry in the tree, or null if the current block tree entry is the gen...
size_t btck_transaction_count_outputs(const btck_Transaction *transaction)
Get the number of outputs of a transaction.
btck_ScriptPubkey * btck_script_pubkey_create(const void *script_pubkey, size_t script_pubkey_len)
Create a script pubkey from serialized data.
btck_ChainParameters * btck_chain_parameters_create(const btck_ChainType chain_type)
Creates a chain parameters struct with default parameters based on the passed in chain type.
btck_ValidationMode btck_block_validation_state_get_validation_mode(const btck_BlockValidationState *block_validation_state_)
Returns the validation mode from an opaque block validation state pointer.
btck_Block * btck_block_create(const void *raw_block, size_t raw_block_length)
Parse a serialized raw block into a new block object.
void btck_chainstate_manager_options_update_block_tree_db_in_memory(btck_ChainstateManagerOptions *chainman_opts, int block_tree_db_in_memory)
Sets block tree db in memory in the options.
size_t btck_block_count_transactions(const btck_Block *block)
Count the number of transactions contained in a block.
btck_LoggingConnection * btck_logging_connection_create(btck_LogCallback callback, void *user_data, btck_DestroyCallback user_data_destroy_callback)
Start logging messages through the provided callback.
const btck_TransactionOutPoint * btck_transaction_input_get_out_point(const btck_TransactionInput *input)
Get the transaction out point.
btck_BlockSpentOutputs * btck_block_spent_outputs_read(const btck_ChainstateManager *chainman, const btck_BlockTreeEntry *entry)
btck_ChainstateManager * btck_chainstate_manager_create(const btck_ChainstateManagerOptions *chainman_opts)
Create a chainstate manager.
btck_BlockHash * btck_block_get_hash(const btck_Block *block)
Calculate and return the hash of a block.
const btck_TransactionSpentOutputs * btck_block_spent_outputs_get_transaction_spent_outputs_at(const btck_BlockSpentOutputs *block_spent_outputs, size_t transaction_index)
Returns a transaction spent outputs contained in the block spent outputs at a certain index.
btck_Context * btck_context_create(const btck_ContextOptions *options)
Create a new kernel context.
const btck_TransactionOutput * btck_coin_get_output(const btck_Coin *coin)
Return the transaction output of a coin.
int btck_coin_is_coinbase(const btck_Coin *coin)
Returns whether the containing transaction was a coinbase.
void btck_txid_to_bytes(const btck_Txid *txid, unsigned char output[32])
int btck_script_pubkey_verify(const btck_ScriptPubkey *script_pubkey, const int64_t amount, const btck_Transaction *tx_to, const btck_TransactionOutput **spent_outputs_, size_t spent_outputs_len, const unsigned int input_index, const btck_ScriptVerificationFlags flags, btck_ScriptVerifyStatus *status)
int btck_chainstate_manager_options_set_wipe_dbs(btck_ChainstateManagerOptions *chainman_opts, int wipe_block_tree_db, int wipe_chainstate_db)
Sets wipe db in the options.
int btck_context_interrupt(btck_Context *context)
Interrupt can be used to halt long-running validation functions like when reindexing,...
const btck_TransactionOutput * btck_transaction_get_output_at(const btck_Transaction *transaction, size_t output_index)
Get the transaction outputs at the provided index.
void btck_logging_set_level_category(btck_LogCategory category, btck_LogLevel level)
Set the log level of the global internal logger.
void btck_context_options_set_chainparams(btck_ContextOptions *options, const btck_ChainParameters *chain_parameters)
const btck_BlockTreeEntry * btck_chain_get_tip(const btck_Chain *chain)
Get the block tree entry of the current chain tip.
btck_BlockHash * btck_block_hash_create(const unsigned char block_hash[32])
Create a block hash from its raw data.
void btck_context_options_set_validation_interface(btck_ContextOptions *options, btck_ValidationInterfaceCallbacks vi_cbs)
Set the validation interface callbacks for the context options.
uint32_t btck_transaction_out_point_get_index(const btck_TransactionOutPoint *out_point)
Get the output position from the transaction out point.
btck_Block * btck_block_read(const btck_ChainstateManager *chainman, const btck_BlockTreeEntry *entry)
const btck_Txid * btck_transaction_get_txid(const btck_Transaction *transaction)
Get the txid of a transaction.
int btck_chain_contains(const btck_Chain *chain, const btck_BlockTreeEntry *entry)
const btck_BlockTreeEntry * btck_chainstate_manager_get_block_tree_entry_by_hash(const btck_ChainstateManager *chainman, const btck_BlockHash *block_hash)
size_t btck_block_spent_outputs_count(const btck_BlockSpentOutputs *block_spent_outputs)
Returns the number of transaction spent outputs whose data is contained in block spent outputs.
const btck_BlockTreeEntry * btck_chain_get_by_height(const btck_Chain *chain, int height)
Retrieve a block tree entry by its height in the currently active chain.
int btck_block_hash_equals(const btck_BlockHash *hash1, const btck_BlockHash *hash2)
int32_t btck_block_tree_entry_get_height(const btck_BlockTreeEntry *entry)
Return the height of a certain block tree entry.
const btck_ScriptPubkey * btck_transaction_output_get_script_pubkey(const btck_TransactionOutput *output)
Get the script pubkey of the output.
int btck_chainstate_manager_process_block(btck_ChainstateManager *chainman, const btck_Block *block, int *_new_block)
size_t btck_transaction_count_inputs(const btck_Transaction *transaction)
Get the number of inputs of a transaction.
int btck_chain_get_height(const btck_Chain *chain)
Return the height of the tip of the chain.
int btck_txid_equals(const btck_Txid *txid1, const btck_Txid *txid2)
btck_Transaction * btck_transaction_create(const void *raw_transaction, size_t raw_transaction_len)
Create a new transaction from the serialized data.
const btck_BlockHash * btck_block_tree_entry_get_block_hash(const btck_BlockTreeEntry *entry)
Return the block hash associated with a block tree entry.
void btck_logging_set_options(const btck_LoggingOptions options)
Set some options for the global internal logger.
void btck_chainstate_manager_options_set_worker_threads_num(btck_ChainstateManagerOptions *opts, int worker_threads)
Set the number of available worker threads used during validation.
int btck_transaction_to_bytes(const btck_Transaction *transaction, btck_WriteBytes writer, void *user_data)
btck_TransactionOutput * btck_transaction_output_create(const btck_ScriptPubkey *script_pubkey, int64_t amount)
Create a transaction output from a script pubkey and an amount.
const btck_BlockTreeEntry * btck_chain_get_genesis(const btck_Chain *chain)
Get the block tree entry of the genesis block.
const btck_Transaction * btck_block_get_transaction_at(const btck_Block *block, size_t index)
Get the transaction at the provided index.
const btck_Chain * btck_chainstate_manager_get_active_chain(const btck_ChainstateManager *chainman)
Returns the best known currently active chain.
btck_ChainstateManagerOptions * btck_chainstate_manager_options_create(const btck_Context *context, const char *data_dir, size_t data_dir_len, const char *blocks_dir, size_t blocks_dir_len)
btck_BlockValidationResult btck_block_validation_state_get_block_validation_result(const btck_BlockValidationState *block_validation_state_)
Returns the validation result from an opaque block validation state pointer.
void btck_block_hash_to_bytes(const btck_BlockHash *block_hash, unsigned char output[32])
size_t btck_transaction_spent_outputs_count(const btck_TransactionSpentOutputs *transaction_spent_outputs)
Returns the number of previous transaction outputs contained in the transaction spent outputs data.
#define btck_ChainType_REGTEST
#define btck_ScriptVerificationFlags_P2SH
evaluate P2SH (BIP16) subscripts
uint8_t btck_LogLevel
The level at which logs should be produced.
#define btck_ScriptVerificationFlags_CHECKLOCKTIMEVERIFY
enable CHECKLOCKTIMEVERIFY (BIP65)
int(* btck_WriteBytes)(const void *bytes, size_t size, void *userdata)
Function signature for serializing data.
#define btck_ChainType_MAINNET
#define btck_BlockValidationResult_HEADER_LOW_WORK
the block header may be on a too-little-work chain
#define btck_Warning_UNKNOWN_NEW_RULES_ACTIVATED
uint8_t btck_ChainType
#define btck_BlockValidationResult_INVALID_PREV
A block this one builds on is invalid.
#define btck_LogCategory_MEMPOOL
#define btck_LogLevel_TRACE
#define btck_ChainType_TESTNET
#define btck_SynchronizationState_INIT_REINDEX
#define btck_ScriptVerifyStatus_ERROR_INVALID_FLAGS_COMBINATION
The flags were combined in an invalid way.
uint32_t btck_BlockValidationResult
A granular "reason" why a block was invalid.
#define btck_LogCategory_BENCH
uint8_t btck_ValidationMode
Whether a validated data structure is valid, invalid, or an error was encountered during processing.
#define btck_ScriptVerificationFlags_ALL
#define btck_LogCategory_PRUNE
uint8_t btck_SynchronizationState
Current sync state passed to tip changed callbacks.
#define btck_ChainType_TESTNET_4
#define btck_LogCategory_COINDB
#define btck_ScriptVerificationFlags_TAPROOT
enable TAPROOT (BIPs 341 & 342)
#define btck_ScriptVerifyStatus_ERROR_SPENT_OUTPUTS_REQUIRED
The taproot flag was set, so valid spent_outputs have to be provided.
#define btck_ScriptVerificationFlags_WITNESS
enable WITNESS (BIP141)
uint32_t btck_ScriptVerificationFlags
Script verification flags that may be composed with each other.
#define btck_LogCategory_VALIDATION
#define btck_LogCategory_REINDEX
#define btck_LogLevel_DEBUG
#define btck_ScriptVerifyStatus_OK
#define btck_ScriptVerificationFlags_NONE
#define btck_LogCategory_RAND
#define btck_BlockValidationResult_CONSENSUS
invalid by consensus rules (excluding any below reasons)
#define btck_BlockValidationResult_UNSET
initial value. Block has not yet been rejected
#define btck_SynchronizationState_POST_INIT
#define btck_BlockValidationResult_MISSING_PREV
We don't have the previous block the checked one is built on.
#define btck_LogCategory_ALL
uint8_t btck_ScriptVerifyStatus
A collection of status codes that may be issued by the script verify function.
#define btck_ValidationMode_INTERNAL_ERROR
uint8_t btck_LogCategory
A collection of logging categories that may be encountered by kernel code.
#define btck_ValidationMode_INVALID
#define btck_ChainType_SIGNET
#define btck_ScriptVerificationFlags_NULLDUMMY
enforce NULLDUMMY (BIP147)
#define btck_BlockValidationResult_INVALID_HEADER
invalid proof of work or time too old
uint8_t btck_Warning
Possible warning types issued by validation.
#define btck_BlockValidationResult_TIME_FUTURE
block timestamp was > 2 hours in the future (or our clock is bad)
#define btck_LogCategory_LEVELDB
#define btck_BlockValidationResult_CACHED_INVALID
this block was cached as being invalid and we didn't store the reason why
#define btck_Warning_LARGE_WORK_INVALID_CHAIN
#define btck_LogLevel_INFO
#define btck_ScriptVerificationFlags_CHECKSEQUENCEVERIFY
enable CHECKSEQUENCEVERIFY (BIP112)
#define btck_LogCategory_BLOCKSTORAGE
#define btck_ValidationMode_VALID
#define btck_LogCategory_KERNEL
#define btck_ScriptVerificationFlags_DERSIG
enforce strict DER (BIP66) compliance
#define btck_BlockValidationResult_MUTATED
the block's data didn't match the data committed to by the PoW
#define btck_SynchronizationState_INIT_DOWNLOAD
#define MAKE_RANGE_METHOD(method_name, ContainerType, SizeFunc, GetFunc, container_expr)
bool operator==(const Derived &other) const
std::array< std::byte, 32 > ToBytes() const
bool operator!=(const Derived &other) const
BlockHash(const std::array< std::byte, 32 > &hash)
BlockHash(btck_BlockHash *hash)
BlockHash(const BlockHashView &view)
BlockHashView(const btck_BlockHash *ptr)
BlockHash GetHash() const
std::vector< std::byte > ToBytes() const
TransactionView GetTransaction(size_t index) const
Block(btck_Block *block)
size_t CountTransactions() const
Block(const std::span< const std::byte > raw_block)
TransactionSpentOutputsView GetTxSpentOutputs(size_t tx_undo_index) const
BlockSpentOutputs(btck_BlockSpentOutputs *block_spent_outputs)
int32_t GetHeight() const
BlockTreeEntry(const btck_BlockTreeEntry *entry)
std::optional< BlockTreeEntry > GetPrevious() const
BlockHashView GetHash() const
BlockValidationResult GetBlockValidationResult() const
BlockValidationState(BlockValidationState &&)=delete
BlockValidationState(const btck_BlockValidationState *state)
BlockValidationState & operator=(BlockValidationState &&)=delete
BlockValidationState & operator=(const BlockValidationState &)=delete
ValidationMode GetValidationMode() const
BlockValidationState(const BlockValidationState &)=delete
const btck_BlockValidationState * m_state
std::optional< BlockTreeEntry > GetBlockTreeEntry(const BlockHash &block_hash) const
std::optional< Block > ReadBlock(const BlockTreeEntry &entry) const
BlockSpentOutputs ReadBlockSpentOutputs(const BlockTreeEntry &entry) const
ChainView GetChain() const
ChainMan(const Context &context, const ChainstateManagerOptions &chainman_opts)
bool ImportBlocks(const std::span< const std::string > paths)
bool ProcessBlock(const Block &block, bool *new_block)
ChainParams(ChainType chain_type)
ChainView(const btck_Chain *ptr)
BlockTreeEntry GetByHeight(int height) const
BlockTreeEntry Tip() const
int32_t Height() const
bool Contains(BlockTreeEntry &entry) const
BlockTreeEntry Genesis() const
ChainstateManagerOptions(const Context &context, const std::string &data_dir, const std::string &blocks_dir)
void SetWorkerThreads(int worker_threads)
void UpdateBlockTreeDbInMemory(bool block_tree_db_in_memory)
void UpdateChainstateDbInMemory(bool chainstate_db_in_memory)
bool SetWipeDbs(bool wipe_block_tree, bool wipe_chainstate)
CoinApi()=default
uint32_t GetConfirmationHeight() const
TransactionOutputView GetOutput() const
Coin(const CoinView &view)
Coin(btck_Coin *coin)
CoinView(const btck_Coin *ptr)
Context(ContextOptions &opts)
void SetValidationInterface(std::shared_ptr< T > validation_interface)
void SetChainParams(ChainParams &chain_params)
void SetNotifications(std::shared_ptr< T > notifications)
Handle & operator=(const Handle &other)
Handle & operator=(Handle &&other) noexcept
Handle(const ViewType &view)
Handle(Handle &&other) noexcept
const CType * get() const
Handle(const Handle &other)
std::random_access_iterator_tag iterator_category
auto operator-(difference_type n) const
auto operator+(difference_type n) const
Iterator(const Collection *ptr)
auto & operator-=(difference_type n)
Iterator()=default
const Collection * m_collection
auto operator<=>(const Iterator &other) const
std::random_access_iterator_tag iterator_concept
friend Iterator operator+(difference_type n, const Iterator &it)
Iterator(const Collection *ptr, size_t idx)
auto & operator+=(difference_type n)
auto operator-(const Iterator &other) const
bool operator==(const Iterator &other) const
std::ptrdiff_t difference_type
ValueType operator[](difference_type n) const
virtual void FatalErrorHandler(std::string_view error)
virtual void WarningSetHandler(Warning warning, std::string_view message)
virtual void BlockTipHandler(SynchronizationState state, BlockTreeEntry entry, double verification_progress)
virtual ~KernelNotifications()=default
virtual void ProgressHandler(std::string_view title, int progress_percent, bool resume_possible)
virtual void WarningUnsetHandler(Warning warning)
virtual void FlushErrorHandler(std::string_view error)
virtual void HeaderTipHandler(SynchronizationState state, int64_t height, int64_t timestamp, bool presync)
Logger(std::unique_ptr< T > log)
OutPointApi()=default
uint32_t index() const
OutPoint(const OutPointView &view)
OutPointView(const btck_TransactionOutPoint *ptr)
Iterator< Range, value_type > iterator
bool empty() const
const Container * m_container
value_type front() const
const_iterator cbegin() const
value_type operator[](size_t index) const
Range(const Container &container)
size_t size() const
const_iterator cend() const
std::ptrdiff_t difference_type
iterator begin() const
iterator end() const
value_type back() const
value_type at(size_t index) const
std::invoke_result_t< decltype(GetFunc), const Container &, size_t > value_type
bool Verify(int64_t amount, const Transaction &tx_to, std::span< const TransactionOutput > spent_outputs, unsigned int input_index, ScriptVerificationFlags flags, ScriptVerifyStatus &status) const
std::vector< std::byte > ToBytes() const
ScriptPubkey(std::span< const std::byte > raw)
ScriptPubkey(const ScriptPubkeyView &view)
ScriptPubkeyView(const btck_ScriptPubkey *ptr)
TransactionInputView GetInput(size_t index) const
TransactionOutputView GetOutput(size_t index) const
std::vector< std::byte > ToBytes() const
Transaction(std::span< const std::byte > raw_transaction)
Transaction(const TransactionView &view)
TransactionInput(const TransactionInputView &view)
TransactionInputView(const btck_TransactionInput *ptr)
ScriptPubkeyView GetScriptPubkey() const
TransactionOutput(const TransactionOutputView &view)
TransactionOutput(const ScriptPubkey &script_pubkey, int64_t amount)
TransactionOutputView(const btck_TransactionOutput *ptr)
CoinView GetCoin(size_t index) const
TransactionSpentOutputs(btck_TransactionSpentOutputs *transaction_spent_outputs)
TransactionSpentOutputs(const TransactionSpentOutputsView &view)
TransactionSpentOutputsView(const btck_TransactionSpentOutputs *ptr)
TransactionView(const btck_Transaction *ptr)
bool operator==(const TxidApi &other) const
std::array< std::byte, 32 > ToBytes() const
TxidApi()=default
bool operator!=(const TxidApi &other) const
Txid(const TxidView &view)
TxidView(const btck_Txid *ptr)
const CType * get() const
std::unique_ptr< CType, Deleter > m_ptr
virtual void BlockChecked(Block block, const BlockValidationState state)
virtual void PowValidBlock(BlockTreeEntry entry, Block block)
virtual void BlockConnected(Block block, BlockTreeEntry entry)
virtual ~ValidationInterface()=default
virtual void BlockDisconnected(Block block, BlockTreeEntry entry)
const CType * get() const
const CType * m_ptr
View(const CType *ptr)
#define T(expected, seed, data)
constexpr T & operator|=(T &lhs, T rhs)
constexpr T & operator&=(T &lhs, T rhs)
constexpr T operator~(T value)
std::vector< std::byte > write_bytes(const T *object, int(*to_bytes)(const T *, btck_WriteBytes, void *))
void logging_set_options(const btck_LoggingOptions &logging_options)
constexpr T operator&(T lhs, T rhs)
constexpr T operator|(T lhs, T rhs)
void logging_set_level_category(LogCategory category, LogLevel level)
@ UNKNOWN_NEW_RULES_ACTIVATED
@ LARGE_WORK_INVALID_CHAIN
void logging_enable_category(LogCategory category)
constexpr T operator^(T lhs, T rhs)
void logging_disable_category(LogCategory category)
T check(T ptr)
void logging_disable()
constexpr T & operator^=(T &lhs, T rhs)
@ OK
The message verification was successful.
void operator()(CType *ptr) const noexcept
Options controlling the format of log messages.
A struct for holding the kernel notification callbacks.
void * user_data
Holds a user-defined opaque structure that is passed to the notification callbacks.
Holds the validation interface callbacks.
void * user_data
Holds a user-defined opaque structure that is passed to the validation interface callbacks.