Bitcoin Kernel
C header for interacting with the Bitcoin Kernel library.
Loading...
Searching...
No Matches
bitcoinkernel.h
Go to the documentation of this file.
1// Copyright (c) 2024-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_KERNEL_BITCOINKERNEL_H
6#define BITCOIN_KERNEL_BITCOINKERNEL_H
7
8#ifndef __cplusplus
9#include <stddef.h>
10#include <stdint.h>
11#else
12#include <cstddef>
13#include <cstdint>
14#endif // __cplusplus
15
16#ifndef BITCOINKERNEL_API
17 #ifdef BITCOINKERNEL_BUILD
18 #if defined(_WIN32)
19 #define BITCOINKERNEL_API __declspec(dllexport)
20 #else
21 #define BITCOINKERNEL_API __attribute__((visibility("default")))
22 #endif
23 #else
24 #if defined(_WIN32) && !defined(BITCOINKERNEL_STATIC)
25 #define BITCOINKERNEL_API __declspec(dllimport)
26 #else
27 #define BITCOINKERNEL_API
28 #endif
29 #endif
30#endif
31
32/* Warning attributes */
33#if defined(__GNUC__)
34 #define BITCOINKERNEL_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
35#else
36 #define BITCOINKERNEL_WARN_UNUSED_RESULT
37#endif
38#if !defined(BITCOINKERNEL_BUILD) && defined(__GNUC__)
39 #define BITCOINKERNEL_ARG_NONNULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
40#else
41 #define BITCOINKERNEL_ARG_NONNULL(...)
42#endif
43
44#ifdef __cplusplus
45extern "C" {
46#endif // __cplusplus
47
110
115
120
133
142
153
169
182
191
202
206typedef struct btck_Block btck_Block;
207
215
220typedef struct btck_Chain btck_Chain;
221
234
243
250typedef struct btck_Coin btck_Coin;
251
258
265
272
273typedef struct btck_Txid btck_Txid;
274
277#define btck_SynchronizationState_INIT_REINDEX ((btck_SynchronizationState)(0))
278#define btck_SynchronizationState_INIT_DOWNLOAD ((btck_SynchronizationState)(1))
279#define btck_SynchronizationState_POST_INIT ((btck_SynchronizationState)(2))
280
282typedef uint8_t btck_Warning;
283#define btck_Warning_UNKNOWN_NEW_RULES_ACTIVATED ((btck_Warning)(0))
284#define btck_Warning_LARGE_WORK_INVALID_CHAIN ((btck_Warning)(1))
285
292typedef void (*btck_LogCallback)(void* user_data, const char* message, size_t message_len);
293
297typedef void (*btck_DestroyCallback)(void* user_data);
298
302typedef void (*btck_NotifyBlockTip)(void* user_data, btck_SynchronizationState state, const btck_BlockTreeEntry* entry, double verification_progress);
303typedef void (*btck_NotifyHeaderTip)(void* user_data, btck_SynchronizationState state, int64_t height, int64_t timestamp, int presync);
304typedef void (*btck_NotifyProgress)(void* user_data, const char* title, size_t title_len, int progress_percent, int resume_possible);
305typedef void (*btck_NotifyWarningSet)(void* user_data, btck_Warning warning, const char* message, size_t message_len);
306typedef void (*btck_NotifyWarningUnset)(void* user_data, btck_Warning warning);
307typedef void (*btck_NotifyFlushError)(void* user_data, const char* message, size_t message_len);
308typedef void (*btck_NotifyFatalError)(void* user_data, const char* message, size_t message_len);
309
313typedef void (*btck_ValidationInterfaceBlockChecked)(void* user_data, btck_Block* block, const btck_BlockValidationState* state);
314typedef void (*btck_ValidationInterfacePowValidBlock)(void* user_data, const btck_BlockTreeEntry* entry, btck_Block* block);
315typedef void (*btck_ValidationInterfaceBlockConnected)(void* user_data, btck_Block* block, const btck_BlockTreeEntry* entry);
316typedef void (*btck_ValidationInterfaceBlockDisconnected)(void* user_data, btck_Block* block, const btck_BlockTreeEntry* entry);
317
321typedef int (*btck_WriteBytes)(const void* bytes, size_t size, void* userdata);
322
327typedef uint8_t btck_ValidationMode;
328#define btck_ValidationMode_VALID ((btck_ValidationMode)(0))
329#define btck_ValidationMode_INVALID ((btck_ValidationMode)(1))
330#define btck_ValidationMode_INTERNAL_ERROR ((btck_ValidationMode)(2))
331
336#define btck_BlockValidationResult_UNSET ((btck_BlockValidationResult)(0))
337#define btck_BlockValidationResult_CONSENSUS ((btck_BlockValidationResult)(1))
338#define btck_BlockValidationResult_CACHED_INVALID ((btck_BlockValidationResult)(2))
339#define btck_BlockValidationResult_INVALID_HEADER ((btck_BlockValidationResult)(3))
340#define btck_BlockValidationResult_MUTATED ((btck_BlockValidationResult)(4))
341#define btck_BlockValidationResult_MISSING_PREV ((btck_BlockValidationResult)(5))
342#define btck_BlockValidationResult_INVALID_PREV ((btck_BlockValidationResult)(6))
343#define btck_BlockValidationResult_TIME_FUTURE ((btck_BlockValidationResult)(7))
344#define btck_BlockValidationResult_HEADER_LOW_WORK ((btck_BlockValidationResult)(8))
345
364
386
390typedef uint8_t btck_LogCategory;
391#define btck_LogCategory_ALL ((btck_LogCategory)(0))
392#define btck_LogCategory_BENCH ((btck_LogCategory)(1))
393#define btck_LogCategory_BLOCKSTORAGE ((btck_LogCategory)(2))
394#define btck_LogCategory_COINDB ((btck_LogCategory)(3))
395#define btck_LogCategory_LEVELDB ((btck_LogCategory)(4))
396#define btck_LogCategory_MEMPOOL ((btck_LogCategory)(5))
397#define btck_LogCategory_PRUNE ((btck_LogCategory)(6))
398#define btck_LogCategory_RAND ((btck_LogCategory)(7))
399#define btck_LogCategory_REINDEX ((btck_LogCategory)(8))
400#define btck_LogCategory_VALIDATION ((btck_LogCategory)(9))
401#define btck_LogCategory_KERNEL ((btck_LogCategory)(10))
402
406typedef uint8_t btck_LogLevel;
407#define btck_LogLevel_TRACE ((btck_LogLevel)(0))
408#define btck_LogLevel_DEBUG ((btck_LogLevel)(1))
409#define btck_LogLevel_INFO ((btck_LogLevel)(2))
410
423
428#define btck_ScriptVerifyStatus_SCRIPT_VERIFY_OK ((btck_ScriptVerifyStatus)(0))
429#define btck_ScriptVerifyStatus_ERROR_INVALID_FLAGS_COMBINATION ((btck_ScriptVerifyStatus)(2))
430#define btck_ScriptVerifyStatus_ERROR_SPENT_OUTPUTS_REQUIRED ((btck_ScriptVerifyStatus)(3))
431
436#define btck_ScriptVerificationFlags_NONE ((btck_ScriptVerificationFlags)(0))
437#define btck_ScriptVerificationFlags_P2SH ((btck_ScriptVerificationFlags)(1U << 0))
438#define btck_ScriptVerificationFlags_DERSIG ((btck_ScriptVerificationFlags)(1U << 2))
439#define btck_ScriptVerificationFlags_NULLDUMMY ((btck_ScriptVerificationFlags)(1U << 4))
440#define btck_ScriptVerificationFlags_CHECKLOCKTIMEVERIFY ((btck_ScriptVerificationFlags)(1U << 9))
441#define btck_ScriptVerificationFlags_CHECKSEQUENCEVERIFY ((btck_ScriptVerificationFlags)(1U << 10))
442#define btck_ScriptVerificationFlags_WITNESS ((btck_ScriptVerificationFlags)(1U << 11))
443#define btck_ScriptVerificationFlags_TAPROOT ((btck_ScriptVerificationFlags)(1U << 17))
444#define btck_ScriptVerificationFlags_ALL ((btck_ScriptVerificationFlags)(btck_ScriptVerificationFlags_P2SH | \
445 btck_ScriptVerificationFlags_DERSIG | \
446 btck_ScriptVerificationFlags_NULLDUMMY | \
447 btck_ScriptVerificationFlags_CHECKLOCKTIMEVERIFY | \
448 btck_ScriptVerificationFlags_CHECKSEQUENCEVERIFY | \
449 btck_ScriptVerificationFlags_WITNESS | \
450 btck_ScriptVerificationFlags_TAPROOT))
451
452typedef uint8_t btck_ChainType;
453#define btck_ChainType_MAINNET ((btck_ChainType)(0))
454#define btck_ChainType_TESTNET ((btck_ChainType)(1))
455#define btck_ChainType_TESTNET_4 ((btck_ChainType)(2))
456#define btck_ChainType_SIGNET ((btck_ChainType)(3))
457#define btck_ChainType_REGTEST ((btck_ChainType)(4))
458
463
472 const void* raw_transaction, size_t raw_transaction_len) BITCOINKERNEL_ARG_NONNULL(1);
473
482 const btck_Transaction* transaction) BITCOINKERNEL_ARG_NONNULL(1);
483
484/*
485 * @brief Serializes the transaction through the passed in callback to bytes.
486 * This is consensus serialization that is also used for the p2p network.
487 *
488 * @param[in] transaction Non-null.
489 * @param[in] writer Non-null, callback to a write bytes function.
490 * @param[in] user_data Holds a user-defined opaque structure that will be
491 * passed back through the writer callback.
492 * @return 0 on success.
493 */
495 const btck_Transaction* transaction,
496 btck_WriteBytes writer,
497 void* user_data) BITCOINKERNEL_ARG_NONNULL(1, 2);
498
506 const btck_Transaction* transaction) BITCOINKERNEL_ARG_NONNULL(1);
507
518 const btck_Transaction* transaction, size_t output_index) BITCOINKERNEL_ARG_NONNULL(1);
519
530 const btck_Transaction* transaction, size_t input_index) BITCOINKERNEL_ARG_NONNULL(1);
531
539 const btck_Transaction* transaction) BITCOINKERNEL_ARG_NONNULL(1);
540
548 const btck_Transaction* transaction) BITCOINKERNEL_ARG_NONNULL(1);
549
554
556
561
569 const void* script_pubkey, size_t script_pubkey_len) BITCOINKERNEL_ARG_NONNULL(1);
570
578 const btck_ScriptPubkey* script_pubkey) BITCOINKERNEL_ARG_NONNULL(1);
579
601 const btck_ScriptPubkey* script_pubkey,
602 int64_t amount,
603 const btck_Transaction* tx_to,
604 const btck_TransactionOutput** spent_outputs, size_t spent_outputs_len,
605 unsigned int input_index,
606 unsigned int flags,
608
609/*
610 * @brief Serializes the script pubkey through the passed in callback to bytes.
611 *
612 * @param[in] script_pubkey Non-null.
613 * @param[in] writer Non-null, callback to a write bytes function.
614 * @param[in] user_data Holds a user-defined opaque structure that will be
615 * passed back through the writer callback.
616 * @return 0 on success.
617 */
619 const btck_ScriptPubkey* script_pubkey,
620 btck_WriteBytes writer,
621 void* user_data) BITCOINKERNEL_ARG_NONNULL(1, 2);
622
627
629
634
643 const btck_ScriptPubkey* script_pubkey,
644 int64_t amount) BITCOINKERNEL_ARG_NONNULL(1);
645
655 const btck_TransactionOutput* transaction_output) BITCOINKERNEL_ARG_NONNULL(1);
656
664 const btck_TransactionOutput* transaction_output) BITCOINKERNEL_ARG_NONNULL(1);
665
673 const btck_TransactionOutput* transaction_output) BITCOINKERNEL_ARG_NONNULL(1);
674
679
681
686
695
709
718
727
743 btck_LogCallback log_callback,
744 void* user_data,
745 btck_DestroyCallback user_data_destroy_callback,
747
752
754
759
768 const btck_ChainType chain_type);
769
774 const btck_ChainParameters* chain_parameters) BITCOINKERNEL_ARG_NONNULL(1);
775
780
782
787
792
801 btck_ContextOptions* context_options,
802 const btck_ChainParameters* chain_parameters) BITCOINKERNEL_ARG_NONNULL(1, 2);
803
812 btck_ContextOptions* context_options,
814
826 btck_ContextOptions* context_options,
827 btck_ValidationInterfaceCallbacks validation_interface_callbacks) BITCOINKERNEL_ARG_NONNULL(1);
828
833
835
840
851 const btck_ContextOptions* context_options);
852
857 const btck_Context* context) BITCOINKERNEL_ARG_NONNULL(1);
858
868
873
875
880
889 const btck_BlockTreeEntry* block_tree_entry) BITCOINKERNEL_ARG_NONNULL(1);
890
898 const btck_BlockTreeEntry* block_tree_entry) BITCOINKERNEL_ARG_NONNULL(1);
899
907 const btck_BlockTreeEntry* block_tree_entry) BITCOINKERNEL_ARG_NONNULL(1);
908
910
915
928 const btck_Context* context,
929 const char* data_directory,
930 size_t data_directory_len,
931 const char* blocks_directory,
932 size_t blocks_directory_len) BITCOINKERNEL_ARG_NONNULL(1, 2);
933
943 btck_ChainstateManagerOptions* chainstate_manager_options,
944 int worker_threads) BITCOINKERNEL_ARG_NONNULL(1);
945
957 btck_ChainstateManagerOptions* chainstate_manager_options,
958 int wipe_block_tree_db,
959 int wipe_chainstate_db) BITCOINKERNEL_ARG_NONNULL(1);
960
968 btck_ChainstateManagerOptions* chainstate_manager_options,
969 int block_tree_db_in_memory) BITCOINKERNEL_ARG_NONNULL(1);
970
978 btck_ChainstateManagerOptions* chainstate_manager_options,
979 int chainstate_db_in_memory) BITCOINKERNEL_ARG_NONNULL(1);
980
985
987
992
1002 const btck_ChainstateManagerOptions* chainstate_manager_options) BITCOINKERNEL_ARG_NONNULL(1);
1003
1015 btck_ChainstateManager* chainstate_manager,
1016 const char** block_file_paths, size_t* block_file_paths_lens,
1017 size_t block_file_paths_len) BITCOINKERNEL_ARG_NONNULL(1, 2);
1018
1034 btck_ChainstateManager* chainstate_manager,
1035 const btck_Block* block,
1036 int* new_block) BITCOINKERNEL_ARG_NONNULL(1, 2, 3);
1037
1050 const btck_ChainstateManager* chainstate_manager) BITCOINKERNEL_ARG_NONNULL(1);
1051
1061 const btck_ChainstateManager* chainstate_manager,
1062 const btck_BlockHash* block_hash) BITCOINKERNEL_ARG_NONNULL(1, 2);
1063
1068
1070
1075
1085 const btck_ChainstateManager* chainstate_manager,
1086 const btck_BlockTreeEntry* block_tree_entry) BITCOINKERNEL_ARG_NONNULL(1, 2);
1087
1096 const void* raw_block, size_t raw_block_len) BITCOINKERNEL_ARG_NONNULL(1);
1097
1106 const btck_Block* block) BITCOINKERNEL_ARG_NONNULL(1);
1107
1115 const btck_Block* block) BITCOINKERNEL_ARG_NONNULL(1);
1116
1126 const btck_Block* block, size_t transaction_index) BITCOINKERNEL_ARG_NONNULL(1);
1127
1128/*
1129 * @brief Calculate and return the hash of a block.
1130 *
1131 * @param[in] block Non-null.
1132 * @return The block hash.
1133 */
1135 const btck_Block* block) BITCOINKERNEL_ARG_NONNULL(1);
1136
1137/*
1138 * @brief Serializes the block through the passed in callback to bytes.
1139 * This is consensus serialization that is also used for the p2p network.
1140 *
1141 * @param[in] block Non-null.
1142 * @param[in] writer Non-null, callback to a write bytes function.
1143 * @param[in] user_data Holds a user-defined opaque structure that will be
1144 * passed back through the writer callback.
1145 * @return 0 on success.
1146 */
1148 const btck_Block* block,
1149 btck_WriteBytes writer,
1150 void* user_data) BITCOINKERNEL_ARG_NONNULL(1, 2);
1151
1156
1158
1163
1168 const btck_BlockValidationState* block_validation_state) BITCOINKERNEL_ARG_NONNULL(1);
1169
1174 const btck_BlockValidationState* block_validation_state) BITCOINKERNEL_ARG_NONNULL(1);
1175
1177
1182
1191 const btck_Chain* chain) BITCOINKERNEL_ARG_NONNULL(1);
1192
1200 const btck_Chain* chain) BITCOINKERNEL_ARG_NONNULL(1);
1201
1202/*
1203 * @brief Get the block tree entry of the genesis block.
1204 *
1205 * @param[in] chain Non-null.
1206 * @return The block tree entry of the genesis block, or null if the chain is empty.
1207 */
1209 const btck_Chain* chain) BITCOINKERNEL_ARG_NONNULL(1);
1210
1221 const btck_Chain* chain,
1222 int block_height) BITCOINKERNEL_ARG_NONNULL(1);
1223
1233 const btck_Chain* chain,
1234 const btck_BlockTreeEntry* block_tree_entry) BITCOINKERNEL_ARG_NONNULL(1, 2);
1235
1237
1242
1252 const btck_ChainstateManager* chainstate_manager,
1253 const btck_BlockTreeEntry* block_tree_entry) BITCOINKERNEL_ARG_NONNULL(1, 2);
1254
1262 const btck_BlockSpentOutputs* block_spent_outputs) BITCOINKERNEL_ARG_NONNULL(1);
1263
1272 const btck_BlockSpentOutputs* block_spent_outputs) BITCOINKERNEL_ARG_NONNULL(1);
1273
1284 const btck_BlockSpentOutputs* block_spent_outputs,
1285 size_t transaction_spent_outputs_index) BITCOINKERNEL_ARG_NONNULL(1);
1286
1291
1293
1298
1306 const btck_TransactionSpentOutputs* transaction_spent_outputs) BITCOINKERNEL_ARG_NONNULL(1);
1307
1316 const btck_TransactionSpentOutputs* transaction_spent_outputs) BITCOINKERNEL_ARG_NONNULL(1);
1317
1329 const btck_TransactionSpentOutputs* transaction_spent_outputs,
1330 size_t coin_index) BITCOINKERNEL_ARG_NONNULL(1);
1331
1336
1338
1343
1351 const btck_TransactionInput* transaction_input) BITCOINKERNEL_ARG_NONNULL(1);
1352
1361 const btck_TransactionInput* transaction_input) BITCOINKERNEL_ARG_NONNULL(1);
1362
1367
1369
1374
1382 const btck_TransactionOutPoint* transaction_out_point) BITCOINKERNEL_ARG_NONNULL(1);
1383
1391 const btck_TransactionOutPoint* transaction_out_point) BITCOINKERNEL_ARG_NONNULL(1);
1392
1400 const btck_TransactionOutPoint* transaction_out_point) BITCOINKERNEL_ARG_NONNULL(1);
1401
1406
1408
1413
1421 const btck_Txid* txid) BITCOINKERNEL_ARG_NONNULL(1);
1422
1431 const btck_Txid* txid1, const btck_Txid* txid2) BITCOINKERNEL_ARG_NONNULL(1, 2);
1432
1440 const btck_Txid* txid, unsigned char output[32]) BITCOINKERNEL_ARG_NONNULL(1, 2);
1441
1446
1448
1450
1455
1463 const btck_Coin* coin) BITCOINKERNEL_ARG_NONNULL(1);
1464
1472 const btck_Coin* coin) BITCOINKERNEL_ARG_NONNULL(1);
1473
1481 const btck_Coin* coin) BITCOINKERNEL_ARG_NONNULL(1);
1482
1491 const btck_Coin* coin) BITCOINKERNEL_ARG_NONNULL(1);
1492
1497
1499
1504
1509 const unsigned char block_hash[32]) BITCOINKERNEL_ARG_NONNULL(1);
1510
1519 const btck_BlockHash* hash1, const btck_BlockHash* hash2) BITCOINKERNEL_ARG_NONNULL(1, 2);
1520
1528 const btck_BlockHash* block_hash) BITCOINKERNEL_ARG_NONNULL(1);
1529
1537 const btck_BlockHash* block_hash, unsigned char output[32]) BITCOINKERNEL_ARG_NONNULL(1, 2);
1538
1543
1545
1546#ifdef __cplusplus
1547} // extern "C"
1548#endif // __cplusplus
1549
1550#endif // BITCOIN_KERNEL_BITCOINKERNEL_H
#define BITCOINKERNEL_API
Definition bitcoinkernel.h:27
BITCOINKERNEL_API int btck_block_hash_equals(const btck_BlockHash *hash1, const btck_BlockHash *hash2) 2)
Check if two block hashes are equal.
BITCOINKERNEL_API btck_BlockSpentOutputs * btck_block_spent_outputs_copy(const btck_BlockSpentOutputs *block_spent_outputs)
Copy a block's spent outputs.
BITCOINKERNEL_API 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.
uint8_t btck_LogLevel
Definition bitcoinkernel.h:406
BITCOINKERNEL_API uint32_t btck_coin_confirmation_height(const btck_Coin *coin)
Returns the height of the block that contains the coin's prevout.
BITCOINKERNEL_API const btck_Transaction * btck_block_get_transaction_at(const btck_Block *block, size_t transaction_index)
Get the transaction at the provided index. The returned transaction is not owned and depends on the l...
BITCOINKERNEL_API btck_TransactionOutPoint * btck_transaction_out_point_copy(const btck_TransactionOutPoint *transaction_out_point)
Copy a transaction out point.
struct btck_ContextOptions btck_ContextOptions
Definition bitcoinkernel.h:152
BITCOINKERNEL_API int btck_transaction_to_bytes(const btck_Transaction *transaction, btck_WriteBytes writer, void *user_data) 2)
BITCOINKERNEL_API void btck_block_hash_to_bytes(const btck_BlockHash *block_hash, unsigned char output[32]) 2)
Serializes the block hash to bytes.
BITCOINKERNEL_API void btck_logging_connection_destroy(btck_LoggingConnection *logging_connection)
struct btck_Context btck_Context
Definition bitcoinkernel.h:168
BITCOINKERNEL_API 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.
BITCOINKERNEL_API btck_ChainstateManagerOptions * btck_chainstate_manager_options_create(const btck_Context *context, const char *data_directory, size_t data_directory_len, const char *blocks_directory, size_t blocks_directory_len) 2)
Create options for the chainstate manager.
BITCOINKERNEL_API btck_BlockSpentOutputs * btck_block_spent_outputs_read(const btck_ChainstateManager *chainstate_manager, const btck_BlockTreeEntry *block_tree_entry) 2)
Reads the block spent coins data the passed in block tree entry points to from disk and returns it.
int(* btck_WriteBytes)(const void *bytes, size_t size, void *userdata)
Definition bitcoinkernel.h:321
struct btck_BlockHash btck_BlockHash
Definition bitcoinkernel.h:257
#define BITCOINKERNEL_WARN_UNUSED_RESULT
Definition bitcoinkernel.h:36
BITCOINKERNEL_API void btck_chainstate_manager_destroy(btck_ChainstateManager *chainstate_manager)
BITCOINKERNEL_API size_t btck_block_count_transactions(const btck_Block *block)
Count the number of transactions contained in a block.
BITCOINKERNEL_API btck_Coin * btck_coin_copy(const btck_Coin *coin)
Copy a coin.
BITCOINKERNEL_API void btck_transaction_destroy(btck_Transaction *transaction)
BITCOINKERNEL_API btck_Block * btck_block_copy(const btck_Block *block)
Copy a block. Blocks are reference counted, so this just increments the reference count.
BITCOINKERNEL_API btck_ScriptPubkey * btck_script_pubkey_copy(const btck_ScriptPubkey *script_pubkey)
Copy a script pubkey.
uint8_t btck_ChainType
Definition bitcoinkernel.h:452
BITCOINKERNEL_API void btck_chainstate_manager_options_set_worker_threads_num(btck_ChainstateManagerOptions *chainstate_manager_options, int worker_threads)
Set the number of available worker threads used during validation.
BITCOINKERNEL_API int btck_block_to_bytes(const btck_Block *block, btck_WriteBytes writer, void *user_data) 2)
BITCOINKERNEL_API btck_Context * btck_context_copy(const btck_Context *context)
BITCOINKERNEL_API const btck_BlockTreeEntry * btck_chain_get_tip(const btck_Chain *chain)
Get the block tree entry of the current chain tip. Once returned, there is no guarantee that it remai...
void(* btck_LogCallback)(void *user_data, const char *message, size_t message_len)
Definition bitcoinkernel.h:292
void(* btck_ValidationInterfaceBlockChecked)(void *user_data, btck_Block *block, const btck_BlockValidationState *state)
Definition bitcoinkernel.h:313
struct btck_LoggingConnection btck_LoggingConnection
Definition bitcoinkernel.h:132
uint32_t btck_BlockValidationResult
Definition bitcoinkernel.h:335
BITCOINKERNEL_API btck_ValidationMode btck_block_validation_state_get_validation_mode(const btck_BlockValidationState *block_validation_state)
uint8_t btck_ValidationMode
Definition bitcoinkernel.h:327
BITCOINKERNEL_API int btck_txid_equals(const btck_Txid *txid1, const btck_Txid *txid2) 2)
Check if two txids are equal.
BITCOINKERNEL_API void btck_logging_disable_category(btck_LogCategory category)
Disable a specific log category for the global internal logger. This changes a global setting and wil...
BITCOINKERNEL_API btck_BlockHash * btck_block_get_hash(const btck_Block *block)
BITCOINKERNEL_API const btck_Txid * btck_transaction_get_txid(const btck_Transaction *transaction)
Get the txid of a transaction.
uint8_t btck_SynchronizationState
Definition bitcoinkernel.h:276
BITCOINKERNEL_API void btck_context_options_destroy(btck_ContextOptions *context_options)
void(* btck_NotifyProgress)(void *user_data, const char *title, size_t title_len, int progress_percent, int resume_possible)
Definition bitcoinkernel.h:304
BITCOINKERNEL_API btck_TransactionSpentOutputs * btck_transaction_spent_outputs_copy(const btck_TransactionSpentOutputs *transaction_spent_outputs)
Copy a transaction's spent outputs.
struct btck_BlockTreeEntry btck_BlockTreeEntry
Definition bitcoinkernel.h:181
void(* btck_NotifyWarningUnset)(void *user_data, btck_Warning warning)
Definition bitcoinkernel.h:306
BITCOINKERNEL_API btck_LoggingConnection * btck_logging_connection_create(btck_LogCallback log_callback, void *user_data, btck_DestroyCallback user_data_destroy_callback, const btck_LoggingOptions options)
Start logging messages through the provided callback. Log messages produced before this function is f...
void(* btck_ValidationInterfaceBlockDisconnected)(void *user_data, btck_Block *block, const btck_BlockTreeEntry *entry)
Definition bitcoinkernel.h:316
void(* btck_ValidationInterfacePowValidBlock)(void *user_data, const btck_BlockTreeEntry *entry, btck_Block *block)
Definition bitcoinkernel.h:314
BITCOINKERNEL_API const btck_BlockTreeEntry * btck_chain_get_genesis(const btck_Chain *chain)
BITCOINKERNEL_API btck_TransactionInput * btck_transaction_input_copy(const btck_TransactionInput *transaction_input)
Copy a transaction input.
BITCOINKERNEL_API void btck_chainstate_manager_options_destroy(btck_ChainstateManagerOptions *chainstate_manager_options)
BITCOINKERNEL_API const btck_TransactionSpentOutputs * btck_block_spent_outputs_get_transaction_spent_outputs_at(const btck_BlockSpentOutputs *block_spent_outputs, size_t transaction_spent_outputs_index)
Returns a transaction spent outputs contained in the block spent outputs at a certain index....
BITCOINKERNEL_API const btck_Txid * btck_transaction_out_point_get_txid(const btck_TransactionOutPoint *transaction_out_point)
Get the txid from the out point.
struct btck_TransactionSpentOutputs btck_TransactionSpentOutputs
Definition bitcoinkernel.h:242
struct btck_BlockSpentOutputs btck_BlockSpentOutputs
Definition bitcoinkernel.h:233
BITCOINKERNEL_API btck_BlockValidationResult btck_block_validation_state_get_block_validation_result(const btck_BlockValidationState *block_validation_state)
struct btck_Chain btck_Chain
Definition bitcoinkernel.h:220
#define BITCOINKERNEL_ARG_NONNULL(...)
Definition bitcoinkernel.h:41
BITCOINKERNEL_API btck_BlockHash * btck_block_tree_entry_get_block_hash(const btck_BlockTreeEntry *block_tree_entry)
Return the block hash associated with a block tree entry.
void(* btck_DestroyCallback)(void *user_data)
Definition bitcoinkernel.h:297
BITCOINKERNEL_API int btck_context_interrupt(btck_Context *context)
Interrupt can be used to halt long-running validation functions like when reindexing,...
BITCOINKERNEL_API const btck_ScriptPubkey * btck_transaction_output_get_script_pubkey(const btck_TransactionOutput *transaction_output)
Get the script pubkey of the output. The returned script pubkey is not owned and depends on the lifet...
uint32_t btck_ScriptVerificationFlags
Definition bitcoinkernel.h:435
BITCOINKERNEL_API void btck_block_hash_destroy(btck_BlockHash *block_hash)
BITCOINKERNEL_API const btck_BlockTreeEntry * btck_chain_get_by_height(const btck_Chain *chain, int block_height)
Retrieve a block tree entry by its height in the currently active chain. Once retrieved there is no g...
BITCOINKERNEL_API int btck_chain_get_height(const btck_Chain *chain)
Return the height of the tip of the chain.
BITCOINKERNEL_API btck_BlockHash * btck_block_hash_copy(const btck_BlockHash *block_hash)
Copy a block hash.
BITCOINKERNEL_API int64_t btck_transaction_output_get_amount(const btck_TransactionOutput *transaction_output)
Get the amount in the output.
BITCOINKERNEL_API const btck_TransactionOutput * btck_transaction_get_output_at(const btck_Transaction *transaction, size_t output_index)
Get the transaction outputs at the provided index. The returned transaction output is not owned and d...
struct btck_ScriptPubkey btck_ScriptPubkey
Definition bitcoinkernel.h:114
BITCOINKERNEL_API 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.
struct btck_Coin btck_Coin
Definition bitcoinkernel.h:250
BITCOINKERNEL_API const btck_TransactionInput * btck_transaction_get_input_at(const btck_Transaction *transaction, size_t input_index)
Get the transaction input at the provided index. The returned transaction input is not owned and depe...
BITCOINKERNEL_API int btck_chain_contains(const btck_Chain *chain, const btck_BlockTreeEntry *block_tree_entry) 2)
Return true if the passed in chain contains the block tree entry.
BITCOINKERNEL_API btck_Block * btck_block_create(const void *raw_block, size_t raw_block_len)
Parse a serialized raw block into a new block object.
BITCOINKERNEL_API int btck_script_pubkey_verify(const btck_ScriptPubkey *script_pubkey, int64_t amount, const btck_Transaction *tx_to, const btck_TransactionOutput **spent_outputs, size_t spent_outputs_len, unsigned int input_index, unsigned int flags, btck_ScriptVerifyStatus *status) 3)
Verify if the input at input_index of tx_to spends the script pubkey under the constraints specified ...
BITCOINKERNEL_API const btck_TransactionOutput * btck_coin_get_output(const btck_Coin *coin)
Return the transaction output of a coin. The returned pointer is unowned and only valid for the lifet...
struct btck_TransactionInput btck_TransactionInput
Definition bitcoinkernel.h:264
BITCOINKERNEL_API btck_Context * btck_context_create(const btck_ContextOptions *context_options)
Create a new kernel context. If the options have not been previously set, their corresponding fields ...
struct btck_TransactionOutPoint btck_TransactionOutPoint
Definition bitcoinkernel.h:271
BITCOINKERNEL_API btck_Transaction * btck_transaction_create(const void *raw_transaction, size_t raw_transaction_len)
Create a new transaction from the serialized data.
BITCOINKERNEL_API void btck_script_pubkey_destroy(btck_ScriptPubkey *script_pubkey)
BITCOINKERNEL_API void btck_transaction_output_destroy(btck_TransactionOutput *transaction_output)
BITCOINKERNEL_API btck_Transaction * btck_transaction_copy(const btck_Transaction *transaction)
Copy a transaction. Transactions are reference counted, so this just increments the reference count.
BITCOINKERNEL_API btck_TransactionOutput * btck_transaction_output_copy(const btck_TransactionOutput *transaction_output)
Copy a transaction output.
BITCOINKERNEL_API btck_ScriptPubkey * btck_script_pubkey_create(const void *script_pubkey, size_t script_pubkey_len)
Create a script pubkey from serialized data.
BITCOINKERNEL_API void btck_txid_destroy(btck_Txid *txid)
BITCOINKERNEL_API void btck_chainstate_manager_options_set_chainstate_db_in_memory(btck_ChainstateManagerOptions *chainstate_manager_options, int chainstate_db_in_memory)
Sets chainstate db in memory in the options.
uint8_t btck_ScriptVerifyStatus
Definition bitcoinkernel.h:427
BITCOINKERNEL_API int btck_script_pubkey_to_bytes(const btck_ScriptPubkey *script_pubkey, btck_WriteBytes writer, void *user_data) 2)
BITCOINKERNEL_API 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. The returned pointer is...
BITCOINKERNEL_API int32_t btck_block_tree_entry_get_height(const btck_BlockTreeEntry *block_tree_entry)
Return the height of a certain block tree entry.
BITCOINKERNEL_API btck_Txid * btck_txid_copy(const btck_Txid *txid)
Copy a txid.
BITCOINKERNEL_API void btck_transaction_out_point_destroy(btck_TransactionOutPoint *transaction_out_point)
BITCOINKERNEL_API btck_Block * btck_block_read(const btck_ChainstateManager *chainstate_manager, const btck_BlockTreeEntry *block_tree_entry) 2)
Reads the block the passed in block tree entry points to from disk and returns it.
BITCOINKERNEL_API btck_BlockHash * btck_block_hash_create(const unsigned char block_hash[32])
Create a block hash from its raw data.
void(* btck_NotifyBlockTip)(void *user_data, btck_SynchronizationState state, const btck_BlockTreeEntry *entry, double verification_progress)
Definition bitcoinkernel.h:302
uint8_t btck_LogCategory
Definition bitcoinkernel.h:390
BITCOINKERNEL_API void btck_context_options_set_validation_interface(btck_ContextOptions *context_options, btck_ValidationInterfaceCallbacks validation_interface_callbacks)
Set the validation interface callbacks for the context options. The context created with the options ...
void(* btck_ValidationInterfaceBlockConnected)(void *user_data, btck_Block *block, const btck_BlockTreeEntry *entry)
Definition bitcoinkernel.h:315
BITCOINKERNEL_API void btck_transaction_spent_outputs_destroy(btck_TransactionSpentOutputs *transaction_spent_outputs)
BITCOINKERNEL_API btck_ChainParameters * btck_chain_parameters_copy(const btck_ChainParameters *chain_parameters)
struct btck_ChainstateManager btck_ChainstateManager
Definition bitcoinkernel.h:201
BITCOINKERNEL_API void btck_chain_parameters_destroy(btck_ChainParameters *chain_parameters)
struct btck_TransactionOutput btck_TransactionOutput
Definition bitcoinkernel.h:119
BITCOINKERNEL_API uint32_t btck_transaction_out_point_get_index(const btck_TransactionOutPoint *transaction_out_point)
Get the output position from the out point.
BITCOINKERNEL_API int btck_chainstate_manager_process_block(btck_ChainstateManager *chainstate_manager, const btck_Block *block, int *new_block) 2
Process and validate the passed in block with the chainstate manager. Processing first does checks on...
BITCOINKERNEL_API btck_ChainstateManager * btck_chainstate_manager_create(const btck_ChainstateManagerOptions *chainstate_manager_options)
Create a chainstate manager. This is the main object for many validation tasks as well as for retriev...
BITCOINKERNEL_API void btck_logging_enable_category(btck_LogCategory category)
Enable a specific log category for the global internal logger. This changes a global setting and will...
struct btck_BlockValidationState btck_BlockValidationState
Definition bitcoinkernel.h:214
BITCOINKERNEL_API const btck_TransactionOutPoint * btck_transaction_input_get_out_point(const btck_TransactionInput *transaction_input)
Get the transaction out point. The returned transaction out point is not owned and depends on the lif...
BITCOINKERNEL_API const btck_BlockTreeEntry * btck_block_tree_entry_get_previous(const btck_BlockTreeEntry *block_tree_entry)
Returns the previous block tree entry in the chain, or null if the current block tree entry is the ge...
BITCOINKERNEL_API void btck_block_destroy(btck_Block *block)
uint8_t btck_Warning
Definition bitcoinkernel.h:282
struct btck_ChainstateManagerOptions btck_ChainstateManagerOptions
Definition bitcoinkernel.h:190
BITCOINKERNEL_API void btck_coin_destroy(btck_Coin *coin)
void(* btck_NotifyHeaderTip)(void *user_data, btck_SynchronizationState state, int64_t height, int64_t timestamp, int presync)
Definition bitcoinkernel.h:303
BITCOINKERNEL_API void btck_context_options_set_chainparams(btck_ContextOptions *context_options, const btck_ChainParameters *chain_parameters) 2)
Sets the chain params for the context options. The context created with the options will be configure...
BITCOINKERNEL_API void btck_block_spent_outputs_destroy(btck_BlockSpentOutputs *block_spent_outputs)
BITCOINKERNEL_API int BITCOINKERNEL_API const btck_Chain * btck_chainstate_manager_get_active_chain(const btck_ChainstateManager *chainstate_manager)
Returns the best known currently active chain. Its lifetime is dependent on the chainstate manager an...
BITCOINKERNEL_API int btck_chainstate_manager_options_set_wipe_dbs(btck_ChainstateManagerOptions *chainstate_manager_options, int wipe_block_tree_db, int wipe_chainstate_db)
Sets wipe db in the options. In combination with calling btck_chainstate_manager_import_blocks this t...
struct btck_ChainParameters btck_ChainParameters
Definition bitcoinkernel.h:141
struct btck_Block btck_Block
Definition bitcoinkernel.h:206
BITCOINKERNEL_API void btck_logging_set_level_category(btck_LogCategory category, btck_LogLevel level)
Set the log level of the global internal logger. This does not enable the selected categories....
BITCOINKERNEL_API size_t btck_transaction_count_inputs(const btck_Transaction *transaction)
Get the number of inputs of a transaction.
BITCOINKERNEL_API int btck_coin_is_coinbase(const btck_Coin *coin)
Returns whether the containing transaction was a coinbase.
BITCOINKERNEL_API const btck_BlockTreeEntry * btck_chainstate_manager_get_block_tree_entry_by_hash(const btck_ChainstateManager *chainstate_manager, const btck_BlockHash *block_hash) 2)
Retrieve a block tree entry by its block hash.
BITCOINKERNEL_API void btck_logging_disable()
This disables the global internal logger. No log messages will be buffered internally anymore once th...
void(* btck_NotifyWarningSet)(void *user_data, btck_Warning warning, const char *message, size_t message_len)
Definition bitcoinkernel.h:305
BITCOINKERNEL_API void btck_transaction_input_destroy(btck_TransactionInput *transaction_input)
BITCOINKERNEL_API void btck_chainstate_manager_options_set_block_tree_db_in_memory(btck_ChainstateManagerOptions *chainstate_manager_options, int block_tree_db_in_memory)
Sets block tree db in memory in the options.
BITCOINKERNEL_API void btck_context_options_set_notifications(btck_ContextOptions *context_options, btck_NotificationInterfaceCallbacks notifications)
Set the kernel notifications for the context options. The context created with the options will be co...
BITCOINKERNEL_API void btck_context_destroy(btck_Context *context)
BITCOINKERNEL_API btck_ContextOptions * btck_context_options_create()
void(* btck_NotifyFatalError)(void *user_data, const char *message, size_t message_len)
Definition bitcoinkernel.h:308
void(* btck_NotifyFlushError)(void *user_data, const char *message, size_t message_len)
Definition bitcoinkernel.h:307
BITCOINKERNEL_API int btck_chainstate_manager_import_blocks(btck_ChainstateManager *chainstate_manager, const char **block_file_paths, size_t *block_file_paths_lens, size_t block_file_paths_len) 2)
Triggers the start of a reindex if the option was previously set for the chainstate and block manager...
struct btck_Txid btck_Txid
Definition bitcoinkernel.h:273
BITCOINKERNEL_API size_t btck_transaction_count_outputs(const btck_Transaction *transaction)
Get the number of outputs of a transaction.
BITCOINKERNEL_API 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.
BITCOINKERNEL_API void btck_txid_to_bytes(const btck_Txid *txid, unsigned char output[32]) 2)
Serializes the txid to bytes.
struct btck_Transaction btck_Transaction
Definition bitcoinkernel.h:109
Definition bitcoinkernel.h:416
int always_print_category_levels
Prepend the log category and level to log messages.
Definition bitcoinkernel.h:421
int log_time_micros
Log timestamps in microsecond precision.
Definition bitcoinkernel.h:418
int log_threadnames
Prepend the name of the thread to log messages.
Definition bitcoinkernel.h:419
int log_sourcelocations
Prepend the source location to log messages.
Definition bitcoinkernel.h:420
int log_timestamps
Prepend a timestamp to log messages.
Definition bitcoinkernel.h:417
Definition bitcoinkernel.h:373
btck_NotifyWarningUnset warning_unset
A previous condition leading to the issuance of a warning is no longer given.
Definition bitcoinkernel.h:382
btck_NotifyBlockTip block_tip
The chain's tip was updated to the provided block entry.
Definition bitcoinkernel.h:378
btck_NotifyWarningSet warning_set
A warning issued by the kernel library during validation.
Definition bitcoinkernel.h:381
btck_NotifyFlushError flush_error
An error encountered when flushing data to disk.
Definition bitcoinkernel.h:383
btck_NotifyProgress progress
Reports on current block synchronization progress.
Definition bitcoinkernel.h:380
btck_NotifyFatalError fatal_error
A un-recoverable system error encountered by the library.
Definition bitcoinkernel.h:384
btck_DestroyCallback user_data_destroy
Frees the provided user data structure.
Definition bitcoinkernel.h:377
void * user_data
Definition bitcoinkernel.h:374
btck_NotifyHeaderTip header_tip
A new best block header was added.
Definition bitcoinkernel.h:379
Definition bitcoinkernel.h:352
btck_DestroyCallback user_data_destroy
Frees the provided user data structure.
Definition bitcoinkernel.h:356
btck_ValidationInterfaceBlockConnected block_connected
Called when a block is valid and has now been connected to the best chain.
Definition bitcoinkernel.h:361
btck_ValidationInterfaceBlockChecked block_checked
Definition bitcoinkernel.h:357
btck_ValidationInterfaceBlockDisconnected block_disconnected
Called during a re-org when a block has been removed from the best chain.
Definition bitcoinkernel.h:362
void * user_data
Definition bitcoinkernel.h:353
btck_ValidationInterfacePowValidBlock pow_valid_block
Definition bitcoinkernel.h:359