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 <exception>
12#include <functional>
13#include <memory>
14#include <optional>
15#include <span>
16#include <stdexcept>
17#include <string>
18#include <string_view>
19#include <type_traits>
20#include <utility>
21#include <vector>
22
23namespace btck {
24
28 BLOCKSTORAGE = btck_LogCategory_BLOCKSTORAGE,
35 VALIDATION = btck_LogCategory_VALIDATION,
37};
38
39enum class LogLevel : btck_LogLevel {
43};
44
51};
52
57};
58
59enum class Warning : btck_Warning {
62};
63
68};
69
80};
81
86};
87
98};
99
100template <typename T>
101struct is_bitmask_enum : std::false_type {
102};
103
104template <>
105struct is_bitmask_enum<ScriptVerificationFlags> : std::true_type {
106};
107
108template <typename T>
109concept BitmaskEnum = is_bitmask_enum<T>::value;
110
111template <BitmaskEnum T>
112constexpr T operator|(T lhs, T rhs)
113{
114 return static_cast<T>(
115 static_cast<std::underlying_type_t<T>>(lhs) | static_cast<std::underlying_type_t<T>>(rhs));
116}
117
118template <BitmaskEnum T>
119constexpr T operator&(T lhs, T rhs)
120{
121 return static_cast<T>(
122 static_cast<std::underlying_type_t<T>>(lhs) & static_cast<std::underlying_type_t<T>>(rhs));
123}
124
125template <BitmaskEnum T>
126constexpr T operator^(T lhs, T rhs)
127{
128 return static_cast<T>(
129 static_cast<std::underlying_type_t<T>>(lhs) ^ static_cast<std::underlying_type_t<T>>(rhs));
130}
131
132template <BitmaskEnum T>
133constexpr T operator~(T value)
134{
135 return static_cast<T>(~static_cast<std::underlying_type_t<T>>(value));
136}
137
138template <BitmaskEnum T>
139constexpr T& operator|=(T& lhs, T rhs)
140{
141 return lhs = lhs | rhs;
142}
143
144template <BitmaskEnum T>
145constexpr T& operator&=(T& lhs, T rhs)
146{
147 return lhs = lhs & rhs;
148}
149
150template <BitmaskEnum T>
151constexpr T& operator^=(T& lhs, T rhs)
152{
153 return lhs = lhs ^ rhs;
154}
155
156template <typename T>
157T check(T ptr)
158{
159 if (ptr == nullptr) {
160 throw std::runtime_error("failed to instantiate btck object");
161 }
162 return ptr;
163}
164
165template <typename Collection, typename ValueType>
167{
168public:
169 using iterator_category = std::random_access_iterator_tag;
170 using iterator_concept = std::random_access_iterator_tag;
171 using difference_type = std::ptrdiff_t;
172 using value_type = ValueType;
173
174private:
175 const Collection* m_collection;
176 size_t m_idx;
177
178public:
179 Iterator() = default;
180 Iterator(const Collection* ptr) : m_collection{ptr}, m_idx{0} {}
181 Iterator(const Collection* ptr, size_t idx) : m_collection{ptr}, m_idx{idx} {}
182
183 // This is just a view, so return a copy.
184 auto operator*() const { return (*m_collection)[m_idx]; }
185 auto operator->() const { return (*m_collection)[m_idx]; }
186
187 auto& operator++() { m_idx++; return *this; }
188 auto operator++(int) { Iterator tmp = *this; ++(*this); return tmp; }
189
190 auto& operator--() { m_idx--; return *this; }
191 auto operator--(int) { auto temp = *this; --m_idx; return temp; }
192
193 auto& operator+=(difference_type n) { m_idx += n; return *this; }
194 auto& operator-=(difference_type n) { m_idx -= n; return *this; }
195
196 auto operator+(difference_type n) const { return Iterator(m_collection, m_idx + n); }
197 auto operator-(difference_type n) const { return Iterator(m_collection, m_idx - n); }
198
199 auto operator-(const Iterator& other) const { return static_cast<difference_type>(m_idx) - static_cast<difference_type>(other.m_idx); }
200
201 ValueType operator[](difference_type n) const { return (*m_collection)[m_idx + n]; }
202
203 auto operator<=>(const Iterator& other) const { return m_idx <=> other.m_idx; }
204
205 bool operator==(const Iterator& other) const { return m_collection == other.m_collection && m_idx == other.m_idx; }
206
207private:
208 friend Iterator operator+(difference_type n, const Iterator& it) { return it + n; }
209};
210
211template <typename Container, typename SizeFunc, typename GetFunc>
212concept IndexedContainer = requires(const Container& c, SizeFunc size_func, GetFunc get_func, std::size_t i) {
213 { std::invoke(size_func, c) } -> std::convertible_to<std::size_t>;
214 { std::invoke(get_func, c, i) }; // Return type is deduced
215};
216
217template <typename Container, auto SizeFunc, auto GetFunc>
218 requires IndexedContainer<Container, decltype(SizeFunc), decltype(GetFunc)>
219class Range
220{
221public:
222 using value_type = std::invoke_result_t<decltype(GetFunc), const Container&, size_t>;
223 using difference_type = std::ptrdiff_t;
226
227private:
228 const Container* m_container;
229
230public:
231 explicit Range(const Container& container) : m_container(&container)
232 {
233 static_assert(std::ranges::random_access_range<Range>);
234 }
235
236 iterator begin() const { return iterator(this, 0); }
237 iterator end() const { return iterator(this, size()); }
238
239 const_iterator cbegin() const { return begin(); }
240 const_iterator cend() const { return end(); }
241
242 size_t size() const { return std::invoke(SizeFunc, *m_container); }
243
244 bool empty() const { return size() == 0; }
245
246 value_type operator[](size_t index) const { return std::invoke(GetFunc, *m_container, index); }
247
248 value_type at(size_t index) const
249 {
250 if (index >= size()) {
251 throw std::out_of_range("Index out of range");
252 }
253 return (*this)[index];
254 }
255
256 value_type front() const { return (*this)[0]; }
257 value_type back() const { return (*this)[size() - 1]; }
258};
259
260#define MAKE_RANGE_METHOD(method_name, ContainerType, SizeFunc, GetFunc, container_expr) \
261 auto method_name() const & { \
262 return Range<ContainerType, SizeFunc, GetFunc>{container_expr}; \
263 } \
264 auto method_name() const && = delete;
265
266template <typename T>
267std::vector<std::byte> write_bytes(const T* object, int (*to_bytes)(const T*, btck_WriteBytes, void*))
268{
269 std::vector<std::byte> bytes;
270 struct UserData {
271 std::vector<std::byte>* bytes;
272 std::exception_ptr exception;
273 };
274 UserData user_data = UserData{.bytes = &bytes, .exception = nullptr};
275
276 constexpr auto const write = +[](const void* buffer, size_t len, void* user_data) -> int {
277 auto& data = *reinterpret_cast<UserData*>(user_data);
278 auto& bytes = *data.bytes;
279 try {
280 auto const* first = static_cast<const std::byte*>(buffer);
281 auto const* last = first + len;
282 bytes.insert(bytes.end(), first, last);
283 return 0;
284 } catch (...) {
285 data.exception = std::current_exception();
286 return -1;
287 }
288 };
289
290 if (to_bytes(object, write, &user_data) != 0) {
291 std::rethrow_exception(user_data.exception);
292 }
293 return bytes;
294}
295
296template <typename CType>
297class View
298{
299protected:
300 const CType* m_ptr;
301
302public:
303 explicit View(const CType* ptr) : m_ptr{check(ptr)} {}
304
305 const CType* get() const { return m_ptr; }
306};
307
308template <typename CType, CType* (*CopyFunc)(const CType*), void (*DestroyFunc)(CType*)>
310{
311protected:
312 CType* m_ptr;
313
314public:
315 explicit Handle(CType* ptr) : m_ptr{check(ptr)} {}
316
317 // Copy constructors
318 Handle(const Handle& other)
319 : m_ptr{check(CopyFunc(other.m_ptr))} {}
320 Handle& operator=(const Handle& other)
321 {
322 if (this != &other) {
323 Handle temp(other);
324 std::swap(m_ptr, temp.m_ptr);
325 }
326 return *this;
327 }
328
329 // Move constructors
330 Handle(Handle&& other) noexcept : m_ptr(other.m_ptr) { other.m_ptr = nullptr; }
331 Handle& operator=(Handle&& other) noexcept
332 {
333 DestroyFunc(m_ptr);
334 m_ptr = std::exchange(other.m_ptr, nullptr);
335 return *this;
336 }
337
338 template <typename ViewType>
339 requires std::derived_from<ViewType, View<CType>>
340 Handle(const ViewType& view)
341 : Handle{CopyFunc(view.get())}
342 {
343 }
344
345 ~Handle() { DestroyFunc(m_ptr); }
346
347 CType* get() { return m_ptr; }
348 const CType* get() const { return m_ptr; }
349};
350
351template <typename CType, void (*DestroyFunc)(CType*)>
353{
354protected:
355 struct Deleter {
356 void operator()(CType* ptr) const noexcept
357 {
358 if (ptr) DestroyFunc(ptr);
359 }
360 };
361 std::unique_ptr<CType, Deleter> m_ptr;
362
363public:
364 explicit UniqueHandle(CType* ptr) : m_ptr{check(ptr)} {}
365
366 CType* get() { return m_ptr.get(); }
367 const CType* get() const { return m_ptr.get(); }
368};
369
370class Transaction;
371class TransactionOutput;
372
373template <typename Derived>
375{
376private:
377 auto impl() const
378 {
379 return static_cast<const Derived*>(this)->get();
380 }
381
382 friend Derived;
383 ScriptPubkeyApi() = default;
384
385public:
386 bool Verify(int64_t amount,
387 const Transaction& tx_to,
388 std::span<const TransactionOutput> spent_outputs,
389 unsigned int input_index,
391 ScriptVerifyStatus& status) const;
392
393 std::vector<std::byte> ToBytes() const
394 {
396 }
397};
398
399class ScriptPubkeyView : public View<btck_ScriptPubkey>, public ScriptPubkeyApi<ScriptPubkeyView>
400{
401public:
402 explicit ScriptPubkeyView(const btck_ScriptPubkey* ptr) : View{ptr} {}
403};
404
405class ScriptPubkey : public Handle<btck_ScriptPubkey, btck_script_pubkey_copy, btck_script_pubkey_destroy>, public ScriptPubkeyApi<ScriptPubkey>
406{
407public:
408 explicit ScriptPubkey(std::span<const std::byte> raw)
409 : Handle{btck_script_pubkey_create(raw.data(), raw.size())} {}
410
412 : Handle(view) {}
413};
414
415template <typename Derived>
417{
418private:
419 auto impl() const
420 {
421 return static_cast<const Derived*>(this)->get();
422 }
423
424 friend Derived;
426
427public:
428 int64_t Amount() const
429 {
431 }
432
434 {
436 }
437};
438
439class TransactionOutputView : public View<btck_TransactionOutput>, public TransactionOutputApi<TransactionOutputView>
440{
441public:
442 explicit TransactionOutputView(const btck_TransactionOutput* ptr) : View{ptr} {}
443};
444
445class TransactionOutput : public Handle<btck_TransactionOutput, btck_transaction_output_copy, btck_transaction_output_destroy>, public TransactionOutputApi<TransactionOutput>
446{
447public:
448 explicit TransactionOutput(const ScriptPubkey& script_pubkey, int64_t amount)
449 : Handle{btck_transaction_output_create(script_pubkey.get(), amount)} {}
450
452 : Handle(view) {}
453};
454
455template <typename Derived>
457{
458private:
459 auto impl() const
460 {
461 return static_cast<const Derived*>(this)->get();
462 }
463
464 friend Derived;
465 TxidApi() = default;
466
467public:
468 bool operator==(const TxidApi& other) const
469 {
470 return btck_txid_equals(impl(), other.impl()) != 0;
471 }
472
473 bool operator!=(const TxidApi& other) const
474 {
475 return btck_txid_equals(impl(), other.impl()) == 0;
476 }
477
478 std::array<std::byte, 32> ToBytes() const
479 {
480 std::array<std::byte, 32> hash;
481 btck_txid_to_bytes(impl(), reinterpret_cast<unsigned char*>(hash.data()));
482 return hash;
483 }
484};
485
486class TxidView : public View<btck_Txid>, public TxidApi<TxidView>
487{
488public:
489 explicit TxidView(const btck_Txid* ptr) : View{ptr} {}
490};
491
492class Txid : public Handle<btck_Txid, btck_txid_copy, btck_txid_destroy>, public TxidApi<Txid>
493{
494public:
495 Txid(const TxidView& view)
496 : Handle(view) {}
497};
498
499template <typename Derived>
501{
502private:
503 auto impl() const
504 {
505 return static_cast<const Derived*>(this)->get();
506 }
507
508 friend Derived;
509 OutPointApi() = default;
510
511public:
512 uint32_t index() const
513 {
515 }
516
518 {
520 }
521};
522
523class OutPointView : public View<btck_TransactionOutPoint>, public OutPointApi<OutPointView>
524{
525public:
526 explicit OutPointView(const btck_TransactionOutPoint* ptr) : View{ptr} {}
527};
528
529class OutPoint : public Handle<btck_TransactionOutPoint, btck_transaction_out_point_copy, btck_transaction_out_point_destroy>, public OutPointApi<OutPoint>
530{
531public:
533 : Handle(view) {}
534};
535
536template <typename Derived>
538{
539private:
540 auto impl() const
541 {
542 return static_cast<const Derived*>(this)->get();
543 }
544
545 friend Derived;
547
548public:
550 {
552 }
553};
554
555class TransactionInputView : public View<btck_TransactionInput>, public TransactionInputApi<TransactionInputView>
556{
557public:
558 explicit TransactionInputView(const btck_TransactionInput* ptr) : View{ptr} {}
559};
560
561class TransactionInput : public Handle<btck_TransactionInput, btck_transaction_input_copy, btck_transaction_input_destroy>, public TransactionInputApi<TransactionInput>
562{
563public:
565 : Handle(view) {}
566};
567
568template <typename Derived>
570{
571private:
572 auto impl() const
573 {
574 return static_cast<const Derived*>(this)->get();
575 }
576
577public:
578 size_t CountOutputs() const
579 {
581 }
582
583 size_t CountInputs() const
584 {
586 }
587
589 {
591 }
592
593 TransactionInputView GetInput(size_t index) const
594 {
596 }
597
599 {
601 }
602
604
606
607 std::vector<std::byte> ToBytes() const
608 {
610 }
611};
612
613class TransactionView : public View<btck_Transaction>, public TransactionApi<TransactionView>
614{
615public:
616 explicit TransactionView(const btck_Transaction* ptr) : View{ptr} {}
617};
618
619class Transaction : public Handle<btck_Transaction, btck_transaction_copy, btck_transaction_destroy>, public TransactionApi<Transaction>
620{
621public:
622 explicit Transaction(std::span<const std::byte> raw_transaction)
623 : Handle{btck_transaction_create(raw_transaction.data(), raw_transaction.size())} {}
624
626 : Handle{view} {}
627};
628
629template <typename Derived>
631 const Transaction& tx_to,
632 const std::span<const TransactionOutput> spent_outputs,
633 unsigned int input_index,
635 ScriptVerifyStatus& status) const
636{
637 const btck_TransactionOutput** spent_outputs_ptr = nullptr;
638 std::vector<const btck_TransactionOutput*> raw_spent_outputs;
639 if (spent_outputs.size() > 0) {
640 raw_spent_outputs.reserve(spent_outputs.size());
641
642 for (const auto& output : spent_outputs) {
643 raw_spent_outputs.push_back(output.get());
644 }
645 spent_outputs_ptr = raw_spent_outputs.data();
646 }
647 auto result = btck_script_pubkey_verify(
648 impl(),
649 amount,
650 tx_to.get(),
651 spent_outputs_ptr, spent_outputs.size(),
652 input_index,
654 reinterpret_cast<btck_ScriptVerifyStatus*>(&status));
655 return result == 1;
656}
657
658template <typename Derived>
660{
661private:
662 auto impl() const
663 {
664 return static_cast<const Derived*>(this)->get();
665 }
666
667public:
668 bool operator==(const Derived& other) const
669 {
670 return btck_block_hash_equals(impl(), other.get()) != 0;
671 }
672
673 bool operator!=(const Derived& other) const
674 {
675 return btck_block_hash_equals(impl(), other.get()) == 0;
676 }
677
678 std::array<std::byte, 32> ToBytes() const
679 {
680 std::array<std::byte, 32> hash;
681 btck_block_hash_to_bytes(impl(), reinterpret_cast<unsigned char*>(hash.data()));
682 return hash;
683 }
684};
685
686class BlockHashView: public View<btck_BlockHash>, public BlockHashApi<BlockHashView>
687{
688public:
689 explicit BlockHashView(const btck_BlockHash* ptr) : View{ptr} {}
690};
691
692class BlockHash : public Handle<btck_BlockHash, btck_block_hash_copy, btck_block_hash_destroy>, public BlockHashApi<BlockHash>
693{
694public:
695 explicit BlockHash(const std::array<std::byte, 32>& hash)
696 : Handle{btck_block_hash_create(reinterpret_cast<const unsigned char*>(hash.data()))} {}
697
698 explicit BlockHash(btck_BlockHash* hash)
699 : Handle{hash} {}
700
702 : Handle{view} {}
703};
704
705class Block : public Handle<btck_Block, btck_block_copy, btck_block_destroy>
706{
707public:
708 Block(const std::span<const std::byte> raw_block)
709 : Handle{btck_block_create(raw_block.data(), raw_block.size())}
710 {
711 }
712
713 Block(btck_Block* block) : Handle{block} {}
714
715 size_t CountTransactions() const
716 {
718 }
719
720 TransactionView GetTransaction(size_t index) const
721 {
723 }
724
726
728 {
730 }
731
732 std::vector<std::byte> ToBytes() const
733 {
735 }
736};
737
738inline void logging_disable()
739{
741}
742
743inline void logging_set_options(const btck_LoggingOptions& logging_options)
744{
745 btck_logging_set_options(logging_options);
746}
747
749{
750 btck_logging_set_level_category(static_cast<btck_LogCategory>(category), static_cast<btck_LogLevel>(level));
751}
752
754{
755 btck_logging_enable_category(static_cast<btck_LogCategory>(category));
756}
757
759{
760 btck_logging_disable_category(static_cast<btck_LogCategory>(category));
761}
762
763template <typename T>
764concept Log = requires(T a, std::string_view message) {
765 { a.LogMessage(message) } -> std::same_as<void>;
766};
767
768template <Log T>
769class Logger : UniqueHandle<btck_LoggingConnection, btck_logging_connection_destroy>
770{
771public:
772 Logger(std::unique_ptr<T> log)
774 +[](void* user_data, const char* message, size_t message_len) { static_cast<T*>(user_data)->LogMessage({message, message_len}); },
775 log.release(),
776 +[](void* user_data) { delete static_cast<T*>(user_data); })}
777 {
778 }
779};
780
781class BlockTreeEntry : public View<btck_BlockTreeEntry>
782{
783public:
785 : View{entry}
786 {
787 }
788
789 std::optional<BlockTreeEntry> GetPrevious() const
790 {
791 auto entry{btck_block_tree_entry_get_previous(get())};
792 if (!entry) return std::nullopt;
793 return entry;
794 }
795
796 int32_t GetHeight() const
797 {
799 }
800
802 {
804 }
805};
806
808{
809public:
810 virtual ~KernelNotifications() = default;
811
812 virtual void BlockTipHandler(SynchronizationState state, BlockTreeEntry entry, double verification_progress) {}
813
814 virtual void HeaderTipHandler(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) {}
815
816 virtual void ProgressHandler(std::string_view title, int progress_percent, bool resume_possible) {}
817
818 virtual void WarningSetHandler(Warning warning, std::string_view message) {}
819
820 virtual void WarningUnsetHandler(Warning warning) {}
821
822 virtual void FlushErrorHandler(std::string_view error) {}
823
824 virtual void FatalErrorHandler(std::string_view error) {}
825};
826
828{
829private:
831
832public:
833 BlockValidationState(const btck_BlockValidationState* state) : m_state{state} {}
834
839
841 {
843 }
844
846 {
848 }
849};
850
852{
853public:
854 virtual ~ValidationInterface() = default;
855
856 virtual void BlockChecked(Block block, const BlockValidationState state) {}
857
858 virtual void PowValidBlock(BlockTreeEntry entry, Block block) {}
859
860 virtual void BlockConnected(Block block, BlockTreeEntry entry) {}
861
862 virtual void BlockDisconnected(Block block, BlockTreeEntry entry) {}
863};
864
865class ChainParams : public Handle<btck_ChainParameters, btck_chain_parameters_copy, btck_chain_parameters_destroy>
866{
867public:
869 : Handle{btck_chain_parameters_create(static_cast<btck_ChainType>(chain_type))} {}
870};
871
872class ContextOptions : public UniqueHandle<btck_ContextOptions, btck_context_options_destroy>
873{
874public:
876
877 void SetChainParams(ChainParams& chain_params)
878 {
879 btck_context_options_set_chainparams(get(), chain_params.get());
880 }
881
882 template <typename T>
883 void SetNotifications(std::shared_ptr<T> notifications)
884 {
885 static_assert(std::is_base_of_v<KernelNotifications, T>);
886 auto heap_notifications = std::make_unique<std::shared_ptr<T>>(std::move(notifications));
887 using user_type = std::shared_ptr<T>*;
889 get(),
891 .user_data = heap_notifications.release(),
892 .user_data_destroy = +[](void* user_data) { delete static_cast<user_type>(user_data); },
893 .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); },
894 .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); },
895 .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); },
896 .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}); },
897 .warning_unset = +[](void* user_data, btck_Warning warning) { (*static_cast<user_type>(user_data))->WarningUnsetHandler(static_cast<Warning>(warning)); },
898 .flush_error = +[](void* user_data, const char* error, size_t error_len) { (*static_cast<user_type>(user_data))->FlushErrorHandler({error, error_len}); },
899 .fatal_error = +[](void* user_data, const char* error, size_t error_len) { (*static_cast<user_type>(user_data))->FatalErrorHandler({error, error_len}); },
900 });
901 }
902
903 template <typename T>
904 void SetValidationInterface(std::shared_ptr<T> validation_interface)
905 {
906 static_assert(std::is_base_of_v<ValidationInterface, T>);
907 auto heap_vi = std::make_unique<std::shared_ptr<T>>(std::move(validation_interface));
908 using user_type = std::shared_ptr<T>*;
910 get(),
912 .user_data = heap_vi.release(),
913 .user_data_destroy = +[](void* user_data) { delete static_cast<user_type>(user_data); },
914 .block_checked = +[](void* user_data, btck_Block* block, const btck_BlockValidationState* state) { (*static_cast<user_type>(user_data))->BlockChecked(Block{block}, BlockValidationState{state}); },
915 .pow_valid_block = +[](void* user_data, btck_Block* block, const btck_BlockTreeEntry* entry) { (*static_cast<user_type>(user_data))->PowValidBlock(BlockTreeEntry{entry}, Block{block}); },
916 .block_connected = +[](void* user_data, btck_Block* block, const btck_BlockTreeEntry* entry) { (*static_cast<user_type>(user_data))->BlockConnected(Block{block}, BlockTreeEntry{entry}); },
917 .block_disconnected = +[](void* user_data, btck_Block* block, const btck_BlockTreeEntry* entry) { (*static_cast<user_type>(user_data))->BlockDisconnected(Block{block}, BlockTreeEntry{entry}); },
918 });
919 }
920};
921
922class Context : public Handle<btck_Context, btck_context_copy, btck_context_destroy>
923{
924public:
926 : Handle{btck_context_create(opts.get())} {}
927
930
932 {
933 return btck_context_interrupt(get()) == 0;
934 }
935};
936
937class ChainstateManagerOptions : public UniqueHandle<btck_ChainstateManagerOptions, btck_chainstate_manager_options_destroy>
938{
939public:
940 ChainstateManagerOptions(const Context& context, std::string_view data_dir, std::string_view blocks_dir)
942 context.get(), data_dir.data(), data_dir.length(), blocks_dir.data(), blocks_dir.length())}
943 {
944 }
945
946 void SetWorkerThreads(int worker_threads)
947 {
949 }
950
951 bool SetWipeDbs(bool wipe_block_tree, bool wipe_chainstate)
952 {
953 return btck_chainstate_manager_options_set_wipe_dbs(get(), wipe_block_tree, wipe_chainstate) == 0;
954 }
955
956 void UpdateBlockTreeDbInMemory(bool block_tree_db_in_memory)
957 {
959 }
960
961 void UpdateChainstateDbInMemory(bool chainstate_db_in_memory)
962 {
964 }
965};
966
967class ChainView : public View<btck_Chain>
968{
969public:
970 explicit ChainView(const btck_Chain* ptr) : View{ptr} {}
971
972 int32_t Height() const
973 {
974 return btck_chain_get_height(get());
975 }
976
977 int CountEntries() const
978 {
979 return btck_chain_get_height(get()) + 1;
980 }
981
982 BlockTreeEntry GetByHeight(int height) const
983 {
984 auto index{btck_chain_get_by_height(get(), height)};
985 if (!index) throw std::runtime_error("No entry in the chain at the provided height");
986 return index;
987 }
988
989 bool Contains(BlockTreeEntry& entry) const
990 {
991 return btck_chain_contains(get(), entry.get());
992 }
993
994 MAKE_RANGE_METHOD(Entries, ChainView, &ChainView::CountEntries, &ChainView::GetByHeight, *this)
995};
996
997template <typename Derived>
999{
1000private:
1001 auto impl() const
1002 {
1003 return static_cast<const Derived*>(this)->get();
1004 }
1005
1006 friend Derived;
1007 CoinApi() = default;
1008
1009public:
1010 uint32_t GetConfirmationHeight() const { return btck_coin_confirmation_height(impl()); }
1011
1012 bool IsCoinbase() const { return btck_coin_is_coinbase(impl()) == 1; }
1013
1015 {
1017 }
1018};
1019
1020class CoinView : public View<btck_Coin>, public CoinApi<CoinView>
1021{
1022public:
1023 explicit CoinView(const btck_Coin* ptr) : View{ptr} {}
1024};
1025
1026class Coin : public Handle<btck_Coin, btck_coin_copy, btck_coin_destroy>, public CoinApi<Coin>
1027{
1028public:
1029 Coin(btck_Coin* coin) : Handle{coin} {}
1030
1031 Coin(const CoinView& view) : Handle{view} {}
1032};
1033
1034template <typename Derived>
1036{
1037private:
1038 auto impl() const
1039 {
1040 return static_cast<const Derived*>(this)->get();
1041 }
1042
1043 friend Derived;
1045
1046public:
1047 size_t Count() const
1048 {
1050 }
1051
1052 CoinView GetCoin(size_t index) const
1053 {
1055 }
1056
1058};
1059
1060class TransactionSpentOutputsView : public View<btck_TransactionSpentOutputs>, public TransactionSpentOutputsApi<TransactionSpentOutputsView>
1061{
1062public:
1064};
1065
1066class TransactionSpentOutputs : public Handle<btck_TransactionSpentOutputs, btck_transaction_spent_outputs_copy, btck_transaction_spent_outputs_destroy>,
1067 public TransactionSpentOutputsApi<TransactionSpentOutputs>
1068{
1069public:
1070 TransactionSpentOutputs(btck_TransactionSpentOutputs* transaction_spent_outputs) : Handle{transaction_spent_outputs} {}
1071
1073};
1074
1075class BlockSpentOutputs : public Handle<btck_BlockSpentOutputs, btck_block_spent_outputs_copy, btck_block_spent_outputs_destroy>
1076{
1077public:
1079 : Handle{block_spent_outputs}
1080 {
1081 }
1082
1083 size_t Count() const
1084 {
1085 return btck_block_spent_outputs_count(get());
1086 }
1087
1089 {
1091 }
1092
1093 MAKE_RANGE_METHOD(TxsSpentOutputs, BlockSpentOutputs, &BlockSpentOutputs::Count, &BlockSpentOutputs::GetTxSpentOutputs, *this)
1094};
1095
1096class ChainMan : UniqueHandle<btck_ChainstateManager, btck_chainstate_manager_destroy>
1097{
1098public:
1099 ChainMan(const Context& context, const ChainstateManagerOptions& chainman_opts)
1100 : UniqueHandle{btck_chainstate_manager_create(chainman_opts.get())}
1101 {
1102 }
1103
1104 bool ImportBlocks(const std::span<const std::string> paths)
1105 {
1106 std::vector<const char*> c_paths;
1107 std::vector<size_t> c_paths_lens;
1108 c_paths.reserve(paths.size());
1109 c_paths_lens.reserve(paths.size());
1110 for (const auto& path : paths) {
1111 c_paths.push_back(path.c_str());
1112 c_paths_lens.push_back(path.length());
1113 }
1114
1115 return btck_chainstate_manager_import_blocks(get(), c_paths.data(), c_paths_lens.data(), c_paths.size()) == 0;
1116 }
1117
1118 bool ProcessBlock(const Block& block, bool* new_block)
1119 {
1120 int _new_block;
1121 int res = btck_chainstate_manager_process_block(get(), block.get(), &_new_block);
1122 if (new_block) *new_block = _new_block == 1;
1123 return res == 0;
1124 }
1125
1127 {
1129 }
1130
1131 std::optional<BlockTreeEntry> GetBlockTreeEntry(const BlockHash& block_hash) const
1132 {
1133 auto entry{btck_chainstate_manager_get_block_tree_entry_by_hash(get(), block_hash.get())};
1134 if (!entry) return std::nullopt;
1135 return entry;
1136 }
1137
1138 std::optional<Block> ReadBlock(const BlockTreeEntry& entry) const
1139 {
1140 auto block{btck_block_read(get(), entry.get())};
1141 if (!block) return std::nullopt;
1142 return block;
1143 }
1144
1146 {
1147 return btck_block_spent_outputs_read(get(), entry.get());
1148 }
1149};
1150
1151} // namespace btck
1152
1153#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)
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_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)
Create options for the chainstate manager.
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
int32_t Height() const
bool Contains(BlockTreeEntry &entry) const
void SetWorkerThreads(int worker_threads)
ChainstateManagerOptions(const Context &context, std::string_view data_dir, std::string_view blocks_dir)
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.