From: Matt Corallo Date: Thu, 15 Apr 2021 23:00:35 +0000 (-0400) Subject: Handle the somewhat half-mapped alias TransactionOutputs X-Git-Tag: v0.0.98~2^2~5 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=aa1fab79e70b10280271c77a01626c62a18e46c4;p=ldk-java Handle the somewhat half-mapped alias TransactionOutputs 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. --- diff --git a/genbindings.py b/genbindings.py index b1f4a5eb..ab5b0cbf 100755 --- a/genbindings.py +++ b/genbindings.py @@ -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:]) diff --git a/genbindings.sh b/genbindings.sh index dcec47be..e208785f 100755 --- a/genbindings.sh +++ b/genbindings.sh @@ -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"