Skip to content

Commit 246459d

Browse files
authored
Merge pull request #2 from TheBlueMatt/main
Expose Features
2 parents b52dde8 + 0941c5e commit 246459d

File tree

294 files changed

+34185
-18729
lines changed

Some content is hidden

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

294 files changed

+34185
-18729
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Building
1010

1111
A release build of the Java bindings library for Linux is available in git. Thus, the bindings should work as long as the `LD_LIBRARY_PATH` includes the top-level directory of this repository.
1212

13-
To build the bindings locally, the bindings require some additional work which is still making its way upstream, for now it should be built against the [rust-lightning 2020-10-java-bindings-base branch on git.bitcoin.ninja](https://git.bitcoin.ninja/?p=rust-lightning;a=shortlog;h=refs/heads/2020-10-java-bindings-base). Check that branch out locally and run the `genbindings.sh` script in it to build the required binaries. Thereafter, in this repo, run the `genbindings.sh` script with the first argument pointing to the rust-lightning directory, the second the relevant JNI CFLAGS, the third argument set to `true` or `false` to indicate whether building in debug mode, and the third set to true or false to indicate if the bindings should be built with workarounds required for Android. JNI CFLAGS on debian are likely "-I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/". When running a program linking against the library in debug mode, LD_PRELOAD should likely include the relevant `libclang_rt.asan-platform.so` path.
13+
To build the bindings locally, the bindings require some additional work which is still making its way upstream, for now it should be built against the [rust-lightning 2021-03-java-bindings-base branch on git.bitcoin.ninja](https://git.bitcoin.ninja/?p=rust-lightning;a=shortlog;h=refs/heads/2021-03-java-bindings-base). Check that branch out locally and run the `genbindings.sh` script in it to build the required binaries. Thereafter, in this repo, run the `genbindings.sh` script with the first argument pointing to the rust-lightning directory, the second the relevant JNI CFLAGS, the third argument set to `true` or `false` to indicate whether building in debug mode, and the third set to true or false to indicate if the bindings should be built with workarounds required for Android. JNI CFLAGS on debian are likely "-I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/". When running a program linking against the library in debug mode, LD_PRELOAD should likely include the relevant `libclang_rt.asan-platform.so` path.
1414

1515
Status
1616
======

gen_type_mapping.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
3232
else:
3333
arr_name = "ret"
3434
arr_len = ret_arr_len
35+
if arr_name == "arg":
36+
arr_name = "ret"
3537
if ty_info.c_ty == "int8_tArray":
3638
(set_pfx, set_sfx) = self.consts.set_native_arr_contents(arr_name + "_arr", arr_len, ty_info)
3739
ret_conv = ("int8_tArray " + arr_name + "_arr = " + self.consts.create_native_arr_call(arr_len, ty_info) + ";\n" + set_pfx, "")
@@ -70,7 +72,9 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
7072
else:
7173
assert not arr_len.isdigit() # fixed length arrays not implemented
7274
assert ty_info.java_ty[len(ty_info.java_ty) - 2:] == "[]"
73-
conv_name = "arr_conv_" + str(len(ty_info.java_hu_ty))
75+
if arr_name == "":
76+
arr_name = "ret"
77+
conv_name = arr_name + "_conv_" + str(len(ty_info.java_hu_ty))
7478
idxc = chr(ord('a') + (len(ty_info.java_hu_ty) % 26))
7579
ty_info.subty.var_name = conv_name
7680
#XXX: We'd really prefer to only ever set to False, avoiding lots of clone, but need smarter free logic
@@ -84,8 +88,6 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
8488
# ChannelMonitors inside of vecs.
8589
ty_info.subty.requires_clone = False
8690
subty = self.map_type_with_info(ty_info.subty, False, None, is_free, holds_ref)
87-
if arr_name == "":
88-
arr_name = "arg"
8991
arg_conv = ty_info.rust_obj + " " + arr_name + "_constr;\n"
9092
arg_conv = arg_conv + arr_name + "_constr." + arr_len + " = " + self.consts.get_native_arr_len_call[0] + arr_name + self.consts.get_native_arr_len_call[1] + ";\n"
9193
arg_conv = arg_conv + "if (" + arr_name + "_constr." + arr_len + " > 0)\n"
@@ -120,8 +122,6 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
120122
if ty_info.is_ptr:
121123
arg_conv_cleanup = "FREE(" + arr_name + "_constr." + ty_info.arr_access + ");"
122124

123-
if arr_name == "arg":
124-
arr_name = "ret"
125125
ret_conv = (ty_info.rust_obj + " " + arr_name + "_var = ", "")
126126
if subty.ret_conv is None:
127127
ret_conv = ("DUMMY", "DUMMY")
@@ -165,7 +165,7 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
165165
elif subty.java_ty == "long":
166166
from_hu_conv = ("Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + subty.from_hu_conv[0] + ").toArray()", "/* TODO 2 " + subty.java_hu_ty + " */")
167167
else:
168-
from_hu_conv = ("(" + ty_info.java_ty + ")Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + subty.from_hu_conv[0] + ").toArray()", "/* TODO 2 " + subty.java_hu_ty + " */")
168+
from_hu_conv = ("Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + subty.from_hu_conv[0] + ").toArray(" + ty_info.java_ty + "::new)", "/* TODO 2 " + subty.java_hu_ty + " */")
169169

170170
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
171171
arg_conv = arg_conv, arg_conv_name = arg_conv_name, arg_conv_cleanup = arg_conv_cleanup,

java_strings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class CommonBase {
198198
size_t alloc_count = 0;
199199
size_t alloc_size = 0;
200200
for (allocation* a = allocation_ll; a != NULL; a = a->next) {
201-
fprintf(stderr, "%s %p remains:\\n", a->struct_name, a->ptr);
201+
fprintf(stderr, "%s %p (%lu bytes) remains:\\n", a->struct_name, a->ptr, a->alloc_len);
202202
backtrace_symbols_fd(a->bt, a->bt_len, STDERR_FILENO);
203203
fprintf(stderr, "\\n\\n");
204204
alloc_count++;
@@ -651,7 +651,7 @@ def native_c_map_trait(self, struct_name, field_vars, field_fns):
651651

652652
out_c = out_c + "\tjobject obj = (*env)->NewLocalRef(env, j_calls->o);\n\tCHECK(obj != NULL);\n"
653653
if fn_line.ret_ty_info.c_ty.endswith("Array"):
654-
out_c = out_c + "\t" + fn_line.ret_ty_info.c_ty + " arg = (*env)->CallObjectMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
654+
out_c = out_c + "\t" + fn_line.ret_ty_info.c_ty + " ret = (*env)->CallObjectMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
655655
elif not fn_line.ret_ty_info.passed_as_ptr:
656656
out_c = out_c + "\treturn (*env)->Call" + fn_line.ret_ty_info.java_ty.title() + "Method(env, obj, j_calls->" + fn_line.fn_name + "_meth"
657657
else:

liblightningjni.so

-120 KB
Binary file not shown.

src/main/java/org/ldk/batteries/ChannelManagerConstructor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ public ChannelManagerConstructor(LDKNetwork network, UserConfig config, byte[] c
7171
channel_monitors = new TwoTuple[0];
7272
channel_manager_latest_block_hash = null;
7373
this.chain_watch = chain_watch;
74-
// Note that current_blockchain_tip_hash will be required in a future version but is currently unused.
75-
channel_manager = ChannelManager.constructor_new(network, fee_estimator, chain_watch, tx_broadcaster, logger, keys_interface, config, current_blockchain_tip_height);
74+
channel_manager = ChannelManager.constructor_new(fee_estimator, chain_watch, tx_broadcaster, logger, keys_interface, config, network, current_blockchain_tip_hash, current_blockchain_tip_height);
7675
}
7776

7877
/**

src/main/java/org/ldk/enums/LDKNetwork.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public enum LDKNetwork {
44
LDKNetwork_Bitcoin,
55
LDKNetwork_Testnet,
66
LDKNetwork_Regtest,
7+
LDKNetwork_Signet,
78
; static native void init();
89
static { init(); }
910
}

src/main/java/org/ldk/enums/LDKSecp256k1Error.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public enum LDKSecp256k1Error {
88
LDKSecp256k1Error_InvalidSecretKey,
99
LDKSecp256k1Error_InvalidRecoveryId,
1010
LDKSecp256k1Error_InvalidTweak,
11+
LDKSecp256k1Error_TweakCheckFailed,
1112
LDKSecp256k1Error_NotEnoughMemory,
12-
LDKSecp256k1Error_CallbackPanicked,
1313
; static native void init();
1414
static { init(); }
1515
}

0 commit comments

Comments
 (0)