]> git.bitcoin.ninja Git - ldk-java/commitdiff
Handle the somewhat half-mapped alias TransactionOutputs
authorMatt Corallo <git@bluematt.me>
Thu, 15 Apr 2021 23:00:35 +0000 (19:00 -0400)
committerMatt Corallo <git@bluematt.me>
Fri, 16 Apr 2021 00:44:11 +0000 (00:44 +0000)
TransactionOutputs is actually a
C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ, but with a type alias that
gives it a more readable name in a few places. Sadly, we don't
support type aliases, so we have to just map it back before building
our bindings.

genbindings.py
genbindings.sh

index b1f4a5eb60c8395af74ab41ba0cb5328e8216b9e..ab5b0cbf183a1372a250bd47f65de85200243aff 100755 (executable)
@@ -151,7 +151,7 @@ def java_c_types(fn_arg, ret_arr_len):
         rust_obj = "LDKCVec_u8Z"
         assert var_is_arr_regex.match(fn_arg[8:])
         arr_access = "data"
-    elif fn_arg.startswith("LDKTransaction"):
+    elif fn_arg.startswith("LDKTransaction ") or fn_arg == "LDKTransaction":
         fn_arg = "uint8_t (*" + fn_arg[15:] + ")[datalen]"
         rust_obj = "LDKTransaction"
         assert var_is_arr_regex.match(fn_arg[8:])
index dcec47be02a88027465398045f54a90a9019a33e..e208785f2156acac8ed0ad58b2b31e13615b0c58 100755 (executable)
@@ -18,15 +18,21 @@ fi
 
 set -e
 
+cp "$1/lightning-c-bindings/include/lightning.h" ./
+sed -i "s/TransactionOutputs/C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ/g" ./lightning.h
+
 echo "Creating Java bindings..."
 mkdir -p src/main/java/org/ldk/{enums,structs}
 rm -f src/main/java/org/ldk/{enums,structs}/*.java
 rm -f src/main/jni/*.h
 if [ "$4" = "true" ]; then
-       ./genbindings.py "$1/lightning-c-bindings/include/lightning.h" src/main/java/org/ldk/impl/bindings.java src/main/java/org/ldk src/main/jni/bindings.c $3 android $4
+       ./genbindings.py "./lightning.h" src/main/java/org/ldk/impl/bindings.java src/main/java/org/ldk src/main/jni/bindings.c.body $3 android $4
 else
-       ./genbindings.py "$1/lightning-c-bindings/include/lightning.h" src/main/java/org/ldk/impl/bindings.java src/main/java/org/ldk src/main/jni/bindings.c $3 java $4
+       ./genbindings.py "./lightning.h" src/main/java/org/ldk/impl/bindings.java src/main/java/org/ldk src/main/jni/bindings.c.body $3 java $4
 fi
+echo "#define LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ LDKCVec_TransactionOutputsZ" > src/main/jni/bindings.c
+echo "#define CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free CVec_TransactionOutputsZ_free" >> src/main/jni/bindings.c
+cat src/main/jni/bindings.c.body >> src/main/jni/bindings.c
 javac -h src/main/jni src/main/java/org/ldk/enums/*.java src/main/java/org/ldk/impl/bindings.java
 rm src/main/java/org/ldk/enums/*.class src/main/java/org/ldk/impl/bindings*.class
 
@@ -41,7 +47,10 @@ fi
 echo "Creating TS bindings..."
 mkdir -p ts/{enums,structs}
 rm -f ts/{enums,structs}/*.ts
-./genbindings.py "$1/lightning-c-bindings/include/lightning.h" ts/bindings.ts ts ts/bindings.c $3 typescript
+./genbindings.py "./lightning.h" ts/bindings.ts ts ts/bindings.c.body $3 typescript
+echo "#define LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ LDKCVec_TransactionOutputsZ" > ts/bindings.c
+echo "#define CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free CVec_TransactionOutputsZ_free" >> ts/bindings.c
+cat ts/bindings.c.body >> ts/bindings.c
 
 echo "Building TS bindings..."
 COMPILE="$COMMON_COMPILE -flto -Wl,--no-entry -Wl,--export-dynamic -Wl,-allow-undefined -nostdlib --target=wasm32-wasi"