Merge pull request #20 from TheBlueMatt/main
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Mon, 3 May 2021 13:18:57 +0000 (13:18 +0000)
committerGitHub <noreply@github.com>
Mon, 3 May 2021 13:18:57 +0000 (13:18 +0000)
.github/workflows/build.yml
c-bindings-gen/src/main.rs
genbindings.sh
lightning-c-bindings/cbindgen.toml
lightning-c-bindings/demo.c
lightning-c-bindings/demo.cpp
lightning-c-bindings/include/ldk_rust_types.h [new file with mode: 0644]
lightning-c-bindings/include/lightning.h
lightning-c-bindings/include/rust_types.h [deleted file]
lightning-c-bindings/src/lib.rs

index 2db5936984a1cbf9c77170372b6be8d9ab5cdcb6..b64b7c09c5d4b6e6b20500bfdaa0487be3965a1c 100644 (file)
@@ -15,12 +15,17 @@ jobs:
         run: |
           apt-get update
           apt-get -y dist-upgrade
-          apt-get -y install cargo valgrind lld git g++ clang
+          apt-get -y install cargo libstd-rust-dev-wasm32 valgrind lld git g++ clang
       - name: Checkout source code
         uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
       - name: Sanity test bindings against Cargo.toml RL
         working-directory: lightning-c-bindings
-        run: cargo check
+        run: |
+          # Note that the version tags aren't checked into git
+          touch src/version.rs
+          cargo check
       - name: Install cbindgen
         run: cargo install --force cbindgen
       - name: Checkout Rust-Lightning git
index c2ef30fbcf83a9e0c37204e1ee1b0f9466756ba4..7d26edce5a4a4bd3bf694300a3dcddadc794b429 100644 (file)
@@ -1422,6 +1422,7 @@ fn convert_file<'a, 'b>(libast: &'a FullLibraryAST, crate_types: &CrateTypes<'a>
                        writeln!(out, "#![allow(unused_braces)]").unwrap();
                        // TODO: We need to map deny(missing_docs) in the source crate(s)
                        //writeln!(out, "#![deny(missing_docs)]").unwrap();
+                       writeln!(out, "pub mod version;").unwrap();
                        writeln!(out, "pub mod c_types;").unwrap();
                        writeln!(out, "pub mod bitcoin;").unwrap();
                } else {
index e0ff6b3f060af4259a92c2545f6ced32d1a6b4d9..2a5e985e99355b71010484d3d3f11c246f8824da 100755 (executable)
@@ -13,6 +13,7 @@ fi
 ORIG_PWD="$(pwd)"
 cd "$1"
 LIGHTNING_PATH="$(pwd)"
+LIGHTNING_GIT="$(git describe --tag --dirty)"
 cd "$ORIG_PWD"
 
 # Generate (and reasonably test) C bindings
@@ -25,6 +26,42 @@ cd c-bindings-gen && cargo build --release && cd ..
 mv lightning-c-bindings/src/c_types/mod.rs ./
 mv lightning-c-bindings/src/bitcoin ./
 
+# Before we try to sed the Cargo.toml, generate version define tags
+# (ignoring any files that we're about to generate)
+
+git checkout lightning-c-bindings/src
+git checkout lightning-c-bindings/include
+BINDINGS_GIT="$(git describe --tag --dirty)"
+echo -e "#ifndef _LDK_HEADER_VER" > lightning-c-bindings/include/ldk_ver.h
+echo -e "static inline int _ldk_strncmp(const char *s1, const char *s2, uint64_t n) {" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\tif (n && *s1 != *s2) return 1;" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\twhile (n && *s1 != 0 && *s2 != 0) {" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\t\ts1++; s2++; n--;" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\t\tif (n && *s1 != *s2) return 1;" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\t}" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\treturn 0;" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "}" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "#define _LDK_HEADER_VER \"$LIGHTNING_GIT\"" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "#define _LDK_C_BINDINGS_HEADER_VER \"$BINDINGS_GIT\"" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "static inline const char* check_get_ldk_version() {" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\tLDKStr bin_ver = _ldk_get_compiled_version();" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\tif (_ldk_strncmp(_LDK_HEADER_VER, (const char*)bin_ver.chars, bin_ver.len) != 0) {" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\t// Version mismatch, we don't know what we're running!" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\t\treturn 0;" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\t}" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\treturn _LDK_HEADER_VER;" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "}" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "static inline const char* check_get_ldk_bindings_version() {" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\tLDKStr bin_ver = _ldk_c_bindings_get_compiled_version();" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\tif (_ldk_strncmp(_LDK_C_BINDINGS_HEADER_VER, (const char*)bin_ver.chars, bin_ver.len) != 0) {" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\t// Version mismatch, we don't know what we're running!" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\t\treturn 0;" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\t}" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "\treturn _LDK_C_BINDINGS_HEADER_VER;" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "}" >> lightning-c-bindings/include/ldk_ver.h
+echo -e "#endif /* _LDK_HEADER_VER */" >> lightning-c-bindings/include/ldk_ver.h
+
 rm -rf lightning-c-bindings/src
 
 mkdir -p lightning-c-bindings/src/{c_types,lightning}
@@ -34,7 +71,7 @@ mv ./bitcoin lightning-c-bindings/src/
 # Finally, run the c-bindings-gen binary, building fresh bindings.
 OUT="$(pwd)/lightning-c-bindings/src"
 OUT_TEMPL="$(pwd)/lightning-c-bindings/src/c_types/derived.rs"
-OUT_F="$(pwd)/lightning-c-bindings/include/rust_types.h"
+OUT_F="$(pwd)/lightning-c-bindings/include/ldk_rust_types.h"
 OUT_CPP="$(pwd)/lightning-c-bindings/include/lightningpp.hpp"
 BIN="$(pwd)/c-bindings-gen/target/release/c-bindings-gen"
 
@@ -83,6 +120,15 @@ add_crate "lightning-invoice" "lightning_invoice"
 
 cat /tmp/crate-source.txt | RUST_BACKTRACE=1 "$BIN" "$OUT/" "$OUT_TEMPL" "$OUT_F" "$OUT_CPP"
 
+echo -e '#[no_mangle]' >> lightning-c-bindings/src/version.rs
+echo -e 'pub extern "C" fn _ldk_get_compiled_version() -> crate::c_types::Str {' >> lightning-c-bindings/src/version.rs
+echo -e '\t"'"$LIGHTNING_GIT"'".into()' >> lightning-c-bindings/src/version.rs
+echo -e '}' >> lightning-c-bindings/src/version.rs
+echo -e '#[no_mangle]' >> lightning-c-bindings/src/version.rs
+echo -e 'pub extern "C" fn _ldk_c_bindings_get_compiled_version() -> crate::c_types::Str {' >> lightning-c-bindings/src/version.rs
+echo -e '\t"'"$BINDINGS_GIT"'".into()' >> lightning-c-bindings/src/version.rs
+echo -e '}' >> lightning-c-bindings/src/version.rs
+
 # Set path to include our rustc wrapper as well as cbindgen
 PATH="$(pwd)/deterministic-build-wrappers:$PATH:~/.cargo/bin"
 # Now cd to lightning-c-bindings, build the generated bindings, and call cbindgen to build a C header file
@@ -110,18 +156,18 @@ if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then
 
        # stdlib.h doesn't exist in clang's wasm sysroot, and cbindgen
        # doesn't actually use it anyway, so drop the import.
-       sed -i '' 's/#include <stdlib.h>//g' include/lightning.h
+       sed -i '' 's/#include <stdlib.h>/#include <ldk_rust_types.h>/g' include/lightning.h
 else
        sed -i 's/typedef LDKnative.*Import.*LDKnative.*;//g' include/lightning.h
 
        # stdlib.h doesn't exist in clang's wasm sysroot, and cbindgen
        # doesn't actually use it anyway, so drop the import.
-       sed -i 's/#include <stdlib.h>//g' include/lightning.h
+       sed -i 's/#include <stdlib.h>/#include <ldk_rust_types.h>/g' include/lightning.h
 fi
 
 # Finally, sanity-check the generated C and C++ bindings with demo apps:
 
-LOCAL_CFLAGS="-Wall -Wno-nullability-completeness -pthread"
+LOCAL_CFLAGS="-Wall -Wno-nullability-completeness -pthread -Iinclude/"
 
 # Naively run the C demo app:
 gcc $LOCAL_CFLAGS -Wall -g -pthread demo.c target/debug/libldk.a -ldl
@@ -251,7 +297,7 @@ clang++ $LOCAL_CFLAGS -std=c++11 -flto -O2 demo.cpp target/release/libldk.a -ldl
 if [ "$HOST_PLATFORM" != "host: x86_64-apple-darwin" -a "$CLANGPP" != "" ]; then
        # If we can use cross-language LTO, use it for building C dependencies (i.e. libsecp256k1) as well
        export CC="$CLANG"
-       export CFLAGS_wasm32_wasi="-target wasm32"
+       export CFLAGS_wasm32_wasi="-target wasm32 -flto"
 fi
 
 if [ "$2" = "false" -a "$(rustc --print target-list | grep wasm32-wasi)" != "" ]; then
@@ -260,8 +306,6 @@ if [ "$2" = "false" -a "$(rustc --print target-list | grep wasm32-wasi)" != "" ]
        clang -nostdlib -o /dev/null --target=wasm32-wasi -Wl,--no-entry genbindings_wasm_test_file.c > /dev/null 2>&1 &&
        # And if it does, build a WASM binary without capturing errors
        cargo rustc -v --target=wasm32-wasi -- -C embed-bitcode=yes &&
-       # Now that we've done our last non-LTO build, turn on LTO in CFLAGS as well
-       export CFLAGS="$CFLAGS -flto" &&
        CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release --target=wasm32-wasi -- -C opt-level=s -C linker-plugin-lto -C lto ||
        echo "Cannot build WASM lib as clang does not seem to support the wasm32-wasi target"
        rm genbindings_wasm_test_file.c
index b9e49b3602890cbb8be374f8addaa7e12f2677fb..bcbe2641dc4a39e161d877b98f14d22253c1a014 100644 (file)
@@ -1,6 +1,7 @@
 language = "C"
 include_guard = "LDK_C_BINDINGS_H"
 autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */"
+trailer = "#include <ldk_ver.h>"
 include_version = true
 namespace = "LDK"
 
index 2e4d363f0310f484cc93d2127013978bdbc51222..2a45e4644157a903313c419fa09632563e2db205 100644 (file)
@@ -1,5 +1,4 @@
-#include "include/rust_types.h"
-#include "include/lightning.h"
+#include <lightning.h>
 
 #include <assert.h>
 #include <stdio.h>
index f2641094b2b6602c959e4e3adb145d968750c298..4bc3115e9715295ce96d1ffa0cf1f3b372d6120e 100644 (file)
@@ -1,6 +1,5 @@
 extern "C" {
-#include "include/rust_types.h"
-#include "include/lightning.h"
+#include <lightning.h>
 }
 #include "include/lightningpp.hpp"
 
diff --git a/lightning-c-bindings/include/ldk_rust_types.h b/lightning-c-bindings/include/ldk_rust_types.h
new file mode 100644 (file)
index 0000000..7dc569b
--- /dev/null
@@ -0,0 +1,211 @@
+#if defined(__GNUC__)
+#define MUST_USE_STRUCT __attribute__((warn_unused))
+#define MUST_USE_RES __attribute__((warn_unused_result))
+#else
+#define MUST_USE_STRUCT
+#define MUST_USE_RES
+#endif
+#if defined(__clang__)
+#define NONNULL_PTR _Nonnull
+#else
+#define NONNULL_PTR
+#endif
+struct nativeChannelHandshakeConfigOpaque;
+typedef struct nativeChannelHandshakeConfigOpaque LDKnativeChannelHandshakeConfig;
+struct nativeChannelHandshakeLimitsOpaque;
+typedef struct nativeChannelHandshakeLimitsOpaque LDKnativeChannelHandshakeLimits;
+struct nativeChannelConfigOpaque;
+typedef struct nativeChannelConfigOpaque LDKnativeChannelConfig;
+struct nativeUserConfigOpaque;
+typedef struct nativeUserConfigOpaque LDKnativeUserConfig;
+struct nativeOutPointOpaque;
+typedef struct nativeOutPointOpaque LDKnativeOutPoint;
+struct nativeTxCreationKeysOpaque;
+typedef struct nativeTxCreationKeysOpaque LDKnativeTxCreationKeys;
+struct nativeChannelPublicKeysOpaque;
+typedef struct nativeChannelPublicKeysOpaque LDKnativeChannelPublicKeys;
+struct nativeHTLCOutputInCommitmentOpaque;
+typedef struct nativeHTLCOutputInCommitmentOpaque LDKnativeHTLCOutputInCommitment;
+struct nativeChannelTransactionParametersOpaque;
+typedef struct nativeChannelTransactionParametersOpaque LDKnativeChannelTransactionParameters;
+struct nativeCounterpartyChannelTransactionParametersOpaque;
+typedef struct nativeCounterpartyChannelTransactionParametersOpaque LDKnativeCounterpartyChannelTransactionParameters;
+struct nativeDirectedChannelTransactionParametersOpaque;
+typedef struct nativeDirectedChannelTransactionParametersOpaque LDKnativeDirectedChannelTransactionParameters;
+struct nativeHolderCommitmentTransactionOpaque;
+typedef struct nativeHolderCommitmentTransactionOpaque LDKnativeHolderCommitmentTransaction;
+struct nativeBuiltCommitmentTransactionOpaque;
+typedef struct nativeBuiltCommitmentTransactionOpaque LDKnativeBuiltCommitmentTransaction;
+struct nativeCommitmentTransactionOpaque;
+typedef struct nativeCommitmentTransactionOpaque LDKnativeCommitmentTransaction;
+struct nativeTrustedCommitmentTransactionOpaque;
+typedef struct nativeTrustedCommitmentTransactionOpaque LDKnativeTrustedCommitmentTransaction;
+struct nativeInvoiceOpaque;
+typedef struct nativeInvoiceOpaque LDKnativeInvoice;
+struct nativeSignedRawInvoiceOpaque;
+typedef struct nativeSignedRawInvoiceOpaque LDKnativeSignedRawInvoice;
+struct nativeRawInvoiceOpaque;
+typedef struct nativeRawInvoiceOpaque LDKnativeRawInvoice;
+struct nativeRawDataPartOpaque;
+typedef struct nativeRawDataPartOpaque LDKnativeRawDataPart;
+struct nativePositiveTimestampOpaque;
+typedef struct nativePositiveTimestampOpaque LDKnativePositiveTimestamp;
+struct nativeSha256Opaque;
+typedef struct nativeSha256Opaque LDKnativeSha256;
+struct nativeDescriptionOpaque;
+typedef struct nativeDescriptionOpaque LDKnativeDescription;
+struct nativePayeePubKeyOpaque;
+typedef struct nativePayeePubKeyOpaque LDKnativePayeePubKey;
+struct nativeExpiryTimeOpaque;
+typedef struct nativeExpiryTimeOpaque LDKnativeExpiryTime;
+struct nativeMinFinalCltvExpiryOpaque;
+typedef struct nativeMinFinalCltvExpiryOpaque LDKnativeMinFinalCltvExpiry;
+struct nativeInvoiceSignatureOpaque;
+typedef struct nativeInvoiceSignatureOpaque LDKnativeInvoiceSignature;
+struct nativeRouteHintOpaque;
+typedef struct nativeRouteHintOpaque LDKnativeRouteHint;
+struct nativeChannelMonitorUpdateOpaque;
+typedef struct nativeChannelMonitorUpdateOpaque LDKnativeChannelMonitorUpdate;
+struct nativeMonitorUpdateErrorOpaque;
+typedef struct nativeMonitorUpdateErrorOpaque LDKnativeMonitorUpdateError;
+struct nativeHTLCUpdateOpaque;
+typedef struct nativeHTLCUpdateOpaque LDKnativeHTLCUpdate;
+struct nativeChannelMonitorOpaque;
+typedef struct nativeChannelMonitorOpaque LDKnativeChannelMonitor;
+struct nativeRouteHopOpaque;
+typedef struct nativeRouteHopOpaque LDKnativeRouteHop;
+struct nativeRouteOpaque;
+typedef struct nativeRouteOpaque LDKnativeRoute;
+struct nativeRouteHintHopOpaque;
+typedef struct nativeRouteHintHopOpaque LDKnativeRouteHintHop;
+struct nativeIgnoringMessageHandlerOpaque;
+typedef struct nativeIgnoringMessageHandlerOpaque LDKnativeIgnoringMessageHandler;
+struct nativeErroringMessageHandlerOpaque;
+typedef struct nativeErroringMessageHandlerOpaque LDKnativeErroringMessageHandler;
+struct nativeMessageHandlerOpaque;
+typedef struct nativeMessageHandlerOpaque LDKnativeMessageHandler;
+typedef struct LDKSocketDescriptor LDKSocketDescriptor;
+struct nativePeerHandleErrorOpaque;
+typedef struct nativePeerHandleErrorOpaque LDKnativePeerHandleError;
+struct nativePeerManagerOpaque;
+typedef struct nativePeerManagerOpaque LDKnativePeerManager;
+struct nativeWatchedOutputOpaque;
+typedef struct nativeWatchedOutputOpaque LDKnativeWatchedOutput;
+struct nativeNetworkGraphOpaque;
+typedef struct nativeNetworkGraphOpaque LDKnativeNetworkGraph;
+struct nativeLockedNetworkGraphOpaque;
+typedef struct nativeLockedNetworkGraphOpaque LDKnativeLockedNetworkGraph;
+struct nativeNetGraphMsgHandlerOpaque;
+typedef struct nativeNetGraphMsgHandlerOpaque LDKnativeNetGraphMsgHandler;
+struct nativeDirectionalChannelInfoOpaque;
+typedef struct nativeDirectionalChannelInfoOpaque LDKnativeDirectionalChannelInfo;
+struct nativeChannelInfoOpaque;
+typedef struct nativeChannelInfoOpaque LDKnativeChannelInfo;
+struct nativeRoutingFeesOpaque;
+typedef struct nativeRoutingFeesOpaque LDKnativeRoutingFees;
+struct nativeNodeAnnouncementInfoOpaque;
+typedef struct nativeNodeAnnouncementInfoOpaque LDKnativeNodeAnnouncementInfo;
+struct nativeNodeInfoOpaque;
+typedef struct nativeNodeInfoOpaque LDKnativeNodeInfo;
+struct nativeInitFeaturesOpaque;
+typedef struct nativeInitFeaturesOpaque LDKnativeInitFeatures;
+struct nativeNodeFeaturesOpaque;
+typedef struct nativeNodeFeaturesOpaque LDKnativeNodeFeatures;
+struct nativeChannelFeaturesOpaque;
+typedef struct nativeChannelFeaturesOpaque LDKnativeChannelFeatures;
+struct nativeInvoiceFeaturesOpaque;
+typedef struct nativeInvoiceFeaturesOpaque LDKnativeInvoiceFeatures;
+struct nativeDecodeErrorOpaque;
+typedef struct nativeDecodeErrorOpaque LDKnativeDecodeError;
+struct nativeInitOpaque;
+typedef struct nativeInitOpaque LDKnativeInit;
+struct nativeErrorMessageOpaque;
+typedef struct nativeErrorMessageOpaque LDKnativeErrorMessage;
+struct nativePingOpaque;
+typedef struct nativePingOpaque LDKnativePing;
+struct nativePongOpaque;
+typedef struct nativePongOpaque LDKnativePong;
+struct nativeOpenChannelOpaque;
+typedef struct nativeOpenChannelOpaque LDKnativeOpenChannel;
+struct nativeAcceptChannelOpaque;
+typedef struct nativeAcceptChannelOpaque LDKnativeAcceptChannel;
+struct nativeFundingCreatedOpaque;
+typedef struct nativeFundingCreatedOpaque LDKnativeFundingCreated;
+struct nativeFundingSignedOpaque;
+typedef struct nativeFundingSignedOpaque LDKnativeFundingSigned;
+struct nativeFundingLockedOpaque;
+typedef struct nativeFundingLockedOpaque LDKnativeFundingLocked;
+struct nativeShutdownOpaque;
+typedef struct nativeShutdownOpaque LDKnativeShutdown;
+struct nativeClosingSignedOpaque;
+typedef struct nativeClosingSignedOpaque LDKnativeClosingSigned;
+struct nativeUpdateAddHTLCOpaque;
+typedef struct nativeUpdateAddHTLCOpaque LDKnativeUpdateAddHTLC;
+struct nativeUpdateFulfillHTLCOpaque;
+typedef struct nativeUpdateFulfillHTLCOpaque LDKnativeUpdateFulfillHTLC;
+struct nativeUpdateFailHTLCOpaque;
+typedef struct nativeUpdateFailHTLCOpaque LDKnativeUpdateFailHTLC;
+struct nativeUpdateFailMalformedHTLCOpaque;
+typedef struct nativeUpdateFailMalformedHTLCOpaque LDKnativeUpdateFailMalformedHTLC;
+struct nativeCommitmentSignedOpaque;
+typedef struct nativeCommitmentSignedOpaque LDKnativeCommitmentSigned;
+struct nativeRevokeAndACKOpaque;
+typedef struct nativeRevokeAndACKOpaque LDKnativeRevokeAndACK;
+struct nativeUpdateFeeOpaque;
+typedef struct nativeUpdateFeeOpaque LDKnativeUpdateFee;
+struct nativeDataLossProtectOpaque;
+typedef struct nativeDataLossProtectOpaque LDKnativeDataLossProtect;
+struct nativeChannelReestablishOpaque;
+typedef struct nativeChannelReestablishOpaque LDKnativeChannelReestablish;
+struct nativeAnnouncementSignaturesOpaque;
+typedef struct nativeAnnouncementSignaturesOpaque LDKnativeAnnouncementSignatures;
+struct nativeUnsignedNodeAnnouncementOpaque;
+typedef struct nativeUnsignedNodeAnnouncementOpaque LDKnativeUnsignedNodeAnnouncement;
+struct nativeNodeAnnouncementOpaque;
+typedef struct nativeNodeAnnouncementOpaque LDKnativeNodeAnnouncement;
+struct nativeUnsignedChannelAnnouncementOpaque;
+typedef struct nativeUnsignedChannelAnnouncementOpaque LDKnativeUnsignedChannelAnnouncement;
+struct nativeChannelAnnouncementOpaque;
+typedef struct nativeChannelAnnouncementOpaque LDKnativeChannelAnnouncement;
+struct nativeUnsignedChannelUpdateOpaque;
+typedef struct nativeUnsignedChannelUpdateOpaque LDKnativeUnsignedChannelUpdate;
+struct nativeChannelUpdateOpaque;
+typedef struct nativeChannelUpdateOpaque LDKnativeChannelUpdate;
+struct nativeQueryChannelRangeOpaque;
+typedef struct nativeQueryChannelRangeOpaque LDKnativeQueryChannelRange;
+struct nativeReplyChannelRangeOpaque;
+typedef struct nativeReplyChannelRangeOpaque LDKnativeReplyChannelRange;
+struct nativeQueryShortChannelIdsOpaque;
+typedef struct nativeQueryShortChannelIdsOpaque LDKnativeQueryShortChannelIds;
+struct nativeReplyShortChannelIdsEndOpaque;
+typedef struct nativeReplyShortChannelIdsEndOpaque LDKnativeReplyShortChannelIdsEnd;
+struct nativeGossipTimestampFilterOpaque;
+typedef struct nativeGossipTimestampFilterOpaque LDKnativeGossipTimestampFilter;
+struct nativeLightningErrorOpaque;
+typedef struct nativeLightningErrorOpaque LDKnativeLightningError;
+struct nativeCommitmentUpdateOpaque;
+typedef struct nativeCommitmentUpdateOpaque LDKnativeCommitmentUpdate;
+struct nativeDelayedPaymentOutputDescriptorOpaque;
+typedef struct nativeDelayedPaymentOutputDescriptorOpaque LDKnativeDelayedPaymentOutputDescriptor;
+struct nativeStaticPaymentOutputDescriptorOpaque;
+typedef struct nativeStaticPaymentOutputDescriptorOpaque LDKnativeStaticPaymentOutputDescriptor;
+struct LDKBaseSign;
+typedef struct LDKBaseSign LDKBaseSign;
+struct nativeInMemorySignerOpaque;
+typedef struct nativeInMemorySignerOpaque LDKnativeInMemorySigner;
+struct nativeKeysManagerOpaque;
+typedef struct nativeKeysManagerOpaque LDKnativeKeysManager;
+struct nativeChainMonitorOpaque;
+typedef struct nativeChainMonitorOpaque LDKnativeChainMonitor;
+struct nativeFilesystemPersisterOpaque;
+typedef struct nativeFilesystemPersisterOpaque LDKnativeFilesystemPersister;
+struct nativeChannelManagerOpaque;
+typedef struct nativeChannelManagerOpaque LDKnativeChannelManager;
+struct nativeChainParametersOpaque;
+typedef struct nativeChainParametersOpaque LDKnativeChainParameters;
+struct nativeBestBlockOpaque;
+typedef struct nativeBestBlockOpaque LDKnativeBestBlock;
+struct nativeChannelDetailsOpaque;
+typedef struct nativeChannelDetailsOpaque LDKnativeChannelDetails;
+struct nativeChannelManagerReadArgsOpaque;
+typedef struct nativeChannelManagerReadArgsOpaque LDKnativeChannelManagerReadArgs;
index 2527e65a2ed349e3b6714bbb7af5b2be5c401acb..60acaae9290efe2ed0decf541d605bea305e56c3 100644 (file)
@@ -8,7 +8,7 @@
 #include <stdarg.h>
 #include <stdbool.h>
 #include <stdint.h>
-
+#include <ldk_rust_types.h>
 
 /**
  * An error when accessing the chain via [`Access`].
@@ -368,6 +368,25 @@ typedef enum LDKSiPrefix {
    LDKSiPrefix_Sentinel,
 } LDKSiPrefix;
 
+/**
+ * A Rust str object, ie a reference to a UTF8-valid string.
+ * This is *not* null-terminated so cannot be used directly as a C string!
+ */
+typedef struct LDKStr {
+   /**
+    * A pointer to the string's bytes, in UTF8 encoding
+    */
+   const uint8_t *chars;
+   /**
+    * The number of bytes (not characters!) pointed to by `chars`
+    */
+   uintptr_t len;
+   /**
+    * Whether the data pointed to by `chars` should be freed or not.
+    */
+   bool chars_is_owned;
+} LDKStr;
+
 /**
  * A serialized transaction, in (pointer, length) form.
  *
@@ -431,25 +450,6 @@ typedef struct LDKTxOut {
    uint64_t value;
 } LDKTxOut;
 
-/**
- * A Rust str object, ie a reference to a UTF8-valid string.
- * This is *not* null-terminated so cannot be used directly as a C string!
- */
-typedef struct LDKStr {
-   /**
-    * A pointer to the string's bytes, in UTF8 encoding
-    */
-   const uint8_t *chars;
-   /**
-    * The number of bytes (not characters!) pointed to by `chars`
-    */
-   uintptr_t len;
-   /**
-    * Whether the data pointed to by `chars` should be freed or not.
-    */
-   bool chars_is_owned;
-} LDKStr;
-
 
 
 /**
@@ -8757,6 +8757,10 @@ extern const uint8_t TAG_PAYMENT_SECRET;
 
 extern const uint8_t TAG_FEATURES;
 
+struct LDKStr _ldk_get_compiled_version(void);
+
+struct LDKStr _ldk_c_bindings_get_compiled_version(void);
+
 /**
  * Frees the data buffer, if data_is_owned is set and datalen > 0.
  */
@@ -17664,3 +17668,5 @@ struct LDKStr Currency_to_str(const enum LDKCurrency *NONNULL_PTR o);
 struct LDKStr SiPrefix_to_str(const enum LDKSiPrefix *NONNULL_PTR o);
 
 #endif /* LDK_C_BINDINGS_H */
+
+#include <ldk_ver.h>
diff --git a/lightning-c-bindings/include/rust_types.h b/lightning-c-bindings/include/rust_types.h
deleted file mode 100644 (file)
index 7dc569b..0000000
+++ /dev/null
@@ -1,211 +0,0 @@
-#if defined(__GNUC__)
-#define MUST_USE_STRUCT __attribute__((warn_unused))
-#define MUST_USE_RES __attribute__((warn_unused_result))
-#else
-#define MUST_USE_STRUCT
-#define MUST_USE_RES
-#endif
-#if defined(__clang__)
-#define NONNULL_PTR _Nonnull
-#else
-#define NONNULL_PTR
-#endif
-struct nativeChannelHandshakeConfigOpaque;
-typedef struct nativeChannelHandshakeConfigOpaque LDKnativeChannelHandshakeConfig;
-struct nativeChannelHandshakeLimitsOpaque;
-typedef struct nativeChannelHandshakeLimitsOpaque LDKnativeChannelHandshakeLimits;
-struct nativeChannelConfigOpaque;
-typedef struct nativeChannelConfigOpaque LDKnativeChannelConfig;
-struct nativeUserConfigOpaque;
-typedef struct nativeUserConfigOpaque LDKnativeUserConfig;
-struct nativeOutPointOpaque;
-typedef struct nativeOutPointOpaque LDKnativeOutPoint;
-struct nativeTxCreationKeysOpaque;
-typedef struct nativeTxCreationKeysOpaque LDKnativeTxCreationKeys;
-struct nativeChannelPublicKeysOpaque;
-typedef struct nativeChannelPublicKeysOpaque LDKnativeChannelPublicKeys;
-struct nativeHTLCOutputInCommitmentOpaque;
-typedef struct nativeHTLCOutputInCommitmentOpaque LDKnativeHTLCOutputInCommitment;
-struct nativeChannelTransactionParametersOpaque;
-typedef struct nativeChannelTransactionParametersOpaque LDKnativeChannelTransactionParameters;
-struct nativeCounterpartyChannelTransactionParametersOpaque;
-typedef struct nativeCounterpartyChannelTransactionParametersOpaque LDKnativeCounterpartyChannelTransactionParameters;
-struct nativeDirectedChannelTransactionParametersOpaque;
-typedef struct nativeDirectedChannelTransactionParametersOpaque LDKnativeDirectedChannelTransactionParameters;
-struct nativeHolderCommitmentTransactionOpaque;
-typedef struct nativeHolderCommitmentTransactionOpaque LDKnativeHolderCommitmentTransaction;
-struct nativeBuiltCommitmentTransactionOpaque;
-typedef struct nativeBuiltCommitmentTransactionOpaque LDKnativeBuiltCommitmentTransaction;
-struct nativeCommitmentTransactionOpaque;
-typedef struct nativeCommitmentTransactionOpaque LDKnativeCommitmentTransaction;
-struct nativeTrustedCommitmentTransactionOpaque;
-typedef struct nativeTrustedCommitmentTransactionOpaque LDKnativeTrustedCommitmentTransaction;
-struct nativeInvoiceOpaque;
-typedef struct nativeInvoiceOpaque LDKnativeInvoice;
-struct nativeSignedRawInvoiceOpaque;
-typedef struct nativeSignedRawInvoiceOpaque LDKnativeSignedRawInvoice;
-struct nativeRawInvoiceOpaque;
-typedef struct nativeRawInvoiceOpaque LDKnativeRawInvoice;
-struct nativeRawDataPartOpaque;
-typedef struct nativeRawDataPartOpaque LDKnativeRawDataPart;
-struct nativePositiveTimestampOpaque;
-typedef struct nativePositiveTimestampOpaque LDKnativePositiveTimestamp;
-struct nativeSha256Opaque;
-typedef struct nativeSha256Opaque LDKnativeSha256;
-struct nativeDescriptionOpaque;
-typedef struct nativeDescriptionOpaque LDKnativeDescription;
-struct nativePayeePubKeyOpaque;
-typedef struct nativePayeePubKeyOpaque LDKnativePayeePubKey;
-struct nativeExpiryTimeOpaque;
-typedef struct nativeExpiryTimeOpaque LDKnativeExpiryTime;
-struct nativeMinFinalCltvExpiryOpaque;
-typedef struct nativeMinFinalCltvExpiryOpaque LDKnativeMinFinalCltvExpiry;
-struct nativeInvoiceSignatureOpaque;
-typedef struct nativeInvoiceSignatureOpaque LDKnativeInvoiceSignature;
-struct nativeRouteHintOpaque;
-typedef struct nativeRouteHintOpaque LDKnativeRouteHint;
-struct nativeChannelMonitorUpdateOpaque;
-typedef struct nativeChannelMonitorUpdateOpaque LDKnativeChannelMonitorUpdate;
-struct nativeMonitorUpdateErrorOpaque;
-typedef struct nativeMonitorUpdateErrorOpaque LDKnativeMonitorUpdateError;
-struct nativeHTLCUpdateOpaque;
-typedef struct nativeHTLCUpdateOpaque LDKnativeHTLCUpdate;
-struct nativeChannelMonitorOpaque;
-typedef struct nativeChannelMonitorOpaque LDKnativeChannelMonitor;
-struct nativeRouteHopOpaque;
-typedef struct nativeRouteHopOpaque LDKnativeRouteHop;
-struct nativeRouteOpaque;
-typedef struct nativeRouteOpaque LDKnativeRoute;
-struct nativeRouteHintHopOpaque;
-typedef struct nativeRouteHintHopOpaque LDKnativeRouteHintHop;
-struct nativeIgnoringMessageHandlerOpaque;
-typedef struct nativeIgnoringMessageHandlerOpaque LDKnativeIgnoringMessageHandler;
-struct nativeErroringMessageHandlerOpaque;
-typedef struct nativeErroringMessageHandlerOpaque LDKnativeErroringMessageHandler;
-struct nativeMessageHandlerOpaque;
-typedef struct nativeMessageHandlerOpaque LDKnativeMessageHandler;
-typedef struct LDKSocketDescriptor LDKSocketDescriptor;
-struct nativePeerHandleErrorOpaque;
-typedef struct nativePeerHandleErrorOpaque LDKnativePeerHandleError;
-struct nativePeerManagerOpaque;
-typedef struct nativePeerManagerOpaque LDKnativePeerManager;
-struct nativeWatchedOutputOpaque;
-typedef struct nativeWatchedOutputOpaque LDKnativeWatchedOutput;
-struct nativeNetworkGraphOpaque;
-typedef struct nativeNetworkGraphOpaque LDKnativeNetworkGraph;
-struct nativeLockedNetworkGraphOpaque;
-typedef struct nativeLockedNetworkGraphOpaque LDKnativeLockedNetworkGraph;
-struct nativeNetGraphMsgHandlerOpaque;
-typedef struct nativeNetGraphMsgHandlerOpaque LDKnativeNetGraphMsgHandler;
-struct nativeDirectionalChannelInfoOpaque;
-typedef struct nativeDirectionalChannelInfoOpaque LDKnativeDirectionalChannelInfo;
-struct nativeChannelInfoOpaque;
-typedef struct nativeChannelInfoOpaque LDKnativeChannelInfo;
-struct nativeRoutingFeesOpaque;
-typedef struct nativeRoutingFeesOpaque LDKnativeRoutingFees;
-struct nativeNodeAnnouncementInfoOpaque;
-typedef struct nativeNodeAnnouncementInfoOpaque LDKnativeNodeAnnouncementInfo;
-struct nativeNodeInfoOpaque;
-typedef struct nativeNodeInfoOpaque LDKnativeNodeInfo;
-struct nativeInitFeaturesOpaque;
-typedef struct nativeInitFeaturesOpaque LDKnativeInitFeatures;
-struct nativeNodeFeaturesOpaque;
-typedef struct nativeNodeFeaturesOpaque LDKnativeNodeFeatures;
-struct nativeChannelFeaturesOpaque;
-typedef struct nativeChannelFeaturesOpaque LDKnativeChannelFeatures;
-struct nativeInvoiceFeaturesOpaque;
-typedef struct nativeInvoiceFeaturesOpaque LDKnativeInvoiceFeatures;
-struct nativeDecodeErrorOpaque;
-typedef struct nativeDecodeErrorOpaque LDKnativeDecodeError;
-struct nativeInitOpaque;
-typedef struct nativeInitOpaque LDKnativeInit;
-struct nativeErrorMessageOpaque;
-typedef struct nativeErrorMessageOpaque LDKnativeErrorMessage;
-struct nativePingOpaque;
-typedef struct nativePingOpaque LDKnativePing;
-struct nativePongOpaque;
-typedef struct nativePongOpaque LDKnativePong;
-struct nativeOpenChannelOpaque;
-typedef struct nativeOpenChannelOpaque LDKnativeOpenChannel;
-struct nativeAcceptChannelOpaque;
-typedef struct nativeAcceptChannelOpaque LDKnativeAcceptChannel;
-struct nativeFundingCreatedOpaque;
-typedef struct nativeFundingCreatedOpaque LDKnativeFundingCreated;
-struct nativeFundingSignedOpaque;
-typedef struct nativeFundingSignedOpaque LDKnativeFundingSigned;
-struct nativeFundingLockedOpaque;
-typedef struct nativeFundingLockedOpaque LDKnativeFundingLocked;
-struct nativeShutdownOpaque;
-typedef struct nativeShutdownOpaque LDKnativeShutdown;
-struct nativeClosingSignedOpaque;
-typedef struct nativeClosingSignedOpaque LDKnativeClosingSigned;
-struct nativeUpdateAddHTLCOpaque;
-typedef struct nativeUpdateAddHTLCOpaque LDKnativeUpdateAddHTLC;
-struct nativeUpdateFulfillHTLCOpaque;
-typedef struct nativeUpdateFulfillHTLCOpaque LDKnativeUpdateFulfillHTLC;
-struct nativeUpdateFailHTLCOpaque;
-typedef struct nativeUpdateFailHTLCOpaque LDKnativeUpdateFailHTLC;
-struct nativeUpdateFailMalformedHTLCOpaque;
-typedef struct nativeUpdateFailMalformedHTLCOpaque LDKnativeUpdateFailMalformedHTLC;
-struct nativeCommitmentSignedOpaque;
-typedef struct nativeCommitmentSignedOpaque LDKnativeCommitmentSigned;
-struct nativeRevokeAndACKOpaque;
-typedef struct nativeRevokeAndACKOpaque LDKnativeRevokeAndACK;
-struct nativeUpdateFeeOpaque;
-typedef struct nativeUpdateFeeOpaque LDKnativeUpdateFee;
-struct nativeDataLossProtectOpaque;
-typedef struct nativeDataLossProtectOpaque LDKnativeDataLossProtect;
-struct nativeChannelReestablishOpaque;
-typedef struct nativeChannelReestablishOpaque LDKnativeChannelReestablish;
-struct nativeAnnouncementSignaturesOpaque;
-typedef struct nativeAnnouncementSignaturesOpaque LDKnativeAnnouncementSignatures;
-struct nativeUnsignedNodeAnnouncementOpaque;
-typedef struct nativeUnsignedNodeAnnouncementOpaque LDKnativeUnsignedNodeAnnouncement;
-struct nativeNodeAnnouncementOpaque;
-typedef struct nativeNodeAnnouncementOpaque LDKnativeNodeAnnouncement;
-struct nativeUnsignedChannelAnnouncementOpaque;
-typedef struct nativeUnsignedChannelAnnouncementOpaque LDKnativeUnsignedChannelAnnouncement;
-struct nativeChannelAnnouncementOpaque;
-typedef struct nativeChannelAnnouncementOpaque LDKnativeChannelAnnouncement;
-struct nativeUnsignedChannelUpdateOpaque;
-typedef struct nativeUnsignedChannelUpdateOpaque LDKnativeUnsignedChannelUpdate;
-struct nativeChannelUpdateOpaque;
-typedef struct nativeChannelUpdateOpaque LDKnativeChannelUpdate;
-struct nativeQueryChannelRangeOpaque;
-typedef struct nativeQueryChannelRangeOpaque LDKnativeQueryChannelRange;
-struct nativeReplyChannelRangeOpaque;
-typedef struct nativeReplyChannelRangeOpaque LDKnativeReplyChannelRange;
-struct nativeQueryShortChannelIdsOpaque;
-typedef struct nativeQueryShortChannelIdsOpaque LDKnativeQueryShortChannelIds;
-struct nativeReplyShortChannelIdsEndOpaque;
-typedef struct nativeReplyShortChannelIdsEndOpaque LDKnativeReplyShortChannelIdsEnd;
-struct nativeGossipTimestampFilterOpaque;
-typedef struct nativeGossipTimestampFilterOpaque LDKnativeGossipTimestampFilter;
-struct nativeLightningErrorOpaque;
-typedef struct nativeLightningErrorOpaque LDKnativeLightningError;
-struct nativeCommitmentUpdateOpaque;
-typedef struct nativeCommitmentUpdateOpaque LDKnativeCommitmentUpdate;
-struct nativeDelayedPaymentOutputDescriptorOpaque;
-typedef struct nativeDelayedPaymentOutputDescriptorOpaque LDKnativeDelayedPaymentOutputDescriptor;
-struct nativeStaticPaymentOutputDescriptorOpaque;
-typedef struct nativeStaticPaymentOutputDescriptorOpaque LDKnativeStaticPaymentOutputDescriptor;
-struct LDKBaseSign;
-typedef struct LDKBaseSign LDKBaseSign;
-struct nativeInMemorySignerOpaque;
-typedef struct nativeInMemorySignerOpaque LDKnativeInMemorySigner;
-struct nativeKeysManagerOpaque;
-typedef struct nativeKeysManagerOpaque LDKnativeKeysManager;
-struct nativeChainMonitorOpaque;
-typedef struct nativeChainMonitorOpaque LDKnativeChainMonitor;
-struct nativeFilesystemPersisterOpaque;
-typedef struct nativeFilesystemPersisterOpaque LDKnativeFilesystemPersister;
-struct nativeChannelManagerOpaque;
-typedef struct nativeChannelManagerOpaque LDKnativeChannelManager;
-struct nativeChainParametersOpaque;
-typedef struct nativeChainParametersOpaque LDKnativeChainParameters;
-struct nativeBestBlockOpaque;
-typedef struct nativeBestBlockOpaque LDKnativeBestBlock;
-struct nativeChannelDetailsOpaque;
-typedef struct nativeChannelDetailsOpaque LDKnativeChannelDetails;
-struct nativeChannelManagerReadArgsOpaque;
-typedef struct nativeChannelManagerReadArgsOpaque LDKnativeChannelManagerReadArgs;
index 3485c467f235e9e8bc0e74c8ce06533a864435d3..e4b62ba01da763a82f52bd3187b4ba75e7d7b048 100644 (file)
@@ -16,6 +16,7 @@
 #![allow(unused_parens)]
 #![allow(unused_unsafe)]
 #![allow(unused_braces)]
+pub mod version;
 pub mod c_types;
 pub mod bitcoin;
 pub mod lightning;