Bitcoin Kernel
C header for interacting with the Bitcoin Kernel library.
|
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | kernel_ValidationInterfaceCallbacks |
struct | kernel_NotificationInterfaceCallbacks |
struct | kernel_LoggingOptions |
struct | kernel_BlockHash |
struct | kernel_ByteArray |
Macros | |
#define | BITCOINKERNEL_GNUC_PREREQ(_maj, _min) 0 |
#define | BITCOINKERNEL_WARN_UNUSED_RESULT |
#define | BITCOINKERNEL_ARG_NONNULL(_x) |
Functions | |
Transaction | |
Functions for working with transactions. | |
kernel_Transaction * | kernel_transaction_create (const unsigned char *raw_transaction, size_t raw_transaction_len) |
Create a new transaction from the serialized data. | |
void | kernel_transaction_destroy (kernel_Transaction *transaction) |
ScriptPubkey | |
Functions for working with script pubkeys. | |
kernel_ScriptPubkey * | kernel_script_pubkey_create (const unsigned char *script_pubkey, size_t script_pubkey_len) |
Create a script pubkey from serialized data. | |
kernel_ByteArray * | kernel_copy_script_pubkey_data (const kernel_ScriptPubkey *script_pubkey) |
Copies the script pubkey data into the returned byte array. | |
void | kernel_script_pubkey_destroy (kernel_ScriptPubkey *script_pubkey) |
TransactionOutput | |
Functions for working with transaction outputs. | |
kernel_TransactionOutput * | kernel_transaction_output_create (const kernel_ScriptPubkey *script_pubkey, int64_t amount) |
Create a transaction output from a script pubkey and an amount. | |
kernel_ScriptPubkey * | kernel_copy_script_pubkey_from_output (kernel_TransactionOutput *transaction_output) |
Copies the script pubkey of an output in the returned script pubkey opaque object. | |
int64_t | kernel_get_transaction_output_amount (kernel_TransactionOutput *transaction_output) |
Gets the amount associated with this transaction output. | |
void | kernel_transaction_output_destroy (kernel_TransactionOutput *transaction_output) |
Script | |
Functions for working with scripts. | |
bool | kernel_verify_script (const kernel_ScriptPubkey *script_pubkey, int64_t amount, const kernel_Transaction *tx_to, const kernel_TransactionOutput **spent_outputs, size_t spent_outputs_len, unsigned int input_index, unsigned int flags, kernel_ScriptVerifyStatus *status) 3) |
Verify if the input at input_index of tx_to spends the script pubkey under the constraints specified by flags. If the kernel_SCRIPT_FLAGS_VERIFY_WITNESS flag is set in the flags bitfield, the amount parameter is used. If the taproot flag is set, the spent outputs parameter is used to validate taproot transactions. | |
Logging | |
Logging-related functions. | |
void | kernel_disable_logging () |
This disables the global internal logger. No log messages will be buffered internally anymore once this is called and the buffer is cleared. This function should only be called once. Log messages will be buffered until this function is called, or a logging connection is created. | |
bool | kernel_add_log_level_category (const kernel_LogCategory category, kernel_LogLevel level) |
Set the log level of the global internal logger. This does not enable the selected categories. Use kernel_enable_log_category to start logging from a specific, or all categories. | |
bool | kernel_enable_log_category (const kernel_LogCategory category) |
Enable a specific log category for the global internal logger. | |
bool | kernel_disable_log_category (const kernel_LogCategory category) |
kernel_LoggingConnection * | kernel_logging_connection_create (kernel_LogCallback callback, const void *user_data, const kernel_LoggingOptions options) |
Start logging messages through the provided callback. Log messages produced before this function is first called are buffered and on calling this function are logged immediately. | |
void | kernel_logging_connection_destroy (kernel_LoggingConnection *logging_connection) |
ChainParameters | |
Functions for working with chain parameters. | |
const kernel_ChainParameters * | kernel_chain_parameters_create (const kernel_ChainType chain_type) |
Creates a chain parameters struct with default parameters based on the passed in chain type. | |
void | kernel_chain_parameters_destroy (const kernel_ChainParameters *chain_parameters) |
ContextOptions | |
Functions for working with context options. | |
kernel_ContextOptions * | kernel_context_options_create () |
void | kernel_context_options_set_chainparams (kernel_ContextOptions *context_options, const kernel_ChainParameters *chain_parameters) 2) |
Sets the chain params for the context options. The context created with the options will be configured for these chain parameters. | |
void | kernel_context_options_set_notifications (kernel_ContextOptions *context_options, kernel_NotificationInterfaceCallbacks notifications) |
Set the kernel notifications for the context options. The context created with the options will be configured with these notifications. | |
void | kernel_context_options_set_validation_interface (kernel_ContextOptions *context_options, kernel_ValidationInterfaceCallbacks validation_interface_callbacks) |
Set the validation interface callbacks for the context options. The context created with the options will be configured for these validation interface callbacks. The callbacks will then be triggered from validation events issued by the chainstate manager created from the same context. | |
void | kernel_context_options_destroy (kernel_ContextOptions *context_options) |
Context | |
Functions for working with contexts. | |
kernel_Context * | kernel_context_create (const kernel_ContextOptions *context_options) |
Create a new kernel context. If the options have not been previously set, their corresponding fields will be initialized to default values; the context will assume mainnet chain parameters and won't attempt to call the kernel notification callbacks. | |
bool | kernel_context_interrupt (kernel_Context *context) |
Interrupt can be used to halt long-running validation functions like when reindexing, importing or processing blocks. | |
void | kernel_context_destroy (kernel_Context *context) |
ChainstateManagerOptions | |
Functions for working with chainstate manager options. | |
kernel_ChainstateManagerOptions * | kernel_chainstate_manager_options_create (const kernel_Context *context, const char *data_directory, size_t data_directory_len) 2) |
Create options for the chainstate manager. | |
void | kernel_chainstate_manager_options_set_worker_threads_num (kernel_ChainstateManagerOptions *chainstate_manager_options, int worker_threads) |
Set the number of available worker threads used during validation. | |
void | kernel_chainstate_manager_options_destroy (kernel_ChainstateManagerOptions *chainstate_manager_options) |
BlockManagerOptions | |
Functions for working with block manager options. | |
kernel_BlockManagerOptions * | kernel_block_manager_options_create (const kernel_Context *context, const char *blocks_directory, size_t blocks_directory_len) 2) |
Create options for the block manager. The block manager is used internally by the chainstate manager for block storage and indexing. | |
void | kernel_block_manager_options_destroy (kernel_BlockManagerOptions *block_manager_options) |
ChainstateLoadOptions | |
Functions for working with chainstate load options. | |
kernel_ChainstateLoadOptions * | kernel_chainstate_load_options_create () |
void | kernel_chainstate_load_options_set_wipe_block_tree_db (kernel_ChainstateLoadOptions *chainstate_load_options, bool wipe_block_tree_db) |
Sets wipe block tree db in the chainstate load options. | |
void | kernel_chainstate_load_options_set_wipe_chainstate_db (kernel_ChainstateLoadOptions *chainstate_load_options, bool wipe_chainstate_db) |
Sets wipe chainstate db in the chainstate load options. | |
void | kernel_chainstate_load_options_set_block_tree_db_in_memory (kernel_ChainstateLoadOptions *chainstate_load_options, bool block_tree_db_in_memory) |
Sets block tree db in memory in the chainstate load options. | |
void | kernel_chainstate_load_options_set_chainstate_db_in_memory (kernel_ChainstateLoadOptions *chainstate_load_options, bool chainstate_db_in_memory) |
Sets chainstate db in memory in the chainstate load options. | |
void | kernel_chainstate_load_options_destroy (kernel_ChainstateLoadOptions *chainstate_load_options) |
ChainstateManager | |
Functions for chainstate management. | |
kernel_ChainstateManager * | kernel_chainstate_manager_create (const kernel_Context *context, const kernel_ChainstateManagerOptions *chainstate_manager_options, const kernel_BlockManagerOptions *block_manager_options, const kernel_ChainstateLoadOptions *chainstate_load_options) 2 |
Create a chainstate manager. This is the main object for many validation tasks as well as for retrieving data from the chain and interacting with its chainstate and indexes. It is only valid for as long as the passed in context also remains in memory. | |
kernel_ChainstateManager bool | kernel_import_blocks (const kernel_Context *context, kernel_ChainstateManager *chainstate_manager, const char **block_file_paths, size_t *block_file_paths_lens, size_t block_file_paths_len) 2) |
May be called after kernel_chainstate_manager_load_chainstate to initialize the chainstate manager. Triggers the start of a reindex if the option was previously set for the chainstate and block manager. Can also import an array of existing block files selected by the user. | |
bool | kernel_chainstate_manager_process_block (const kernel_Context *context, kernel_ChainstateManager *chainstate_manager, kernel_Block *block, bool *new_block) 2 |
Process and validate the passed in block with the chainstate manager. More detailed validation information in case of a failure can also be retrieved through a registered validation interface. If the block fails to validate the block_checked callback's 'BlockValidationState' will contain details. | |
bool void | kernel_chainstate_manager_destroy (kernel_ChainstateManager *chainstate_manager, const kernel_Context *context) |
Block | |
Functions for working with blocks. | |
kernel_Block * | kernel_read_block_from_disk (const kernel_Context *context, kernel_ChainstateManager *chainstate_manager, const kernel_BlockIndex *block_index) 2 |
Reads the block the passed in block index points to from disk and returns it. | |
kernel_Block kernel_Block * | kernel_block_create (const unsigned char *raw_block, size_t raw_block_len) |
Parse a serialized raw block into a new block object. | |
kernel_BlockHash * | kernel_block_get_hash (kernel_Block *block) |
Calculate and return the hash of a block. | |
ByteArray | |
Functions for working with byte arrays. | |
kernel_BlockHash * | kernel_block_pointer_get_hash (const kernel_BlockPointer *block) |
kernel_ByteArray * | kernel_copy_block_data (kernel_Block *block) |
Copies block data into the returned byte array. | |
kernel_ByteArray * | kernel_copy_block_pointer_data (const kernel_BlockPointer *block) |
Copies block data into the returned byte array. | |
void | kernel_block_destroy (kernel_Block *block) |
void | kernel_byte_array_destroy (kernel_ByteArray *byte_array) |
BlockValidationState | |
Functions for working with block validation states. | |
kernel_ValidationMode | kernel_get_validation_mode_from_block_validation_state (const kernel_BlockValidationState *block_validation_state) |
kernel_BlockValidationResult | kernel_get_block_validation_result_from_block_validation_state (const kernel_BlockValidationState *block_validation_state) |
BlockIndex | |
Functions for working with block indexes. | |
kernel_BlockIndex * | kernel_get_block_index_from_tip (const kernel_Context *context, kernel_ChainstateManager *chainstate_manager) 2) |
Get the block index entry of the current chain tip. Once returned, there is no guarantee that it remains in the active chain. | |
kernel_BlockIndex * | kernel_get_block_index_from_genesis (const kernel_Context *context, kernel_ChainstateManager *chainstate_manager) 2) |
Get the block index entry of the genesis block. | |
kernel_BlockIndex * | kernel_get_block_index_from_hash (const kernel_Context *context, kernel_ChainstateManager *chainstate_manager, kernel_BlockHash *block_hash) 2 |
Retrieve a block index by its block hash. | |
kernel_BlockIndex kernel_BlockIndex * | kernel_get_block_index_from_height (const kernel_Context *context, kernel_ChainstateManager *chainstate_manager, int block_height) 2) |
Retrieve a block index by its height in the currently active chain. Once retrieved there is no guarantee that it remains in the active chain. | |
kernel_BlockIndex * | kernel_get_next_block_index (const kernel_Context *context, kernel_ChainstateManager *chainstate_manager, const kernel_BlockIndex *block_index) 2 |
Return the next block index in the currently active chain, or null if the current block index is the tip, or is not in the currently active chain. | |
kernel_BlockIndex kernel_BlockIndex * | kernel_get_previous_block_index (const kernel_BlockIndex *block_index) |
Returns the previous block index in the chain, or null if the current block index entry is the genesis block. | |
int32_t | kernel_block_index_get_height (const kernel_BlockIndex *block_index) |
Return the height of a certain block index. | |
void | kernel_block_index_destroy (kernel_BlockIndex *block_index) |
Destroy the block index. | |
BlockUndo | |
Functions for working with block undo data. | |
kernel_BlockUndo * | kernel_read_block_undo_from_disk (const kernel_Context *context, kernel_ChainstateManager *chainstate_manager, const kernel_BlockIndex *block_index) 2 |
Reads the block undo data the passed in block index points to from disk and returns it. | |
kernel_BlockUndo uint64_t | kernel_block_undo_size (const kernel_BlockUndo *block_undo) |
Returns the number of transactions whose undo data is contained in block undo. | |
uint64_t | kernel_get_transaction_undo_size (const kernel_BlockUndo *block_undo, uint64_t transaction_undo_index) |
Returns the number of previous transaction outputs contained in the transaction undo data. | |
kernel_TransactionOutput * | kernel_get_undo_output_by_index (const kernel_BlockUndo *block_undo, uint64_t transaction_undo_index, uint64_t output_index) |
Return a transaction output contained in the transaction undo data of a block undo data at a certain index. | |
void | kernel_block_undo_destroy (kernel_BlockUndo *block_undo) |
BlockHash | |
Functions for working with block hashes. | |
kernel_BlockHash * | kernel_block_index_get_block_hash (const kernel_BlockIndex *block_index) |
Return the block hash associated with a block index. | |
void | kernel_block_hash_destroy (kernel_BlockHash *block_hash) |
#define BITCOINKERNEL_ARG_NONNULL | ( | _x | ) |
#define BITCOINKERNEL_GNUC_PREREQ | ( | _maj, | |
_min | |||
) | 0 |
#define BITCOINKERNEL_WARN_UNUSED_RESULT |
typedef struct kernel_Block kernel_Block |
Opaque data structure for holding a block.
typedef struct kernel_BlockIndex kernel_BlockIndex |
Opaque data structure for holding a block index pointer.
This is a pointer to an element in the block index currently in memory of the chainstate manager. It is valid for the lifetime of the chainstate manager it was retrieved from.
typedef struct kernel_BlockManagerOptions kernel_BlockManagerOptions |
Opaque data structure for holding options for creating a new chainstate manager.
The chainstate manager has an internal block manager that takes its own set of parameters. It is initialized with default options.
typedef struct kernel_BlockPointer kernel_BlockPointer |
Opaque data structure for holding a non-owned block. This is typically a block available to the user through one of the validation callbacks.
typedef struct kernel_BlockUndo kernel_BlockUndo |
Opaque data structure for holding a block undo struct.
It holds all the previous outputs consumed by all transactions in a specific block. Internally it holds a nested vector. The top level vector has an entry for each transaction in a block (in order of the actual transactions of the block and minus the coinbase transaction). Each entry is in turn a vector of all the previous outputs of a transaction (in order of their corresponding inputs).
typedef struct kernel_BlockValidationState kernel_BlockValidationState |
Opaque data structure for holding the state of a block during validation.
Contains information indicating whether validation was successful, and if not which step during block validation failed.
typedef struct kernel_ChainParameters kernel_ChainParameters |
Opaque data structure for holding the chain parameters.
These are eventually placed into a kernel context through the kernel context options. The parameters describe the properties of a chain, and may be instantiated for either mainnet, testnet, signet, or regtest.
typedef struct kernel_ChainstateLoadOptions kernel_ChainstateLoadOptions |
Opaque data structure for holding parameters used for loading the chainstate of a chainstate manager.
Is initialized with default parameters.
typedef struct kernel_ChainstateManager kernel_ChainstateManager |
Opaque data structure for holding a chainstate manager.
The chainstate manager is the central object for doing validation tasks as well as retrieving data from the chain. Internally it is a complex data structure with diverse functionality.
The chainstate manager is only valid for as long as the context with which it was created remains in memory.
Its functionality will be more and more exposed in the future.
typedef struct kernel_ChainstateManagerOptions kernel_ChainstateManagerOptions |
Opaque data structure for holding options for creating a new chainstate manager.
The chainstate manager options are used to set some parameters for the chainstate manager. For now it just holds default options.
typedef struct kernel_Context kernel_Context |
Opaque data structure for holding a kernel context.
The kernel context is used to initialize internal state and hold the chain parameters and callbacks for handling error and validation events. Once other validation objects are instantiated from it, the context needs to be kept in memory for the duration of their lifetimes.
The processing of validation events is done through an internal task runner owned by the context. The task runner drives the execution of events triggering validation interface callbacks. Multiple validation interfaces can be registered with the context. The kernel will create an event for each of the registered validation interfaces through the task runner.
A constructed context can be safely used from multiple threads, but functions taking it as a non-cost argument need exclusive access to it.
typedef struct kernel_ContextOptions kernel_ContextOptions |
Opaque data structure for holding options for creating a new kernel context.
Once a kernel context has been created from these options, they may be destroyed. The options hold the notification callbacks as well as the selected chain type until they are passed to the context. If no options are configured, the context will be instantiated with no callbacks and for mainnet. Their content and scope can be expanded over time.
typedef void(* kernel_LogCallback) (void *user_data, const char *message, size_t message_len) |
Callback function types Function signature for the global logging callback. All bitcoin kernel internal logs will pass through this callback.
typedef struct kernel_LoggingConnection kernel_LoggingConnection |
Opaque data structure for holding a logging connection.
The logging connection can be used to manually stop logging.
Messages that were logged before a connection is created are buffered in a 1MB buffer. Logging can alternatively be permanently disabled by calling kernel_disable_logging().
typedef void(* kernel_NotifyBlockTip) (void *user_data, kernel_SynchronizationState state, const kernel_BlockIndex *index) |
Function signatures for the kernel notifications.
typedef void(* kernel_NotifyFatalError) (void *user_data, const char *message, size_t message_len) |
typedef void(* kernel_NotifyFlushError) (void *user_data, const char *message, size_t message_len) |
typedef void(* kernel_NotifyHeaderTip) (void *user_data, kernel_SynchronizationState state, int64_t height, int64_t timestamp, bool presync) |
typedef void(* kernel_NotifyProgress) (void *user_data, const char *title, size_t title_len, int progress_percent, bool resume_possible) |
typedef void(* kernel_NotifyWarningSet) (void *user_data, kernel_Warning warning, const char *message, size_t message_len) |
typedef void(* kernel_NotifyWarningUnset) (void *user_data, kernel_Warning warning) |
typedef struct kernel_ScriptPubkey kernel_ScriptPubkey |
Opaque data structure for holding a script pubkey.
typedef struct kernel_Transaction kernel_Transaction |
Opaque data structure for holding a transaction.
typedef struct kernel_TransactionOutput kernel_TransactionOutput |
Opaque data structure for holding a transaction output.
typedef struct kernel_ValidationInterface kernel_ValidationInterface |
Opaque data structure for holding a validation interface.
The validation interface can be registered with the internal task runner of an existing context. It holds callbacks that will be triggered by certain validation events. The callbacks registered with it will block further validation progress when triggered.
typedef void(* kernel_ValidationInterfaceBlockChecked) (void *user_data, const kernel_BlockPointer *block, const kernel_BlockValidationState *state) |
Function signatures for the validation interface.
A granular "reason" why a block was invalid.
enum kernel_ChainType |
enum kernel_LogCategory |
A collection of logging categories that may be encountered by kernel code.
enum kernel_LogLevel |
enum kernel_ScriptFlags |
Script verification flags that may be composed with each other.
A collection of status codes that may be issued by the script verify function.
enum kernel_Warning |
bool kernel_add_log_level_category | ( | const kernel_LogCategory | category, |
kernel_LogLevel | level | ||
) |
Set the log level of the global internal logger. This does not enable the selected categories. Use kernel_enable_log_category
to start logging from a specific, or all categories.
[in] | category | If kernel_LOG_ALL is chosen, all messages at the specified level will be logged. Otherwise only messages from the specified category will be logged at the specified level and above. |
[in] | level | Log level at which the log category is set. |
kernel_Block kernel_Block * kernel_block_create | ( | const unsigned char * | raw_block, |
size_t | raw_block_len | ||
) |
Parse a serialized raw block into a new block object.
[in] | raw_block | Non-null, serialized block. |
[in] | raw_block_len | Length of the serialized block. |
void kernel_block_destroy | ( | kernel_Block * | block | ) |
Destroy the block.
kernel_BlockHash * kernel_block_get_hash | ( | kernel_Block * | block | ) |
Calculate and return the hash of a block.
[in] | block | Non-null. |
void kernel_block_hash_destroy | ( | kernel_BlockHash * | block_hash | ) |
Destroy the block hash.
void kernel_block_index_destroy | ( | kernel_BlockIndex * | block_index | ) |
Destroy the block index.
kernel_BlockHash * kernel_block_index_get_block_hash | ( | const kernel_BlockIndex * | block_index | ) |
Return the block hash associated with a block index.
[in] | block_index | Non-null. |
int32_t kernel_block_index_get_height | ( | const kernel_BlockIndex * | block_index | ) |
Return the height of a certain block index.
[in] | block_index | Non-null. |
kernel_BlockManagerOptions * kernel_block_manager_options_create | ( | const kernel_Context * | context, |
const char * | blocks_directory, | ||
size_t | blocks_directory_len | ||
) |
Create options for the block manager. The block manager is used internally by the chainstate manager for block storage and indexing.
[in] | context | Non-null, the created options will associate with this kernel context for the duration of their lifetime. The same context needs to be used when instantiating the chainstate manager. |
[in] | blocks_directory | Non-null, path string of the directory containing the block data. If the directory does not exist yet, it will be created. |
void kernel_block_manager_options_destroy | ( | kernel_BlockManagerOptions * | block_manager_options | ) |
Destroy the block manager options.
kernel_BlockHash * kernel_block_pointer_get_hash | ( | const kernel_BlockPointer * | block | ) |
void kernel_block_undo_destroy | ( | kernel_BlockUndo * | block_undo | ) |
Destroy the block undo data.
kernel_BlockUndo uint64_t kernel_block_undo_size | ( | const kernel_BlockUndo * | block_undo | ) |
Returns the number of transactions whose undo data is contained in block undo.
[in] | block_undo | Non-null. |
void kernel_byte_array_destroy | ( | kernel_ByteArray * | byte_array | ) |
A helper function for destroying an existing byte array.
const kernel_ChainParameters * kernel_chain_parameters_create | ( | const kernel_ChainType | chain_type | ) |
Creates a chain parameters struct with default parameters based on the passed in chain type.
[in] | chain_type | Controls the chain parameters type created. |
void kernel_chain_parameters_destroy | ( | const kernel_ChainParameters * | chain_parameters | ) |
Destroy the chain parameters.
kernel_ChainstateLoadOptions * kernel_chainstate_load_options_create | ( | ) |
Create options for loading the chainstate.
void kernel_chainstate_load_options_destroy | ( | kernel_ChainstateLoadOptions * | chainstate_load_options | ) |
Destroy the chainstate load options
void kernel_chainstate_load_options_set_block_tree_db_in_memory | ( | kernel_ChainstateLoadOptions * | chainstate_load_options, |
bool | block_tree_db_in_memory | ||
) |
Sets block tree db in memory in the chainstate load options.
[in] | chainstate_load_options | Non-null, created by kernel_chainstate_load_options_create. |
[in] | block_tree_db_in_memory | Set block tree db in memory. |
void kernel_chainstate_load_options_set_chainstate_db_in_memory | ( | kernel_ChainstateLoadOptions * | chainstate_load_options, |
bool | chainstate_db_in_memory | ||
) |
Sets chainstate db in memory in the chainstate load options.
[in] | chainstate_load_options | Non-null, created by kernel_chainstate_load_options_create. |
[in] | chainstate_db_in_memory | Set chainstate db in memory. |
void kernel_chainstate_load_options_set_wipe_block_tree_db | ( | kernel_ChainstateLoadOptions * | chainstate_load_options, |
bool | wipe_block_tree_db | ||
) |
Sets wipe block tree db in the chainstate load options.
[in] | chainstate_load_options | Non-null, created by kernel_chainstate_load_options_create. |
[in] | wipe_block_tree_db | Set wipe block tree db. |
void kernel_chainstate_load_options_set_wipe_chainstate_db | ( | kernel_ChainstateLoadOptions * | chainstate_load_options, |
bool | wipe_chainstate_db | ||
) |
Sets wipe chainstate db in the chainstate load options.
[in] | chainstate_load_options | Non-null, created by kernel_chainstate_load_options_create. |
[in] | wipe_chainstate_db | Set wipe chainstate db. |
kernel_ChainstateManager * kernel_chainstate_manager_create | ( | const kernel_Context * | context, |
const kernel_ChainstateManagerOptions * | chainstate_manager_options, | ||
const kernel_BlockManagerOptions * | block_manager_options, | ||
const kernel_ChainstateLoadOptions * | chainstate_load_options | ||
) |
Create a chainstate manager. This is the main object for many validation tasks as well as for retrieving data from the chain and interacting with its chainstate and indexes. It is only valid for as long as the passed in context also remains in memory.
[in] | chainstate_manager_options | Non-null, created by kernel_chainstate_manager_options_create. |
[in] | block_manager_options | Non-null, created by kernel_block_manager_options_create. |
[in] | context | Non-null, the created chainstate manager will associate with this kernel context for the duration of its lifetime. The same context needs to be used for later interactions with the chainstate manager. |
bool void kernel_chainstate_manager_destroy | ( | kernel_ChainstateManager * | chainstate_manager, |
const kernel_Context * | context | ||
) |
Destroy the chainstate manager.
kernel_ChainstateManagerOptions * kernel_chainstate_manager_options_create | ( | const kernel_Context * | context, |
const char * | data_directory, | ||
size_t | data_directory_len | ||
) |
Create options for the chainstate manager.
[in] | context | Non-null, the created options will associate with this kernel context for the duration of their lifetime. The same context needs to be used when instantiating the chainstate manager. |
[in] | data_directory | Non-null, path string of the directory containing the chainstate data. If the directory does not exist yet, it will be created. |
void kernel_chainstate_manager_options_destroy | ( | kernel_ChainstateManagerOptions * | chainstate_manager_options | ) |
Destroy the chainstate manager options.
void kernel_chainstate_manager_options_set_worker_threads_num | ( | kernel_ChainstateManagerOptions * | chainstate_manager_options, |
int | worker_threads | ||
) |
Set the number of available worker threads used during validation.
[in] | chainstate_manager_options | Non-null, options to be set. |
[in] | worker_threads | The number of worker threads that should be spawned in the thread pool used for validation. When set to 0 no parallel verification is done. The value range is clamped internally between 0 and 15. |
bool kernel_chainstate_manager_process_block | ( | const kernel_Context * | context, |
kernel_ChainstateManager * | chainstate_manager, | ||
kernel_Block * | block, | ||
bool * | new_block | ||
) |
Process and validate the passed in block with the chainstate manager. More detailed validation information in case of a failure can also be retrieved through a registered validation interface. If the block fails to validate the block_checked
callback's 'BlockValidationState' will contain details.
[in] | context | Non-null. |
[in] | chainstate_manager | Non-null. |
[in] | block | Non-null, block to be validated. |
[out] | new_block | Nullable, will be set to true if this block was not processed before, and false otherwise. |
kernel_Context * kernel_context_create | ( | const kernel_ContextOptions * | context_options | ) |
Create a new kernel context. If the options have not been previously set, their corresponding fields will be initialized to default values; the context will assume mainnet chain parameters and won't attempt to call the kernel notification callbacks.
[in] | context_options | Nullable, created by kernel_context_options_create. |
void kernel_context_destroy | ( | kernel_Context * | context | ) |
Destroy the context.
bool kernel_context_interrupt | ( | kernel_Context * | context | ) |
Interrupt can be used to halt long-running validation functions like when reindexing, importing or processing blocks.
[in] | context | Non-null. |
kernel_ContextOptions * kernel_context_options_create | ( | ) |
Creates an empty context options.
void kernel_context_options_destroy | ( | kernel_ContextOptions * | context_options | ) |
Destroy the context options.
void kernel_context_options_set_chainparams | ( | kernel_ContextOptions * | context_options, |
const kernel_ChainParameters * | chain_parameters | ||
) |
Sets the chain params for the context options. The context created with the options will be configured for these chain parameters.
[in] | context_options | Non-null, previously created by kernel_context_options_create. |
[in] | chain_parameters | Is set to the context options. |
void kernel_context_options_set_notifications | ( | kernel_ContextOptions * | context_options, |
kernel_NotificationInterfaceCallbacks | notifications | ||
) |
Set the kernel notifications for the context options. The context created with the options will be configured with these notifications.
[in] | context_options | Non-null, previously created by kernel_context_options_create. |
[in] | notifications | Is set to the context options. |
void kernel_context_options_set_validation_interface | ( | kernel_ContextOptions * | context_options, |
kernel_ValidationInterfaceCallbacks | validation_interface_callbacks | ||
) |
Set the validation interface callbacks for the context options. The context created with the options will be configured for these validation interface callbacks. The callbacks will then be triggered from validation events issued by the chainstate manager created from the same context.
[in] | context_options | Non-null, previously created with kernel_context_options_create. |
[in] | validation_interface_callbacks | The callbacks used for passing validation information to the user. |
kernel_ByteArray * kernel_copy_block_data | ( | kernel_Block * | block | ) |
Copies block data into the returned byte array.
[in] | block | Non-null. |
kernel_ByteArray * kernel_copy_block_pointer_data | ( | const kernel_BlockPointer * | block | ) |
Copies block data into the returned byte array.
[in] | block | Non-null. |
kernel_ByteArray * kernel_copy_script_pubkey_data | ( | const kernel_ScriptPubkey * | script_pubkey | ) |
Copies the script pubkey data into the returned byte array.
[in] | script_pubkey | Non-null. |
kernel_ScriptPubkey * kernel_copy_script_pubkey_from_output | ( | kernel_TransactionOutput * | transaction_output | ) |
Copies the script pubkey of an output in the returned script pubkey opaque object.
[in] | transaction_output | Non-null. |
bool kernel_disable_log_category | ( | const kernel_LogCategory | category | ) |
Disable a specific log category for the global internal logger.
[in] | category | If kernel_LOG_ALL is chosen, all categories will be disabled. |
void kernel_disable_logging | ( | ) |
This disables the global internal logger. No log messages will be buffered internally anymore once this is called and the buffer is cleared. This function should only be called once. Log messages will be buffered until this function is called, or a logging connection is created.
bool kernel_enable_log_category | ( | const kernel_LogCategory | category | ) |
Enable a specific log category for the global internal logger.
[in] | category | If kernel_LOG_ALL is chosen, all categories will be enabled. |
kernel_BlockIndex * kernel_get_block_index_from_genesis | ( | const kernel_Context * | context, |
kernel_ChainstateManager * | chainstate_manager | ||
) |
Get the block index entry of the genesis block.
[in] | context | Non-null. |
[in] | chainstate_manager | Non-null. |
kernel_BlockIndex * kernel_get_block_index_from_hash | ( | const kernel_Context * | context, |
kernel_ChainstateManager * | chainstate_manager, | ||
kernel_BlockHash * | block_hash | ||
) |
Retrieve a block index by its block hash.
[in] | context | Non-null. |
[in] | chainstate_manager | Non-null. |
[in] | block_hash | Non-null. |
kernel_BlockIndex kernel_BlockIndex * kernel_get_block_index_from_height | ( | const kernel_Context * | context, |
kernel_ChainstateManager * | chainstate_manager, | ||
int | block_height | ||
) |
Retrieve a block index by its height in the currently active chain. Once retrieved there is no guarantee that it remains in the active chain.
[in] | context | Non-null. |
[in] | chainstate_manager | Non-null. |
[in] | block_height | Height in the chain of the to be retrieved block index. |
kernel_BlockIndex * kernel_get_block_index_from_tip | ( | const kernel_Context * | context, |
kernel_ChainstateManager * | chainstate_manager | ||
) |
Get the block index entry of the current chain tip. Once returned, there is no guarantee that it remains in the active chain.
[in] | context | Non-null. |
[in] | chainstate_manager | Non-null. |
kernel_BlockValidationResult kernel_get_block_validation_result_from_block_validation_state | ( | const kernel_BlockValidationState * | block_validation_state | ) |
Returns the validation result from an opaque block validation state pointer.
kernel_BlockIndex * kernel_get_next_block_index | ( | const kernel_Context * | context, |
kernel_ChainstateManager * | chainstate_manager, | ||
const kernel_BlockIndex * | block_index | ||
) |
Return the next block index in the currently active chain, or null if the current block index is the tip, or is not in the currently active chain.
[in] | context | Non-null. |
[in] | block_index | Non-null. |
[in] | chainstate_manager | Non-null. |
kernel_BlockIndex kernel_BlockIndex * kernel_get_previous_block_index | ( | const kernel_BlockIndex * | block_index | ) |
Returns the previous block index in the chain, or null if the current block index entry is the genesis block.
[in] | block_index | Non-null. |
int64_t kernel_get_transaction_output_amount | ( | kernel_TransactionOutput * | transaction_output | ) |
Gets the amount associated with this transaction output.
[in] | transaction_output | Non-null. |
uint64_t kernel_get_transaction_undo_size | ( | const kernel_BlockUndo * | block_undo, |
uint64_t | transaction_undo_index | ||
) |
Returns the number of previous transaction outputs contained in the transaction undo data.
[in] | block_undo | Non-null, the block undo data from which tx_undo was retrieved from. |
[in] | transaction_undo_index | The index of the transaction undo data within the block undo data. |
kernel_TransactionOutput * kernel_get_undo_output_by_index | ( | const kernel_BlockUndo * | block_undo, |
uint64_t | transaction_undo_index, | ||
uint64_t | output_index | ||
) |
Return a transaction output contained in the transaction undo data of a block undo data at a certain index.
[in] | block_undo | Non-null. |
[in] | transaction_undo_index | The index of the transaction undo data within the block undo data. |
[in] | output_index | The index of the to be retrieved transaction output within the transaction undo data. |
kernel_ValidationMode kernel_get_validation_mode_from_block_validation_state | ( | const kernel_BlockValidationState * | block_validation_state | ) |
Returns the validation mode from an opaque block validation state pointer.
kernel_ChainstateManager bool kernel_import_blocks | ( | const kernel_Context * | context, |
kernel_ChainstateManager * | chainstate_manager, | ||
const char ** | block_file_paths, | ||
size_t * | block_file_paths_lens, | ||
size_t | block_file_paths_len | ||
) |
May be called after kernel_chainstate_manager_load_chainstate to initialize the chainstate manager. Triggers the start of a reindex if the option was previously set for the chainstate and block manager. Can also import an array of existing block files selected by the user.
[in] | context | Non-null. |
[in] | chainstate_manager | Non-null. |
[in] | block_file_paths | Nullable, array of block files described by their full filesystem paths. |
[in] | block_file_paths_len | Length of the block_file_paths array. |
kernel_LoggingConnection * kernel_logging_connection_create | ( | kernel_LogCallback | callback, |
const void * | user_data, | ||
const kernel_LoggingOptions | options | ||
) |
Start logging messages through the provided callback. Log messages produced before this function is first called are buffered and on calling this function are logged immediately.
[in] | callback | Non-null, function through which messages will be logged. |
[in] | user_data | Nullable, holds a user-defined opaque structure. Is passed back to the user through the callback. |
[in] | options | Sets formatting options of the log messages. |
void kernel_logging_connection_destroy | ( | kernel_LoggingConnection * | logging_connection | ) |
Stop logging and destroy the logging connection.
kernel_Block * kernel_read_block_from_disk | ( | const kernel_Context * | context, |
kernel_ChainstateManager * | chainstate_manager, | ||
const kernel_BlockIndex * | block_index | ||
) |
Reads the block the passed in block index points to from disk and returns it.
[in] | context | Non-null. |
[in] | chainstate_manager | Non-null. |
[in] | block_index | Non-null. |
kernel_BlockUndo * kernel_read_block_undo_from_disk | ( | const kernel_Context * | context, |
kernel_ChainstateManager * | chainstate_manager, | ||
const kernel_BlockIndex * | block_index | ||
) |
Reads the block undo data the passed in block index points to from disk and returns it.
[in] | context | Non-null. |
[in] | chainstate_manager | Non-null. |
[in] | block_index | Non-null. |
kernel_ScriptPubkey * kernel_script_pubkey_create | ( | const unsigned char * | script_pubkey, |
size_t | script_pubkey_len | ||
) |
Create a script pubkey from serialized data.
[in] | script_pubkey | Non-null. |
[in] | script_pubkey_len | Length of the script pubkey data. |
void kernel_script_pubkey_destroy | ( | kernel_ScriptPubkey * | script_pubkey | ) |
Destroy the script pubkey.
kernel_Transaction * kernel_transaction_create | ( | const unsigned char * | raw_transaction, |
size_t | raw_transaction_len | ||
) |
Create a new transaction from the serialized data.
[in] | raw_transaction | Non-null. |
[in] | raw_transaction_len | Length of the serialized transaction. |
void kernel_transaction_destroy | ( | kernel_Transaction * | transaction | ) |
Destroy the transaction.
kernel_TransactionOutput * kernel_transaction_output_create | ( | const kernel_ScriptPubkey * | script_pubkey, |
int64_t | amount | ||
) |
Create a transaction output from a script pubkey and an amount.
[in] | script_pubkey | Non-null. |
[in] | amount | The amount associated with the script pubkey for this output. |
void kernel_transaction_output_destroy | ( | kernel_TransactionOutput * | transaction_output | ) |
Destroy the transaction output.
bool kernel_verify_script | ( | const kernel_ScriptPubkey * | script_pubkey, |
int64_t | amount, | ||
const kernel_Transaction * | tx_to, | ||
const kernel_TransactionOutput ** | spent_outputs, | ||
size_t | spent_outputs_len, | ||
unsigned int | input_index, | ||
unsigned int | flags, | ||
kernel_ScriptVerifyStatus * | status | ||
) |
Verify if the input at input_index of tx_to spends the script pubkey under the constraints specified by flags. If the kernel_SCRIPT_FLAGS_VERIFY_WITNESS
flag is set in the flags bitfield, the amount parameter is used. If the taproot flag is set, the spent outputs parameter is used to validate taproot transactions.
[in] | script_pubkey | Non-null, script pubkey to be spent. |
[in] | amount | Amount of the script pubkey's associated output. May be zero if the witness flag is not set. |
[in] | tx_to | Non-null, transaction spending the script_pubkey. |
[in] | spent_outputs | Nullable if the taproot flag is not set. Points to an array of outputs spent by the transaction. |
[in] | spent_outputs_len | Length of the spent_outputs array. |
[in] | input_index | Index of the input in tx_to spending the script_pubkey. |
[in] | flags | Bitfield of kernel_ScriptFlags controlling validation constraints. |
[out] | status | Nullable, will be set to an error code if the operation fails. Should be set to kernel_SCRIPT_VERIFY_OK. |