Skip to content

Commit 3f3e1e7

Browse files
Squashed 'libbitcoinkernel-sys/bitcoin/' changes from a755e00a1354..edf99b88e644
edf99b88e644 kernel: Fix bitcoin-chainstate for windows 8fbe027a8a66 kernel: Add Purpose section to header documentation 75f44d950566 kernel: Allowing reducing exports d3f5df4a38ce kernel: Add pure kernel bitcoin-chainstate e5009f3707ee Kernel: Add functions for working with outpoints c337b7e609d5 kernel: Add block hash type and block tree utility functions to C header 7d3f0ced45f0 kernel: Add function to read block undo data from disk to C header 83b7abc0537c kernel: Add functions to read block from disk to C header 4c765dddcbec kernel: Add function for copying block data to C header ae6570017493 kernel: Add functions for the block validation state to C header c2bb6b06af78 kernel: Add validation interface to C header 3efd276cedd9 kernel: Add interrupt function to C header f0ffab556086 kernel: Add import blocks function to C header bdcb7b8b05ab kernel: Add chainstate load options for in-memory dbs in C header 6dab7199fe78 kernel: Add options for reindexing in C header bee1c1d7363d kernel: Add block validation to C header 7e2b237e67d1 kernel: Add chainstate loading when instantiating a ChainstateManager e4f1e00203f2 kernel: Add chainstate manager option for setting worker threads a7a3138fa2b4 kernel: Add chainstate manager object to C header 564e0cf1bf84 kernel: Add notifications context option to C header 2ce38f954b86 kernel: Add chain params context option to C header 58eae5695813 kernel: Add kernel library context object c5f8bd0e0ea2 kernel: Add logging to kernel library C header bff9b7f388c7 kernel: Introduce initial kernel C header API REVERT: a755e00a1354 kernel: Fix bitcoin-chainstate for windows REVERT: 670eb49289e3 kernel: Add Purpose section to header documentation REVERT: 06ee1c7336be kernel: Allowing reducing exports REVERT: 57b20b5a4d9c kernel: Add pure kernel bitcoin-chainstate REVERT: 7cf58f8c4cba Kernel: Add functions for working with outpoints REVERT: 64a4564ccb62 kernel: Add block hash type and block tree utility functions to C header REVERT: 43855d656eb1 kernel: Add function to read block undo data from disk to C header REVERT: e080e80da7db kernel: Add functions to read block from disk to C header REVERT: 51634ca37ab6 kernel: Add function for copying block data to C header REVERT: 5ed5a9724fdd kernel: Add functions for the block validation state to C header REVERT: 38e5c526a861 kernel: Add validation interface to C header REVERT: 38a990dd482e kernel: Add interrupt function to C header REVERT: fee8f6ff38b1 kernel: Add import blocks function to C header REVERT: c29a6b87ccdf kernel: Add chainstate load options for in-memory dbs in C header REVERT: e788b3ba0658 kernel: Add options for reindexing in C header REVERT: 2707fc515c52 kernel: Add block validation to C header REVERT: 51a24c4004e8 kernel: Add chainstate loading when instantiating a ChainstateManager REVERT: ea01a8caf354 kernel: Add chainstate manager option for setting worker threads REVERT: add5904e0ac8 kernel: Add chainstate manager object to C header REVERT: 37a3395d2718 kernel: Add notifications context option to C header REVERT: d838a934be0f kernel: Add chain params context option to C header REVERT: dc58ae9fc04e kernel: Add kernel library context object REVERT: 774499759624 kernel: Add logging to kernel library C header REVERT: dc504f57b3b5 kernel: Introduce initial kernel C header API git-subtree-dir: libbitcoinkernel-sys/bitcoin git-subtree-split: edf99b88e644c7d2a2db434c8db298c9c5303cf9
1 parent 1601515 commit 3f3e1e7

File tree

8 files changed

+265
-484
lines changed

8 files changed

+265
-484
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ jobs:
202202
job-type: [standard, fuzz]
203203
include:
204204
- job-type: standard
205-
generate-options: '-DBUILD_GUI=ON -DWITH_ZMQ=ON -DBUILD_BENCH=ON -DBUILD_KERNEL_LIB=ON -DBUILD_UTIL_CHAINSTATE=ON -DBUILD_KERNEL_TEST=OFF -DWERROR=ON'
205+
generate-options: '-DBUILD_GUI=ON -DWITH_ZMQ=ON -DBUILD_BENCH=ON -DBUILD_KERNEL_LIB=ON -DBUILD_UTIL_CHAINSTATE=ON -DWERROR=ON'
206206
job-name: 'Windows native, VS 2022'
207207
- job-type: fuzz
208208
generate-options: '-DVCPKG_MANIFEST_NO_DEFAULT_FEATURES=ON -DVCPKG_MANIFEST_FEATURES="wallet" -DBUILD_GUI=OFF -DBUILD_FOR_FUZZING=ON -DWERROR=ON'

ci/test/00_setup_env_mac_cross.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ export XCODE_BUILD_ID=15A240d
1717
export RUN_UNIT_TESTS=false
1818
export RUN_FUNCTIONAL_TESTS=false
1919
export GOAL="deploy"
20-
export BITCOIN_CONFIG="-DBUILD_GUI=ON -DREDUCE_EXPORTS=ON"
20+
export BITCOIN_CONFIG="-DBUILD_GUI=ON -DBUILD_KERNEL_LIB=ON -DREDUCE_EXPORTS=ON"

ci/test/00_setup_env_mac_native.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export CONTAINER_NAME="ci_mac_native" # macos does not use a container, but the
1212
export PIP_PACKAGES="--break-system-packages zmq"
1313
export GOAL="install deploy"
1414
export CMAKE_GENERATOR="Ninja"
15-
export BITCOIN_CONFIG="-DBUILD_GUI=ON -DWITH_ZMQ=ON -DBUILD_KERNEL_LIB=ON -DBUILD_KERNEL_TEST=ON -DREDUCE_EXPORTS=ON -DCMAKE_EXE_LINKER_FLAGS='-Wl,-stack_size -Wl,0x80000'"
15+
export BITCOIN_CONFIG="-DBUILD_GUI=ON -DWITH_ZMQ=ON -DBUILD_KERNEL_LIB=ON -DBUILD_UTIL_CHAINSTATE=ON -DBUILD_KERNEL_TEST=ON -DREDUCE_EXPORTS=ON -DCMAKE_EXE_LINKER_FLAGS='-Wl,-stack_size -Wl,0x80000'"
1616
export CI_OS_NAME="macos"
1717
export NO_DEPENDS=1
1818
export OSX_SDK=""

src/kernel/bitcoinkernel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,8 @@ int btck_script_pubkey_verify(const btck_ScriptPubkey* script_pubkey,
629629
return 0;
630630
}
631631

632+
if (status) *status = btck_ScriptVerifyStatus_OK;
633+
632634
const CTransaction& tx{*btck_Transaction::get(tx_to)};
633635
std::vector<CTxOut> spent_outputs;
634636
if (spent_outputs_ != nullptr) {

src/kernel/bitcoinkernel.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,9 @@ typedef struct {
425425
* A collection of status codes that may be issued by the script verify function.
426426
*/
427427
typedef uint8_t btck_ScriptVerifyStatus;
428-
#define btck_ScriptVerifyStatus_SCRIPT_VERIFY_OK ((btck_ScriptVerifyStatus)(0))
429-
#define btck_ScriptVerifyStatus_ERROR_INVALID_FLAGS_COMBINATION ((btck_ScriptVerifyStatus)(2)) //!< The flags were combined in an invalid way.
430-
#define btck_ScriptVerifyStatus_ERROR_SPENT_OUTPUTS_REQUIRED ((btck_ScriptVerifyStatus)(3)) //!< The taproot flag was set, so valid spent_outputs have to be provided.
428+
#define btck_ScriptVerifyStatus_OK ((btck_ScriptVerifyStatus)(0))
429+
#define btck_ScriptVerifyStatus_ERROR_INVALID_FLAGS_COMBINATION ((btck_ScriptVerifyStatus)(1)) //!< The flags were combined in an invalid way.
430+
#define btck_ScriptVerifyStatus_ERROR_SPENT_OUTPUTS_REQUIRED ((btck_ScriptVerifyStatus)(2)) //!< The taproot flag was set, so valid spent_outputs have to be provided.
431431

432432
/**
433433
* Script verification flags that may be composed with each other.
@@ -594,8 +594,7 @@ BITCOINKERNEL_API btck_ScriptPubkey* BITCOINKERNEL_WARN_UNUSED_RESULT btck_scrip
594594
* @param[in] spent_outputs_len Length of the spent_outputs array.
595595
* @param[in] input_index Index of the input in tx_to spending the script_pubkey.
596596
* @param[in] flags Bitfield of btck_ScriptFlags controlling validation constraints.
597-
* @param[out] status Nullable, will be set to an error code if the operation fails.
598-
* Should be set to btck_SCRIPT_VERIFY_OK.
597+
* @param[out] status Nullable, will be set to an error code if the operation fails, or OK otherwise.
599598
* @return 1 if the script is valid, 0 otherwise.
600599
*/
601600
BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_script_pubkey_verify(
@@ -670,7 +669,7 @@ BITCOINKERNEL_API int64_t BITCOINKERNEL_WARN_UNUSED_RESULT btck_transaction_outp
670669
* @param[in] transaction_output Non-null.
671670
* @return The copied transaction output.
672671
*/
673-
BITCOINKERNEL_API btck_TransactionOutput* btck_transaction_output_copy(
672+
BITCOINKERNEL_API btck_TransactionOutput* BITCOINKERNEL_WARN_UNUSED_RESULT btck_transaction_output_copy(
674673
const btck_TransactionOutput* transaction_output) BITCOINKERNEL_ARG_NONNULL(1);
675674

676675
/**
@@ -954,7 +953,7 @@ BITCOINKERNEL_API void btck_chainstate_manager_options_set_worker_threads_num(
954953
* @param[in] wipe_chainstate_db Set wipe chainstate db.
955954
* @return 0 if the set was successful, non-zero if the set failed.
956955
*/
957-
BITCOINKERNEL_API int btck_chainstate_manager_options_set_wipe_dbs(
956+
BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_chainstate_manager_options_set_wipe_dbs(
958957
btck_ChainstateManagerOptions* chainstate_manager_options,
959958
int wipe_block_tree_db,
960959
int wipe_chainstate_db) BITCOINKERNEL_ARG_NONNULL(1);
@@ -1013,7 +1012,7 @@ BITCOINKERNEL_API btck_ChainstateManager* BITCOINKERNEL_WARN_UNUSED_RESULT btck_
10131012
* @param[in] block_file_paths_data_len Length of the block_file_paths_data and block_file_paths_len arrays.
10141013
* @return 0 if the import blocks call was completed successfully, non-zero otherwise.
10151014
*/
1016-
BITCOINKERNEL_API int btck_chainstate_manager_import_blocks(
1015+
BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_chainstate_manager_import_blocks(
10171016
btck_ChainstateManager* chainstate_manager,
10181017
const char** block_file_paths_data, size_t* block_file_paths_lens,
10191018
size_t block_file_paths_data_len) BITCOINKERNEL_ARG_NONNULL(1, 2);
@@ -1235,7 +1234,7 @@ BITCOINKERNEL_API const btck_BlockTreeEntry* BITCOINKERNEL_WARN_UNUSED_RESULT bt
12351234
* @return 1 if the block_tree_entry is in the chain, 0 otherwise.
12361235
*
12371236
*/
1238-
BITCOINKERNEL_API int btck_chain_contains(
1237+
BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_chain_contains(
12391238
const btck_Chain* chain,
12401239
const btck_BlockTreeEntry* block_tree_entry) BITCOINKERNEL_ARG_NONNULL(1, 2);
12411240

@@ -1393,7 +1392,7 @@ BITCOINKERNEL_API btck_TransactionOutPoint* BITCOINKERNEL_WARN_UNUSED_RESULT btc
13931392
* @param[in] transaction_out_point Non-null.
13941393
* @return The output index.
13951394
*/
1396-
BITCOINKERNEL_API uint32_t btck_transaction_out_point_get_index(
1395+
BITCOINKERNEL_API uint32_t BITCOINKERNEL_WARN_UNUSED_RESULT btck_transaction_out_point_get_index(
13971396
const btck_TransactionOutPoint* transaction_out_point) BITCOINKERNEL_ARG_NONNULL(1);
13981397

13991398
/**
@@ -1403,7 +1402,7 @@ BITCOINKERNEL_API uint32_t btck_transaction_out_point_get_index(
14031402
* @param[in] transaction_out_point Non-null.
14041403
* @return The txid.
14051404
*/
1406-
BITCOINKERNEL_API const btck_Txid* btck_transaction_out_point_get_txid(
1405+
BITCOINKERNEL_API const btck_Txid* BITCOINKERNEL_WARN_UNUSED_RESULT btck_transaction_out_point_get_txid(
14071406
const btck_TransactionOutPoint* transaction_out_point) BITCOINKERNEL_ARG_NONNULL(1);
14081407

14091408
/**
@@ -1434,7 +1433,7 @@ BITCOINKERNEL_API btck_Txid* BITCOINKERNEL_WARN_UNUSED_RESULT btck_txid_copy(
14341433
* @param[in] txid2 Non-null.
14351434
* @return 0 if the txid is not equal.
14361435
*/
1437-
BITCOINKERNEL_API int btck_txid_equals(
1436+
BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_txid_equals(
14381437
const btck_Txid* txid1, const btck_Txid* txid2) BITCOINKERNEL_ARG_NONNULL(1, 2);
14391438

14401439
/**
@@ -1523,7 +1522,7 @@ BITCOINKERNEL_API btck_BlockHash* BITCOINKERNEL_WARN_UNUSED_RESULT btck_block_ha
15231522
* @param[in] hash2 Non-null.
15241523
* @return 0 if the block hashes are not equal.
15251524
*/
1526-
BITCOINKERNEL_API int btck_block_hash_equals(
1525+
BITCOINKERNEL_API int BITCOINKERNEL_WARN_UNUSED_RESULT btck_block_hash_equals(
15271526
const btck_BlockHash* hash1, const btck_BlockHash* hash2) BITCOINKERNEL_ARG_NONNULL(1, 2);
15281527

15291528
/**

src/kernel/bitcoinkernel_wrapper.h

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
namespace btck {
2323

24-
class Transaction;
25-
class TransactionOutput;
26-
2724
enum class LogCategory : btck_LogCategory {
2825
ALL = btck_LogCategory_ALL,
2926
BENCH = btck_LogCategory_BENCH,
@@ -82,7 +79,7 @@ enum class BlockValidationResult : btck_BlockValidationResult {
8279
};
8380

8481
enum class ScriptVerifyStatus : btck_ScriptVerifyStatus {
85-
OK = btck_ScriptVerifyStatus_SCRIPT_VERIFY_OK,
82+
OK = btck_ScriptVerifyStatus_OK,
8683
ERROR_INVALID_FLAGS_COMBINATION = btck_ScriptVerifyStatus_ERROR_INVALID_FLAGS_COMBINATION,
8784
ERROR_SPENT_OUTPUTS_REQUIRED = btck_ScriptVerifyStatus_ERROR_SPENT_OUTPUTS_REQUIRED,
8885
};
@@ -259,6 +256,12 @@ class Range
259256
value_type back() const { return (*this)[size() - 1]; }
260257
};
261258

259+
#define MAKE_RANGE_METHOD(method_name, ContainerType, SizeFunc, GetFunc, container_expr) \
260+
auto method_name() const & { \
261+
return Range<ContainerType, SizeFunc, GetFunc>{container_expr}; \
262+
} \
263+
auto method_name() const && = delete;
264+
262265
template <typename T>
263266
std::vector<std::byte> write_bytes(const T* object, int (*to_bytes)(const T*, btck_WriteBytes, void*))
264267
{
@@ -596,15 +599,9 @@ class TransactionApi
596599
return TxidView{btck_transaction_get_txid(impl())};
597600
}
598601

599-
auto Outputs() const
600-
{
601-
return Range<Derived, &TransactionApi<Derived>::CountOutputs, &TransactionApi<Derived>::GetOutput>{*static_cast<const Derived*>(this)};
602-
}
602+
MAKE_RANGE_METHOD(Outputs, Derived, &TransactionApi<Derived>::CountOutputs, &TransactionApi<Derived>::GetOutput, *static_cast<const Derived*>(this))
603603

604-
auto Inputs() const
605-
{
606-
return Range<Derived, &TransactionApi<Derived>::CountInputs, &TransactionApi<Derived>::GetInput>{*static_cast<const Derived*>(this)};
607-
}
604+
MAKE_RANGE_METHOD(Inputs, Derived, &TransactionApi<Derived>::CountInputs, &TransactionApi<Derived>::GetInput, *static_cast<const Derived*>(this))
608605

609606
std::vector<std::byte> ToBytes() const
610607
{
@@ -724,10 +721,7 @@ class Block : public Handle<btck_Block, btck_block_copy, btck_block_destroy>
724721
return TransactionView{btck_block_get_transaction_at(get(), index)};
725722
}
726723

727-
auto Transactions() const
728-
{
729-
return Range<Block, &Block::CountTransactions, &Block::GetTransaction>{*this};
730-
}
724+
MAKE_RANGE_METHOD(Transactions, Block, &Block::CountTransactions, &Block::GetTransaction, *this)
731725

732726
BlockHash GetHash() const
733727
{
@@ -994,6 +988,11 @@ class ChainView : public View<btck_Chain>
994988
return btck_chain_get_height(get());
995989
}
996990

991+
int CountEntries() const
992+
{
993+
return btck_chain_get_height(get()) + 1;
994+
}
995+
997996
BlockTreeEntry Genesis() const
998997
{
999998
return btck_chain_get_genesis(get());
@@ -1011,10 +1010,7 @@ class ChainView : public View<btck_Chain>
10111010
return btck_chain_contains(get(), entry.get());
10121011
}
10131012

1014-
auto Entries() const
1015-
{
1016-
return Range<ChainView, &ChainView::Height, &ChainView::GetByHeight>{*this};
1017-
}
1013+
MAKE_RANGE_METHOD(Entries, ChainView, &ChainView::CountEntries, &ChainView::GetByHeight, *this)
10181014
};
10191015

10201016
template <typename Derived>
@@ -1077,10 +1073,7 @@ class TransactionSpentOutputsApi
10771073
return CoinView{btck_transaction_spent_outputs_get_coin_at(impl(), index)};
10781074
}
10791075

1080-
auto Coins() const
1081-
{
1082-
return Range<Derived, &TransactionSpentOutputsApi<Derived>::Count, &TransactionSpentOutputsApi<Derived>::GetCoin>{*static_cast<const Derived*>(this)};
1083-
}
1076+
MAKE_RANGE_METHOD(Coins, Derived, &TransactionSpentOutputsApi<Derived>::Count, &TransactionSpentOutputsApi<Derived>::GetCoin, *static_cast<const Derived*>(this))
10841077
};
10851078

10861079
class TransactionSpentOutputsView : public View<btck_TransactionSpentOutputs>, public TransactionSpentOutputsApi<TransactionSpentOutputsView>
@@ -1116,10 +1109,7 @@ class BlockSpentOutputs : public Handle<btck_BlockSpentOutputs, btck_block_spent
11161109
return TransactionSpentOutputsView{btck_block_spent_outputs_get_transaction_spent_outputs_at(get(), tx_undo_index)};
11171110
}
11181111

1119-
auto TxsSpentOutputs() const
1120-
{
1121-
return Range<BlockSpentOutputs, &BlockSpentOutputs::Count, &BlockSpentOutputs::GetTxSpentOutputs>{*this};
1122-
}
1112+
MAKE_RANGE_METHOD(TxsSpentOutputs, BlockSpentOutputs, &BlockSpentOutputs::Count, &BlockSpentOutputs::GetTxSpentOutputs, *this)
11231113
};
11241114

11251115
class ChainMan : UniqueHandle<btck_ChainstateManager, btck_chainstate_manager_destroy>

0 commit comments

Comments
 (0)