Skip to content

Commit a672396

Browse files
authored
Merge pull request #128 from TheBlueMatt/main
Update to LDK 0.0.115
2 parents 94769d9 + b3fe89e commit a672396

File tree

528 files changed

+147306
-104642
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

528 files changed

+147306
-104642
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ jobs:
4040
# Note this is a different endpoint, as we need one non-upstream commit!
4141
git clone https://git.bitcoin.ninja/rust-lightning
4242
cd rust-lightning
43-
git checkout origin/2023-02-0.0.114-java-bindings
43+
git checkout origin/2023-04-0.0.115-java-bindings
4444
cd ..
4545
git clone https://github.com/lightningdevkit/ldk-c-bindings
4646
cd ldk-c-bindings
47-
git checkout 0.0.114
47+
git checkout 0.0.115
4848
- name: Rebuild C bindings without STD
4949
run: |
5050
cd ldk-c-bindings
@@ -134,11 +134,11 @@ jobs:
134134
# Note this is a different endpoint, as we need one non-upstream commit!
135135
git clone https://git.bitcoin.ninja/rust-lightning
136136
cd rust-lightning
137-
git checkout origin/2023-02-0.0.114-java-bindings
137+
git checkout origin/2023-04-0.0.115-java-bindings
138138
cd ..
139139
git clone https://github.com/lightningdevkit/ldk-c-bindings
140140
cd ldk-c-bindings
141-
git checkout 0.0.114
141+
git checkout 0.0.115
142142
- name: Rebuild C bindings, and check the sample app builds + links
143143
run: |
144144
cd ldk-c-bindings
@@ -190,11 +190,11 @@ jobs:
190190
# Note this is a different endpoint, as we need one non-upstream commit!
191191
git clone https://git.bitcoin.ninja/rust-lightning
192192
cd rust-lightning
193-
git checkout origin/2023-02-0.0.114-java-bindings
193+
git checkout origin/2023-04-0.0.115-java-bindings
194194
cd ..
195195
git clone https://github.com/lightningdevkit/ldk-c-bindings
196196
cd ldk-c-bindings
197-
git checkout 0.0.114
197+
git checkout 0.0.115
198198
- name: Rebuild C bindings, and check the sample app builds + links
199199
run: |
200200
cd ldk-c-bindings
@@ -297,11 +297,11 @@ jobs:
297297
# Note this is a different endpoint, as we need one non-upstream commit!
298298
git clone https://git.bitcoin.ninja/rust-lightning
299299
cd rust-lightning
300-
git checkout origin/2023-02-0.0.114-java-bindings
300+
git checkout origin/2023-04-0.0.115-java-bindings
301301
cd ..
302302
git clone https://github.com/lightningdevkit/ldk-c-bindings
303303
cd ldk-c-bindings
304-
git checkout 0.0.114
304+
git checkout 0.0.115
305305
- name: Checkout Android AAR binaries and artifacts
306306
run: |
307307
# Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
@@ -378,11 +378,11 @@ jobs:
378378
# Note this is a different endpoint, as we need one non-upstream commit!
379379
git clone https://git.bitcoin.ninja/rust-lightning
380380
cd rust-lightning
381-
git checkout origin/2023-02-0.0.114-java-bindings
381+
git checkout origin/2023-04-0.0.115-java-bindings
382382
cd ..
383383
git clone https://github.com/lightningdevkit/ldk-c-bindings
384384
cd ldk-c-bindings
385-
git checkout 0.0.114
385+
git checkout 0.0.115
386386
- name: Rebuild C bindings with upstream clang, and check the sample app builds + links
387387
run: |
388388
export PATH=`pwd`/clang+llvm-15.0.7-x86_64-apple-darwin21.0/bin:$PATH

genbindings.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@
3030
import csharp_strings
3131
from csharp_strings import Consts
3232
target = csharp_strings.Target.CSHARP
33+
elif sys.argv[6] == "python":
34+
import python_strings
35+
from python_strings import Consts
36+
target = python_strings.Target.PYTHON
3337
else:
34-
print("Only java, typescript, or c_sharp can be set for lang")
38+
print("Only java, typescript, python, or c_sharp can be set for lang")
3539
sys.exit(1)
3640

3741

@@ -128,13 +132,15 @@ def java_c_types(fn_arg, ret_arr_len):
128132
rust_obj = None
129133
arr_access = None
130134
java_hu_ty = None
131-
if fn_arg.startswith("LDKPaymentPreimage") or fn_arg.startswith("LDKPaymentSecret") or fn_arg.startswith("LDKPaymentHash"):
135+
if fn_arg.startswith("LDKPaymentPreimage") or fn_arg.startswith("LDKPaymentSecret") or fn_arg.startswith("LDKPaymentHash") or fn_arg.startswith("LDKChainHash"):
132136
if fn_arg.startswith("LDKPaymentPreimage"):
133137
fn_arg = "uint8_t (*" + fn_arg[19:] + ")[32]"
134138
elif fn_arg.startswith("LDKPaymentSecret"):
135139
fn_arg = "uint8_t (*" + fn_arg[17:] + ")[32]"
136140
elif fn_arg.startswith("LDKPaymentHash"):
137141
fn_arg = "uint8_t (*" + fn_arg[15:] + ")[32]"
142+
elif fn_arg.startswith("LDKChainHash"):
143+
fn_arg = "uint8_t (*" + fn_arg[13:] + ")[32]"
138144
assert var_is_arr_regex.match(fn_arg[8:])
139145
rust_obj = "LDKThirtyTwoBytes"
140146
arr_access = "data"
@@ -339,14 +345,17 @@ def java_c_types(fn_arg, ret_arr_len):
339345
arr_ty = "LDKStr"
340346
fn_ty_arg = "Ljava/lang/String;"
341347
fn_arg = fn_arg[6:].strip()
342-
elif fn_arg.startswith("LDKStr"):
348+
elif fn_arg.startswith("LDKStr") or fn_arg.startswith("LDKAddress"):
343349
rust_obj = "LDKStr"
344350
arr_ty = "LDKStr"
345351
java_ty = consts.java_type_map["String"]
346352
java_hu_ty = consts.java_hu_type_map["String"]
347353
c_ty = "jstring"
348354
fn_ty_arg = "Ljava/lang/String;"
349-
fn_arg = fn_arg[6:].strip()
355+
if fn_arg.startswith("LDKAddress"):
356+
fn_arg = fn_arg[10:].strip()
357+
else:
358+
fn_arg = fn_arg[6:].strip()
350359
arr_access = "chars"
351360
arr_len = "len"
352361
elif fn_arg.startswith("LDKError ") or fn_arg == "LDKError":

genbindings.sh

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,74 @@ if [ "$2" = "c_sharp" ]; then
121121
$COMPILE $LINK -o liblightningjni_debug$LDK_TARGET_SUFFIX.so -g -fsanitize=address -shared-libasan -rdynamic -I"$1"/lightning-c-bindings/include/ $2 c_sharp/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/debug/libldk.a -lm
122122
else
123123
$COMPILE -o bindings.o -c -flto -O3 -I"$1"/lightning-c-bindings/include/ $2 c_sharp/bindings.c
124-
$COMPILE $LINK -o liblightningjni_release$LDK_TARGET_SUFFIX.so -Wl,--version-script=c_sharp/libcode.version -flto -O3 -Wl,--lto-O3 -Wl,-O3 -Wl,--version-script=c_sharp/libcode.version -I"$1"/lightning-c-bindings/include/ $2 bindings.o "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a -lm
124+
$COMPILE $LINK -o liblightningjni_release$LDK_TARGET_SUFFIX.so -flto -O3 -Wl,--lto-O3 -Wl,-O3 -Wl,--version-script=c_sharp/libcode.version -I"$1"/lightning-c-bindings/include/ $2 bindings.o "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a -lm
125125
llvm-strip liblightningjni_release$LDK_TARGET_SUFFIX.so
126126
fi
127+
elif [ "$2" = "python" ]; then
128+
TARGET_STRING="$LDK_TARGET"
129+
if [ "$TARGET_STRING" = "" ]; then
130+
# We assume clang-style $CC --version here, but worst-case we just get an empty suffix
131+
TARGET_STRING="$($CC --version | grep Target | awk '{ print $2 }')"
132+
fi
133+
case "$TARGET_STRING" in
134+
"x86_64-pc-linux"*)
135+
LDK_TARGET_SUFFIX="_Linux-amd64"
136+
LDK_JAR_TARGET=true
137+
;;
138+
"x86_64-apple-darwin"*)
139+
LDK_TARGET_SUFFIX="_MacOSX-x86_64"
140+
LDK_JAR_TARGET=true
141+
;;
142+
"aarch64-apple-darwin"*)
143+
LDK_TARGET_CPU="apple-a14"
144+
LDK_TARGET_SUFFIX="_MacOSX-aarch64"
145+
LDK_JAR_TARGET=true
146+
;;
147+
*)
148+
LDK_TARGET_SUFFIX="_${TARGET_STRING}"
149+
esac
150+
if [ "$LDK_TARGET_CPU" = "" ]; then
151+
LDK_TARGET_CPU="sandybridge"
152+
fi
153+
154+
echo "Creating Python bindings..."
155+
mkdir -p python/src/{enums,structs,impl}
156+
rm -f python/src/{enums,structs,impl}/*.py
157+
./genbindings.py "./lightning.h" python/src/impl python/src python/ $DEBUG_ARG python $4
158+
rm -f python/bindings.c
159+
if [ "$3" = "true" ]; then
160+
echo "#define LDK_DEBUG_BUILD" > python/bindings.c
161+
elif [ "$3" = "leaks" ]; then
162+
# For leak checking we use release libldk which doesn't expose
163+
# __unmangle_inner_ptr, but the C code expects to be able to call it.
164+
echo "#define __unmangle_inner_ptr(a) (a)" > python/bindings.c
165+
fi
166+
echo "#define LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ LDKCVec_TransactionOutputsZ" >> python/bindings.c
167+
echo "#define CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free CVec_TransactionOutputsZ_free" >> python/bindings.c
168+
cat python/bindings.c.body >> python/bindings.c
169+
170+
IS_MAC=false
171+
[ "$($CC --version | grep apple-darwin)" != "" ] && IS_MAC=true
172+
IS_APPLE_CLANG=false
173+
[ "$($CC --version | grep "Apple clang version")" != "" ] && IS_APPLE_CLANG=true
174+
175+
echo "Building Python bindings..."
176+
COMPILE="$COMMON_COMPILE -mcpu=$LDK_TARGET_CPU -Isrc/main/jni -pthread -fPIC"
177+
LINK="-ldl -shared"
178+
[ "$IS_MAC" = "false" ] && LINK="$LINK -Wl,--no-undefined"
179+
[ "$IS_MAC" = "true" ] && COMPILE="$COMPILE -mmacosx-version-min=10.9"
180+
[ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && LINK="$LINK -fuse-ld=lld"
181+
[ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && echo "WARNING: Need at least upstream clang 13!"
182+
[ "$IS_MAC" = "false" -a "$3" != "false" ] && LINK="$LINK -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,malloc -Wl,-wrap,free"
183+
184+
exit 0 # Sadly compilation doesn't currently work
185+
if [ "$3" = "true" ]; then
186+
$COMPILE $LINK -o liblightningpython_debug$LDK_TARGET_SUFFIX.so -g -fsanitize=address -shared-libasan -rdynamic -I"$1"/lightning-c-bindings/include/ $2 c_sharp/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/debug/libldk.a -lm
187+
else
188+
$COMPILE -o bindings.o -c -flto -O3 -I"$1"/lightning-c-bindings/include/ $2 c_sharp/bindings.c
189+
$COMPILE $LINK -o liblightningpython_release$LDK_TARGET_SUFFIX.so -Wl,--version-script=python/libcode.version -flto -O3 -Wl,--lto-O3 -Wl,-O3 -I"$1"/lightning-c-bindings/include/ $2 bindings.o "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a -lm
190+
llvm-strip liblightningpython_release$LDK_TARGET_SUFFIX.so
191+
fi
127192
elif [ "$2" = "wasm" ]; then
128193
echo "Creating TS bindings..."
129194
mkdir -p ts/{enums,structs}

java_strings.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ def create_native_arr_call(self, arr_len, ty_info):
521521
clz_var = ty_info.java_fn_ty_arg[1:].replace("[", "arr_of_")
522522
self.c_array_class_caches.add(clz_var)
523523
return "(*env)->NewObjectArray(env, " + arr_len + ", " + clz_var + "_clz, NULL);\n"
524+
elif ty_info.subty.c_ty == "jstring":
525+
return "(*env)->NewObjectArray(env, " + arr_len + ", String_clz, NULL);\n"
524526
else:
525527
return "(*env)->New" + ty_info.java_ty.strip("[]").title() + "Array(env, " + arr_len + ")"
526528
def set_native_arr_contents(self, arr_name, arr_len, ty_info):
@@ -531,6 +533,8 @@ def set_native_arr_contents(self, arr_name, arr_len, ty_info):
531533
else:
532534
assert False
533535
def get_native_arr_contents(self, arr_name, dest_name, arr_len, ty_info, copy):
536+
if "String" in ty_info.java_ty:
537+
return None
534538
if ty_info.c_ty == "int8_tArray" or ty_info.c_ty == "int16_tArray":
535539
fn_ty = "Byte" if ty_info.c_ty == "int8_tArray" else "Short"
536540
if copy:
@@ -590,11 +594,16 @@ def init_str(self):
590594
res = ""
591595
for ty in sorted(self.c_array_class_caches):
592596
res = res + "static jclass " + ty + "_clz = NULL;\n"
597+
res = res + "static jclass String_clz = NULL;\n"
593598
res = res + "JNIEXPORT void Java_org_ldk_impl_bindings_init_1class_1cache(JNIEnv * env, jclass clz) {\n"
594599
for ty in sorted(self.c_array_class_caches):
595600
res = res + "\t" + ty + "_clz = (*env)->FindClass(env, \"" + ty.replace("arr_of_", "[") + "\");\n"
596601
res = res + "\tCHECK(" + ty + "_clz != NULL);\n"
597602
res = res + "\t" + ty + "_clz = (*env)->NewGlobalRef(env, " + ty + "_clz);\n"
603+
res = res + "\tString_clz = (*env)->FindClass(env, \"Ljava/lang/String;\");\n"
604+
res = res + "\tCHECK(String_clz != NULL);\n"
605+
res = res + "\tString_clz = (*env)->NewGlobalRef(env, String_clz);\n"
606+
598607
res = res + "}\n"
599608
return res
600609

@@ -1331,6 +1340,8 @@ def map_function(self, argument_types, c_call_string, method_name, meth_n, retur
13311340
extra_java_struct_out += "\t\tif (!(o instanceof " + struct_meth + ")) return false;\n"
13321341
extra_java_struct_out += "\t\treturn this.eq((" + struct_meth + ")o);\n"
13331342
extra_java_struct_out += "\t}\n"
1343+
if meth_n == "wait":
1344+
meth_n = "wait_indefinite"
13341345
out_java_struct += ("\tpublic " + return_type_info.java_hu_ty + " " + meth_n + "(")
13351346
for idx, arg in enumerate(argument_types):
13361347
if idx != 0:

javatester/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<dependency>
1818
<groupId>org.bitcoinj</groupId>
1919
<artifactId>bitcoinj-core</artifactId>
20-
<version>0.15.10</version>
20+
<version>0.17-alpha1</version>
2121
<scope>compile</scope>
2222
</dependency>
2323
<dependency>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<dependency>
5353
<groupId>org.bitcoinj</groupId>
5454
<artifactId>bitcoinj-core</artifactId>
55-
<version>RELEASE</version>
55+
<version>0.17-alpha1</version>
5656
<scope>test</scope>
5757
</dependency>
5858
<dependency>

0 commit comments

Comments
 (0)