refactor: Small style fixups in src/kernel/bitcoinkernel.cpp
What changed, and why it matters
This is a pure code cleanup (refactoring) change in Bitcoin Core's libbitcoinkernel. It replaces a few verbose type names and function calls with shorter equivalents, removes an unused header include, and rewords a documentation comment. There is no change to program behavior, no bug fix, and no security relevance.
No security action needed. Treat as normal code-quality review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit makes four style-only changes in src/kernel/bitcoinkernel.cpp/.h: (1) uses the TranslateFn type alias instead of spelling out std::function
Changed components
src/kernel/bitcoinkernel.cppsrc/kernel/bitcoinkernel.hInspect captured patch +7 / −8
diff --git a/src/kernel/bitcoinkernel.cpp b/src/kernel/bitcoinkernel.cpp
index c8189b62..ea646cd5 100644
--- a/src/kernel/bitcoinkernel.cpp
+++ b/src/kernel/bitcoinkernel.cpp
@@ -41,7 +41,6 @@
#include <cstring>
#include <exception>
#include <functional>
-#include <iterator>
#include <list>
#include <memory>
#include <span>
@@ -56,7 +55,7 @@ using util::ImmediateTaskRunner;
// Define G_TRANSLATION_FUN symbol in libbitcoinkernel library so users of the
// library aren't required to export this symbol
-extern const std::function<std::string(const char*)> G_TRANSLATION_FUN{nullptr};
+extern const TranslateFn G_TRANSLATION_FUN{nullptr};
static const kernel::Context btck_context_static{};
@@ -84,7 +83,7 @@ public:
//
void write(std::span<const std::byte> src)
{
- if (m_writer(std::data(src), src.size(), m_user_data) != 0) {
+ if (m_writer(src.data(), src.size(), m_user_data) != 0) {
throw std::runtime_error("Failed to write serialization data");
}
}
@@ -113,13 +112,13 @@ struct Handle {
static C* create(Args&&... args)
{
auto cpp_obj{std::make_unique<CPP>(std::forward<Args>(args)...)};
- return reinterpret_cast<C*>(cpp_obj.release());
+ return ref(cpp_obj.release());
}
static C* copy(const C* ptr)
{
auto cpp_obj{std::make_unique<CPP>(get(ptr))};
- return reinterpret_cast<C*>(cpp_obj.release());
+ return ref(cpp_obj.release());
}
static const CPP& get(const C* ptr)
diff --git a/src/kernel/bitcoinkernel.h b/src/kernel/bitcoinkernel.h
index a7f09dd3..5427e776 100644
--- a/src/kernel/bitcoinkernel.h
+++ b/src/kernel/bitcoinkernel.h
@@ -82,9 +82,9 @@ extern "C" {
* @section error Error handling
*
* Functions communicate an error through their return types, usually returning
- * a nullptr, 0, or false if an error is encountered. Additionally, verification
- * functions, e.g. for scripts, may communicate more detailed error information
- * through status code out parameters.
+ * a nullptr or a status code as documented by the returning function.
+ * Additionally, verification functions, e.g. for scripts, may communicate more
+ * detailed error information through status code out parameters.
*
* Fine-grained validation information is communicated through the validation
* interface.
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.