diff --git a/src/kernel/bitcoinkernel.cpp b/src/kernel/bitcoinkernel.cpp index dc03be71461..4ba60c1b56c 100644 --- a/src/kernel/bitcoinkernel.cpp +++ b/src/kernel/bitcoinkernel.cpp @@ -1352,13 +1352,13 @@ const btck_Chain* btck_chainstate_manager_get_active_chain(const btck_Chainstate return btck_Chain::ref(&WITH_LOCK(btck_ChainstateManager::get(chainman).m_chainman->GetMutex(), return btck_ChainstateManager::get(chainman).m_chainman->ActiveChain())); } -int btck_chain_get_height(const btck_Chain* chain) +int32_t btck_chain_get_height(const btck_Chain* chain) { LOCK(::cs_main); return btck_Chain::get(chain).Height(); } -const btck_BlockTreeEntry* btck_chain_get_by_height(const btck_Chain* chain, int height) +const btck_BlockTreeEntry* btck_chain_get_by_height(const btck_Chain* chain, int32_t height) { LOCK(::cs_main); return btck_BlockTreeEntry::ref(btck_Chain::get(chain)[height]); diff --git a/src/kernel/bitcoinkernel.h b/src/kernel/bitcoinkernel.h index d3028b491d2..cd837573dff 100644 --- a/src/kernel/bitcoinkernel.h +++ b/src/kernel/bitcoinkernel.h @@ -112,6 +112,12 @@ extern "C" { * object. * * Array lengths follow the pointer argument they describe. + * + * @section types Type conventions + * + * Fixed-width integer types (e.g. int32_t, uint32_t) are used for data values + * such as heights. Plain int and unsigned int are used for boolean-like values + * and flags. */ /** @@ -1423,7 +1429,7 @@ BITCOINKERNEL_API int32_t BITCOINKERNEL_WARN_UNUSED_RESULT btck_chain_get_height */ BITCOINKERNEL_API const btck_BlockTreeEntry* BITCOINKERNEL_WARN_UNUSED_RESULT btck_chain_get_by_height( const btck_Chain* chain, - int block_height) BITCOINKERNEL_ARG_NONNULL(1); + int32_t block_height) BITCOINKERNEL_ARG_NONNULL(1); /** * @brief Return true if the passed in chain contains the block tree entry. diff --git a/src/kernel/bitcoinkernel_wrapper.h b/src/kernel/bitcoinkernel_wrapper.h index cb7af8b35dd..38dd709f948 100644 --- a/src/kernel/bitcoinkernel_wrapper.h +++ b/src/kernel/bitcoinkernel_wrapper.h @@ -1122,12 +1122,12 @@ public: return btck_chain_get_height(get()); } - int CountEntries() const + int32_t CountEntries() const { return btck_chain_get_height(get()) + 1; } - BlockTreeEntry GetByHeight(int height) const + BlockTreeEntry GetByHeight(int32_t height) const { auto index{btck_chain_get_by_height(get(), height)}; if (!index) throw std::runtime_error("No entry in the chain at the provided height");