5#ifndef BITCOIN_KERNEL_BITCOINKERNEL_WRAPPER_H
6#define BITCOIN_KERNEL_BITCOINKERNEL_WRAPPER_H
175template <BitmaskEnum T>
178 return static_cast<T>(
179 static_cast<std::underlying_type_t<T>
>(
lhs) |
static_cast<std::underlying_type_t<T>
>(
rhs));
182template <BitmaskEnum T>
185 return static_cast<T>(
186 static_cast<std::underlying_type_t<T>
>(
lhs) &
static_cast<std::underlying_type_t<T>
>(
rhs));
189template <BitmaskEnum T>
192 return static_cast<T>(
193 static_cast<std::underlying_type_t<T>
>(
lhs) ^
static_cast<std::underlying_type_t<T>
>(
rhs));
196template <BitmaskEnum T>
202template <BitmaskEnum T>
208template <BitmaskEnum T>
214template <BitmaskEnum T>
223 if (ptr ==
nullptr) {
224 throw std::runtime_error(
"failed to instantiate btck object");
234template <
typename Collection,
typename ValueType, auto GetFunc>
279template <
typename Container,
typename SizeFunc,
typename GetFunc>
281 { std::invoke(
size_func,
c) } -> std::convertible_to<std::size_t>;
285template <
typename Container, auto SizeFunc, auto GetFunc>
301 static_assert(std::ranges::random_access_range<Range>);
318 if (index >=
size()) {
319 throw std::out_of_range(
"Index out of range");
321 return (*
this)[index];
328#define MAKE_RANGE_METHOD(method_name, ContainerType, SizeFunc, GetFunc, container_expr) \
329 auto method_name() const & { \
330 return Range<ContainerType, SizeFunc, GetFunc>{container_expr}; \
332 auto method_name() const && = delete;
337 std::vector<std::byte> bytes;
339 std::vector<std::byte>* bytes;
340 std::exception_ptr exception;
344 constexpr auto const write = +[](
const void* buffer,
size_t len,
void* user_data) ->
int {
346 auto& bytes = *
data.bytes;
348 auto const*
first =
static_cast<const std::byte*
>(buffer);
353 data.exception = std::current_exception();
358 if (
to_bytes(
object, write, &user_data) != 0) {
359 std::rethrow_exception(user_data.exception);
364template <
typename CType>
376template <
typename CType, CType* (*CopyFunc)(const CType*),
void (*DestroyFunc)(CType*)>
390 if (
this != &other) {
401 if (
this != &other) {
403 m_ptr = std::exchange(other.m_ptr,
nullptr);
408 template <
typename ViewType>
409 requires std::derived_from<ViewType, View<CType>>
421template <
typename CType,
void (*DestroyFunc)(CType*)>
431 std::unique_ptr<CType, Deleter>
m_ptr;
442class TransactionOutput;
445template <
typename Derived>
451 return static_cast<const Derived*
>(
this)->get();
487template <
typename Derived>
493 return static_cast<const Derived*
>(
this)->get();
527template <
typename Derived>
533 return static_cast<const Derived*
>(
this)->get();
552 std::array<std::byte, 32> hash;
571template <
typename Derived>
577 return static_cast<const Derived*
>(
this)->get();
596 std::array<std::byte, 32> hash;
615template <
typename Derived>
621 return static_cast<const Derived*
>(
this)->get();
645class OutPoint :
public Handle<btck_TransactionOutPoint, btck_transaction_out_point_copy, btck_transaction_out_point_destroy>,
public OutPointApi<OutPoint>
652template <
typename Derived>
658 return static_cast<const Derived*
>(
this)->get();
670 std::vector<std::byte>
GetItem(
size_t index)
const
695template <
typename Derived>
701 return static_cast<const Derived*
>(
this)->get();
742template <
typename Derived>
748 return static_cast<const Derived*
>(
this)->get();
834template <
typename Derived>
853template <
typename Derived>
859 return static_cast<const Derived*
>(
this)->get();
875 std::array<std::byte, 32> hash;
890 explicit BlockHash(
const std::array<std::byte, 32>& hash)
900template <
typename Derived>
906 return static_cast<const Derived*
>(
this)->get();
925 std::array<std::byte, 32> merkle_root;
952 std::array<std::byte, 80> header;
955 throw std::runtime_error(
"Failed to serialize block header");
986class Block :
public Handle<btck_Block, btck_block_copy, btck_block_destroy>
1043 std::chrono::sys_time<std::chrono::nanoseconds>
Timestamp()
const
1047 std::optional<std::chrono::sys_seconds>
MockTime()
const
1051 return std::chrono::sys_seconds{std::chrono::seconds{
mocktime_s}};
1060template <
typename T>
1061concept Log =
requires(
T a,
const LogEntry& entry) {
1062 {
a.LogMessage(entry) } -> std::same_as<void>;
1073 +[](
void* user_data) {
delete static_cast<T*
>(user_data); })}
1094 if (!entry)
return std::nullopt;
1140template <
typename Derived>
1146 return static_cast<const Derived*
>(
this)->get();
1190 using UniqueHandle::UniqueHandle;
1223class ChainParams :
public Handle<btck_ChainParameters, btck_chain_parameters_copy, btck_chain_parameters_destroy>
1248 template <
typename T>
1251 static_assert(std::is_base_of_v<KernelNotifications, T>);
1252 auto heap_notifications = std::make_unique<std::shared_ptr<T>>(std::move(notifications));
1258 .user_data_destroy = +[](
void* user_data) {
delete static_cast<user_type>(user_data); },
1264 .flush_error = +[](
void* user_data,
const char* error,
size_t error_len) { (*
static_cast<user_type>(user_data))->FlushErrorHandler({error,
error_len}); },
1265 .fatal_error = +[](
void* user_data,
const char* error,
size_t error_len) { (*
static_cast<user_type>(user_data))->FatalErrorHandler({error,
error_len}); },
1269 template <
typename T>
1272 static_assert(std::is_base_of_v<ValidationInterface, T>);
1279 .user_data_destroy = +[](
void* user_data) {
delete static_cast<user_type>(user_data); },
1288class Context :
public Handle<btck_Context, btck_context_copy, btck_context_destroy>
1356 if (!index)
throw std::runtime_error(
"No entry in the chain at the provided height");
1368template <
typename Derived>
1374 return static_cast<const Derived*
>(
this)->get();
1405template <
typename Derived>
1411 return static_cast<const Derived*
>(
this)->get();
1477 std::vector<const char*>
c_paths;
1481 for (
const auto& path :
paths) {
1482 c_paths.push_back(path.c_str());
1511 if (!entry)
return std::nullopt;
1523 if (!block)
return std::nullopt;
1536 throw std::runtime_error(
"timestamp out of range");
int btck_block_to_bytes(const btck_Block *block, btck_WriteBytes writer, void *user_data)
int btck_script_pubkey_to_bytes(const btck_ScriptPubkey *script_pubkey_, btck_WriteBytes writer, void *user_data)
btck_TxValidationResult btck_tx_validation_state_get_tx_validation_result(const btck_TxValidationState *state_)
Returns the validation result from an opaque btck_TxValidationState pointer.
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.
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_StringView btck_log_entry_get_function_name(const btck_LogEntry *entry)
Get the name of the function that produced the log statement.
btck_ContextOptions * btck_context_options_create()
Creates an empty context options.
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.
const btck_BlockTreeEntry * btck_block_tree_entry_get_ancestor(const btck_BlockTreeEntry *block_tree_entry, int32_t height)
Return the ancestor of a btck_BlockTreeEntry at the given height.
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.
uint32_t btck_block_header_get_nonce(const btck_BlockHeader *header)
Get the nonce from btck_BlockHeader.
const btck_Txid * btck_transaction_out_point_get_txid(const btck_TransactionOutPoint *out_point)
Get the txid from the transaction out point.
btck_BlockValidationState * btck_block_validation_state_create()
Create a new btck_BlockValidationState.
btck_LogCategory btck_log_entry_get_category(const btck_LogEntry *entry)
Get the category of the log entry.
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.
int btck_witness_stack_get_item_at(const btck_WitnessStack *witness_stack, size_t index, btck_WriteBytes writer, void *user_data)
size_t btck_witness_stack_count_items(const btck_WitnessStack *witness_stack)
Return the number of items in a witness stack.
btck_ScriptPubkey * btck_script_pubkey_create(const void *script_pubkey, size_t script_pubkey_len)
Create a script pubkey from serialized data.
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 ...
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.
int32_t btck_block_header_get_version(const btck_BlockHeader *header)
Get the version from btck_BlockHeader.
int btck_set_mock_time(int64_t timestamp)
Override the current time with a fixed timestamp for testing.
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.
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.
int btck_block_tree_entry_equals(const btck_BlockTreeEntry *entry1, const btck_BlockTreeEntry *entry2)
uint32_t btck_block_header_get_bits(const btck_BlockHeader *header)
Get the nBits difficulty target from btck_BlockHeader.
const btck_Wtxid * btck_transaction_get_wtxid(const btck_Transaction *transaction)
Get the wtxid of a transaction.
int32_t btck_chain_get_height(const btck_Chain *chain)
Return the height of the tip of the chain.
btck_BlockHeader * btck_block_get_header(const btck_Block *block)
Get the btck_BlockHeader from the block.
size_t btck_block_count_transactions(const btck_Block *block)
Count the number of transactions contained in a block.
int64_t btck_log_entry_get_timestamp_ns(const btck_LogEntry *entry)
Get the wall-clock time when the entry was logged.
void btck_logging_set_min_level(btck_LogLevel level)
Set the minimum log level.
void btck_block_header_get_merkle_root(const btck_BlockHeader *header, unsigned char output[32])
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.
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)
uint32_t btck_log_entry_get_line(const btck_LogEntry *entry)
Get the line number of the source code that produced the log statement.
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.
int btck_transaction_check(const btck_Transaction *tx, btck_TxValidationState *validation_state)
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.
uint32_t btck_transaction_get_locktime(const btck_Transaction *transaction)
Get a transaction's nLockTime value.
int btck_coin_is_coinbase(const btck_Coin *coin)
Returns whether the containing transaction was a coinbase.
int btck_wtxid_equals(const btck_Wtxid *wtxid1, const btck_Wtxid *wtxid2)
void btck_txid_to_bytes(const btck_Txid *txid, unsigned char output[32])
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.
uint32_t btck_transaction_get_version(const btck_Transaction *transaction)
Get a transaction's version.
btck_BlockHeader * btck_block_tree_entry_get_block_header(const btck_BlockTreeEntry *entry)
Return the btck_BlockHeader associated with this entry.
int btck_context_interrupt(btck_Context *context)
Interrupt can be used to halt long-running validation functions like when reindexing,...
const btck_ConsensusParams * btck_chain_parameters_get_consensus_params(const btck_ChainParameters *chain_parameters)
Get btck_ConsensusParams from btck_ChainParameters.
const btck_TransactionOutput * btck_transaction_get_output_at(const btck_Transaction *transaction, size_t output_index)
Get the transaction outputs at the provided index.
const btck_BlockTreeEntry * btck_chain_get_by_height(const btck_Chain *chain, int32_t height)
Retrieve a block tree entry by its height in the currently active chain.
void btck_context_options_set_chainparams(btck_ContextOptions *options, const btck_ChainParameters *chain_parameters)
int btck_block_header_to_bytes(const btck_BlockHeader *header, unsigned char output[80])
int64_t btck_log_entry_get_mocktime_s(const btck_LogEntry *entry)
Get the mock time in effect when the entry was logged.
int btck_chainstate_manager_options_set_database_cache_bytes(btck_ChainstateManagerOptions *chainman_opts, uint64_t database_cache_bytes)
Set the total database cache used by the chainstate manager.
const btck_WitnessStack * btck_transaction_input_get_witness_stack(const btck_TransactionInput *input)
Get the witness stack of a transaction input.
btck_BlockHeader * btck_block_header_create(const void *raw_block_header, size_t raw_block_header_len)
Create a btck_BlockHeader from serialized data.
uint32_t btck_block_header_get_timestamp(const btck_BlockHeader *header)
Get the timestamp from btck_BlockHeader.
btck_ChainParameters * btck_chain_parameters_create_signet(const void *challenge, size_t challenge_len)
Create a signet chain parameters struct with a user-provided challenge.
btck_BlockHash * btck_block_hash_create(const unsigned char block_hash[32])
Create a block hash from its raw data.
btck_BlockHash * btck_block_header_get_hash(const btck_BlockHeader *header)
Get the btck_BlockHash.
btck_LogLevel btck_log_entry_get_level(const btck_LogEntry *entry)
Get the severity level of the log entry.
btck_ValidationMode btck_tx_validation_state_get_validation_mode(const btck_TxValidationState *state_)
Returns the validation mode from an opaque btck_TxValidationState pointer.
void btck_wtxid_to_bytes(const btck_Wtxid *wtxid, unsigned char output[32])
int btck_transaction_input_get_script_sig(const btck_TransactionInput *input, btck_WriteBytes writer, void *user_data)
int btck_transaction_has_witness(const btck_Transaction *transaction)
Check whether a transaction has witness 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.
const btck_BlockHash * btck_block_header_get_prev_hash(const btck_BlockHeader *header)
Get the previous btck_BlockHash from btck_BlockHeader.
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.
btck_BlockValidationState * btck_chainstate_manager_process_block_header(btck_ChainstateManager *chainstate_manager, const btck_BlockHeader *header)
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.
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_block_check(const btck_Block *block, const btck_ConsensusParams *consensus_params, btck_BlockCheckFlags flags, btck_BlockValidationState *validation_state)
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_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.
btck_StringView btck_log_entry_get_message(const btck_LogEntry *entry)
Get the message text from a btck_LogEntry.
btck_TxValidationState * btck_tx_validation_state_create()
Create a new btck_TxValidationState.
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_StringView btck_log_entry_get_file_name(const btck_LogEntry *entry)
Get the name of the source file that produced the log statement.
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_block_hash_to_bytes(const btck_BlockHash *block_hash, unsigned char output[32])
uint32_t btck_transaction_input_get_sequence(const btck_TransactionInput *input)
Get a transaction input's nSequence value.
btck_StringView btck_log_entry_get_thread_name(const btck_LogEntry *entry)
Get the name of the thread that produced the log message.
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 severity of a log statement.
#define btck_TxValidationResult_NOT_STANDARD
otherwise didn't meet local policy rules
#define btck_TxValidationResult_CONFLICT
tx already in mempool or conflicts with a tx in the chain
#define btck_LogLevel_WARNING
#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_TxValidationResult_RECONSIDERABLE
fails some policy, but might be acceptable if submitted in a (different) package
uint32_t btck_TxValidationResult
Indicates the reason why a transaction failed validation.
#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
#define btck_TxValidationResult_MISSING_INPUTS
transaction was missing some of its inputs
#define btck_BlockValidationResult_INVALID_PREV
A block this one builds on is invalid.
#define btck_BlockCheckFlags_MERKLE
verify merkle root (and mutation detection)
#define btck_LogCategory_MEMPOOL
#define btck_TxValidationResult_UNKNOWN
transaction was not validated because package failed
#define btck_LogLevel_TRACE
#define btck_ChainType_TESTNET
#define btck_SynchronizationState_INIT_REINDEX
#define btck_BlockCheckFlags_BASE
run the base context-free block checks only
#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_LOCK
#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_TxValidationResult_NO_MEMPOOL
this node does not have a mempool so can't validate the transaction
#define btck_BlockCheckFlags_ALL
enable all optional context-free block checks
#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)
#define btck_BlockCheckFlags_POW
run CheckProofOfWork via CheckBlockHeader
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_TxValidationResult_WITNESS_STRIPPED
transaction is missing a witness
#define btck_ScriptVerificationFlags_NONE
#define btck_LogCategory_RAND
#define btck_TxValidationResult_INPUTS_NOT_STANDARD
inputs (covered by txid) failed policy rules
#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_TxValidationResult_UNSET
initial value. Tx 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.
uint8_t btck_ScriptVerifyStatus
A collection of status codes that may be issued by the script verify function.
#define btck_ValidationMode_INTERNAL_ERROR
#define btck_TxValidationResult_WITNESS_MUTATED
witness may have been malleated or is prior to SegWit activation
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_TxValidationResult_CONSENSUS
invalid by consensus rules
uint32_t btck_BlockCheckFlags
Bitflags to control context-free block checks (optional).
#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_LogCategory_NONE
Not tied to a specific category, e.g. most INFO, WARNING and ERROR entries.
#define btck_BlockValidationResult_TIME_FUTURE
block timestamp was > 2 hours in the future (or our clock is bad)
#define btck_LogCategory_LEVELDB
#define btck_LogLevel_ERROR
#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_TxValidationResult_PREMATURE_SPEND
transaction spends a coinbase too early, or violates locktime/sequence locks
#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_LogCategory_TXPACKAGES
#define btck_TxValidationResult_MEMPOOL_POLICY
violated mempool's fee/size/descendant/RBF/etc limits
#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
bool Check(const ConsensusParamsView &consensus_params, BlockCheckFlags flags, BlockValidationState &state) const
TransactionView GetTransaction(size_t index) const
BlockHeader GetHeader() const
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
bool operator==(const BlockTreeEntry &other) const
BlockTreeEntry GetAncestor(int32_t height) const
BlockHashView GetHash() const
BlockHeader GetHeader() const
ValidationMode GetValidationMode() const
BlockValidationStateApi()=default
BlockValidationResult GetBlockValidationResult() const
BlockValidationState(const BlockValidationStateView &view)
BlockValidationState(btck_BlockValidationState *state)
BlockValidationStateView(const btck_BlockValidationState *ptr)
std::optional< BlockTreeEntry > GetBlockTreeEntry(const BlockHash &block_hash) const
std::optional< Block > ReadBlock(const BlockTreeEntry &entry) const
BlockSpentOutputs ReadBlockSpentOutputs(const BlockTreeEntry &entry) const
BlockValidationState ProcessBlockHeader(const BlockHeader &header)
ChainView GetChain() const
BlockTreeEntry GetBestEntry() 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(std::span< const std::byte > signet_challenge)
ChainParams(ChainType chain_type)
ConsensusParamsView GetConsensusParams() const
ChainView(const btck_Chain *ptr)
BlockTreeEntry GetByHeight(int32_t height) const
bool Contains(BlockTreeEntry &entry) const
int32_t CountEntries() 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 SetDatabaseCacheBytes(uint64_t database_cache_bytes)
bool SetWipeDbs(bool wipe_block_tree, bool wipe_chainstate)
uint32_t GetConfirmationHeight() const
TransactionOutputView GetOutput() const
Coin(const CoinView &view)
CoinView(const btck_Coin *ptr)
ConsensusParamsView(const btck_ConsensusParams *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)
Iterator(const Collection *ptr)
auto operator+(difference_type n) const
auto operator-(difference_type n) const
std::random_access_iterator_tag iterator_category
std::random_access_iterator_tag iterator_concept
auto operator<=>(const Iterator &other) const
auto & operator+=(difference_type n)
friend Iterator operator+(difference_type n, const Iterator &it)
const Collection * m_collection
bool operator==(const Iterator &other) const
std::ptrdiff_t difference_type
auto & operator-=(difference_type n)
ValueType operator[](difference_type n) const
auto operator-(const Iterator &other) const
Iterator(const Collection *ptr, size_t idx)
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)
Non-owning view over a btck_LogEntry.
std::optional< std::chrono::sys_seconds > MockTime() const
std::string_view FunctionName() const
std::string_view FileName() const
LogCategory Category() const
std::string_view ThreadName() const
std::string_view Message() const
LogEntry(const btck_LogEntry *entry)
std::chrono::sys_time< std::chrono::nanoseconds > Timestamp() const
Logger(std::unique_ptr< T > log)
OutPoint(const OutPointView &view)
OutPointView(const btck_TransactionOutPoint *ptr)
PrecomputedTransactionData(const Transaction &tx_to, std::span< const TransactionOutput > spent_outputs)
const Container * m_container
const_iterator cbegin() const
value_type operator[](size_t index) const
Range(const Container &container)
const_iterator cend() const
std::ptrdiff_t difference_type
Iterator< Container, value_type, GetFunc > iterator
value_type at(size_t index) const
std::invoke_result_t< decltype(GetFunc), const Container &, size_t > value_type
ScriptPubkeyApi()=default
std::vector< std::byte > ToBytes() const
bool Verify(int64_t amount, const Transaction &tx_to, const PrecomputedTransactionData *precomputed_txdata, unsigned int input_index, ScriptVerificationFlags flags, ScriptVerifyStatus &status) const
ScriptPubkey(std::span< const std::byte > raw)
ScriptPubkey(const ScriptPubkeyView &view)
ScriptPubkeyView(const btck_ScriptPubkey *ptr)
uint32_t GetLocktime() const
TransactionInputView GetInput(size_t index) const
TransactionOutputView GetOutput(size_t index) const
uint32_t GetVersion() const
size_t CountInputs() const
std::vector< std::byte > ToBytes() const
size_t CountOutputs() const
Transaction(std::span< const std::byte > raw_transaction)
Transaction(const TransactionView &view)
TransactionOutputApi()=default
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
TransactionSpentOutputsApi()=default
TransactionSpentOutputs(btck_TransactionSpentOutputs *transaction_spent_outputs)
TransactionSpentOutputs(const TransactionSpentOutputsView &view)
TransactionSpentOutputsView(const btck_TransactionSpentOutputs *ptr)
TransactionView(const btck_Transaction *ptr)
TxValidationResult GetTxValidationResult() const
ValidationMode GetValidationMode() const
bool operator==(const TxidApi &other) const
std::array< std::byte, 32 > ToBytes() const
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 PowValidBlock(BlockTreeEntry entry, Block block)
virtual void BlockConnected(Block block, BlockTreeEntry entry)
virtual ~ValidationInterface()=default
virtual void BlockDisconnected(Block block, BlockTreeEntry entry)
virtual void BlockChecked(Block block, BlockValidationStateView state)
const CType * get() const
size_t CountItems() const
WitnessStackApi()=default
std::vector< std::byte > GetItem(size_t index) const
WitnessStack(const WitnessStackView &view)
WitnessStackView(const btck_WitnessStack *ptr)
bool operator==(const WtxidApi &other) const
bool operator!=(const WtxidApi &other) const
std::array< std::byte, 32 > ToBytes() const
Wtxid(const WtxidView &view)
WtxidView(const btck_Wtxid *ptr)
static const PrecomputedData data
Precomputed COutPoint and CCoins values.
#define T(expected, seed, data)
constexpr T & operator|=(T &lhs, T rhs)
std::string_view ToStringView(btck_StringView view)
void set_mock_time(std::chrono::seconds timestamp)
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_min_level(LogLevel level)
constexpr T operator&(T lhs, T rhs)
constexpr std::string_view Name(LogLevel level) noexcept
constexpr T operator|(T lhs, T rhs)
@ ERROR_INVALID_FLAGS_COMBINATION
@ ERROR_SPENT_OUTPUTS_REQUIRED
@ UNKNOWN_NEW_RULES_ACTIVATED
@ LARGE_WORK_INVALID_CHAIN
constexpr T operator^(T lhs, T rhs)
constexpr T & operator^=(T &lhs, T rhs)
void operator()(CType *ptr) const noexcept
A struct for holding the kernel notification callbacks.
void * user_data
Holds a user-defined opaque structure that is passed to the notification callbacks.
A non-owning view of a string.
Holds the validation interface callbacks.
void * user_data
Holds a user-defined opaque structure that is passed to the validation interface callbacks.
bool CheckTransaction(const CTransaction &tx, TxValidationState &state)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.