Skip to content

Commit

Permalink
WIP: libbitcoinsv2 C header API
Browse files Browse the repository at this point in the history
Standalone library with Stratum v2 functionality.

TODO: ?
  • Loading branch information
Sjors committed Sep 19, 2024
1 parent 5fca2c5 commit 5fb7fad
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ endif()

option(WITH_SV2 "Enable Stratum v2 functionality." OFF)

option(BUILD_SV2_LIB "Build experimental bitcoinsv2 library." OFF)

cmake_dependent_option(BUILD_GUI_TESTS "Build test_bitcoin-qt executable." ON "BUILD_GUI;BUILD_TESTS" OFF)
if(BUILD_GUI)
set(qt_components Core Gui Widgets LinguistTools)
Expand Down Expand Up @@ -245,6 +247,7 @@ if(BUILD_FOR_FUZZING)
set(WITH_MINIUPNPC OFF)
set(WITH_ZMQ OFF)
set(WITH_SV2 OFF)
set(BUILD_SV2_LIB OFF)
set(BUILD_TESTS OFF)
set(BUILD_GUI_TESTS OFF)
set(BUILD_BENCH OFF)
Expand Down Expand Up @@ -632,6 +635,7 @@ message(" USDT tracing ........................ ${WITH_USDT}")
message(" QR code (GUI) ....................... ${WITH_QRENCODE}")
message(" DBus (GUI, Linux only) .............. ${WITH_DBUS}")
message(" Stratum v2 .......................... ${WITH_SV2}")
message(" libbitcoinsv2 (experimental) ........ ${BUILD_SV2_LIB}")
message("Tests:")
message(" test_bitcoin ........................ ${BUILD_TESTS}")
message(" test_bitcoin-qt ..................... ${BUILD_GUI_TESTS}")
Expand Down
11 changes: 11 additions & 0 deletions libbitcoinsv2.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

Name: @PACKAGE_NAME@ sv2 library
Description: Experimental library for the Bitcoin Core Stratum v2 functionality.
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lbitcoinsv2
Libs.private: -L${libdir} @LIBS_PRIVATE@
Cflags: -I${includedir}
8 changes: 8 additions & 0 deletions src/sv2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ target_link_libraries(bitcoin_sv2
bitcoin_crypto
$<$<PLATFORM_ID:Windows>:ws2_32>
)

if (BUILD_SV2_LIB)
install(FILES bitcoinsv2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

configure_file(${PROJECT_SOURCE_DIR}/libbitcoinsv2.pc.in ${PROJECT_BINARY_DIR}/libbitcoinsv2.pc @ONLY)
install(FILES ${PROJECT_BINARY_DIR}/libbitcoinsv2.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

endif()
63 changes: 63 additions & 0 deletions src/sv2/bitcoinsv2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2024-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_SV2_BITCOINSV2_H
#define BITCOIN_SV2_BITCOINSV2_H

#ifndef __cplusplus
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#else
#include <cstddef>
#include <cstdint>
#endif // __cplusplus


#if !defined(BITCOINSV2_GNUC_PREREQ)
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
#define BITCOINSV2_GNUC_PREREQ(_maj, _min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((_maj) << 16) + (_min))
#else
#define BITCOINSV2_GNUC_PREREQ(_maj, _min) 0
#endif
#endif

/* Warning attributes */
#if defined(__GNUC__) && BITCOINSV2_GNUC_PREREQ(3, 4)
#define BITCOINSV2_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
#else
#define BITCOINSV2_WARN_UNUSED_RESULT
#endif
#if !defined(BITCOINSV2_BUILD) && defined(__GNUC__) && BITCOINSV2_GNUC_PREREQ(3, 4)
#define BITCOINSV2_ARG_NONNULL(_x) __attribute__((__nonnull__(_x)))
#else
#define BITCOINSV2_ARG_NONNULL(_x)
#endif

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/**
* ------ Context ------
*
* The library provides Stratum v2 functionality.
*
* ------ Error handling ------
*
* TODO
*
* ------ Pointer and argument conventions ------
*
* TODO
*/

// TODO: some actual methods

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

#endif // BITCOIN_SV2_BITCOINSV2_H

0 comments on commit 5fb7fad

Please sign in to comment.