5 #ifndef BITCOIN_KERNEL_BITCOINKERNEL_WRAPPER_H 6 #define BITCOIN_KERNEL_BITCOINKERNEL_WRAPPER_H 18 #include <string_view> 19 #include <type_traits> 100 template <
typename T>
108 template <
typename T>
111 template <BitmaskEnum T>
114 return static_cast<T>(
115 static_cast<std::underlying_type_t<T>
>(lhs) |
static_cast<std::underlying_type_t<T>
>(rhs));
118 template <BitmaskEnum T>
121 return static_cast<T>(
122 static_cast<std::underlying_type_t<T>
>(lhs) &
static_cast<std::underlying_type_t<T>
>(rhs));
125 template <BitmaskEnum T>
128 return static_cast<T>(
129 static_cast<std::underlying_type_t<T>
>(lhs) ^
static_cast<std::underlying_type_t<T>
>(rhs));
132 template <BitmaskEnum T>
135 return static_cast<T>(~static_cast<std::underlying_type_t<T>>(value));
138 template <BitmaskEnum T>
141 return lhs = lhs | rhs;
144 template <BitmaskEnum T>
147 return lhs = lhs & rhs;
150 template <BitmaskEnum T>
153 return lhs = lhs ^ rhs;
156 template <
typename T>
159 if (ptr ==
nullptr) {
160 throw std::runtime_error(
"failed to instantiate btck object");
165 template <
typename Collection,
typename ValueType>
203 auto operator<=>(
const Iterator& other)
const {
return m_idx <=> other.
m_idx; }
211 template <
typename Container,
typename SizeFunc,
typename GetFunc>
212 concept
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) };
217 template <
typename Container, auto SizeFunc, auto GetFunc>
218 requires IndexedContainer<Container, decltype(SizeFunc), decltype(GetFunc)>
222 using value_type = std::invoke_result_t<decltype(GetFunc), const Container&, size_t>;
233 static_assert(std::ranges::random_access_range<Range>);
250 if (index >=
size()) {
251 throw std::out_of_range(
"Index out of range");
253 return (*
this)[index];
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}; \ 264 auto method_name() const && = delete; 266 template <
typename T>
269 std::vector<std::byte> bytes;
271 std::vector<std::byte>* bytes;
272 std::exception_ptr exception;
274 UserData user_data = UserData{.bytes = &bytes, .exception =
nullptr};
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;
280 auto const* first =
static_cast<const std::byte*
>(buffer);
281 auto const* last = first + len;
282 bytes.insert(bytes.end(), first, last);
285 data.exception = std::current_exception();
290 if (to_bytes(
object, write, &user_data) != 0) {
291 std::rethrow_exception(user_data.exception);
296 template <
typename CType>
305 const CType*
get()
const {
return m_ptr; }
308 template <
typename CType, CType* (*CopyFunc)(const CType*),
void (*DestroyFunc)(CType*)>
322 if (
this != &other) {
334 m_ptr = std::exchange(other.m_ptr,
nullptr);
338 template <
typename ViewType>
339 requires std::derived_from<ViewType, View<CType>>
341 :
Handle{CopyFunc(view.get())}
348 const CType*
get()
const {
return m_ptr; }
351 template <
typename CType,
void (*DestroyFunc)(CType*)>
358 if (ptr) DestroyFunc(ptr);
361 std::unique_ptr<CType, Deleter>
m_ptr;
366 CType*
get() {
return m_ptr.get(); }
367 const CType*
get()
const {
return m_ptr.get(); }
372 class TransactionOutput;
374 template <
typename Derived>
380 return static_cast<const Derived*
>(
this)->
get();
387 bool Verify(int64_t amount,
390 unsigned int input_index,
416 template <
typename Derived>
422 return static_cast<const Derived*
>(
this)->
get();
456 template <
typename Derived>
462 return static_cast<const Derived*
>(
this)->
get();
481 std::array<std::byte, 32> hash;
500 template <
typename Derived>
506 return static_cast<const Derived*
>(
this)->
get();
530 class OutPoint :
public Handle<btck_TransactionOutPoint, btck_transaction_out_point_copy, btck_transaction_out_point_destroy>,
public OutPointApi<OutPoint>
537 template <
typename Derived>
543 return static_cast<const Derived*
>(
this)->
get();
569 template <
typename Derived>
575 return static_cast<const Derived*
>(
this)->
get();
638 spent_outputs.size())} {}
641 template <
typename Derived>
645 unsigned int input_index,
653 precomputed_txdata ? precomputed_txdata->
get() :
nullptr,
656 reinterpret_cast<btck_ScriptVerifyStatus*>(&status));
660 template <
typename Derived>
666 return static_cast<const Derived*
>(
this)->
get();
682 std::array<std::byte, 32> hash;
697 explicit BlockHash(
const std::array<std::byte, 32>& hash)
707 template <
typename Derived>
713 return static_cast<const Derived*
>(
this)->
get();
770 class Block :
public Handle<btck_Block, btck_block_copy, btck_block_destroy>
773 Block(
const std::span<const std::byte> raw_block)
833 template <
typename T>
834 concept
Log = requires(T a, std::string_view message) {
835 { a.LogMessage(message) } -> std::same_as<void>;
844 +[](
void* user_data,
const char* message,
size_t message_len) {
static_cast<T*
>(user_data)->LogMessage({message, message_len}); },
846 +[](
void* user_data) {
delete static_cast<T*
>(user_data); })}
867 if (!entry)
return std::nullopt;
896 virtual void ProgressHandler(std::string_view title,
int progress_percent,
bool resume_possible) {}
907 template <
typename Derived>
913 return static_cast<const Derived*
>(
this)->
get();
959 class ChainParams :
public Handle<btck_ChainParameters, btck_chain_parameters_copy, btck_chain_parameters_destroy>
976 template <
typename T>
979 static_assert(std::is_base_of_v<KernelNotifications, T>);
980 auto heap_notifications = std::make_unique<std::shared_ptr<T>>(std::move(notifications));
981 using user_type = std::shared_ptr<T>*;
985 .
user_data = heap_notifications.release(),
986 .user_data_destroy = +[](
void* user_data) {
delete static_cast<user_type
>(user_data); },
988 .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); },
989 .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); },
990 .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}); },
991 .warning_unset = +[](
void* user_data,
btck_Warning warning) { (*
static_cast<user_type
>(user_data))->WarningUnsetHandler(static_cast<Warning>(warning)); },
992 .flush_error = +[](
void* user_data,
const char* error,
size_t error_len) { (*
static_cast<user_type
>(user_data))->FlushErrorHandler({error, error_len}); },
993 .fatal_error = +[](
void* user_data,
const char* error,
size_t error_len) { (*
static_cast<user_type
>(user_data))->FatalErrorHandler({error, error_len}); },
997 template <
typename T>
1000 static_assert(std::is_base_of_v<ValidationInterface, T>);
1001 auto heap_vi = std::make_unique<std::shared_ptr<T>>(std::move(validation_interface));
1002 using user_type = std::shared_ptr<T>*;
1007 .user_data_destroy = +[](
void* user_data) {
delete static_cast<user_type
>(user_data); },
1016 class Context :
public Handle<btck_Context, btck_context_copy, btck_context_destroy>
1036 context.
get(), data_dir.data(), data_dir.length(), blocks_dir.data(), blocks_dir.length())}
1079 if (!index)
throw std::runtime_error(
"No entry in the chain at the provided height");
1091 template <
typename Derived>
1097 return static_cast<const Derived*
>(
this)->
get();
1128 template <
typename Derived>
1134 return static_cast<const Derived*
>(
this)->
get();
1173 :
Handle{block_spent_outputs}
1200 std::vector<const char*> c_paths;
1201 std::vector<size_t> c_paths_lens;
1202 c_paths.reserve(paths.size());
1203 c_paths_lens.reserve(paths.size());
1204 for (
const auto& path : paths) {
1205 c_paths.push_back(path.c_str());
1206 c_paths_lens.push_back(path.length());
1216 if (new_block) *new_block = _new_block == 1;
1233 if (!entry)
return std::nullopt;
1245 if (!block)
return std::nullopt;
1257 #endif // BITCOIN_KERNEL_BITCOINKERNEL_WRAPPER_H
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...
int btck_chain_contains(const btck_Chain *chain, const btck_BlockTreeEntry *entry)
const btck_Chain * btck_chainstate_manager_get_active_chain(const btck_ChainstateManager *chainman)
Returns the best known currently active chain.
BlockHash(const BlockHashView &view)
Iterator(const Collection *ptr, size_t idx)
int btck_transaction_to_bytes(const btck_Transaction *transaction, btck_WriteBytes writer, void *user_data)
btck_PrecomputedTransactionData * btck_precomputed_transaction_data_create(const btck_Transaction *tx_to, const btck_TransactionOutput **spent_outputs_, size_t spent_outputs_len)
Create precomputed transaction data for script verification.
int btck_chain_get_height(const btck_Chain *chain)
Return the height of the tip of the chain.
int(* btck_WriteBytes)(const void *bytes, size_t size, void *userdata)
Function signature for serializing data.
void SetNotifications(std::shared_ptr< T > notifications)
void btck_context_options_set_chainparams(btck_ContextOptions *options, const btck_ChainParameters *chain_parameters)
friend Iterator operator+(difference_type n, const Iterator &it)
uint32_t btck_ScriptVerificationFlags
Script verification flags that may be composed with each other.
uint32_t GetConfirmationHeight() const
value_type operator[](size_t index) const
void logging_disable_category(LogCategory category)
std::optional< Block > ReadBlock(const BlockTreeEntry &entry) const
const btck_BlockTreeEntry * btck_chainstate_manager_get_block_tree_entry_by_hash(const btck_ChainstateManager *chainman, const btck_BlockHash *block_hash)
void SetValidationInterface(std::shared_ptr< T > validation_interface)
BlockHash(btck_BlockHash *hash)
void SetWorkerThreads(int worker_threads)
void btck_logging_enable_category(btck_LogCategory category)
Enable a specific log category for the global internal logger.
ScriptPubkeyView GetScriptPubkey() const
btck_Block * btck_block_read(const btck_ChainstateManager *chainman, const btck_BlockTreeEntry *entry)
#define btck_ValidationMode_INTERNAL_ERROR
ChainParams(ChainType chain_type)
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.
Handle & operator=(Handle &&other) noexcept
btck_BlockHeader * btck_block_header_create(const void *raw_block_header, size_t raw_block_header_len)
Create a btck_BlockHeader from serialized data.
Transaction(std::span< const std::byte > raw_transaction)
const btck_TransactionInput * btck_transaction_get_input_at(const btck_Transaction *transaction, size_t input_index)
Get the transaction input at the provided index.
int btck_chainstate_manager_process_block(btck_ChainstateManager *chainman, const btck_Block *block, int *_new_block)
std::invoke_result_t< decltype(GetFunc), const Container &, size_t > value_type
void btck_logging_disable()
This disables the global internal logger.
#define btck_ChainType_SIGNET
BlockSpentOutputs ReadBlockSpentOutputs(const BlockTreeEntry &entry) const
BlockValidationStateApi()=default
bool ProcessBlockHeader(const BlockHeader &header, BlockValidationState &state)
#define btck_ScriptVerifyStatus_OK
TransactionSpentOutputsApi()=default
void * user_data
Holds a user-defined opaque structure that is passed to the validation interface callbacks.
uint32_t btck_block_header_get_nonce(const btck_BlockHeader *header)
Get the nonce from btck_BlockHeader.
std::array< std::byte, 32 > ToBytes() const
const btck_TransactionOutput * btck_transaction_get_output_at(const btck_Transaction *transaction, size_t output_index)
Get the transaction outputs at the provided index.
#define btck_SynchronizationState_POST_INIT
Handle(const Handle &other)
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...
#define btck_ScriptVerificationFlags_WITNESS
enable WITNESS (BIP141)
ValidationMode GetValidationMode() const
size_t CountTransactions() const
BlockHeader GetHeader() const
void btck_context_options_set_validation_interface(btck_ContextOptions *options, btck_ValidationInterfaceCallbacks vi_cbs)
Set the validation interface callbacks for the context options.
BlockValidationState(const BlockValidationStateView &view)
btck_BlockHash * btck_block_hash_create(const unsigned char block_hash[32])
Create a block hash from its raw data.
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.
int btck_block_to_bytes(const btck_Block *block, btck_WriteBytes writer, void *user_data)
CoinView GetCoin(size_t index) const
virtual void WarningUnsetHandler(Warning warning)
#define btck_ChainType_TESTNET_4
TransactionOutputView(const btck_TransactionOutput *ptr)
Block(const std::span< const std::byte > raw_block)
#define btck_ChainType_TESTNET
#define btck_BlockValidationResult_CACHED_INVALID
this block was cached as being invalid and we didn't store the reason why
constexpr T & operator^=(T &lhs, T rhs)
BlockHash GetHash() const
#define btck_Warning_UNKNOWN_NEW_RULES_ACTIVATED
std::optional< BlockTreeEntry > GetBlockTreeEntry(const BlockHash &block_hash) const
#define btck_LogCategory_RAND
btck_Block * btck_block_create(const void *raw_block, size_t raw_block_length)
Parse a serialized raw block into a new block object.
#define btck_Warning_LARGE_WORK_INVALID_CHAIN
btck_BlockHeader * btck_block_tree_entry_get_block_header(const btck_BlockTreeEntry *entry)
Return the btck_BlockHeader associated with this entry.
std::random_access_iterator_tag iterator_concept
void btck_logging_disable_category(btck_LogCategory category)
Disable a specific log category for the global internal logger.
void btck_logging_set_level_category(btck_LogCategory category, btck_LogLevel level)
Set the log level of the global internal logger.
bool operator==(const BlockTreeEntry &other) const
TransactionOutput(const ScriptPubkey &script_pubkey, int64_t amount)
BlockTreeEntry GetBestEntry() const
#define btck_LogCategory_BENCH
BlockHeader GetHeader() const
void UpdateBlockTreeDbInMemory(bool block_tree_db_in_memory)
const btck_BlockHash * btck_block_tree_entry_get_block_hash(const btck_BlockTreeEntry *entry)
Return the block hash associated with a block tree entry.
int btck_script_pubkey_verify(const btck_ScriptPubkey *script_pubkey, const int64_t amount, const btck_Transaction *tx_to, const btck_PrecomputedTransactionData *precomputed_txdata, const unsigned int input_index, const btck_ScriptVerificationFlags flags, btck_ScriptVerifyStatus *status)
#define btck_ValidationMode_VALID
const btck_Transaction * btck_block_get_transaction_at(const btck_Block *block, size_t index)
Get the transaction at the provided index.
btck_BlockHash * btck_block_header_get_hash(const btck_BlockHeader *header)
Get the btck_BlockHash.
std::ptrdiff_t difference_type
#define btck_ChainType_REGTEST
uint8_t btck_Warning
Possible warning types issued by validation.
uint32_t btck_coin_confirmation_height(const btck_Coin *coin)
Returns the block height where the transaction that created this coin was included in...
TransactionSpentOutputsView(const btck_TransactionSpentOutputs *ptr)
size_t CountInputs() const
CoinView(const btck_Coin *ptr)
#define btck_ScriptVerificationFlags_NULLDUMMY
enforce NULLDUMMY (BIP147)
#define btck_ScriptVerificationFlags_ALL
size_t btck_block_count_transactions(const btck_Block *block)
Count the number of transactions contained in a block.
auto & operator-=(difference_type n)
virtual void BlockChecked(Block block, BlockValidationStateView state)
virtual void BlockDisconnected(Block block, BlockTreeEntry entry)
ValueType operator[](difference_type n) const
void btck_txid_to_bytes(const btck_Txid *txid, unsigned char output[32])
#define btck_LogCategory_COINDB
const Collection * m_collection
#define btck_ScriptVerifyStatus_ERROR_INVALID_FLAGS_COMBINATION
The flags were combined in an invalid way.
auto operator+(difference_type n) const
std::vector< std::byte > write_bytes(const T *object, int(*to_bytes)(const T *, btck_WriteBytes, void *))
TransactionInputView GetInput(size_t index) const
uint8_t btck_LogLevel
The level at which logs should be produced.
TransactionOutputApi()=default
#define btck_BlockValidationResult_UNSET
initial value. Block has not yet been rejected
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...
void * user_data
Holds a user-defined opaque structure that is passed to the notification callbacks.
Iterator(const Collection *ptr)
#define btck_BlockValidationResult_CONSENSUS
invalid by consensus rules (excluding any below reasons)
const Container * m_container
const btck_BlockTreeEntry * btck_chainstate_manager_get_best_entry(const btck_ChainstateManager *chainstate_manager)
Get the btck_BlockTreeEntry whose associated btck_BlockHeader has the most known cumulative proof of ...
TransactionOutputView GetOutput() const
btck_ChainstateManager * btck_chainstate_manager_create(const btck_ChainstateManagerOptions *chainman_opts)
Create a chainstate manager.
constexpr T operator &(T lhs, T rhs)
bool ImportBlocks(const std::span< const std::string > paths)
btck_BlockHash * btck_block_get_hash(const btck_Block *block)
Calculate and return the hash of a block.
uint32_t btck_block_header_get_bits(const btck_BlockHeader *header)
Get the nBits difficulty target from btck_BlockHeader.
constexpr T operator|(T lhs, T rhs)
void logging_enable_category(LogCategory category)
#define btck_LogCategory_BLOCKSTORAGE
bool Verify(int64_t amount, const Transaction &tx_to, const PrecomputedTransactionData *precomputed_txdata, unsigned int input_index, ScriptVerificationFlags flags, ScriptVerifyStatus &status) const
const btck_TransactionOutPoint * btck_transaction_input_get_out_point(const btck_TransactionInput *input)
Get the transaction out point.
constexpr T & operator &=(T &lhs, T rhs)
virtual void HeaderTipHandler(SynchronizationState state, int64_t height, int64_t timestamp, bool presync)
Transaction(const TransactionView &view)
auto & operator+=(difference_type n)
int btck_context_interrupt(btck_Context *context)
Interrupt can be used to halt long-running validation functions like when reindexing, importing or processing blocks.
bool operator==(const Derived &other) const
ScriptPubkey(const ScriptPubkeyView &view)
void UpdateChainstateDbInMemory(bool chainstate_db_in_memory)
const_iterator cbegin() const
virtual void FatalErrorHandler(std::string_view error)
virtual void BlockConnected(Block block, BlockTreeEntry entry)
#define btck_LogCategory_ALL
#define btck_LogLevel_DEBUG
btck_ContextOptions * btck_context_options_create()
Creates an empty context options.
int btck_script_pubkey_to_bytes(const btck_ScriptPubkey *script_pubkey_, btck_WriteBytes writer, void *user_data)
bool operator!=(const Derived &other) const
bool ProcessBlock(const Block &block, bool *new_block)
#define btck_ScriptVerificationFlags_NONE
#define btck_ScriptVerificationFlags_CHECKSEQUENCEVERIFY
enable CHECKSEQUENCEVERIFY (BIP112)
bool operator==(const Iterator &other) const
#define btck_ScriptVerificationFlags_P2SH
evaluate P2SH (BIP16) subscripts
ChainMan(const Context &context, const ChainstateManagerOptions &chainman_opts)
btck_BlockValidationResult btck_block_validation_state_get_block_validation_result(const btck_BlockValidationState *block_validation_state_)
Returns the validation result from an opaque btck_BlockValidationState pointer.
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.
#define btck_LogCategory_KERNEL
requires std::derived_from< ViewType, View< CType > > Handle(const ViewType &view)
Logger(std::unique_ptr< T > log)
BlockHashView GetHash() const
value_type at(size_t index) const
#define btck_LogCategory_MEMPOOL
BlockHashView(const btck_BlockHash *ptr)
#define btck_SynchronizationState_INIT_DOWNLOAD
void operator()(CType *ptr) const noexcept
BlockValidationStateView(const btck_BlockValidationState *ptr)
TransactionOutput(const TransactionOutputView &view)
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_iterator cend() const
int32_t btck_block_header_get_version(const btck_BlockHeader *header)
Get the version from btck_BlockHeader.
Range(const Container &container)
uint8_t btck_LogCategory
A collection of logging categories that may be encountered by kernel code.
Txid(const TxidView &view)
bool SetWipeDbs(bool wipe_block_tree, bool wipe_chainstate)
void logging_set_options(const btck_LoggingOptions &logging_options)
std::vector< std::byte > ToBytes() const
#define btck_BlockValidationResult_TIME_FUTURE
block timestamp was > 2 hours in the future (or our clock is bad)
BlockSpentOutputs(btck_BlockSpentOutputs *block_spent_outputs)
Handle & operator=(const Handle &other)
uint32_t btck_BlockValidationResult
A granular "reason" why a block was invalid.
btck_BlockHeader * btck_block_get_header(const btck_Block *block)
Get the btck_BlockHeader from the block.
#define btck_BlockValidationResult_INVALID_PREV
A block this one builds on is invalid.
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.
btck_BlockSpentOutputs * btck_block_spent_outputs_read(const btck_ChainstateManager *chainman, const btck_BlockTreeEntry *entry)
Iterator< Range, value_type > iterator
const btck_ScriptPubkey * btck_transaction_output_get_script_pubkey(const btck_TransactionOutput *output)
Get the script pubkey of the output.
std::random_access_iterator_tag iterator_category
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.
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.
#define btck_BlockValidationResult_MISSING_PREV
We don't have the previous block the checked one is built on.
std::vector< std::byte > ToBytes() const
bool operator!=(const TxidApi &other) const
size_t CountOutputs() const
OutPoint(const OutPointView &view)
std::vector< std::byte > ToBytes() const
bool operator==(const TxidApi &other) const
const btck_TransactionOutput * btck_coin_get_output(const btck_Coin *coin)
Return the transaction output of a coin.
uint8_t btck_ValidationMode
Whether a validated data structure is valid, invalid, or an error was encountered during processing...
int btck_coin_is_coinbase(const btck_Coin *coin)
Returns whether the containing transaction was a coinbase.
void btck_block_hash_to_bytes(const btck_BlockHash *block_hash, unsigned char output[32])
bool Contains(BlockTreeEntry &entry) const
TransactionSpentOutputsView GetTxSpentOutputs(size_t tx_undo_index) const
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...
ChainView GetChain() const
btck_ScriptPubkey * btck_script_pubkey_create(const void *script_pubkey, size_t script_pubkey_len)
Create a script pubkey from serialized data.
btck_ValidationMode btck_block_validation_state_get_validation_mode(const btck_BlockValidationState *block_validation_state_)
Returns the validation mode from an opaque btck_BlockValidationState pointer.
TxidView(const btck_Txid *ptr)
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...
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.
ScriptPubkeyApi()=default
BlockValidationResult GetBlockValidationResult() const
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_Context * btck_context_create(const btck_ContextOptions *options)
Create a new kernel context.
BlockTreeEntry(const btck_BlockTreeEntry *entry)
#define btck_LogCategory_REINDEX
TransactionView GetTransaction(size_t index) const
A struct for holding the kernel notification callbacks.
uint8_t btck_ScriptVerifyStatus
A collection of status codes that may be issued by the script verify function.
auto operator-(difference_type n) const
BlockTreeEntry GetByHeight(int height) const
std::optional< BlockTreeEntry > GetPrevious() const
int64_t btck_transaction_output_get_amount(const btck_TransactionOutput *output)
Get the amount in the output.
uint32_t btck_block_header_get_timestamp(const btck_BlockHeader *header)
Get the timestamp from btck_BlockHeader.
virtual ~KernelNotifications()=default
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...
size_t btck_transaction_count_inputs(const btck_Transaction *transaction)
Get the number of inputs of a transaction.
#define btck_ScriptVerificationFlags_CHECKLOCKTIMEVERIFY
enable CHECKLOCKTIMEVERIFY (BIP65)
int btck_chainstate_manager_process_block_header(btck_ChainstateManager *chainstate_manager, const btck_BlockHeader *header, btck_BlockValidationState *state)
Coin(const CoinView &view)
std::array< std::byte, 32 > ToBytes() const
#define btck_LogCategory_VALIDATION
#define btck_ValidationMode_INVALID
constexpr T operator~(T value)
#define btck_LogCategory_PRUNE
ChainView(const btck_Chain *ptr)
#define btck_ChainType_MAINNET
Holds the validation interface callbacks.
#define btck_ScriptVerificationFlags_DERSIG
enforce strict DER (BIP66) compliance
TransactionSpentOutputs(const TransactionSpentOutputsView &view)
virtual void FlushErrorHandler(std::string_view error)
Options controlling the format of log messages.
virtual void WarningSetHandler(Warning warning, std::string_view message)
size_t btck_transaction_count_outputs(const btck_Transaction *transaction)
Get the number of outputs of a transaction.
ScriptPubkey(std::span< const std::byte > raw)
auto operator-(const Iterator &other) const
#define btck_SynchronizationState_INIT_REINDEX
Handle(Handle &&other) noexcept
void btck_context_options_set_notifications(btck_ContextOptions *options, btck_NotificationInterfaceCallbacks notifications)
Set the kernel notifications for the context options.
#define btck_LogLevel_INFO
TransactionView(const btck_Transaction *ptr)
#define btck_BlockValidationResult_HEADER_LOW_WORK
the block header may be on a too-little-work chain
int32_t btck_block_tree_entry_get_height(const btck_BlockTreeEntry *entry)
Return the height of a certain block tree entry.
std::unique_ptr< CType, Deleter > m_ptr
void btck_logging_set_options(const btck_LoggingOptions options)
Set some options for the global internal logger.
int btck_block_hash_equals(const btck_BlockHash *hash1, const btck_BlockHash *hash2)
virtual ~ValidationInterface()=default
uint8_t btck_SynchronizationState
Current sync state passed to tip changed callbacks.
const CType * get() const
BlockHash(const std::array< std::byte, 32 > &hash)
virtual void ProgressHandler(std::string_view title, int progress_percent, bool resume_possible)
#define btck_ScriptVerificationFlags_TAPROOT
enable TAPROOT (BIPs 341 & 342)
const btck_Txid * btck_transaction_out_point_get_txid(const btck_TransactionOutPoint *out_point)
Get the txid from the transaction out point.
Context(ContextOptions &opts)
constexpr T & operator|=(T &lhs, T rhs)
btck_BlockValidationState * btck_block_validation_state_create()
Create a new btck_BlockValidationState.
PrecomputedTransactionData(const Transaction &tx_to, std::span< const TransactionOutput > spent_outputs)
#define btck_BlockValidationResult_INVALID_HEADER
invalid proof of work or time too old
ScriptPubkeyView(const btck_ScriptPubkey *ptr)
#define btck_LogCategory_LEVELDB
constexpr T operator^(T lhs, T rhs)
const btck_Txid * btck_transaction_get_txid(const btck_Transaction *transaction)
Get the txid of a transaction.
#define T(expected, seed, data)
int btck_block_tree_entry_equals(const btck_BlockTreeEntry *entry1, const btck_BlockTreeEntry *entry2)
uint32_t btck_transaction_out_point_get_index(const btck_TransactionOutPoint *out_point)
Get the output position from the transaction out point.
TransactionSpentOutputs(btck_TransactionSpentOutputs *transaction_spent_outputs)
void logging_set_level_category(LogCategory category, LogLevel level)
#define btck_ScriptVerifyStatus_ERROR_SPENT_OUTPUTS_REQUIRED
The taproot flag was set, so valid spent_outputs have to be provided.
#define MAKE_RANGE_METHOD(method_name, ContainerType, SizeFunc, GetFunc, container_expr)
void SetChainParams(ChainParams &chain_params)
btck_Transaction * btck_transaction_create(const void *raw_transaction, size_t raw_transaction_len)
Create a new transaction from the serialized data.
#define btck_BlockValidationResult_MUTATED
the block's data didn't match the data committed to by the PoW
virtual void BlockTipHandler(SynchronizationState state, BlockTreeEntry entry, double verification_progress)
OutPointView(const btck_TransactionOutPoint *ptr)
std::ptrdiff_t difference_type
const btck_BlockHash * btck_block_header_get_prev_hash(const btck_BlockHeader *header)
Get the previous btck_BlockHash from btck_BlockHeader.
ChainstateManagerOptions(const Context &context, std::string_view data_dir, std::string_view blocks_dir)
virtual void PowValidBlock(BlockTreeEntry entry, Block block)
TransactionOutputView GetOutput(size_t index) const
int btck_txid_equals(const btck_Txid *txid1, const btck_Txid *txid2)
int32_t GetHeight() const
#define btck_LogLevel_TRACE